Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1617007ybv; Fri, 21 Feb 2020 00:21:59 -0800 (PST) X-Google-Smtp-Source: APXvYqwvYEobWm9Tl6bHuk+x2hfFmSInEV0kQqg7yygF20cM1CDAWiDz96lGuFrQufHtVZeD9tO5 X-Received: by 2002:a9d:5d09:: with SMTP id b9mr26679012oti.207.1582273319327; Fri, 21 Feb 2020 00:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273319; cv=none; d=google.com; s=arc-20160816; b=Dq4x1OYhDNrthPFjGBA62uFaYPMcxnzrN2fq/z+Dw4/casn6wN13RfCCKZxJol+7pl 59DgPky461V9xOW/0Jwscjm/KS6NOS1VBihtaHAtcWpOMQrjNM5+W2MekqbnjUjQ4TSu QbPX16epJCDZlH69EL6NoPb6yg/5RLPI0QrF1Lec8FV8Bmt3O/Mr9F7nVcNW+ZB9WlZS jy1pw98NCU7O0PQQ4TClA8Xo3EaF8IBWw8binWmWz7nkos8ZG6B6wyh7OQ5O/p2Vv4ll TWhh83kwxl4U5+I45JrKS7pXW2EVkjYHvy5cM3qquaq/tmKWS3mYH+VgpDVhojwcyqRn 0LDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=37pOWXzIWgBDN4hW9P6yY0jfLy4zLDQlFXXwzXSpyJM=; b=UKCvSCec0wF2tm6kpr6w6MZjrXDbXB0neNeSW+lEFd9KHP7aYXicOeGjRUpPV6Tpys ANsfRQgi7lEFJYPR7VxhcXTqqKVhdmpo0uqwY42q8WvTOZYLD8FuTkLa4pGQPae3hr6Z wSKcyGYmkfLn7TDyNb3psQPTNlS1s4+I7ocYfvQ/rw9A6Pneh3Jr6ggl31iFNnZH0Ig4 UX1S0nNcNlw4Ehps2G17Odleax6rtCoOwm7LNc3HBDJcRQxS3Kd7V3sd+aFPBADFxPiM p1YqKnOC2RAzEx4zpdeTWK5GFrTVfE+MOKwwxSwGSQf6OvM2rB6cYUzG2KjKq9nL/xsI 6DmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DswUV0cU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u14si1154624otg.10.2020.02.21.00.21.47; Fri, 21 Feb 2020 00:21:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DswUV0cU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387999AbgBUIVE (ORCPT + 99 others); Fri, 21 Feb 2020 03:21:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:60320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387930AbgBUIVC (ORCPT ); Fri, 21 Feb 2020 03:21:02 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C9552073A; Fri, 21 Feb 2020 08:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273261; bh=DJOrz9cU+Db2X5LufbrBNiGevY8hRrDU7M5k8LQc3Wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DswUV0cUqkOh30sk2p1xoo7H/1tOh/4UNYEuJB9AL3CZDwXj1Gc1sSgdKRw2ASITh aCNNImm1s/WzLTlQlzH2FuCvjM3DCY+8VqgfLOemAJ63v02U6UW6K4NL5QL5tnRqz5 ljDhsKI3Jw86hkpnqdS2mYHMByiR3W+NXtn/uqyw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , Jan Kara , Sasha Levin Subject: [PATCH 4.19 105/191] udf: Fix free space reporting for metadata and virtual partitions Date: Fri, 21 Feb 2020 08:41:18 +0100 Message-Id: <20200221072303.549580099@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ Upstream commit a4a8b99ec819ca60b49dc582a4287ef03411f117 ] Free space on filesystems with metadata or virtual partition maps currently gets misreported. This is because these partitions are just remapped onto underlying real partitions from which keep track of free blocks. Take this remapping into account when counting free blocks as well. Reviewed-by: Pali Rohár Reported-by: Pali Rohár Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/udf/super.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fs/udf/super.c b/fs/udf/super.c index 6fd0f14e9dd22..1676a175cd7a8 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -2469,17 +2469,29 @@ static unsigned int udf_count_free_table(struct super_block *sb, static unsigned int udf_count_free(struct super_block *sb) { unsigned int accum = 0; - struct udf_sb_info *sbi; + struct udf_sb_info *sbi = UDF_SB(sb); struct udf_part_map *map; + unsigned int part = sbi->s_partition; + int ptype = sbi->s_partmaps[part].s_partition_type; + + if (ptype == UDF_METADATA_MAP25) { + part = sbi->s_partmaps[part].s_type_specific.s_metadata. + s_phys_partition_ref; + } else if (ptype == UDF_VIRTUAL_MAP15 || ptype == UDF_VIRTUAL_MAP20) { + /* + * Filesystems with VAT are append-only and we cannot write to + * them. Let's just report 0 here. + */ + return 0; + } - sbi = UDF_SB(sb); if (sbi->s_lvid_bh) { struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *) sbi->s_lvid_bh->b_data; - if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { + if (le32_to_cpu(lvid->numOfPartitions) > part) { accum = le32_to_cpu( - lvid->freeSpaceTable[sbi->s_partition]); + lvid->freeSpaceTable[part]); if (accum == 0xFFFFFFFF) accum = 0; } @@ -2488,7 +2500,7 @@ static unsigned int udf_count_free(struct super_block *sb) if (accum) return accum; - map = &sbi->s_partmaps[sbi->s_partition]; + map = &sbi->s_partmaps[part]; if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { accum += udf_count_free_bitmap(sb, map->s_uspace.s_bitmap); -- 2.20.1