Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1591852ybv; Thu, 20 Feb 2020 23:54:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwQe4OZnsyZeZQPLFBEkKWLzSW7eLQ0MHLfCUwl+dcV+78TLB0FFaVNeIs8l2TOEt3aqsKJ X-Received: by 2002:a9d:754e:: with SMTP id b14mr11628260otl.59.1582271660579; Thu, 20 Feb 2020 23:54:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271660; cv=none; d=google.com; s=arc-20160816; b=v0VzVRSWYfF8Eo2Zc6VKar4F4IZ0qeujUH7hY4K8ldlAP8VeqQq74+RPOTcP9WK1Lw 5WRhX7FjAx1t8RPJxJZ4vjGV2acmQGieRo+NXS0hbMHlwBGrGZQHEV1Sp0XxXK80A47e z6i89orwL9bk+QFSpC6Mhdh/IRJs9L07HTVQ/K8OGs7itdnbdX6pKdY7u+r67N0WL+BO dbAkgik+OdlnPlocUwa/6Pl2CGXaExKtHlCNbnIoFjYRYJxC4ihKuiu0hvXkiXVfhJtH VQuHlbT+0eBE9GR9hoqwieyMAhgSU53f83WfteGgDhjo08/IvWDSks+FOusUsXyICX37 2GAw== 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=dbSi34gahiuxQlpkphOctYzqbRzaJbGVkgdgKJnvRJg=; b=LmrTFVWdEkFKzbgHlmmmNIE1ie8OBcjQKjuj5+fuv+Ki/VY+UDvTsJeo1Li9OTMN0m 7JJtFWJFyVuNk0c1zY8IpBNURPFrQEdNYeDhkPHOPBsFqPr5tPmhG3Xegzjs7Kg88g0R lEv8T9wIbHzm6tYbsVnaIO3q//Izm8vAI0beTuhmW8FcqsV1Mw/itlpPT8shmQJPJ/za 8HIGGXiWgy480nyKY9w2x5Rpru98ZX8tl1jOpdCcIBQIqk6BO9BJABCV1DXPJvdzYhPC q+OLNUGl25mkCiOYADcbSUrwhKLzmcRui64ONuSTzi4VCC6GY5JTxEH7N9FOzbFWSglC usYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kmUdS9x7; 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 77si431744oie.10.2020.02.20.23.54.08; Thu, 20 Feb 2020 23:54:20 -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=kmUdS9x7; 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 S1730006AbgBUHxG (ORCPT + 99 others); Fri, 21 Feb 2020 02:53:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:51132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728953AbgBUHxD (ORCPT ); Fri, 21 Feb 2020 02:53:03 -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 113C924650; Fri, 21 Feb 2020 07:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271582; bh=veonelLyHYVdZEaWEmcvfnbE3w0QTXWIx3ruw3NtQm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmUdS9x7Ov0NbSfnUlFaWyEYg3/v80GoF2fQnS+1h1U0oJkd3AlLP/EI4xBBhQ1TX qs8BhTn7Q/c5LGy8eDIcni1vgrmSleAIGV/Q2aGDoPmT9fmU652k1HkFrLyOU0lmwe uD0MQ/JF1cEhULUHqmC6Kjp0UoBpvrm/e3tRwTzI= 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 5.5 221/399] udf: Fix free space reporting for metadata and virtual partitions Date: Fri, 21 Feb 2020 08:39:06 +0100 Message-Id: <20200221072424.454614923@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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 008bf96b1732d..4baa1ca91e9be 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -2491,17 +2491,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; } @@ -2510,7 +2522,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