All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] udf: Fix free space reporting for metadata and virtual partitions
@ 2020-01-09 12:53 Jan Kara
  2020-01-09 12:59 ` Pali Rohár
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2020-01-09 12:53 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Pali Rohár, Jan Kara

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.

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 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 2d0b90800519..5a4a6fb36819 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -2492,17 +2492,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;
 		}
@@ -2511,7 +2523,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.16.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] udf: Fix free space reporting for metadata and virtual partitions
  2020-01-09 12:53 [PATCH v2] udf: Fix free space reporting for metadata and virtual partitions Jan Kara
@ 2020-01-09 12:59 ` Pali Rohár
  0 siblings, 0 replies; 2+ messages in thread
From: Pali Rohár @ 2020-01-09 12:59 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel

On Thursday 09 January 2020 13:53:30 Jan Kara wrote:
> 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.
> 
> Reported-by: Pali Rohár <pali.rohar@gmail.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Reviewed-by: Pali Rohár <pali.rohar@gmail.com>

> ---
>  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 2d0b90800519..5a4a6fb36819 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -2492,17 +2492,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;
>  		}
> @@ -2511,7 +2523,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);

-- 
Pali Rohár
pali.rohar@gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-09 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09 12:53 [PATCH v2] udf: Fix free space reporting for metadata and virtual partitions Jan Kara
2020-01-09 12:59 ` Pali Rohár

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.