diff options
Diffstat (limited to 'fs/udf')
| -rw-r--r-- | fs/udf/balloc.c | 491 | ||||
| -rw-r--r-- | fs/udf/crc.c | 2 | ||||
| -rw-r--r-- | fs/udf/dir.c | 127 | ||||
| -rw-r--r-- | fs/udf/directory.c | 102 | ||||
| -rw-r--r-- | fs/udf/file.c | 43 | ||||
| -rw-r--r-- | fs/udf/ialloc.c | 94 | ||||
| -rw-r--r-- | fs/udf/inode.c | 973 | ||||
| -rw-r--r-- | fs/udf/misc.c | 146 | ||||
| -rw-r--r-- | fs/udf/namei.c | 443 | ||||
| -rw-r--r-- | fs/udf/partition.c | 197 | ||||
| -rw-r--r-- | fs/udf/super.c | 1158 | ||||
| -rw-r--r-- | fs/udf/symlink.c | 9 | ||||
| -rw-r--r-- | fs/udf/truncate.c | 100 | ||||
| -rw-r--r-- | fs/udf/udf_i.h | 16 | ||||
| -rw-r--r-- | fs/udf/udf_sb.h | 90 | ||||
| -rw-r--r-- | fs/udf/udfdecl.h | 15 | ||||
| -rw-r--r-- | fs/udf/udftime.c | 59 | ||||
| -rw-r--r-- | fs/udf/unicode.c | 85 |
18 files changed, 2409 insertions, 1741 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index ab26176f6b91..d721a1af1972 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c | |||
| @@ -28,15 +28,16 @@ | |||
| 28 | #include "udf_i.h" | 28 | #include "udf_i.h" |
| 29 | #include "udf_sb.h" | 29 | #include "udf_sb.h" |
| 30 | 30 | ||
| 31 | #define udf_clear_bit(nr,addr) ext2_clear_bit(nr,addr) | 31 | #define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr) |
| 32 | #define udf_set_bit(nr,addr) ext2_set_bit(nr,addr) | 32 | #define udf_set_bit(nr, addr) ext2_set_bit(nr, addr) |
| 33 | #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr) | 33 | #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr) |
| 34 | #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size) | 34 | #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size) |
| 35 | #define udf_find_next_one_bit(addr, size, offset) find_next_one_bit(addr, size, offset) | 35 | #define udf_find_next_one_bit(addr, size, offset) \ |
| 36 | find_next_one_bit(addr, size, offset) | ||
| 36 | 37 | ||
| 37 | #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x) | 38 | #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x) |
| 38 | #define leNUM_to_cpup(x,y) xleNUM_to_cpup(x,y) | 39 | #define leNUM_to_cpup(x, y) xleNUM_to_cpup(x, y) |
| 39 | #define xleNUM_to_cpup(x,y) (le ## x ## _to_cpup(y)) | 40 | #define xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y)) |
| 40 | #define uintBPL_t uint(BITS_PER_LONG) | 41 | #define uintBPL_t uint(BITS_PER_LONG) |
| 41 | #define uint(x) xuint(x) | 42 | #define uint(x) xuint(x) |
| 42 | #define xuint(x) __le ## x | 43 | #define xuint(x) __le ## x |
| @@ -62,7 +63,8 @@ static inline int find_next_one_bit(void *addr, int size, int offset) | |||
| 62 | result += BITS_PER_LONG; | 63 | result += BITS_PER_LONG; |
| 63 | } | 64 | } |
| 64 | while (size & ~(BITS_PER_LONG - 1)) { | 65 | while (size & ~(BITS_PER_LONG - 1)) { |
| 65 | if ((tmp = leBPL_to_cpup(p++))) | 66 | tmp = leBPL_to_cpup(p++); |
| 67 | if (tmp) | ||
| 66 | goto found_middle; | 68 | goto found_middle; |
| 67 | result += BITS_PER_LONG; | 69 | result += BITS_PER_LONG; |
| 68 | size -= BITS_PER_LONG; | 70 | size -= BITS_PER_LONG; |
| @@ -88,12 +90,12 @@ static int read_block_bitmap(struct super_block *sb, | |||
| 88 | kernel_lb_addr loc; | 90 | kernel_lb_addr loc; |
| 89 | 91 | ||
| 90 | loc.logicalBlockNum = bitmap->s_extPosition; | 92 | loc.logicalBlockNum = bitmap->s_extPosition; |
| 91 | loc.partitionReferenceNum = UDF_SB_PARTITION(sb); | 93 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; |
| 92 | 94 | ||
| 93 | bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); | 95 | bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); |
| 94 | if (!bh) { | 96 | if (!bh) |
| 95 | retval = -EIO; | 97 | retval = -EIO; |
| 96 | } | 98 | |
| 97 | bitmap->s_block_bitmap[bitmap_nr] = bh; | 99 | bitmap->s_block_bitmap[bitmap_nr] = bh; |
| 98 | return retval; | 100 | return retval; |
| 99 | } | 101 | } |
| @@ -138,6 +140,20 @@ static inline int load_block_bitmap(struct super_block *sb, | |||
| 138 | return slot; | 140 | return slot; |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 143 | static bool udf_add_free_space(struct udf_sb_info *sbi, | ||
| 144 | u16 partition, u32 cnt) | ||
| 145 | { | ||
| 146 | struct logicalVolIntegrityDesc *lvid; | ||
| 147 | |||
| 148 | if (sbi->s_lvid_bh) | ||
| 149 | return false; | ||
| 150 | |||
| 151 | lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | ||
| 152 | lvid->freeSpaceTable[partition] = cpu_to_le32(le32_to_cpu( | ||
| 153 | lvid->freeSpaceTable[partition]) + cnt); | ||
| 154 | return true; | ||
| 155 | } | ||
| 156 | |||
| 141 | static void udf_bitmap_free_blocks(struct super_block *sb, | 157 | static void udf_bitmap_free_blocks(struct super_block *sb, |
| 142 | struct inode *inode, | 158 | struct inode *inode, |
| 143 | struct udf_bitmap *bitmap, | 159 | struct udf_bitmap *bitmap, |
| @@ -155,57 +171,58 @@ static void udf_bitmap_free_blocks(struct super_block *sb, | |||
| 155 | 171 | ||
| 156 | mutex_lock(&sbi->s_alloc_mutex); | 172 | mutex_lock(&sbi->s_alloc_mutex); |
| 157 | if (bloc.logicalBlockNum < 0 || | 173 | if (bloc.logicalBlockNum < 0 || |
| 158 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { | 174 | (bloc.logicalBlockNum + count) > |
| 175 | sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | ||
| 159 | udf_debug("%d < %d || %d + %d > %d\n", | 176 | udf_debug("%d < %d || %d + %d > %d\n", |
| 160 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 177 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
| 161 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); | 178 | sbi->s_partmaps[bloc.partitionReferenceNum]. |
| 179 | s_partition_len); | ||
| 162 | goto error_return; | 180 | goto error_return; |
| 163 | } | 181 | } |
| 164 | 182 | ||
| 165 | block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3); | 183 | block = bloc.logicalBlockNum + offset + |
| 184 | (sizeof(struct spaceBitmapDesc) << 3); | ||
| 166 | 185 | ||
| 167 | do_more: | 186 | do { |
| 168 | overflow = 0; | 187 | overflow = 0; |
| 169 | block_group = block >> (sb->s_blocksize_bits + 3); | 188 | block_group = block >> (sb->s_blocksize_bits + 3); |
| 170 | bit = block % (sb->s_blocksize << 3); | 189 | bit = block % (sb->s_blocksize << 3); |
| 171 | 190 | ||
| 172 | /* | 191 | /* |
| 173 | * Check to see if we are freeing blocks across a group boundary. | 192 | * Check to see if we are freeing blocks across a group boundary. |
| 174 | */ | 193 | */ |
| 175 | if (bit + count > (sb->s_blocksize << 3)) { | 194 | if (bit + count > (sb->s_blocksize << 3)) { |
| 176 | overflow = bit + count - (sb->s_blocksize << 3); | 195 | overflow = bit + count - (sb->s_blocksize << 3); |
| 177 | count -= overflow; | 196 | count -= overflow; |
| 178 | } | 197 | } |
| 179 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); | 198 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 180 | if (bitmap_nr < 0) | 199 | if (bitmap_nr < 0) |
| 181 | goto error_return; | 200 | goto error_return; |
| 182 | 201 | ||
| 183 | bh = bitmap->s_block_bitmap[bitmap_nr]; | 202 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
| 184 | for (i = 0; i < count; i++) { | 203 | for (i = 0; i < count; i++) { |
| 185 | if (udf_set_bit(bit + i, bh->b_data)) { | 204 | if (udf_set_bit(bit + i, bh->b_data)) { |
| 186 | udf_debug("bit %ld already set\n", bit + i); | 205 | udf_debug("bit %ld already set\n", bit + i); |
| 187 | udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); | 206 | udf_debug("byte=%2x\n", |
| 188 | } else { | 207 | ((char *)bh->b_data)[(bit + i) >> 3]); |
| 189 | if (inode) | 208 | } else { |
| 190 | DQUOT_FREE_BLOCK(inode, 1); | 209 | if (inode) |
| 191 | if (UDF_SB_LVIDBH(sb)) { | 210 | DQUOT_FREE_BLOCK(inode, 1); |
| 192 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = | 211 | udf_add_free_space(sbi, sbi->s_partition, 1); |
| 193 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + 1); | ||
| 194 | } | 212 | } |
| 195 | } | 213 | } |
| 196 | } | 214 | mark_buffer_dirty(bh); |
| 197 | mark_buffer_dirty(bh); | 215 | if (overflow) { |
| 198 | if (overflow) { | 216 | block += count; |
| 199 | block += count; | 217 | count = overflow; |
| 200 | count = overflow; | 218 | } |
| 201 | goto do_more; | 219 | } while (overflow); |
| 202 | } | 220 | |
| 203 | error_return: | 221 | error_return: |
| 204 | sb->s_dirt = 1; | 222 | sb->s_dirt = 1; |
| 205 | if (UDF_SB_LVIDBH(sb)) | 223 | if (sbi->s_lvid_bh) |
| 206 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 224 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 207 | mutex_unlock(&sbi->s_alloc_mutex); | 225 | mutex_unlock(&sbi->s_alloc_mutex); |
| 208 | return; | ||
| 209 | } | 226 | } |
| 210 | 227 | ||
| 211 | static int udf_bitmap_prealloc_blocks(struct super_block *sb, | 228 | static int udf_bitmap_prealloc_blocks(struct super_block *sb, |
| @@ -219,53 +236,50 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb, | |||
| 219 | int bit, block, block_group, group_start; | 236 | int bit, block, block_group, group_start; |
| 220 | int nr_groups, bitmap_nr; | 237 | int nr_groups, bitmap_nr; |
| 221 | struct buffer_head *bh; | 238 | struct buffer_head *bh; |
| 239 | __u32 part_len; | ||
| 222 | 240 | ||
| 223 | mutex_lock(&sbi->s_alloc_mutex); | 241 | mutex_lock(&sbi->s_alloc_mutex); |
| 224 | if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition)) | 242 | part_len = sbi->s_partmaps[partition].s_partition_len; |
| 243 | if (first_block < 0 || first_block >= part_len) | ||
| 225 | goto out; | 244 | goto out; |
| 226 | 245 | ||
| 227 | if (first_block + block_count > UDF_SB_PARTLEN(sb, partition)) | 246 | if (first_block + block_count > part_len) |
| 228 | block_count = UDF_SB_PARTLEN(sb, partition) - first_block; | 247 | block_count = part_len - first_block; |
| 229 | 248 | ||
| 230 | repeat: | 249 | do { |
| 231 | nr_groups = (UDF_SB_PARTLEN(sb, partition) + | 250 | nr_groups = udf_compute_nr_groups(sb, partition); |
| 232 | (sizeof(struct spaceBitmapDesc) << 3) + | 251 | block = first_block + (sizeof(struct spaceBitmapDesc) << 3); |
| 233 | (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8); | 252 | block_group = block >> (sb->s_blocksize_bits + 3); |
| 234 | block = first_block + (sizeof(struct spaceBitmapDesc) << 3); | 253 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
| 235 | block_group = block >> (sb->s_blocksize_bits + 3); | ||
| 236 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); | ||
| 237 | 254 | ||
| 238 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); | 255 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 239 | if (bitmap_nr < 0) | 256 | if (bitmap_nr < 0) |
| 240 | goto out; | 257 | goto out; |
| 241 | bh = bitmap->s_block_bitmap[bitmap_nr]; | 258 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
| 242 | 259 | ||
| 243 | bit = block % (sb->s_blocksize << 3); | 260 | bit = block % (sb->s_blocksize << 3); |
| 244 | 261 | ||
| 245 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { | 262 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { |
| 246 | if (!udf_test_bit(bit, bh->b_data)) { | 263 | if (!udf_test_bit(bit, bh->b_data)) |
| 247 | goto out; | 264 | goto out; |
| 248 | } else if (DQUOT_PREALLOC_BLOCK(inode, 1)) { | 265 | else if (DQUOT_PREALLOC_BLOCK(inode, 1)) |
| 249 | goto out; | 266 | goto out; |
| 250 | } else if (!udf_clear_bit(bit, bh->b_data)) { | 267 | else if (!udf_clear_bit(bit, bh->b_data)) { |
| 251 | udf_debug("bit already cleared for block %d\n", bit); | 268 | udf_debug("bit already cleared for block %d\n", bit); |
| 252 | DQUOT_FREE_BLOCK(inode, 1); | 269 | DQUOT_FREE_BLOCK(inode, 1); |
| 253 | goto out; | 270 | goto out; |
| 271 | } | ||
| 272 | block_count--; | ||
| 273 | alloc_count++; | ||
| 274 | bit++; | ||
| 275 | block++; | ||
| 254 | } | 276 | } |
| 255 | block_count--; | 277 | mark_buffer_dirty(bh); |
| 256 | alloc_count++; | 278 | } while (block_count > 0); |
| 257 | bit++; | 279 | |
| 258 | block++; | ||
| 259 | } | ||
| 260 | mark_buffer_dirty(bh); | ||
| 261 | if (block_count > 0) | ||
| 262 | goto repeat; | ||
| 263 | out: | 280 | out: |
| 264 | if (UDF_SB_LVIDBH(sb)) { | 281 | if (udf_add_free_space(sbi, partition, -alloc_count)) |
| 265 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 282 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 266 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count); | ||
| 267 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 268 | } | ||
| 269 | sb->s_dirt = 1; | 283 | sb->s_dirt = 1; |
| 270 | mutex_unlock(&sbi->s_alloc_mutex); | 284 | mutex_unlock(&sbi->s_alloc_mutex); |
| 271 | return alloc_count; | 285 | return alloc_count; |
| @@ -287,7 +301,7 @@ static int udf_bitmap_new_block(struct super_block *sb, | |||
| 287 | mutex_lock(&sbi->s_alloc_mutex); | 301 | mutex_lock(&sbi->s_alloc_mutex); |
| 288 | 302 | ||
| 289 | repeat: | 303 | repeat: |
| 290 | if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition)) | 304 | if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) |
| 291 | goal = 0; | 305 | goal = 0; |
| 292 | 306 | ||
| 293 | nr_groups = bitmap->s_nr_groups; | 307 | nr_groups = bitmap->s_nr_groups; |
| @@ -312,14 +326,16 @@ repeat: | |||
| 312 | if (bit < end_goal) | 326 | if (bit < end_goal) |
| 313 | goto got_block; | 327 | goto got_block; |
| 314 | 328 | ||
| 315 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); | 329 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, |
| 330 | sb->s_blocksize - ((bit + 7) >> 3)); | ||
| 316 | newbit = (ptr - ((char *)bh->b_data)) << 3; | 331 | newbit = (ptr - ((char *)bh->b_data)) << 3; |
| 317 | if (newbit < sb->s_blocksize << 3) { | 332 | if (newbit < sb->s_blocksize << 3) { |
| 318 | bit = newbit; | 333 | bit = newbit; |
| 319 | goto search_back; | 334 | goto search_back; |
| 320 | } | 335 | } |
| 321 | 336 | ||
| 322 | newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); | 337 | newbit = udf_find_next_one_bit(bh->b_data, |
| 338 | sb->s_blocksize << 3, bit); | ||
| 323 | if (newbit < sb->s_blocksize << 3) { | 339 | if (newbit < sb->s_blocksize << 3) { |
| 324 | bit = newbit; | 340 | bit = newbit; |
| 325 | goto got_block; | 341 | goto got_block; |
| @@ -358,15 +374,20 @@ repeat: | |||
| 358 | if (bit < sb->s_blocksize << 3) | 374 | if (bit < sb->s_blocksize << 3) |
| 359 | goto search_back; | 375 | goto search_back; |
| 360 | else | 376 | else |
| 361 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); | 377 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, |
| 378 | group_start << 3); | ||
| 362 | if (bit >= sb->s_blocksize << 3) { | 379 | if (bit >= sb->s_blocksize << 3) { |
| 363 | mutex_unlock(&sbi->s_alloc_mutex); | 380 | mutex_unlock(&sbi->s_alloc_mutex); |
| 364 | return 0; | 381 | return 0; |
| 365 | } | 382 | } |
| 366 | 383 | ||
| 367 | search_back: | 384 | search_back: |
| 368 | for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--) | 385 | i = 0; |
| 369 | ; /* empty loop */ | 386 | while (i < 7 && bit > (group_start << 3) && |
| 387 | udf_test_bit(bit - 1, bh->b_data)) { | ||
| 388 | ++i; | ||
| 389 | --bit; | ||
| 390 | } | ||
| 370 | 391 | ||
| 371 | got_block: | 392 | got_block: |
| 372 | 393 | ||
| @@ -389,11 +410,8 @@ got_block: | |||
| 389 | 410 | ||
| 390 | mark_buffer_dirty(bh); | 411 | mark_buffer_dirty(bh); |
| 391 | 412 | ||
| 392 | if (UDF_SB_LVIDBH(sb)) { | 413 | if (udf_add_free_space(sbi, partition, -1)) |
| 393 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 414 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 394 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1); | ||
| 395 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 396 | } | ||
| 397 | sb->s_dirt = 1; | 415 | sb->s_dirt = 1; |
| 398 | mutex_unlock(&sbi->s_alloc_mutex); | 416 | mutex_unlock(&sbi->s_alloc_mutex); |
| 399 | *err = 0; | 417 | *err = 0; |
| @@ -418,56 +436,70 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
| 418 | struct extent_position oepos, epos; | 436 | struct extent_position oepos, epos; |
| 419 | int8_t etype; | 437 | int8_t etype; |
| 420 | int i; | 438 | int i; |
| 439 | struct udf_inode_info *iinfo; | ||
| 421 | 440 | ||
| 422 | mutex_lock(&sbi->s_alloc_mutex); | 441 | mutex_lock(&sbi->s_alloc_mutex); |
| 423 | if (bloc.logicalBlockNum < 0 || | 442 | if (bloc.logicalBlockNum < 0 || |
| 424 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { | 443 | (bloc.logicalBlockNum + count) > |
| 444 | sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | ||
| 425 | udf_debug("%d < %d || %d + %d > %d\n", | 445 | udf_debug("%d < %d || %d + %d > %d\n", |
| 426 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 446 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
| 427 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); | 447 | sbi->s_partmaps[bloc.partitionReferenceNum]. |
| 448 | s_partition_len); | ||
| 428 | goto error_return; | 449 | goto error_return; |
| 429 | } | 450 | } |
| 430 | 451 | ||
| 431 | /* We do this up front - There are some error conditions that could occure, | 452 | iinfo = UDF_I(table); |
| 432 | but.. oh well */ | 453 | /* We do this up front - There are some error conditions that |
| 454 | could occure, but.. oh well */ | ||
| 433 | if (inode) | 455 | if (inode) |
| 434 | DQUOT_FREE_BLOCK(inode, count); | 456 | DQUOT_FREE_BLOCK(inode, count); |
| 435 | if (UDF_SB_LVIDBH(sb)) { | 457 | if (udf_add_free_space(sbi, sbi->s_partition, count)) |
| 436 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = | 458 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 437 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + count); | ||
| 438 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 439 | } | ||
| 440 | 459 | ||
| 441 | start = bloc.logicalBlockNum + offset; | 460 | start = bloc.logicalBlockNum + offset; |
| 442 | end = bloc.logicalBlockNum + offset + count - 1; | 461 | end = bloc.logicalBlockNum + offset + count - 1; |
| 443 | 462 | ||
| 444 | epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry); | 463 | epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry); |
| 445 | elen = 0; | 464 | elen = 0; |
| 446 | epos.block = oepos.block = UDF_I_LOCATION(table); | 465 | epos.block = oepos.block = iinfo->i_location; |
| 447 | epos.bh = oepos.bh = NULL; | 466 | epos.bh = oepos.bh = NULL; |
| 448 | 467 | ||
| 449 | while (count && | 468 | while (count && |
| 450 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { | 469 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
| 451 | if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) { | 470 | if (((eloc.logicalBlockNum + |
| 452 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { | 471 | (elen >> sb->s_blocksize_bits)) == start)) { |
| 453 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 472 | if ((0x3FFFFFFF - elen) < |
| 454 | start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 473 | (count << sb->s_blocksize_bits)) { |
| 455 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); | 474 | uint32_t tmp = ((0x3FFFFFFF - elen) >> |
| 475 | sb->s_blocksize_bits); | ||
| 476 | count -= tmp; | ||
| 477 | start += tmp; | ||
| 478 | elen = (etype << 30) | | ||
| 479 | (0x40000000 - sb->s_blocksize); | ||
| 456 | } else { | 480 | } else { |
| 457 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); | 481 | elen = (etype << 30) | |
| 482 | (elen + | ||
| 483 | (count << sb->s_blocksize_bits)); | ||
| 458 | start += count; | 484 | start += count; |
| 459 | count = 0; | 485 | count = 0; |
| 460 | } | 486 | } |
| 461 | udf_write_aext(table, &oepos, eloc, elen, 1); | 487 | udf_write_aext(table, &oepos, eloc, elen, 1); |
| 462 | } else if (eloc.logicalBlockNum == (end + 1)) { | 488 | } else if (eloc.logicalBlockNum == (end + 1)) { |
| 463 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { | 489 | if ((0x3FFFFFFF - elen) < |
| 464 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 490 | (count << sb->s_blocksize_bits)) { |
| 465 | end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 491 | uint32_t tmp = ((0x3FFFFFFF - elen) >> |
| 466 | eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 492 | sb->s_blocksize_bits); |
| 467 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); | 493 | count -= tmp; |
| 494 | end -= tmp; | ||
| 495 | eloc.logicalBlockNum -= tmp; | ||
| 496 | elen = (etype << 30) | | ||
| 497 | (0x40000000 - sb->s_blocksize); | ||
| 468 | } else { | 498 | } else { |
| 469 | eloc.logicalBlockNum = start; | 499 | eloc.logicalBlockNum = start; |
| 470 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); | 500 | elen = (etype << 30) | |
| 501 | (elen + | ||
| 502 | (count << sb->s_blocksize_bits)); | ||
| 471 | end -= count; | 503 | end -= count; |
| 472 | count = 0; | 504 | count = 0; |
| 473 | } | 505 | } |
| @@ -488,9 +520,9 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
| 488 | 520 | ||
| 489 | if (count) { | 521 | if (count) { |
| 490 | /* | 522 | /* |
| 491 | * NOTE: we CANNOT use udf_add_aext here, as it can try to allocate | 523 | * NOTE: we CANNOT use udf_add_aext here, as it can try to |
| 492 | * a new block, and since we hold the super block lock already | 524 | * allocate a new block, and since we hold the super block |
| 493 | * very bad things would happen :) | 525 | * lock already very bad things would happen :) |
| 494 | * | 526 | * |
| 495 | * We copy the behavior of udf_add_aext, but instead of | 527 | * We copy the behavior of udf_add_aext, but instead of |
| 496 | * trying to allocate a new block close to the existing one, | 528 | * trying to allocate a new block close to the existing one, |
| @@ -509,11 +541,11 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
| 509 | elen = EXT_RECORDED_ALLOCATED | | 541 | elen = EXT_RECORDED_ALLOCATED | |
| 510 | (count << sb->s_blocksize_bits); | 542 | (count << sb->s_blocksize_bits); |
| 511 | 543 | ||
| 512 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) { | 544 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 513 | adsize = sizeof(short_ad); | 545 | adsize = sizeof(short_ad); |
| 514 | } else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) { | 546 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 515 | adsize = sizeof(long_ad); | 547 | adsize = sizeof(long_ad); |
| 516 | } else { | 548 | else { |
| 517 | brelse(oepos.bh); | 549 | brelse(oepos.bh); |
| 518 | brelse(epos.bh); | 550 | brelse(epos.bh); |
| 519 | goto error_return; | 551 | goto error_return; |
| @@ -531,56 +563,70 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
| 531 | eloc.logicalBlockNum++; | 563 | eloc.logicalBlockNum++; |
| 532 | elen -= sb->s_blocksize; | 564 | elen -= sb->s_blocksize; |
| 533 | 565 | ||
| 534 | if (!(epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, epos.block, 0)))) { | 566 | epos.bh = udf_tread(sb, |
| 567 | udf_get_lb_pblock(sb, epos.block, 0)); | ||
| 568 | if (!epos.bh) { | ||
| 535 | brelse(oepos.bh); | 569 | brelse(oepos.bh); |
| 536 | goto error_return; | 570 | goto error_return; |
| 537 | } | 571 | } |
| 538 | aed = (struct allocExtDesc *)(epos.bh->b_data); | 572 | aed = (struct allocExtDesc *)(epos.bh->b_data); |
| 539 | aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); | 573 | aed->previousAllocExtLocation = |
| 574 | cpu_to_le32(oepos.block.logicalBlockNum); | ||
| 540 | if (epos.offset + adsize > sb->s_blocksize) { | 575 | if (epos.offset + adsize > sb->s_blocksize) { |
| 541 | loffset = epos.offset; | 576 | loffset = epos.offset; |
| 542 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 577 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
| 543 | sptr = UDF_I_DATA(table) + epos.offset - adsize; | 578 | sptr = iinfo->i_ext.i_data + epos.offset |
| 544 | dptr = epos.bh->b_data + sizeof(struct allocExtDesc); | 579 | - adsize; |
| 580 | dptr = epos.bh->b_data + | ||
| 581 | sizeof(struct allocExtDesc); | ||
| 545 | memcpy(dptr, sptr, adsize); | 582 | memcpy(dptr, sptr, adsize); |
| 546 | epos.offset = sizeof(struct allocExtDesc) + adsize; | 583 | epos.offset = sizeof(struct allocExtDesc) + |
| 584 | adsize; | ||
| 547 | } else { | 585 | } else { |
| 548 | loffset = epos.offset + adsize; | 586 | loffset = epos.offset + adsize; |
| 549 | aed->lengthAllocDescs = cpu_to_le32(0); | 587 | aed->lengthAllocDescs = cpu_to_le32(0); |
| 550 | if (oepos.bh) { | 588 | if (oepos.bh) { |
| 551 | sptr = oepos.bh->b_data + epos.offset; | 589 | sptr = oepos.bh->b_data + epos.offset; |
| 552 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 590 | aed = (struct allocExtDesc *) |
| 591 | oepos.bh->b_data; | ||
| 553 | aed->lengthAllocDescs = | 592 | aed->lengthAllocDescs = |
| 554 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 593 | cpu_to_le32(le32_to_cpu( |
| 594 | aed->lengthAllocDescs) + | ||
| 595 | adsize); | ||
| 555 | } else { | 596 | } else { |
| 556 | sptr = UDF_I_DATA(table) + epos.offset; | 597 | sptr = iinfo->i_ext.i_data + |
| 557 | UDF_I_LENALLOC(table) += adsize; | 598 | epos.offset; |
| 599 | iinfo->i_lenAlloc += adsize; | ||
| 558 | mark_inode_dirty(table); | 600 | mark_inode_dirty(table); |
| 559 | } | 601 | } |
| 560 | epos.offset = sizeof(struct allocExtDesc); | 602 | epos.offset = sizeof(struct allocExtDesc); |
| 561 | } | 603 | } |
| 562 | if (UDF_SB_UDFREV(sb) >= 0x0200) | 604 | if (sbi->s_udfrev >= 0x0200) |
| 563 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, | 605 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, |
| 564 | epos.block.logicalBlockNum, sizeof(tag)); | 606 | 3, 1, epos.block.logicalBlockNum, |
| 607 | sizeof(tag)); | ||
| 565 | else | 608 | else |
| 566 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, | 609 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, |
| 567 | epos.block.logicalBlockNum, sizeof(tag)); | 610 | 2, 1, epos.block.logicalBlockNum, |
| 568 | 611 | sizeof(tag)); | |
| 569 | switch (UDF_I_ALLOCTYPE(table)) { | 612 | |
| 570 | case ICBTAG_FLAG_AD_SHORT: | 613 | switch (iinfo->i_alloc_type) { |
| 571 | sad = (short_ad *)sptr; | 614 | case ICBTAG_FLAG_AD_SHORT: |
| 572 | sad->extLength = cpu_to_le32( | 615 | sad = (short_ad *)sptr; |
| 573 | EXT_NEXT_EXTENT_ALLOCDECS | | 616 | sad->extLength = cpu_to_le32( |
| 574 | sb->s_blocksize); | 617 | EXT_NEXT_EXTENT_ALLOCDECS | |
| 575 | sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); | 618 | sb->s_blocksize); |
| 576 | break; | 619 | sad->extPosition = |
| 577 | case ICBTAG_FLAG_AD_LONG: | 620 | cpu_to_le32(epos.block.logicalBlockNum); |
| 578 | lad = (long_ad *)sptr; | 621 | break; |
| 579 | lad->extLength = cpu_to_le32( | 622 | case ICBTAG_FLAG_AD_LONG: |
| 580 | EXT_NEXT_EXTENT_ALLOCDECS | | 623 | lad = (long_ad *)sptr; |
| 581 | sb->s_blocksize); | 624 | lad->extLength = cpu_to_le32( |
| 582 | lad->extLocation = cpu_to_lelb(epos.block); | 625 | EXT_NEXT_EXTENT_ALLOCDECS | |
| 583 | break; | 626 | sb->s_blocksize); |
| 627 | lad->extLocation = | ||
| 628 | cpu_to_lelb(epos.block); | ||
| 629 | break; | ||
| 584 | } | 630 | } |
| 585 | if (oepos.bh) { | 631 | if (oepos.bh) { |
| 586 | udf_update_tag(oepos.bh->b_data, loffset); | 632 | udf_update_tag(oepos.bh->b_data, loffset); |
| @@ -590,16 +636,18 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
| 590 | } | 636 | } |
| 591 | } | 637 | } |
| 592 | 638 | ||
| 593 | if (elen) { /* It's possible that stealing the block emptied the extent */ | 639 | /* It's possible that stealing the block emptied the extent */ |
| 640 | if (elen) { | ||
| 594 | udf_write_aext(table, &epos, eloc, elen, 1); | 641 | udf_write_aext(table, &epos, eloc, elen, 1); |
| 595 | 642 | ||
| 596 | if (!epos.bh) { | 643 | if (!epos.bh) { |
| 597 | UDF_I_LENALLOC(table) += adsize; | 644 | iinfo->i_lenAlloc += adsize; |
| 598 | mark_inode_dirty(table); | 645 | mark_inode_dirty(table); |
| 599 | } else { | 646 | } else { |
| 600 | aed = (struct allocExtDesc *)epos.bh->b_data; | 647 | aed = (struct allocExtDesc *)epos.bh->b_data; |
| 601 | aed->lengthAllocDescs = | 648 | aed->lengthAllocDescs = |
| 602 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 649 | cpu_to_le32(le32_to_cpu( |
| 650 | aed->lengthAllocDescs) + adsize); | ||
| 603 | udf_update_tag(epos.bh->b_data, epos.offset); | 651 | udf_update_tag(epos.bh->b_data, epos.offset); |
| 604 | mark_buffer_dirty(epos.bh); | 652 | mark_buffer_dirty(epos.bh); |
| 605 | } | 653 | } |
| @@ -626,20 +674,23 @@ static int udf_table_prealloc_blocks(struct super_block *sb, | |||
| 626 | kernel_lb_addr eloc; | 674 | kernel_lb_addr eloc; |
| 627 | struct extent_position epos; | 675 | struct extent_position epos; |
| 628 | int8_t etype = -1; | 676 | int8_t etype = -1; |
| 677 | struct udf_inode_info *iinfo; | ||
| 629 | 678 | ||
| 630 | if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition)) | 679 | if (first_block < 0 || |
| 680 | first_block >= sbi->s_partmaps[partition].s_partition_len) | ||
| 631 | return 0; | 681 | return 0; |
| 632 | 682 | ||
| 633 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) | 683 | iinfo = UDF_I(table); |
| 684 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) | ||
| 634 | adsize = sizeof(short_ad); | 685 | adsize = sizeof(short_ad); |
| 635 | else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) | 686 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 636 | adsize = sizeof(long_ad); | 687 | adsize = sizeof(long_ad); |
| 637 | else | 688 | else |
| 638 | return 0; | 689 | return 0; |
| 639 | 690 | ||
| 640 | mutex_lock(&sbi->s_alloc_mutex); | 691 | mutex_lock(&sbi->s_alloc_mutex); |
| 641 | epos.offset = sizeof(struct unallocSpaceEntry); | 692 | epos.offset = sizeof(struct unallocSpaceEntry); |
| 642 | epos.block = UDF_I_LOCATION(table); | 693 | epos.block = iinfo->i_location; |
| 643 | epos.bh = NULL; | 694 | epos.bh = NULL; |
| 644 | eloc.logicalBlockNum = 0xFFFFFFFF; | 695 | eloc.logicalBlockNum = 0xFFFFFFFF; |
| 645 | 696 | ||
| @@ -654,26 +705,26 @@ static int udf_table_prealloc_blocks(struct super_block *sb, | |||
| 654 | epos.offset -= adsize; | 705 | epos.offset -= adsize; |
| 655 | 706 | ||
| 656 | alloc_count = (elen >> sb->s_blocksize_bits); | 707 | alloc_count = (elen >> sb->s_blocksize_bits); |
| 657 | if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) { | 708 | if (inode && DQUOT_PREALLOC_BLOCK(inode, |
| 709 | alloc_count > block_count ? block_count : alloc_count)) | ||
| 658 | alloc_count = 0; | 710 | alloc_count = 0; |
| 659 | } else if (alloc_count > block_count) { | 711 | else if (alloc_count > block_count) { |
| 660 | alloc_count = block_count; | 712 | alloc_count = block_count; |
| 661 | eloc.logicalBlockNum += alloc_count; | 713 | eloc.logicalBlockNum += alloc_count; |
| 662 | elen -= (alloc_count << sb->s_blocksize_bits); | 714 | elen -= (alloc_count << sb->s_blocksize_bits); |
| 663 | udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); | 715 | udf_write_aext(table, &epos, eloc, |
| 664 | } else { | 716 | (etype << 30) | elen, 1); |
| 665 | udf_delete_aext(table, epos, eloc, (etype << 30) | elen); | 717 | } else |
| 666 | } | 718 | udf_delete_aext(table, epos, eloc, |
| 719 | (etype << 30) | elen); | ||
| 667 | } else { | 720 | } else { |
| 668 | alloc_count = 0; | 721 | alloc_count = 0; |
| 669 | } | 722 | } |
| 670 | 723 | ||
| 671 | brelse(epos.bh); | 724 | brelse(epos.bh); |
| 672 | 725 | ||
| 673 | if (alloc_count && UDF_SB_LVIDBH(sb)) { | 726 | if (alloc_count && udf_add_free_space(sbi, partition, -alloc_count)) { |
| 674 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 727 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 675 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count); | ||
| 676 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 677 | sb->s_dirt = 1; | 728 | sb->s_dirt = 1; |
| 678 | } | 729 | } |
| 679 | mutex_unlock(&sbi->s_alloc_mutex); | 730 | mutex_unlock(&sbi->s_alloc_mutex); |
| @@ -692,33 +743,35 @@ static int udf_table_new_block(struct super_block *sb, | |||
| 692 | kernel_lb_addr eloc, uninitialized_var(goal_eloc); | 743 | kernel_lb_addr eloc, uninitialized_var(goal_eloc); |
| 693 | struct extent_position epos, goal_epos; | 744 | struct extent_position epos, goal_epos; |
| 694 | int8_t etype; | 745 | int8_t etype; |
| 746 | struct udf_inode_info *iinfo = UDF_I(table); | ||
| 695 | 747 | ||
| 696 | *err = -ENOSPC; | 748 | *err = -ENOSPC; |
| 697 | 749 | ||
| 698 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) | 750 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 699 | adsize = sizeof(short_ad); | 751 | adsize = sizeof(short_ad); |
| 700 | else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) | 752 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 701 | adsize = sizeof(long_ad); | 753 | adsize = sizeof(long_ad); |
| 702 | else | 754 | else |
| 703 | return newblock; | 755 | return newblock; |
| 704 | 756 | ||
| 705 | mutex_lock(&sbi->s_alloc_mutex); | 757 | mutex_lock(&sbi->s_alloc_mutex); |
| 706 | if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition)) | 758 | if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) |
| 707 | goal = 0; | 759 | goal = 0; |
| 708 | 760 | ||
| 709 | /* We search for the closest matching block to goal. If we find a exact hit, | 761 | /* We search for the closest matching block to goal. If we find |
| 710 | we stop. Otherwise we keep going till we run out of extents. | 762 | a exact hit, we stop. Otherwise we keep going till we run out |
| 711 | We store the buffer_head, bloc, and extoffset of the current closest | 763 | of extents. We store the buffer_head, bloc, and extoffset |
| 712 | match and use that when we are done. | 764 | of the current closest match and use that when we are done. |
| 713 | */ | 765 | */ |
| 714 | epos.offset = sizeof(struct unallocSpaceEntry); | 766 | epos.offset = sizeof(struct unallocSpaceEntry); |
| 715 | epos.block = UDF_I_LOCATION(table); | 767 | epos.block = iinfo->i_location; |
| 716 | epos.bh = goal_epos.bh = NULL; | 768 | epos.bh = goal_epos.bh = NULL; |
| 717 | 769 | ||
| 718 | while (spread && | 770 | while (spread && |
| 719 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { | 771 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
| 720 | if (goal >= eloc.logicalBlockNum) { | 772 | if (goal >= eloc.logicalBlockNum) { |
| 721 | if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) | 773 | if (goal < eloc.logicalBlockNum + |
| 774 | (elen >> sb->s_blocksize_bits)) | ||
| 722 | nspread = 0; | 775 | nspread = 0; |
| 723 | else | 776 | else |
| 724 | nspread = goal - eloc.logicalBlockNum - | 777 | nspread = goal - eloc.logicalBlockNum - |
| @@ -771,11 +824,8 @@ static int udf_table_new_block(struct super_block *sb, | |||
| 771 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); | 824 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); |
| 772 | brelse(goal_epos.bh); | 825 | brelse(goal_epos.bh); |
| 773 | 826 | ||
| 774 | if (UDF_SB_LVIDBH(sb)) { | 827 | if (udf_add_free_space(sbi, partition, -1)) |
| 775 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 828 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 776 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1); | ||
| 777 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 778 | } | ||
| 779 | 829 | ||
| 780 | sb->s_dirt = 1; | 830 | sb->s_dirt = 1; |
| 781 | mutex_unlock(&sbi->s_alloc_mutex); | 831 | mutex_unlock(&sbi->s_alloc_mutex); |
| @@ -789,22 +839,23 @@ inline void udf_free_blocks(struct super_block *sb, | |||
| 789 | uint32_t count) | 839 | uint32_t count) |
| 790 | { | 840 | { |
| 791 | uint16_t partition = bloc.partitionReferenceNum; | 841 | uint16_t partition = bloc.partitionReferenceNum; |
| 842 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; | ||
| 792 | 843 | ||
| 793 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { | 844 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { |
| 794 | return udf_bitmap_free_blocks(sb, inode, | 845 | return udf_bitmap_free_blocks(sb, inode, |
| 795 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 846 | map->s_uspace.s_bitmap, |
| 796 | bloc, offset, count); | 847 | bloc, offset, count); |
| 797 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { | 848 | } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { |
| 798 | return udf_table_free_blocks(sb, inode, | 849 | return udf_table_free_blocks(sb, inode, |
| 799 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 850 | map->s_uspace.s_table, |
| 800 | bloc, offset, count); | 851 | bloc, offset, count); |
| 801 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { | 852 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { |
| 802 | return udf_bitmap_free_blocks(sb, inode, | 853 | return udf_bitmap_free_blocks(sb, inode, |
| 803 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 854 | map->s_fspace.s_bitmap, |
| 804 | bloc, offset, count); | 855 | bloc, offset, count); |
| 805 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { | 856 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { |
| 806 | return udf_table_free_blocks(sb, inode, | 857 | return udf_table_free_blocks(sb, inode, |
| 807 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 858 | map->s_fspace.s_table, |
| 808 | bloc, offset, count); | 859 | bloc, offset, count); |
| 809 | } else { | 860 | } else { |
| 810 | return; | 861 | return; |
| @@ -816,51 +867,55 @@ inline int udf_prealloc_blocks(struct super_block *sb, | |||
| 816 | uint16_t partition, uint32_t first_block, | 867 | uint16_t partition, uint32_t first_block, |
| 817 | uint32_t block_count) | 868 | uint32_t block_count) |
| 818 | { | 869 | { |
| 819 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { | 870 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
| 871 | |||
| 872 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) | ||
| 820 | return udf_bitmap_prealloc_blocks(sb, inode, | 873 | return udf_bitmap_prealloc_blocks(sb, inode, |
| 821 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 874 | map->s_uspace.s_bitmap, |
| 822 | partition, first_block, block_count); | 875 | partition, first_block, |
| 823 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { | 876 | block_count); |
| 877 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) | ||
| 824 | return udf_table_prealloc_blocks(sb, inode, | 878 | return udf_table_prealloc_blocks(sb, inode, |
| 825 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 879 | map->s_uspace.s_table, |
| 826 | partition, first_block, block_count); | 880 | partition, first_block, |
| 827 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { | 881 | block_count); |
| 882 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) | ||
| 828 | return udf_bitmap_prealloc_blocks(sb, inode, | 883 | return udf_bitmap_prealloc_blocks(sb, inode, |
| 829 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 884 | map->s_fspace.s_bitmap, |
| 830 | partition, first_block, block_count); | 885 | partition, first_block, |
| 831 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { | 886 | block_count); |
| 887 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) | ||
| 832 | return udf_table_prealloc_blocks(sb, inode, | 888 | return udf_table_prealloc_blocks(sb, inode, |
| 833 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 889 | map->s_fspace.s_table, |
| 834 | partition, first_block, block_count); | 890 | partition, first_block, |
| 835 | } else { | 891 | block_count); |
| 892 | else | ||
| 836 | return 0; | 893 | return 0; |
| 837 | } | ||
| 838 | } | 894 | } |
| 839 | 895 | ||
| 840 | inline int udf_new_block(struct super_block *sb, | 896 | inline int udf_new_block(struct super_block *sb, |
| 841 | struct inode *inode, | 897 | struct inode *inode, |
| 842 | uint16_t partition, uint32_t goal, int *err) | 898 | uint16_t partition, uint32_t goal, int *err) |
| 843 | { | 899 | { |
| 844 | int ret; | 900 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
| 845 | 901 | ||
| 846 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { | 902 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
| 847 | ret = udf_bitmap_new_block(sb, inode, | 903 | return udf_bitmap_new_block(sb, inode, |
| 848 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 904 | map->s_uspace.s_bitmap, |
| 849 | partition, goal, err); | 905 | partition, goal, err); |
| 850 | return ret; | 906 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
| 851 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { | ||
| 852 | return udf_table_new_block(sb, inode, | 907 | return udf_table_new_block(sb, inode, |
| 853 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 908 | map->s_uspace.s_table, |
| 854 | partition, goal, err); | 909 | partition, goal, err); |
| 855 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { | 910 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
| 856 | return udf_bitmap_new_block(sb, inode, | 911 | return udf_bitmap_new_block(sb, inode, |
| 857 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 912 | map->s_fspace.s_bitmap, |
| 858 | partition, goal, err); | 913 | partition, goal, err); |
| 859 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { | 914 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
| 860 | return udf_table_new_block(sb, inode, | 915 | return udf_table_new_block(sb, inode, |
| 861 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 916 | map->s_fspace.s_table, |
| 862 | partition, goal, err); | 917 | partition, goal, err); |
| 863 | } else { | 918 | else { |
| 864 | *err = -EIO; | 919 | *err = -EIO; |
| 865 | return 0; | 920 | return 0; |
| 866 | } | 921 | } |
diff --git a/fs/udf/crc.c b/fs/udf/crc.c index 85aaee5fab26..b1661296e786 100644 --- a/fs/udf/crc.c +++ b/fs/udf/crc.c | |||
| @@ -79,7 +79,7 @@ static uint16_t crc_table[256] = { | |||
| 79 | * July 21, 1997 - Andrew E. Mileski | 79 | * July 21, 1997 - Andrew E. Mileski |
| 80 | * Adapted from OSTA-UDF(tm) 1.50 standard. | 80 | * Adapted from OSTA-UDF(tm) 1.50 standard. |
| 81 | */ | 81 | */ |
| 82 | uint16_t udf_crc(uint8_t * data, uint32_t size, uint16_t crc) | 82 | uint16_t udf_crc(uint8_t *data, uint32_t size, uint16_t crc) |
| 83 | { | 83 | { |
| 84 | while (size--) | 84 | while (size--) |
| 85 | crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); | 85 | crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); |
diff --git a/fs/udf/dir.c b/fs/udf/dir.c index 9e3b9f97ddbc..4b44e23caa12 100644 --- a/fs/udf/dir.c +++ b/fs/udf/dir.c | |||
| @@ -36,68 +36,8 @@ | |||
| 36 | #include "udf_i.h" | 36 | #include "udf_i.h" |
| 37 | #include "udf_sb.h" | 37 | #include "udf_sb.h" |
| 38 | 38 | ||
| 39 | /* Prototypes for file operations */ | 39 | static int do_udf_readdir(struct inode *dir, struct file *filp, |
| 40 | static int udf_readdir(struct file *, void *, filldir_t); | 40 | filldir_t filldir, void *dirent) |
| 41 | static int do_udf_readdir(struct inode *, struct file *, filldir_t, void *); | ||
| 42 | |||
| 43 | /* readdir and lookup functions */ | ||
| 44 | |||
| 45 | const struct file_operations udf_dir_operations = { | ||
| 46 | .read = generic_read_dir, | ||
| 47 | .readdir = udf_readdir, | ||
| 48 | .ioctl = udf_ioctl, | ||
| 49 | .fsync = udf_fsync_file, | ||
| 50 | }; | ||
| 51 | |||
| 52 | /* | ||
| 53 | * udf_readdir | ||
| 54 | * | ||
| 55 | * PURPOSE | ||
| 56 | * Read a directory entry. | ||
| 57 | * | ||
| 58 | * DESCRIPTION | ||
| 59 | * Optional - sys_getdents() will return -ENOTDIR if this routine is not | ||
| 60 | * available. | ||
| 61 | * | ||
| 62 | * Refer to sys_getdents() in fs/readdir.c | ||
| 63 | * sys_getdents() -> . | ||
| 64 | * | ||
| 65 | * PRE-CONDITIONS | ||
| 66 | * filp Pointer to directory file. | ||
| 67 | * buf Pointer to directory entry buffer. | ||
| 68 | * filldir Pointer to filldir function. | ||
| 69 | * | ||
| 70 | * POST-CONDITIONS | ||
| 71 | * <return> >=0 on success. | ||
| 72 | * | ||
| 73 | * HISTORY | ||
| 74 | * July 1, 1997 - Andrew E. Mileski | ||
| 75 | * Written, tested, and released. | ||
| 76 | */ | ||
| 77 | |||
| 78 | int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) | ||
| 79 | { | ||
| 80 | struct inode *dir = filp->f_path.dentry->d_inode; | ||
| 81 | int result; | ||
| 82 | |||
| 83 | lock_kernel(); | ||
| 84 | |||
| 85 | if (filp->f_pos == 0) { | ||
| 86 | if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) { | ||
| 87 | unlock_kernel(); | ||
| 88 | return 0; | ||
| 89 | } | ||
| 90 | filp->f_pos++; | ||
| 91 | } | ||
| 92 | |||
| 93 | result = do_udf_readdir(dir, filp, filldir, dirent); | ||
| 94 | unlock_kernel(); | ||
| 95 | return result; | ||
| 96 | } | ||
| 97 | |||
| 98 | static int | ||
| 99 | do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir, | ||
| 100 | void *dirent) | ||
| 101 | { | 41 | { |
| 102 | struct udf_fileident_bh fibh; | 42 | struct udf_fileident_bh fibh; |
| 103 | struct fileIdentDesc *fi = NULL; | 43 | struct fileIdentDesc *fi = NULL; |
| @@ -117,6 +57,7 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir, | |||
| 117 | int i, num; | 57 | int i, num; |
| 118 | unsigned int dt_type; | 58 | unsigned int dt_type; |
| 119 | struct extent_position epos = { NULL, 0, {0, 0} }; | 59 | struct extent_position epos = { NULL, 0, {0, 0} }; |
| 60 | struct udf_inode_info *iinfo; | ||
| 120 | 61 | ||
| 121 | if (nf_pos >= size) | 62 | if (nf_pos >= size) |
| 122 | return 0; | 63 | return 0; |
| @@ -125,15 +66,17 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir, | |||
| 125 | nf_pos = (udf_ext0_offset(dir) >> 2); | 66 | nf_pos = (udf_ext0_offset(dir) >> 2); |
| 126 | 67 | ||
| 127 | fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 68 | fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
| 128 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 69 | iinfo = UDF_I(dir); |
| 70 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { | ||
| 129 | fibh.sbh = fibh.ebh = NULL; | 71 | fibh.sbh = fibh.ebh = NULL; |
| 130 | } else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), | 72 | } else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), |
| 131 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 73 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { |
| 132 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 74 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
| 133 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 75 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
| 134 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 76 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 135 | epos.offset -= sizeof(short_ad); | 77 | epos.offset -= sizeof(short_ad); |
| 136 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 78 | else if (iinfo->i_alloc_type == |
| 79 | ICBTAG_FLAG_AD_LONG) | ||
| 137 | epos.offset -= sizeof(long_ad); | 80 | epos.offset -= sizeof(long_ad); |
| 138 | } else { | 81 | } else { |
| 139 | offset = 0; | 82 | offset = 0; |
| @@ -244,3 +187,57 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir, | |||
| 244 | 187 | ||
| 245 | return 0; | 188 | return 0; |
| 246 | } | 189 | } |
| 190 | |||
| 191 | /* | ||
| 192 | * udf_readdir | ||
| 193 | * | ||
| 194 | * PURPOSE | ||
| 195 | * Read a directory entry. | ||
| 196 | * | ||
| 197 | * DESCRIPTION | ||
| 198 | * Optional - sys_getdents() will return -ENOTDIR if this routine is not | ||
| 199 | * available. | ||
| 200 | * | ||
| 201 | * Refer to sys_getdents() in fs/readdir.c | ||
| 202 | * sys_getdents() -> . | ||
| 203 | * | ||
| 204 | * PRE-CONDITIONS | ||
| 205 | * filp Pointer to directory file. | ||
| 206 | * buf Pointer to directory entry buffer. | ||
| 207 | * filldir Pointer to filldir function. | ||
| 208 | * | ||
| 209 | * POST-CONDITIONS | ||
| 210 | * <return> >=0 on success. | ||
| 211 | * | ||
| 212 | * HISTORY | ||
| 213 | * July 1, 1997 - Andrew E. Mileski | ||
| 214 | * Written, tested, and released. | ||
| 215 | */ | ||
| 216 | |||
| 217 | static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) | ||
| 218 | { | ||
| 219 | struct inode *dir = filp->f_path.dentry->d_inode; | ||
| 220 | int result; | ||
| 221 | |||
| 222 | lock_kernel(); | ||
| 223 | |||
| 224 | if (filp->f_pos == 0) { | ||
| 225 | if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) { | ||
| 226 | unlock_kernel(); | ||
| 227 | return 0; | ||
| 228 | } | ||
| 229 | filp->f_pos++; | ||
| 230 | } | ||
| 231 | |||
| 232 | result = do_udf_readdir(dir, filp, filldir, dirent); | ||
| 233 | unlock_kernel(); | ||
| 234 | return result; | ||
| 235 | } | ||
| 236 | |||
| 237 | /* readdir and lookup functions */ | ||
| 238 | const struct file_operations udf_dir_operations = { | ||
| 239 | .read = generic_read_dir, | ||
| 240 | .readdir = udf_readdir, | ||
| 241 | .ioctl = udf_ioctl, | ||
| 242 | .fsync = udf_fsync_file, | ||
| 243 | }; | ||
diff --git a/fs/udf/directory.c b/fs/udf/directory.c index ff8c08fd7bf5..2820f8fcf4cc 100644 --- a/fs/udf/directory.c +++ b/fs/udf/directory.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/buffer_head.h> | 19 | #include <linux/buffer_head.h> |
| 20 | 20 | ||
| 21 | #if 0 | 21 | #if 0 |
| 22 | static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, | 22 | static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad, |
| 23 | uint8_t ad_size, kernel_lb_addr fe_loc, | 23 | uint8_t ad_size, kernel_lb_addr fe_loc, |
| 24 | int *pos, int *offset, struct buffer_head **bh, | 24 | int *pos, int *offset, struct buffer_head **bh, |
| 25 | int *error) | 25 | int *error) |
| @@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, | |||
| 45 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); | 45 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); |
| 46 | if (!block) | 46 | if (!block) |
| 47 | return NULL; | 47 | return NULL; |
| 48 | if (!(*bh = udf_tread(dir->i_sb, block))) | 48 | *bh = udf_tread(dir->i_sb, block); |
| 49 | if (!*bh) | ||
| 49 | return NULL; | 50 | return NULL; |
| 50 | } else if (*offset > dir->i_sb->s_blocksize) { | 51 | } else if (*offset > dir->i_sb->s_blocksize) { |
| 51 | ad = tmpad; | 52 | ad = tmpad; |
| @@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, | |||
| 57 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); | 58 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); |
| 58 | if (!block) | 59 | if (!block) |
| 59 | return NULL; | 60 | return NULL; |
| 60 | if (!((*bh) = udf_tread(dir->i_sb, block))) | 61 | (*bh) = udf_tread(dir->i_sb, block); |
| 62 | if (!*bh) | ||
| 61 | return NULL; | 63 | return NULL; |
| 62 | 64 | ||
| 63 | memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); | 65 | memcpy((uint8_t *)ad + remainder, (*bh)->b_data, |
| 66 | ad_size - remainder); | ||
| 64 | *offset = ad_size - remainder; | 67 | *offset = ad_size - remainder; |
| 65 | } | 68 | } |
| 66 | 69 | ||
| @@ -68,29 +71,31 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, | |||
| 68 | } | 71 | } |
| 69 | #endif | 72 | #endif |
| 70 | 73 | ||
| 71 | struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | 74 | struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, |
| 72 | struct udf_fileident_bh *fibh, | 75 | struct udf_fileident_bh *fibh, |
| 73 | struct fileIdentDesc *cfi, | 76 | struct fileIdentDesc *cfi, |
| 74 | struct extent_position *epos, | 77 | struct extent_position *epos, |
| 75 | kernel_lb_addr * eloc, uint32_t * elen, | 78 | kernel_lb_addr *eloc, uint32_t *elen, |
| 76 | sector_t * offset) | 79 | sector_t *offset) |
| 77 | { | 80 | { |
| 78 | struct fileIdentDesc *fi; | 81 | struct fileIdentDesc *fi; |
| 79 | int i, num, block; | 82 | int i, num, block; |
| 80 | struct buffer_head *tmp, *bha[16]; | 83 | struct buffer_head *tmp, *bha[16]; |
| 84 | struct udf_inode_info *iinfo = UDF_I(dir); | ||
| 81 | 85 | ||
| 82 | fibh->soffset = fibh->eoffset; | 86 | fibh->soffset = fibh->eoffset; |
| 83 | 87 | ||
| 84 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 88 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 85 | fi = udf_get_fileident(UDF_I_DATA(dir) - | 89 | fi = udf_get_fileident(iinfo->i_ext.i_data - |
| 86 | (UDF_I_EFE(dir) ? | 90 | (iinfo->i_efe ? |
| 87 | sizeof(struct extendedFileEntry) : | 91 | sizeof(struct extendedFileEntry) : |
| 88 | sizeof(struct fileEntry)), | 92 | sizeof(struct fileEntry)), |
| 89 | dir->i_sb->s_blocksize, &(fibh->eoffset)); | 93 | dir->i_sb->s_blocksize, |
| 94 | &(fibh->eoffset)); | ||
| 90 | if (!fi) | 95 | if (!fi) |
| 91 | return NULL; | 96 | return NULL; |
| 92 | 97 | ||
| 93 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); | 98 | *nf_pos += fibh->eoffset - fibh->soffset; |
| 94 | 99 | ||
| 95 | memcpy((uint8_t *)cfi, (uint8_t *)fi, | 100 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
| 96 | sizeof(struct fileIdentDesc)); | 101 | sizeof(struct fileIdentDesc)); |
| @@ -100,6 +105,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
| 100 | 105 | ||
| 101 | if (fibh->eoffset == dir->i_sb->s_blocksize) { | 106 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
| 102 | int lextoffset = epos->offset; | 107 | int lextoffset = epos->offset; |
| 108 | unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits; | ||
| 103 | 109 | ||
| 104 | if (udf_next_aext(dir, epos, eloc, elen, 1) != | 110 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
| 105 | (EXT_RECORDED_ALLOCATED >> 30)) | 111 | (EXT_RECORDED_ALLOCATED >> 30)) |
| @@ -109,24 +115,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
| 109 | 115 | ||
| 110 | (*offset)++; | 116 | (*offset)++; |
| 111 | 117 | ||
| 112 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) | 118 | if ((*offset << blocksize_bits) >= *elen) |
| 113 | *offset = 0; | 119 | *offset = 0; |
| 114 | else | 120 | else |
| 115 | epos->offset = lextoffset; | 121 | epos->offset = lextoffset; |
| 116 | 122 | ||
| 117 | brelse(fibh->sbh); | 123 | brelse(fibh->sbh); |
| 118 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) | 124 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 125 | if (!fibh->sbh) | ||
| 119 | return NULL; | 126 | return NULL; |
| 120 | fibh->soffset = fibh->eoffset = 0; | 127 | fibh->soffset = fibh->eoffset = 0; |
| 121 | 128 | ||
| 122 | if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { | 129 | if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) { |
| 123 | i = 16 >> (dir->i_sb->s_blocksize_bits - 9); | 130 | i = 16 >> (blocksize_bits - 9); |
| 124 | if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) | 131 | if (i + *offset > (*elen >> blocksize_bits)) |
| 125 | i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; | 132 | i = (*elen >> blocksize_bits)-*offset; |
| 126 | for (num = 0; i > 0; i--) { | 133 | for (num = 0; i > 0; i--) { |
| 127 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); | 134 | block = udf_get_lb_pblock(dir->i_sb, *eloc, |
| 135 | *offset + i); | ||
| 128 | tmp = udf_tgetblk(dir->i_sb, block); | 136 | tmp = udf_tgetblk(dir->i_sb, block); |
| 129 | if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) | 137 | if (tmp && !buffer_uptodate(tmp) && |
| 138 | !buffer_locked(tmp)) | ||
| 130 | bha[num++] = tmp; | 139 | bha[num++] = tmp; |
| 131 | else | 140 | else |
| 132 | brelse(tmp); | 141 | brelse(tmp); |
| @@ -148,7 +157,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
| 148 | if (!fi) | 157 | if (!fi) |
| 149 | return NULL; | 158 | return NULL; |
| 150 | 159 | ||
| 151 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); | 160 | *nf_pos += fibh->eoffset - fibh->soffset; |
| 152 | 161 | ||
| 153 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { | 162 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { |
| 154 | memcpy((uint8_t *)cfi, (uint8_t *)fi, | 163 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
| @@ -172,20 +181,23 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
| 172 | fibh->soffset -= dir->i_sb->s_blocksize; | 181 | fibh->soffset -= dir->i_sb->s_blocksize; |
| 173 | fibh->eoffset -= dir->i_sb->s_blocksize; | 182 | fibh->eoffset -= dir->i_sb->s_blocksize; |
| 174 | 183 | ||
| 175 | if (!(fibh->ebh = udf_tread(dir->i_sb, block))) | 184 | fibh->ebh = udf_tread(dir->i_sb, block); |
| 185 | if (!fibh->ebh) | ||
| 176 | return NULL; | 186 | return NULL; |
| 177 | 187 | ||
| 178 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { | 188 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
| 179 | int fi_len; | 189 | int fi_len; |
| 180 | 190 | ||
| 181 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); | 191 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); |
| 182 | memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, | 192 | memcpy((uint8_t *)cfi - fibh->soffset, |
| 193 | fibh->ebh->b_data, | ||
| 183 | sizeof(struct fileIdentDesc) + fibh->soffset); | 194 | sizeof(struct fileIdentDesc) + fibh->soffset); |
| 184 | 195 | ||
| 185 | fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + | 196 | fi_len = (sizeof(struct fileIdentDesc) + |
| 197 | cfi->lengthFileIdent + | ||
| 186 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; | 198 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; |
| 187 | 199 | ||
| 188 | *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); | 200 | *nf_pos += fi_len - (fibh->eoffset - fibh->soffset); |
| 189 | fibh->eoffset = fibh->soffset + fi_len; | 201 | fibh->eoffset = fibh->soffset + fi_len; |
| 190 | } else { | 202 | } else { |
| 191 | memcpy((uint8_t *)cfi, (uint8_t *)fi, | 203 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
| @@ -210,11 +222,10 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) | |||
| 210 | 222 | ||
| 211 | ptr = buffer; | 223 | ptr = buffer; |
| 212 | 224 | ||
| 213 | if ((*offset > 0) && (*offset < bufsize)) { | 225 | if ((*offset > 0) && (*offset < bufsize)) |
| 214 | ptr += *offset; | 226 | ptr += *offset; |
| 215 | } | ||
| 216 | fi = (struct fileIdentDesc *)ptr; | 227 | fi = (struct fileIdentDesc *)ptr; |
| 217 | if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { | 228 | if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) { |
| 218 | udf_debug("0x%x != TAG_IDENT_FID\n", | 229 | udf_debug("0x%x != TAG_IDENT_FID\n", |
| 219 | le16_to_cpu(fi->descTag.tagIdent)); | 230 | le16_to_cpu(fi->descTag.tagIdent)); |
| 220 | udf_debug("offset: %u sizeof: %lu bufsize: %u\n", | 231 | udf_debug("offset: %u sizeof: %lu bufsize: %u\n", |
| @@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) | |||
| 222 | bufsize); | 233 | bufsize); |
| 223 | return NULL; | 234 | return NULL; |
| 224 | } | 235 | } |
| 225 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { | 236 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) |
| 226 | lengthThisIdent = sizeof(struct fileIdentDesc); | 237 | lengthThisIdent = sizeof(struct fileIdentDesc); |
| 227 | } else { | 238 | else |
| 228 | lengthThisIdent = sizeof(struct fileIdentDesc) + | 239 | lengthThisIdent = sizeof(struct fileIdentDesc) + |
| 229 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); | 240 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); |
| 230 | } | ||
| 231 | 241 | ||
| 232 | /* we need to figure padding, too! */ | 242 | /* we need to figure padding, too! */ |
| 233 | padlen = lengthThisIdent % UDF_NAME_PAD; | 243 | padlen = lengthThisIdent % UDF_NAME_PAD; |
| @@ -252,17 +262,17 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) | |||
| 252 | 262 | ||
| 253 | fe = (struct fileEntry *)buffer; | 263 | fe = (struct fileEntry *)buffer; |
| 254 | 264 | ||
| 255 | if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) { | 265 | if (fe->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FE)) { |
| 256 | udf_debug("0x%x != TAG_IDENT_FE\n", | 266 | udf_debug("0x%x != TAG_IDENT_FE\n", |
| 257 | le16_to_cpu(fe->descTag.tagIdent)); | 267 | le16_to_cpu(fe->descTag.tagIdent)); |
| 258 | return NULL; | 268 | return NULL; |
| 259 | } | 269 | } |
| 260 | 270 | ||
| 261 | ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); | 271 | ptr = (uint8_t *)(fe->extendedAttr) + |
| 272 | le32_to_cpu(fe->lengthExtendedAttr); | ||
| 262 | 273 | ||
| 263 | if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { | 274 | if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) |
| 264 | ptr += *offset; | 275 | ptr += *offset; |
| 265 | } | ||
| 266 | 276 | ||
| 267 | ext = (extent_ad *)ptr; | 277 | ext = (extent_ad *)ptr; |
| 268 | 278 | ||
| @@ -271,7 +281,7 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) | |||
| 271 | } | 281 | } |
| 272 | #endif | 282 | #endif |
| 273 | 283 | ||
| 274 | short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, | 284 | short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset, |
| 275 | int inc) | 285 | int inc) |
| 276 | { | 286 | { |
| 277 | short_ad *sa; | 287 | short_ad *sa; |
| @@ -281,17 +291,20 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, | |||
| 281 | return NULL; | 291 | return NULL; |
| 282 | } | 292 | } |
| 283 | 293 | ||
| 284 | if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) | 294 | if ((*offset + sizeof(short_ad)) > maxoffset) |
| 285 | return NULL; | ||
| 286 | else if ((sa = (short_ad *)ptr)->extLength == 0) | ||
| 287 | return NULL; | 295 | return NULL; |
| 296 | else { | ||
| 297 | sa = (short_ad *)ptr; | ||
| 298 | if (sa->extLength == 0) | ||
| 299 | return NULL; | ||
| 300 | } | ||
| 288 | 301 | ||
| 289 | if (inc) | 302 | if (inc) |
| 290 | *offset += sizeof(short_ad); | 303 | *offset += sizeof(short_ad); |
| 291 | return sa; | 304 | return sa; |
| 292 | } | 305 | } |
| 293 | 306 | ||
| 294 | long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) | 307 | long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc) |
| 295 | { | 308 | { |
| 296 | long_ad *la; | 309 | long_ad *la; |
| 297 | 310 | ||
| @@ -300,10 +313,13 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) | |||
| 300 | return NULL; | 313 | return NULL; |
| 301 | } | 314 | } |
| 302 | 315 | ||
| 303 | if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) | 316 | if ((*offset + sizeof(long_ad)) > maxoffset) |
| 304 | return NULL; | ||
| 305 | else if ((la = (long_ad *)ptr)->extLength == 0) | ||
| 306 | return NULL; | 317 | return NULL; |
| 318 | else { | ||
| 319 | la = (long_ad *)ptr; | ||
| 320 | if (la->extLength == 0) | ||
| 321 | return NULL; | ||
| 322 | } | ||
| 307 | 323 | ||
| 308 | if (inc) | 324 | if (inc) |
| 309 | *offset += sizeof(long_ad); | 325 | *offset += sizeof(long_ad); |
diff --git a/fs/udf/file.c b/fs/udf/file.c index 7c7a1b39d56c..97c71ae7c689 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c | |||
| @@ -45,12 +45,13 @@ static int udf_adinicb_readpage(struct file *file, struct page *page) | |||
| 45 | { | 45 | { |
| 46 | struct inode *inode = page->mapping->host; | 46 | struct inode *inode = page->mapping->host; |
| 47 | char *kaddr; | 47 | char *kaddr; |
| 48 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 48 | 49 | ||
| 49 | BUG_ON(!PageLocked(page)); | 50 | BUG_ON(!PageLocked(page)); |
| 50 | 51 | ||
| 51 | kaddr = kmap(page); | 52 | kaddr = kmap(page); |
| 52 | memset(kaddr, 0, PAGE_CACHE_SIZE); | 53 | memset(kaddr, 0, PAGE_CACHE_SIZE); |
| 53 | memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), inode->i_size); | 54 | memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, inode->i_size); |
| 54 | flush_dcache_page(page); | 55 | flush_dcache_page(page); |
| 55 | SetPageUptodate(page); | 56 | SetPageUptodate(page); |
| 56 | kunmap(page); | 57 | kunmap(page); |
| @@ -59,15 +60,17 @@ static int udf_adinicb_readpage(struct file *file, struct page *page) | |||
| 59 | return 0; | 60 | return 0; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc) | 63 | static int udf_adinicb_writepage(struct page *page, |
| 64 | struct writeback_control *wbc) | ||
| 63 | { | 65 | { |
| 64 | struct inode *inode = page->mapping->host; | 66 | struct inode *inode = page->mapping->host; |
| 65 | char *kaddr; | 67 | char *kaddr; |
| 68 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 66 | 69 | ||
| 67 | BUG_ON(!PageLocked(page)); | 70 | BUG_ON(!PageLocked(page)); |
| 68 | 71 | ||
| 69 | kaddr = kmap(page); | 72 | kaddr = kmap(page); |
| 70 | memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), kaddr, inode->i_size); | 73 | memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr, inode->i_size); |
| 71 | mark_inode_dirty(inode); | 74 | mark_inode_dirty(inode); |
| 72 | SetPageUptodate(page); | 75 | SetPageUptodate(page); |
| 73 | kunmap(page); | 76 | kunmap(page); |
| @@ -84,9 +87,10 @@ static int udf_adinicb_write_end(struct file *file, | |||
| 84 | struct inode *inode = mapping->host; | 87 | struct inode *inode = mapping->host; |
| 85 | unsigned offset = pos & (PAGE_CACHE_SIZE - 1); | 88 | unsigned offset = pos & (PAGE_CACHE_SIZE - 1); |
| 86 | char *kaddr; | 89 | char *kaddr; |
| 90 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 87 | 91 | ||
| 88 | kaddr = kmap_atomic(page, KM_USER0); | 92 | kaddr = kmap_atomic(page, KM_USER0); |
| 89 | memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, | 93 | memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset, |
| 90 | kaddr + offset, copied); | 94 | kaddr + offset, copied); |
| 91 | kunmap_atomic(kaddr, KM_USER0); | 95 | kunmap_atomic(kaddr, KM_USER0); |
| 92 | 96 | ||
| @@ -109,25 +113,27 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
| 109 | struct inode *inode = file->f_path.dentry->d_inode; | 113 | struct inode *inode = file->f_path.dentry->d_inode; |
| 110 | int err, pos; | 114 | int err, pos; |
| 111 | size_t count = iocb->ki_left; | 115 | size_t count = iocb->ki_left; |
| 116 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 112 | 117 | ||
| 113 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 118 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 114 | if (file->f_flags & O_APPEND) | 119 | if (file->f_flags & O_APPEND) |
| 115 | pos = inode->i_size; | 120 | pos = inode->i_size; |
| 116 | else | 121 | else |
| 117 | pos = ppos; | 122 | pos = ppos; |
| 118 | 123 | ||
| 119 | if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + | 124 | if (inode->i_sb->s_blocksize < |
| 125 | (udf_file_entry_alloc_offset(inode) + | ||
| 120 | pos + count)) { | 126 | pos + count)) { |
| 121 | udf_expand_file_adinicb(inode, pos + count, &err); | 127 | udf_expand_file_adinicb(inode, pos + count, &err); |
| 122 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 128 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 123 | udf_debug("udf_expand_adinicb: err=%d\n", err); | 129 | udf_debug("udf_expand_adinicb: err=%d\n", err); |
| 124 | return err; | 130 | return err; |
| 125 | } | 131 | } |
| 126 | } else { | 132 | } else { |
| 127 | if (pos + count > inode->i_size) | 133 | if (pos + count > inode->i_size) |
| 128 | UDF_I_LENALLOC(inode) = pos + count; | 134 | iinfo->i_lenAlloc = pos + count; |
| 129 | else | 135 | else |
| 130 | UDF_I_LENALLOC(inode) = inode->i_size; | 136 | iinfo->i_lenAlloc = inode->i_size; |
| 131 | } | 137 | } |
| 132 | } | 138 | } |
| 133 | 139 | ||
| @@ -191,23 +197,28 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, | |||
| 191 | 197 | ||
| 192 | switch (cmd) { | 198 | switch (cmd) { |
| 193 | case UDF_GETVOLIDENT: | 199 | case UDF_GETVOLIDENT: |
| 194 | return copy_to_user((char __user *)arg, | 200 | if (copy_to_user((char __user *)arg, |
| 195 | UDF_SB_VOLIDENT(inode->i_sb), 32) ? -EFAULT : 0; | 201 | UDF_SB(inode->i_sb)->s_volume_ident, 32)) |
| 202 | return -EFAULT; | ||
| 203 | else | ||
| 204 | return 0; | ||
| 196 | case UDF_RELOCATE_BLOCKS: | 205 | case UDF_RELOCATE_BLOCKS: |
| 197 | if (!capable(CAP_SYS_ADMIN)) | 206 | if (!capable(CAP_SYS_ADMIN)) |
| 198 | return -EACCES; | 207 | return -EACCES; |
| 199 | if (get_user(old_block, (long __user *)arg)) | 208 | if (get_user(old_block, (long __user *)arg)) |
| 200 | return -EFAULT; | 209 | return -EFAULT; |
| 201 | if ((result = udf_relocate_blocks(inode->i_sb, | 210 | result = udf_relocate_blocks(inode->i_sb, |
| 202 | old_block, &new_block)) == 0) | 211 | old_block, &new_block); |
| 212 | if (result == 0) | ||
| 203 | result = put_user(new_block, (long __user *)arg); | 213 | result = put_user(new_block, (long __user *)arg); |
| 204 | return result; | 214 | return result; |
| 205 | case UDF_GETEASIZE: | 215 | case UDF_GETEASIZE: |
| 206 | result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg); | 216 | result = put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg); |
| 207 | break; | 217 | break; |
| 208 | case UDF_GETEABLOCK: | 218 | case UDF_GETEABLOCK: |
| 209 | result = copy_to_user((char __user *)arg, UDF_I_DATA(inode), | 219 | result = copy_to_user((char __user *)arg, |
| 210 | UDF_I_LENEATTR(inode)) ? -EFAULT : 0; | 220 | UDF_I(inode)->i_ext.i_data, |
| 221 | UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0; | ||
| 211 | break; | 222 | break; |
| 212 | } | 223 | } |
| 213 | 224 | ||
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c index 636d8f613929..84360315aca2 100644 --- a/fs/udf/ialloc.c +++ b/fs/udf/ialloc.c | |||
| @@ -43,19 +43,21 @@ void udf_free_inode(struct inode *inode) | |||
| 43 | clear_inode(inode); | 43 | clear_inode(inode); |
| 44 | 44 | ||
| 45 | mutex_lock(&sbi->s_alloc_mutex); | 45 | mutex_lock(&sbi->s_alloc_mutex); |
| 46 | if (sbi->s_lvidbh) { | 46 | if (sbi->s_lvid_bh) { |
| 47 | struct logicalVolIntegrityDescImpUse *lvidiu = | ||
| 48 | udf_sb_lvidiu(sbi); | ||
| 47 | if (S_ISDIR(inode->i_mode)) | 49 | if (S_ISDIR(inode->i_mode)) |
| 48 | UDF_SB_LVIDIU(sb)->numDirs = | 50 | lvidiu->numDirs = |
| 49 | cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) - 1); | 51 | cpu_to_le32(le32_to_cpu(lvidiu->numDirs) - 1); |
| 50 | else | 52 | else |
| 51 | UDF_SB_LVIDIU(sb)->numFiles = | 53 | lvidiu->numFiles = |
| 52 | cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1); | 54 | cpu_to_le32(le32_to_cpu(lvidiu->numFiles) - 1); |
| 53 | 55 | ||
| 54 | mark_buffer_dirty(sbi->s_lvidbh); | 56 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 55 | } | 57 | } |
| 56 | mutex_unlock(&sbi->s_alloc_mutex); | 58 | mutex_unlock(&sbi->s_alloc_mutex); |
| 57 | 59 | ||
| 58 | udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1); | 60 | udf_free_blocks(sb, NULL, UDF_I(inode)->i_location, 0, 1); |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | 63 | struct inode *udf_new_inode(struct inode *dir, int mode, int *err) |
| @@ -64,7 +66,9 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
| 64 | struct udf_sb_info *sbi = UDF_SB(sb); | 66 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 65 | struct inode *inode; | 67 | struct inode *inode; |
| 66 | int block; | 68 | int block; |
| 67 | uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum; | 69 | uint32_t start = UDF_I(dir)->i_location.logicalBlockNum; |
| 70 | struct udf_inode_info *iinfo; | ||
| 71 | struct udf_inode_info *dinfo = UDF_I(dir); | ||
| 68 | 72 | ||
| 69 | inode = new_inode(sb); | 73 | inode = new_inode(sb); |
| 70 | 74 | ||
| @@ -74,13 +78,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
| 74 | } | 78 | } |
| 75 | *err = -ENOSPC; | 79 | *err = -ENOSPC; |
| 76 | 80 | ||
| 77 | UDF_I_UNIQUE(inode) = 0; | 81 | iinfo = UDF_I(inode); |
| 78 | UDF_I_LENEXTENTS(inode) = 0; | 82 | iinfo->i_unique = 0; |
| 79 | UDF_I_NEXT_ALLOC_BLOCK(inode) = 0; | 83 | iinfo->i_lenExtents = 0; |
| 80 | UDF_I_NEXT_ALLOC_GOAL(inode) = 0; | 84 | iinfo->i_next_alloc_block = 0; |
| 81 | UDF_I_STRAT4096(inode) = 0; | 85 | iinfo->i_next_alloc_goal = 0; |
| 86 | iinfo->i_strat4096 = 0; | ||
| 82 | 87 | ||
| 83 | block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, | 88 | block = udf_new_block(dir->i_sb, NULL, |
| 89 | dinfo->i_location.partitionReferenceNum, | ||
| 84 | start, err); | 90 | start, err); |
| 85 | if (*err) { | 91 | if (*err) { |
| 86 | iput(inode); | 92 | iput(inode); |
| @@ -88,21 +94,27 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
| 88 | } | 94 | } |
| 89 | 95 | ||
| 90 | mutex_lock(&sbi->s_alloc_mutex); | 96 | mutex_lock(&sbi->s_alloc_mutex); |
| 91 | if (UDF_SB_LVIDBH(sb)) { | 97 | if (sbi->s_lvid_bh) { |
| 98 | struct logicalVolIntegrityDesc *lvid = | ||
| 99 | (struct logicalVolIntegrityDesc *) | ||
| 100 | sbi->s_lvid_bh->b_data; | ||
| 101 | struct logicalVolIntegrityDescImpUse *lvidiu = | ||
| 102 | udf_sb_lvidiu(sbi); | ||
| 92 | struct logicalVolHeaderDesc *lvhd; | 103 | struct logicalVolHeaderDesc *lvhd; |
| 93 | uint64_t uniqueID; | 104 | uint64_t uniqueID; |
| 94 | lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse); | 105 | lvhd = (struct logicalVolHeaderDesc *) |
| 106 | (lvid->logicalVolContentsUse); | ||
| 95 | if (S_ISDIR(mode)) | 107 | if (S_ISDIR(mode)) |
| 96 | UDF_SB_LVIDIU(sb)->numDirs = | 108 | lvidiu->numDirs = |
| 97 | cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) + 1); | 109 | cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1); |
| 98 | else | 110 | else |
| 99 | UDF_SB_LVIDIU(sb)->numFiles = | 111 | lvidiu->numFiles = |
| 100 | cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1); | 112 | cpu_to_le32(le32_to_cpu(lvidiu->numFiles) + 1); |
| 101 | UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID); | 113 | iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID); |
| 102 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) | 114 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 103 | uniqueID += 16; | 115 | uniqueID += 16; |
| 104 | lvhd->uniqueID = cpu_to_le64(uniqueID); | 116 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
| 105 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 117 | mark_buffer_dirty(sbi->s_lvid_bh); |
| 106 | } | 118 | } |
| 107 | inode->i_mode = mode; | 119 | inode->i_mode = mode; |
| 108 | inode->i_uid = current->fsuid; | 120 | inode->i_uid = current->fsuid; |
| @@ -114,35 +126,41 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
| 114 | inode->i_gid = current->fsgid; | 126 | inode->i_gid = current->fsgid; |
| 115 | } | 127 | } |
| 116 | 128 | ||
| 117 | UDF_I_LOCATION(inode).logicalBlockNum = block; | 129 | iinfo->i_location.logicalBlockNum = block; |
| 118 | UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; | 130 | iinfo->i_location.partitionReferenceNum = |
| 119 | inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); | 131 | dinfo->i_location.partitionReferenceNum; |
| 132 | inode->i_ino = udf_get_lb_pblock(sb, iinfo->i_location, 0); | ||
| 120 | inode->i_blocks = 0; | 133 | inode->i_blocks = 0; |
| 121 | UDF_I_LENEATTR(inode) = 0; | 134 | iinfo->i_lenEAttr = 0; |
| 122 | UDF_I_LENALLOC(inode) = 0; | 135 | iinfo->i_lenAlloc = 0; |
| 123 | UDF_I_USE(inode) = 0; | 136 | iinfo->i_use = 0; |
| 124 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { | 137 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { |
| 125 | UDF_I_EFE(inode) = 1; | 138 | iinfo->i_efe = 1; |
| 126 | UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE); | 139 | if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) |
| 127 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); | 140 | sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; |
| 141 | iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize - | ||
| 142 | sizeof(struct extendedFileEntry), | ||
| 143 | GFP_KERNEL); | ||
| 128 | } else { | 144 | } else { |
| 129 | UDF_I_EFE(inode) = 0; | 145 | iinfo->i_efe = 0; |
| 130 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); | 146 | iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize - |
| 147 | sizeof(struct fileEntry), | ||
| 148 | GFP_KERNEL); | ||
| 131 | } | 149 | } |
| 132 | if (!UDF_I_DATA(inode)) { | 150 | if (!iinfo->i_ext.i_data) { |
| 133 | iput(inode); | 151 | iput(inode); |
| 134 | *err = -ENOMEM; | 152 | *err = -ENOMEM; |
| 135 | mutex_unlock(&sbi->s_alloc_mutex); | 153 | mutex_unlock(&sbi->s_alloc_mutex); |
| 136 | return NULL; | 154 | return NULL; |
| 137 | } | 155 | } |
| 138 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) | 156 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) |
| 139 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 157 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; |
| 140 | else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) | 158 | else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
| 141 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; | 159 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; |
| 142 | else | 160 | else |
| 143 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG; | 161 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
| 144 | inode->i_mtime = inode->i_atime = inode->i_ctime = | 162 | inode->i_mtime = inode->i_atime = inode->i_ctime = |
| 145 | UDF_I_CRTIME(inode) = current_fs_time(inode->i_sb); | 163 | iinfo->i_crtime = current_fs_time(inode->i_sb); |
| 146 | insert_inode_hash(inode); | 164 | insert_inode_hash(inode); |
| 147 | mark_inode_dirty(inode); | 165 | mark_inode_dirty(inode); |
| 148 | mutex_unlock(&sbi->s_alloc_mutex); | 166 | mutex_unlock(&sbi->s_alloc_mutex); |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 6ff8151984cf..24cfa55d0fdc 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
| @@ -19,7 +19,8 @@ | |||
| 19 | * 10/04/98 dgb Added rudimentary directory functions | 19 | * 10/04/98 dgb Added rudimentary directory functions |
| 20 | * 10/07/98 Fully working udf_block_map! It works! | 20 | * 10/07/98 Fully working udf_block_map! It works! |
| 21 | * 11/25/98 bmap altered to better support extents | 21 | * 11/25/98 bmap altered to better support extents |
| 22 | * 12/06/98 blf partition support in udf_iget, udf_block_map and udf_read_inode | 22 | * 12/06/98 blf partition support in udf_iget, udf_block_map |
| 23 | * and udf_read_inode | ||
| 23 | * 12/12/98 rewrote udf_block_map to handle next extents and descs across | 24 | * 12/12/98 rewrote udf_block_map to handle next extents and descs across |
| 24 | * block boundaries (which is not actually allowed) | 25 | * block boundaries (which is not actually allowed) |
| 25 | * 12/20/98 added support for strategy 4096 | 26 | * 12/20/98 added support for strategy 4096 |
| @@ -51,7 +52,7 @@ static int udf_update_inode(struct inode *, int); | |||
| 51 | static void udf_fill_inode(struct inode *, struct buffer_head *); | 52 | static void udf_fill_inode(struct inode *, struct buffer_head *); |
| 52 | static int udf_alloc_i_data(struct inode *inode, size_t size); | 53 | static int udf_alloc_i_data(struct inode *inode, size_t size); |
| 53 | static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, | 54 | static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, |
| 54 | long *, int *); | 55 | sector_t *, int *); |
| 55 | static int8_t udf_insert_aext(struct inode *, struct extent_position, | 56 | static int8_t udf_insert_aext(struct inode *, struct extent_position, |
| 56 | kernel_lb_addr, uint32_t); | 57 | kernel_lb_addr, uint32_t); |
| 57 | static void udf_split_extents(struct inode *, int *, int, int, | 58 | static void udf_split_extents(struct inode *, int *, int, int, |
| @@ -111,16 +112,18 @@ no_delete: | |||
| 111 | */ | 112 | */ |
| 112 | void udf_clear_inode(struct inode *inode) | 113 | void udf_clear_inode(struct inode *inode) |
| 113 | { | 114 | { |
| 115 | struct udf_inode_info *iinfo; | ||
| 114 | if (!(inode->i_sb->s_flags & MS_RDONLY)) { | 116 | if (!(inode->i_sb->s_flags & MS_RDONLY)) { |
| 115 | lock_kernel(); | 117 | lock_kernel(); |
| 116 | /* Discard preallocation for directories, symlinks, etc. */ | 118 | /* Discard preallocation for directories, symlinks, etc. */ |
| 117 | udf_discard_prealloc(inode); | 119 | udf_discard_prealloc(inode); |
| 118 | udf_truncate_tail_extent(inode); | 120 | udf_truncate_tail_extent(inode); |
| 119 | unlock_kernel(); | 121 | unlock_kernel(); |
| 120 | write_inode_now(inode, 1); | 122 | write_inode_now(inode, 0); |
| 121 | } | 123 | } |
| 122 | kfree(UDF_I_DATA(inode)); | 124 | iinfo = UDF_I(inode); |
| 123 | UDF_I_DATA(inode) = NULL; | 125 | kfree(iinfo->i_ext.i_data); |
| 126 | iinfo->i_ext.i_data = NULL; | ||
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | static int udf_writepage(struct page *page, struct writeback_control *wbc) | 129 | static int udf_writepage(struct page *page, struct writeback_control *wbc) |
| @@ -160,6 +163,7 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err) | |||
| 160 | { | 163 | { |
| 161 | struct page *page; | 164 | struct page *page; |
| 162 | char *kaddr; | 165 | char *kaddr; |
| 166 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 163 | struct writeback_control udf_wbc = { | 167 | struct writeback_control udf_wbc = { |
| 164 | .sync_mode = WB_SYNC_NONE, | 168 | .sync_mode = WB_SYNC_NONE, |
| 165 | .nr_to_write = 1, | 169 | .nr_to_write = 1, |
| @@ -168,11 +172,11 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err) | |||
| 168 | /* from now on we have normal address_space methods */ | 172 | /* from now on we have normal address_space methods */ |
| 169 | inode->i_data.a_ops = &udf_aops; | 173 | inode->i_data.a_ops = &udf_aops; |
| 170 | 174 | ||
| 171 | if (!UDF_I_LENALLOC(inode)) { | 175 | if (!iinfo->i_lenAlloc) { |
| 172 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) | 176 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
| 173 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; | 177 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; |
| 174 | else | 178 | else |
| 175 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG; | 179 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
| 176 | mark_inode_dirty(inode); | 180 | mark_inode_dirty(inode); |
| 177 | return; | 181 | return; |
| 178 | } | 182 | } |
| @@ -182,21 +186,21 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err) | |||
| 182 | 186 | ||
| 183 | if (!PageUptodate(page)) { | 187 | if (!PageUptodate(page)) { |
| 184 | kaddr = kmap(page); | 188 | kaddr = kmap(page); |
| 185 | memset(kaddr + UDF_I_LENALLOC(inode), 0x00, | 189 | memset(kaddr + iinfo->i_lenAlloc, 0x00, |
| 186 | PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode)); | 190 | PAGE_CACHE_SIZE - iinfo->i_lenAlloc); |
| 187 | memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), | 191 | memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, |
| 188 | UDF_I_LENALLOC(inode)); | 192 | iinfo->i_lenAlloc); |
| 189 | flush_dcache_page(page); | 193 | flush_dcache_page(page); |
| 190 | SetPageUptodate(page); | 194 | SetPageUptodate(page); |
| 191 | kunmap(page); | 195 | kunmap(page); |
| 192 | } | 196 | } |
| 193 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00, | 197 | memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0x00, |
| 194 | UDF_I_LENALLOC(inode)); | 198 | iinfo->i_lenAlloc); |
| 195 | UDF_I_LENALLOC(inode) = 0; | 199 | iinfo->i_lenAlloc = 0; |
| 196 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) | 200 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
| 197 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; | 201 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; |
| 198 | else | 202 | else |
| 199 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG; | 203 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
| 200 | 204 | ||
| 201 | inode->i_data.a_ops->writepage(page, &udf_wbc); | 205 | inode->i_data.a_ops->writepage(page, &udf_wbc); |
| 202 | page_cache_release(page); | 206 | page_cache_release(page); |
| @@ -215,9 +219,10 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
| 215 | struct extent_position epos; | 219 | struct extent_position epos; |
| 216 | 220 | ||
| 217 | struct udf_fileident_bh sfibh, dfibh; | 221 | struct udf_fileident_bh sfibh, dfibh; |
| 218 | loff_t f_pos = udf_ext0_offset(inode) >> 2; | 222 | loff_t f_pos = udf_ext0_offset(inode); |
| 219 | int size = (udf_ext0_offset(inode) + inode->i_size) >> 2; | 223 | int size = udf_ext0_offset(inode) + inode->i_size; |
| 220 | struct fileIdentDesc cfi, *sfi, *dfi; | 224 | struct fileIdentDesc cfi, *sfi, *dfi; |
| 225 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 221 | 226 | ||
| 222 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) | 227 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
| 223 | alloctype = ICBTAG_FLAG_AD_SHORT; | 228 | alloctype = ICBTAG_FLAG_AD_SHORT; |
| @@ -225,19 +230,20 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
| 225 | alloctype = ICBTAG_FLAG_AD_LONG; | 230 | alloctype = ICBTAG_FLAG_AD_LONG; |
| 226 | 231 | ||
| 227 | if (!inode->i_size) { | 232 | if (!inode->i_size) { |
| 228 | UDF_I_ALLOCTYPE(inode) = alloctype; | 233 | iinfo->i_alloc_type = alloctype; |
| 229 | mark_inode_dirty(inode); | 234 | mark_inode_dirty(inode); |
| 230 | return NULL; | 235 | return NULL; |
| 231 | } | 236 | } |
| 232 | 237 | ||
| 233 | /* alloc block, and copy data to it */ | 238 | /* alloc block, and copy data to it */ |
| 234 | *block = udf_new_block(inode->i_sb, inode, | 239 | *block = udf_new_block(inode->i_sb, inode, |
| 235 | UDF_I_LOCATION(inode).partitionReferenceNum, | 240 | iinfo->i_location.partitionReferenceNum, |
| 236 | UDF_I_LOCATION(inode).logicalBlockNum, err); | 241 | iinfo->i_location.logicalBlockNum, err); |
| 237 | if (!(*block)) | 242 | if (!(*block)) |
| 238 | return NULL; | 243 | return NULL; |
| 239 | newblock = udf_get_pblock(inode->i_sb, *block, | 244 | newblock = udf_get_pblock(inode->i_sb, *block, |
| 240 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); | 245 | iinfo->i_location.partitionReferenceNum, |
| 246 | 0); | ||
| 241 | if (!newblock) | 247 | if (!newblock) |
| 242 | return NULL; | 248 | return NULL; |
| 243 | dbh = udf_tgetblk(inode->i_sb, newblock); | 249 | dbh = udf_tgetblk(inode->i_sb, newblock); |
| @@ -249,39 +255,44 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
| 249 | unlock_buffer(dbh); | 255 | unlock_buffer(dbh); |
| 250 | mark_buffer_dirty_inode(dbh, inode); | 256 | mark_buffer_dirty_inode(dbh, inode); |
| 251 | 257 | ||
| 252 | sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; | 258 | sfibh.soffset = sfibh.eoffset = |
| 259 | f_pos & (inode->i_sb->s_blocksize - 1); | ||
| 253 | sfibh.sbh = sfibh.ebh = NULL; | 260 | sfibh.sbh = sfibh.ebh = NULL; |
| 254 | dfibh.soffset = dfibh.eoffset = 0; | 261 | dfibh.soffset = dfibh.eoffset = 0; |
| 255 | dfibh.sbh = dfibh.ebh = dbh; | 262 | dfibh.sbh = dfibh.ebh = dbh; |
| 256 | while ((f_pos < size)) { | 263 | while (f_pos < size) { |
| 257 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 264 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; |
| 258 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); | 265 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, |
| 266 | NULL, NULL, NULL); | ||
| 259 | if (!sfi) { | 267 | if (!sfi) { |
| 260 | brelse(dbh); | 268 | brelse(dbh); |
| 261 | return NULL; | 269 | return NULL; |
| 262 | } | 270 | } |
| 263 | UDF_I_ALLOCTYPE(inode) = alloctype; | 271 | iinfo->i_alloc_type = alloctype; |
| 264 | sfi->descTag.tagLocation = cpu_to_le32(*block); | 272 | sfi->descTag.tagLocation = cpu_to_le32(*block); |
| 265 | dfibh.soffset = dfibh.eoffset; | 273 | dfibh.soffset = dfibh.eoffset; |
| 266 | dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); | 274 | dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); |
| 267 | dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); | 275 | dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); |
| 268 | if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, | 276 | if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, |
| 269 | sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) { | 277 | sfi->fileIdent + |
| 270 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 278 | le16_to_cpu(sfi->lengthOfImpUse))) { |
| 279 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; | ||
| 271 | brelse(dbh); | 280 | brelse(dbh); |
| 272 | return NULL; | 281 | return NULL; |
| 273 | } | 282 | } |
| 274 | } | 283 | } |
| 275 | mark_buffer_dirty_inode(dbh, inode); | 284 | mark_buffer_dirty_inode(dbh, inode); |
| 276 | 285 | ||
| 277 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); | 286 | memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0, |
| 278 | UDF_I_LENALLOC(inode) = 0; | 287 | iinfo->i_lenAlloc); |
| 288 | iinfo->i_lenAlloc = 0; | ||
| 279 | eloc.logicalBlockNum = *block; | 289 | eloc.logicalBlockNum = *block; |
| 280 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 290 | eloc.partitionReferenceNum = |
| 281 | elen = inode->i_size; | 291 | iinfo->i_location.partitionReferenceNum; |
| 282 | UDF_I_LENEXTENTS(inode) = elen; | 292 | elen = inode->i_sb->s_blocksize; |
| 293 | iinfo->i_lenExtents = elen; | ||
| 283 | epos.bh = NULL; | 294 | epos.bh = NULL; |
| 284 | epos.block = UDF_I_LOCATION(inode); | 295 | epos.block = iinfo->i_location; |
| 285 | epos.offset = udf_file_entry_alloc_offset(inode); | 296 | epos.offset = udf_file_entry_alloc_offset(inode); |
| 286 | udf_add_aext(inode, &epos, eloc, elen, 0); | 297 | udf_add_aext(inode, &epos, eloc, elen, 0); |
| 287 | /* UniqueID stuff */ | 298 | /* UniqueID stuff */ |
| @@ -296,7 +307,8 @@ static int udf_get_block(struct inode *inode, sector_t block, | |||
| 296 | { | 307 | { |
| 297 | int err, new; | 308 | int err, new; |
| 298 | struct buffer_head *bh; | 309 | struct buffer_head *bh; |
| 299 | unsigned long phys; | 310 | sector_t phys = 0; |
| 311 | struct udf_inode_info *iinfo; | ||
| 300 | 312 | ||
| 301 | if (!create) { | 313 | if (!create) { |
| 302 | phys = udf_block_map(inode, block); | 314 | phys = udf_block_map(inode, block); |
| @@ -314,9 +326,10 @@ static int udf_get_block(struct inode *inode, sector_t block, | |||
| 314 | if (block < 0) | 326 | if (block < 0) |
| 315 | goto abort_negative; | 327 | goto abort_negative; |
| 316 | 328 | ||
| 317 | if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) { | 329 | iinfo = UDF_I(inode); |
| 318 | UDF_I_NEXT_ALLOC_BLOCK(inode)++; | 330 | if (block == iinfo->i_next_alloc_block + 1) { |
| 319 | UDF_I_NEXT_ALLOC_GOAL(inode)++; | 331 | iinfo->i_next_alloc_block++; |
| 332 | iinfo->i_next_alloc_goal++; | ||
| 320 | } | 333 | } |
| 321 | 334 | ||
| 322 | err = 0; | 335 | err = 0; |
| @@ -366,32 +379,35 @@ static struct buffer_head *udf_getblk(struct inode *inode, long block, | |||
| 366 | 379 | ||
| 367 | /* Extend the file by 'blocks' blocks, return the number of extents added */ | 380 | /* Extend the file by 'blocks' blocks, return the number of extents added */ |
| 368 | int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | 381 | int udf_extend_file(struct inode *inode, struct extent_position *last_pos, |
| 369 | kernel_long_ad * last_ext, sector_t blocks) | 382 | kernel_long_ad *last_ext, sector_t blocks) |
| 370 | { | 383 | { |
| 371 | sector_t add; | 384 | sector_t add; |
| 372 | int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | 385 | int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); |
| 373 | struct super_block *sb = inode->i_sb; | 386 | struct super_block *sb = inode->i_sb; |
| 374 | kernel_lb_addr prealloc_loc = {}; | 387 | kernel_lb_addr prealloc_loc = {}; |
| 375 | int prealloc_len = 0; | 388 | int prealloc_len = 0; |
| 389 | struct udf_inode_info *iinfo; | ||
| 376 | 390 | ||
| 377 | /* The previous extent is fake and we should not extend by anything | 391 | /* The previous extent is fake and we should not extend by anything |
| 378 | * - there's nothing to do... */ | 392 | * - there's nothing to do... */ |
| 379 | if (!blocks && fake) | 393 | if (!blocks && fake) |
| 380 | return 0; | 394 | return 0; |
| 381 | 395 | ||
| 396 | iinfo = UDF_I(inode); | ||
| 382 | /* Round the last extent up to a multiple of block size */ | 397 | /* Round the last extent up to a multiple of block size */ |
| 383 | if (last_ext->extLength & (sb->s_blocksize - 1)) { | 398 | if (last_ext->extLength & (sb->s_blocksize - 1)) { |
| 384 | last_ext->extLength = | 399 | last_ext->extLength = |
| 385 | (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | | 400 | (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | |
| 386 | (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + | 401 | (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 387 | sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); | 402 | sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); |
| 388 | UDF_I_LENEXTENTS(inode) = | 403 | iinfo->i_lenExtents = |
| 389 | (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & | 404 | (iinfo->i_lenExtents + sb->s_blocksize - 1) & |
| 390 | ~(sb->s_blocksize - 1); | 405 | ~(sb->s_blocksize - 1); |
| 391 | } | 406 | } |
| 392 | 407 | ||
| 393 | /* Last extent are just preallocated blocks? */ | 408 | /* Last extent are just preallocated blocks? */ |
| 394 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { | 409 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == |
| 410 | EXT_NOT_RECORDED_ALLOCATED) { | ||
| 395 | /* Save the extent so that we can reattach it to the end */ | 411 | /* Save the extent so that we can reattach it to the end */ |
| 396 | prealloc_loc = last_ext->extLocation; | 412 | prealloc_loc = last_ext->extLocation; |
| 397 | prealloc_len = last_ext->extLength; | 413 | prealloc_len = last_ext->extLength; |
| @@ -399,13 +415,15 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
| 399 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 415 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
| 400 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | 416 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); |
| 401 | last_ext->extLocation.logicalBlockNum = 0; | 417 | last_ext->extLocation.logicalBlockNum = 0; |
| 402 | last_ext->extLocation.partitionReferenceNum = 0; | 418 | last_ext->extLocation.partitionReferenceNum = 0; |
| 403 | } | 419 | } |
| 404 | 420 | ||
| 405 | /* Can we merge with the previous extent? */ | 421 | /* Can we merge with the previous extent? */ |
| 406 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { | 422 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == |
| 407 | add = ((1 << 30) - sb->s_blocksize - (last_ext->extLength & | 423 | EXT_NOT_RECORDED_NOT_ALLOCATED) { |
| 408 | UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; | 424 | add = ((1 << 30) - sb->s_blocksize - |
| 425 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> | ||
| 426 | sb->s_blocksize_bits; | ||
| 409 | if (add > blocks) | 427 | if (add > blocks) |
| 410 | add = blocks; | 428 | add = blocks; |
| 411 | blocks -= add; | 429 | blocks -= add; |
| @@ -416,9 +434,9 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
| 416 | udf_add_aext(inode, last_pos, last_ext->extLocation, | 434 | udf_add_aext(inode, last_pos, last_ext->extLocation, |
| 417 | last_ext->extLength, 1); | 435 | last_ext->extLength, 1); |
| 418 | count++; | 436 | count++; |
| 419 | } else { | 437 | } else |
| 420 | udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); | 438 | udf_write_aext(inode, last_pos, last_ext->extLocation, |
| 421 | } | 439 | last_ext->extLength, 1); |
| 422 | 440 | ||
| 423 | /* Managed to do everything necessary? */ | 441 | /* Managed to do everything necessary? */ |
| 424 | if (!blocks) | 442 | if (!blocks) |
| @@ -426,9 +444,10 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
| 426 | 444 | ||
| 427 | /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ | 445 | /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ |
| 428 | last_ext->extLocation.logicalBlockNum = 0; | 446 | last_ext->extLocation.logicalBlockNum = 0; |
| 429 | last_ext->extLocation.partitionReferenceNum = 0; | 447 | last_ext->extLocation.partitionReferenceNum = 0; |
| 430 | add = (1 << (30-sb->s_blocksize_bits)) - 1; | 448 | add = (1 << (30-sb->s_blocksize_bits)) - 1; |
| 431 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); | 449 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
| 450 | (add << sb->s_blocksize_bits); | ||
| 432 | 451 | ||
| 433 | /* Create enough extents to cover the whole hole */ | 452 | /* Create enough extents to cover the whole hole */ |
| 434 | while (blocks > add) { | 453 | while (blocks > add) { |
| @@ -450,7 +469,8 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
| 450 | out: | 469 | out: |
| 451 | /* Do we have some preallocated blocks saved? */ | 470 | /* Do we have some preallocated blocks saved? */ |
| 452 | if (prealloc_len) { | 471 | if (prealloc_len) { |
| 453 | if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1) | 472 | if (udf_add_aext(inode, last_pos, prealloc_loc, |
| 473 | prealloc_len, 1) == -1) | ||
| 454 | return -1; | 474 | return -1; |
| 455 | last_ext->extLocation = prealloc_loc; | 475 | last_ext->extLocation = prealloc_loc; |
| 456 | last_ext->extLength = prealloc_len; | 476 | last_ext->extLength = prealloc_len; |
| @@ -458,9 +478,9 @@ out: | |||
| 458 | } | 478 | } |
| 459 | 479 | ||
| 460 | /* last_pos should point to the last written extent... */ | 480 | /* last_pos should point to the last written extent... */ |
| 461 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 481 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 462 | last_pos->offset -= sizeof(short_ad); | 482 | last_pos->offset -= sizeof(short_ad); |
| 463 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 483 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 464 | last_pos->offset -= sizeof(long_ad); | 484 | last_pos->offset -= sizeof(long_ad); |
| 465 | else | 485 | else |
| 466 | return -1; | 486 | return -1; |
| @@ -469,7 +489,7 @@ out: | |||
| 469 | } | 489 | } |
| 470 | 490 | ||
| 471 | static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | 491 | static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, |
| 472 | int *err, long *phys, int *new) | 492 | int *err, sector_t *phys, int *new) |
| 473 | { | 493 | { |
| 474 | static sector_t last_block; | 494 | static sector_t last_block; |
| 475 | struct buffer_head *result = NULL; | 495 | struct buffer_head *result = NULL; |
| @@ -483,11 +503,12 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 483 | uint32_t newblocknum, newblock; | 503 | uint32_t newblocknum, newblock; |
| 484 | sector_t offset = 0; | 504 | sector_t offset = 0; |
| 485 | int8_t etype; | 505 | int8_t etype; |
| 486 | int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum; | 506 | struct udf_inode_info *iinfo = UDF_I(inode); |
| 507 | int goal = 0, pgoal = iinfo->i_location.logicalBlockNum; | ||
| 487 | int lastblock = 0; | 508 | int lastblock = 0; |
| 488 | 509 | ||
| 489 | prev_epos.offset = udf_file_entry_alloc_offset(inode); | 510 | prev_epos.offset = udf_file_entry_alloc_offset(inode); |
| 490 | prev_epos.block = UDF_I_LOCATION(inode); | 511 | prev_epos.block = iinfo->i_location; |
| 491 | prev_epos.bh = NULL; | 512 | prev_epos.bh = NULL; |
| 492 | cur_epos = next_epos = prev_epos; | 513 | cur_epos = next_epos = prev_epos; |
| 493 | b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; | 514 | b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; |
| @@ -515,7 +536,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 515 | prev_epos.offset = cur_epos.offset; | 536 | prev_epos.offset = cur_epos.offset; |
| 516 | cur_epos.offset = next_epos.offset; | 537 | cur_epos.offset = next_epos.offset; |
| 517 | 538 | ||
| 518 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1) | 539 | etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1); |
| 540 | if (etype == -1) | ||
| 519 | break; | 541 | break; |
| 520 | 542 | ||
| 521 | c = !c; | 543 | c = !c; |
| @@ -569,9 +591,11 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 569 | startnum = 1; | 591 | startnum = 1; |
| 570 | } else { | 592 | } else { |
| 571 | /* Create a fake extent when there's not one */ | 593 | /* Create a fake extent when there's not one */ |
| 572 | memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); | 594 | memset(&laarr[0].extLocation, 0x00, |
| 595 | sizeof(kernel_lb_addr)); | ||
| 573 | laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; | 596 | laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; |
| 574 | /* Will udf_extend_file() create real extent from a fake one? */ | 597 | /* Will udf_extend_file() create real extent from |
| 598 | a fake one? */ | ||
| 575 | startnum = (offset > 0); | 599 | startnum = (offset > 0); |
| 576 | } | 600 | } |
| 577 | /* Create extents for the hole between EOF and offset */ | 601 | /* Create extents for the hole between EOF and offset */ |
| @@ -589,14 +613,16 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 589 | offset = 0; | 613 | offset = 0; |
| 590 | count += ret; | 614 | count += ret; |
| 591 | /* We are not covered by a preallocated extent? */ | 615 | /* We are not covered by a preallocated extent? */ |
| 592 | if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) { | 616 | if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != |
| 617 | EXT_NOT_RECORDED_ALLOCATED) { | ||
| 593 | /* Is there any real extent? - otherwise we overwrite | 618 | /* Is there any real extent? - otherwise we overwrite |
| 594 | * the fake one... */ | 619 | * the fake one... */ |
| 595 | if (count) | 620 | if (count) |
| 596 | c = !c; | 621 | c = !c; |
| 597 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 622 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
| 598 | inode->i_sb->s_blocksize; | 623 | inode->i_sb->s_blocksize; |
| 599 | memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); | 624 | memset(&laarr[c].extLocation, 0x00, |
| 625 | sizeof(kernel_lb_addr)); | ||
| 600 | count++; | 626 | count++; |
| 601 | endnum++; | 627 | endnum++; |
| 602 | } | 628 | } |
| @@ -605,7 +631,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 605 | } else { | 631 | } else { |
| 606 | endnum = startnum = ((count > 2) ? 2 : count); | 632 | endnum = startnum = ((count > 2) ? 2 : count); |
| 607 | 633 | ||
| 608 | /* if the current extent is in position 0, swap it with the previous */ | 634 | /* if the current extent is in position 0, |
| 635 | swap it with the previous */ | ||
| 609 | if (!c && count != 1) { | 636 | if (!c && count != 1) { |
| 610 | laarr[2] = laarr[0]; | 637 | laarr[2] = laarr[0]; |
| 611 | laarr[0] = laarr[1]; | 638 | laarr[0] = laarr[1]; |
| @@ -613,44 +640,47 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 613 | c = 1; | 640 | c = 1; |
| 614 | } | 641 | } |
| 615 | 642 | ||
| 616 | /* if the current block is located in an extent, read the next extent */ | 643 | /* if the current block is located in an extent, |
| 617 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) { | 644 | read the next extent */ |
| 645 | etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0); | ||
| 646 | if (etype != -1) { | ||
| 618 | laarr[c + 1].extLength = (etype << 30) | elen; | 647 | laarr[c + 1].extLength = (etype << 30) | elen; |
| 619 | laarr[c + 1].extLocation = eloc; | 648 | laarr[c + 1].extLocation = eloc; |
| 620 | count++; | 649 | count++; |
| 621 | startnum++; | 650 | startnum++; |
| 622 | endnum++; | 651 | endnum++; |
| 623 | } else { | 652 | } else |
| 624 | lastblock = 1; | 653 | lastblock = 1; |
| 625 | } | ||
| 626 | } | 654 | } |
| 627 | 655 | ||
| 628 | /* if the current extent is not recorded but allocated, get the | 656 | /* if the current extent is not recorded but allocated, get the |
| 629 | * block in the extent corresponding to the requested block */ | 657 | * block in the extent corresponding to the requested block */ |
| 630 | if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 658 | if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) |
| 631 | newblocknum = laarr[c].extLocation.logicalBlockNum + offset; | 659 | newblocknum = laarr[c].extLocation.logicalBlockNum + offset; |
| 632 | } else { /* otherwise, allocate a new block */ | 660 | else { /* otherwise, allocate a new block */ |
| 633 | if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) | 661 | if (iinfo->i_next_alloc_block == block) |
| 634 | goal = UDF_I_NEXT_ALLOC_GOAL(inode); | 662 | goal = iinfo->i_next_alloc_goal; |
| 635 | 663 | ||
| 636 | if (!goal) { | 664 | if (!goal) { |
| 637 | if (!(goal = pgoal)) | 665 | if (!(goal = pgoal)) /* XXX: what was intended here? */ |
| 638 | goal = UDF_I_LOCATION(inode).logicalBlockNum + 1; | 666 | goal = iinfo->i_location.logicalBlockNum + 1; |
| 639 | } | 667 | } |
| 640 | 668 | ||
| 641 | if (!(newblocknum = udf_new_block(inode->i_sb, inode, | 669 | newblocknum = udf_new_block(inode->i_sb, inode, |
| 642 | UDF_I_LOCATION(inode).partitionReferenceNum, | 670 | iinfo->i_location.partitionReferenceNum, |
| 643 | goal, err))) { | 671 | goal, err); |
| 672 | if (!newblocknum) { | ||
| 644 | brelse(prev_epos.bh); | 673 | brelse(prev_epos.bh); |
| 645 | *err = -ENOSPC; | 674 | *err = -ENOSPC; |
| 646 | return NULL; | 675 | return NULL; |
| 647 | } | 676 | } |
| 648 | UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize; | 677 | iinfo->i_lenExtents += inode->i_sb->s_blocksize; |
| 649 | } | 678 | } |
| 650 | 679 | ||
| 651 | /* if the extent the requsted block is located in contains multiple blocks, | 680 | /* if the extent the requsted block is located in contains multiple |
| 652 | * split the extent into at most three extents. blocks prior to requested | 681 | * blocks, split the extent into at most three extents. blocks prior |
| 653 | * block, requested block, and blocks after requested block */ | 682 | * to requested block, requested block, and blocks after requested |
| 683 | * block */ | ||
| 654 | udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); | 684 | udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); |
| 655 | 685 | ||
| 656 | #ifdef UDF_PREALLOCATE | 686 | #ifdef UDF_PREALLOCATE |
| @@ -668,15 +698,15 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
| 668 | 698 | ||
| 669 | brelse(prev_epos.bh); | 699 | brelse(prev_epos.bh); |
| 670 | 700 | ||
| 671 | if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, | 701 | newblock = udf_get_pblock(inode->i_sb, newblocknum, |
| 672 | UDF_I_LOCATION(inode).partitionReferenceNum, 0))) { | 702 | iinfo->i_location.partitionReferenceNum, 0); |
| 703 | if (!newblock) | ||
| 673 | return NULL; | 704 | return NULL; |
| 674 | } | ||
| 675 | *phys = newblock; | 705 | *phys = newblock; |
| 676 | *err = 0; | 706 | *err = 0; |
| 677 | *new = 1; | 707 | *new = 1; |
| 678 | UDF_I_NEXT_ALLOC_BLOCK(inode) = block; | 708 | iinfo->i_next_alloc_block = block; |
| 679 | UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum; | 709 | iinfo->i_next_alloc_goal = newblocknum; |
| 680 | inode->i_ctime = current_fs_time(inode->i_sb); | 710 | inode->i_ctime = current_fs_time(inode->i_sb); |
| 681 | 711 | ||
| 682 | if (IS_SYNC(inode)) | 712 | if (IS_SYNC(inode)) |
| @@ -692,16 +722,20 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
| 692 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], | 722 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], |
| 693 | int *endnum) | 723 | int *endnum) |
| 694 | { | 724 | { |
| 725 | unsigned long blocksize = inode->i_sb->s_blocksize; | ||
| 726 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
| 727 | |||
| 695 | if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || | 728 | if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || |
| 696 | (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | 729 | (laarr[*c].extLength >> 30) == |
| 730 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | ||
| 697 | int curr = *c; | 731 | int curr = *c; |
| 698 | int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + | 732 | int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + |
| 699 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; | 733 | blocksize - 1) >> blocksize_bits; |
| 700 | int8_t etype = (laarr[curr].extLength >> 30); | 734 | int8_t etype = (laarr[curr].extLength >> 30); |
| 701 | 735 | ||
| 702 | if (blen == 1) { | 736 | if (blen == 1) |
| 703 | ; | 737 | ; |
| 704 | } else if (!offset || blen == offset + 1) { | 738 | else if (!offset || blen == offset + 1) { |
| 705 | laarr[curr + 2] = laarr[curr + 1]; | 739 | laarr[curr + 2] = laarr[curr + 1]; |
| 706 | laarr[curr + 1] = laarr[curr]; | 740 | laarr[curr + 1] = laarr[curr]; |
| 707 | } else { | 741 | } else { |
| @@ -711,15 +745,18 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
| 711 | 745 | ||
| 712 | if (offset) { | 746 | if (offset) { |
| 713 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 747 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 714 | udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); | 748 | udf_free_blocks(inode->i_sb, inode, |
| 715 | laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 749 | laarr[curr].extLocation, |
| 716 | (offset << inode->i_sb->s_blocksize_bits); | 750 | 0, offset); |
| 751 | laarr[curr].extLength = | ||
| 752 | EXT_NOT_RECORDED_NOT_ALLOCATED | | ||
| 753 | (offset << blocksize_bits); | ||
| 717 | laarr[curr].extLocation.logicalBlockNum = 0; | 754 | laarr[curr].extLocation.logicalBlockNum = 0; |
| 718 | laarr[curr].extLocation.partitionReferenceNum = 0; | 755 | laarr[curr].extLocation. |
| 719 | } else { | 756 | partitionReferenceNum = 0; |
| 757 | } else | ||
| 720 | laarr[curr].extLength = (etype << 30) | | 758 | laarr[curr].extLength = (etype << 30) | |
| 721 | (offset << inode->i_sb->s_blocksize_bits); | 759 | (offset << blocksize_bits); |
| 722 | } | ||
| 723 | curr++; | 760 | curr++; |
| 724 | (*c)++; | 761 | (*c)++; |
| 725 | (*endnum)++; | 762 | (*endnum)++; |
| @@ -728,16 +765,17 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
| 728 | laarr[curr].extLocation.logicalBlockNum = newblocknum; | 765 | laarr[curr].extLocation.logicalBlockNum = newblocknum; |
| 729 | if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) | 766 | if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) |
| 730 | laarr[curr].extLocation.partitionReferenceNum = | 767 | laarr[curr].extLocation.partitionReferenceNum = |
| 731 | UDF_I_LOCATION(inode).partitionReferenceNum; | 768 | UDF_I(inode)->i_location.partitionReferenceNum; |
| 732 | laarr[curr].extLength = EXT_RECORDED_ALLOCATED | | 769 | laarr[curr].extLength = EXT_RECORDED_ALLOCATED | |
| 733 | inode->i_sb->s_blocksize; | 770 | blocksize; |
| 734 | curr++; | 771 | curr++; |
| 735 | 772 | ||
| 736 | if (blen != offset + 1) { | 773 | if (blen != offset + 1) { |
| 737 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) | 774 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) |
| 738 | laarr[curr].extLocation.logicalBlockNum += (offset + 1); | 775 | laarr[curr].extLocation.logicalBlockNum += |
| 776 | offset + 1; | ||
| 739 | laarr[curr].extLength = (etype << 30) | | 777 | laarr[curr].extLength = (etype << 30) | |
| 740 | ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); | 778 | ((blen - (offset + 1)) << blocksize_bits); |
| 741 | curr++; | 779 | curr++; |
| 742 | (*endnum)++; | 780 | (*endnum)++; |
| 743 | } | 781 | } |
| @@ -756,69 +794,86 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock, | |||
| 756 | else | 794 | else |
| 757 | start = c; | 795 | start = c; |
| 758 | } else { | 796 | } else { |
| 759 | if ((laarr[c + 1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 797 | if ((laarr[c + 1].extLength >> 30) == |
| 798 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | ||
| 760 | start = c + 1; | 799 | start = c + 1; |
| 761 | length = currlength = (((laarr[c + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 800 | length = currlength = |
| 762 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 801 | (((laarr[c + 1].extLength & |
| 763 | } else { | 802 | UDF_EXTENT_LENGTH_MASK) + |
| 803 | inode->i_sb->s_blocksize - 1) >> | ||
| 804 | inode->i_sb->s_blocksize_bits); | ||
| 805 | } else | ||
| 764 | start = c; | 806 | start = c; |
| 765 | } | ||
| 766 | } | 807 | } |
| 767 | 808 | ||
| 768 | for (i = start + 1; i <= *endnum; i++) { | 809 | for (i = start + 1; i <= *endnum; i++) { |
| 769 | if (i == *endnum) { | 810 | if (i == *endnum) { |
| 770 | if (lastblock) | 811 | if (lastblock) |
| 771 | length += UDF_DEFAULT_PREALLOC_BLOCKS; | 812 | length += UDF_DEFAULT_PREALLOC_BLOCKS; |
| 772 | } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | 813 | } else if ((laarr[i].extLength >> 30) == |
| 773 | length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 814 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { |
| 774 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 815 | length += (((laarr[i].extLength & |
| 775 | } else { | 816 | UDF_EXTENT_LENGTH_MASK) + |
| 817 | inode->i_sb->s_blocksize - 1) >> | ||
| 818 | inode->i_sb->s_blocksize_bits); | ||
| 819 | } else | ||
| 776 | break; | 820 | break; |
| 777 | } | ||
| 778 | } | 821 | } |
| 779 | 822 | ||
| 780 | if (length) { | 823 | if (length) { |
| 781 | int next = laarr[start].extLocation.logicalBlockNum + | 824 | int next = laarr[start].extLocation.logicalBlockNum + |
| 782 | (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + | 825 | (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + |
| 783 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 826 | inode->i_sb->s_blocksize - 1) >> |
| 827 | inode->i_sb->s_blocksize_bits); | ||
| 784 | int numalloc = udf_prealloc_blocks(inode->i_sb, inode, | 828 | int numalloc = udf_prealloc_blocks(inode->i_sb, inode, |
| 785 | laarr[start].extLocation.partitionReferenceNum, | 829 | laarr[start].extLocation.partitionReferenceNum, |
| 786 | next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length : | 830 | next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? |
| 787 | UDF_DEFAULT_PREALLOC_BLOCKS) - currlength); | 831 | length : UDF_DEFAULT_PREALLOC_BLOCKS) - |
| 832 | currlength); | ||
| 788 | if (numalloc) { | 833 | if (numalloc) { |
| 789 | if (start == (c + 1)) { | 834 | if (start == (c + 1)) |
| 790 | laarr[start].extLength += | 835 | laarr[start].extLength += |
| 791 | (numalloc << inode->i_sb->s_blocksize_bits); | 836 | (numalloc << |
| 792 | } else { | 837 | inode->i_sb->s_blocksize_bits); |
| 838 | else { | ||
| 793 | memmove(&laarr[c + 2], &laarr[c + 1], | 839 | memmove(&laarr[c + 2], &laarr[c + 1], |
| 794 | sizeof(long_ad) * (*endnum - (c + 1))); | 840 | sizeof(long_ad) * (*endnum - (c + 1))); |
| 795 | (*endnum)++; | 841 | (*endnum)++; |
| 796 | laarr[c + 1].extLocation.logicalBlockNum = next; | 842 | laarr[c + 1].extLocation.logicalBlockNum = next; |
| 797 | laarr[c + 1].extLocation.partitionReferenceNum = | 843 | laarr[c + 1].extLocation.partitionReferenceNum = |
| 798 | laarr[c].extLocation.partitionReferenceNum; | 844 | laarr[c].extLocation. |
| 799 | laarr[c + 1].extLength = EXT_NOT_RECORDED_ALLOCATED | | 845 | partitionReferenceNum; |
| 800 | (numalloc << inode->i_sb->s_blocksize_bits); | 846 | laarr[c + 1].extLength = |
| 847 | EXT_NOT_RECORDED_ALLOCATED | | ||
| 848 | (numalloc << | ||
| 849 | inode->i_sb->s_blocksize_bits); | ||
| 801 | start = c + 1; | 850 | start = c + 1; |
| 802 | } | 851 | } |
| 803 | 852 | ||
| 804 | for (i = start + 1; numalloc && i < *endnum; i++) { | 853 | for (i = start + 1; numalloc && i < *endnum; i++) { |
| 805 | int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 854 | int elen = ((laarr[i].extLength & |
| 806 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; | 855 | UDF_EXTENT_LENGTH_MASK) + |
| 856 | inode->i_sb->s_blocksize - 1) >> | ||
| 857 | inode->i_sb->s_blocksize_bits; | ||
| 807 | 858 | ||
| 808 | if (elen > numalloc) { | 859 | if (elen > numalloc) { |
| 809 | laarr[i].extLength -= | 860 | laarr[i].extLength -= |
| 810 | (numalloc << inode->i_sb->s_blocksize_bits); | 861 | (numalloc << |
| 862 | inode->i_sb->s_blocksize_bits); | ||
| 811 | numalloc = 0; | 863 | numalloc = 0; |
| 812 | } else { | 864 | } else { |
| 813 | numalloc -= elen; | 865 | numalloc -= elen; |
| 814 | if (*endnum > (i + 1)) | 866 | if (*endnum > (i + 1)) |
| 815 | memmove(&laarr[i], &laarr[i + 1], | 867 | memmove(&laarr[i], |
| 816 | sizeof(long_ad) * (*endnum - (i + 1))); | 868 | &laarr[i + 1], |
| 869 | sizeof(long_ad) * | ||
| 870 | (*endnum - (i + 1))); | ||
| 817 | i--; | 871 | i--; |
| 818 | (*endnum)--; | 872 | (*endnum)--; |
| 819 | } | 873 | } |
| 820 | } | 874 | } |
| 821 | UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits; | 875 | UDF_I(inode)->i_lenExtents += |
| 876 | numalloc << inode->i_sb->s_blocksize_bits; | ||
| 822 | } | 877 | } |
| 823 | } | 878 | } |
| 824 | } | 879 | } |
| @@ -828,70 +883,97 @@ static void udf_merge_extents(struct inode *inode, | |||
| 828 | int *endnum) | 883 | int *endnum) |
| 829 | { | 884 | { |
| 830 | int i; | 885 | int i; |
| 886 | unsigned long blocksize = inode->i_sb->s_blocksize; | ||
| 887 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
| 831 | 888 | ||
| 832 | for (i = 0; i < (*endnum - 1); i++) { | 889 | for (i = 0; i < (*endnum - 1); i++) { |
| 833 | if ((laarr[i].extLength >> 30) == (laarr[i + 1].extLength >> 30)) { | 890 | kernel_long_ad *li /*l[i]*/ = &laarr[i]; |
| 834 | if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || | 891 | kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1]; |
| 835 | ((laarr[i + 1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) == | 892 | |
| 836 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 893 | if (((li->extLength >> 30) == (lip1->extLength >> 30)) && |
| 837 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) { | 894 | (((li->extLength >> 30) == |
| 838 | if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 895 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || |
| 839 | (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 896 | ((lip1->extLocation.logicalBlockNum - |
| 840 | inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { | 897 | li->extLocation.logicalBlockNum) == |
| 841 | laarr[i + 1].extLength = (laarr[i + 1].extLength - | 898 | (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 842 | (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 899 | blocksize - 1) >> blocksize_bits)))) { |
| 843 | UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1); | 900 | |
| 844 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + | 901 | if (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 845 | (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; | 902 | (lip1->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 846 | laarr[i + 1].extLocation.logicalBlockNum = | 903 | blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { |
| 847 | laarr[i].extLocation.logicalBlockNum + | 904 | lip1->extLength = (lip1->extLength - |
| 848 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >> | 905 | (li->extLength & |
| 849 | inode->i_sb->s_blocksize_bits); | 906 | UDF_EXTENT_LENGTH_MASK) + |
| 850 | } else { | 907 | UDF_EXTENT_LENGTH_MASK) & |
| 851 | laarr[i].extLength = laarr[i + 1].extLength + | 908 | ~(blocksize - 1); |
| 852 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 909 | li->extLength = (li->extLength & |
| 853 | inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1)); | 910 | UDF_EXTENT_FLAG_MASK) + |
| 854 | if (*endnum > (i + 2)) | 911 | (UDF_EXTENT_LENGTH_MASK + 1) - |
| 855 | memmove(&laarr[i + 1], &laarr[i + 2], | 912 | blocksize; |
| 856 | sizeof(long_ad) * (*endnum - (i + 2))); | 913 | lip1->extLocation.logicalBlockNum = |
| 857 | i--; | 914 | li->extLocation.logicalBlockNum + |
| 858 | (*endnum)--; | 915 | ((li->extLength & |
| 859 | } | 916 | UDF_EXTENT_LENGTH_MASK) >> |
| 917 | blocksize_bits); | ||
| 918 | } else { | ||
| 919 | li->extLength = lip1->extLength + | ||
| 920 | (((li->extLength & | ||
| 921 | UDF_EXTENT_LENGTH_MASK) + | ||
| 922 | blocksize - 1) & ~(blocksize - 1)); | ||
| 923 | if (*endnum > (i + 2)) | ||
| 924 | memmove(&laarr[i + 1], &laarr[i + 2], | ||
| 925 | sizeof(long_ad) * | ||
| 926 | (*endnum - (i + 2))); | ||
| 927 | i--; | ||
| 928 | (*endnum)--; | ||
| 860 | } | 929 | } |
| 861 | } else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) && | 930 | } else if (((li->extLength >> 30) == |
| 862 | ((laarr[i + 1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) { | 931 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) && |
| 863 | udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, | 932 | ((lip1->extLength >> 30) == |
| 864 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 933 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) { |
| 865 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 934 | udf_free_blocks(inode->i_sb, inode, li->extLocation, 0, |
| 866 | laarr[i].extLocation.logicalBlockNum = 0; | 935 | ((li->extLength & |
| 867 | laarr[i].extLocation.partitionReferenceNum = 0; | 936 | UDF_EXTENT_LENGTH_MASK) + |
| 868 | 937 | blocksize - 1) >> blocksize_bits); | |
| 869 | if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 938 | li->extLocation.logicalBlockNum = 0; |
| 870 | (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 939 | li->extLocation.partitionReferenceNum = 0; |
| 871 | inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { | 940 | |
| 872 | laarr[i + 1].extLength = (laarr[i + 1].extLength - | 941 | if (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 873 | (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 942 | (lip1->extLength & UDF_EXTENT_LENGTH_MASK) + |
| 874 | UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1); | 943 | blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { |
| 875 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + | 944 | lip1->extLength = (lip1->extLength - |
| 876 | (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; | 945 | (li->extLength & |
| 946 | UDF_EXTENT_LENGTH_MASK) + | ||
| 947 | UDF_EXTENT_LENGTH_MASK) & | ||
| 948 | ~(blocksize - 1); | ||
| 949 | li->extLength = (li->extLength & | ||
| 950 | UDF_EXTENT_FLAG_MASK) + | ||
| 951 | (UDF_EXTENT_LENGTH_MASK + 1) - | ||
| 952 | blocksize; | ||
| 877 | } else { | 953 | } else { |
| 878 | laarr[i].extLength = laarr[i + 1].extLength + | 954 | li->extLength = lip1->extLength + |
| 879 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 955 | (((li->extLength & |
| 880 | inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1)); | 956 | UDF_EXTENT_LENGTH_MASK) + |
| 957 | blocksize - 1) & ~(blocksize - 1)); | ||
| 881 | if (*endnum > (i + 2)) | 958 | if (*endnum > (i + 2)) |
| 882 | memmove(&laarr[i + 1], &laarr[i + 2], | 959 | memmove(&laarr[i + 1], &laarr[i + 2], |
| 883 | sizeof(long_ad) * (*endnum - (i + 2))); | 960 | sizeof(long_ad) * |
| 961 | (*endnum - (i + 2))); | ||
| 884 | i--; | 962 | i--; |
| 885 | (*endnum)--; | 963 | (*endnum)--; |
| 886 | } | 964 | } |
| 887 | } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 965 | } else if ((li->extLength >> 30) == |
| 888 | udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, | 966 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 889 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 967 | udf_free_blocks(inode->i_sb, inode, |
| 890 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 968 | li->extLocation, 0, |
| 891 | laarr[i].extLocation.logicalBlockNum = 0; | 969 | ((li->extLength & |
| 892 | laarr[i].extLocation.partitionReferenceNum = 0; | 970 | UDF_EXTENT_LENGTH_MASK) + |
| 893 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) | | 971 | blocksize - 1) >> blocksize_bits); |
| 894 | EXT_NOT_RECORDED_NOT_ALLOCATED; | 972 | li->extLocation.logicalBlockNum = 0; |
| 973 | li->extLocation.partitionReferenceNum = 0; | ||
| 974 | li->extLength = (li->extLength & | ||
| 975 | UDF_EXTENT_LENGTH_MASK) | | ||
| 976 | EXT_NOT_RECORDED_NOT_ALLOCATED; | ||
| 895 | } | 977 | } |
| 896 | } | 978 | } |
| 897 | } | 979 | } |
| @@ -953,6 +1035,7 @@ void udf_truncate(struct inode *inode) | |||
| 953 | { | 1035 | { |
| 954 | int offset; | 1036 | int offset; |
| 955 | int err; | 1037 | int err; |
| 1038 | struct udf_inode_info *iinfo; | ||
| 956 | 1039 | ||
| 957 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | 1040 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || |
| 958 | S_ISLNK(inode->i_mode))) | 1041 | S_ISLNK(inode->i_mode))) |
| @@ -961,25 +1044,28 @@ void udf_truncate(struct inode *inode) | |||
| 961 | return; | 1044 | return; |
| 962 | 1045 | ||
| 963 | lock_kernel(); | 1046 | lock_kernel(); |
| 964 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1047 | iinfo = UDF_I(inode); |
| 965 | if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + | 1048 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 966 | inode->i_size)) { | 1049 | if (inode->i_sb->s_blocksize < |
| 1050 | (udf_file_entry_alloc_offset(inode) + | ||
| 1051 | inode->i_size)) { | ||
| 967 | udf_expand_file_adinicb(inode, inode->i_size, &err); | 1052 | udf_expand_file_adinicb(inode, inode->i_size, &err); |
| 968 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1053 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 969 | inode->i_size = UDF_I_LENALLOC(inode); | 1054 | inode->i_size = iinfo->i_lenAlloc; |
| 970 | unlock_kernel(); | 1055 | unlock_kernel(); |
| 971 | return; | 1056 | return; |
| 972 | } else { | 1057 | } else |
| 973 | udf_truncate_extents(inode); | 1058 | udf_truncate_extents(inode); |
| 974 | } | ||
| 975 | } else { | 1059 | } else { |
| 976 | offset = inode->i_size & (inode->i_sb->s_blocksize - 1); | 1060 | offset = inode->i_size & (inode->i_sb->s_blocksize - 1); |
| 977 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, | 1061 | memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset, |
| 978 | inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode)); | 1062 | 0x00, inode->i_sb->s_blocksize - |
| 979 | UDF_I_LENALLOC(inode) = inode->i_size; | 1063 | offset - udf_file_entry_alloc_offset(inode)); |
| 1064 | iinfo->i_lenAlloc = inode->i_size; | ||
| 980 | } | 1065 | } |
| 981 | } else { | 1066 | } else { |
| 982 | block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block); | 1067 | block_truncate_page(inode->i_mapping, inode->i_size, |
| 1068 | udf_get_block); | ||
| 983 | udf_truncate_extents(inode); | 1069 | udf_truncate_extents(inode); |
| 984 | } | 1070 | } |
| 985 | 1071 | ||
| @@ -996,6 +1082,7 @@ static void __udf_read_inode(struct inode *inode) | |||
| 996 | struct buffer_head *bh = NULL; | 1082 | struct buffer_head *bh = NULL; |
| 997 | struct fileEntry *fe; | 1083 | struct fileEntry *fe; |
| 998 | uint16_t ident; | 1084 | uint16_t ident; |
| 1085 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 999 | 1086 | ||
| 1000 | /* | 1087 | /* |
| 1001 | * Set defaults, but the inode is still incomplete! | 1088 | * Set defaults, but the inode is still incomplete! |
| @@ -1009,7 +1096,7 @@ static void __udf_read_inode(struct inode *inode) | |||
| 1009 | * i_nlink = 1 | 1096 | * i_nlink = 1 |
| 1010 | * i_op = NULL; | 1097 | * i_op = NULL; |
| 1011 | */ | 1098 | */ |
| 1012 | bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident); | 1099 | bh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 0, &ident); |
| 1013 | if (!bh) { | 1100 | if (!bh) { |
| 1014 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", | 1101 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", |
| 1015 | inode->i_ino); | 1102 | inode->i_ino); |
| @@ -1019,8 +1106,8 @@ static void __udf_read_inode(struct inode *inode) | |||
| 1019 | 1106 | ||
| 1020 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && | 1107 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && |
| 1021 | ident != TAG_IDENT_USE) { | 1108 | ident != TAG_IDENT_USE) { |
| 1022 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", | 1109 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) " |
| 1023 | inode->i_ino, ident); | 1110 | "failed ident=%d\n", inode->i_ino, ident); |
| 1024 | brelse(bh); | 1111 | brelse(bh); |
| 1025 | make_bad_inode(inode); | 1112 | make_bad_inode(inode); |
| 1026 | return; | 1113 | return; |
| @@ -1028,11 +1115,12 @@ static void __udf_read_inode(struct inode *inode) | |||
| 1028 | 1115 | ||
| 1029 | fe = (struct fileEntry *)bh->b_data; | 1116 | fe = (struct fileEntry *)bh->b_data; |
| 1030 | 1117 | ||
| 1031 | if (le16_to_cpu(fe->icbTag.strategyType) == 4096) { | 1118 | if (fe->icbTag.strategyType == cpu_to_le16(4096)) { |
| 1032 | struct buffer_head *ibh = NULL, *nbh = NULL; | 1119 | struct buffer_head *ibh = NULL, *nbh = NULL; |
| 1033 | struct indirectEntry *ie; | 1120 | struct indirectEntry *ie; |
| 1034 | 1121 | ||
| 1035 | ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident); | 1122 | ibh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 1, |
| 1123 | &ident); | ||
| 1036 | if (ident == TAG_IDENT_IE) { | 1124 | if (ident == TAG_IDENT_IE) { |
| 1037 | if (ibh) { | 1125 | if (ibh) { |
| 1038 | kernel_lb_addr loc; | 1126 | kernel_lb_addr loc; |
| @@ -1041,10 +1129,12 @@ static void __udf_read_inode(struct inode *inode) | |||
| 1041 | loc = lelb_to_cpu(ie->indirectICB.extLocation); | 1129 | loc = lelb_to_cpu(ie->indirectICB.extLocation); |
| 1042 | 1130 | ||
| 1043 | if (ie->indirectICB.extLength && | 1131 | if (ie->indirectICB.extLength && |
| 1044 | (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) { | 1132 | (nbh = udf_read_ptagged(inode->i_sb, loc, 0, |
| 1133 | &ident))) { | ||
| 1045 | if (ident == TAG_IDENT_FE || | 1134 | if (ident == TAG_IDENT_FE || |
| 1046 | ident == TAG_IDENT_EFE) { | 1135 | ident == TAG_IDENT_EFE) { |
| 1047 | memcpy(&UDF_I_LOCATION(inode), &loc, | 1136 | memcpy(&iinfo->i_location, |
| 1137 | &loc, | ||
| 1048 | sizeof(kernel_lb_addr)); | 1138 | sizeof(kernel_lb_addr)); |
| 1049 | brelse(bh); | 1139 | brelse(bh); |
| 1050 | brelse(ibh); | 1140 | brelse(ibh); |
| @@ -1062,7 +1152,7 @@ static void __udf_read_inode(struct inode *inode) | |||
| 1062 | } else { | 1152 | } else { |
| 1063 | brelse(ibh); | 1153 | brelse(ibh); |
| 1064 | } | 1154 | } |
| 1065 | } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) { | 1155 | } else if (fe->icbTag.strategyType != cpu_to_le16(4)) { |
| 1066 | printk(KERN_ERR "udf: unsupported strategy type: %d\n", | 1156 | printk(KERN_ERR "udf: unsupported strategy type: %d\n", |
| 1067 | le16_to_cpu(fe->icbTag.strategyType)); | 1157 | le16_to_cpu(fe->icbTag.strategyType)); |
| 1068 | brelse(bh); | 1158 | brelse(bh); |
| @@ -1081,51 +1171,63 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1081 | time_t convtime; | 1171 | time_t convtime; |
| 1082 | long convtime_usec; | 1172 | long convtime_usec; |
| 1083 | int offset; | 1173 | int offset; |
| 1174 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | ||
| 1175 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 1084 | 1176 | ||
| 1085 | fe = (struct fileEntry *)bh->b_data; | 1177 | fe = (struct fileEntry *)bh->b_data; |
| 1086 | efe = (struct extendedFileEntry *)bh->b_data; | 1178 | efe = (struct extendedFileEntry *)bh->b_data; |
| 1087 | 1179 | ||
| 1088 | if (le16_to_cpu(fe->icbTag.strategyType) == 4) | 1180 | if (fe->icbTag.strategyType == cpu_to_le16(4)) |
| 1089 | UDF_I_STRAT4096(inode) = 0; | 1181 | iinfo->i_strat4096 = 0; |
| 1090 | else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ | 1182 | else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */ |
| 1091 | UDF_I_STRAT4096(inode) = 1; | 1183 | iinfo->i_strat4096 = 1; |
| 1092 | 1184 | ||
| 1093 | UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK; | 1185 | iinfo->i_alloc_type = le16_to_cpu(fe->icbTag.flags) & |
| 1094 | UDF_I_UNIQUE(inode) = 0; | 1186 | ICBTAG_FLAG_AD_MASK; |
| 1095 | UDF_I_LENEATTR(inode) = 0; | 1187 | iinfo->i_unique = 0; |
| 1096 | UDF_I_LENEXTENTS(inode) = 0; | 1188 | iinfo->i_lenEAttr = 0; |
| 1097 | UDF_I_LENALLOC(inode) = 0; | 1189 | iinfo->i_lenExtents = 0; |
| 1098 | UDF_I_NEXT_ALLOC_BLOCK(inode) = 0; | 1190 | iinfo->i_lenAlloc = 0; |
| 1099 | UDF_I_NEXT_ALLOC_GOAL(inode) = 0; | 1191 | iinfo->i_next_alloc_block = 0; |
| 1100 | if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) { | 1192 | iinfo->i_next_alloc_goal = 0; |
| 1101 | UDF_I_EFE(inode) = 1; | 1193 | if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) { |
| 1102 | UDF_I_USE(inode) = 0; | 1194 | iinfo->i_efe = 1; |
| 1103 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) { | 1195 | iinfo->i_use = 0; |
| 1196 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | ||
| 1197 | sizeof(struct extendedFileEntry))) { | ||
| 1104 | make_bad_inode(inode); | 1198 | make_bad_inode(inode); |
| 1105 | return; | 1199 | return; |
| 1106 | } | 1200 | } |
| 1107 | memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), | 1201 | memcpy(iinfo->i_ext.i_data, |
| 1108 | inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); | 1202 | bh->b_data + sizeof(struct extendedFileEntry), |
| 1109 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) { | 1203 | inode->i_sb->s_blocksize - |
| 1110 | UDF_I_EFE(inode) = 0; | 1204 | sizeof(struct extendedFileEntry)); |
| 1111 | UDF_I_USE(inode) = 0; | 1205 | } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) { |
| 1112 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) { | 1206 | iinfo->i_efe = 0; |
| 1207 | iinfo->i_use = 0; | ||
| 1208 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | ||
| 1209 | sizeof(struct fileEntry))) { | ||
| 1113 | make_bad_inode(inode); | 1210 | make_bad_inode(inode); |
| 1114 | return; | 1211 | return; |
| 1115 | } | 1212 | } |
| 1116 | memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), | 1213 | memcpy(iinfo->i_ext.i_data, |
| 1214 | bh->b_data + sizeof(struct fileEntry), | ||
| 1117 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); | 1215 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); |
| 1118 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) { | 1216 | } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) { |
| 1119 | UDF_I_EFE(inode) = 0; | 1217 | iinfo->i_efe = 0; |
| 1120 | UDF_I_USE(inode) = 1; | 1218 | iinfo->i_use = 1; |
| 1121 | UDF_I_LENALLOC(inode) = | 1219 | iinfo->i_lenAlloc = le32_to_cpu( |
| 1122 | le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs); | 1220 | ((struct unallocSpaceEntry *)bh->b_data)-> |
| 1123 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) { | 1221 | lengthAllocDescs); |
| 1222 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | ||
| 1223 | sizeof(struct unallocSpaceEntry))) { | ||
| 1124 | make_bad_inode(inode); | 1224 | make_bad_inode(inode); |
| 1125 | return; | 1225 | return; |
| 1126 | } | 1226 | } |
| 1127 | memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), | 1227 | memcpy(iinfo->i_ext.i_data, |
| 1128 | inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); | 1228 | bh->b_data + sizeof(struct unallocSpaceEntry), |
| 1229 | inode->i_sb->s_blocksize - | ||
| 1230 | sizeof(struct unallocSpaceEntry)); | ||
| 1129 | return; | 1231 | return; |
| 1130 | } | 1232 | } |
| 1131 | 1233 | ||
| @@ -1146,12 +1248,12 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1146 | inode->i_nlink = 1; | 1248 | inode->i_nlink = 1; |
| 1147 | 1249 | ||
| 1148 | inode->i_size = le64_to_cpu(fe->informationLength); | 1250 | inode->i_size = le64_to_cpu(fe->informationLength); |
| 1149 | UDF_I_LENEXTENTS(inode) = inode->i_size; | 1251 | iinfo->i_lenExtents = inode->i_size; |
| 1150 | 1252 | ||
| 1151 | inode->i_mode = udf_convert_permissions(fe); | 1253 | inode->i_mode = udf_convert_permissions(fe); |
| 1152 | inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask; | 1254 | inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask; |
| 1153 | 1255 | ||
| 1154 | if (UDF_I_EFE(inode) == 0) { | 1256 | if (iinfo->i_efe == 0) { |
| 1155 | inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << | 1257 | inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << |
| 1156 | (inode->i_sb->s_blocksize_bits - 9); | 1258 | (inode->i_sb->s_blocksize_bits - 9); |
| 1157 | 1259 | ||
| @@ -1160,7 +1262,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1160 | inode->i_atime.tv_sec = convtime; | 1262 | inode->i_atime.tv_sec = convtime; |
| 1161 | inode->i_atime.tv_nsec = convtime_usec * 1000; | 1263 | inode->i_atime.tv_nsec = convtime_usec * 1000; |
| 1162 | } else { | 1264 | } else { |
| 1163 | inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); | 1265 | inode->i_atime = sbi->s_record_time; |
| 1164 | } | 1266 | } |
| 1165 | 1267 | ||
| 1166 | if (udf_stamp_to_time(&convtime, &convtime_usec, | 1268 | if (udf_stamp_to_time(&convtime, &convtime_usec, |
| @@ -1168,7 +1270,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1168 | inode->i_mtime.tv_sec = convtime; | 1270 | inode->i_mtime.tv_sec = convtime; |
| 1169 | inode->i_mtime.tv_nsec = convtime_usec * 1000; | 1271 | inode->i_mtime.tv_nsec = convtime_usec * 1000; |
| 1170 | } else { | 1272 | } else { |
| 1171 | inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); | 1273 | inode->i_mtime = sbi->s_record_time; |
| 1172 | } | 1274 | } |
| 1173 | 1275 | ||
| 1174 | if (udf_stamp_to_time(&convtime, &convtime_usec, | 1276 | if (udf_stamp_to_time(&convtime, &convtime_usec, |
| @@ -1176,13 +1278,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1176 | inode->i_ctime.tv_sec = convtime; | 1278 | inode->i_ctime.tv_sec = convtime; |
| 1177 | inode->i_ctime.tv_nsec = convtime_usec * 1000; | 1279 | inode->i_ctime.tv_nsec = convtime_usec * 1000; |
| 1178 | } else { | 1280 | } else { |
| 1179 | inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); | 1281 | inode->i_ctime = sbi->s_record_time; |
| 1180 | } | 1282 | } |
| 1181 | 1283 | ||
| 1182 | UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID); | 1284 | iinfo->i_unique = le64_to_cpu(fe->uniqueID); |
| 1183 | UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr); | 1285 | iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr); |
| 1184 | UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs); | 1286 | iinfo->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs); |
| 1185 | offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode); | 1287 | offset = sizeof(struct fileEntry) + iinfo->i_lenEAttr; |
| 1186 | } else { | 1288 | } else { |
| 1187 | inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << | 1289 | inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << |
| 1188 | (inode->i_sb->s_blocksize_bits - 9); | 1290 | (inode->i_sb->s_blocksize_bits - 9); |
| @@ -1192,7 +1294,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1192 | inode->i_atime.tv_sec = convtime; | 1294 | inode->i_atime.tv_sec = convtime; |
| 1193 | inode->i_atime.tv_nsec = convtime_usec * 1000; | 1295 | inode->i_atime.tv_nsec = convtime_usec * 1000; |
| 1194 | } else { | 1296 | } else { |
| 1195 | inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); | 1297 | inode->i_atime = sbi->s_record_time; |
| 1196 | } | 1298 | } |
| 1197 | 1299 | ||
| 1198 | if (udf_stamp_to_time(&convtime, &convtime_usec, | 1300 | if (udf_stamp_to_time(&convtime, &convtime_usec, |
| @@ -1200,15 +1302,15 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1200 | inode->i_mtime.tv_sec = convtime; | 1302 | inode->i_mtime.tv_sec = convtime; |
| 1201 | inode->i_mtime.tv_nsec = convtime_usec * 1000; | 1303 | inode->i_mtime.tv_nsec = convtime_usec * 1000; |
| 1202 | } else { | 1304 | } else { |
| 1203 | inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); | 1305 | inode->i_mtime = sbi->s_record_time; |
| 1204 | } | 1306 | } |
| 1205 | 1307 | ||
| 1206 | if (udf_stamp_to_time(&convtime, &convtime_usec, | 1308 | if (udf_stamp_to_time(&convtime, &convtime_usec, |
| 1207 | lets_to_cpu(efe->createTime))) { | 1309 | lets_to_cpu(efe->createTime))) { |
| 1208 | UDF_I_CRTIME(inode).tv_sec = convtime; | 1310 | iinfo->i_crtime.tv_sec = convtime; |
| 1209 | UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000; | 1311 | iinfo->i_crtime.tv_nsec = convtime_usec * 1000; |
| 1210 | } else { | 1312 | } else { |
| 1211 | UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb); | 1313 | iinfo->i_crtime = sbi->s_record_time; |
| 1212 | } | 1314 | } |
| 1213 | 1315 | ||
| 1214 | if (udf_stamp_to_time(&convtime, &convtime_usec, | 1316 | if (udf_stamp_to_time(&convtime, &convtime_usec, |
| @@ -1216,13 +1318,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1216 | inode->i_ctime.tv_sec = convtime; | 1318 | inode->i_ctime.tv_sec = convtime; |
| 1217 | inode->i_ctime.tv_nsec = convtime_usec * 1000; | 1319 | inode->i_ctime.tv_nsec = convtime_usec * 1000; |
| 1218 | } else { | 1320 | } else { |
| 1219 | inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); | 1321 | inode->i_ctime = sbi->s_record_time; |
| 1220 | } | 1322 | } |
| 1221 | 1323 | ||
| 1222 | UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); | 1324 | iinfo->i_unique = le64_to_cpu(efe->uniqueID); |
| 1223 | UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); | 1325 | iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr); |
| 1224 | UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); | 1326 | iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs); |
| 1225 | offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode); | 1327 | offset = sizeof(struct extendedFileEntry) + |
| 1328 | iinfo->i_lenEAttr; | ||
| 1226 | } | 1329 | } |
| 1227 | 1330 | ||
| 1228 | switch (fe->icbTag.fileType) { | 1331 | switch (fe->icbTag.fileType) { |
| @@ -1235,7 +1338,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1235 | case ICBTAG_FILE_TYPE_REALTIME: | 1338 | case ICBTAG_FILE_TYPE_REALTIME: |
| 1236 | case ICBTAG_FILE_TYPE_REGULAR: | 1339 | case ICBTAG_FILE_TYPE_REGULAR: |
| 1237 | case ICBTAG_FILE_TYPE_UNDEF: | 1340 | case ICBTAG_FILE_TYPE_UNDEF: |
| 1238 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) | 1341 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1239 | inode->i_data.a_ops = &udf_adinicb_aops; | 1342 | inode->i_data.a_ops = &udf_adinicb_aops; |
| 1240 | else | 1343 | else |
| 1241 | inode->i_data.a_ops = &udf_aops; | 1344 | inode->i_data.a_ops = &udf_aops; |
| @@ -1261,31 +1364,33 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
| 1261 | inode->i_mode = S_IFLNK | S_IRWXUGO; | 1364 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
| 1262 | break; | 1365 | break; |
| 1263 | default: | 1366 | default: |
| 1264 | printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n", | 1367 | printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown " |
| 1265 | inode->i_ino, fe->icbTag.fileType); | 1368 | "file type=%d\n", inode->i_ino, |
| 1369 | fe->icbTag.fileType); | ||
| 1266 | make_bad_inode(inode); | 1370 | make_bad_inode(inode); |
| 1267 | return; | 1371 | return; |
| 1268 | } | 1372 | } |
| 1269 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { | 1373 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { |
| 1270 | struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1); | 1374 | struct deviceSpec *dsea = |
| 1375 | (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1); | ||
| 1271 | if (dsea) { | 1376 | if (dsea) { |
| 1272 | init_special_inode(inode, inode->i_mode, | 1377 | init_special_inode(inode, inode->i_mode, |
| 1273 | MKDEV(le32_to_cpu(dsea->majorDeviceIdent), | 1378 | MKDEV(le32_to_cpu(dsea->majorDeviceIdent), |
| 1274 | le32_to_cpu(dsea->minorDeviceIdent))); | 1379 | le32_to_cpu(dsea->minorDeviceIdent))); |
| 1275 | /* Developer ID ??? */ | 1380 | /* Developer ID ??? */ |
| 1276 | } else { | 1381 | } else |
| 1277 | make_bad_inode(inode); | 1382 | make_bad_inode(inode); |
| 1278 | } | ||
| 1279 | } | 1383 | } |
| 1280 | } | 1384 | } |
| 1281 | 1385 | ||
| 1282 | static int udf_alloc_i_data(struct inode *inode, size_t size) | 1386 | static int udf_alloc_i_data(struct inode *inode, size_t size) |
| 1283 | { | 1387 | { |
| 1284 | UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); | 1388 | struct udf_inode_info *iinfo = UDF_I(inode); |
| 1389 | iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL); | ||
| 1285 | 1390 | ||
| 1286 | if (!UDF_I_DATA(inode)) { | 1391 | if (!iinfo->i_ext.i_data) { |
| 1287 | printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n", | 1392 | printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) " |
| 1288 | inode->i_ino); | 1393 | "no free memory\n", inode->i_ino); |
| 1289 | return -ENOMEM; | 1394 | return -ENOMEM; |
| 1290 | } | 1395 | } |
| 1291 | 1396 | ||
| @@ -1301,12 +1406,12 @@ static mode_t udf_convert_permissions(struct fileEntry *fe) | |||
| 1301 | permissions = le32_to_cpu(fe->permissions); | 1406 | permissions = le32_to_cpu(fe->permissions); |
| 1302 | flags = le16_to_cpu(fe->icbTag.flags); | 1407 | flags = le16_to_cpu(fe->icbTag.flags); |
| 1303 | 1408 | ||
| 1304 | mode = (( permissions ) & S_IRWXO) | | 1409 | mode = ((permissions) & S_IRWXO) | |
| 1305 | (( permissions >> 2 ) & S_IRWXG) | | 1410 | ((permissions >> 2) & S_IRWXG) | |
| 1306 | (( permissions >> 4 ) & S_IRWXU) | | 1411 | ((permissions >> 4) & S_IRWXU) | |
| 1307 | (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | | 1412 | ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | |
| 1308 | (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | | 1413 | ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | |
| 1309 | (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); | 1414 | ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); |
| 1310 | 1415 | ||
| 1311 | return mode; | 1416 | return mode; |
| 1312 | } | 1417 | } |
| @@ -1350,11 +1455,15 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1350 | uint32_t udfperms; | 1455 | uint32_t udfperms; |
| 1351 | uint16_t icbflags; | 1456 | uint16_t icbflags; |
| 1352 | uint16_t crclen; | 1457 | uint16_t crclen; |
| 1353 | int i; | ||
| 1354 | kernel_timestamp cpu_time; | 1458 | kernel_timestamp cpu_time; |
| 1355 | int err = 0; | 1459 | int err = 0; |
| 1460 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | ||
| 1461 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
| 1462 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 1356 | 1463 | ||
| 1357 | bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0)); | 1464 | bh = udf_tread(inode->i_sb, |
| 1465 | udf_get_lb_pblock(inode->i_sb, | ||
| 1466 | iinfo->i_location, 0)); | ||
| 1358 | if (!bh) { | 1467 | if (!bh) { |
| 1359 | udf_debug("bread failure\n"); | 1468 | udf_debug("bread failure\n"); |
| 1360 | return -EIO; | 1469 | return -EIO; |
| @@ -1365,23 +1474,24 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1365 | fe = (struct fileEntry *)bh->b_data; | 1474 | fe = (struct fileEntry *)bh->b_data; |
| 1366 | efe = (struct extendedFileEntry *)bh->b_data; | 1475 | efe = (struct extendedFileEntry *)bh->b_data; |
| 1367 | 1476 | ||
| 1368 | if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) { | 1477 | if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) { |
| 1369 | struct unallocSpaceEntry *use = | 1478 | struct unallocSpaceEntry *use = |
| 1370 | (struct unallocSpaceEntry *)bh->b_data; | 1479 | (struct unallocSpaceEntry *)bh->b_data; |
| 1371 | 1480 | ||
| 1372 | use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); | 1481 | use->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc); |
| 1373 | memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), | 1482 | memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), |
| 1374 | inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); | 1483 | iinfo->i_ext.i_data, inode->i_sb->s_blocksize - |
| 1375 | crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - sizeof(tag); | 1484 | sizeof(struct unallocSpaceEntry)); |
| 1376 | use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); | 1485 | crclen = sizeof(struct unallocSpaceEntry) + |
| 1486 | iinfo->i_lenAlloc - sizeof(tag); | ||
| 1487 | use->descTag.tagLocation = cpu_to_le32( | ||
| 1488 | iinfo->i_location. | ||
| 1489 | logicalBlockNum); | ||
| 1377 | use->descTag.descCRCLength = cpu_to_le16(crclen); | 1490 | use->descTag.descCRCLength = cpu_to_le16(crclen); |
| 1378 | use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0)); | 1491 | use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + |
| 1379 | 1492 | sizeof(tag), crclen, | |
| 1380 | use->descTag.tagChecksum = 0; | 1493 | 0)); |
| 1381 | for (i = 0; i < 16; i++) { | 1494 | use->descTag.tagChecksum = udf_tag_checksum(&use->descTag); |
| 1382 | if (i != 4) | ||
| 1383 | use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; | ||
| 1384 | } | ||
| 1385 | 1495 | ||
| 1386 | mark_buffer_dirty(bh); | 1496 | mark_buffer_dirty(bh); |
| 1387 | brelse(bh); | 1497 | brelse(bh); |
| @@ -1398,14 +1508,14 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1398 | else | 1508 | else |
| 1399 | fe->gid = cpu_to_le32(inode->i_gid); | 1509 | fe->gid = cpu_to_le32(inode->i_gid); |
| 1400 | 1510 | ||
| 1401 | udfperms = ((inode->i_mode & S_IRWXO) ) | | 1511 | udfperms = ((inode->i_mode & S_IRWXO)) | |
| 1402 | ((inode->i_mode & S_IRWXG) << 2) | | 1512 | ((inode->i_mode & S_IRWXG) << 2) | |
| 1403 | ((inode->i_mode & S_IRWXU) << 4); | 1513 | ((inode->i_mode & S_IRWXU) << 4); |
| 1404 | 1514 | ||
| 1405 | udfperms |= (le32_to_cpu(fe->permissions) & | 1515 | udfperms |= (le32_to_cpu(fe->permissions) & |
| 1406 | (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | | 1516 | (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | |
| 1407 | FE_PERM_G_DELETE | FE_PERM_G_CHATTR | | 1517 | FE_PERM_G_DELETE | FE_PERM_G_CHATTR | |
| 1408 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); | 1518 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); |
| 1409 | fe->permissions = cpu_to_le32(udfperms); | 1519 | fe->permissions = cpu_to_le32(udfperms); |
| 1410 | 1520 | ||
| 1411 | if (S_ISDIR(inode->i_mode)) | 1521 | if (S_ISDIR(inode->i_mode)) |
| @@ -1426,8 +1536,9 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1426 | sizeof(regid), 12, 0x3); | 1536 | sizeof(regid), 12, 0x3); |
| 1427 | dsea->attrType = cpu_to_le32(12); | 1537 | dsea->attrType = cpu_to_le32(12); |
| 1428 | dsea->attrSubtype = 1; | 1538 | dsea->attrSubtype = 1; |
| 1429 | dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + | 1539 | dsea->attrLength = cpu_to_le32( |
| 1430 | sizeof(regid)); | 1540 | sizeof(struct deviceSpec) + |
| 1541 | sizeof(regid)); | ||
| 1431 | dsea->impUseLength = cpu_to_le32(sizeof(regid)); | 1542 | dsea->impUseLength = cpu_to_le32(sizeof(regid)); |
| 1432 | } | 1543 | } |
| 1433 | eid = (regid *)dsea->impUse; | 1544 | eid = (regid *)dsea->impUse; |
| @@ -1439,12 +1550,13 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1439 | dsea->minorDeviceIdent = cpu_to_le32(iminor(inode)); | 1550 | dsea->minorDeviceIdent = cpu_to_le32(iminor(inode)); |
| 1440 | } | 1551 | } |
| 1441 | 1552 | ||
| 1442 | if (UDF_I_EFE(inode) == 0) { | 1553 | if (iinfo->i_efe == 0) { |
| 1443 | memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), | 1554 | memcpy(bh->b_data + sizeof(struct fileEntry), |
| 1555 | iinfo->i_ext.i_data, | ||
| 1444 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); | 1556 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); |
| 1445 | fe->logicalBlocksRecorded = cpu_to_le64( | 1557 | fe->logicalBlocksRecorded = cpu_to_le64( |
| 1446 | (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> | 1558 | (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> |
| 1447 | (inode->i_sb->s_blocksize_bits - 9)); | 1559 | (blocksize_bits - 9)); |
| 1448 | 1560 | ||
| 1449 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) | 1561 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) |
| 1450 | fe->accessTime = cpu_to_lets(cpu_time); | 1562 | fe->accessTime = cpu_to_lets(cpu_time); |
| @@ -1456,40 +1568,41 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1456 | strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER); | 1568 | strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER); |
| 1457 | fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1569 | fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 1458 | fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1570 | fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
| 1459 | fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode)); | 1571 | fe->uniqueID = cpu_to_le64(iinfo->i_unique); |
| 1460 | fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode)); | 1572 | fe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr); |
| 1461 | fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); | 1573 | fe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc); |
| 1462 | fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); | 1574 | fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); |
| 1463 | crclen = sizeof(struct fileEntry); | 1575 | crclen = sizeof(struct fileEntry); |
| 1464 | } else { | 1576 | } else { |
| 1465 | memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), | 1577 | memcpy(bh->b_data + sizeof(struct extendedFileEntry), |
| 1466 | inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); | 1578 | iinfo->i_ext.i_data, |
| 1579 | inode->i_sb->s_blocksize - | ||
| 1580 | sizeof(struct extendedFileEntry)); | ||
| 1467 | efe->objectSize = cpu_to_le64(inode->i_size); | 1581 | efe->objectSize = cpu_to_le64(inode->i_size); |
| 1468 | efe->logicalBlocksRecorded = cpu_to_le64( | 1582 | efe->logicalBlocksRecorded = cpu_to_le64( |
| 1469 | (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> | 1583 | (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> |
| 1470 | (inode->i_sb->s_blocksize_bits - 9)); | 1584 | (blocksize_bits - 9)); |
| 1471 | 1585 | ||
| 1472 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || | 1586 | if (iinfo->i_crtime.tv_sec > inode->i_atime.tv_sec || |
| 1473 | (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && | 1587 | (iinfo->i_crtime.tv_sec == inode->i_atime.tv_sec && |
| 1474 | UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) { | 1588 | iinfo->i_crtime.tv_nsec > inode->i_atime.tv_nsec)) |
| 1475 | UDF_I_CRTIME(inode) = inode->i_atime; | 1589 | iinfo->i_crtime = inode->i_atime; |
| 1476 | } | 1590 | |
| 1477 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || | 1591 | if (iinfo->i_crtime.tv_sec > inode->i_mtime.tv_sec || |
| 1478 | (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && | 1592 | (iinfo->i_crtime.tv_sec == inode->i_mtime.tv_sec && |
| 1479 | UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) { | 1593 | iinfo->i_crtime.tv_nsec > inode->i_mtime.tv_nsec)) |
| 1480 | UDF_I_CRTIME(inode) = inode->i_mtime; | 1594 | iinfo->i_crtime = inode->i_mtime; |
| 1481 | } | 1595 | |
| 1482 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || | 1596 | if (iinfo->i_crtime.tv_sec > inode->i_ctime.tv_sec || |
| 1483 | (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && | 1597 | (iinfo->i_crtime.tv_sec == inode->i_ctime.tv_sec && |
| 1484 | UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) { | 1598 | iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec)) |
| 1485 | UDF_I_CRTIME(inode) = inode->i_ctime; | 1599 | iinfo->i_crtime = inode->i_ctime; |
| 1486 | } | ||
| 1487 | 1600 | ||
| 1488 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) | 1601 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) |
| 1489 | efe->accessTime = cpu_to_lets(cpu_time); | 1602 | efe->accessTime = cpu_to_lets(cpu_time); |
| 1490 | if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) | 1603 | if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) |
| 1491 | efe->modificationTime = cpu_to_lets(cpu_time); | 1604 | efe->modificationTime = cpu_to_lets(cpu_time); |
| 1492 | if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode))) | 1605 | if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime)) |
| 1493 | efe->createTime = cpu_to_lets(cpu_time); | 1606 | efe->createTime = cpu_to_lets(cpu_time); |
| 1494 | if (udf_time_to_stamp(&cpu_time, inode->i_ctime)) | 1607 | if (udf_time_to_stamp(&cpu_time, inode->i_ctime)) |
| 1495 | efe->attrTime = cpu_to_lets(cpu_time); | 1608 | efe->attrTime = cpu_to_lets(cpu_time); |
| @@ -1498,13 +1611,13 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1498 | strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER); | 1611 | strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER); |
| 1499 | efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1612 | efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 1500 | efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1613 | efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
| 1501 | efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode)); | 1614 | efe->uniqueID = cpu_to_le64(iinfo->i_unique); |
| 1502 | efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode)); | 1615 | efe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr); |
| 1503 | efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); | 1616 | efe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc); |
| 1504 | efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE); | 1617 | efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE); |
| 1505 | crclen = sizeof(struct extendedFileEntry); | 1618 | crclen = sizeof(struct extendedFileEntry); |
| 1506 | } | 1619 | } |
| 1507 | if (UDF_I_STRAT4096(inode)) { | 1620 | if (iinfo->i_strat4096) { |
| 1508 | fe->icbTag.strategyType = cpu_to_le16(4096); | 1621 | fe->icbTag.strategyType = cpu_to_le16(4096); |
| 1509 | fe->icbTag.strategyParameter = cpu_to_le16(1); | 1622 | fe->icbTag.strategyParameter = cpu_to_le16(1); |
| 1510 | fe->icbTag.numEntries = cpu_to_le16(2); | 1623 | fe->icbTag.numEntries = cpu_to_le16(2); |
| @@ -1528,7 +1641,7 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1528 | else if (S_ISSOCK(inode->i_mode)) | 1641 | else if (S_ISSOCK(inode->i_mode)) |
| 1529 | fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET; | 1642 | fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET; |
| 1530 | 1643 | ||
| 1531 | icbflags = UDF_I_ALLOCTYPE(inode) | | 1644 | icbflags = iinfo->i_alloc_type | |
| 1532 | ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) | | 1645 | ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) | |
| 1533 | ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) | | 1646 | ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) | |
| 1534 | ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) | | 1647 | ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) | |
| @@ -1537,29 +1650,28 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
| 1537 | ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY)); | 1650 | ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY)); |
| 1538 | 1651 | ||
| 1539 | fe->icbTag.flags = cpu_to_le16(icbflags); | 1652 | fe->icbTag.flags = cpu_to_le16(icbflags); |
| 1540 | if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) | 1653 | if (sbi->s_udfrev >= 0x0200) |
| 1541 | fe->descTag.descVersion = cpu_to_le16(3); | 1654 | fe->descTag.descVersion = cpu_to_le16(3); |
| 1542 | else | 1655 | else |
| 1543 | fe->descTag.descVersion = cpu_to_le16(2); | 1656 | fe->descTag.descVersion = cpu_to_le16(2); |
| 1544 | fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); | 1657 | fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); |
| 1545 | fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); | 1658 | fe->descTag.tagLocation = cpu_to_le32( |
| 1546 | crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); | 1659 | iinfo->i_location.logicalBlockNum); |
| 1660 | crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc - | ||
| 1661 | sizeof(tag); | ||
| 1547 | fe->descTag.descCRCLength = cpu_to_le16(crclen); | 1662 | fe->descTag.descCRCLength = cpu_to_le16(crclen); |
| 1548 | fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0)); | 1663 | fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), |
| 1549 | 1664 | crclen, 0)); | |
| 1550 | fe->descTag.tagChecksum = 0; | 1665 | fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag); |
| 1551 | for (i = 0; i < 16; i++) { | ||
| 1552 | if (i != 4) | ||
| 1553 | fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i]; | ||
| 1554 | } | ||
| 1555 | 1666 | ||
| 1556 | /* write the data blocks */ | 1667 | /* write the data blocks */ |
| 1557 | mark_buffer_dirty(bh); | 1668 | mark_buffer_dirty(bh); |
| 1558 | if (do_sync) { | 1669 | if (do_sync) { |
| 1559 | sync_dirty_buffer(bh); | 1670 | sync_dirty_buffer(bh); |
| 1560 | if (buffer_req(bh) && !buffer_uptodate(bh)) { | 1671 | if (buffer_req(bh) && !buffer_uptodate(bh)) { |
| 1561 | printk("IO error syncing udf inode [%s:%08lx]\n", | 1672 | printk(KERN_WARNING "IO error syncing udf inode " |
| 1562 | inode->i_sb->s_id, inode->i_ino); | 1673 | "[%s:%08lx]\n", inode->i_sb->s_id, |
| 1674 | inode->i_ino); | ||
| 1563 | err = -EIO; | 1675 | err = -EIO; |
| 1564 | } | 1676 | } |
| 1565 | } | 1677 | } |
| @@ -1577,7 +1689,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
| 1577 | return NULL; | 1689 | return NULL; |
| 1578 | 1690 | ||
| 1579 | if (inode->i_state & I_NEW) { | 1691 | if (inode->i_state & I_NEW) { |
| 1580 | memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr)); | 1692 | memcpy(&UDF_I(inode)->i_location, &ino, sizeof(kernel_lb_addr)); |
| 1581 | __udf_read_inode(inode); | 1693 | __udf_read_inode(inode); |
| 1582 | unlock_new_inode(inode); | 1694 | unlock_new_inode(inode); |
| 1583 | } | 1695 | } |
| @@ -1585,7 +1697,8 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
| 1585 | if (is_bad_inode(inode)) | 1697 | if (is_bad_inode(inode)) |
| 1586 | goto out_iput; | 1698 | goto out_iput; |
| 1587 | 1699 | ||
| 1588 | if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) { | 1700 | if (ino.logicalBlockNum >= UDF_SB(sb)-> |
| 1701 | s_partmaps[ino.partitionReferenceNum].s_partition_len) { | ||
| 1589 | udf_debug("block=%d, partition=%d out of range\n", | 1702 | udf_debug("block=%d, partition=%d out of range\n", |
| 1590 | ino.logicalBlockNum, ino.partitionReferenceNum); | 1703 | ino.logicalBlockNum, ino.partitionReferenceNum); |
| 1591 | make_bad_inode(inode); | 1704 | make_bad_inode(inode); |
| @@ -1599,7 +1712,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
| 1599 | return NULL; | 1712 | return NULL; |
| 1600 | } | 1713 | } |
| 1601 | 1714 | ||
| 1602 | int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | 1715 | int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, |
| 1603 | kernel_lb_addr eloc, uint32_t elen, int inc) | 1716 | kernel_lb_addr eloc, uint32_t elen, int inc) |
| 1604 | { | 1717 | { |
| 1605 | int adsize; | 1718 | int adsize; |
| @@ -1608,15 +1721,18 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1608 | struct allocExtDesc *aed; | 1721 | struct allocExtDesc *aed; |
| 1609 | int8_t etype; | 1722 | int8_t etype; |
| 1610 | uint8_t *ptr; | 1723 | uint8_t *ptr; |
| 1724 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 1611 | 1725 | ||
| 1612 | if (!epos->bh) | 1726 | if (!epos->bh) |
| 1613 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1727 | ptr = iinfo->i_ext.i_data + epos->offset - |
| 1728 | udf_file_entry_alloc_offset(inode) + | ||
| 1729 | iinfo->i_lenEAttr; | ||
| 1614 | else | 1730 | else |
| 1615 | ptr = epos->bh->b_data + epos->offset; | 1731 | ptr = epos->bh->b_data + epos->offset; |
| 1616 | 1732 | ||
| 1617 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 1733 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 1618 | adsize = sizeof(short_ad); | 1734 | adsize = sizeof(short_ad); |
| 1619 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 1735 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 1620 | adsize = sizeof(long_ad); | 1736 | adsize = sizeof(long_ad); |
| 1621 | else | 1737 | else |
| 1622 | return -1; | 1738 | return -1; |
| @@ -1627,15 +1743,16 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1627 | int err, loffset; | 1743 | int err, loffset; |
| 1628 | kernel_lb_addr obloc = epos->block; | 1744 | kernel_lb_addr obloc = epos->block; |
| 1629 | 1745 | ||
| 1630 | if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, | 1746 | epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, |
| 1631 | obloc.partitionReferenceNum, | 1747 | obloc.partitionReferenceNum, |
| 1632 | obloc.logicalBlockNum, &err))) { | 1748 | obloc.logicalBlockNum, &err); |
| 1749 | if (!epos->block.logicalBlockNum) | ||
| 1633 | return -1; | 1750 | return -1; |
| 1634 | } | 1751 | nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, |
| 1635 | if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, | 1752 | epos->block, |
| 1636 | epos->block, 0)))) { | 1753 | 0)); |
| 1754 | if (!nbh) | ||
| 1637 | return -1; | 1755 | return -1; |
| 1638 | } | ||
| 1639 | lock_buffer(nbh); | 1756 | lock_buffer(nbh); |
| 1640 | memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize); | 1757 | memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize); |
| 1641 | set_buffer_uptodate(nbh); | 1758 | set_buffer_uptodate(nbh); |
| @@ -1644,7 +1761,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1644 | 1761 | ||
| 1645 | aed = (struct allocExtDesc *)(nbh->b_data); | 1762 | aed = (struct allocExtDesc *)(nbh->b_data); |
| 1646 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) | 1763 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
| 1647 | aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); | 1764 | aed->previousAllocExtLocation = |
| 1765 | cpu_to_le32(obloc.logicalBlockNum); | ||
| 1648 | if (epos->offset + adsize > inode->i_sb->s_blocksize) { | 1766 | if (epos->offset + adsize > inode->i_sb->s_blocksize) { |
| 1649 | loffset = epos->offset; | 1767 | loffset = epos->offset; |
| 1650 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 1768 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
| @@ -1661,24 +1779,26 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1661 | if (epos->bh) { | 1779 | if (epos->bh) { |
| 1662 | aed = (struct allocExtDesc *)epos->bh->b_data; | 1780 | aed = (struct allocExtDesc *)epos->bh->b_data; |
| 1663 | aed->lengthAllocDescs = | 1781 | aed->lengthAllocDescs = |
| 1664 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1782 | cpu_to_le32(le32_to_cpu( |
| 1783 | aed->lengthAllocDescs) + adsize); | ||
| 1665 | } else { | 1784 | } else { |
| 1666 | UDF_I_LENALLOC(inode) += adsize; | 1785 | iinfo->i_lenAlloc += adsize; |
| 1667 | mark_inode_dirty(inode); | 1786 | mark_inode_dirty(inode); |
| 1668 | } | 1787 | } |
| 1669 | } | 1788 | } |
| 1670 | if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) | 1789 | if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200) |
| 1671 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, | 1790 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, |
| 1672 | epos->block.logicalBlockNum, sizeof(tag)); | 1791 | epos->block.logicalBlockNum, sizeof(tag)); |
| 1673 | else | 1792 | else |
| 1674 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, | 1793 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, |
| 1675 | epos->block.logicalBlockNum, sizeof(tag)); | 1794 | epos->block.logicalBlockNum, sizeof(tag)); |
| 1676 | switch (UDF_I_ALLOCTYPE(inode)) { | 1795 | switch (iinfo->i_alloc_type) { |
| 1677 | case ICBTAG_FLAG_AD_SHORT: | 1796 | case ICBTAG_FLAG_AD_SHORT: |
| 1678 | sad = (short_ad *)sptr; | 1797 | sad = (short_ad *)sptr; |
| 1679 | sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | | 1798 | sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | |
| 1680 | inode->i_sb->s_blocksize); | 1799 | inode->i_sb->s_blocksize); |
| 1681 | sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); | 1800 | sad->extPosition = |
| 1801 | cpu_to_le32(epos->block.logicalBlockNum); | ||
| 1682 | break; | 1802 | break; |
| 1683 | case ICBTAG_FLAG_AD_LONG: | 1803 | case ICBTAG_FLAG_AD_LONG: |
| 1684 | lad = (long_ad *)sptr; | 1804 | lad = (long_ad *)sptr; |
| @@ -1690,10 +1810,11 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1690 | } | 1810 | } |
| 1691 | if (epos->bh) { | 1811 | if (epos->bh) { |
| 1692 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 1812 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 1693 | UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 1813 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
| 1694 | udf_update_tag(epos->bh->b_data, loffset); | 1814 | udf_update_tag(epos->bh->b_data, loffset); |
| 1695 | else | 1815 | else |
| 1696 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); | 1816 | udf_update_tag(epos->bh->b_data, |
| 1817 | sizeof(struct allocExtDesc)); | ||
| 1697 | mark_buffer_dirty_inode(epos->bh, inode); | 1818 | mark_buffer_dirty_inode(epos->bh, inode); |
| 1698 | brelse(epos->bh); | 1819 | brelse(epos->bh); |
| 1699 | } else { | 1820 | } else { |
| @@ -1705,36 +1826,43 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
| 1705 | etype = udf_write_aext(inode, epos, eloc, elen, inc); | 1826 | etype = udf_write_aext(inode, epos, eloc, elen, inc); |
| 1706 | 1827 | ||
| 1707 | if (!epos->bh) { | 1828 | if (!epos->bh) { |
| 1708 | UDF_I_LENALLOC(inode) += adsize; | 1829 | iinfo->i_lenAlloc += adsize; |
| 1709 | mark_inode_dirty(inode); | 1830 | mark_inode_dirty(inode); |
| 1710 | } else { | 1831 | } else { |
| 1711 | aed = (struct allocExtDesc *)epos->bh->b_data; | 1832 | aed = (struct allocExtDesc *)epos->bh->b_data; |
| 1712 | aed->lengthAllocDescs = | 1833 | aed->lengthAllocDescs = |
| 1713 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1834 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + |
| 1714 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 1835 | adsize); |
| 1715 | udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize)); | 1836 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 1837 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | ||
| 1838 | udf_update_tag(epos->bh->b_data, | ||
| 1839 | epos->offset + (inc ? 0 : adsize)); | ||
| 1716 | else | 1840 | else |
| 1717 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); | 1841 | udf_update_tag(epos->bh->b_data, |
| 1842 | sizeof(struct allocExtDesc)); | ||
| 1718 | mark_buffer_dirty_inode(epos->bh, inode); | 1843 | mark_buffer_dirty_inode(epos->bh, inode); |
| 1719 | } | 1844 | } |
| 1720 | 1845 | ||
| 1721 | return etype; | 1846 | return etype; |
| 1722 | } | 1847 | } |
| 1723 | 1848 | ||
| 1724 | int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | 1849 | int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, |
| 1725 | kernel_lb_addr eloc, uint32_t elen, int inc) | 1850 | kernel_lb_addr eloc, uint32_t elen, int inc) |
| 1726 | { | 1851 | { |
| 1727 | int adsize; | 1852 | int adsize; |
| 1728 | uint8_t *ptr; | 1853 | uint8_t *ptr; |
| 1729 | short_ad *sad; | 1854 | short_ad *sad; |
| 1730 | long_ad *lad; | 1855 | long_ad *lad; |
| 1856 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 1731 | 1857 | ||
| 1732 | if (!epos->bh) | 1858 | if (!epos->bh) |
| 1733 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1859 | ptr = iinfo->i_ext.i_data + epos->offset - |
| 1860 | udf_file_entry_alloc_offset(inode) + | ||
| 1861 | iinfo->i_lenEAttr; | ||
| 1734 | else | 1862 | else |
| 1735 | ptr = epos->bh->b_data + epos->offset; | 1863 | ptr = epos->bh->b_data + epos->offset; |
| 1736 | 1864 | ||
| 1737 | switch (UDF_I_ALLOCTYPE(inode)) { | 1865 | switch (iinfo->i_alloc_type) { |
| 1738 | case ICBTAG_FLAG_AD_SHORT: | 1866 | case ICBTAG_FLAG_AD_SHORT: |
| 1739 | sad = (short_ad *)ptr; | 1867 | sad = (short_ad *)ptr; |
| 1740 | sad->extLength = cpu_to_le32(elen); | 1868 | sad->extLength = cpu_to_le32(elen); |
| @@ -1754,10 +1882,12 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | |||
| 1754 | 1882 | ||
| 1755 | if (epos->bh) { | 1883 | if (epos->bh) { |
| 1756 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 1884 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 1757 | UDF_SB_UDFREV(inode->i_sb) >= 0x0201) { | 1885 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) { |
| 1758 | struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; | 1886 | struct allocExtDesc *aed = |
| 1887 | (struct allocExtDesc *)epos->bh->b_data; | ||
| 1759 | udf_update_tag(epos->bh->b_data, | 1888 | udf_update_tag(epos->bh->b_data, |
| 1760 | le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); | 1889 | le32_to_cpu(aed->lengthAllocDescs) + |
| 1890 | sizeof(struct allocExtDesc)); | ||
| 1761 | } | 1891 | } |
| 1762 | mark_buffer_dirty_inode(epos->bh, inode); | 1892 | mark_buffer_dirty_inode(epos->bh, inode); |
| 1763 | } else { | 1893 | } else { |
| @@ -1770,19 +1900,21 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | |||
| 1770 | return (elen >> 30); | 1900 | return (elen >> 30); |
| 1771 | } | 1901 | } |
| 1772 | 1902 | ||
| 1773 | int8_t udf_next_aext(struct inode * inode, struct extent_position * epos, | 1903 | int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, |
| 1774 | kernel_lb_addr * eloc, uint32_t * elen, int inc) | 1904 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
| 1775 | { | 1905 | { |
| 1776 | int8_t etype; | 1906 | int8_t etype; |
| 1777 | 1907 | ||
| 1778 | while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == | 1908 | while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == |
| 1779 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { | 1909 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
| 1910 | int block; | ||
| 1780 | epos->block = *eloc; | 1911 | epos->block = *eloc; |
| 1781 | epos->offset = sizeof(struct allocExtDesc); | 1912 | epos->offset = sizeof(struct allocExtDesc); |
| 1782 | brelse(epos->bh); | 1913 | brelse(epos->bh); |
| 1783 | if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) { | 1914 | block = udf_get_lb_pblock(inode->i_sb, epos->block, 0); |
| 1784 | udf_debug("reading block %d failed!\n", | 1915 | epos->bh = udf_tread(inode->i_sb, block); |
| 1785 | udf_get_lb_pblock(inode->i_sb, epos->block, 0)); | 1916 | if (!epos->bh) { |
| 1917 | udf_debug("reading block %d failed!\n", block); | ||
| 1786 | return -1; | 1918 | return -1; |
| 1787 | } | 1919 | } |
| 1788 | } | 1920 | } |
| @@ -1790,47 +1922,55 @@ int8_t udf_next_aext(struct inode * inode, struct extent_position * epos, | |||
| 1790 | return etype; | 1922 | return etype; |
| 1791 | } | 1923 | } |
| 1792 | 1924 | ||
| 1793 | int8_t udf_current_aext(struct inode * inode, struct extent_position * epos, | 1925 | int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, |
| 1794 | kernel_lb_addr * eloc, uint32_t * elen, int inc) | 1926 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
| 1795 | { | 1927 | { |
| 1796 | int alen; | 1928 | int alen; |
| 1797 | int8_t etype; | 1929 | int8_t etype; |
| 1798 | uint8_t *ptr; | 1930 | uint8_t *ptr; |
| 1799 | short_ad *sad; | 1931 | short_ad *sad; |
| 1800 | long_ad *lad; | 1932 | long_ad *lad; |
| 1801 | 1933 | struct udf_inode_info *iinfo = UDF_I(inode); | |
| 1802 | 1934 | ||
| 1803 | if (!epos->bh) { | 1935 | if (!epos->bh) { |
| 1804 | if (!epos->offset) | 1936 | if (!epos->offset) |
| 1805 | epos->offset = udf_file_entry_alloc_offset(inode); | 1937 | epos->offset = udf_file_entry_alloc_offset(inode); |
| 1806 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1938 | ptr = iinfo->i_ext.i_data + epos->offset - |
| 1807 | alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); | 1939 | udf_file_entry_alloc_offset(inode) + |
| 1940 | iinfo->i_lenEAttr; | ||
| 1941 | alen = udf_file_entry_alloc_offset(inode) + | ||
| 1942 | iinfo->i_lenAlloc; | ||
| 1808 | } else { | 1943 | } else { |
| 1809 | if (!epos->offset) | 1944 | if (!epos->offset) |
| 1810 | epos->offset = sizeof(struct allocExtDesc); | 1945 | epos->offset = sizeof(struct allocExtDesc); |
| 1811 | ptr = epos->bh->b_data + epos->offset; | 1946 | ptr = epos->bh->b_data + epos->offset; |
| 1812 | alen = sizeof(struct allocExtDesc) + | 1947 | alen = sizeof(struct allocExtDesc) + |
| 1813 | le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); | 1948 | le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)-> |
| 1949 | lengthAllocDescs); | ||
| 1814 | } | 1950 | } |
| 1815 | 1951 | ||
| 1816 | switch (UDF_I_ALLOCTYPE(inode)) { | 1952 | switch (iinfo->i_alloc_type) { |
| 1817 | case ICBTAG_FLAG_AD_SHORT: | 1953 | case ICBTAG_FLAG_AD_SHORT: |
| 1818 | if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc))) | 1954 | sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc); |
| 1955 | if (!sad) | ||
| 1819 | return -1; | 1956 | return -1; |
| 1820 | etype = le32_to_cpu(sad->extLength) >> 30; | 1957 | etype = le32_to_cpu(sad->extLength) >> 30; |
| 1821 | eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); | 1958 | eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); |
| 1822 | eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 1959 | eloc->partitionReferenceNum = |
| 1960 | iinfo->i_location.partitionReferenceNum; | ||
| 1823 | *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; | 1961 | *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; |
| 1824 | break; | 1962 | break; |
| 1825 | case ICBTAG_FLAG_AD_LONG: | 1963 | case ICBTAG_FLAG_AD_LONG: |
| 1826 | if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc))) | 1964 | lad = udf_get_filelongad(ptr, alen, &epos->offset, inc); |
| 1965 | if (!lad) | ||
| 1827 | return -1; | 1966 | return -1; |
| 1828 | etype = le32_to_cpu(lad->extLength) >> 30; | 1967 | etype = le32_to_cpu(lad->extLength) >> 30; |
| 1829 | *eloc = lelb_to_cpu(lad->extLocation); | 1968 | *eloc = lelb_to_cpu(lad->extLocation); |
| 1830 | *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; | 1969 | *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; |
| 1831 | break; | 1970 | break; |
| 1832 | default: | 1971 | default: |
| 1833 | udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode)); | 1972 | udf_debug("alloc_type = %d unsupported\n", |
| 1973 | iinfo->i_alloc_type); | ||
| 1834 | return -1; | 1974 | return -1; |
| 1835 | } | 1975 | } |
| 1836 | 1976 | ||
| @@ -1858,22 +1998,24 @@ static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos, | |||
| 1858 | return (nelen >> 30); | 1998 | return (nelen >> 30); |
| 1859 | } | 1999 | } |
| 1860 | 2000 | ||
| 1861 | int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | 2001 | int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, |
| 1862 | kernel_lb_addr eloc, uint32_t elen) | 2002 | kernel_lb_addr eloc, uint32_t elen) |
| 1863 | { | 2003 | { |
| 1864 | struct extent_position oepos; | 2004 | struct extent_position oepos; |
| 1865 | int adsize; | 2005 | int adsize; |
| 1866 | int8_t etype; | 2006 | int8_t etype; |
| 1867 | struct allocExtDesc *aed; | 2007 | struct allocExtDesc *aed; |
| 2008 | struct udf_inode_info *iinfo; | ||
| 1868 | 2009 | ||
| 1869 | if (epos.bh) { | 2010 | if (epos.bh) { |
| 1870 | get_bh(epos.bh); | 2011 | get_bh(epos.bh); |
| 1871 | get_bh(epos.bh); | 2012 | get_bh(epos.bh); |
| 1872 | } | 2013 | } |
| 1873 | 2014 | ||
| 1874 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 2015 | iinfo = UDF_I(inode); |
| 2016 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) | ||
| 1875 | adsize = sizeof(short_ad); | 2017 | adsize = sizeof(short_ad); |
| 1876 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 2018 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 1877 | adsize = sizeof(long_ad); | 2019 | adsize = sizeof(long_ad); |
| 1878 | else | 2020 | else |
| 1879 | adsize = 0; | 2021 | adsize = 0; |
| @@ -1900,33 +2042,39 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | |||
| 1900 | udf_write_aext(inode, &oepos, eloc, elen, 1); | 2042 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
| 1901 | udf_write_aext(inode, &oepos, eloc, elen, 1); | 2043 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
| 1902 | if (!oepos.bh) { | 2044 | if (!oepos.bh) { |
| 1903 | UDF_I_LENALLOC(inode) -= (adsize * 2); | 2045 | iinfo->i_lenAlloc -= (adsize * 2); |
| 1904 | mark_inode_dirty(inode); | 2046 | mark_inode_dirty(inode); |
| 1905 | } else { | 2047 | } else { |
| 1906 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 2048 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
| 1907 | aed->lengthAllocDescs = | 2049 | aed->lengthAllocDescs = |
| 1908 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2 * adsize)); | 2050 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - |
| 2051 | (2 * adsize)); | ||
| 1909 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 2052 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 1910 | UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 2053 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
| 1911 | udf_update_tag(oepos.bh->b_data, oepos.offset - (2 * adsize)); | 2054 | udf_update_tag(oepos.bh->b_data, |
| 2055 | oepos.offset - (2 * adsize)); | ||
| 1912 | else | 2056 | else |
| 1913 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); | 2057 | udf_update_tag(oepos.bh->b_data, |
| 2058 | sizeof(struct allocExtDesc)); | ||
| 1914 | mark_buffer_dirty_inode(oepos.bh, inode); | 2059 | mark_buffer_dirty_inode(oepos.bh, inode); |
| 1915 | } | 2060 | } |
| 1916 | } else { | 2061 | } else { |
| 1917 | udf_write_aext(inode, &oepos, eloc, elen, 1); | 2062 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
| 1918 | if (!oepos.bh) { | 2063 | if (!oepos.bh) { |
| 1919 | UDF_I_LENALLOC(inode) -= adsize; | 2064 | iinfo->i_lenAlloc -= adsize; |
| 1920 | mark_inode_dirty(inode); | 2065 | mark_inode_dirty(inode); |
| 1921 | } else { | 2066 | } else { |
| 1922 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 2067 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
| 1923 | aed->lengthAllocDescs = | 2068 | aed->lengthAllocDescs = |
| 1924 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); | 2069 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - |
| 2070 | adsize); | ||
| 1925 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 2071 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 1926 | UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 2072 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
| 1927 | udf_update_tag(oepos.bh->b_data, epos.offset - adsize); | 2073 | udf_update_tag(oepos.bh->b_data, |
| 2074 | epos.offset - adsize); | ||
| 1928 | else | 2075 | else |
| 1929 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); | 2076 | udf_update_tag(oepos.bh->b_data, |
| 2077 | sizeof(struct allocExtDesc)); | ||
| 1930 | mark_buffer_dirty_inode(oepos.bh, inode); | 2078 | mark_buffer_dirty_inode(oepos.bh, inode); |
| 1931 | } | 2079 | } |
| 1932 | } | 2080 | } |
| @@ -1937,34 +2085,38 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | |||
| 1937 | return (elen >> 30); | 2085 | return (elen >> 30); |
| 1938 | } | 2086 | } |
| 1939 | 2087 | ||
| 1940 | int8_t inode_bmap(struct inode * inode, sector_t block, | 2088 | int8_t inode_bmap(struct inode *inode, sector_t block, |
| 1941 | struct extent_position * pos, kernel_lb_addr * eloc, | 2089 | struct extent_position *pos, kernel_lb_addr *eloc, |
| 1942 | uint32_t * elen, sector_t * offset) | 2090 | uint32_t *elen, sector_t *offset) |
| 1943 | { | 2091 | { |
| 2092 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
| 1944 | loff_t lbcount = 0, bcount = | 2093 | loff_t lbcount = 0, bcount = |
| 1945 | (loff_t) block << inode->i_sb->s_blocksize_bits; | 2094 | (loff_t) block << blocksize_bits; |
| 1946 | int8_t etype; | 2095 | int8_t etype; |
| 2096 | struct udf_inode_info *iinfo; | ||
| 1947 | 2097 | ||
| 1948 | if (block < 0) { | 2098 | if (block < 0) { |
| 1949 | printk(KERN_ERR "udf: inode_bmap: block < 0\n"); | 2099 | printk(KERN_ERR "udf: inode_bmap: block < 0\n"); |
| 1950 | return -1; | 2100 | return -1; |
| 1951 | } | 2101 | } |
| 1952 | 2102 | ||
| 2103 | iinfo = UDF_I(inode); | ||
| 1953 | pos->offset = 0; | 2104 | pos->offset = 0; |
| 1954 | pos->block = UDF_I_LOCATION(inode); | 2105 | pos->block = iinfo->i_location; |
| 1955 | pos->bh = NULL; | 2106 | pos->bh = NULL; |
| 1956 | *elen = 0; | 2107 | *elen = 0; |
| 1957 | 2108 | ||
| 1958 | do { | 2109 | do { |
| 1959 | if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) { | 2110 | etype = udf_next_aext(inode, pos, eloc, elen, 1); |
| 1960 | *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits; | 2111 | if (etype == -1) { |
| 1961 | UDF_I_LENEXTENTS(inode) = lbcount; | 2112 | *offset = (bcount - lbcount) >> blocksize_bits; |
| 2113 | iinfo->i_lenExtents = lbcount; | ||
| 1962 | return -1; | 2114 | return -1; |
| 1963 | } | 2115 | } |
| 1964 | lbcount += *elen; | 2116 | lbcount += *elen; |
| 1965 | } while (lbcount <= bcount); | 2117 | } while (lbcount <= bcount); |
| 1966 | 2118 | ||
| 1967 | *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits; | 2119 | *offset = (bcount + *elen - lbcount) >> blocksize_bits; |
| 1968 | 2120 | ||
| 1969 | return etype; | 2121 | return etype; |
| 1970 | } | 2122 | } |
| @@ -1979,7 +2131,8 @@ long udf_block_map(struct inode *inode, sector_t block) | |||
| 1979 | 2131 | ||
| 1980 | lock_kernel(); | 2132 | lock_kernel(); |
| 1981 | 2133 | ||
| 1982 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) | 2134 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == |
| 2135 | (EXT_RECORDED_ALLOCATED >> 30)) | ||
| 1983 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); | 2136 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); |
| 1984 | else | 2137 | else |
| 1985 | ret = 0; | 2138 | ret = 0; |
diff --git a/fs/udf/misc.c b/fs/udf/misc.c index 15297deb5051..a1d6da0caf71 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c | |||
| @@ -51,18 +51,18 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size, | |||
| 51 | uint8_t *ea = NULL, *ad = NULL; | 51 | uint8_t *ea = NULL, *ad = NULL; |
| 52 | int offset; | 52 | int offset; |
| 53 | uint16_t crclen; | 53 | uint16_t crclen; |
| 54 | int i; | 54 | struct udf_inode_info *iinfo = UDF_I(inode); |
| 55 | 55 | ||
| 56 | ea = UDF_I_DATA(inode); | 56 | ea = iinfo->i_ext.i_data; |
| 57 | if (UDF_I_LENEATTR(inode)) { | 57 | if (iinfo->i_lenEAttr) { |
| 58 | ad = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); | 58 | ad = iinfo->i_ext.i_data + iinfo->i_lenEAttr; |
| 59 | } else { | 59 | } else { |
| 60 | ad = ea; | 60 | ad = ea; |
| 61 | size += sizeof(struct extendedAttrHeaderDesc); | 61 | size += sizeof(struct extendedAttrHeaderDesc); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | offset = inode->i_sb->s_blocksize - udf_file_entry_alloc_offset(inode) - | 64 | offset = inode->i_sb->s_blocksize - udf_file_entry_alloc_offset(inode) - |
| 65 | UDF_I_LENALLOC(inode); | 65 | iinfo->i_lenAlloc; |
| 66 | 66 | ||
| 67 | /* TODO - Check for FreeEASpace */ | 67 | /* TODO - Check for FreeEASpace */ |
| 68 | 68 | ||
| @@ -70,69 +70,80 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size, | |||
| 70 | struct extendedAttrHeaderDesc *eahd; | 70 | struct extendedAttrHeaderDesc *eahd; |
| 71 | eahd = (struct extendedAttrHeaderDesc *)ea; | 71 | eahd = (struct extendedAttrHeaderDesc *)ea; |
| 72 | 72 | ||
| 73 | if (UDF_I_LENALLOC(inode)) { | 73 | if (iinfo->i_lenAlloc) |
| 74 | memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); | 74 | memmove(&ad[size], ad, iinfo->i_lenAlloc); |
| 75 | } | ||
| 76 | 75 | ||
| 77 | if (UDF_I_LENEATTR(inode)) { | 76 | if (iinfo->i_lenEAttr) { |
| 78 | /* check checksum/crc */ | 77 | /* check checksum/crc */ |
| 79 | if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || | 78 | if (eahd->descTag.tagIdent != |
| 80 | le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { | 79 | cpu_to_le16(TAG_IDENT_EAHD) || |
| 80 | le32_to_cpu(eahd->descTag.tagLocation) != | ||
| 81 | iinfo->i_location.logicalBlockNum) | ||
| 81 | return NULL; | 82 | return NULL; |
| 82 | } | ||
| 83 | } else { | 83 | } else { |
| 84 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | ||
| 85 | |||
| 84 | size -= sizeof(struct extendedAttrHeaderDesc); | 86 | size -= sizeof(struct extendedAttrHeaderDesc); |
| 85 | UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); | 87 | iinfo->i_lenEAttr += |
| 88 | sizeof(struct extendedAttrHeaderDesc); | ||
| 86 | eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); | 89 | eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); |
| 87 | if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) | 90 | if (sbi->s_udfrev >= 0x0200) |
| 88 | eahd->descTag.descVersion = cpu_to_le16(3); | 91 | eahd->descTag.descVersion = cpu_to_le16(3); |
| 89 | else | 92 | else |
| 90 | eahd->descTag.descVersion = cpu_to_le16(2); | 93 | eahd->descTag.descVersion = cpu_to_le16(2); |
| 91 | eahd->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); | 94 | eahd->descTag.tagSerialNum = |
| 92 | eahd->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); | 95 | cpu_to_le16(sbi->s_serial_number); |
| 96 | eahd->descTag.tagLocation = cpu_to_le32( | ||
| 97 | iinfo->i_location.logicalBlockNum); | ||
| 93 | eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); | 98 | eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); |
| 94 | eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); | 99 | eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); |
| 95 | } | 100 | } |
| 96 | 101 | ||
| 97 | offset = UDF_I_LENEATTR(inode); | 102 | offset = iinfo->i_lenEAttr; |
| 98 | if (type < 2048) { | 103 | if (type < 2048) { |
| 99 | if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { | 104 | if (le32_to_cpu(eahd->appAttrLocation) < |
| 100 | uint32_t aal = le32_to_cpu(eahd->appAttrLocation); | 105 | iinfo->i_lenEAttr) { |
| 106 | uint32_t aal = | ||
| 107 | le32_to_cpu(eahd->appAttrLocation); | ||
| 101 | memmove(&ea[offset - aal + size], | 108 | memmove(&ea[offset - aal + size], |
| 102 | &ea[aal], offset - aal); | 109 | &ea[aal], offset - aal); |
| 103 | offset -= aal; | 110 | offset -= aal; |
| 104 | eahd->appAttrLocation = cpu_to_le32(aal + size); | 111 | eahd->appAttrLocation = |
| 112 | cpu_to_le32(aal + size); | ||
| 105 | } | 113 | } |
| 106 | if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) { | 114 | if (le32_to_cpu(eahd->impAttrLocation) < |
| 107 | uint32_t ial = le32_to_cpu(eahd->impAttrLocation); | 115 | iinfo->i_lenEAttr) { |
| 116 | uint32_t ial = | ||
| 117 | le32_to_cpu(eahd->impAttrLocation); | ||
| 108 | memmove(&ea[offset - ial + size], | 118 | memmove(&ea[offset - ial + size], |
| 109 | &ea[ial], offset - ial); | 119 | &ea[ial], offset - ial); |
| 110 | offset -= ial; | 120 | offset -= ial; |
| 111 | eahd->impAttrLocation = cpu_to_le32(ial + size); | 121 | eahd->impAttrLocation = |
| 122 | cpu_to_le32(ial + size); | ||
| 112 | } | 123 | } |
| 113 | } else if (type < 65536) { | 124 | } else if (type < 65536) { |
| 114 | if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { | 125 | if (le32_to_cpu(eahd->appAttrLocation) < |
| 115 | uint32_t aal = le32_to_cpu(eahd->appAttrLocation); | 126 | iinfo->i_lenEAttr) { |
| 127 | uint32_t aal = | ||
| 128 | le32_to_cpu(eahd->appAttrLocation); | ||
| 116 | memmove(&ea[offset - aal + size], | 129 | memmove(&ea[offset - aal + size], |
| 117 | &ea[aal], offset - aal); | 130 | &ea[aal], offset - aal); |
| 118 | offset -= aal; | 131 | offset -= aal; |
| 119 | eahd->appAttrLocation = cpu_to_le32(aal + size); | 132 | eahd->appAttrLocation = |
| 133 | cpu_to_le32(aal + size); | ||
| 120 | } | 134 | } |
| 121 | } | 135 | } |
| 122 | /* rewrite CRC + checksum of eahd */ | 136 | /* rewrite CRC + checksum of eahd */ |
| 123 | crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); | 137 | crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); |
| 124 | eahd->descTag.descCRCLength = cpu_to_le16(crclen); | 138 | eahd->descTag.descCRCLength = cpu_to_le16(crclen); |
| 125 | eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + | 139 | eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + |
| 126 | sizeof(tag), crclen, 0)); | 140 | sizeof(tag), crclen, 0)); |
| 127 | eahd->descTag.tagChecksum = 0; | 141 | eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag); |
| 128 | for (i = 0; i < 16; i++) | 142 | iinfo->i_lenEAttr += size; |
| 129 | if (i != 4) | ||
| 130 | eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; | ||
| 131 | UDF_I_LENEATTR(inode) += size; | ||
| 132 | return (struct genericFormat *)&ea[offset]; | 143 | return (struct genericFormat *)&ea[offset]; |
| 133 | } | 144 | } |
| 134 | if (loc & 0x02) { | 145 | if (loc & 0x02) |
| 135 | } | 146 | ; |
| 136 | 147 | ||
| 137 | return NULL; | 148 | return NULL; |
| 138 | } | 149 | } |
| @@ -143,18 +154,20 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
| 143 | struct genericFormat *gaf; | 154 | struct genericFormat *gaf; |
| 144 | uint8_t *ea = NULL; | 155 | uint8_t *ea = NULL; |
| 145 | uint32_t offset; | 156 | uint32_t offset; |
| 157 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 146 | 158 | ||
| 147 | ea = UDF_I_DATA(inode); | 159 | ea = iinfo->i_ext.i_data; |
| 148 | 160 | ||
| 149 | if (UDF_I_LENEATTR(inode)) { | 161 | if (iinfo->i_lenEAttr) { |
| 150 | struct extendedAttrHeaderDesc *eahd; | 162 | struct extendedAttrHeaderDesc *eahd; |
| 151 | eahd = (struct extendedAttrHeaderDesc *)ea; | 163 | eahd = (struct extendedAttrHeaderDesc *)ea; |
| 152 | 164 | ||
| 153 | /* check checksum/crc */ | 165 | /* check checksum/crc */ |
| 154 | if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || | 166 | if (eahd->descTag.tagIdent != |
| 155 | le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { | 167 | cpu_to_le16(TAG_IDENT_EAHD) || |
| 168 | le32_to_cpu(eahd->descTag.tagLocation) != | ||
| 169 | iinfo->i_location.logicalBlockNum) | ||
| 156 | return NULL; | 170 | return NULL; |
| 157 | } | ||
| 158 | 171 | ||
| 159 | if (type < 2048) | 172 | if (type < 2048) |
| 160 | offset = sizeof(struct extendedAttrHeaderDesc); | 173 | offset = sizeof(struct extendedAttrHeaderDesc); |
| @@ -163,9 +176,10 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
| 163 | else | 176 | else |
| 164 | offset = le32_to_cpu(eahd->appAttrLocation); | 177 | offset = le32_to_cpu(eahd->appAttrLocation); |
| 165 | 178 | ||
| 166 | while (offset < UDF_I_LENEATTR(inode)) { | 179 | while (offset < iinfo->i_lenEAttr) { |
| 167 | gaf = (struct genericFormat *)&ea[offset]; | 180 | gaf = (struct genericFormat *)&ea[offset]; |
| 168 | if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) | 181 | if (le32_to_cpu(gaf->attrType) == type && |
| 182 | gaf->attrSubtype == subtype) | ||
| 169 | return gaf; | 183 | return gaf; |
| 170 | else | 184 | else |
| 171 | offset += le32_to_cpu(gaf->attrLength); | 185 | offset += le32_to_cpu(gaf->attrLength); |
| @@ -186,21 +200,20 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
| 186 | * Written, tested, and released. | 200 | * Written, tested, and released. |
| 187 | */ | 201 | */ |
| 188 | struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | 202 | struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, |
| 189 | uint32_t location, uint16_t * ident) | 203 | uint32_t location, uint16_t *ident) |
| 190 | { | 204 | { |
| 191 | tag *tag_p; | 205 | tag *tag_p; |
| 192 | struct buffer_head *bh = NULL; | 206 | struct buffer_head *bh = NULL; |
| 193 | register uint8_t checksum; | 207 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 194 | register int i; | ||
| 195 | 208 | ||
| 196 | /* Read the block */ | 209 | /* Read the block */ |
| 197 | if (block == 0xFFFFFFFF) | 210 | if (block == 0xFFFFFFFF) |
| 198 | return NULL; | 211 | return NULL; |
| 199 | 212 | ||
| 200 | bh = udf_tread(sb, block + UDF_SB_SESSION(sb)); | 213 | bh = udf_tread(sb, block + sbi->s_session); |
| 201 | if (!bh) { | 214 | if (!bh) { |
| 202 | udf_debug("block=%d, location=%d: read failed\n", | 215 | udf_debug("block=%d, location=%d: read failed\n", |
| 203 | block + UDF_SB_SESSION(sb), location); | 216 | block + sbi->s_session, location); |
| 204 | return NULL; | 217 | return NULL; |
| 205 | } | 218 | } |
| 206 | 219 | ||
| @@ -210,24 +223,20 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | |||
| 210 | 223 | ||
| 211 | if (location != le32_to_cpu(tag_p->tagLocation)) { | 224 | if (location != le32_to_cpu(tag_p->tagLocation)) { |
| 212 | udf_debug("location mismatch block %u, tag %u != %u\n", | 225 | udf_debug("location mismatch block %u, tag %u != %u\n", |
| 213 | block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location); | 226 | block + sbi->s_session, |
| 227 | le32_to_cpu(tag_p->tagLocation), location); | ||
| 214 | goto error_out; | 228 | goto error_out; |
| 215 | } | 229 | } |
| 216 | 230 | ||
| 217 | /* Verify the tag checksum */ | 231 | /* Verify the tag checksum */ |
| 218 | checksum = 0U; | 232 | if (udf_tag_checksum(tag_p) != tag_p->tagChecksum) { |
| 219 | for (i = 0; i < 4; i++) | ||
| 220 | checksum += (uint8_t)(bh->b_data[i]); | ||
| 221 | for (i = 5; i < 16; i++) | ||
| 222 | checksum += (uint8_t)(bh->b_data[i]); | ||
| 223 | if (checksum != tag_p->tagChecksum) { | ||
| 224 | printk(KERN_ERR "udf: tag checksum failed block %d\n", block); | 233 | printk(KERN_ERR "udf: tag checksum failed block %d\n", block); |
| 225 | goto error_out; | 234 | goto error_out; |
| 226 | } | 235 | } |
| 227 | 236 | ||
| 228 | /* Verify the tag version */ | 237 | /* Verify the tag version */ |
| 229 | if (le16_to_cpu(tag_p->descVersion) != 0x0002U && | 238 | if (tag_p->descVersion != cpu_to_le16(0x0002U) && |
| 230 | le16_to_cpu(tag_p->descVersion) != 0x0003U) { | 239 | tag_p->descVersion != cpu_to_le16(0x0003U)) { |
| 231 | udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n", | 240 | udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n", |
| 232 | le16_to_cpu(tag_p->descVersion), block); | 241 | le16_to_cpu(tag_p->descVersion), block); |
| 233 | goto error_out; | 242 | goto error_out; |
| @@ -236,11 +245,11 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | |||
| 236 | /* Verify the descriptor CRC */ | 245 | /* Verify the descriptor CRC */ |
| 237 | if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || | 246 | if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || |
| 238 | le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), | 247 | le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), |
| 239 | le16_to_cpu(tag_p->descCRCLength), 0)) { | 248 | le16_to_cpu(tag_p->descCRCLength), 0)) |
| 240 | return bh; | 249 | return bh; |
| 241 | } | 250 | |
| 242 | udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", | 251 | udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", |
| 243 | block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC), | 252 | block + sbi->s_session, le16_to_cpu(tag_p->descCRC), |
| 244 | le16_to_cpu(tag_p->descCRCLength)); | 253 | le16_to_cpu(tag_p->descCRCLength)); |
| 245 | 254 | ||
| 246 | error_out: | 255 | error_out: |
| @@ -249,7 +258,7 @@ error_out: | |||
| 249 | } | 258 | } |
| 250 | 259 | ||
| 251 | struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, | 260 | struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, |
| 252 | uint32_t offset, uint16_t * ident) | 261 | uint32_t offset, uint16_t *ident) |
| 253 | { | 262 | { |
| 254 | return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), | 263 | return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), |
| 255 | loc.logicalBlockNum + offset, ident); | 264 | loc.logicalBlockNum + offset, ident); |
| @@ -258,17 +267,11 @@ struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, | |||
| 258 | void udf_update_tag(char *data, int length) | 267 | void udf_update_tag(char *data, int length) |
| 259 | { | 268 | { |
| 260 | tag *tptr = (tag *)data; | 269 | tag *tptr = (tag *)data; |
| 261 | int i; | ||
| 262 | |||
| 263 | length -= sizeof(tag); | 270 | length -= sizeof(tag); |
| 264 | 271 | ||
| 265 | tptr->tagChecksum = 0; | ||
| 266 | tptr->descCRCLength = cpu_to_le16(length); | 272 | tptr->descCRCLength = cpu_to_le16(length); |
| 267 | tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); | 273 | tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); |
| 268 | 274 | tptr->tagChecksum = udf_tag_checksum(tptr); | |
| 269 | for (i = 0; i < 16; i++) | ||
| 270 | if (i != 4) | ||
| 271 | tptr->tagChecksum += (uint8_t)(data[i]); | ||
| 272 | } | 275 | } |
| 273 | 276 | ||
| 274 | void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, | 277 | void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, |
| @@ -281,3 +284,14 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, | |||
| 281 | tptr->tagLocation = cpu_to_le32(loc); | 284 | tptr->tagLocation = cpu_to_le32(loc); |
| 282 | udf_update_tag(data, length); | 285 | udf_update_tag(data, length); |
| 283 | } | 286 | } |
| 287 | |||
| 288 | u8 udf_tag_checksum(const tag *t) | ||
| 289 | { | ||
| 290 | u8 *data = (u8 *)t; | ||
| 291 | u8 checksum = 0; | ||
| 292 | int i; | ||
| 293 | for (i = 0; i < sizeof(tag); ++i) | ||
| 294 | if (i != 4) /* position of checksum */ | ||
| 295 | checksum += data[i]; | ||
| 296 | return checksum; | ||
| 297 | } | ||
diff --git a/fs/udf/namei.c b/fs/udf/namei.c index bec96a6b3343..112a5fb0b27b 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c | |||
| @@ -43,12 +43,10 @@ static inline int udf_match(int len1, const char *name1, int len2, | |||
| 43 | 43 | ||
| 44 | int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | 44 | int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, |
| 45 | struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, | 45 | struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, |
| 46 | uint8_t * impuse, uint8_t * fileident) | 46 | uint8_t *impuse, uint8_t *fileident) |
| 47 | { | 47 | { |
| 48 | uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); | 48 | uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); |
| 49 | uint16_t crc; | 49 | uint16_t crc; |
| 50 | uint8_t checksum = 0; | ||
| 51 | int i; | ||
| 52 | int offset; | 50 | int offset; |
| 53 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); | 51 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 54 | uint8_t lfi = cfi->lengthFileIdent; | 52 | uint8_t lfi = cfi->lengthFileIdent; |
| @@ -56,7 +54,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
| 56 | sizeof(struct fileIdentDesc); | 54 | sizeof(struct fileIdentDesc); |
| 57 | int adinicb = 0; | 55 | int adinicb = 0; |
| 58 | 56 | ||
| 59 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) | 57 | if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 60 | adinicb = 1; | 58 | adinicb = 1; |
| 61 | 59 | ||
| 62 | offset = fibh->soffset + sizeof(struct fileIdentDesc); | 60 | offset = fibh->soffset + sizeof(struct fileIdentDesc); |
| @@ -68,7 +66,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
| 68 | memcpy(fibh->ebh->b_data + offset, impuse, liu); | 66 | memcpy(fibh->ebh->b_data + offset, impuse, liu); |
| 69 | } else { | 67 | } else { |
| 70 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); | 68 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); |
| 71 | memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); | 69 | memcpy(fibh->ebh->b_data, impuse - offset, |
| 70 | liu + offset); | ||
| 72 | } | 71 | } |
| 73 | } | 72 | } |
| 74 | 73 | ||
| @@ -80,8 +79,10 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
| 80 | } else if (offset >= 0) { | 79 | } else if (offset >= 0) { |
| 81 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); | 80 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); |
| 82 | } else { | 81 | } else { |
| 83 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); | 82 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, |
| 84 | memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); | 83 | -offset); |
| 84 | memcpy(fibh->ebh->b_data, fileident - offset, | ||
| 85 | lfi + offset); | ||
| 85 | } | 86 | } |
| 86 | } | 87 | } |
| 87 | 88 | ||
| @@ -101,27 +102,29 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
| 101 | 102 | ||
| 102 | if (fibh->sbh == fibh->ebh) { | 103 | if (fibh->sbh == fibh->ebh) { |
| 103 | crc = udf_crc((uint8_t *)sfi->impUse, | 104 | crc = udf_crc((uint8_t *)sfi->impUse, |
| 104 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); | 105 | crclen + sizeof(tag) - |
| 106 | sizeof(struct fileIdentDesc), crc); | ||
| 105 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { | 107 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { |
| 106 | crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, | 108 | crc = udf_crc(fibh->ebh->b_data + |
| 107 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); | 109 | sizeof(struct fileIdentDesc) + |
| 110 | fibh->soffset, | ||
| 111 | crclen + sizeof(tag) - | ||
| 112 | sizeof(struct fileIdentDesc), | ||
| 113 | crc); | ||
| 108 | } else { | 114 | } else { |
| 109 | crc = udf_crc((uint8_t *)sfi->impUse, | 115 | crc = udf_crc((uint8_t *)sfi->impUse, |
| 110 | -fibh->soffset - sizeof(struct fileIdentDesc), crc); | 116 | -fibh->soffset - sizeof(struct fileIdentDesc), |
| 117 | crc); | ||
| 111 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); | 118 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); |
| 112 | } | 119 | } |
| 113 | 120 | ||
| 114 | cfi->descTag.descCRC = cpu_to_le16(crc); | 121 | cfi->descTag.descCRC = cpu_to_le16(crc); |
| 115 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); | 122 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); |
| 123 | cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag); | ||
| 116 | 124 | ||
| 117 | for (i = 0; i < 16; i++) { | ||
| 118 | if (i != 4) | ||
| 119 | checksum += ((uint8_t *)&cfi->descTag)[i]; | ||
| 120 | } | ||
| 121 | |||
| 122 | cfi->descTag.tagChecksum = checksum; | ||
| 123 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { | 125 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { |
| 124 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); | 126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, |
| 127 | sizeof(struct fileIdentDesc)); | ||
| 125 | } else { | 128 | } else { |
| 126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); | 129 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); |
| 127 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, | 130 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, |
| @@ -155,26 +158,28 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
| 155 | uint32_t elen; | 158 | uint32_t elen; |
| 156 | sector_t offset; | 159 | sector_t offset; |
| 157 | struct extent_position epos = {}; | 160 | struct extent_position epos = {}; |
| 161 | struct udf_inode_info *dinfo = UDF_I(dir); | ||
| 158 | 162 | ||
| 159 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; | 163 | size = udf_ext0_offset(dir) + dir->i_size; |
| 160 | f_pos = (udf_ext0_offset(dir) >> 2); | 164 | f_pos = udf_ext0_offset(dir); |
| 161 | 165 | ||
| 162 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 166 | fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); |
| 163 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 167 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 164 | fibh->sbh = fibh->ebh = NULL; | 168 | fibh->sbh = fibh->ebh = NULL; |
| 165 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 169 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
| 166 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 170 | &epos, &eloc, &elen, &offset) == |
| 171 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
| 167 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 172 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
| 168 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 173 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
| 169 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 174 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 170 | epos.offset -= sizeof(short_ad); | 175 | epos.offset -= sizeof(short_ad); |
| 171 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 176 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 172 | epos.offset -= sizeof(long_ad); | 177 | epos.offset -= sizeof(long_ad); |
| 173 | } else { | 178 | } else |
| 174 | offset = 0; | 179 | offset = 0; |
| 175 | } | ||
| 176 | 180 | ||
| 177 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 181 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 182 | if (!fibh->sbh) { | ||
| 178 | brelse(epos.bh); | 183 | brelse(epos.bh); |
| 179 | return NULL; | 184 | return NULL; |
| 180 | } | 185 | } |
| @@ -183,7 +188,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
| 183 | return NULL; | 188 | return NULL; |
| 184 | } | 189 | } |
| 185 | 190 | ||
| 186 | while ((f_pos < size)) { | 191 | while (f_pos < size) { |
| 187 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, | 192 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 188 | &elen, &offset); | 193 | &elen, &offset); |
| 189 | if (!fi) { | 194 | if (!fi) { |
| @@ -202,14 +207,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
| 202 | } else { | 207 | } else { |
| 203 | int poffset; /* Unpaded ending offset */ | 208 | int poffset; /* Unpaded ending offset */ |
| 204 | 209 | ||
| 205 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; | 210 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 211 | liu + lfi; | ||
| 206 | 212 | ||
| 207 | if (poffset >= lfi) { | 213 | if (poffset >= lfi) |
| 208 | nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); | 214 | nameptr = (uint8_t *)(fibh->ebh->b_data + |
| 209 | } else { | 215 | poffset - lfi); |
| 216 | else { | ||
| 210 | nameptr = fname; | 217 | nameptr = fname; |
| 211 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); | 218 | memcpy(nameptr, fi->fileIdent + liu, |
| 212 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); | 219 | lfi - poffset); |
| 220 | memcpy(nameptr + lfi - poffset, | ||
| 221 | fibh->ebh->b_data, poffset); | ||
| 213 | } | 222 | } |
| 214 | } | 223 | } |
| 215 | 224 | ||
| @@ -226,11 +235,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
| 226 | if (!lfi) | 235 | if (!lfi) |
| 227 | continue; | 236 | continue; |
| 228 | 237 | ||
| 229 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { | 238 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 230 | if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { | 239 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 231 | brelse(epos.bh); | 240 | dentry->d_name.name)) { |
| 232 | return fi; | 241 | brelse(epos.bh); |
| 233 | } | 242 | return fi; |
| 234 | } | 243 | } |
| 235 | } | 244 | } |
| 236 | 245 | ||
| @@ -291,16 +300,16 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
| 291 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { | 300 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { |
| 292 | kernel_lb_addr lb = { | 301 | kernel_lb_addr lb = { |
| 293 | .logicalBlockNum = 0, | 302 | .logicalBlockNum = 0, |
| 294 | .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3, | 303 | .partitionReferenceNum = |
| 295 | NULL, 0), | 304 | simple_strtoul(dentry->d_name.name + 3, |
| 305 | NULL, 0), | ||
| 296 | }; | 306 | }; |
| 297 | inode = udf_iget(dir->i_sb, lb); | 307 | inode = udf_iget(dir->i_sb, lb); |
| 298 | if (!inode) { | 308 | if (!inode) { |
| 299 | unlock_kernel(); | 309 | unlock_kernel(); |
| 300 | return ERR_PTR(-EACCES); | 310 | return ERR_PTR(-EACCES); |
| 301 | } | 311 | } |
| 302 | } | 312 | } else |
| 303 | else | ||
| 304 | #endif /* UDF_RECOVERY */ | 313 | #endif /* UDF_RECOVERY */ |
| 305 | 314 | ||
| 306 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { | 315 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { |
| @@ -325,14 +334,14 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 325 | struct udf_fileident_bh *fibh, | 334 | struct udf_fileident_bh *fibh, |
| 326 | struct fileIdentDesc *cfi, int *err) | 335 | struct fileIdentDesc *cfi, int *err) |
| 327 | { | 336 | { |
| 328 | struct super_block *sb; | 337 | struct super_block *sb = dir->i_sb; |
| 329 | struct fileIdentDesc *fi = NULL; | 338 | struct fileIdentDesc *fi = NULL; |
| 330 | char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; | 339 | char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; |
| 331 | int namelen; | 340 | int namelen; |
| 332 | loff_t f_pos; | 341 | loff_t f_pos; |
| 333 | int flen; | 342 | int flen; |
| 334 | char *nameptr; | 343 | char *nameptr; |
| 335 | loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; | 344 | loff_t size = udf_ext0_offset(dir) + dir->i_size; |
| 336 | int nfidlen; | 345 | int nfidlen; |
| 337 | uint8_t lfi; | 346 | uint8_t lfi; |
| 338 | uint16_t liu; | 347 | uint16_t liu; |
| @@ -341,16 +350,16 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 341 | uint32_t elen; | 350 | uint32_t elen; |
| 342 | sector_t offset; | 351 | sector_t offset; |
| 343 | struct extent_position epos = {}; | 352 | struct extent_position epos = {}; |
| 344 | 353 | struct udf_inode_info *dinfo; | |
| 345 | sb = dir->i_sb; | ||
| 346 | 354 | ||
| 347 | if (dentry) { | 355 | if (dentry) { |
| 348 | if (!dentry->d_name.len) { | 356 | if (!dentry->d_name.len) { |
| 349 | *err = -EINVAL; | 357 | *err = -EINVAL; |
| 350 | return NULL; | 358 | return NULL; |
| 351 | } | 359 | } |
| 352 | if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name, | 360 | namelen = udf_put_filename(sb, dentry->d_name.name, name, |
| 353 | dentry->d_name.len))) { | 361 | dentry->d_name.len); |
| 362 | if (!namelen) { | ||
| 354 | *err = -ENAMETOOLONG; | 363 | *err = -ENAMETOOLONG; |
| 355 | return NULL; | 364 | return NULL; |
| 356 | } | 365 | } |
| @@ -360,39 +369,40 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 360 | 369 | ||
| 361 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; | 370 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; |
| 362 | 371 | ||
| 363 | f_pos = (udf_ext0_offset(dir) >> 2); | 372 | f_pos = udf_ext0_offset(dir); |
| 364 | 373 | ||
| 365 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 374 | fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); |
| 366 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 375 | dinfo = UDF_I(dir); |
| 376 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
| 367 | fibh->sbh = fibh->ebh = NULL; | 377 | fibh->sbh = fibh->ebh = NULL; |
| 368 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 378 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
| 369 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 379 | &epos, &eloc, &elen, &offset) == |
| 380 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
| 370 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 381 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
| 371 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 382 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
| 372 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 383 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 373 | epos.offset -= sizeof(short_ad); | 384 | epos.offset -= sizeof(short_ad); |
| 374 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 385 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 375 | epos.offset -= sizeof(long_ad); | 386 | epos.offset -= sizeof(long_ad); |
| 376 | } else { | 387 | } else |
| 377 | offset = 0; | 388 | offset = 0; |
| 378 | } | ||
| 379 | 389 | ||
| 380 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 390 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 391 | if (!fibh->sbh) { | ||
| 381 | brelse(epos.bh); | 392 | brelse(epos.bh); |
| 382 | *err = -EIO; | 393 | *err = -EIO; |
| 383 | return NULL; | 394 | return NULL; |
| 384 | } | 395 | } |
| 385 | 396 | ||
| 386 | block = UDF_I_LOCATION(dir).logicalBlockNum; | 397 | block = dinfo->i_location.logicalBlockNum; |
| 387 | |||
| 388 | } else { | 398 | } else { |
| 389 | block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0); | 399 | block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0); |
| 390 | fibh->sbh = fibh->ebh = NULL; | 400 | fibh->sbh = fibh->ebh = NULL; |
| 391 | fibh->soffset = fibh->eoffset = sb->s_blocksize; | 401 | fibh->soffset = fibh->eoffset = sb->s_blocksize; |
| 392 | goto add; | 402 | goto add; |
| 393 | } | 403 | } |
| 394 | 404 | ||
| 395 | while ((f_pos < size)) { | 405 | while (f_pos < size) { |
| 396 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, | 406 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 397 | &elen, &offset); | 407 | &elen, &offset); |
| 398 | 408 | ||
| @@ -408,33 +418,39 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 408 | liu = le16_to_cpu(cfi->lengthOfImpUse); | 418 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 409 | lfi = cfi->lengthFileIdent; | 419 | lfi = cfi->lengthFileIdent; |
| 410 | 420 | ||
| 411 | if (fibh->sbh == fibh->ebh) { | 421 | if (fibh->sbh == fibh->ebh) |
| 412 | nameptr = fi->fileIdent + liu; | 422 | nameptr = fi->fileIdent + liu; |
| 413 | } else { | 423 | else { |
| 414 | int poffset; /* Unpaded ending offset */ | 424 | int poffset; /* Unpaded ending offset */ |
| 415 | 425 | ||
| 416 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; | 426 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 427 | liu + lfi; | ||
| 417 | 428 | ||
| 418 | if (poffset >= lfi) { | 429 | if (poffset >= lfi) |
| 419 | nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); | 430 | nameptr = (char *)(fibh->ebh->b_data + |
| 420 | } else { | 431 | poffset - lfi); |
| 432 | else { | ||
| 421 | nameptr = fname; | 433 | nameptr = fname; |
| 422 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); | 434 | memcpy(nameptr, fi->fileIdent + liu, |
| 423 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); | 435 | lfi - poffset); |
| 436 | memcpy(nameptr + lfi - poffset, | ||
| 437 | fibh->ebh->b_data, poffset); | ||
| 424 | } | 438 | } |
| 425 | } | 439 | } |
| 426 | 440 | ||
| 427 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { | 441 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
| 428 | if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) { | 442 | if (((sizeof(struct fileIdentDesc) + |
| 443 | liu + lfi + 3) & ~3) == nfidlen) { | ||
| 429 | brelse(epos.bh); | 444 | brelse(epos.bh); |
| 430 | cfi->descTag.tagSerialNum = cpu_to_le16(1); | 445 | cfi->descTag.tagSerialNum = cpu_to_le16(1); |
| 431 | cfi->fileVersionNum = cpu_to_le16(1); | 446 | cfi->fileVersionNum = cpu_to_le16(1); |
| 432 | cfi->fileCharacteristics = 0; | 447 | cfi->fileCharacteristics = 0; |
| 433 | cfi->lengthFileIdent = namelen; | 448 | cfi->lengthFileIdent = namelen; |
| 434 | cfi->lengthOfImpUse = cpu_to_le16(0); | 449 | cfi->lengthOfImpUse = cpu_to_le16(0); |
| 435 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { | 450 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, |
| 451 | name)) | ||
| 436 | return fi; | 452 | return fi; |
| 437 | } else { | 453 | else { |
| 438 | *err = -EIO; | 454 | *err = -EIO; |
| 439 | return NULL; | 455 | return NULL; |
| 440 | } | 456 | } |
| @@ -444,8 +460,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 444 | if (!lfi || !dentry) | 460 | if (!lfi || !dentry) |
| 445 | continue; | 461 | continue; |
| 446 | 462 | ||
| 447 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && | 463 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 448 | udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { | 464 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 465 | dentry->d_name.name)) { | ||
| 449 | if (fibh->sbh != fibh->ebh) | 466 | if (fibh->sbh != fibh->ebh) |
| 450 | brelse(fibh->ebh); | 467 | brelse(fibh->ebh); |
| 451 | brelse(fibh->sbh); | 468 | brelse(fibh->sbh); |
| @@ -456,29 +473,34 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
| 456 | } | 473 | } |
| 457 | 474 | ||
| 458 | add: | 475 | add: |
| 476 | if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { | ||
| 477 | elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1); | ||
| 478 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) | ||
| 479 | epos.offset -= sizeof(short_ad); | ||
| 480 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) | ||
| 481 | epos.offset -= sizeof(long_ad); | ||
| 482 | udf_write_aext(dir, &epos, eloc, elen, 1); | ||
| 483 | } | ||
| 459 | f_pos += nfidlen; | 484 | f_pos += nfidlen; |
| 460 | 485 | ||
| 461 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && | 486 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && |
| 462 | sb->s_blocksize - fibh->eoffset < nfidlen) { | 487 | sb->s_blocksize - fibh->eoffset < nfidlen) { |
| 463 | brelse(epos.bh); | 488 | brelse(epos.bh); |
| 464 | epos.bh = NULL; | 489 | epos.bh = NULL; |
| 465 | fibh->soffset -= udf_ext0_offset(dir); | 490 | fibh->soffset -= udf_ext0_offset(dir); |
| 466 | fibh->eoffset -= udf_ext0_offset(dir); | 491 | fibh->eoffset -= udf_ext0_offset(dir); |
| 467 | f_pos -= (udf_ext0_offset(dir) >> 2); | 492 | f_pos -= udf_ext0_offset(dir); |
| 468 | if (fibh->sbh != fibh->ebh) | 493 | if (fibh->sbh != fibh->ebh) |
| 469 | brelse(fibh->ebh); | 494 | brelse(fibh->ebh); |
| 470 | brelse(fibh->sbh); | 495 | brelse(fibh->sbh); |
| 471 | if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) | 496 | fibh->sbh = fibh->ebh = |
| 497 | udf_expand_dir_adinicb(dir, &block, err); | ||
| 498 | if (!fibh->sbh) | ||
| 472 | return NULL; | 499 | return NULL; |
| 473 | epos.block = UDF_I_LOCATION(dir); | 500 | epos.block = dinfo->i_location; |
| 474 | eloc.logicalBlockNum = block; | ||
| 475 | eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; | ||
| 476 | elen = dir->i_sb->s_blocksize; | ||
| 477 | epos.offset = udf_file_entry_alloc_offset(dir); | 501 | epos.offset = udf_file_entry_alloc_offset(dir); |
| 478 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 502 | /* Load extent udf_expand_dir_adinicb() has created */ |
| 479 | epos.offset += sizeof(short_ad); | 503 | udf_current_aext(dir, &epos, &eloc, &elen, 1); |
| 480 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | ||
| 481 | epos.offset += sizeof(long_ad); | ||
| 482 | } | 504 | } |
| 483 | 505 | ||
| 484 | if (sb->s_blocksize - fibh->eoffset >= nfidlen) { | 506 | if (sb->s_blocksize - fibh->eoffset >= nfidlen) { |
| @@ -489,15 +511,19 @@ add: | |||
| 489 | fibh->sbh = fibh->ebh; | 511 | fibh->sbh = fibh->ebh; |
| 490 | } | 512 | } |
| 491 | 513 | ||
| 492 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 514 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 493 | block = UDF_I_LOCATION(dir).logicalBlockNum; | 515 | block = dinfo->i_location.logicalBlockNum; |
| 494 | fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - | 516 | fi = (struct fileIdentDesc *) |
| 495 | udf_ext0_offset(dir) + | 517 | (dinfo->i_ext.i_data + |
| 496 | UDF_I_LENEATTR(dir)); | 518 | fibh->soffset - |
| 519 | udf_ext0_offset(dir) + | ||
| 520 | dinfo->i_lenEAttr); | ||
| 497 | } else { | 521 | } else { |
| 498 | block = eloc.logicalBlockNum + ((elen - 1) >> | 522 | block = eloc.logicalBlockNum + |
| 499 | dir->i_sb->s_blocksize_bits); | 523 | ((elen - 1) >> |
| 500 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); | 524 | dir->i_sb->s_blocksize_bits); |
| 525 | fi = (struct fileIdentDesc *) | ||
| 526 | (fibh->sbh->b_data + fibh->soffset); | ||
| 501 | } | 527 | } |
| 502 | } else { | 528 | } else { |
| 503 | fibh->soffset = fibh->eoffset - sb->s_blocksize; | 529 | fibh->soffset = fibh->eoffset - sb->s_blocksize; |
| @@ -509,7 +535,8 @@ add: | |||
| 509 | 535 | ||
| 510 | block = eloc.logicalBlockNum + ((elen - 1) >> | 536 | block = eloc.logicalBlockNum + ((elen - 1) >> |
| 511 | dir->i_sb->s_blocksize_bits); | 537 | dir->i_sb->s_blocksize_bits); |
| 512 | fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err); | 538 | fibh->ebh = udf_bread(dir, |
| 539 | f_pos >> dir->i_sb->s_blocksize_bits, 1, err); | ||
| 513 | if (!fibh->ebh) { | 540 | if (!fibh->ebh) { |
| 514 | brelse(epos.bh); | 541 | brelse(epos.bh); |
| 515 | brelse(fibh->sbh); | 542 | brelse(fibh->sbh); |
| @@ -521,32 +548,34 @@ add: | |||
| 521 | (EXT_RECORDED_ALLOCATED >> 30)) { | 548 | (EXT_RECORDED_ALLOCATED >> 30)) { |
| 522 | block = eloc.logicalBlockNum + ((elen - 1) >> | 549 | block = eloc.logicalBlockNum + ((elen - 1) >> |
| 523 | dir->i_sb->s_blocksize_bits); | 550 | dir->i_sb->s_blocksize_bits); |
| 524 | } else { | 551 | } else |
| 525 | block++; | 552 | block++; |
| 526 | } | ||
| 527 | 553 | ||
| 528 | brelse(fibh->sbh); | 554 | brelse(fibh->sbh); |
| 529 | fibh->sbh = fibh->ebh; | 555 | fibh->sbh = fibh->ebh; |
| 530 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); | 556 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); |
| 531 | } else { | 557 | } else { |
| 532 | fi = (struct fileIdentDesc *) | 558 | fi = (struct fileIdentDesc *) |
| 533 | (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); | 559 | (fibh->sbh->b_data + sb->s_blocksize + |
| 560 | fibh->soffset); | ||
| 534 | } | 561 | } |
| 535 | } | 562 | } |
| 536 | 563 | ||
| 537 | memset(cfi, 0, sizeof(struct fileIdentDesc)); | 564 | memset(cfi, 0, sizeof(struct fileIdentDesc)); |
| 538 | if (UDF_SB_UDFREV(sb) >= 0x0200) | 565 | if (UDF_SB(sb)->s_udfrev >= 0x0200) |
| 539 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); | 566 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, |
| 567 | sizeof(tag)); | ||
| 540 | else | 568 | else |
| 541 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); | 569 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, |
| 570 | sizeof(tag)); | ||
| 542 | cfi->fileVersionNum = cpu_to_le16(1); | 571 | cfi->fileVersionNum = cpu_to_le16(1); |
| 543 | cfi->lengthFileIdent = namelen; | 572 | cfi->lengthFileIdent = namelen; |
| 544 | cfi->lengthOfImpUse = cpu_to_le16(0); | 573 | cfi->lengthOfImpUse = cpu_to_le16(0); |
| 545 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { | 574 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { |
| 546 | brelse(epos.bh); | 575 | brelse(epos.bh); |
| 547 | dir->i_size += nfidlen; | 576 | dir->i_size += nfidlen; |
| 548 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | 577 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 549 | UDF_I_LENALLOC(dir) += nfidlen; | 578 | dinfo->i_lenAlloc += nfidlen; |
| 550 | mark_inode_dirty(dir); | 579 | mark_inode_dirty(dir); |
| 551 | return fi; | 580 | return fi; |
| 552 | } else { | 581 | } else { |
| @@ -578,6 +607,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
| 578 | struct inode *inode; | 607 | struct inode *inode; |
| 579 | struct fileIdentDesc cfi, *fi; | 608 | struct fileIdentDesc cfi, *fi; |
| 580 | int err; | 609 | int err; |
| 610 | struct udf_inode_info *iinfo; | ||
| 581 | 611 | ||
| 582 | lock_kernel(); | 612 | lock_kernel(); |
| 583 | inode = udf_new_inode(dir, mode, &err); | 613 | inode = udf_new_inode(dir, mode, &err); |
| @@ -586,7 +616,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
| 586 | return err; | 616 | return err; |
| 587 | } | 617 | } |
| 588 | 618 | ||
| 589 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) | 619 | iinfo = UDF_I(inode); |
| 620 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
| 590 | inode->i_data.a_ops = &udf_adinicb_aops; | 621 | inode->i_data.a_ops = &udf_adinicb_aops; |
| 591 | else | 622 | else |
| 592 | inode->i_data.a_ops = &udf_aops; | 623 | inode->i_data.a_ops = &udf_aops; |
| @@ -595,7 +626,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
| 595 | inode->i_mode = mode; | 626 | inode->i_mode = mode; |
| 596 | mark_inode_dirty(inode); | 627 | mark_inode_dirty(inode); |
| 597 | 628 | ||
| 598 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 629 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 630 | if (!fi) { | ||
| 599 | inode->i_nlink--; | 631 | inode->i_nlink--; |
| 600 | mark_inode_dirty(inode); | 632 | mark_inode_dirty(inode); |
| 601 | iput(inode); | 633 | iput(inode); |
| @@ -603,13 +635,12 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
| 603 | return err; | 635 | return err; |
| 604 | } | 636 | } |
| 605 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 637 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 606 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 638 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
| 607 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 639 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 608 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 640 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
| 609 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 641 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
| 610 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 642 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 611 | mark_inode_dirty(dir); | 643 | mark_inode_dirty(dir); |
| 612 | } | ||
| 613 | if (fibh.sbh != fibh.ebh) | 644 | if (fibh.sbh != fibh.ebh) |
| 614 | brelse(fibh.ebh); | 645 | brelse(fibh.ebh); |
| 615 | brelse(fibh.sbh); | 646 | brelse(fibh.sbh); |
| @@ -626,6 +657,7 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
| 626 | struct udf_fileident_bh fibh; | 657 | struct udf_fileident_bh fibh; |
| 627 | struct fileIdentDesc cfi, *fi; | 658 | struct fileIdentDesc cfi, *fi; |
| 628 | int err; | 659 | int err; |
| 660 | struct udf_inode_info *iinfo; | ||
| 629 | 661 | ||
| 630 | if (!old_valid_dev(rdev)) | 662 | if (!old_valid_dev(rdev)) |
| 631 | return -EINVAL; | 663 | return -EINVAL; |
| @@ -636,9 +668,11 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
| 636 | if (!inode) | 668 | if (!inode) |
| 637 | goto out; | 669 | goto out; |
| 638 | 670 | ||
| 671 | iinfo = UDF_I(inode); | ||
| 639 | inode->i_uid = current->fsuid; | 672 | inode->i_uid = current->fsuid; |
| 640 | init_special_inode(inode, mode, rdev); | 673 | init_special_inode(inode, mode, rdev); |
| 641 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 674 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 675 | if (!fi) { | ||
| 642 | inode->i_nlink--; | 676 | inode->i_nlink--; |
| 643 | mark_inode_dirty(inode); | 677 | mark_inode_dirty(inode); |
| 644 | iput(inode); | 678 | iput(inode); |
| @@ -646,13 +680,12 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
| 646 | return err; | 680 | return err; |
| 647 | } | 681 | } |
| 648 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 682 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 649 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 683 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
| 650 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 684 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 651 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 685 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
| 652 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 686 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
| 653 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 687 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 654 | mark_inode_dirty(dir); | 688 | mark_inode_dirty(dir); |
| 655 | } | ||
| 656 | mark_inode_dirty(inode); | 689 | mark_inode_dirty(inode); |
| 657 | 690 | ||
| 658 | if (fibh.sbh != fibh.ebh) | 691 | if (fibh.sbh != fibh.ebh) |
| @@ -672,6 +705,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 672 | struct udf_fileident_bh fibh; | 705 | struct udf_fileident_bh fibh; |
| 673 | struct fileIdentDesc cfi, *fi; | 706 | struct fileIdentDesc cfi, *fi; |
| 674 | int err; | 707 | int err; |
| 708 | struct udf_inode_info *dinfo = UDF_I(dir); | ||
| 709 | struct udf_inode_info *iinfo; | ||
| 675 | 710 | ||
| 676 | lock_kernel(); | 711 | lock_kernel(); |
| 677 | err = -EMLINK; | 712 | err = -EMLINK; |
| @@ -683,9 +718,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 683 | if (!inode) | 718 | if (!inode) |
| 684 | goto out; | 719 | goto out; |
| 685 | 720 | ||
| 721 | iinfo = UDF_I(inode); | ||
| 686 | inode->i_op = &udf_dir_inode_operations; | 722 | inode->i_op = &udf_dir_inode_operations; |
| 687 | inode->i_fop = &udf_dir_operations; | 723 | inode->i_fop = &udf_dir_operations; |
| 688 | if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) { | 724 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); |
| 725 | if (!fi) { | ||
| 689 | inode->i_nlink--; | 726 | inode->i_nlink--; |
| 690 | mark_inode_dirty(inode); | 727 | mark_inode_dirty(inode); |
| 691 | iput(inode); | 728 | iput(inode); |
| @@ -693,10 +730,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 693 | } | 730 | } |
| 694 | inode->i_nlink = 2; | 731 | inode->i_nlink = 2; |
| 695 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 732 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 696 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); | 733 | cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location); |
| 697 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 734 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 698 | cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); | 735 | cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL); |
| 699 | cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; | 736 | cfi.fileCharacteristics = |
| 737 | FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; | ||
| 700 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); | 738 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); |
| 701 | brelse(fibh.sbh); | 739 | brelse(fibh.sbh); |
| 702 | inode->i_mode = S_IFDIR | mode; | 740 | inode->i_mode = S_IFDIR | mode; |
| @@ -704,16 +742,17 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 704 | inode->i_mode |= S_ISGID; | 742 | inode->i_mode |= S_ISGID; |
| 705 | mark_inode_dirty(inode); | 743 | mark_inode_dirty(inode); |
| 706 | 744 | ||
| 707 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 745 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 746 | if (!fi) { | ||
| 708 | inode->i_nlink = 0; | 747 | inode->i_nlink = 0; |
| 709 | mark_inode_dirty(inode); | 748 | mark_inode_dirty(inode); |
| 710 | iput(inode); | 749 | iput(inode); |
| 711 | goto out; | 750 | goto out; |
| 712 | } | 751 | } |
| 713 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 752 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 714 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 753 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
| 715 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 754 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 716 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 755 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
| 717 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; | 756 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; |
| 718 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 757 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
| 719 | inc_nlink(dir); | 758 | inc_nlink(dir); |
| @@ -734,32 +773,33 @@ static int empty_dir(struct inode *dir) | |||
| 734 | struct fileIdentDesc *fi, cfi; | 773 | struct fileIdentDesc *fi, cfi; |
| 735 | struct udf_fileident_bh fibh; | 774 | struct udf_fileident_bh fibh; |
| 736 | loff_t f_pos; | 775 | loff_t f_pos; |
| 737 | loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; | 776 | loff_t size = udf_ext0_offset(dir) + dir->i_size; |
| 738 | int block; | 777 | int block; |
| 739 | kernel_lb_addr eloc; | 778 | kernel_lb_addr eloc; |
| 740 | uint32_t elen; | 779 | uint32_t elen; |
| 741 | sector_t offset; | 780 | sector_t offset; |
| 742 | struct extent_position epos = {}; | 781 | struct extent_position epos = {}; |
| 782 | struct udf_inode_info *dinfo = UDF_I(dir); | ||
| 743 | 783 | ||
| 744 | f_pos = (udf_ext0_offset(dir) >> 2); | 784 | f_pos = udf_ext0_offset(dir); |
| 785 | fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1); | ||
| 745 | 786 | ||
| 746 | fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 787 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 747 | |||
| 748 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | ||
| 749 | fibh.sbh = fibh.ebh = NULL; | 788 | fibh.sbh = fibh.ebh = NULL; |
| 750 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 789 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
| 751 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 790 | &epos, &eloc, &elen, &offset) == |
| 791 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
| 752 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 792 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
| 753 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 793 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
| 754 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 794 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 755 | epos.offset -= sizeof(short_ad); | 795 | epos.offset -= sizeof(short_ad); |
| 756 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 796 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 757 | epos.offset -= sizeof(long_ad); | 797 | epos.offset -= sizeof(long_ad); |
| 758 | } else { | 798 | } else |
| 759 | offset = 0; | 799 | offset = 0; |
| 760 | } | ||
| 761 | 800 | ||
| 762 | if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { | 801 | fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block); |
| 802 | if (!fibh.sbh) { | ||
| 763 | brelse(epos.bh); | 803 | brelse(epos.bh); |
| 764 | return 0; | 804 | return 0; |
| 765 | } | 805 | } |
| @@ -768,7 +808,7 @@ static int empty_dir(struct inode *dir) | |||
| 768 | return 0; | 808 | return 0; |
| 769 | } | 809 | } |
| 770 | 810 | ||
| 771 | while ((f_pos < size)) { | 811 | while (f_pos < size) { |
| 772 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, | 812 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, |
| 773 | &elen, &offset); | 813 | &elen, &offset); |
| 774 | if (!fi) { | 814 | if (!fi) { |
| @@ -828,7 +868,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry) | |||
| 828 | clear_nlink(inode); | 868 | clear_nlink(inode); |
| 829 | inode->i_size = 0; | 869 | inode->i_size = 0; |
| 830 | inode_dec_link_count(dir); | 870 | inode_dec_link_count(dir); |
| 831 | inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); | 871 | inode->i_ctime = dir->i_ctime = dir->i_mtime = |
| 872 | current_fs_time(dir->i_sb); | ||
| 832 | mark_inode_dirty(dir); | 873 | mark_inode_dirty(dir); |
| 833 | 874 | ||
| 834 | end_rmdir: | 875 | end_rmdir: |
| @@ -901,36 +942,42 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
| 901 | int block; | 942 | int block; |
| 902 | char name[UDF_NAME_LEN]; | 943 | char name[UDF_NAME_LEN]; |
| 903 | int namelen; | 944 | int namelen; |
| 945 | struct buffer_head *bh; | ||
| 946 | struct udf_inode_info *iinfo; | ||
| 904 | 947 | ||
| 905 | lock_kernel(); | 948 | lock_kernel(); |
| 906 | if (!(inode = udf_new_inode(dir, S_IFLNK, &err))) | 949 | inode = udf_new_inode(dir, S_IFLNK, &err); |
| 950 | if (!inode) | ||
| 907 | goto out; | 951 | goto out; |
| 908 | 952 | ||
| 953 | iinfo = UDF_I(inode); | ||
| 909 | inode->i_mode = S_IFLNK | S_IRWXUGO; | 954 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
| 910 | inode->i_data.a_ops = &udf_symlink_aops; | 955 | inode->i_data.a_ops = &udf_symlink_aops; |
| 911 | inode->i_op = &page_symlink_inode_operations; | 956 | inode->i_op = &page_symlink_inode_operations; |
| 912 | 957 | ||
| 913 | if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) { | 958 | if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
| 914 | kernel_lb_addr eloc; | 959 | kernel_lb_addr eloc; |
| 915 | uint32_t elen; | 960 | uint32_t elen; |
| 916 | 961 | ||
| 917 | block = udf_new_block(inode->i_sb, inode, | 962 | block = udf_new_block(inode->i_sb, inode, |
| 918 | UDF_I_LOCATION(inode).partitionReferenceNum, | 963 | iinfo->i_location.partitionReferenceNum, |
| 919 | UDF_I_LOCATION(inode).logicalBlockNum, &err); | 964 | iinfo->i_location.logicalBlockNum, &err); |
| 920 | if (!block) | 965 | if (!block) |
| 921 | goto out_no_entry; | 966 | goto out_no_entry; |
| 922 | epos.block = UDF_I_LOCATION(inode); | 967 | epos.block = iinfo->i_location; |
| 923 | epos.offset = udf_file_entry_alloc_offset(inode); | 968 | epos.offset = udf_file_entry_alloc_offset(inode); |
| 924 | epos.bh = NULL; | 969 | epos.bh = NULL; |
| 925 | eloc.logicalBlockNum = block; | 970 | eloc.logicalBlockNum = block; |
| 926 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 971 | eloc.partitionReferenceNum = |
| 972 | iinfo->i_location.partitionReferenceNum; | ||
| 927 | elen = inode->i_sb->s_blocksize; | 973 | elen = inode->i_sb->s_blocksize; |
| 928 | UDF_I_LENEXTENTS(inode) = elen; | 974 | iinfo->i_lenExtents = elen; |
| 929 | udf_add_aext(inode, &epos, eloc, elen, 0); | 975 | udf_add_aext(inode, &epos, eloc, elen, 0); |
| 930 | brelse(epos.bh); | 976 | brelse(epos.bh); |
| 931 | 977 | ||
| 932 | block = udf_get_pblock(inode->i_sb, block, | 978 | block = udf_get_pblock(inode->i_sb, block, |
| 933 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); | 979 | iinfo->i_location.partitionReferenceNum, |
| 980 | 0); | ||
| 934 | epos.bh = udf_tread(inode->i_sb, block); | 981 | epos.bh = udf_tread(inode->i_sb, block); |
| 935 | lock_buffer(epos.bh); | 982 | lock_buffer(epos.bh); |
| 936 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); | 983 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); |
| @@ -938,9 +985,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
| 938 | unlock_buffer(epos.bh); | 985 | unlock_buffer(epos.bh); |
| 939 | mark_buffer_dirty_inode(epos.bh, inode); | 986 | mark_buffer_dirty_inode(epos.bh, inode); |
| 940 | ea = epos.bh->b_data + udf_ext0_offset(inode); | 987 | ea = epos.bh->b_data + udf_ext0_offset(inode); |
| 941 | } else { | 988 | } else |
| 942 | ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); | 989 | ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr; |
| 943 | } | ||
| 944 | 990 | ||
| 945 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); | 991 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); |
| 946 | pc = (struct pathComponent *)ea; | 992 | pc = (struct pathComponent *)ea; |
| @@ -977,7 +1023,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
| 977 | if (compstart[0] == '.') { | 1023 | if (compstart[0] == '.') { |
| 978 | if ((symname - compstart) == 1) | 1024 | if ((symname - compstart) == 1) |
| 979 | pc->componentType = 4; | 1025 | pc->componentType = 4; |
| 980 | else if ((symname - compstart) == 2 && compstart[1] == '.') | 1026 | else if ((symname - compstart) == 2 && |
| 1027 | compstart[1] == '.') | ||
| 981 | pc->componentType = 3; | 1028 | pc->componentType = 3; |
| 982 | } | 1029 | } |
| 983 | 1030 | ||
| @@ -987,7 +1034,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
| 987 | if (!namelen) | 1034 | if (!namelen) |
| 988 | goto out_no_entry; | 1035 | goto out_no_entry; |
| 989 | 1036 | ||
| 990 | if (elen + sizeof(struct pathComponent) + namelen > eoffset) | 1037 | if (elen + sizeof(struct pathComponent) + namelen > |
| 1038 | eoffset) | ||
| 991 | goto out_no_entry; | 1039 | goto out_no_entry; |
| 992 | else | 1040 | else |
| 993 | pc->lengthComponentIdent = namelen; | 1041 | pc->lengthComponentIdent = namelen; |
| @@ -1006,30 +1054,34 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
| 1006 | 1054 | ||
| 1007 | brelse(epos.bh); | 1055 | brelse(epos.bh); |
| 1008 | inode->i_size = elen; | 1056 | inode->i_size = elen; |
| 1009 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) | 1057 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1010 | UDF_I_LENALLOC(inode) = inode->i_size; | 1058 | iinfo->i_lenAlloc = inode->i_size; |
| 1011 | mark_inode_dirty(inode); | 1059 | mark_inode_dirty(inode); |
| 1012 | 1060 | ||
| 1013 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) | 1061 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1062 | if (!fi) | ||
| 1014 | goto out_no_entry; | 1063 | goto out_no_entry; |
| 1015 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 1064 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 1016 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 1065 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
| 1017 | if (UDF_SB_LVIDBH(inode->i_sb)) { | 1066 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1067 | if (bh) { | ||
| 1068 | struct logicalVolIntegrityDesc *lvid = | ||
| 1069 | (struct logicalVolIntegrityDesc *)bh->b_data; | ||
| 1018 | struct logicalVolHeaderDesc *lvhd; | 1070 | struct logicalVolHeaderDesc *lvhd; |
| 1019 | uint64_t uniqueID; | 1071 | uint64_t uniqueID; |
| 1020 | lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); | 1072 | lvhd = (struct logicalVolHeaderDesc *) |
| 1073 | lvid->logicalVolContentsUse; | ||
| 1021 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1074 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
| 1022 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1075 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1023 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1076 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
| 1024 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) | 1077 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1025 | uniqueID += 16; | 1078 | uniqueID += 16; |
| 1026 | lvhd->uniqueID = cpu_to_le64(uniqueID); | 1079 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
| 1027 | mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); | 1080 | mark_buffer_dirty(bh); |
| 1028 | } | 1081 | } |
| 1029 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 1082 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
| 1030 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 1083 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1031 | mark_inode_dirty(dir); | 1084 | mark_inode_dirty(dir); |
| 1032 | } | ||
| 1033 | if (fibh.sbh != fibh.ebh) | 1085 | if (fibh.sbh != fibh.ebh) |
| 1034 | brelse(fibh.ebh); | 1086 | brelse(fibh.ebh); |
| 1035 | brelse(fibh.sbh); | 1087 | brelse(fibh.sbh); |
| @@ -1053,6 +1105,7 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
| 1053 | struct udf_fileident_bh fibh; | 1105 | struct udf_fileident_bh fibh; |
| 1054 | struct fileIdentDesc cfi, *fi; | 1106 | struct fileIdentDesc cfi, *fi; |
| 1055 | int err; | 1107 | int err; |
| 1108 | struct buffer_head *bh; | ||
| 1056 | 1109 | ||
| 1057 | lock_kernel(); | 1110 | lock_kernel(); |
| 1058 | if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { | 1111 | if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { |
| @@ -1060,28 +1113,32 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
| 1060 | return -EMLINK; | 1113 | return -EMLINK; |
| 1061 | } | 1114 | } |
| 1062 | 1115 | ||
| 1063 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 1116 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1117 | if (!fi) { | ||
| 1064 | unlock_kernel(); | 1118 | unlock_kernel(); |
| 1065 | return err; | 1119 | return err; |
| 1066 | } | 1120 | } |
| 1067 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 1121 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
| 1068 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 1122 | cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location); |
| 1069 | if (UDF_SB_LVIDBH(inode->i_sb)) { | 1123 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1124 | if (bh) { | ||
| 1125 | struct logicalVolIntegrityDesc *lvid = | ||
| 1126 | (struct logicalVolIntegrityDesc *)bh->b_data; | ||
| 1070 | struct logicalVolHeaderDesc *lvhd; | 1127 | struct logicalVolHeaderDesc *lvhd; |
| 1071 | uint64_t uniqueID; | 1128 | uint64_t uniqueID; |
| 1072 | lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); | 1129 | lvhd = (struct logicalVolHeaderDesc *) |
| 1130 | (lvid->logicalVolContentsUse); | ||
| 1073 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1131 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
| 1074 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1132 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1075 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1133 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
| 1076 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) | 1134 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1077 | uniqueID += 16; | 1135 | uniqueID += 16; |
| 1078 | lvhd->uniqueID = cpu_to_le64(uniqueID); | 1136 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
| 1079 | mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); | 1137 | mark_buffer_dirty(bh); |
| 1080 | } | 1138 | } |
| 1081 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 1139 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
| 1082 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 1140 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1083 | mark_inode_dirty(dir); | 1141 | mark_inode_dirty(dir); |
| 1084 | } | ||
| 1085 | 1142 | ||
| 1086 | if (fibh.sbh != fibh.ebh) | 1143 | if (fibh.sbh != fibh.ebh) |
| 1087 | brelse(fibh.ebh); | 1144 | brelse(fibh.ebh); |
| @@ -1105,13 +1162,16 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 1105 | struct inode *old_inode = old_dentry->d_inode; | 1162 | struct inode *old_inode = old_dentry->d_inode; |
| 1106 | struct inode *new_inode = new_dentry->d_inode; | 1163 | struct inode *new_inode = new_dentry->d_inode; |
| 1107 | struct udf_fileident_bh ofibh, nfibh; | 1164 | struct udf_fileident_bh ofibh, nfibh; |
| 1108 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; | 1165 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; |
| 1166 | struct fileIdentDesc ocfi, ncfi; | ||
| 1109 | struct buffer_head *dir_bh = NULL; | 1167 | struct buffer_head *dir_bh = NULL; |
| 1110 | int retval = -ENOENT; | 1168 | int retval = -ENOENT; |
| 1111 | kernel_lb_addr tloc; | 1169 | kernel_lb_addr tloc; |
| 1170 | struct udf_inode_info *old_iinfo = UDF_I(old_inode); | ||
| 1112 | 1171 | ||
| 1113 | lock_kernel(); | 1172 | lock_kernel(); |
| 1114 | if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) { | 1173 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
| 1174 | if (ofi) { | ||
| 1115 | if (ofibh.sbh != ofibh.ebh) | 1175 | if (ofibh.sbh != ofibh.ebh) |
| 1116 | brelse(ofibh.ebh); | 1176 | brelse(ofibh.ebh); |
| 1117 | brelse(ofibh.sbh); | 1177 | brelse(ofibh.sbh); |
| @@ -1131,7 +1191,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 1131 | } | 1191 | } |
| 1132 | } | 1192 | } |
| 1133 | if (S_ISDIR(old_inode->i_mode)) { | 1193 | if (S_ISDIR(old_inode->i_mode)) { |
| 1134 | uint32_t offset = udf_ext0_offset(old_inode); | 1194 | int offset = udf_ext0_offset(old_inode); |
| 1135 | 1195 | ||
| 1136 | if (new_inode) { | 1196 | if (new_inode) { |
| 1137 | retval = -ENOTEMPTY; | 1197 | retval = -ENOTEMPTY; |
| @@ -1139,30 +1199,36 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 1139 | goto end_rename; | 1199 | goto end_rename; |
| 1140 | } | 1200 | } |
| 1141 | retval = -EIO; | 1201 | retval = -EIO; |
| 1142 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1202 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 1143 | dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - | 1203 | dir_fi = udf_get_fileident( |
| 1144 | (UDF_I_EFE(old_inode) ? | 1204 | old_iinfo->i_ext.i_data - |
| 1145 | sizeof(struct extendedFileEntry) : | 1205 | (old_iinfo->i_efe ? |
| 1146 | sizeof(struct fileEntry)), | 1206 | sizeof(struct extendedFileEntry) : |
| 1147 | old_inode->i_sb->s_blocksize, &offset); | 1207 | sizeof(struct fileEntry)), |
| 1208 | old_inode->i_sb->s_blocksize, &offset); | ||
| 1148 | } else { | 1209 | } else { |
| 1149 | dir_bh = udf_bread(old_inode, 0, 0, &retval); | 1210 | dir_bh = udf_bread(old_inode, 0, 0, &retval); |
| 1150 | if (!dir_bh) | 1211 | if (!dir_bh) |
| 1151 | goto end_rename; | 1212 | goto end_rename; |
| 1152 | dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); | 1213 | dir_fi = udf_get_fileident(dir_bh->b_data, |
| 1214 | old_inode->i_sb->s_blocksize, &offset); | ||
| 1153 | } | 1215 | } |
| 1154 | if (!dir_fi) | 1216 | if (!dir_fi) |
| 1155 | goto end_rename; | 1217 | goto end_rename; |
| 1156 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); | 1218 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); |
| 1157 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino) | 1219 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != |
| 1220 | old_dir->i_ino) | ||
| 1158 | goto end_rename; | 1221 | goto end_rename; |
| 1159 | 1222 | ||
| 1160 | retval = -EMLINK; | 1223 | retval = -EMLINK; |
| 1161 | if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1) | 1224 | if (!new_inode && |
| 1225 | new_dir->i_nlink >= | ||
| 1226 | (256 << sizeof(new_dir->i_nlink)) - 1) | ||
| 1162 | goto end_rename; | 1227 | goto end_rename; |
| 1163 | } | 1228 | } |
| 1164 | if (!nfi) { | 1229 | if (!nfi) { |
| 1165 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); | 1230 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, |
| 1231 | &retval); | ||
| 1166 | if (!nfi) | 1232 | if (!nfi) |
| 1167 | goto end_rename; | 1233 | goto end_rename; |
| 1168 | } | 1234 | } |
| @@ -1194,18 +1260,19 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 1194 | mark_inode_dirty(old_dir); | 1260 | mark_inode_dirty(old_dir); |
| 1195 | 1261 | ||
| 1196 | if (dir_fi) { | 1262 | if (dir_fi) { |
| 1197 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); | 1263 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location); |
| 1198 | udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + | 1264 | udf_update_tag((char *)dir_fi, |
| 1199 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); | 1265 | (sizeof(struct fileIdentDesc) + |
| 1200 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1266 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); |
| 1267 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
| 1201 | mark_inode_dirty(old_inode); | 1268 | mark_inode_dirty(old_inode); |
| 1202 | } else { | 1269 | else |
| 1203 | mark_buffer_dirty_inode(dir_bh, old_inode); | 1270 | mark_buffer_dirty_inode(dir_bh, old_inode); |
| 1204 | } | 1271 | |
| 1205 | inode_dec_link_count(old_dir); | 1272 | inode_dec_link_count(old_dir); |
| 1206 | if (new_inode) { | 1273 | if (new_inode) |
| 1207 | inode_dec_link_count(new_inode); | 1274 | inode_dec_link_count(new_inode); |
| 1208 | } else { | 1275 | else { |
| 1209 | inc_nlink(new_dir); | 1276 | inc_nlink(new_dir); |
| 1210 | mark_inode_dirty(new_dir); | 1277 | mark_inode_dirty(new_dir); |
| 1211 | } | 1278 | } |
diff --git a/fs/udf/partition.c b/fs/udf/partition.c index aaab24c8c498..fc533345ab89 100644 --- a/fs/udf/partition.c +++ b/fs/udf/partition.c | |||
| @@ -31,15 +31,18 @@ | |||
| 31 | inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, | 31 | inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, |
| 32 | uint16_t partition, uint32_t offset) | 32 | uint16_t partition, uint32_t offset) |
| 33 | { | 33 | { |
| 34 | if (partition >= UDF_SB_NUMPARTS(sb)) { | 34 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 35 | udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", | 35 | struct udf_part_map *map; |
| 36 | block, partition, offset); | 36 | if (partition >= sbi->s_partitions) { |
| 37 | udf_debug("block=%d, partition=%d, offset=%d: " | ||
| 38 | "invalid partition\n", block, partition, offset); | ||
| 37 | return 0xFFFFFFFF; | 39 | return 0xFFFFFFFF; |
| 38 | } | 40 | } |
| 39 | if (UDF_SB_PARTFUNC(sb, partition)) | 41 | map = &sbi->s_partmaps[partition]; |
| 40 | return UDF_SB_PARTFUNC(sb, partition)(sb, block, partition, offset); | 42 | if (map->s_partition_func) |
| 43 | return map->s_partition_func(sb, block, partition, offset); | ||
| 41 | else | 44 | else |
| 42 | return UDF_SB_PARTROOT(sb, partition) + block + offset; | 45 | return map->s_partition_root + block + offset; |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | 48 | uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, |
| @@ -49,12 +52,18 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
| 49 | uint32_t newblock; | 52 | uint32_t newblock; |
| 50 | uint32_t index; | 53 | uint32_t index; |
| 51 | uint32_t loc; | 54 | uint32_t loc; |
| 55 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 56 | struct udf_part_map *map; | ||
| 57 | struct udf_virtual_data *vdata; | ||
| 58 | struct udf_inode_info *iinfo; | ||
| 52 | 59 | ||
| 53 | index = (sb->s_blocksize - UDF_SB_TYPEVIRT(sb,partition).s_start_offset) / sizeof(uint32_t); | 60 | map = &sbi->s_partmaps[partition]; |
| 61 | vdata = &map->s_type_specific.s_virtual; | ||
| 62 | index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t); | ||
| 54 | 63 | ||
| 55 | if (block > UDF_SB_TYPEVIRT(sb,partition).s_num_entries) { | 64 | if (block > vdata->s_num_entries) { |
| 56 | udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", | 65 | udf_debug("Trying to access block beyond end of VAT " |
| 57 | block, UDF_SB_TYPEVIRT(sb,partition).s_num_entries); | 66 | "(%d max %d)\n", block, vdata->s_num_entries); |
| 58 | return 0xFFFFFFFF; | 67 | return 0xFFFFFFFF; |
| 59 | } | 68 | } |
| 60 | 69 | ||
| @@ -64,12 +73,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
| 64 | index = block % (sb->s_blocksize / sizeof(uint32_t)); | 73 | index = block % (sb->s_blocksize / sizeof(uint32_t)); |
| 65 | } else { | 74 | } else { |
| 66 | newblock = 0; | 75 | newblock = 0; |
| 67 | index = UDF_SB_TYPEVIRT(sb,partition).s_start_offset / sizeof(uint32_t) + block; | 76 | index = vdata->s_start_offset / sizeof(uint32_t) + block; |
| 68 | } | 77 | } |
| 69 | 78 | ||
| 70 | loc = udf_block_map(UDF_SB_VAT(sb), newblock); | 79 | loc = udf_block_map(sbi->s_vat_inode, newblock); |
| 71 | 80 | ||
| 72 | if (!(bh = sb_bread(sb, loc))) { | 81 | bh = sb_bread(sb, loc); |
| 82 | if (!bh) { | ||
| 73 | udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", | 83 | udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", |
| 74 | sb, block, partition, loc, index); | 84 | sb, block, partition, loc, index); |
| 75 | return 0xFFFFFFFF; | 85 | return 0xFFFFFFFF; |
| @@ -79,50 +89,61 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
| 79 | 89 | ||
| 80 | brelse(bh); | 90 | brelse(bh); |
| 81 | 91 | ||
| 82 | if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) { | 92 | iinfo = UDF_I(sbi->s_vat_inode); |
| 93 | if (iinfo->i_location.partitionReferenceNum == partition) { | ||
| 83 | udf_debug("recursive call to udf_get_pblock!\n"); | 94 | udf_debug("recursive call to udf_get_pblock!\n"); |
| 84 | return 0xFFFFFFFF; | 95 | return 0xFFFFFFFF; |
| 85 | } | 96 | } |
| 86 | 97 | ||
| 87 | return udf_get_pblock(sb, loc, | 98 | return udf_get_pblock(sb, loc, |
| 88 | UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum, | 99 | iinfo->i_location.partitionReferenceNum, |
| 89 | offset); | 100 | offset); |
| 90 | } | 101 | } |
| 91 | 102 | ||
| 92 | inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block, | 103 | inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block, |
| 93 | uint16_t partition, uint32_t offset) | 104 | uint16_t partition, uint32_t offset) |
| 94 | { | 105 | { |
| 95 | return udf_get_pblock_virt15(sb, block, partition, offset); | 106 | return udf_get_pblock_virt15(sb, block, partition, offset); |
| 96 | } | 107 | } |
| 97 | 108 | ||
| 98 | uint32_t udf_get_pblock_spar15(struct super_block * sb, uint32_t block, | 109 | uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, |
| 99 | uint16_t partition, uint32_t offset) | 110 | uint16_t partition, uint32_t offset) |
| 100 | { | 111 | { |
| 101 | int i; | 112 | int i; |
| 102 | struct sparingTable *st = NULL; | 113 | struct sparingTable *st = NULL; |
| 103 | uint32_t packet = (block + offset) & ~(UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1); | 114 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 115 | struct udf_part_map *map; | ||
| 116 | uint32_t packet; | ||
| 117 | struct udf_sparing_data *sdata; | ||
| 118 | |||
| 119 | map = &sbi->s_partmaps[partition]; | ||
| 120 | sdata = &map->s_type_specific.s_sparing; | ||
| 121 | packet = (block + offset) & ~(sdata->s_packet_len - 1); | ||
| 104 | 122 | ||
| 105 | for (i = 0; i < 4; i++) { | 123 | for (i = 0; i < 4; i++) { |
| 106 | if (UDF_SB_TYPESPAR(sb,partition).s_spar_map[i] != NULL) { | 124 | if (sdata->s_spar_map[i] != NULL) { |
| 107 | st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,partition).s_spar_map[i]->b_data; | 125 | st = (struct sparingTable *) |
| 126 | sdata->s_spar_map[i]->b_data; | ||
| 108 | break; | 127 | break; |
| 109 | } | 128 | } |
| 110 | } | 129 | } |
| 111 | 130 | ||
| 112 | if (st) { | 131 | if (st) { |
| 113 | for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { | 132 | for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { |
| 114 | if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) { | 133 | struct sparingEntry *entry = &st->mapEntry[i]; |
| 134 | u32 origLoc = le32_to_cpu(entry->origLocation); | ||
| 135 | if (origLoc >= 0xFFFFFFF0) | ||
| 115 | break; | 136 | break; |
| 116 | } else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) { | 137 | else if (origLoc == packet) |
| 117 | return le32_to_cpu(st->mapEntry[i].mappedLocation) + | 138 | return le32_to_cpu(entry->mappedLocation) + |
| 118 | ((block + offset) & (UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1)); | 139 | ((block + offset) & |
| 119 | } else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) { | 140 | (sdata->s_packet_len - 1)); |
| 141 | else if (origLoc > packet) | ||
| 120 | break; | 142 | break; |
| 121 | } | ||
| 122 | } | 143 | } |
| 123 | } | 144 | } |
| 124 | 145 | ||
| 125 | return UDF_SB_PARTROOT(sb,partition) + block + offset; | 146 | return map->s_partition_root + block + offset; |
| 126 | } | 147 | } |
| 127 | 148 | ||
| 128 | int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) | 149 | int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) |
| @@ -132,69 +153,109 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) | |||
| 132 | struct sparingEntry mapEntry; | 153 | struct sparingEntry mapEntry; |
| 133 | uint32_t packet; | 154 | uint32_t packet; |
| 134 | int i, j, k, l; | 155 | int i, j, k, l; |
| 156 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 157 | u16 reallocationTableLen; | ||
| 158 | struct buffer_head *bh; | ||
| 135 | 159 | ||
| 136 | for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { | 160 | for (i = 0; i < sbi->s_partitions; i++) { |
| 137 | if (old_block > UDF_SB_PARTROOT(sb,i) && | 161 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
| 138 | old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i)) { | 162 | if (old_block > map->s_partition_root && |
| 139 | sdata = &UDF_SB_TYPESPAR(sb,i); | 163 | old_block < map->s_partition_root + map->s_partition_len) { |
| 140 | packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1); | 164 | sdata = &map->s_type_specific.s_sparing; |
| 165 | packet = (old_block - map->s_partition_root) & | ||
| 166 | ~(sdata->s_packet_len - 1); | ||
| 141 | 167 | ||
| 142 | for (j = 0; j < 4; j++) { | 168 | for (j = 0; j < 4; j++) |
| 143 | if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) { | 169 | if (sdata->s_spar_map[j] != NULL) { |
| 144 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 170 | st = (struct sparingTable *) |
| 171 | sdata->s_spar_map[j]->b_data; | ||
| 145 | break; | 172 | break; |
| 146 | } | 173 | } |
| 147 | } | ||
| 148 | 174 | ||
| 149 | if (!st) | 175 | if (!st) |
| 150 | return 1; | 176 | return 1; |
| 151 | 177 | ||
| 152 | for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) { | 178 | reallocationTableLen = |
| 153 | if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) { | 179 | le16_to_cpu(st->reallocationTableLen); |
| 180 | for (k = 0; k < reallocationTableLen; k++) { | ||
| 181 | struct sparingEntry *entry = &st->mapEntry[k]; | ||
| 182 | u32 origLoc = le32_to_cpu(entry->origLocation); | ||
| 183 | |||
| 184 | if (origLoc == 0xFFFFFFFF) { | ||
| 154 | for (; j < 4; j++) { | 185 | for (; j < 4; j++) { |
| 155 | if (sdata->s_spar_map[j]) { | 186 | int len; |
| 156 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 187 | bh = sdata->s_spar_map[j]; |
| 157 | st->mapEntry[k].origLocation = cpu_to_le32(packet); | 188 | if (!bh) |
| 158 | udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); | 189 | continue; |
| 159 | mark_buffer_dirty(sdata->s_spar_map[j]); | 190 | |
| 160 | } | 191 | st = (struct sparingTable *) |
| 192 | bh->b_data; | ||
| 193 | entry->origLocation = | ||
| 194 | cpu_to_le32(packet); | ||
| 195 | len = | ||
| 196 | sizeof(struct sparingTable) + | ||
| 197 | reallocationTableLen * | ||
| 198 | sizeof(struct sparingEntry); | ||
| 199 | udf_update_tag((char *)st, len); | ||
| 200 | mark_buffer_dirty(bh); | ||
| 161 | } | 201 | } |
| 162 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 202 | *new_block = le32_to_cpu( |
| 163 | ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); | 203 | entry->mappedLocation) + |
| 204 | ((old_block - | ||
| 205 | map->s_partition_root) & | ||
| 206 | (sdata->s_packet_len - 1)); | ||
| 164 | return 0; | 207 | return 0; |
| 165 | } else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) { | 208 | } else if (origLoc == packet) { |
| 166 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 209 | *new_block = le32_to_cpu( |
| 167 | ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); | 210 | entry->mappedLocation) + |
| 211 | ((old_block - | ||
| 212 | map->s_partition_root) & | ||
| 213 | (sdata->s_packet_len - 1)); | ||
| 168 | return 0; | 214 | return 0; |
| 169 | } else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) { | 215 | } else if (origLoc > packet) |
| 170 | break; | 216 | break; |
| 171 | } | ||
| 172 | } | 217 | } |
| 173 | 218 | ||
| 174 | for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) { | 219 | for (l = k; l < reallocationTableLen; l++) { |
| 175 | if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) { | 220 | struct sparingEntry *entry = &st->mapEntry[l]; |
| 176 | for (; j < 4; j++) { | 221 | u32 origLoc = le32_to_cpu(entry->origLocation); |
| 177 | if (sdata->s_spar_map[j]) { | 222 | |
| 178 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 223 | if (origLoc != 0xFFFFFFFF) |
| 179 | mapEntry = st->mapEntry[l]; | 224 | continue; |
| 180 | mapEntry.origLocation = cpu_to_le32(packet); | 225 | |
| 181 | memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry)); | 226 | for (; j < 4; j++) { |
| 182 | st->mapEntry[k] = mapEntry; | 227 | bh = sdata->s_spar_map[j]; |
| 183 | udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); | 228 | if (!bh) |
| 184 | mark_buffer_dirty(sdata->s_spar_map[j]); | 229 | continue; |
| 185 | } | 230 | |
| 186 | } | 231 | st = (struct sparingTable *)bh->b_data; |
| 187 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 232 | mapEntry = st->mapEntry[l]; |
| 188 | ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); | 233 | mapEntry.origLocation = |
| 189 | return 0; | 234 | cpu_to_le32(packet); |
| 235 | memmove(&st->mapEntry[k + 1], | ||
| 236 | &st->mapEntry[k], | ||
| 237 | (l - k) * | ||
| 238 | sizeof(struct sparingEntry)); | ||
| 239 | st->mapEntry[k] = mapEntry; | ||
| 240 | udf_update_tag((char *)st, | ||
| 241 | sizeof(struct sparingTable) + | ||
| 242 | reallocationTableLen * | ||
| 243 | sizeof(struct sparingEntry)); | ||
| 244 | mark_buffer_dirty(bh); | ||
| 190 | } | 245 | } |
| 246 | *new_block = | ||
| 247 | le32_to_cpu( | ||
| 248 | st->mapEntry[k].mappedLocation) + | ||
| 249 | ((old_block - map->s_partition_root) & | ||
| 250 | (sdata->s_packet_len - 1)); | ||
| 251 | return 0; | ||
| 191 | } | 252 | } |
| 192 | 253 | ||
| 193 | return 1; | 254 | return 1; |
| 194 | } /* if old_block */ | 255 | } /* if old_block */ |
| 195 | } | 256 | } |
| 196 | 257 | ||
| 197 | if (i == UDF_SB_NUMPARTS(sb)) { | 258 | if (i == sbi->s_partitions) { |
| 198 | /* outside of partitions */ | 259 | /* outside of partitions */ |
| 199 | /* for now, fail =) */ | 260 | /* for now, fail =) */ |
| 200 | return 1; | 261 | return 1; |
diff --git a/fs/udf/super.c b/fs/udf/super.c index 4360c7a05743..f3ac4abfc946 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c | |||
| @@ -33,8 +33,8 @@ | |||
| 33 | * 10/17/98 added freespace count for "df" | 33 | * 10/17/98 added freespace count for "df" |
| 34 | * 11/11/98 gr added novrs option | 34 | * 11/11/98 gr added novrs option |
| 35 | * 11/26/98 dgb added fileset,anchor mount options | 35 | * 11/26/98 dgb added fileset,anchor mount options |
| 36 | * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs | 36 | * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced |
| 37 | * rewrote option handling based on isofs | 37 | * vol descs. rewrote option handling based on isofs |
| 38 | * 12/20/98 find the free space bitmap (if it exists) | 38 | * 12/20/98 find the free space bitmap (if it exists) |
| 39 | */ | 39 | */ |
| 40 | 40 | ||
| @@ -52,6 +52,9 @@ | |||
| 52 | #include <linux/buffer_head.h> | 52 | #include <linux/buffer_head.h> |
| 53 | #include <linux/vfs.h> | 53 | #include <linux/vfs.h> |
| 54 | #include <linux/vmalloc.h> | 54 | #include <linux/vmalloc.h> |
| 55 | #include <linux/errno.h> | ||
| 56 | #include <linux/mount.h> | ||
| 57 | #include <linux/seq_file.h> | ||
| 55 | #include <asm/byteorder.h> | 58 | #include <asm/byteorder.h> |
| 56 | 59 | ||
| 57 | #include <linux/udf_fs.h> | 60 | #include <linux/udf_fs.h> |
| @@ -70,6 +73,8 @@ | |||
| 70 | #define VDS_POS_TERMINATING_DESC 6 | 73 | #define VDS_POS_TERMINATING_DESC 6 |
| 71 | #define VDS_POS_LENGTH 7 | 74 | #define VDS_POS_LENGTH 7 |
| 72 | 75 | ||
| 76 | #define UDF_DEFAULT_BLOCKSIZE 2048 | ||
| 77 | |||
| 73 | static char error_buf[1024]; | 78 | static char error_buf[1024]; |
| 74 | 79 | ||
| 75 | /* These are the "meat" - everything else is stuffing */ | 80 | /* These are the "meat" - everything else is stuffing */ |
| @@ -94,6 +99,17 @@ static void udf_open_lvid(struct super_block *); | |||
| 94 | static void udf_close_lvid(struct super_block *); | 99 | static void udf_close_lvid(struct super_block *); |
| 95 | static unsigned int udf_count_free(struct super_block *); | 100 | static unsigned int udf_count_free(struct super_block *); |
| 96 | static int udf_statfs(struct dentry *, struct kstatfs *); | 101 | static int udf_statfs(struct dentry *, struct kstatfs *); |
| 102 | static int udf_show_options(struct seq_file *, struct vfsmount *); | ||
| 103 | |||
| 104 | struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) | ||
| 105 | { | ||
| 106 | struct logicalVolIntegrityDesc *lvid = | ||
| 107 | (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | ||
| 108 | __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions); | ||
| 109 | __u32 offset = number_of_partitions * 2 * | ||
| 110 | sizeof(uint32_t)/sizeof(uint8_t); | ||
| 111 | return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); | ||
| 112 | } | ||
| 97 | 113 | ||
| 98 | /* UDF filesystem type */ | 114 | /* UDF filesystem type */ |
| 99 | static int udf_get_sb(struct file_system_type *fs_type, | 115 | static int udf_get_sb(struct file_system_type *fs_type, |
| @@ -116,7 +132,7 @@ static struct kmem_cache *udf_inode_cachep; | |||
| 116 | static struct inode *udf_alloc_inode(struct super_block *sb) | 132 | static struct inode *udf_alloc_inode(struct super_block *sb) |
| 117 | { | 133 | { |
| 118 | struct udf_inode_info *ei; | 134 | struct udf_inode_info *ei; |
| 119 | ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL); | 135 | ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL); |
| 120 | if (!ei) | 136 | if (!ei) |
| 121 | return NULL; | 137 | return NULL; |
| 122 | 138 | ||
| @@ -170,6 +186,7 @@ static const struct super_operations udf_sb_ops = { | |||
| 170 | .write_super = udf_write_super, | 186 | .write_super = udf_write_super, |
| 171 | .statfs = udf_statfs, | 187 | .statfs = udf_statfs, |
| 172 | .remount_fs = udf_remount_fs, | 188 | .remount_fs = udf_remount_fs, |
| 189 | .show_options = udf_show_options, | ||
| 173 | }; | 190 | }; |
| 174 | 191 | ||
| 175 | struct udf_options { | 192 | struct udf_options { |
| @@ -218,6 +235,79 @@ static void __exit exit_udf_fs(void) | |||
| 218 | module_init(init_udf_fs) | 235 | module_init(init_udf_fs) |
| 219 | module_exit(exit_udf_fs) | 236 | module_exit(exit_udf_fs) |
| 220 | 237 | ||
| 238 | static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count) | ||
| 239 | { | ||
| 240 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 241 | |||
| 242 | sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map), | ||
| 243 | GFP_KERNEL); | ||
| 244 | if (!sbi->s_partmaps) { | ||
| 245 | udf_error(sb, __FUNCTION__, | ||
| 246 | "Unable to allocate space for %d partition maps", | ||
| 247 | count); | ||
| 248 | sbi->s_partitions = 0; | ||
| 249 | return -ENOMEM; | ||
| 250 | } | ||
| 251 | |||
| 252 | sbi->s_partitions = count; | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | |||
| 256 | static int udf_show_options(struct seq_file *seq, struct vfsmount *mnt) | ||
| 257 | { | ||
| 258 | struct super_block *sb = mnt->mnt_sb; | ||
| 259 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 260 | |||
| 261 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT)) | ||
| 262 | seq_puts(seq, ",nostrict"); | ||
| 263 | if (sb->s_blocksize != UDF_DEFAULT_BLOCKSIZE) | ||
| 264 | seq_printf(seq, ",bs=%lu", sb->s_blocksize); | ||
| 265 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE)) | ||
| 266 | seq_puts(seq, ",unhide"); | ||
| 267 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE)) | ||
| 268 | seq_puts(seq, ",undelete"); | ||
| 269 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB)) | ||
| 270 | seq_puts(seq, ",noadinicb"); | ||
| 271 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD)) | ||
| 272 | seq_puts(seq, ",shortad"); | ||
| 273 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET)) | ||
| 274 | seq_puts(seq, ",uid=forget"); | ||
| 275 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE)) | ||
| 276 | seq_puts(seq, ",uid=ignore"); | ||
| 277 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET)) | ||
| 278 | seq_puts(seq, ",gid=forget"); | ||
| 279 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE)) | ||
| 280 | seq_puts(seq, ",gid=ignore"); | ||
| 281 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET)) | ||
| 282 | seq_printf(seq, ",uid=%u", sbi->s_uid); | ||
| 283 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET)) | ||
| 284 | seq_printf(seq, ",gid=%u", sbi->s_gid); | ||
| 285 | if (sbi->s_umask != 0) | ||
| 286 | seq_printf(seq, ",umask=%o", sbi->s_umask); | ||
| 287 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET)) | ||
| 288 | seq_printf(seq, ",session=%u", sbi->s_session); | ||
| 289 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET)) | ||
| 290 | seq_printf(seq, ",lastblock=%u", sbi->s_last_block); | ||
| 291 | /* | ||
| 292 | * s_anchor[2] could be zeroed out in case there is no anchor | ||
| 293 | * in the specified block, but then the "anchor=N" option | ||
| 294 | * originally given by the user wasn't effective, so it's OK | ||
| 295 | * if we don't show it. | ||
| 296 | */ | ||
| 297 | if (sbi->s_anchor[2] != 0) | ||
| 298 | seq_printf(seq, ",anchor=%u", sbi->s_anchor[2]); | ||
| 299 | /* | ||
| 300 | * volume, partition, fileset and rootdir seem to be ignored | ||
| 301 | * currently | ||
| 302 | */ | ||
| 303 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) | ||
| 304 | seq_puts(seq, ",utf8"); | ||
| 305 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map) | ||
| 306 | seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset); | ||
| 307 | |||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | |||
| 221 | /* | 311 | /* |
| 222 | * udf_parse_options | 312 | * udf_parse_options |
| 223 | * | 313 | * |
| @@ -310,13 +400,14 @@ static match_table_t tokens = { | |||
| 310 | {Opt_err, NULL} | 400 | {Opt_err, NULL} |
| 311 | }; | 401 | }; |
| 312 | 402 | ||
| 313 | static int udf_parse_options(char *options, struct udf_options *uopt) | 403 | static int udf_parse_options(char *options, struct udf_options *uopt, |
| 404 | bool remount) | ||
| 314 | { | 405 | { |
| 315 | char *p; | 406 | char *p; |
| 316 | int option; | 407 | int option; |
| 317 | 408 | ||
| 318 | uopt->novrs = 0; | 409 | uopt->novrs = 0; |
| 319 | uopt->blocksize = 2048; | 410 | uopt->blocksize = UDF_DEFAULT_BLOCKSIZE; |
| 320 | uopt->partition = 0xFFFF; | 411 | uopt->partition = 0xFFFF; |
| 321 | uopt->session = 0xFFFFFFFF; | 412 | uopt->session = 0xFFFFFFFF; |
| 322 | uopt->lastblock = 0; | 413 | uopt->lastblock = 0; |
| @@ -386,11 +477,15 @@ static int udf_parse_options(char *options, struct udf_options *uopt) | |||
| 386 | if (match_int(args, &option)) | 477 | if (match_int(args, &option)) |
| 387 | return 0; | 478 | return 0; |
| 388 | uopt->session = option; | 479 | uopt->session = option; |
| 480 | if (!remount) | ||
| 481 | uopt->flags |= (1 << UDF_FLAG_SESSION_SET); | ||
| 389 | break; | 482 | break; |
| 390 | case Opt_lastblock: | 483 | case Opt_lastblock: |
| 391 | if (match_int(args, &option)) | 484 | if (match_int(args, &option)) |
| 392 | return 0; | 485 | return 0; |
| 393 | uopt->lastblock = option; | 486 | uopt->lastblock = option; |
| 487 | if (!remount) | ||
| 488 | uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET); | ||
| 394 | break; | 489 | break; |
| 395 | case Opt_anchor: | 490 | case Opt_anchor: |
| 396 | if (match_int(args, &option)) | 491 | if (match_int(args, &option)) |
| @@ -447,7 +542,7 @@ static int udf_parse_options(char *options, struct udf_options *uopt) | |||
| 447 | return 1; | 542 | return 1; |
| 448 | } | 543 | } |
| 449 | 544 | ||
| 450 | void udf_write_super(struct super_block *sb) | 545 | static void udf_write_super(struct super_block *sb) |
| 451 | { | 546 | { |
| 452 | lock_kernel(); | 547 | lock_kernel(); |
| 453 | 548 | ||
| @@ -461,22 +556,23 @@ void udf_write_super(struct super_block *sb) | |||
| 461 | static int udf_remount_fs(struct super_block *sb, int *flags, char *options) | 556 | static int udf_remount_fs(struct super_block *sb, int *flags, char *options) |
| 462 | { | 557 | { |
| 463 | struct udf_options uopt; | 558 | struct udf_options uopt; |
| 559 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 464 | 560 | ||
| 465 | uopt.flags = UDF_SB(sb)->s_flags; | 561 | uopt.flags = sbi->s_flags; |
| 466 | uopt.uid = UDF_SB(sb)->s_uid; | 562 | uopt.uid = sbi->s_uid; |
| 467 | uopt.gid = UDF_SB(sb)->s_gid; | 563 | uopt.gid = sbi->s_gid; |
| 468 | uopt.umask = UDF_SB(sb)->s_umask; | 564 | uopt.umask = sbi->s_umask; |
| 469 | 565 | ||
| 470 | if (!udf_parse_options(options, &uopt)) | 566 | if (!udf_parse_options(options, &uopt, true)) |
| 471 | return -EINVAL; | 567 | return -EINVAL; |
| 472 | 568 | ||
| 473 | UDF_SB(sb)->s_flags = uopt.flags; | 569 | sbi->s_flags = uopt.flags; |
| 474 | UDF_SB(sb)->s_uid = uopt.uid; | 570 | sbi->s_uid = uopt.uid; |
| 475 | UDF_SB(sb)->s_gid = uopt.gid; | 571 | sbi->s_gid = uopt.gid; |
| 476 | UDF_SB(sb)->s_umask = uopt.umask; | 572 | sbi->s_umask = uopt.umask; |
| 477 | 573 | ||
| 478 | if (UDF_SB_LVIDBH(sb)) { | 574 | if (sbi->s_lvid_bh) { |
| 479 | int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); | 575 | int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev); |
| 480 | if (write_rev > UDF_MAX_WRITE_VERSION) | 576 | if (write_rev > UDF_MAX_WRITE_VERSION) |
| 481 | *flags |= MS_RDONLY; | 577 | *flags |= MS_RDONLY; |
| 482 | } | 578 | } |
| @@ -538,17 +634,19 @@ static int udf_vrs(struct super_block *sb, int silent) | |||
| 538 | int iso9660 = 0; | 634 | int iso9660 = 0; |
| 539 | int nsr02 = 0; | 635 | int nsr02 = 0; |
| 540 | int nsr03 = 0; | 636 | int nsr03 = 0; |
| 637 | struct udf_sb_info *sbi; | ||
| 541 | 638 | ||
| 542 | /* Block size must be a multiple of 512 */ | 639 | /* Block size must be a multiple of 512 */ |
| 543 | if (sb->s_blocksize & 511) | 640 | if (sb->s_blocksize & 511) |
| 544 | return 0; | 641 | return 0; |
| 642 | sbi = UDF_SB(sb); | ||
| 545 | 643 | ||
| 546 | if (sb->s_blocksize < sizeof(struct volStructDesc)) | 644 | if (sb->s_blocksize < sizeof(struct volStructDesc)) |
| 547 | sectorsize = sizeof(struct volStructDesc); | 645 | sectorsize = sizeof(struct volStructDesc); |
| 548 | else | 646 | else |
| 549 | sectorsize = sb->s_blocksize; | 647 | sectorsize = sb->s_blocksize; |
| 550 | 648 | ||
| 551 | sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits); | 649 | sector += (sbi->s_session << sb->s_blocksize_bits); |
| 552 | 650 | ||
| 553 | udf_debug("Starting at sector %u (%ld byte sectors)\n", | 651 | udf_debug("Starting at sector %u (%ld byte sectors)\n", |
| 554 | (sector >> sb->s_blocksize_bits), sb->s_blocksize); | 652 | (sector >> sb->s_blocksize_bits), sb->s_blocksize); |
| @@ -561,47 +659,52 @@ static int udf_vrs(struct super_block *sb, int silent) | |||
| 561 | 659 | ||
| 562 | /* Look for ISO descriptors */ | 660 | /* Look for ISO descriptors */ |
| 563 | vsd = (struct volStructDesc *)(bh->b_data + | 661 | vsd = (struct volStructDesc *)(bh->b_data + |
| 564 | (sector & (sb->s_blocksize - 1))); | 662 | (sector & (sb->s_blocksize - 1))); |
| 565 | 663 | ||
| 566 | if (vsd->stdIdent[0] == 0) { | 664 | if (vsd->stdIdent[0] == 0) { |
| 567 | brelse(bh); | 665 | brelse(bh); |
| 568 | break; | 666 | break; |
| 569 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) { | 667 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, |
| 668 | VSD_STD_ID_LEN)) { | ||
| 570 | iso9660 = sector; | 669 | iso9660 = sector; |
| 571 | switch (vsd->structType) { | 670 | switch (vsd->structType) { |
| 572 | case 0: | 671 | case 0: |
| 573 | udf_debug("ISO9660 Boot Record found\n"); | 672 | udf_debug("ISO9660 Boot Record found\n"); |
| 574 | break; | 673 | break; |
| 575 | case 1: | 674 | case 1: |
| 576 | udf_debug | 675 | udf_debug("ISO9660 Primary Volume Descriptor " |
| 577 | ("ISO9660 Primary Volume Descriptor found\n"); | 676 | "found\n"); |
| 578 | break; | 677 | break; |
| 579 | case 2: | 678 | case 2: |
| 580 | udf_debug | 679 | udf_debug("ISO9660 Supplementary Volume " |
| 581 | ("ISO9660 Supplementary Volume Descriptor found\n"); | 680 | "Descriptor found\n"); |
| 582 | break; | 681 | break; |
| 583 | case 3: | 682 | case 3: |
| 584 | udf_debug | 683 | udf_debug("ISO9660 Volume Partition Descriptor " |
| 585 | ("ISO9660 Volume Partition Descriptor found\n"); | 684 | "found\n"); |
| 586 | break; | 685 | break; |
| 587 | case 255: | 686 | case 255: |
| 588 | udf_debug | 687 | udf_debug("ISO9660 Volume Descriptor Set " |
| 589 | ("ISO9660 Volume Descriptor Set Terminator found\n"); | 688 | "Terminator found\n"); |
| 590 | break; | 689 | break; |
| 591 | default: | 690 | default: |
| 592 | udf_debug("ISO9660 VRS (%u) found\n", | 691 | udf_debug("ISO9660 VRS (%u) found\n", |
| 593 | vsd->structType); | 692 | vsd->structType); |
| 594 | break; | 693 | break; |
| 595 | } | 694 | } |
| 596 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) { | 695 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, |
| 597 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) { | 696 | VSD_STD_ID_LEN)) |
| 697 | ; /* nothing */ | ||
| 698 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, | ||
| 699 | VSD_STD_ID_LEN)) { | ||
| 598 | brelse(bh); | 700 | brelse(bh); |
| 599 | break; | 701 | break; |
| 600 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) { | 702 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, |
| 703 | VSD_STD_ID_LEN)) | ||
| 601 | nsr02 = sector; | 704 | nsr02 = sector; |
| 602 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) { | 705 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, |
| 706 | VSD_STD_ID_LEN)) | ||
| 603 | nsr03 = sector; | 707 | nsr03 = sector; |
| 604 | } | ||
| 605 | brelse(bh); | 708 | brelse(bh); |
| 606 | } | 709 | } |
| 607 | 710 | ||
| @@ -609,7 +712,7 @@ static int udf_vrs(struct super_block *sb, int silent) | |||
| 609 | return nsr03; | 712 | return nsr03; |
| 610 | else if (nsr02) | 713 | else if (nsr02) |
| 611 | return nsr02; | 714 | return nsr02; |
| 612 | else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768) | 715 | else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768) |
| 613 | return -1; | 716 | return -1; |
| 614 | else | 717 | else |
| 615 | return 0; | 718 | return 0; |
| @@ -634,11 +737,15 @@ static int udf_vrs(struct super_block *sb, int silent) | |||
| 634 | */ | 737 | */ |
| 635 | static void udf_find_anchor(struct super_block *sb) | 738 | static void udf_find_anchor(struct super_block *sb) |
| 636 | { | 739 | { |
| 637 | int lastblock = UDF_SB_LASTBLOCK(sb); | 740 | int lastblock; |
| 638 | struct buffer_head *bh = NULL; | 741 | struct buffer_head *bh = NULL; |
| 639 | uint16_t ident; | 742 | uint16_t ident; |
| 640 | uint32_t location; | 743 | uint32_t location; |
| 641 | int i; | 744 | int i; |
| 745 | struct udf_sb_info *sbi; | ||
| 746 | |||
| 747 | sbi = UDF_SB(sb); | ||
| 748 | lastblock = sbi->s_last_block; | ||
| 642 | 749 | ||
| 643 | if (lastblock) { | 750 | if (lastblock) { |
| 644 | int varlastblock = udf_variable_to_fixed(lastblock); | 751 | int varlastblock = udf_variable_to_fixed(lastblock); |
| @@ -658,57 +765,83 @@ static void udf_find_anchor(struct super_block *sb) | |||
| 658 | * however, if the disc isn't closed, it could be 512 */ | 765 | * however, if the disc isn't closed, it could be 512 */ |
| 659 | 766 | ||
| 660 | for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) { | 767 | for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) { |
| 661 | if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) { | 768 | ident = location = 0; |
| 662 | ident = location = 0; | 769 | if (last[i] >= 0) { |
| 663 | } else { | 770 | bh = sb_bread(sb, last[i]); |
| 664 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); | 771 | if (bh) { |
| 665 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | 772 | tag *t = (tag *)bh->b_data; |
| 666 | brelse(bh); | 773 | ident = le16_to_cpu(t->tagIdent); |
| 774 | location = le32_to_cpu(t->tagLocation); | ||
| 775 | brelse(bh); | ||
| 776 | } | ||
| 667 | } | 777 | } |
| 668 | 778 | ||
| 669 | if (ident == TAG_IDENT_AVDP) { | 779 | if (ident == TAG_IDENT_AVDP) { |
| 670 | if (location == last[i] - UDF_SB_SESSION(sb)) { | 780 | if (location == last[i] - sbi->s_session) { |
| 671 | lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb); | 781 | lastblock = last[i] - sbi->s_session; |
| 672 | UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb); | 782 | sbi->s_anchor[0] = lastblock; |
| 673 | } else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) { | 783 | sbi->s_anchor[1] = lastblock - 256; |
| 784 | } else if (location == | ||
| 785 | udf_variable_to_fixed(last[i]) - | ||
| 786 | sbi->s_session) { | ||
| 674 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | 787 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); |
| 675 | lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb); | 788 | lastblock = |
| 676 | UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb); | 789 | udf_variable_to_fixed(last[i]) - |
| 790 | sbi->s_session; | ||
| 791 | sbi->s_anchor[0] = lastblock; | ||
| 792 | sbi->s_anchor[1] = lastblock - 256 - | ||
| 793 | sbi->s_session; | ||
| 677 | } else { | 794 | } else { |
| 678 | udf_debug("Anchor found at block %d, location mismatch %d.\n", | 795 | udf_debug("Anchor found at block %d, " |
| 796 | "location mismatch %d.\n", | ||
| 679 | last[i], location); | 797 | last[i], location); |
| 680 | } | 798 | } |
| 681 | } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) { | 799 | } else if (ident == TAG_IDENT_FE || |
| 800 | ident == TAG_IDENT_EFE) { | ||
| 682 | lastblock = last[i]; | 801 | lastblock = last[i]; |
| 683 | UDF_SB_ANCHOR(sb)[3] = 512; | 802 | sbi->s_anchor[3] = 512; |
| 684 | } else { | 803 | } else { |
| 685 | if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256))) { | 804 | ident = location = 0; |
| 686 | ident = location = 0; | 805 | if (last[i] >= 256) { |
| 687 | } else { | 806 | bh = sb_bread(sb, last[i] - 256); |
| 688 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); | 807 | if (bh) { |
| 689 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | 808 | tag *t = (tag *)bh->b_data; |
| 690 | brelse(bh); | 809 | ident = le16_to_cpu( |
| 810 | t->tagIdent); | ||
| 811 | location = le32_to_cpu( | ||
| 812 | t->tagLocation); | ||
| 813 | brelse(bh); | ||
| 814 | } | ||
| 691 | } | 815 | } |
| 692 | 816 | ||
| 693 | if (ident == TAG_IDENT_AVDP && | 817 | if (ident == TAG_IDENT_AVDP && |
| 694 | location == last[i] - 256 - UDF_SB_SESSION(sb)) { | 818 | location == last[i] - 256 - |
| 819 | sbi->s_session) { | ||
| 695 | lastblock = last[i]; | 820 | lastblock = last[i]; |
| 696 | UDF_SB_ANCHOR(sb)[1] = last[i] - 256; | 821 | sbi->s_anchor[1] = last[i] - 256; |
| 697 | } else { | 822 | } else { |
| 698 | if (last[i] < 312 + UDF_SB_SESSION(sb) || | 823 | ident = location = 0; |
| 699 | !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb)))) { | 824 | if (last[i] >= 312 + sbi->s_session) { |
| 700 | ident = location = 0; | 825 | bh = sb_bread(sb, |
| 701 | } else { | 826 | last[i] - 312 - |
| 702 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); | 827 | sbi->s_session); |
| 703 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | 828 | if (bh) { |
| 704 | brelse(bh); | 829 | tag *t = (tag *) |
| 830 | bh->b_data; | ||
| 831 | ident = le16_to_cpu( | ||
| 832 | t->tagIdent); | ||
| 833 | location = le32_to_cpu( | ||
| 834 | t->tagLocation); | ||
| 835 | brelse(bh); | ||
| 836 | } | ||
| 705 | } | 837 | } |
| 706 | 838 | ||
| 707 | if (ident == TAG_IDENT_AVDP && | 839 | if (ident == TAG_IDENT_AVDP && |
| 708 | location == udf_variable_to_fixed(last[i]) - 256) { | 840 | location == udf_variable_to_fixed(last[i]) - 256) { |
| 709 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | 841 | UDF_SET_FLAG(sb, |
| 842 | UDF_FLAG_VARCONV); | ||
| 710 | lastblock = udf_variable_to_fixed(last[i]); | 843 | lastblock = udf_variable_to_fixed(last[i]); |
| 711 | UDF_SB_ANCHOR(sb)[1] = lastblock - 256; | 844 | sbi->s_anchor[1] = lastblock - 256; |
| 712 | } | 845 | } |
| 713 | } | 846 | } |
| 714 | } | 847 | } |
| @@ -716,10 +849,12 @@ static void udf_find_anchor(struct super_block *sb) | |||
| 716 | } | 849 | } |
| 717 | 850 | ||
| 718 | if (!lastblock) { | 851 | if (!lastblock) { |
| 719 | /* We havn't found the lastblock. check 312 */ | 852 | /* We haven't found the lastblock. check 312 */ |
| 720 | if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) { | 853 | bh = sb_bread(sb, 312 + sbi->s_session); |
| 721 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); | 854 | if (bh) { |
| 722 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | 855 | tag *t = (tag *)bh->b_data; |
| 856 | ident = le16_to_cpu(t->tagIdent); | ||
| 857 | location = le32_to_cpu(t->tagLocation); | ||
| 723 | brelse(bh); | 858 | brelse(bh); |
| 724 | 859 | ||
| 725 | if (ident == TAG_IDENT_AVDP && location == 256) | 860 | if (ident == TAG_IDENT_AVDP && location == 256) |
| @@ -727,29 +862,33 @@ static void udf_find_anchor(struct super_block *sb) | |||
| 727 | } | 862 | } |
| 728 | } | 863 | } |
| 729 | 864 | ||
| 730 | for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { | 865 | for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) { |
| 731 | if (UDF_SB_ANCHOR(sb)[i]) { | 866 | if (sbi->s_anchor[i]) { |
| 732 | if (!(bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i], | 867 | bh = udf_read_tagged(sb, sbi->s_anchor[i], |
| 733 | UDF_SB_ANCHOR(sb)[i], &ident))) { | 868 | sbi->s_anchor[i], &ident); |
| 734 | UDF_SB_ANCHOR(sb)[i] = 0; | 869 | if (!bh) |
| 735 | } else { | 870 | sbi->s_anchor[i] = 0; |
| 871 | else { | ||
| 736 | brelse(bh); | 872 | brelse(bh); |
| 737 | if ((ident != TAG_IDENT_AVDP) && | 873 | if ((ident != TAG_IDENT_AVDP) && |
| 738 | (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) { | 874 | (i || (ident != TAG_IDENT_FE && |
| 739 | UDF_SB_ANCHOR(sb)[i] = 0; | 875 | ident != TAG_IDENT_EFE))) |
| 740 | } | 876 | sbi->s_anchor[i] = 0; |
| 741 | } | 877 | } |
| 742 | } | 878 | } |
| 743 | } | 879 | } |
| 744 | 880 | ||
| 745 | UDF_SB_LASTBLOCK(sb) = lastblock; | 881 | sbi->s_last_block = lastblock; |
| 746 | } | 882 | } |
| 747 | 883 | ||
| 748 | static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root) | 884 | static int udf_find_fileset(struct super_block *sb, |
| 885 | kernel_lb_addr *fileset, | ||
| 886 | kernel_lb_addr *root) | ||
| 749 | { | 887 | { |
| 750 | struct buffer_head *bh = NULL; | 888 | struct buffer_head *bh = NULL; |
| 751 | long lastblock; | 889 | long lastblock; |
| 752 | uint16_t ident; | 890 | uint16_t ident; |
| 891 | struct udf_sb_info *sbi; | ||
| 753 | 892 | ||
| 754 | if (fileset->logicalBlockNum != 0xFFFFFFFF || | 893 | if (fileset->logicalBlockNum != 0xFFFFFFFF || |
| 755 | fileset->partitionReferenceNum != 0xFFFF) { | 894 | fileset->partitionReferenceNum != 0xFFFF) { |
| @@ -764,22 +903,27 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker | |||
| 764 | 903 | ||
| 765 | } | 904 | } |
| 766 | 905 | ||
| 767 | if (!bh) { /* Search backwards through the partitions */ | 906 | sbi = UDF_SB(sb); |
| 907 | if (!bh) { | ||
| 908 | /* Search backwards through the partitions */ | ||
| 768 | kernel_lb_addr newfileset; | 909 | kernel_lb_addr newfileset; |
| 769 | 910 | ||
| 770 | /* --> cvg: FIXME - is it reasonable? */ | 911 | /* --> cvg: FIXME - is it reasonable? */ |
| 771 | return 1; | 912 | return 1; |
| 772 | 913 | ||
| 773 | for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1; | 914 | for (newfileset.partitionReferenceNum = sbi->s_partitions - 1; |
| 774 | (newfileset.partitionReferenceNum != 0xFFFF && | 915 | (newfileset.partitionReferenceNum != 0xFFFF && |
| 775 | fileset->logicalBlockNum == 0xFFFFFFFF && | 916 | fileset->logicalBlockNum == 0xFFFFFFFF && |
| 776 | fileset->partitionReferenceNum == 0xFFFF); | 917 | fileset->partitionReferenceNum == 0xFFFF); |
| 777 | newfileset.partitionReferenceNum--) { | 918 | newfileset.partitionReferenceNum--) { |
| 778 | lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum); | 919 | lastblock = sbi->s_partmaps |
| 920 | [newfileset.partitionReferenceNum] | ||
| 921 | .s_partition_len; | ||
| 779 | newfileset.logicalBlockNum = 0; | 922 | newfileset.logicalBlockNum = 0; |
| 780 | 923 | ||
| 781 | do { | 924 | do { |
| 782 | bh = udf_read_ptagged(sb, newfileset, 0, &ident); | 925 | bh = udf_read_ptagged(sb, newfileset, 0, |
| 926 | &ident); | ||
| 783 | if (!bh) { | 927 | if (!bh) { |
| 784 | newfileset.logicalBlockNum++; | 928 | newfileset.logicalBlockNum++; |
| 785 | continue; | 929 | continue; |
| @@ -789,11 +933,12 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker | |||
| 789 | case TAG_IDENT_SBD: | 933 | case TAG_IDENT_SBD: |
| 790 | { | 934 | { |
| 791 | struct spaceBitmapDesc *sp; | 935 | struct spaceBitmapDesc *sp; |
| 792 | sp = (struct spaceBitmapDesc *)bh->b_data; | 936 | sp = (struct spaceBitmapDesc *) |
| 937 | bh->b_data; | ||
| 793 | newfileset.logicalBlockNum += 1 + | 938 | newfileset.logicalBlockNum += 1 + |
| 794 | ((le32_to_cpu(sp->numOfBytes) + | 939 | ((le32_to_cpu(sp->numOfBytes) + |
| 795 | sizeof(struct spaceBitmapDesc) - 1) | 940 | sizeof(struct spaceBitmapDesc) |
| 796 | >> sb->s_blocksize_bits); | 941 | - 1) >> sb->s_blocksize_bits); |
| 797 | brelse(bh); | 942 | brelse(bh); |
| 798 | break; | 943 | break; |
| 799 | } | 944 | } |
| @@ -818,7 +963,7 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker | |||
| 818 | fileset->logicalBlockNum, | 963 | fileset->logicalBlockNum, |
| 819 | fileset->partitionReferenceNum); | 964 | fileset->partitionReferenceNum); |
| 820 | 965 | ||
| 821 | UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum; | 966 | sbi->s_partition = fileset->partitionReferenceNum; |
| 822 | udf_load_fileset(sb, bh, root); | 967 | udf_load_fileset(sb, bh, root); |
| 823 | brelse(bh); | 968 | brelse(bh); |
| 824 | return 0; | 969 | return 0; |
| @@ -840,26 +985,26 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh) | |||
| 840 | lets_to_cpu(pvoldesc->recordingDateAndTime))) { | 985 | lets_to_cpu(pvoldesc->recordingDateAndTime))) { |
| 841 | kernel_timestamp ts; | 986 | kernel_timestamp ts; |
| 842 | ts = lets_to_cpu(pvoldesc->recordingDateAndTime); | 987 | ts = lets_to_cpu(pvoldesc->recordingDateAndTime); |
| 843 | udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n", | 988 | udf_debug("recording time %ld/%ld, %04u/%02u/%02u" |
| 989 | " %02u:%02u (%x)\n", | ||
| 844 | recording, recording_usec, | 990 | recording, recording_usec, |
| 845 | ts.year, ts.month, ts.day, ts.hour, | 991 | ts.year, ts.month, ts.day, ts.hour, |
| 846 | ts.minute, ts.typeAndTimezone); | 992 | ts.minute, ts.typeAndTimezone); |
| 847 | UDF_SB_RECORDTIME(sb).tv_sec = recording; | 993 | UDF_SB(sb)->s_record_time.tv_sec = recording; |
| 848 | UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000; | 994 | UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000; |
| 849 | } | 995 | } |
| 850 | 996 | ||
| 851 | if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) { | 997 | if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) |
| 852 | if (udf_CS0toUTF8(&outstr, &instr)) { | 998 | if (udf_CS0toUTF8(&outstr, &instr)) { |
| 853 | strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name, | 999 | strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name, |
| 854 | outstr.u_len > 31 ? 31 : outstr.u_len); | 1000 | outstr.u_len > 31 ? 31 : outstr.u_len); |
| 855 | udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb)); | 1001 | udf_debug("volIdent[] = '%s'\n", |
| 1002 | UDF_SB(sb)->s_volume_ident); | ||
| 856 | } | 1003 | } |
| 857 | } | ||
| 858 | 1004 | ||
| 859 | if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) { | 1005 | if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) |
| 860 | if (udf_CS0toUTF8(&outstr, &instr)) | 1006 | if (udf_CS0toUTF8(&outstr, &instr)) |
| 861 | udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); | 1007 | udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); |
| 862 | } | ||
| 863 | } | 1008 | } |
| 864 | 1009 | ||
| 865 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, | 1010 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, |
| @@ -871,65 +1016,124 @@ static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, | |||
| 871 | 1016 | ||
| 872 | *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation); | 1017 | *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation); |
| 873 | 1018 | ||
| 874 | UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum); | 1019 | UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum); |
| 875 | 1020 | ||
| 876 | udf_debug("Rootdir at block=%d, partition=%d\n", | 1021 | udf_debug("Rootdir at block=%d, partition=%d\n", |
| 877 | root->logicalBlockNum, root->partitionReferenceNum); | 1022 | root->logicalBlockNum, root->partitionReferenceNum); |
| 878 | } | 1023 | } |
| 879 | 1024 | ||
| 1025 | int udf_compute_nr_groups(struct super_block *sb, u32 partition) | ||
| 1026 | { | ||
| 1027 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; | ||
| 1028 | return (map->s_partition_len + | ||
| 1029 | (sizeof(struct spaceBitmapDesc) << 3) + | ||
| 1030 | (sb->s_blocksize * 8) - 1) / | ||
| 1031 | (sb->s_blocksize * 8); | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) | ||
| 1035 | { | ||
| 1036 | struct udf_bitmap *bitmap; | ||
| 1037 | int nr_groups; | ||
| 1038 | int size; | ||
| 1039 | |||
| 1040 | nr_groups = udf_compute_nr_groups(sb, index); | ||
| 1041 | size = sizeof(struct udf_bitmap) + | ||
| 1042 | (sizeof(struct buffer_head *) * nr_groups); | ||
| 1043 | |||
| 1044 | if (size <= PAGE_SIZE) | ||
| 1045 | bitmap = kmalloc(size, GFP_KERNEL); | ||
| 1046 | else | ||
| 1047 | bitmap = vmalloc(size); /* TODO: get rid of vmalloc */ | ||
| 1048 | |||
| 1049 | if (bitmap == NULL) { | ||
| 1050 | udf_error(sb, __FUNCTION__, | ||
| 1051 | "Unable to allocate space for bitmap " | ||
| 1052 | "and %d buffer_head pointers", nr_groups); | ||
| 1053 | return NULL; | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | memset(bitmap, 0x00, size); | ||
| 1057 | bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1); | ||
| 1058 | bitmap->s_nr_groups = nr_groups; | ||
| 1059 | return bitmap; | ||
| 1060 | } | ||
| 1061 | |||
| 880 | static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | 1062 | static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) |
| 881 | { | 1063 | { |
| 882 | struct partitionDesc *p; | 1064 | struct partitionDesc *p; |
| 883 | int i; | 1065 | int i; |
| 1066 | struct udf_part_map *map; | ||
| 1067 | struct udf_sb_info *sbi; | ||
| 884 | 1068 | ||
| 885 | p = (struct partitionDesc *)bh->b_data; | 1069 | p = (struct partitionDesc *)bh->b_data; |
| 1070 | sbi = UDF_SB(sb); | ||
| 886 | 1071 | ||
| 887 | for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { | 1072 | for (i = 0; i < sbi->s_partitions; i++) { |
| 1073 | map = &sbi->s_partmaps[i]; | ||
| 888 | udf_debug("Searching map: (%d == %d)\n", | 1074 | udf_debug("Searching map: (%d == %d)\n", |
| 889 | UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber)); | 1075 | map->s_partition_num, |
| 890 | if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) { | 1076 | le16_to_cpu(p->partitionNumber)); |
| 891 | UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */ | 1077 | if (map->s_partition_num == |
| 892 | UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation); | 1078 | le16_to_cpu(p->partitionNumber)) { |
| 893 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) | 1079 | map->s_partition_len = |
| 894 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY; | 1080 | le32_to_cpu(p->partitionLength); /* blocks */ |
| 895 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE) | 1081 | map->s_partition_root = |
| 896 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE; | 1082 | le32_to_cpu(p->partitionStartingLocation); |
| 897 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE) | 1083 | if (p->accessType == |
| 898 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE; | 1084 | cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY)) |
| 899 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE) | 1085 | map->s_partition_flags |= |
| 900 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE; | 1086 | UDF_PART_FLAG_READ_ONLY; |
| 901 | 1087 | if (p->accessType == | |
| 902 | if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) || | 1088 | cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE)) |
| 903 | !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) { | 1089 | map->s_partition_flags |= |
| 1090 | UDF_PART_FLAG_WRITE_ONCE; | ||
| 1091 | if (p->accessType == | ||
| 1092 | cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE)) | ||
| 1093 | map->s_partition_flags |= | ||
| 1094 | UDF_PART_FLAG_REWRITABLE; | ||
| 1095 | if (p->accessType == | ||
| 1096 | cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE)) | ||
| 1097 | map->s_partition_flags |= | ||
| 1098 | UDF_PART_FLAG_OVERWRITABLE; | ||
| 1099 | |||
| 1100 | if (!strcmp(p->partitionContents.ident, | ||
| 1101 | PD_PARTITION_CONTENTS_NSR02) || | ||
| 1102 | !strcmp(p->partitionContents.ident, | ||
| 1103 | PD_PARTITION_CONTENTS_NSR03)) { | ||
| 904 | struct partitionHeaderDesc *phd; | 1104 | struct partitionHeaderDesc *phd; |
| 905 | 1105 | ||
| 906 | phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); | 1106 | phd = (struct partitionHeaderDesc *) |
| 1107 | (p->partitionContentsUse); | ||
| 907 | if (phd->unallocSpaceTable.extLength) { | 1108 | if (phd->unallocSpaceTable.extLength) { |
| 908 | kernel_lb_addr loc = { | 1109 | kernel_lb_addr loc = { |
| 909 | .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), | 1110 | .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), |
| 910 | .partitionReferenceNum = i, | 1111 | .partitionReferenceNum = i, |
| 911 | }; | 1112 | }; |
| 912 | 1113 | ||
| 913 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table = | 1114 | map->s_uspace.s_table = |
| 914 | udf_iget(sb, loc); | 1115 | udf_iget(sb, loc); |
| 915 | if (!UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table) { | 1116 | if (!map->s_uspace.s_table) { |
| 916 | udf_debug("cannot load unallocSpaceTable (part %d)\n", i); | 1117 | udf_debug("cannot load unallocSpaceTable (part %d)\n", i); |
| 917 | return 1; | 1118 | return 1; |
| 918 | } | 1119 | } |
| 919 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE; | 1120 | map->s_partition_flags |= |
| 1121 | UDF_PART_FLAG_UNALLOC_TABLE; | ||
| 920 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", | 1122 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", |
| 921 | i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino); | 1123 | i, map->s_uspace.s_table->i_ino); |
| 922 | } | 1124 | } |
| 923 | if (phd->unallocSpaceBitmap.extLength) { | 1125 | if (phd->unallocSpaceBitmap.extLength) { |
| 924 | UDF_SB_ALLOC_BITMAP(sb, i, s_uspace); | 1126 | struct udf_bitmap *bitmap = |
| 925 | if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) { | 1127 | udf_sb_alloc_bitmap(sb, i); |
| 926 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength = | 1128 | map->s_uspace.s_bitmap = bitmap; |
| 1129 | if (bitmap != NULL) { | ||
| 1130 | bitmap->s_extLength = | ||
| 927 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); | 1131 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); |
| 928 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition = | 1132 | bitmap->s_extPosition = |
| 929 | le32_to_cpu(phd->unallocSpaceBitmap.extPosition); | 1133 | le32_to_cpu(phd->unallocSpaceBitmap.extPosition); |
| 930 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP; | 1134 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; |
| 931 | udf_debug("unallocSpaceBitmap (part %d) @ %d\n", | 1135 | udf_debug("unallocSpaceBitmap (part %d) @ %d\n", |
| 932 | i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition); | 1136 | i, bitmap->s_extPosition); |
| 933 | } | 1137 | } |
| 934 | } | 1138 | } |
| 935 | if (phd->partitionIntegrityTable.extLength) | 1139 | if (phd->partitionIntegrityTable.extLength) |
| @@ -940,40 +1144,45 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
| 940 | .partitionReferenceNum = i, | 1144 | .partitionReferenceNum = i, |
| 941 | }; | 1145 | }; |
| 942 | 1146 | ||
| 943 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table = | 1147 | map->s_fspace.s_table = |
| 944 | udf_iget(sb, loc); | 1148 | udf_iget(sb, loc); |
| 945 | if (!UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table) { | 1149 | if (!map->s_fspace.s_table) { |
| 946 | udf_debug("cannot load freedSpaceTable (part %d)\n", i); | 1150 | udf_debug("cannot load freedSpaceTable (part %d)\n", i); |
| 947 | return 1; | 1151 | return 1; |
| 948 | } | 1152 | } |
| 949 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE; | 1153 | map->s_partition_flags |= |
| 1154 | UDF_PART_FLAG_FREED_TABLE; | ||
| 950 | udf_debug("freedSpaceTable (part %d) @ %ld\n", | 1155 | udf_debug("freedSpaceTable (part %d) @ %ld\n", |
| 951 | i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino); | 1156 | i, map->s_fspace.s_table->i_ino); |
| 952 | } | 1157 | } |
| 953 | if (phd->freedSpaceBitmap.extLength) { | 1158 | if (phd->freedSpaceBitmap.extLength) { |
| 954 | UDF_SB_ALLOC_BITMAP(sb, i, s_fspace); | 1159 | struct udf_bitmap *bitmap = |
| 955 | if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) { | 1160 | udf_sb_alloc_bitmap(sb, i); |
| 956 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength = | 1161 | map->s_fspace.s_bitmap = bitmap; |
| 1162 | if (bitmap != NULL) { | ||
| 1163 | bitmap->s_extLength = | ||
| 957 | le32_to_cpu(phd->freedSpaceBitmap.extLength); | 1164 | le32_to_cpu(phd->freedSpaceBitmap.extLength); |
| 958 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition = | 1165 | bitmap->s_extPosition = |
| 959 | le32_to_cpu(phd->freedSpaceBitmap.extPosition); | 1166 | le32_to_cpu(phd->freedSpaceBitmap.extPosition); |
| 960 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP; | 1167 | map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; |
| 961 | udf_debug("freedSpaceBitmap (part %d) @ %d\n", | 1168 | udf_debug("freedSpaceBitmap (part %d) @ %d\n", |
| 962 | i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition); | 1169 | i, bitmap->s_extPosition); |
| 963 | } | 1170 | } |
| 964 | } | 1171 | } |
| 965 | } | 1172 | } |
| 966 | break; | 1173 | break; |
| 967 | } | 1174 | } |
| 968 | } | 1175 | } |
| 969 | if (i == UDF_SB_NUMPARTS(sb)) { | 1176 | if (i == sbi->s_partitions) |
| 970 | udf_debug("Partition (%d) not found in partition map\n", | 1177 | udf_debug("Partition (%d) not found in partition map\n", |
| 971 | le16_to_cpu(p->partitionNumber)); | 1178 | le16_to_cpu(p->partitionNumber)); |
| 972 | } else { | 1179 | else |
| 973 | udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n", | 1180 | udf_debug("Partition (%d:%d type %x) starts at physical %d, " |
| 974 | le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i), | 1181 | "block length %d\n", |
| 975 | UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i)); | 1182 | le16_to_cpu(p->partitionNumber), i, |
| 976 | } | 1183 | map->s_partition_type, |
| 1184 | map->s_partition_root, | ||
| 1185 | map->s_partition_len); | ||
| 977 | return 0; | 1186 | return 0; |
| 978 | } | 1187 | } |
| 979 | 1188 | ||
| @@ -983,70 +1192,105 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh, | |||
| 983 | struct logicalVolDesc *lvd; | 1192 | struct logicalVolDesc *lvd; |
| 984 | int i, j, offset; | 1193 | int i, j, offset; |
| 985 | uint8_t type; | 1194 | uint8_t type; |
| 1195 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 1196 | struct genericPartitionMap *gpm; | ||
| 986 | 1197 | ||
| 987 | lvd = (struct logicalVolDesc *)bh->b_data; | 1198 | lvd = (struct logicalVolDesc *)bh->b_data; |
| 988 | 1199 | ||
| 989 | UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps)); | 1200 | i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps)); |
| 1201 | if (i != 0) | ||
| 1202 | return i; | ||
| 990 | 1203 | ||
| 991 | for (i = 0, offset = 0; | 1204 | for (i = 0, offset = 0; |
| 992 | i < UDF_SB_NUMPARTS(sb) && offset < le32_to_cpu(lvd->mapTableLength); | 1205 | i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); |
| 993 | i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) { | 1206 | i++, offset += gpm->partitionMapLength) { |
| 994 | type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; | 1207 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
| 1208 | gpm = (struct genericPartitionMap *) | ||
| 1209 | &(lvd->partitionMaps[offset]); | ||
| 1210 | type = gpm->partitionMapType; | ||
| 995 | if (type == 1) { | 1211 | if (type == 1) { |
| 996 | struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); | 1212 | struct genericPartitionMap1 *gpm1 = |
| 997 | UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15; | 1213 | (struct genericPartitionMap1 *)gpm; |
| 998 | UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum); | 1214 | map->s_partition_type = UDF_TYPE1_MAP15; |
| 999 | UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum); | 1215 | map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum); |
| 1000 | UDF_SB_PARTFUNC(sb,i) = NULL; | 1216 | map->s_partition_num = le16_to_cpu(gpm1->partitionNum); |
| 1217 | map->s_partition_func = NULL; | ||
| 1001 | } else if (type == 2) { | 1218 | } else if (type == 2) { |
| 1002 | struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); | 1219 | struct udfPartitionMap2 *upm2 = |
| 1003 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) { | 1220 | (struct udfPartitionMap2 *)gpm; |
| 1004 | if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) { | 1221 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, |
| 1005 | UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15; | 1222 | strlen(UDF_ID_VIRTUAL))) { |
| 1006 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15; | 1223 | u16 suf = |
| 1007 | } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) { | 1224 | le16_to_cpu(((__le16 *)upm2->partIdent. |
| 1008 | UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20; | 1225 | identSuffix)[0]); |
| 1009 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20; | 1226 | if (suf == 0x0150) { |
| 1227 | map->s_partition_type = | ||
| 1228 | UDF_VIRTUAL_MAP15; | ||
| 1229 | map->s_partition_func = | ||
| 1230 | udf_get_pblock_virt15; | ||
| 1231 | } else if (suf == 0x0200) { | ||
| 1232 | map->s_partition_type = | ||
| 1233 | UDF_VIRTUAL_MAP20; | ||
| 1234 | map->s_partition_func = | ||
| 1235 | udf_get_pblock_virt20; | ||
| 1010 | } | 1236 | } |
| 1011 | } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) { | 1237 | } else if (!strncmp(upm2->partIdent.ident, |
| 1238 | UDF_ID_SPARABLE, | ||
| 1239 | strlen(UDF_ID_SPARABLE))) { | ||
| 1012 | uint32_t loc; | 1240 | uint32_t loc; |
| 1013 | uint16_t ident; | 1241 | uint16_t ident; |
| 1014 | struct sparingTable *st; | 1242 | struct sparingTable *st; |
| 1015 | struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]); | 1243 | struct sparablePartitionMap *spm = |
| 1244 | (struct sparablePartitionMap *)gpm; | ||
| 1016 | 1245 | ||
| 1017 | UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15; | 1246 | map->s_partition_type = UDF_SPARABLE_MAP15; |
| 1018 | UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength); | 1247 | map->s_type_specific.s_sparing.s_packet_len = |
| 1248 | le16_to_cpu(spm->packetLength); | ||
| 1019 | for (j = 0; j < spm->numSparingTables; j++) { | 1249 | for (j = 0; j < spm->numSparingTables; j++) { |
| 1020 | loc = le32_to_cpu(spm->locSparingTable[j]); | 1250 | struct buffer_head *bh2; |
| 1021 | UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = | 1251 | |
| 1022 | udf_read_tagged(sb, loc, loc, &ident); | 1252 | loc = le32_to_cpu( |
| 1023 | if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) { | 1253 | spm->locSparingTable[j]); |
| 1024 | st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data; | 1254 | bh2 = udf_read_tagged(sb, loc, loc, |
| 1025 | if (ident != 0 || | 1255 | &ident); |
| 1026 | strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) { | 1256 | map->s_type_specific.s_sparing. |
| 1027 | brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]); | 1257 | s_spar_map[j] = bh2; |
| 1028 | UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL; | 1258 | |
| 1259 | if (bh2 != NULL) { | ||
| 1260 | st = (struct sparingTable *) | ||
| 1261 | bh2->b_data; | ||
| 1262 | if (ident != 0 || strncmp( | ||
| 1263 | st->sparingIdent.ident, | ||
| 1264 | UDF_ID_SPARING, | ||
| 1265 | strlen(UDF_ID_SPARING))) { | ||
| 1266 | brelse(bh2); | ||
| 1267 | map->s_type_specific. | ||
| 1268 | s_sparing. | ||
| 1269 | s_spar_map[j] = | ||
| 1270 | NULL; | ||
| 1029 | } | 1271 | } |
| 1030 | } | 1272 | } |
| 1031 | } | 1273 | } |
| 1032 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15; | 1274 | map->s_partition_func = udf_get_pblock_spar15; |
| 1033 | } else { | 1275 | } else { |
| 1034 | udf_debug("Unknown ident: %s\n", upm2->partIdent.ident); | 1276 | udf_debug("Unknown ident: %s\n", |
| 1277 | upm2->partIdent.ident); | ||
| 1035 | continue; | 1278 | continue; |
| 1036 | } | 1279 | } |
| 1037 | UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum); | 1280 | map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum); |
| 1038 | UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum); | 1281 | map->s_partition_num = le16_to_cpu(upm2->partitionNum); |
| 1039 | } | 1282 | } |
| 1040 | udf_debug("Partition (%d:%d) type %d on volume %d\n", | 1283 | udf_debug("Partition (%d:%d) type %d on volume %d\n", |
| 1041 | i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i)); | 1284 | i, map->s_partition_num, type, |
| 1285 | map->s_volumeseqnum); | ||
| 1042 | } | 1286 | } |
| 1043 | 1287 | ||
| 1044 | if (fileset) { | 1288 | if (fileset) { |
| 1045 | long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]); | 1289 | long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]); |
| 1046 | 1290 | ||
| 1047 | *fileset = lelb_to_cpu(la->extLocation); | 1291 | *fileset = lelb_to_cpu(la->extLocation); |
| 1048 | udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n", | 1292 | udf_debug("FileSet found in LogicalVolDesc at block=%d, " |
| 1049 | fileset->logicalBlockNum, | 1293 | "partition=%d\n", fileset->logicalBlockNum, |
| 1050 | fileset->partitionReferenceNum); | 1294 | fileset->partitionReferenceNum); |
| 1051 | } | 1295 | } |
| 1052 | if (lvd->integritySeqExt.extLength) | 1296 | if (lvd->integritySeqExt.extLength) |
| @@ -1063,22 +1307,26 @@ static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc) | |||
| 1063 | { | 1307 | { |
| 1064 | struct buffer_head *bh = NULL; | 1308 | struct buffer_head *bh = NULL; |
| 1065 | uint16_t ident; | 1309 | uint16_t ident; |
| 1310 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 1311 | struct logicalVolIntegrityDesc *lvid; | ||
| 1066 | 1312 | ||
| 1067 | while (loc.extLength > 0 && | 1313 | while (loc.extLength > 0 && |
| 1068 | (bh = udf_read_tagged(sb, loc.extLocation, | 1314 | (bh = udf_read_tagged(sb, loc.extLocation, |
| 1069 | loc.extLocation, &ident)) && | 1315 | loc.extLocation, &ident)) && |
| 1070 | ident == TAG_IDENT_LVID) { | 1316 | ident == TAG_IDENT_LVID) { |
| 1071 | UDF_SB_LVIDBH(sb) = bh; | 1317 | sbi->s_lvid_bh = bh; |
| 1318 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | ||
| 1072 | 1319 | ||
| 1073 | if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength) | 1320 | if (lvid->nextIntegrityExt.extLength) |
| 1074 | udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt)); | 1321 | udf_load_logicalvolint(sb, |
| 1322 | leea_to_cpu(lvid->nextIntegrityExt)); | ||
| 1075 | 1323 | ||
| 1076 | if (UDF_SB_LVIDBH(sb) != bh) | 1324 | if (sbi->s_lvid_bh != bh) |
| 1077 | brelse(bh); | 1325 | brelse(bh); |
| 1078 | loc.extLength -= sb->s_blocksize; | 1326 | loc.extLength -= sb->s_blocksize; |
| 1079 | loc.extLocation++; | 1327 | loc.extLocation++; |
| 1080 | } | 1328 | } |
| 1081 | if (UDF_SB_LVIDBH(sb) != bh) | 1329 | if (sbi->s_lvid_bh != bh) |
| 1082 | brelse(bh); | 1330 | brelse(bh); |
| 1083 | } | 1331 | } |
| 1084 | 1332 | ||
| @@ -1097,11 +1345,12 @@ static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc) | |||
| 1097 | * July 1, 1997 - Andrew E. Mileski | 1345 | * July 1, 1997 - Andrew E. Mileski |
| 1098 | * Written, tested, and released. | 1346 | * Written, tested, and released. |
| 1099 | */ | 1347 | */ |
| 1100 | static int udf_process_sequence(struct super_block *sb, long block, long lastblock, | 1348 | static int udf_process_sequence(struct super_block *sb, long block, |
| 1101 | kernel_lb_addr *fileset) | 1349 | long lastblock, kernel_lb_addr *fileset) |
| 1102 | { | 1350 | { |
| 1103 | struct buffer_head *bh = NULL; | 1351 | struct buffer_head *bh = NULL; |
| 1104 | struct udf_vds_record vds[VDS_POS_LENGTH]; | 1352 | struct udf_vds_record vds[VDS_POS_LENGTH]; |
| 1353 | struct udf_vds_record *curr; | ||
| 1105 | struct generic_desc *gd; | 1354 | struct generic_desc *gd; |
| 1106 | struct volDescPtr *vdp; | 1355 | struct volDescPtr *vdp; |
| 1107 | int done = 0; | 1356 | int done = 0; |
| @@ -1124,43 +1373,51 @@ static int udf_process_sequence(struct super_block *sb, long block, long lastblo | |||
| 1124 | vdsn = le32_to_cpu(gd->volDescSeqNum); | 1373 | vdsn = le32_to_cpu(gd->volDescSeqNum); |
| 1125 | switch (ident) { | 1374 | switch (ident) { |
| 1126 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ | 1375 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ |
| 1127 | if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) { | 1376 | curr = &vds[VDS_POS_PRIMARY_VOL_DESC]; |
| 1128 | vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; | 1377 | if (vdsn >= curr->volDescSeqNum) { |
| 1129 | vds[VDS_POS_PRIMARY_VOL_DESC].block = block; | 1378 | curr->volDescSeqNum = vdsn; |
| 1379 | curr->block = block; | ||
| 1130 | } | 1380 | } |
| 1131 | break; | 1381 | break; |
| 1132 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ | 1382 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ |
| 1133 | if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) { | 1383 | curr = &vds[VDS_POS_VOL_DESC_PTR]; |
| 1134 | vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; | 1384 | if (vdsn >= curr->volDescSeqNum) { |
| 1135 | vds[VDS_POS_VOL_DESC_PTR].block = block; | 1385 | curr->volDescSeqNum = vdsn; |
| 1386 | curr->block = block; | ||
| 1136 | 1387 | ||
| 1137 | vdp = (struct volDescPtr *)bh->b_data; | 1388 | vdp = (struct volDescPtr *)bh->b_data; |
| 1138 | next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); | 1389 | next_s = le32_to_cpu( |
| 1139 | next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); | 1390 | vdp->nextVolDescSeqExt.extLocation); |
| 1391 | next_e = le32_to_cpu( | ||
| 1392 | vdp->nextVolDescSeqExt.extLength); | ||
| 1140 | next_e = next_e >> sb->s_blocksize_bits; | 1393 | next_e = next_e >> sb->s_blocksize_bits; |
| 1141 | next_e += next_s; | 1394 | next_e += next_s; |
| 1142 | } | 1395 | } |
| 1143 | break; | 1396 | break; |
| 1144 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ | 1397 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ |
| 1145 | if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) { | 1398 | curr = &vds[VDS_POS_IMP_USE_VOL_DESC]; |
| 1146 | vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; | 1399 | if (vdsn >= curr->volDescSeqNum) { |
| 1147 | vds[VDS_POS_IMP_USE_VOL_DESC].block = block; | 1400 | curr->volDescSeqNum = vdsn; |
| 1401 | curr->block = block; | ||
| 1148 | } | 1402 | } |
| 1149 | break; | 1403 | break; |
| 1150 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ | 1404 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ |
| 1151 | if (!vds[VDS_POS_PARTITION_DESC].block) | 1405 | curr = &vds[VDS_POS_PARTITION_DESC]; |
| 1152 | vds[VDS_POS_PARTITION_DESC].block = block; | 1406 | if (!curr->block) |
| 1407 | curr->block = block; | ||
| 1153 | break; | 1408 | break; |
| 1154 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ | 1409 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ |
| 1155 | if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) { | 1410 | curr = &vds[VDS_POS_LOGICAL_VOL_DESC]; |
| 1156 | vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; | 1411 | if (vdsn >= curr->volDescSeqNum) { |
| 1157 | vds[VDS_POS_LOGICAL_VOL_DESC].block = block; | 1412 | curr->volDescSeqNum = vdsn; |
| 1413 | curr->block = block; | ||
| 1158 | } | 1414 | } |
| 1159 | break; | 1415 | break; |
| 1160 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ | 1416 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ |
| 1161 | if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) { | 1417 | curr = &vds[VDS_POS_UNALLOC_SPACE_DESC]; |
| 1162 | vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; | 1418 | if (vdsn >= curr->volDescSeqNum) { |
| 1163 | vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; | 1419 | curr->volDescSeqNum = vdsn; |
| 1420 | curr->block = block; | ||
| 1164 | } | 1421 | } |
| 1165 | break; | 1422 | break; |
| 1166 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ | 1423 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ |
| @@ -1169,32 +1426,38 @@ static int udf_process_sequence(struct super_block *sb, long block, long lastblo | |||
| 1169 | block = next_s; | 1426 | block = next_s; |
| 1170 | lastblock = next_e; | 1427 | lastblock = next_e; |
| 1171 | next_s = next_e = 0; | 1428 | next_s = next_e = 0; |
| 1172 | } else { | 1429 | } else |
| 1173 | done = 1; | 1430 | done = 1; |
| 1174 | } | ||
| 1175 | break; | 1431 | break; |
| 1176 | } | 1432 | } |
| 1177 | brelse(bh); | 1433 | brelse(bh); |
| 1178 | } | 1434 | } |
| 1179 | for (i = 0; i < VDS_POS_LENGTH; i++) { | 1435 | for (i = 0; i < VDS_POS_LENGTH; i++) { |
| 1180 | if (vds[i].block) { | 1436 | if (vds[i].block) { |
| 1181 | bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident); | 1437 | bh = udf_read_tagged(sb, vds[i].block, vds[i].block, |
| 1438 | &ident); | ||
| 1182 | 1439 | ||
| 1183 | if (i == VDS_POS_PRIMARY_VOL_DESC) { | 1440 | if (i == VDS_POS_PRIMARY_VOL_DESC) { |
| 1184 | udf_load_pvoldesc(sb, bh); | 1441 | udf_load_pvoldesc(sb, bh); |
| 1185 | } else if (i == VDS_POS_LOGICAL_VOL_DESC) { | 1442 | } else if (i == VDS_POS_LOGICAL_VOL_DESC) { |
| 1186 | udf_load_logicalvol(sb, bh, fileset); | 1443 | if (udf_load_logicalvol(sb, bh, fileset)) { |
| 1444 | brelse(bh); | ||
| 1445 | return 1; | ||
| 1446 | } | ||
| 1187 | } else if (i == VDS_POS_PARTITION_DESC) { | 1447 | } else if (i == VDS_POS_PARTITION_DESC) { |
| 1188 | struct buffer_head *bh2 = NULL; | 1448 | struct buffer_head *bh2 = NULL; |
| 1189 | if (udf_load_partdesc(sb, bh)) { | 1449 | if (udf_load_partdesc(sb, bh)) { |
| 1190 | brelse(bh); | 1450 | brelse(bh); |
| 1191 | return 1; | 1451 | return 1; |
| 1192 | } | 1452 | } |
| 1193 | for (j = vds[i].block + 1; j < vds[VDS_POS_TERMINATING_DESC].block; j++) { | 1453 | for (j = vds[i].block + 1; |
| 1454 | j < vds[VDS_POS_TERMINATING_DESC].block; | ||
| 1455 | j++) { | ||
| 1194 | bh2 = udf_read_tagged(sb, j, j, &ident); | 1456 | bh2 = udf_read_tagged(sb, j, j, &ident); |
| 1195 | gd = (struct generic_desc *)bh2->b_data; | 1457 | gd = (struct generic_desc *)bh2->b_data; |
| 1196 | if (ident == TAG_IDENT_PD) | 1458 | if (ident == TAG_IDENT_PD) |
| 1197 | if (udf_load_partdesc(sb, bh2)) { | 1459 | if (udf_load_partdesc(sb, |
| 1460 | bh2)) { | ||
| 1198 | brelse(bh); | 1461 | brelse(bh); |
| 1199 | brelse(bh2); | 1462 | brelse(bh2); |
| 1200 | return 1; | 1463 | return 1; |
| @@ -1222,14 +1485,17 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent) | |||
| 1222 | } | 1485 | } |
| 1223 | /* Check that it is NSR02 compliant */ | 1486 | /* Check that it is NSR02 compliant */ |
| 1224 | /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ | 1487 | /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ |
| 1225 | else if ((block = udf_vrs(sb, silent)) == -1) { | 1488 | else { |
| 1226 | udf_debug("Failed to read byte 32768. Assuming open disc. " | 1489 | block = udf_vrs(sb, silent); |
| 1227 | "Skipping validity check\n"); | 1490 | if (block == -1) { |
| 1228 | if (!UDF_SB_LASTBLOCK(sb)) | 1491 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1229 | UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); | 1492 | udf_debug("Failed to read byte 32768. Assuming open " |
| 1230 | return 0; | 1493 | "disc. Skipping validity check\n"); |
| 1231 | } else { | 1494 | if (!sbi->s_last_block) |
| 1232 | return !block; | 1495 | sbi->s_last_block = udf_get_last_block(sb); |
| 1496 | return 0; | ||
| 1497 | } else | ||
| 1498 | return !block; | ||
| 1233 | } | 1499 | } |
| 1234 | } | 1500 | } |
| 1235 | 1501 | ||
| @@ -1240,100 +1506,121 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
| 1240 | struct buffer_head *bh; | 1506 | struct buffer_head *bh; |
| 1241 | long main_s, main_e, reserve_s, reserve_e; | 1507 | long main_s, main_e, reserve_s, reserve_e; |
| 1242 | int i, j; | 1508 | int i, j; |
| 1509 | struct udf_sb_info *sbi; | ||
| 1243 | 1510 | ||
| 1244 | if (!sb) | 1511 | if (!sb) |
| 1245 | return 1; | 1512 | return 1; |
| 1513 | sbi = UDF_SB(sb); | ||
| 1246 | 1514 | ||
| 1247 | for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { | 1515 | for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) { |
| 1248 | if (UDF_SB_ANCHOR(sb)[i] && | 1516 | if (!sbi->s_anchor[i]) |
| 1249 | (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i], | 1517 | continue; |
| 1250 | UDF_SB_ANCHOR(sb)[i], &ident))) { | 1518 | bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i], |
| 1251 | anchor = (struct anchorVolDescPtr *)bh->b_data; | 1519 | &ident); |
| 1520 | if (!bh) | ||
| 1521 | continue; | ||
| 1252 | 1522 | ||
| 1253 | /* Locate the main sequence */ | 1523 | anchor = (struct anchorVolDescPtr *)bh->b_data; |
| 1254 | main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); | ||
| 1255 | main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength ); | ||
| 1256 | main_e = main_e >> sb->s_blocksize_bits; | ||
| 1257 | main_e += main_s; | ||
| 1258 | 1524 | ||
| 1259 | /* Locate the reserve sequence */ | 1525 | /* Locate the main sequence */ |
| 1260 | reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); | 1526 | main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); |
| 1261 | reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); | 1527 | main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength); |
| 1262 | reserve_e = reserve_e >> sb->s_blocksize_bits; | 1528 | main_e = main_e >> sb->s_blocksize_bits; |
| 1263 | reserve_e += reserve_s; | 1529 | main_e += main_s; |
| 1264 | 1530 | ||
| 1265 | brelse(bh); | 1531 | /* Locate the reserve sequence */ |
| 1532 | reserve_s = le32_to_cpu( | ||
| 1533 | anchor->reserveVolDescSeqExt.extLocation); | ||
| 1534 | reserve_e = le32_to_cpu( | ||
| 1535 | anchor->reserveVolDescSeqExt.extLength); | ||
| 1536 | reserve_e = reserve_e >> sb->s_blocksize_bits; | ||
| 1537 | reserve_e += reserve_s; | ||
| 1266 | 1538 | ||
| 1267 | /* Process the main & reserve sequences */ | 1539 | brelse(bh); |
| 1268 | /* responsible for finding the PartitionDesc(s) */ | 1540 | |
| 1269 | if (!(udf_process_sequence(sb, main_s, main_e, fileset) && | 1541 | /* Process the main & reserve sequences */ |
| 1270 | udf_process_sequence(sb, reserve_s, reserve_e, fileset))) { | 1542 | /* responsible for finding the PartitionDesc(s) */ |
| 1271 | break; | 1543 | if (!(udf_process_sequence(sb, main_s, main_e, |
| 1272 | } | 1544 | fileset) && |
| 1273 | } | 1545 | udf_process_sequence(sb, reserve_s, reserve_e, |
| 1546 | fileset))) | ||
| 1547 | break; | ||
| 1274 | } | 1548 | } |
| 1275 | 1549 | ||
| 1276 | if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) { | 1550 | if (i == ARRAY_SIZE(sbi->s_anchor)) { |
| 1277 | udf_debug("No Anchor block found\n"); | 1551 | udf_debug("No Anchor block found\n"); |
| 1278 | return 1; | 1552 | return 1; |
| 1279 | } else | 1553 | } |
| 1280 | udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]); | 1554 | udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]); |
| 1281 | 1555 | ||
| 1282 | for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { | 1556 | for (i = 0; i < sbi->s_partitions; i++) { |
| 1283 | kernel_lb_addr uninitialized_var(ino); | 1557 | kernel_lb_addr uninitialized_var(ino); |
| 1284 | switch (UDF_SB_PARTTYPE(sb, i)) { | 1558 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
| 1559 | switch (map->s_partition_type) { | ||
| 1285 | case UDF_VIRTUAL_MAP15: | 1560 | case UDF_VIRTUAL_MAP15: |
| 1286 | case UDF_VIRTUAL_MAP20: | 1561 | case UDF_VIRTUAL_MAP20: |
| 1287 | if (!UDF_SB_LASTBLOCK(sb)) { | 1562 | if (!sbi->s_last_block) { |
| 1288 | UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); | 1563 | sbi->s_last_block = udf_get_last_block(sb); |
| 1289 | udf_find_anchor(sb); | 1564 | udf_find_anchor(sb); |
| 1290 | } | 1565 | } |
| 1291 | 1566 | ||
| 1292 | if (!UDF_SB_LASTBLOCK(sb)) { | 1567 | if (!sbi->s_last_block) { |
| 1293 | udf_debug("Unable to determine Lastblock (For " | 1568 | udf_debug("Unable to determine Lastblock (For " |
| 1294 | "Virtual Partition)\n"); | 1569 | "Virtual Partition)\n"); |
| 1295 | return 1; | 1570 | return 1; |
| 1296 | } | 1571 | } |
| 1297 | 1572 | ||
| 1298 | for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) { | 1573 | for (j = 0; j < sbi->s_partitions; j++) { |
| 1574 | struct udf_part_map *map2 = &sbi->s_partmaps[j]; | ||
| 1299 | if (j != i && | 1575 | if (j != i && |
| 1300 | UDF_SB_PARTVSN(sb, i) == UDF_SB_PARTVSN(sb, j) && | 1576 | map->s_volumeseqnum == |
| 1301 | UDF_SB_PARTNUM(sb, i) == UDF_SB_PARTNUM(sb, j)) { | 1577 | map2->s_volumeseqnum && |
| 1578 | map->s_partition_num == | ||
| 1579 | map2->s_partition_num) { | ||
| 1302 | ino.partitionReferenceNum = j; | 1580 | ino.partitionReferenceNum = j; |
| 1303 | ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) - UDF_SB_PARTROOT(sb, j); | 1581 | ino.logicalBlockNum = |
| 1582 | sbi->s_last_block - | ||
| 1583 | map2->s_partition_root; | ||
| 1304 | break; | 1584 | break; |
| 1305 | } | 1585 | } |
| 1306 | } | 1586 | } |
| 1307 | 1587 | ||
| 1308 | if (j == UDF_SB_NUMPARTS(sb)) | 1588 | if (j == sbi->s_partitions) |
| 1309 | return 1; | 1589 | return 1; |
| 1310 | 1590 | ||
| 1311 | if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino))) | 1591 | sbi->s_vat_inode = udf_iget(sb, ino); |
| 1592 | if (!sbi->s_vat_inode) | ||
| 1312 | return 1; | 1593 | return 1; |
| 1313 | 1594 | ||
| 1314 | if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) { | 1595 | if (map->s_partition_type == UDF_VIRTUAL_MAP15) { |
| 1315 | UDF_SB_TYPEVIRT(sb, i).s_start_offset = | 1596 | map->s_type_specific.s_virtual.s_start_offset = |
| 1316 | udf_ext0_offset(UDF_SB_VAT(sb)); | 1597 | udf_ext0_offset(sbi->s_vat_inode); |
| 1317 | UDF_SB_TYPEVIRT(sb, i).s_num_entries = | 1598 | map->s_type_specific.s_virtual.s_num_entries = |
| 1318 | (UDF_SB_VAT(sb)->i_size - 36) >> 2; | 1599 | (sbi->s_vat_inode->i_size - 36) >> 2; |
| 1319 | } else if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP20) { | 1600 | } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { |
| 1320 | struct buffer_head *bh = NULL; | ||
| 1321 | uint32_t pos; | 1601 | uint32_t pos; |
| 1602 | struct virtualAllocationTable20 *vat20; | ||
| 1322 | 1603 | ||
| 1323 | pos = udf_block_map(UDF_SB_VAT(sb), 0); | 1604 | pos = udf_block_map(sbi->s_vat_inode, 0); |
| 1324 | bh = sb_bread(sb, pos); | 1605 | bh = sb_bread(sb, pos); |
| 1325 | if (!bh) | 1606 | if (!bh) |
| 1326 | return 1; | 1607 | return 1; |
| 1327 | UDF_SB_TYPEVIRT(sb, i).s_start_offset = | 1608 | vat20 = (struct virtualAllocationTable20 *) |
| 1328 | le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + | 1609 | bh->b_data + |
| 1329 | udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) + | 1610 | udf_ext0_offset(sbi->s_vat_inode); |
| 1330 | udf_ext0_offset(UDF_SB_VAT(sb)); | 1611 | map->s_type_specific.s_virtual.s_start_offset = |
| 1331 | UDF_SB_TYPEVIRT(sb, i).s_num_entries = (UDF_SB_VAT(sb)->i_size - | 1612 | le16_to_cpu(vat20->lengthHeader) + |
| 1332 | UDF_SB_TYPEVIRT(sb, i).s_start_offset) >> 2; | 1613 | udf_ext0_offset(sbi->s_vat_inode); |
| 1614 | map->s_type_specific.s_virtual.s_num_entries = | ||
| 1615 | (sbi->s_vat_inode->i_size - | ||
| 1616 | map->s_type_specific.s_virtual. | ||
| 1617 | s_start_offset) >> 2; | ||
| 1333 | brelse(bh); | 1618 | brelse(bh); |
| 1334 | } | 1619 | } |
| 1335 | UDF_SB_PARTROOT(sb, i) = udf_get_pblock(sb, 0, i, 0); | 1620 | map->s_partition_root = udf_get_pblock(sb, 0, i, 0); |
| 1336 | UDF_SB_PARTLEN(sb, i) = UDF_SB_PARTLEN(sb, ino.partitionReferenceNum); | 1621 | map->s_partition_len = |
| 1622 | sbi->s_partmaps[ino.partitionReferenceNum]. | ||
| 1623 | s_partition_len; | ||
| 1337 | } | 1624 | } |
| 1338 | } | 1625 | } |
| 1339 | return 0; | 1626 | return 0; |
| @@ -1341,62 +1628,86 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
| 1341 | 1628 | ||
| 1342 | static void udf_open_lvid(struct super_block *sb) | 1629 | static void udf_open_lvid(struct super_block *sb) |
| 1343 | { | 1630 | { |
| 1344 | if (UDF_SB_LVIDBH(sb)) { | 1631 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1345 | int i; | 1632 | struct buffer_head *bh = sbi->s_lvid_bh; |
| 1633 | if (bh) { | ||
| 1346 | kernel_timestamp cpu_time; | 1634 | kernel_timestamp cpu_time; |
| 1635 | struct logicalVolIntegrityDesc *lvid = | ||
| 1636 | (struct logicalVolIntegrityDesc *)bh->b_data; | ||
| 1637 | struct logicalVolIntegrityDescImpUse *lvidiu = | ||
| 1638 | udf_sb_lvidiu(sbi); | ||
| 1347 | 1639 | ||
| 1348 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1640 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 1349 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1641 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
| 1350 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) | 1642 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) |
| 1351 | UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); | 1643 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); |
| 1352 | UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN; | 1644 | lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; |
| 1353 | |||
| 1354 | UDF_SB_LVID(sb)->descTag.descCRC = cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), | ||
| 1355 | le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); | ||
| 1356 | 1645 | ||
| 1357 | UDF_SB_LVID(sb)->descTag.tagChecksum = 0; | 1646 | lvid->descTag.descCRC = cpu_to_le16( |
| 1358 | for (i = 0; i < 16; i++) | 1647 | udf_crc((char *)lvid + sizeof(tag), |
| 1359 | if (i != 4) | 1648 | le16_to_cpu(lvid->descTag.descCRCLength), |
| 1360 | UDF_SB_LVID(sb)->descTag.tagChecksum += | 1649 | 0)); |
| 1361 | ((uint8_t *) &(UDF_SB_LVID(sb)->descTag))[i]; | ||
| 1362 | 1650 | ||
| 1363 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 1651 | lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag); |
| 1652 | mark_buffer_dirty(bh); | ||
| 1364 | } | 1653 | } |
| 1365 | } | 1654 | } |
| 1366 | 1655 | ||
| 1367 | static void udf_close_lvid(struct super_block *sb) | 1656 | static void udf_close_lvid(struct super_block *sb) |
| 1368 | { | 1657 | { |
| 1369 | kernel_timestamp cpu_time; | 1658 | kernel_timestamp cpu_time; |
| 1370 | int i; | 1659 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1660 | struct buffer_head *bh = sbi->s_lvid_bh; | ||
| 1661 | struct logicalVolIntegrityDesc *lvid; | ||
| 1662 | |||
| 1663 | if (!bh) | ||
| 1664 | return; | ||
| 1665 | |||
| 1666 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | ||
| 1371 | 1667 | ||
| 1372 | if (UDF_SB_LVIDBH(sb) && | 1668 | if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) { |
| 1373 | UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) { | 1669 | struct logicalVolIntegrityDescImpUse *lvidiu = |
| 1374 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1670 | udf_sb_lvidiu(sbi); |
| 1375 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1671 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 1672 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | ||
| 1376 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) | 1673 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) |
| 1377 | UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); | 1674 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); |
| 1378 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev)) | 1675 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) |
| 1379 | UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); | 1676 | lvidiu->maxUDFWriteRev = |
| 1380 | if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev)) | 1677 | cpu_to_le16(UDF_MAX_WRITE_VERSION); |
| 1381 | UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb)); | 1678 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) |
| 1382 | if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev)) | 1679 | lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); |
| 1383 | UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb)); | 1680 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) |
| 1384 | UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); | 1681 | lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); |
| 1385 | 1682 | lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); | |
| 1386 | UDF_SB_LVID(sb)->descTag.descCRC = | 1683 | |
| 1387 | cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), | 1684 | lvid->descTag.descCRC = cpu_to_le16( |
| 1388 | le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); | 1685 | udf_crc((char *)lvid + sizeof(tag), |
| 1389 | 1686 | le16_to_cpu(lvid->descTag.descCRCLength), | |
| 1390 | UDF_SB_LVID(sb)->descTag.tagChecksum = 0; | 1687 | 0)); |
| 1391 | for (i = 0; i < 16; i++) | 1688 | |
| 1392 | if (i != 4) | 1689 | lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag); |
| 1393 | UDF_SB_LVID(sb)->descTag.tagChecksum += | 1690 | mark_buffer_dirty(bh); |
| 1394 | ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; | ||
| 1395 | |||
| 1396 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | ||
| 1397 | } | 1691 | } |
| 1398 | } | 1692 | } |
| 1399 | 1693 | ||
| 1694 | static void udf_sb_free_bitmap(struct udf_bitmap *bitmap) | ||
| 1695 | { | ||
| 1696 | int i; | ||
| 1697 | int nr_groups = bitmap->s_nr_groups; | ||
| 1698 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * | ||
| 1699 | nr_groups); | ||
| 1700 | |||
| 1701 | for (i = 0; i < nr_groups; i++) | ||
| 1702 | if (bitmap->s_block_bitmap[i]) | ||
| 1703 | brelse(bitmap->s_block_bitmap[i]); | ||
| 1704 | |||
| 1705 | if (size <= PAGE_SIZE) | ||
| 1706 | kfree(bitmap); | ||
| 1707 | else | ||
| 1708 | vfree(bitmap); | ||
| 1709 | } | ||
| 1710 | |||
| 1400 | /* | 1711 | /* |
| 1401 | * udf_read_super | 1712 | * udf_read_super |
| 1402 | * | 1713 | * |
| @@ -1426,16 +1737,15 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1426 | uopt.gid = -1; | 1737 | uopt.gid = -1; |
| 1427 | uopt.umask = 0; | 1738 | uopt.umask = 0; |
| 1428 | 1739 | ||
| 1429 | sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL); | 1740 | sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL); |
| 1430 | if (!sbi) | 1741 | if (!sbi) |
| 1431 | return -ENOMEM; | 1742 | return -ENOMEM; |
| 1432 | 1743 | ||
| 1433 | sb->s_fs_info = sbi; | 1744 | sb->s_fs_info = sbi; |
| 1434 | memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info)); | ||
| 1435 | 1745 | ||
| 1436 | mutex_init(&sbi->s_alloc_mutex); | 1746 | mutex_init(&sbi->s_alloc_mutex); |
| 1437 | 1747 | ||
| 1438 | if (!udf_parse_options((char *)options, &uopt)) | 1748 | if (!udf_parse_options((char *)options, &uopt, false)) |
| 1439 | goto error_out; | 1749 | goto error_out; |
| 1440 | 1750 | ||
| 1441 | if (uopt.flags & (1 << UDF_FLAG_UTF8) && | 1751 | if (uopt.flags & (1 << UDF_FLAG_UTF8) && |
| @@ -1459,30 +1769,31 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1459 | fileset.logicalBlockNum = 0xFFFFFFFF; | 1769 | fileset.logicalBlockNum = 0xFFFFFFFF; |
| 1460 | fileset.partitionReferenceNum = 0xFFFF; | 1770 | fileset.partitionReferenceNum = 0xFFFF; |
| 1461 | 1771 | ||
| 1462 | UDF_SB(sb)->s_flags = uopt.flags; | 1772 | sbi->s_flags = uopt.flags; |
| 1463 | UDF_SB(sb)->s_uid = uopt.uid; | 1773 | sbi->s_uid = uopt.uid; |
| 1464 | UDF_SB(sb)->s_gid = uopt.gid; | 1774 | sbi->s_gid = uopt.gid; |
| 1465 | UDF_SB(sb)->s_umask = uopt.umask; | 1775 | sbi->s_umask = uopt.umask; |
| 1466 | UDF_SB(sb)->s_nls_map = uopt.nls_map; | 1776 | sbi->s_nls_map = uopt.nls_map; |
| 1467 | 1777 | ||
| 1468 | /* Set the block size for all transfers */ | 1778 | /* Set the block size for all transfers */ |
| 1469 | if (!udf_set_blocksize(sb, uopt.blocksize)) | 1779 | if (!udf_set_blocksize(sb, uopt.blocksize)) |
| 1470 | goto error_out; | 1780 | goto error_out; |
| 1471 | 1781 | ||
| 1472 | if (uopt.session == 0xFFFFFFFF) | 1782 | if (uopt.session == 0xFFFFFFFF) |
| 1473 | UDF_SB_SESSION(sb) = udf_get_last_session(sb); | 1783 | sbi->s_session = udf_get_last_session(sb); |
| 1474 | else | 1784 | else |
| 1475 | UDF_SB_SESSION(sb) = uopt.session; | 1785 | sbi->s_session = uopt.session; |
| 1476 | 1786 | ||
| 1477 | udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb)); | 1787 | udf_debug("Multi-session=%d\n", sbi->s_session); |
| 1478 | 1788 | ||
| 1479 | UDF_SB_LASTBLOCK(sb) = uopt.lastblock; | 1789 | sbi->s_last_block = uopt.lastblock; |
| 1480 | UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0; | 1790 | sbi->s_anchor[0] = sbi->s_anchor[1] = 0; |
| 1481 | UDF_SB_ANCHOR(sb)[2] = uopt.anchor; | 1791 | sbi->s_anchor[2] = uopt.anchor; |
| 1482 | UDF_SB_ANCHOR(sb)[3] = 256; | 1792 | sbi->s_anchor[3] = 256; |
| 1483 | 1793 | ||
| 1484 | if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */ | 1794 | if (udf_check_valid(sb, uopt.novrs, silent)) { |
| 1485 | printk("UDF-fs: No VRS found\n"); | 1795 | /* read volume recognition sequences */ |
| 1796 | printk(KERN_WARNING "UDF-fs: No VRS found\n"); | ||
| 1486 | goto error_out; | 1797 | goto error_out; |
| 1487 | } | 1798 | } |
| 1488 | 1799 | ||
| @@ -1496,27 +1807,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1496 | sb->s_time_gran = 1000; | 1807 | sb->s_time_gran = 1000; |
| 1497 | 1808 | ||
| 1498 | if (udf_load_partition(sb, &fileset)) { | 1809 | if (udf_load_partition(sb, &fileset)) { |
| 1499 | printk("UDF-fs: No partition found (1)\n"); | 1810 | printk(KERN_WARNING "UDF-fs: No partition found (1)\n"); |
| 1500 | goto error_out; | 1811 | goto error_out; |
| 1501 | } | 1812 | } |
| 1502 | 1813 | ||
| 1503 | udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb)); | 1814 | udf_debug("Lastblock=%d\n", sbi->s_last_block); |
| 1504 | 1815 | ||
| 1505 | if (UDF_SB_LVIDBH(sb)) { | 1816 | if (sbi->s_lvid_bh) { |
| 1506 | uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev); | 1817 | struct logicalVolIntegrityDescImpUse *lvidiu = |
| 1507 | uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); | 1818 | udf_sb_lvidiu(sbi); |
| 1508 | /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */ | 1819 | uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev); |
| 1820 | uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev); | ||
| 1821 | /* uint16_t maxUDFWriteRev = | ||
| 1822 | le16_to_cpu(lvidiu->maxUDFWriteRev); */ | ||
| 1509 | 1823 | ||
| 1510 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { | 1824 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { |
| 1511 | printk("UDF-fs: minUDFReadRev=%x (max is %x)\n", | 1825 | printk(KERN_ERR "UDF-fs: minUDFReadRev=%x " |
| 1512 | le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev), | 1826 | "(max is %x)\n", |
| 1827 | le16_to_cpu(lvidiu->minUDFReadRev), | ||
| 1513 | UDF_MAX_READ_VERSION); | 1828 | UDF_MAX_READ_VERSION); |
| 1514 | goto error_out; | 1829 | goto error_out; |
| 1515 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) { | 1830 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) |
| 1516 | sb->s_flags |= MS_RDONLY; | 1831 | sb->s_flags |= MS_RDONLY; |
| 1517 | } | ||
| 1518 | 1832 | ||
| 1519 | UDF_SB_UDFREV(sb) = minUDFWriteRev; | 1833 | sbi->s_udfrev = minUDFWriteRev; |
| 1520 | 1834 | ||
| 1521 | if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE) | 1835 | if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE) |
| 1522 | UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE); | 1836 | UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE); |
| @@ -1524,29 +1838,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1524 | UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); | 1838 | UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); |
| 1525 | } | 1839 | } |
| 1526 | 1840 | ||
| 1527 | if (!UDF_SB_NUMPARTS(sb)) { | 1841 | if (!sbi->s_partitions) { |
| 1528 | printk("UDF-fs: No partition found (2)\n"); | 1842 | printk(KERN_WARNING "UDF-fs: No partition found (2)\n"); |
| 1529 | goto error_out; | 1843 | goto error_out; |
| 1530 | } | 1844 | } |
| 1531 | 1845 | ||
| 1532 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_READ_ONLY) { | 1846 | if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & |
| 1533 | printk("UDF-fs: Partition marked readonly; forcing readonly mount\n"); | 1847 | UDF_PART_FLAG_READ_ONLY) { |
| 1848 | printk(KERN_NOTICE "UDF-fs: Partition marked readonly; " | ||
| 1849 | "forcing readonly mount\n"); | ||
| 1534 | sb->s_flags |= MS_RDONLY; | 1850 | sb->s_flags |= MS_RDONLY; |
| 1535 | } | 1851 | } |
| 1536 | 1852 | ||
| 1537 | if (udf_find_fileset(sb, &fileset, &rootdir)) { | 1853 | if (udf_find_fileset(sb, &fileset, &rootdir)) { |
| 1538 | printk("UDF-fs: No fileset found\n"); | 1854 | printk(KERN_WARNING "UDF-fs: No fileset found\n"); |
| 1539 | goto error_out; | 1855 | goto error_out; |
| 1540 | } | 1856 | } |
| 1541 | 1857 | ||
| 1542 | if (!silent) { | 1858 | if (!silent) { |
| 1543 | kernel_timestamp ts; | 1859 | kernel_timestamp ts; |
| 1544 | udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb)); | 1860 | udf_time_to_stamp(&ts, sbi->s_record_time); |
| 1545 | udf_info("UDF %s (%s) Mounting volume '%s', " | 1861 | udf_info("UDF: Mounting volume '%s', " |
| 1546 | "timestamp %04u/%02u/%02u %02u:%02u (%x)\n", | 1862 | "timestamp %04u/%02u/%02u %02u:%02u (%x)\n", |
| 1547 | UDFFS_VERSION, UDFFS_DATE, | 1863 | sbi->s_volume_ident, ts.year, ts.month, ts.day, |
| 1548 | UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute, | 1864 | ts.hour, ts.minute, ts.typeAndTimezone); |
| 1549 | ts.typeAndTimezone); | ||
| 1550 | } | 1865 | } |
| 1551 | if (!(sb->s_flags & MS_RDONLY)) | 1866 | if (!(sb->s_flags & MS_RDONLY)) |
| 1552 | udf_open_lvid(sb); | 1867 | udf_open_lvid(sb); |
| @@ -1556,7 +1871,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1556 | /* perhaps it's not extensible enough, but for now ... */ | 1871 | /* perhaps it's not extensible enough, but for now ... */ |
| 1557 | inode = udf_iget(sb, rootdir); | 1872 | inode = udf_iget(sb, rootdir); |
| 1558 | if (!inode) { | 1873 | if (!inode) { |
| 1559 | printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n", | 1874 | printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, " |
| 1875 | "partition=%d\n", | ||
| 1560 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); | 1876 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); |
| 1561 | goto error_out; | 1877 | goto error_out; |
| 1562 | } | 1878 | } |
| @@ -1564,7 +1880,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1564 | /* Allocate a dentry for the root inode */ | 1880 | /* Allocate a dentry for the root inode */ |
| 1565 | sb->s_root = d_alloc_root(inode); | 1881 | sb->s_root = d_alloc_root(inode); |
| 1566 | if (!sb->s_root) { | 1882 | if (!sb->s_root) { |
| 1567 | printk("UDF-fs: Couldn't allocate root dentry\n"); | 1883 | printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n"); |
| 1568 | iput(inode); | 1884 | iput(inode); |
| 1569 | goto error_out; | 1885 | goto error_out; |
| 1570 | } | 1886 | } |
| @@ -1572,30 +1888,32 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
| 1572 | return 0; | 1888 | return 0; |
| 1573 | 1889 | ||
| 1574 | error_out: | 1890 | error_out: |
| 1575 | if (UDF_SB_VAT(sb)) | 1891 | if (sbi->s_vat_inode) |
| 1576 | iput(UDF_SB_VAT(sb)); | 1892 | iput(sbi->s_vat_inode); |
| 1577 | if (UDF_SB_NUMPARTS(sb)) { | 1893 | if (sbi->s_partitions) { |
| 1578 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) | 1894 | struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition]; |
| 1579 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | 1895 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
| 1580 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) | 1896 | iput(map->s_uspace.s_table); |
| 1581 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | 1897 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
| 1582 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) | 1898 | iput(map->s_fspace.s_table); |
| 1583 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace); | 1899 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
| 1584 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) | 1900 | udf_sb_free_bitmap(map->s_uspace.s_bitmap); |
| 1585 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace); | 1901 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
| 1586 | if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) { | 1902 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
| 1903 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | ||
| 1587 | for (i = 0; i < 4; i++) | 1904 | for (i = 0; i < 4; i++) |
| 1588 | brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); | 1905 | brelse(map->s_type_specific.s_sparing. |
| 1589 | } | 1906 | s_spar_map[i]); |
| 1590 | } | 1907 | } |
| 1591 | #ifdef CONFIG_UDF_NLS | 1908 | #ifdef CONFIG_UDF_NLS |
| 1592 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 1909 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
| 1593 | unload_nls(UDF_SB(sb)->s_nls_map); | 1910 | unload_nls(sbi->s_nls_map); |
| 1594 | #endif | 1911 | #endif |
| 1595 | if (!(sb->s_flags & MS_RDONLY)) | 1912 | if (!(sb->s_flags & MS_RDONLY)) |
| 1596 | udf_close_lvid(sb); | 1913 | udf_close_lvid(sb); |
| 1597 | brelse(UDF_SB_LVIDBH(sb)); | 1914 | brelse(sbi->s_lvid_bh); |
| 1598 | UDF_SB_FREE(sb); | 1915 | |
| 1916 | kfree(sbi->s_partmaps); | ||
| 1599 | kfree(sbi); | 1917 | kfree(sbi); |
| 1600 | sb->s_fs_info = NULL; | 1918 | sb->s_fs_info = NULL; |
| 1601 | 1919 | ||
| @@ -1614,7 +1932,7 @@ void udf_error(struct super_block *sb, const char *function, | |||
| 1614 | va_start(args, fmt); | 1932 | va_start(args, fmt); |
| 1615 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); | 1933 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); |
| 1616 | va_end(args); | 1934 | va_end(args); |
| 1617 | printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n", | 1935 | printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n", |
| 1618 | sb->s_id, function, error_buf); | 1936 | sb->s_id, function, error_buf); |
| 1619 | } | 1937 | } |
| 1620 | 1938 | ||
| @@ -1646,31 +1964,34 @@ void udf_warning(struct super_block *sb, const char *function, | |||
| 1646 | static void udf_put_super(struct super_block *sb) | 1964 | static void udf_put_super(struct super_block *sb) |
| 1647 | { | 1965 | { |
| 1648 | int i; | 1966 | int i; |
| 1967 | struct udf_sb_info *sbi; | ||
| 1649 | 1968 | ||
| 1650 | if (UDF_SB_VAT(sb)) | 1969 | sbi = UDF_SB(sb); |
| 1651 | iput(UDF_SB_VAT(sb)); | 1970 | if (sbi->s_vat_inode) |
| 1652 | if (UDF_SB_NUMPARTS(sb)) { | 1971 | iput(sbi->s_vat_inode); |
| 1653 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) | 1972 | if (sbi->s_partitions) { |
| 1654 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | 1973 | struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition]; |
| 1655 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) | 1974 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
| 1656 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | 1975 | iput(map->s_uspace.s_table); |
| 1657 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) | 1976 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
| 1658 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace); | 1977 | iput(map->s_fspace.s_table); |
| 1659 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) | 1978 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
| 1660 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace); | 1979 | udf_sb_free_bitmap(map->s_uspace.s_bitmap); |
| 1661 | if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) { | 1980 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
| 1981 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); | ||
| 1982 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | ||
| 1662 | for (i = 0; i < 4; i++) | 1983 | for (i = 0; i < 4; i++) |
| 1663 | brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); | 1984 | brelse(map->s_type_specific.s_sparing. |
| 1664 | } | 1985 | s_spar_map[i]); |
| 1665 | } | 1986 | } |
| 1666 | #ifdef CONFIG_UDF_NLS | 1987 | #ifdef CONFIG_UDF_NLS |
| 1667 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 1988 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
| 1668 | unload_nls(UDF_SB(sb)->s_nls_map); | 1989 | unload_nls(sbi->s_nls_map); |
| 1669 | #endif | 1990 | #endif |
| 1670 | if (!(sb->s_flags & MS_RDONLY)) | 1991 | if (!(sb->s_flags & MS_RDONLY)) |
| 1671 | udf_close_lvid(sb); | 1992 | udf_close_lvid(sb); |
| 1672 | brelse(UDF_SB_LVIDBH(sb)); | 1993 | brelse(sbi->s_lvid_bh); |
| 1673 | UDF_SB_FREE(sb); | 1994 | kfree(sbi->s_partmaps); |
| 1674 | kfree(sb->s_fs_info); | 1995 | kfree(sb->s_fs_info); |
| 1675 | sb->s_fs_info = NULL; | 1996 | sb->s_fs_info = NULL; |
| 1676 | } | 1997 | } |
| @@ -1691,15 +2012,22 @@ static void udf_put_super(struct super_block *sb) | |||
| 1691 | static int udf_statfs(struct dentry *dentry, struct kstatfs *buf) | 2012 | static int udf_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 1692 | { | 2013 | { |
| 1693 | struct super_block *sb = dentry->d_sb; | 2014 | struct super_block *sb = dentry->d_sb; |
| 2015 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 2016 | struct logicalVolIntegrityDescImpUse *lvidiu; | ||
| 2017 | |||
| 2018 | if (sbi->s_lvid_bh != NULL) | ||
| 2019 | lvidiu = udf_sb_lvidiu(sbi); | ||
| 2020 | else | ||
| 2021 | lvidiu = NULL; | ||
| 1694 | 2022 | ||
| 1695 | buf->f_type = UDF_SUPER_MAGIC; | 2023 | buf->f_type = UDF_SUPER_MAGIC; |
| 1696 | buf->f_bsize = sb->s_blocksize; | 2024 | buf->f_bsize = sb->s_blocksize; |
| 1697 | buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb)); | 2025 | buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len; |
| 1698 | buf->f_bfree = udf_count_free(sb); | 2026 | buf->f_bfree = udf_count_free(sb); |
| 1699 | buf->f_bavail = buf->f_bfree; | 2027 | buf->f_bavail = buf->f_bfree; |
| 1700 | buf->f_files = (UDF_SB_LVIDBH(sb) ? | 2028 | buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) + |
| 1701 | (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + | 2029 | le32_to_cpu(lvidiu->numDirs)) : 0) |
| 1702 | le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree; | 2030 | + buf->f_bfree; |
| 1703 | buf->f_ffree = buf->f_bfree; | 2031 | buf->f_ffree = buf->f_bfree; |
| 1704 | /* __kernel_fsid_t f_fsid */ | 2032 | /* __kernel_fsid_t f_fsid */ |
| 1705 | buf->f_namelen = UDF_NAME_LEN - 2; | 2033 | buf->f_namelen = UDF_NAME_LEN - 2; |
| @@ -1711,7 +2039,8 @@ static unsigned char udf_bitmap_lookup[16] = { | |||
| 1711 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 | 2039 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 |
| 1712 | }; | 2040 | }; |
| 1713 | 2041 | ||
| 1714 | static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) | 2042 | static unsigned int udf_count_free_bitmap(struct super_block *sb, |
| 2043 | struct udf_bitmap *bitmap) | ||
| 1715 | { | 2044 | { |
| 1716 | struct buffer_head *bh = NULL; | 2045 | struct buffer_head *bh = NULL; |
| 1717 | unsigned int accum = 0; | 2046 | unsigned int accum = 0; |
| @@ -1727,7 +2056,7 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bit | |||
| 1727 | lock_kernel(); | 2056 | lock_kernel(); |
| 1728 | 2057 | ||
| 1729 | loc.logicalBlockNum = bitmap->s_extPosition; | 2058 | loc.logicalBlockNum = bitmap->s_extPosition; |
| 1730 | loc.partitionReferenceNum = UDF_SB_PARTITION(sb); | 2059 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; |
| 1731 | bh = udf_read_ptagged(sb, loc, 0, &ident); | 2060 | bh = udf_read_ptagged(sb, loc, 0, &ident); |
| 1732 | 2061 | ||
| 1733 | if (!bh) { | 2062 | if (!bh) { |
| @@ -1772,7 +2101,8 @@ out: | |||
| 1772 | return accum; | 2101 | return accum; |
| 1773 | } | 2102 | } |
| 1774 | 2103 | ||
| 1775 | static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table) | 2104 | static unsigned int udf_count_free_table(struct super_block *sb, |
| 2105 | struct inode *table) | ||
| 1776 | { | 2106 | { |
| 1777 | unsigned int accum = 0; | 2107 | unsigned int accum = 0; |
| 1778 | uint32_t elen; | 2108 | uint32_t elen; |
| @@ -1782,13 +2112,13 @@ static unsigned int udf_count_free_table(struct super_block *sb, struct inode *t | |||
| 1782 | 2112 | ||
| 1783 | lock_kernel(); | 2113 | lock_kernel(); |
| 1784 | 2114 | ||
| 1785 | epos.block = UDF_I_LOCATION(table); | 2115 | epos.block = UDF_I(table)->i_location; |
| 1786 | epos.offset = sizeof(struct unallocSpaceEntry); | 2116 | epos.offset = sizeof(struct unallocSpaceEntry); |
| 1787 | epos.bh = NULL; | 2117 | epos.bh = NULL; |
| 1788 | 2118 | ||
| 1789 | while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { | 2119 | while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) |
| 1790 | accum += (elen >> table->i_sb->s_blocksize_bits); | 2120 | accum += (elen >> table->i_sb->s_blocksize_bits); |
| 1791 | } | 2121 | |
| 1792 | brelse(epos.bh); | 2122 | brelse(epos.bh); |
| 1793 | 2123 | ||
| 1794 | unlock_kernel(); | 2124 | unlock_kernel(); |
| @@ -1799,10 +2129,17 @@ static unsigned int udf_count_free_table(struct super_block *sb, struct inode *t | |||
| 1799 | static unsigned int udf_count_free(struct super_block *sb) | 2129 | static unsigned int udf_count_free(struct super_block *sb) |
| 1800 | { | 2130 | { |
| 1801 | unsigned int accum = 0; | 2131 | unsigned int accum = 0; |
| 1802 | 2132 | struct udf_sb_info *sbi; | |
| 1803 | if (UDF_SB_LVIDBH(sb)) { | 2133 | struct udf_part_map *map; |
| 1804 | if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) { | 2134 | |
| 1805 | accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]); | 2135 | sbi = UDF_SB(sb); |
| 2136 | if (sbi->s_lvid_bh) { | ||
| 2137 | struct logicalVolIntegrityDesc *lvid = | ||
| 2138 | (struct logicalVolIntegrityDesc *) | ||
| 2139 | sbi->s_lvid_bh->b_data; | ||
| 2140 | if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { | ||
| 2141 | accum = le32_to_cpu( | ||
| 2142 | lvid->freeSpaceTable[sbi->s_partition]); | ||
| 1806 | if (accum == 0xFFFFFFFF) | 2143 | if (accum == 0xFFFFFFFF) |
| 1807 | accum = 0; | 2144 | accum = 0; |
| 1808 | } | 2145 | } |
| @@ -1811,24 +2148,25 @@ static unsigned int udf_count_free(struct super_block *sb) | |||
| 1811 | if (accum) | 2148 | if (accum) |
| 1812 | return accum; | 2149 | return accum; |
| 1813 | 2150 | ||
| 1814 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) { | 2151 | map = &sbi->s_partmaps[sbi->s_partition]; |
| 2152 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { | ||
| 1815 | accum += udf_count_free_bitmap(sb, | 2153 | accum += udf_count_free_bitmap(sb, |
| 1816 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap); | 2154 | map->s_uspace.s_bitmap); |
| 1817 | } | 2155 | } |
| 1818 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) { | 2156 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { |
| 1819 | accum += udf_count_free_bitmap(sb, | 2157 | accum += udf_count_free_bitmap(sb, |
| 1820 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap); | 2158 | map->s_fspace.s_bitmap); |
| 1821 | } | 2159 | } |
| 1822 | if (accum) | 2160 | if (accum) |
| 1823 | return accum; | 2161 | return accum; |
| 1824 | 2162 | ||
| 1825 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) { | 2163 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { |
| 1826 | accum += udf_count_free_table(sb, | 2164 | accum += udf_count_free_table(sb, |
| 1827 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | 2165 | map->s_uspace.s_table); |
| 1828 | } | 2166 | } |
| 1829 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) { | 2167 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { |
| 1830 | accum += udf_count_free_table(sb, | 2168 | accum += udf_count_free_table(sb, |
| 1831 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | 2169 | map->s_fspace.s_table); |
| 1832 | } | 2170 | } |
| 1833 | 2171 | ||
| 1834 | return accum; | 2172 | return accum; |
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c index e6f933dd6a7b..6ec99221e50c 100644 --- a/fs/udf/symlink.c +++ b/fs/udf/symlink.c | |||
| @@ -33,7 +33,8 @@ | |||
| 33 | #include <linux/buffer_head.h> | 33 | #include <linux/buffer_head.h> |
| 34 | #include "udf_i.h" | 34 | #include "udf_i.h" |
| 35 | 35 | ||
| 36 | static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to) | 36 | static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, |
| 37 | char *to) | ||
| 37 | { | 38 | { |
| 38 | struct pathComponent *pc; | 39 | struct pathComponent *pc; |
| 39 | int elen = 0; | 40 | int elen = 0; |
| @@ -78,10 +79,12 @@ static int udf_symlink_filler(struct file *file, struct page *page) | |||
| 78 | char *symlink; | 79 | char *symlink; |
| 79 | int err = -EIO; | 80 | int err = -EIO; |
| 80 | char *p = kmap(page); | 81 | char *p = kmap(page); |
| 82 | struct udf_inode_info *iinfo; | ||
| 81 | 83 | ||
| 82 | lock_kernel(); | 84 | lock_kernel(); |
| 83 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 85 | iinfo = UDF_I(inode); |
| 84 | symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); | 86 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 87 | symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr; | ||
| 85 | } else { | 88 | } else { |
| 86 | bh = sb_bread(inode->i_sb, udf_block_map(inode, 0)); | 89 | bh = sb_bread(inode->i_sb, udf_block_map(inode, 0)); |
| 87 | 90 | ||
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index 7fc3912885a5..fe61be17cdab 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c | |||
| @@ -74,17 +74,18 @@ void udf_truncate_tail_extent(struct inode *inode) | |||
| 74 | uint64_t lbcount = 0; | 74 | uint64_t lbcount = 0; |
| 75 | int8_t etype = -1, netype; | 75 | int8_t etype = -1, netype; |
| 76 | int adsize; | 76 | int adsize; |
| 77 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 77 | 78 | ||
| 78 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || | 79 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB || |
| 79 | inode->i_size == UDF_I_LENEXTENTS(inode)) | 80 | inode->i_size == iinfo->i_lenExtents) |
| 80 | return; | 81 | return; |
| 81 | /* Are we going to delete the file anyway? */ | 82 | /* Are we going to delete the file anyway? */ |
| 82 | if (inode->i_nlink == 0) | 83 | if (inode->i_nlink == 0) |
| 83 | return; | 84 | return; |
| 84 | 85 | ||
| 85 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 86 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 86 | adsize = sizeof(short_ad); | 87 | adsize = sizeof(short_ad); |
| 87 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 88 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 88 | adsize = sizeof(long_ad); | 89 | adsize = sizeof(long_ad); |
| 89 | else | 90 | else |
| 90 | BUG(); | 91 | BUG(); |
| @@ -117,7 +118,7 @@ void udf_truncate_tail_extent(struct inode *inode) | |||
| 117 | } | 118 | } |
| 118 | /* This inode entry is in-memory only and thus we don't have to mark | 119 | /* This inode entry is in-memory only and thus we don't have to mark |
| 119 | * the inode dirty */ | 120 | * the inode dirty */ |
| 120 | UDF_I_LENEXTENTS(inode) = inode->i_size; | 121 | iinfo->i_lenExtents = inode->i_size; |
| 121 | brelse(epos.bh); | 122 | brelse(epos.bh); |
| 122 | } | 123 | } |
| 123 | 124 | ||
| @@ -129,19 +130,20 @@ void udf_discard_prealloc(struct inode *inode) | |||
| 129 | uint64_t lbcount = 0; | 130 | uint64_t lbcount = 0; |
| 130 | int8_t etype = -1, netype; | 131 | int8_t etype = -1, netype; |
| 131 | int adsize; | 132 | int adsize; |
| 133 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 132 | 134 | ||
| 133 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || | 135 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB || |
| 134 | inode->i_size == UDF_I_LENEXTENTS(inode)) | 136 | inode->i_size == iinfo->i_lenExtents) |
| 135 | return; | 137 | return; |
| 136 | 138 | ||
| 137 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 139 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 138 | adsize = sizeof(short_ad); | 140 | adsize = sizeof(short_ad); |
| 139 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 141 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 140 | adsize = sizeof(long_ad); | 142 | adsize = sizeof(long_ad); |
| 141 | else | 143 | else |
| 142 | adsize = 0; | 144 | adsize = 0; |
| 143 | 145 | ||
| 144 | epos.block = UDF_I_LOCATION(inode); | 146 | epos.block = iinfo->i_location; |
| 145 | 147 | ||
| 146 | /* Find the last extent in the file */ | 148 | /* Find the last extent in the file */ |
| 147 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { | 149 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { |
| @@ -153,8 +155,9 @@ void udf_discard_prealloc(struct inode *inode) | |||
| 153 | lbcount -= elen; | 155 | lbcount -= elen; |
| 154 | extent_trunc(inode, &epos, eloc, etype, elen, 0); | 156 | extent_trunc(inode, &epos, eloc, etype, elen, 0); |
| 155 | if (!epos.bh) { | 157 | if (!epos.bh) { |
| 156 | UDF_I_LENALLOC(inode) = | 158 | iinfo->i_lenAlloc = |
| 157 | epos.offset - udf_file_entry_alloc_offset(inode); | 159 | epos.offset - |
| 160 | udf_file_entry_alloc_offset(inode); | ||
| 158 | mark_inode_dirty(inode); | 161 | mark_inode_dirty(inode); |
| 159 | } else { | 162 | } else { |
| 160 | struct allocExtDesc *aed = | 163 | struct allocExtDesc *aed = |
| @@ -163,7 +166,7 @@ void udf_discard_prealloc(struct inode *inode) | |||
| 163 | cpu_to_le32(epos.offset - | 166 | cpu_to_le32(epos.offset - |
| 164 | sizeof(struct allocExtDesc)); | 167 | sizeof(struct allocExtDesc)); |
| 165 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 168 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
| 166 | UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 169 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
| 167 | udf_update_tag(epos.bh->b_data, epos.offset); | 170 | udf_update_tag(epos.bh->b_data, epos.offset); |
| 168 | else | 171 | else |
| 169 | udf_update_tag(epos.bh->b_data, | 172 | udf_update_tag(epos.bh->b_data, |
| @@ -173,7 +176,7 @@ void udf_discard_prealloc(struct inode *inode) | |||
| 173 | } | 176 | } |
| 174 | /* This inode entry is in-memory only and thus we don't have to mark | 177 | /* This inode entry is in-memory only and thus we don't have to mark |
| 175 | * the inode dirty */ | 178 | * the inode dirty */ |
| 176 | UDF_I_LENEXTENTS(inode) = lbcount; | 179 | iinfo->i_lenExtents = lbcount; |
| 177 | brelse(epos.bh); | 180 | brelse(epos.bh); |
| 178 | } | 181 | } |
| 179 | 182 | ||
| @@ -184,13 +187,15 @@ void udf_truncate_extents(struct inode *inode) | |||
| 184 | uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; | 187 | uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; |
| 185 | int8_t etype; | 188 | int8_t etype; |
| 186 | struct super_block *sb = inode->i_sb; | 189 | struct super_block *sb = inode->i_sb; |
| 190 | struct udf_sb_info *sbi = UDF_SB(sb); | ||
| 187 | sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset; | 191 | sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset; |
| 188 | loff_t byte_offset; | 192 | loff_t byte_offset; |
| 189 | int adsize; | 193 | int adsize; |
| 194 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
| 190 | 195 | ||
| 191 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 196 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 192 | adsize = sizeof(short_ad); | 197 | adsize = sizeof(short_ad); |
| 193 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | 198 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 194 | adsize = sizeof(long_ad); | 199 | adsize = sizeof(long_ad); |
| 195 | else | 200 | else |
| 196 | BUG(); | 201 | BUG(); |
| @@ -212,7 +217,8 @@ void udf_truncate_extents(struct inode *inode) | |||
| 212 | else | 217 | else |
| 213 | lenalloc -= sizeof(struct allocExtDesc); | 218 | lenalloc -= sizeof(struct allocExtDesc); |
| 214 | 219 | ||
| 215 | while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) { | 220 | while ((etype = udf_current_aext(inode, &epos, &eloc, |
| 221 | &elen, 0)) != -1) { | ||
| 216 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { | 222 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
| 217 | udf_write_aext(inode, &epos, neloc, nelen, 0); | 223 | udf_write_aext(inode, &epos, neloc, nelen, 0); |
| 218 | if (indirect_ext_len) { | 224 | if (indirect_ext_len) { |
| @@ -224,35 +230,43 @@ void udf_truncate_extents(struct inode *inode) | |||
| 224 | 0, indirect_ext_len); | 230 | 0, indirect_ext_len); |
| 225 | } else { | 231 | } else { |
| 226 | if (!epos.bh) { | 232 | if (!epos.bh) { |
| 227 | UDF_I_LENALLOC(inode) = lenalloc; | 233 | iinfo->i_lenAlloc = |
| 234 | lenalloc; | ||
| 228 | mark_inode_dirty(inode); | 235 | mark_inode_dirty(inode); |
| 229 | } else { | 236 | } else { |
| 230 | struct allocExtDesc *aed = | 237 | struct allocExtDesc *aed = |
| 231 | (struct allocExtDesc *)(epos.bh->b_data); | 238 | (struct allocExtDesc *) |
| 239 | (epos.bh->b_data); | ||
| 240 | int len = | ||
| 241 | sizeof(struct allocExtDesc); | ||
| 242 | |||
| 232 | aed->lengthAllocDescs = | 243 | aed->lengthAllocDescs = |
| 233 | cpu_to_le32(lenalloc); | 244 | cpu_to_le32(lenalloc); |
| 234 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || | 245 | if (!UDF_QUERY_FLAG(sb, |
| 235 | UDF_SB_UDFREV(sb) >= 0x0201) | 246 | UDF_FLAG_STRICT) || |
| 236 | udf_update_tag(epos.bh->b_data, | 247 | sbi->s_udfrev >= 0x0201) |
| 237 | lenalloc + | 248 | len += lenalloc; |
| 238 | sizeof(struct allocExtDesc)); | 249 | |
| 239 | else | 250 | udf_update_tag(epos.bh->b_data, |
| 240 | udf_update_tag(epos.bh->b_data, | 251 | len); |
| 241 | sizeof(struct allocExtDesc)); | 252 | mark_buffer_dirty_inode( |
| 242 | mark_buffer_dirty_inode(epos.bh, inode); | 253 | epos.bh, inode); |
| 243 | } | 254 | } |
| 244 | } | 255 | } |
| 245 | brelse(epos.bh); | 256 | brelse(epos.bh); |
| 246 | epos.offset = sizeof(struct allocExtDesc); | 257 | epos.offset = sizeof(struct allocExtDesc); |
| 247 | epos.block = eloc; | 258 | epos.block = eloc; |
| 248 | epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); | 259 | epos.bh = udf_tread(sb, |
| 260 | udf_get_lb_pblock(sb, eloc, 0)); | ||
| 249 | if (elen) | 261 | if (elen) |
| 250 | indirect_ext_len = (elen + sb->s_blocksize -1) >> | 262 | indirect_ext_len = |
| 263 | (elen + sb->s_blocksize - 1) >> | ||
| 251 | sb->s_blocksize_bits; | 264 | sb->s_blocksize_bits; |
| 252 | else | 265 | else |
| 253 | indirect_ext_len = 1; | 266 | indirect_ext_len = 1; |
| 254 | } else { | 267 | } else { |
| 255 | extent_trunc(inode, &epos, eloc, etype, elen, 0); | 268 | extent_trunc(inode, &epos, eloc, etype, |
| 269 | elen, 0); | ||
| 256 | epos.offset += adsize; | 270 | epos.offset += adsize; |
| 257 | } | 271 | } |
| 258 | } | 272 | } |
| @@ -264,19 +278,20 @@ void udf_truncate_extents(struct inode *inode) | |||
| 264 | indirect_ext_len); | 278 | indirect_ext_len); |
| 265 | } else { | 279 | } else { |
| 266 | if (!epos.bh) { | 280 | if (!epos.bh) { |
| 267 | UDF_I_LENALLOC(inode) = lenalloc; | 281 | iinfo->i_lenAlloc = lenalloc; |
| 268 | mark_inode_dirty(inode); | 282 | mark_inode_dirty(inode); |
| 269 | } else { | 283 | } else { |
| 270 | struct allocExtDesc *aed = | 284 | struct allocExtDesc *aed = |
| 271 | (struct allocExtDesc *)(epos.bh->b_data); | 285 | (struct allocExtDesc *)(epos.bh->b_data); |
| 272 | aed->lengthAllocDescs = cpu_to_le32(lenalloc); | 286 | aed->lengthAllocDescs = cpu_to_le32(lenalloc); |
| 273 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || | 287 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || |
| 274 | UDF_SB_UDFREV(sb) >= 0x0201) | 288 | sbi->s_udfrev >= 0x0201) |
| 275 | udf_update_tag(epos.bh->b_data, | 289 | udf_update_tag(epos.bh->b_data, |
| 276 | lenalloc + sizeof(struct allocExtDesc)); | 290 | lenalloc + |
| 291 | sizeof(struct allocExtDesc)); | ||
| 277 | else | 292 | else |
| 278 | udf_update_tag(epos.bh->b_data, | 293 | udf_update_tag(epos.bh->b_data, |
| 279 | sizeof(struct allocExtDesc)); | 294 | sizeof(struct allocExtDesc)); |
| 280 | mark_buffer_dirty_inode(epos.bh, inode); | 295 | mark_buffer_dirty_inode(epos.bh, inode); |
| 281 | } | 296 | } |
| 282 | } | 297 | } |
| @@ -290,13 +305,16 @@ void udf_truncate_extents(struct inode *inode) | |||
| 290 | * extending the file by 'offset' blocks. | 305 | * extending the file by 'offset' blocks. |
| 291 | */ | 306 | */ |
| 292 | if ((!epos.bh && | 307 | if ((!epos.bh && |
| 293 | epos.offset == udf_file_entry_alloc_offset(inode)) || | 308 | epos.offset == |
| 294 | (epos.bh && epos.offset == sizeof(struct allocExtDesc))) { | 309 | udf_file_entry_alloc_offset(inode)) || |
| 310 | (epos.bh && epos.offset == | ||
| 311 | sizeof(struct allocExtDesc))) { | ||
| 295 | /* File has no extents at all or has empty last | 312 | /* File has no extents at all or has empty last |
| 296 | * indirect extent! Create a fake extent... */ | 313 | * indirect extent! Create a fake extent... */ |
| 297 | extent.extLocation.logicalBlockNum = 0; | 314 | extent.extLocation.logicalBlockNum = 0; |
| 298 | extent.extLocation.partitionReferenceNum = 0; | 315 | extent.extLocation.partitionReferenceNum = 0; |
| 299 | extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; | 316 | extent.extLength = |
| 317 | EXT_NOT_RECORDED_NOT_ALLOCATED; | ||
| 300 | } else { | 318 | } else { |
| 301 | epos.offset -= adsize; | 319 | epos.offset -= adsize; |
| 302 | etype = udf_next_aext(inode, &epos, | 320 | etype = udf_next_aext(inode, &epos, |
| @@ -305,10 +323,12 @@ void udf_truncate_extents(struct inode *inode) | |||
| 305 | extent.extLength |= etype << 30; | 323 | extent.extLength |= etype << 30; |
| 306 | } | 324 | } |
| 307 | udf_extend_file(inode, &epos, &extent, | 325 | udf_extend_file(inode, &epos, &extent, |
| 308 | offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0)); | 326 | offset + |
| 327 | ((inode->i_size & | ||
| 328 | (sb->s_blocksize - 1)) != 0)); | ||
| 309 | } | 329 | } |
| 310 | } | 330 | } |
| 311 | UDF_I_LENEXTENTS(inode) = inode->i_size; | 331 | iinfo->i_lenExtents = inode->i_size; |
| 312 | 332 | ||
| 313 | brelse(epos.bh); | 333 | brelse(epos.bh); |
| 314 | } | 334 | } |
diff --git a/fs/udf/udf_i.h b/fs/udf/udf_i.h index d7dbe6f3ba0c..ccc52f16bf7d 100644 --- a/fs/udf/udf_i.h +++ b/fs/udf/udf_i.h | |||
| @@ -7,20 +7,4 @@ static inline struct udf_inode_info *UDF_I(struct inode *inode) | |||
| 7 | return list_entry(inode, struct udf_inode_info, vfs_inode); | 7 | return list_entry(inode, struct udf_inode_info, vfs_inode); |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | #define UDF_I_LOCATION(X) ( UDF_I(X)->i_location ) | ||
| 11 | #define UDF_I_LENEATTR(X) ( UDF_I(X)->i_lenEAttr ) | ||
| 12 | #define UDF_I_LENALLOC(X) ( UDF_I(X)->i_lenAlloc ) | ||
| 13 | #define UDF_I_LENEXTENTS(X) ( UDF_I(X)->i_lenExtents ) | ||
| 14 | #define UDF_I_UNIQUE(X) ( UDF_I(X)->i_unique ) | ||
| 15 | #define UDF_I_ALLOCTYPE(X) ( UDF_I(X)->i_alloc_type ) | ||
| 16 | #define UDF_I_EFE(X) ( UDF_I(X)->i_efe ) | ||
| 17 | #define UDF_I_USE(X) ( UDF_I(X)->i_use ) | ||
| 18 | #define UDF_I_STRAT4096(X) ( UDF_I(X)->i_strat4096 ) | ||
| 19 | #define UDF_I_NEXT_ALLOC_BLOCK(X) ( UDF_I(X)->i_next_alloc_block ) | ||
| 20 | #define UDF_I_NEXT_ALLOC_GOAL(X) ( UDF_I(X)->i_next_alloc_goal ) | ||
| 21 | #define UDF_I_CRTIME(X) ( UDF_I(X)->i_crtime ) | ||
| 22 | #define UDF_I_SAD(X) ( UDF_I(X)->i_ext.i_sad ) | ||
| 23 | #define UDF_I_LAD(X) ( UDF_I(X)->i_ext.i_lad ) | ||
| 24 | #define UDF_I_DATA(X) ( UDF_I(X)->i_ext.i_data ) | ||
| 25 | |||
| 26 | #endif /* !defined(_LINUX_UDF_I_H) */ | 10 | #endif /* !defined(_LINUX_UDF_I_H) */ |
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h index 3c2982017c6d..737d1c604eea 100644 --- a/fs/udf/udf_sb.h +++ b/fs/udf/udf_sb.h | |||
| @@ -26,6 +26,8 @@ | |||
| 26 | #define UDF_FLAG_GID_IGNORE 14 | 26 | #define UDF_FLAG_GID_IGNORE 14 |
| 27 | #define UDF_FLAG_UID_SET 15 | 27 | #define UDF_FLAG_UID_SET 15 |
| 28 | #define UDF_FLAG_GID_SET 16 | 28 | #define UDF_FLAG_GID_SET 16 |
| 29 | #define UDF_FLAG_SESSION_SET 17 | ||
| 30 | #define UDF_FLAG_LASTBLOCK_SET 18 | ||
| 29 | 31 | ||
| 30 | #define UDF_PART_FLAG_UNALLOC_BITMAP 0x0001 | 32 | #define UDF_PART_FLAG_UNALLOC_BITMAP 0x0001 |
| 31 | #define UDF_PART_FLAG_UNALLOC_TABLE 0x0002 | 33 | #define UDF_PART_FLAG_UNALLOC_TABLE 0x0002 |
| @@ -41,96 +43,12 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb) | |||
| 41 | return sb->s_fs_info; | 43 | return sb->s_fs_info; |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | #define UDF_SB_FREE(X)\ | 46 | struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi); |
| 45 | {\ | ||
| 46 | if (UDF_SB(X)) {\ | ||
| 47 | kfree(UDF_SB_PARTMAPS(X));\ | ||
| 48 | UDF_SB_PARTMAPS(X) = NULL;\ | ||
| 49 | }\ | ||
| 50 | } | ||
| 51 | |||
| 52 | #define UDF_SB_ALLOC_PARTMAPS(X,Y)\ | ||
| 53 | {\ | ||
| 54 | UDF_SB_PARTMAPS(X) = kmalloc(sizeof(struct udf_part_map) * Y, GFP_KERNEL);\ | ||
| 55 | if (UDF_SB_PARTMAPS(X) != NULL) {\ | ||
| 56 | UDF_SB_NUMPARTS(X) = Y;\ | ||
| 57 | memset(UDF_SB_PARTMAPS(X), 0x00, sizeof(struct udf_part_map) * Y);\ | ||
| 58 | } else {\ | ||
| 59 | UDF_SB_NUMPARTS(X) = 0;\ | ||
| 60 | udf_error(X, __FUNCTION__, "Unable to allocate space for %d partition maps", Y);\ | ||
| 61 | }\ | ||
| 62 | } | ||
| 63 | |||
| 64 | #define UDF_SB_ALLOC_BITMAP(X,Y,Z)\ | ||
| 65 | {\ | ||
| 66 | int nr_groups = ((UDF_SB_PARTLEN((X),(Y)) + (sizeof(struct spaceBitmapDesc) << 3) +\ | ||
| 67 | ((X)->s_blocksize * 8) - 1) / ((X)->s_blocksize * 8));\ | ||
| 68 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\ | ||
| 69 | if (size <= PAGE_SIZE)\ | ||
| 70 | UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = kmalloc(size, GFP_KERNEL);\ | ||
| 71 | else\ | ||
| 72 | UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = vmalloc(size);\ | ||
| 73 | if (UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap != NULL) {\ | ||
| 74 | memset(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap, 0x00, size);\ | ||
| 75 | UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap =\ | ||
| 76 | (struct buffer_head **)(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap + 1);\ | ||
| 77 | UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups = nr_groups;\ | ||
| 78 | } else {\ | ||
| 79 | udf_error(X, __FUNCTION__, "Unable to allocate space for bitmap and %d buffer_head pointers", nr_groups);\ | ||
| 80 | }\ | ||
| 81 | } | ||
| 82 | 47 | ||
| 83 | #define UDF_SB_FREE_BITMAP(X,Y,Z)\ | 48 | int udf_compute_nr_groups(struct super_block *sb, u32 partition); |
| 84 | {\ | ||
| 85 | int i;\ | ||
| 86 | int nr_groups = UDF_SB_BITMAP_NR_GROUPS(X,Y,Z);\ | ||
| 87 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\ | ||
| 88 | for (i = 0; i < nr_groups; i++) {\ | ||
| 89 | if (UDF_SB_BITMAP(X,Y,Z,i))\ | ||
| 90 | brelse(UDF_SB_BITMAP(X,Y,Z,i));\ | ||
| 91 | }\ | ||
| 92 | if (size <= PAGE_SIZE)\ | ||
| 93 | kfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\ | ||
| 94 | else\ | ||
| 95 | vfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\ | ||
| 96 | } | ||
| 97 | 49 | ||
| 98 | #define UDF_QUERY_FLAG(X,Y) ( UDF_SB(X)->s_flags & ( 1 << (Y) ) ) | 50 | #define UDF_QUERY_FLAG(X,Y) ( UDF_SB(X)->s_flags & ( 1 << (Y) ) ) |
| 99 | #define UDF_SET_FLAG(X,Y) ( UDF_SB(X)->s_flags |= ( 1 << (Y) ) ) | 51 | #define UDF_SET_FLAG(X,Y) ( UDF_SB(X)->s_flags |= ( 1 << (Y) ) ) |
| 100 | #define UDF_CLEAR_FLAG(X,Y) ( UDF_SB(X)->s_flags &= ~( 1 << (Y) ) ) | 52 | #define UDF_CLEAR_FLAG(X,Y) ( UDF_SB(X)->s_flags &= ~( 1 << (Y) ) ) |
| 101 | 53 | ||
| 102 | #define UDF_UPDATE_UDFREV(X,Y) ( ((Y) > UDF_SB_UDFREV(X)) ? UDF_SB_UDFREV(X) = (Y) : UDF_SB_UDFREV(X) ) | ||
| 103 | |||
| 104 | #define UDF_SB_PARTMAPS(X) ( UDF_SB(X)->s_partmaps ) | ||
| 105 | #define UDF_SB_PARTTYPE(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_type ) | ||
| 106 | #define UDF_SB_PARTROOT(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_root ) | ||
| 107 | #define UDF_SB_PARTLEN(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_len ) | ||
| 108 | #define UDF_SB_PARTVSN(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_volumeseqnum ) | ||
| 109 | #define UDF_SB_PARTNUM(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_num ) | ||
| 110 | #define UDF_SB_TYPESPAR(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_sparing ) | ||
| 111 | #define UDF_SB_TYPEVIRT(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_virtual ) | ||
| 112 | #define UDF_SB_PARTFUNC(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_func ) | ||
| 113 | #define UDF_SB_PARTFLAGS(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_flags ) | ||
| 114 | #define UDF_SB_BITMAP(X,Y,Z,I) ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap[I] ) | ||
| 115 | #define UDF_SB_BITMAP_NR_GROUPS(X,Y,Z) ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups ) | ||
| 116 | |||
| 117 | #define UDF_SB_VOLIDENT(X) ( UDF_SB(X)->s_volident ) | ||
| 118 | #define UDF_SB_NUMPARTS(X) ( UDF_SB(X)->s_partitions ) | ||
| 119 | #define UDF_SB_PARTITION(X) ( UDF_SB(X)->s_partition ) | ||
| 120 | #define UDF_SB_SESSION(X) ( UDF_SB(X)->s_session ) | ||
| 121 | #define UDF_SB_ANCHOR(X) ( UDF_SB(X)->s_anchor ) | ||
| 122 | #define UDF_SB_LASTBLOCK(X) ( UDF_SB(X)->s_lastblock ) | ||
| 123 | #define UDF_SB_LVIDBH(X) ( UDF_SB(X)->s_lvidbh ) | ||
| 124 | #define UDF_SB_LVID(X) ( (struct logicalVolIntegrityDesc *)UDF_SB_LVIDBH(X)->b_data ) | ||
| 125 | #define UDF_SB_LVIDIU(X) ( (struct logicalVolIntegrityDescImpUse *)&(UDF_SB_LVID(X)->impUse[le32_to_cpu(UDF_SB_LVID(X)->numOfPartitions) * 2 * sizeof(uint32_t)/sizeof(uint8_t)]) ) | ||
| 126 | |||
| 127 | #define UDF_SB_UMASK(X) ( UDF_SB(X)->s_umask ) | ||
| 128 | #define UDF_SB_GID(X) ( UDF_SB(X)->s_gid ) | ||
| 129 | #define UDF_SB_UID(X) ( UDF_SB(X)->s_uid ) | ||
| 130 | #define UDF_SB_RECORDTIME(X) ( UDF_SB(X)->s_recordtime ) | ||
| 131 | #define UDF_SB_SERIALNUM(X) ( UDF_SB(X)->s_serialnum ) | ||
| 132 | #define UDF_SB_UDFREV(X) ( UDF_SB(X)->s_udfrev ) | ||
| 133 | #define UDF_SB_FLAGS(X) ( UDF_SB(X)->s_flags ) | ||
| 134 | #define UDF_SB_VAT(X) ( UDF_SB(X)->s_vat ) | ||
| 135 | |||
| 136 | #endif /* __LINUX_UDF_SB_H */ | 54 | #endif /* __LINUX_UDF_SB_H */ |
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index c8016cc9e7e6..681dc2b66cdb 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h | |||
| @@ -24,18 +24,21 @@ | |||
| 24 | #define UDF_PATH_LEN 1023 | 24 | #define UDF_PATH_LEN 1023 |
| 25 | 25 | ||
| 26 | #define udf_file_entry_alloc_offset(inode)\ | 26 | #define udf_file_entry_alloc_offset(inode)\ |
| 27 | (UDF_I_USE(inode) ?\ | 27 | (UDF_I(inode)->i_use ?\ |
| 28 | sizeof(struct unallocSpaceEntry) :\ | 28 | sizeof(struct unallocSpaceEntry) :\ |
| 29 | ((UDF_I_EFE(inode) ?\ | 29 | ((UDF_I(inode)->i_efe ?\ |
| 30 | sizeof(struct extendedFileEntry) :\ | 30 | sizeof(struct extendedFileEntry) :\ |
| 31 | sizeof(struct fileEntry)) + UDF_I_LENEATTR(inode))) | 31 | sizeof(struct fileEntry)) + UDF_I(inode)->i_lenEAttr)) |
| 32 | 32 | ||
| 33 | #define udf_ext0_offset(inode)\ | 33 | #define udf_ext0_offset(inode)\ |
| 34 | (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ?\ | 34 | (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ?\ |
| 35 | udf_file_entry_alloc_offset(inode) : 0) | 35 | udf_file_entry_alloc_offset(inode) : 0) |
| 36 | 36 | ||
| 37 | #define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset)) | 37 | #define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset)) |
| 38 | 38 | ||
| 39 | /* computes tag checksum */ | ||
| 40 | u8 udf_tag_checksum(const tag *t); | ||
| 41 | |||
| 39 | struct dentry; | 42 | struct dentry; |
| 40 | struct inode; | 43 | struct inode; |
| 41 | struct task_struct; | 44 | struct task_struct; |
| @@ -185,8 +188,8 @@ extern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *, | |||
| 185 | sector_t *); | 188 | sector_t *); |
| 186 | extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, | 189 | extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, |
| 187 | int *offset); | 190 | int *offset); |
| 188 | extern long_ad *udf_get_filelongad(uint8_t *, int, int *, int); | 191 | extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int); |
| 189 | extern short_ad *udf_get_fileshortad(uint8_t *, int, int *, int); | 192 | extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int); |
| 190 | 193 | ||
| 191 | /* crc.c */ | 194 | /* crc.c */ |
| 192 | extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t); | 195 | extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t); |
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c index adcb87c2da7e..ce595732ba6f 100644 --- a/fs/udf/udftime.c +++ b/fs/udf/udftime.c | |||
| @@ -18,8 +18,10 @@ | |||
| 18 | Boston, MA 02111-1307, USA. */ | 18 | Boston, MA 02111-1307, USA. */ |
| 19 | 19 | ||
| 20 | /* | 20 | /* |
| 21 | * dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time | 21 | * dgb 10/02/98: ripped this from glibc source to help convert timestamps |
| 22 | * 10/04/98: added new table-based lookup after seeing how ugly the gnu code is | 22 | * to unix time |
| 23 | * 10/04/98: added new table-based lookup after seeing how ugly | ||
| 24 | * the gnu code is | ||
| 23 | * blf 09/27/99: ripped out all the old code and inserted new table from | 25 | * blf 09/27/99: ripped out all the old code and inserted new table from |
| 24 | * John Brockmeyer (without leap second corrections) | 26 | * John Brockmeyer (without leap second corrections) |
| 25 | * rewrote udf_stamp_to_time and fixed timezone accounting in | 27 | * rewrote udf_stamp_to_time and fixed timezone accounting in |
| @@ -55,27 +57,27 @@ static const unsigned short int __mon_yday[2][13] = { | |||
| 55 | 57 | ||
| 56 | #define MAX_YEAR_SECONDS 69 | 58 | #define MAX_YEAR_SECONDS 69 |
| 57 | #define SPD 0x15180 /*3600*24 */ | 59 | #define SPD 0x15180 /*3600*24 */ |
| 58 | #define SPY(y,l,s) (SPD * (365*y+l)+s) | 60 | #define SPY(y, l, s) (SPD * (365 * y + l) + s) |
| 59 | 61 | ||
| 60 | static time_t year_seconds[MAX_YEAR_SECONDS]= { | 62 | static time_t year_seconds[MAX_YEAR_SECONDS] = { |
| 61 | /*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0), | 63 | /*1970*/ SPY(0, 0, 0), SPY(1, 0, 0), SPY(2, 0, 0), SPY(3, 1, 0), |
| 62 | /*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0), | 64 | /*1974*/ SPY(4, 1, 0), SPY(5, 1, 0), SPY(6, 1, 0), SPY(7, 2, 0), |
| 63 | /*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0), | 65 | /*1978*/ SPY(8, 2, 0), SPY(9, 2, 0), SPY(10, 2, 0), SPY(11, 3, 0), |
| 64 | /*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0), | 66 | /*1982*/ SPY(12, 3, 0), SPY(13, 3, 0), SPY(14, 3, 0), SPY(15, 4, 0), |
| 65 | /*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0), | 67 | /*1986*/ SPY(16, 4, 0), SPY(17, 4, 0), SPY(18, 4, 0), SPY(19, 5, 0), |
| 66 | /*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0), | 68 | /*1990*/ SPY(20, 5, 0), SPY(21, 5, 0), SPY(22, 5, 0), SPY(23, 6, 0), |
| 67 | /*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0), | 69 | /*1994*/ SPY(24, 6, 0), SPY(25, 6, 0), SPY(26, 6, 0), SPY(27, 7, 0), |
| 68 | /*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0), | 70 | /*1998*/ SPY(28, 7, 0), SPY(29, 7, 0), SPY(30, 7, 0), SPY(31, 8, 0), |
| 69 | /*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0), | 71 | /*2002*/ SPY(32, 8, 0), SPY(33, 8, 0), SPY(34, 8, 0), SPY(35, 9, 0), |
| 70 | /*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0), | 72 | /*2006*/ SPY(36, 9, 0), SPY(37, 9, 0), SPY(38, 9, 0), SPY(39, 10, 0), |
| 71 | /*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0), | 73 | /*2010*/ SPY(40, 10, 0), SPY(41, 10, 0), SPY(42, 10, 0), SPY(43, 11, 0), |
| 72 | /*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0), | 74 | /*2014*/ SPY(44, 11, 0), SPY(45, 11, 0), SPY(46, 11, 0), SPY(47, 12, 0), |
| 73 | /*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0), | 75 | /*2018*/ SPY(48, 12, 0), SPY(49, 12, 0), SPY(50, 12, 0), SPY(51, 13, 0), |
| 74 | /*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0), | 76 | /*2022*/ SPY(52, 13, 0), SPY(53, 13, 0), SPY(54, 13, 0), SPY(55, 14, 0), |
| 75 | /*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0), | 77 | /*2026*/ SPY(56, 14, 0), SPY(57, 14, 0), SPY(58, 14, 0), SPY(59, 15, 0), |
| 76 | /*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0), | 78 | /*2030*/ SPY(60, 15, 0), SPY(61, 15, 0), SPY(62, 15, 0), SPY(63, 16, 0), |
| 77 | /*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0), | 79 | /*2034*/ SPY(64, 16, 0), SPY(65, 16, 0), SPY(66, 16, 0), SPY(67, 17, 0), |
| 78 | /*2038*/ SPY(68,17,0) | 80 | /*2038*/ SPY(68, 17, 0) |
| 79 | }; | 81 | }; |
| 80 | 82 | ||
| 81 | extern struct timezone sys_tz; | 83 | extern struct timezone sys_tz; |
| @@ -115,7 +117,7 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src) | |||
| 115 | return dest; | 117 | return dest; |
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) | 120 | kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts) |
| 119 | { | 121 | { |
| 120 | long int days, rem, y; | 122 | long int days, rem, y; |
| 121 | const unsigned short int *ip; | 123 | const unsigned short int *ip; |
| @@ -137,7 +139,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) | |||
| 137 | dest->second = rem % 60; | 139 | dest->second = rem % 60; |
| 138 | y = 1970; | 140 | y = 1970; |
| 139 | 141 | ||
| 140 | #define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) | 142 | #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) |
| 141 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) | 143 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) |
| 142 | 144 | ||
| 143 | while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { | 145 | while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { |
| @@ -145,8 +147,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) | |||
| 145 | 147 | ||
| 146 | /* Adjust DAYS and Y to match the guessed year. */ | 148 | /* Adjust DAYS and Y to match the guessed year. */ |
| 147 | days -= ((yg - y) * 365 | 149 | days -= ((yg - y) * 365 |
| 148 | + LEAPS_THRU_END_OF (yg - 1) | 150 | + LEAPS_THRU_END_OF(yg - 1) |
| 149 | - LEAPS_THRU_END_OF (y - 1)); | 151 | - LEAPS_THRU_END_OF(y - 1)); |
| 150 | y = yg; | 152 | y = yg; |
| 151 | } | 153 | } |
| 152 | dest->year = y; | 154 | dest->year = y; |
| @@ -158,7 +160,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) | |||
| 158 | dest->day = days + 1; | 160 | dest->day = days + 1; |
| 159 | 161 | ||
| 160 | dest->centiseconds = ts.tv_nsec / 10000000; | 162 | dest->centiseconds = ts.tv_nsec / 10000000; |
| 161 | dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; | 163 | dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - |
| 164 | dest->centiseconds * 10000) / 100; | ||
| 162 | dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - | 165 | dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - |
| 163 | dest->hundredsOfMicroseconds * 100); | 166 | dest->hundredsOfMicroseconds * 100); |
| 164 | return dest; | 167 | return dest; |
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index 9e6099c26c27..e533b11703bf 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c | |||
| @@ -136,12 +136,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i) | |||
| 136 | if (c < 0x80U) { | 136 | if (c < 0x80U) { |
| 137 | utf_o->u_name[utf_o->u_len++] = (uint8_t)c; | 137 | utf_o->u_name[utf_o->u_len++] = (uint8_t)c; |
| 138 | } else if (c < 0x800U) { | 138 | } else if (c < 0x800U) { |
| 139 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); | 139 | utf_o->u_name[utf_o->u_len++] = |
| 140 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); | 140 | (uint8_t)(0xc0 | (c >> 6)); |
| 141 | utf_o->u_name[utf_o->u_len++] = | ||
| 142 | (uint8_t)(0x80 | (c & 0x3f)); | ||
| 141 | } else { | 143 | } else { |
| 142 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); | 144 | utf_o->u_name[utf_o->u_len++] = |
| 143 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); | 145 | (uint8_t)(0xe0 | (c >> 12)); |
| 144 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); | 146 | utf_o->u_name[utf_o->u_len++] = |
| 147 | (uint8_t)(0x80 | | ||
| 148 | ((c >> 6) & 0x3f)); | ||
| 149 | utf_o->u_name[utf_o->u_len++] = | ||
| 150 | (uint8_t)(0x80 | (c & 0x3f)); | ||
| 145 | } | 151 | } |
| 146 | } | 152 | } |
| 147 | utf_o->u_cmpID = 8; | 153 | utf_o->u_cmpID = 8; |
| @@ -232,9 +238,8 @@ try_again: | |||
| 232 | goto error_out; | 238 | goto error_out; |
| 233 | } | 239 | } |
| 234 | 240 | ||
| 235 | if (max_val == 0xffffU) { | 241 | if (max_val == 0xffffU) |
| 236 | ocu[++u_len] = (uint8_t)(utf_char >> 8); | 242 | ocu[++u_len] = (uint8_t)(utf_char >> 8); |
| 237 | } | ||
| 238 | ocu[++u_len] = (uint8_t)(utf_char & 0xffU); | 243 | ocu[++u_len] = (uint8_t)(utf_char & 0xffU); |
| 239 | } | 244 | } |
| 240 | 245 | ||
| @@ -330,29 +335,29 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, | |||
| 330 | struct ustr filename, unifilename; | 335 | struct ustr filename, unifilename; |
| 331 | int len; | 336 | int len; |
| 332 | 337 | ||
| 333 | if (udf_build_ustr_exact(&unifilename, sname, flen)) { | 338 | if (udf_build_ustr_exact(&unifilename, sname, flen)) |
| 334 | return 0; | 339 | return 0; |
| 335 | } | ||
| 336 | 340 | ||
| 337 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { | 341 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
| 338 | if (!udf_CS0toUTF8(&filename, &unifilename)) { | 342 | if (!udf_CS0toUTF8(&filename, &unifilename)) { |
| 339 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); | 343 | udf_debug("Failed in udf_get_filename: sname = %s\n", |
| 344 | sname); | ||
| 340 | return 0; | 345 | return 0; |
| 341 | } | 346 | } |
| 342 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { | 347 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
| 343 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) { | 348 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, |
| 344 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); | 349 | &unifilename)) { |
| 350 | udf_debug("Failed in udf_get_filename: sname = %s\n", | ||
| 351 | sname); | ||
| 345 | return 0; | 352 | return 0; |
| 346 | } | 353 | } |
| 347 | } else { | 354 | } else |
| 348 | return 0; | 355 | return 0; |
| 349 | } | ||
| 350 | 356 | ||
| 351 | len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, | 357 | len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, |
| 352 | unifilename.u_name, unifilename.u_len); | 358 | unifilename.u_name, unifilename.u_len); |
| 353 | if (len) { | 359 | if (len) |
| 354 | return len; | 360 | return len; |
| 355 | } | ||
| 356 | 361 | ||
| 357 | return 0; | 362 | return 0; |
| 358 | } | 363 | } |
| @@ -363,23 +368,20 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, | |||
| 363 | struct ustr unifilename; | 368 | struct ustr unifilename; |
| 364 | int namelen; | 369 | int namelen; |
| 365 | 370 | ||
| 366 | if (!(udf_char_to_ustr(&unifilename, sname, flen))) { | 371 | if (!udf_char_to_ustr(&unifilename, sname, flen)) |
| 367 | return 0; | 372 | return 0; |
| 368 | } | ||
| 369 | 373 | ||
| 370 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { | 374 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
| 371 | namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); | 375 | namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); |
| 372 | if (!namelen) { | 376 | if (!namelen) |
| 373 | return 0; | 377 | return 0; |
| 374 | } | ||
| 375 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { | 378 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
| 376 | namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN); | 379 | namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, |
| 377 | if (!namelen) { | 380 | &unifilename, UDF_NAME_LEN); |
| 381 | if (!namelen) | ||
| 378 | return 0; | 382 | return 0; |
| 379 | } | 383 | } else |
| 380 | } else { | ||
| 381 | return 0; | 384 | return 0; |
| 382 | } | ||
| 383 | 385 | ||
| 384 | return namelen; | 386 | return namelen; |
| 385 | } | 387 | } |
| @@ -389,8 +391,9 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, | |||
| 389 | #define CRC_MARK '#' | 391 | #define CRC_MARK '#' |
| 390 | #define EXT_SIZE 5 | 392 | #define EXT_SIZE 5 |
| 391 | 393 | ||
| 392 | static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, | 394 | static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, |
| 393 | uint8_t *fidName, int fidNameLen) | 395 | int udfLen, uint8_t *fidName, |
| 396 | int fidNameLen) | ||
| 394 | { | 397 | { |
| 395 | int index, newIndex = 0, needsCRC = 0; | 398 | int index, newIndex = 0, needsCRC = 0; |
| 396 | int extIndex = 0, newExtIndex = 0, hasExt = 0; | 399 | int extIndex = 0, newExtIndex = 0, hasExt = 0; |
| @@ -409,13 +412,16 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
| 409 | if (curr == '/' || curr == 0) { | 412 | if (curr == '/' || curr == 0) { |
| 410 | needsCRC = 1; | 413 | needsCRC = 1; |
| 411 | curr = ILLEGAL_CHAR_MARK; | 414 | curr = ILLEGAL_CHAR_MARK; |
| 412 | while (index + 1 < udfLen && (udfName[index + 1] == '/' || | 415 | while (index + 1 < udfLen && |
| 413 | udfName[index + 1] == 0)) | 416 | (udfName[index + 1] == '/' || |
| 417 | udfName[index + 1] == 0)) | ||
| 414 | index++; | 418 | index++; |
| 415 | } if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) { | 419 | } |
| 416 | if (udfLen == index + 1) { | 420 | if (curr == EXT_MARK && |
| 421 | (udfLen - index - 1) <= EXT_SIZE) { | ||
| 422 | if (udfLen == index + 1) | ||
| 417 | hasExt = 0; | 423 | hasExt = 0; |
| 418 | } else { | 424 | else { |
| 419 | hasExt = 1; | 425 | hasExt = 1; |
| 420 | extIndex = index; | 426 | extIndex = index; |
| 421 | newExtIndex = newIndex; | 427 | newExtIndex = newIndex; |
| @@ -433,16 +439,18 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
| 433 | 439 | ||
| 434 | if (hasExt) { | 440 | if (hasExt) { |
| 435 | int maxFilenameLen; | 441 | int maxFilenameLen; |
| 436 | for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) { | 442 | for (index = 0; |
| 443 | index < EXT_SIZE && extIndex + index + 1 < udfLen; | ||
| 444 | index++) { | ||
| 437 | curr = udfName[extIndex + index + 1]; | 445 | curr = udfName[extIndex + index + 1]; |
| 438 | 446 | ||
| 439 | if (curr == '/' || curr == 0) { | 447 | if (curr == '/' || curr == 0) { |
| 440 | needsCRC = 1; | 448 | needsCRC = 1; |
| 441 | curr = ILLEGAL_CHAR_MARK; | 449 | curr = ILLEGAL_CHAR_MARK; |
| 442 | while(extIndex + index + 2 < udfLen && | 450 | while (extIndex + index + 2 < udfLen && |
| 443 | (index + 1 < EXT_SIZE | 451 | (index + 1 < EXT_SIZE && |
| 444 | && (udfName[extIndex + index + 2] == '/' || | 452 | (udfName[extIndex + index + 2] == '/' || |
| 445 | udfName[extIndex + index + 2] == 0))) | 453 | udfName[extIndex + index + 2] == 0))) |
| 446 | index++; | 454 | index++; |
| 447 | } | 455 | } |
| 448 | ext[localExtIndex++] = curr; | 456 | ext[localExtIndex++] = curr; |
| @@ -452,9 +460,8 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
| 452 | newIndex = maxFilenameLen; | 460 | newIndex = maxFilenameLen; |
| 453 | else | 461 | else |
| 454 | newIndex = newExtIndex; | 462 | newIndex = newExtIndex; |
| 455 | } else if (newIndex > 250) { | 463 | } else if (newIndex > 250) |
| 456 | newIndex = 250; | 464 | newIndex = 250; |
| 457 | } | ||
| 458 | newName[newIndex++] = CRC_MARK; | 465 | newName[newIndex++] = CRC_MARK; |
| 459 | valueCRC = udf_crc(fidName, fidNameLen, 0); | 466 | valueCRC = udf_crc(fidName, fidNameLen, 0); |
| 460 | newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; | 467 | newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; |
