Skip to content

Commit a4a8b99

Browse files
committed
udf: Fix free space reporting for metadata and virtual partitions
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 <pali.rohar@gmail.com> Reported-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 6146446 commit a4a8b99

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

‎fs/udf/super.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,17 +2492,29 @@ static unsigned int udf_count_free_table(struct super_block *sb,
24922492
static unsigned int udf_count_free(struct super_block *sb)
24932493
{
24942494
unsigned int accum = 0;
2495-
struct udf_sb_info *sbi;
2495+
struct udf_sb_info *sbi = UDF_SB(sb);
24962496
struct udf_part_map *map;
2497+
unsigned int part = sbi->s_partition;
2498+
int ptype = sbi->s_partmaps[part].s_partition_type;
2499+
2500+
if (ptype == UDF_METADATA_MAP25) {
2501+
part = sbi->s_partmaps[part].s_type_specific.s_metadata.
2502+
s_phys_partition_ref;
2503+
} else if (ptype == UDF_VIRTUAL_MAP15 || ptype == UDF_VIRTUAL_MAP20) {
2504+
/*
2505+
* Filesystems with VAT are append-only and we cannot write to
2506+
* them. Let's just report 0 here.
2507+
*/
2508+
return 0;
2509+
}
24972510

2498-
sbi = UDF_SB(sb);
24992511
if (sbi->s_lvid_bh) {
25002512
struct logicalVolIntegrityDesc *lvid =
25012513
(struct logicalVolIntegrityDesc *)
25022514
sbi->s_lvid_bh->b_data;
2503-
if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
2515+
if (le32_to_cpu(lvid->numOfPartitions) > part) {
25042516
accum = le32_to_cpu(
2505-
lvid->freeSpaceTable[sbi->s_partition]);
2517+
lvid->freeSpaceTable[part]);
25062518
if (accum == 0xFFFFFFFF)
25072519
accum = 0;
25082520
}
@@ -2511,7 +2523,7 @@ static unsigned int udf_count_free(struct super_block *sb)
25112523
if (accum)
25122524
return accum;
25132525

2514-
map = &sbi->s_partmaps[sbi->s_partition];
2526+
map = &sbi->s_partmaps[part];
25152527
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
25162528
accum += udf_count_free_bitmap(sb,
25172529
map->s_uspace.s_bitmap);

0 commit comments

Comments
 (0)