Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1946215ybv; Fri, 14 Feb 2020 08:40:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyEfCYzA8bKPUzb9glMw4EZgPlVhuQufhzpwBzUAD2bBiVhkIhHkUl6Lzha1TTyCKjPqbBx X-Received: by 2002:aca:d483:: with SMTP id l125mr2444147oig.124.1581698435739; Fri, 14 Feb 2020 08:40:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698435; cv=none; d=google.com; s=arc-20160816; b=gRVL5Hdi8HLPsszL0EIW5Yf9uKnaY5jr31ZioMxlySgWFD0xbKmJNvI4DTHxTefgie AOsX1XQzjTpYPBb09dpAda5RjtEcYac075PP2LuUfy3g8iaH5ZKQdh3XJ7EGKf4J9vnO nOpZGSQcXufo74Z8XLehnC6ze88C+9YJh1ZW4wD5gUR2DewjQ9mneqPnN2y/XEKiwTEH FmmvwcqegxRmymKxwuLjk2VV4wAMPYxMmh9U2K8F+or5XG56P5EKdv62liMZen1t6FSJ zJaSnbEWnHpH5g53GUPSINCIOJWNNBaAA1DlzoMxqA7vDnIUI2REuaB98zJg+7yT7h5Y /s8w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nytw4mbka5q8jpCLFYFOv0p8K6gbpe/TQiKimUcMMx4=; b=PGnHLGmIuSEA/e5ZIxOXtwyWDAgT3iHj+TLUZQAA8qPpfmaf9l0As2/IwVdM13FSeD JdVCv3RrTabqYz1+M1nRen8DqjHd5ftTMvuXUHlABXMxOvgcGFvzvHgK6Vet/MYmLIrn +C5N4Z151Chd+5/2CYtxv5hmXBxpuEII3Isbz70CTQnZNHM6EQwwIj4wmDsjbUT2MhXY y63YL5KLy+nQnU6iD/1xfZJRtDsUZ311e1DqKIuJDyf9Kf5gRqRLTCZn3XsRHTKN6zt2 qInqvak55vxn0cwGjgEuQeO8FntDOHcrnaiOOV/myD9tnynHWBnzE1SvC9x/RK1oIVC5 8TeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZjdcrBQv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si2814788oii.60.2020.02.14.08.40.24; Fri, 14 Feb 2020 08:40:35 -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=ZjdcrBQv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405624AbgBNQjq (ORCPT + 99 others); Fri, 14 Feb 2020 11:39:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:59164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403862AbgBNQXI (ORCPT ); Fri, 14 Feb 2020 11:23:08 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3E40924762; Fri, 14 Feb 2020 16:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697387; bh=tGdP8o+5wmH2dix7IVUCYODW9Z+SAHSKNrxu6lyRy8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZjdcrBQvlKIyWMI+UyT/PK84KAKSNdCo4yGu8Ow472xnMkWb+Y8MncRnBJ3DvRflX no4nykr5OpEt3LhoW+c9+H1s+URzr96MZv9h0DDYGazqn52O/0zicr7zf9beeQAIfI w8e13oMJlT93SWC9HxW07ldo2/r5AHyYobVE/IoY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jan Kara , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Sasha Levin Subject: [PATCH AUTOSEL 4.9 083/141] udf: Fix free space reporting for metadata and virtual partitions Date: Fri, 14 Feb 2020 11:20:23 -0500 Message-Id: <20200214162122.19794-83-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore 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 03369a89600e0..4abdba453885e 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -2460,17 +2460,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; } @@ -2479,7 +2491,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