Skip to content

Commit fa5e081

Browse files
committed
udf: Handle VAT packed inside inode properly
We didn't handle VAT packed inside the inode - we tried to call udf_block_map() on such file which lead to strange results at best. Add proper handling of packed VAT as we do it with other packed files. Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 742e179 commit fa5e081

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎fs/udf/partition.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,22 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
5454
struct udf_sb_info *sbi = UDF_SB(sb);
5555
struct udf_part_map *map;
5656
struct udf_virtual_data *vdata;
57-
struct udf_inode_info *iinfo;
57+
struct udf_inode_info *iinfo = UDF_I(sbi->s_vat_inode);
5858

5959
map = &sbi->s_partmaps[partition];
6060
vdata = &map->s_type_specific.s_virtual;
61-
index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
6261

6362
if (block > vdata->s_num_entries) {
6463
udf_debug("Trying to access block beyond end of VAT "
6564
"(%d max %d)\n", block, vdata->s_num_entries);
6665
return 0xFFFFFFFF;
6766
}
6867

68+
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
69+
loc = le32_to_cpu(((__le32 *)iinfo->i_ext.i_data)[block]);
70+
goto translate;
71+
}
72+
index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
6973
if (block >= index) {
7074
block -= index;
7175
newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t)));
@@ -88,7 +92,7 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
8892

8993
brelse(bh);
9094

91-
iinfo = UDF_I(sbi->s_vat_inode);
95+
translate:
9296
if (iinfo->i_location.partitionReferenceNum == partition) {
9397
udf_debug("recursive call to udf_get_pblock!\n");
9498
return 0xFFFFFFFF;

‎fs/udf/super.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,10 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
11071107
struct udf_sb_info *sbi = UDF_SB(sb);
11081108
struct udf_part_map *map = &sbi->s_partmaps[p_index];
11091109
kernel_lb_addr ino;
1110-
struct buffer_head *bh;
1110+
struct buffer_head *bh = NULL;
1111+
struct udf_inode_info *vati;
1112+
uint32_t pos;
1113+
struct virtualAllocationTable20 *vat20;
11111114

11121115
/* VAT file entry is in the last recorded block */
11131116
ino.partitionReferenceNum = type1_index;
@@ -1122,15 +1125,18 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
11221125
map->s_type_specific.s_virtual.s_num_entries =
11231126
(sbi->s_vat_inode->i_size - 36) >> 2;
11241127
} else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
1125-
uint32_t pos;
1126-
struct virtualAllocationTable20 *vat20;
1128+
vati = UDF_I(sbi->s_vat_inode);
1129+
if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
1130+
pos = udf_block_map(sbi->s_vat_inode, 0);
1131+
bh = sb_bread(sb, pos);
1132+
if (!bh)
1133+
return 1;
1134+
vat20 = (struct virtualAllocationTable20 *)bh->b_data;
1135+
} else {
1136+
vat20 = (struct virtualAllocationTable20 *)
1137+
vati->i_ext.i_data;
1138+
}
11271139

1128-
pos = udf_block_map(sbi->s_vat_inode, 0);
1129-
bh = sb_bread(sb, pos);
1130-
if (!bh)
1131-
return 1;
1132-
vat20 = (struct virtualAllocationTable20 *)bh->b_data +
1133-
udf_ext0_offset(sbi->s_vat_inode);
11341140
map->s_type_specific.s_virtual.s_start_offset =
11351141
le16_to_cpu(vat20->lengthHeader) +
11361142
udf_ext0_offset(sbi->s_vat_inode);

0 commit comments

Comments
 (0)