diff options
author | Marcin Slusarz <marcin.slusarz@gmail.com> | 2008-02-08 07:20:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 12:22:35 -0500 |
commit | 4b11111aba6c80cc2969fd1806d2a869bfc9f357 (patch) | |
tree | 57b72a1ca58859dc6a9e47d647f29cebb9bcf7e0 | |
parent | bd45a420f93d18c91115f3f0568dd6a2555aa15a (diff) |
udf: fix coding style
fix coding style errors found by checkpatch:
- assignments in if conditions
- braces {} around single statement blocks
- no spaces after commas
- printks without KERN_*
- lines longer than 80 characters
- spaces between "type *" and variable name
before: 192 errors, 561 warnings, 8987 lines checked
after: 1 errors, 38 warnings, 9468 lines checked
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/udf/balloc.c | 231 | ||||
-rw-r--r-- | fs/udf/crc.c | 2 | ||||
-rw-r--r-- | fs/udf/directory.c | 80 | ||||
-rw-r--r-- | fs/udf/file.c | 18 | ||||
-rw-r--r-- | fs/udf/ialloc.c | 24 | ||||
-rw-r--r-- | fs/udf/inode.c | 665 | ||||
-rw-r--r-- | fs/udf/misc.c | 76 | ||||
-rw-r--r-- | fs/udf/namei.c | 298 | ||||
-rw-r--r-- | fs/udf/partition.c | 160 | ||||
-rw-r--r-- | fs/udf/super.c | 377 | ||||
-rw-r--r-- | fs/udf/symlink.c | 3 | ||||
-rw-r--r-- | fs/udf/truncate.c | 58 | ||||
-rw-r--r-- | fs/udf/udftime.c | 59 | ||||
-rw-r--r-- | fs/udf/unicode.c | 85 |
14 files changed, 1306 insertions, 830 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 3f67d9dc8631..dc9f8a96b6e4 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; |
@@ -91,9 +93,9 @@ static int read_block_bitmap(struct super_block *sb, | |||
91 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; | 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 | } |
@@ -155,14 +157,17 @@ static void udf_bitmap_free_blocks(struct super_block *sb, | |||
155 | 157 | ||
156 | mutex_lock(&sbi->s_alloc_mutex); | 158 | mutex_lock(&sbi->s_alloc_mutex); |
157 | if (bloc.logicalBlockNum < 0 || | 159 | if (bloc.logicalBlockNum < 0 || |
158 | (bloc.logicalBlockNum + count) > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | 160 | (bloc.logicalBlockNum + count) > |
161 | sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | ||
159 | udf_debug("%d < %d || %d + %d > %d\n", | 162 | udf_debug("%d < %d || %d + %d > %d\n", |
160 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 163 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
161 | sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len); | 164 | sbi->s_partmaps[bloc.partitionReferenceNum]. |
165 | s_partition_len); | ||
162 | goto error_return; | 166 | goto error_return; |
163 | } | 167 | } |
164 | 168 | ||
165 | block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3); | 169 | block = bloc.logicalBlockNum + offset + |
170 | (sizeof(struct spaceBitmapDesc) << 3); | ||
166 | 171 | ||
167 | do_more: | 172 | do_more: |
168 | overflow = 0; | 173 | overflow = 0; |
@@ -184,7 +189,8 @@ do_more: | |||
184 | for (i = 0; i < count; i++) { | 189 | for (i = 0; i < count; i++) { |
185 | if (udf_set_bit(bit + i, bh->b_data)) { | 190 | if (udf_set_bit(bit + i, bh->b_data)) { |
186 | udf_debug("bit %ld already set\n", bit + i); | 191 | udf_debug("bit %ld already set\n", bit + i); |
187 | udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); | 192 | udf_debug("byte=%2x\n", |
193 | ((char *)bh->b_data)[(bit + i) >> 3]); | ||
188 | } else { | 194 | } else { |
189 | if (inode) | 195 | if (inode) |
190 | DQUOT_FREE_BLOCK(inode, 1); | 196 | DQUOT_FREE_BLOCK(inode, 1); |
@@ -314,14 +320,16 @@ repeat: | |||
314 | if (bit < end_goal) | 320 | if (bit < end_goal) |
315 | goto got_block; | 321 | goto got_block; |
316 | 322 | ||
317 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); | 323 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, |
324 | sb->s_blocksize - ((bit + 7) >> 3)); | ||
318 | newbit = (ptr - ((char *)bh->b_data)) << 3; | 325 | newbit = (ptr - ((char *)bh->b_data)) << 3; |
319 | if (newbit < sb->s_blocksize << 3) { | 326 | if (newbit < sb->s_blocksize << 3) { |
320 | bit = newbit; | 327 | bit = newbit; |
321 | goto search_back; | 328 | goto search_back; |
322 | } | 329 | } |
323 | 330 | ||
324 | newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); | 331 | newbit = udf_find_next_one_bit(bh->b_data, |
332 | sb->s_blocksize << 3, bit); | ||
325 | if (newbit < sb->s_blocksize << 3) { | 333 | if (newbit < sb->s_blocksize << 3) { |
326 | bit = newbit; | 334 | bit = newbit; |
327 | goto got_block; | 335 | goto got_block; |
@@ -360,15 +368,20 @@ repeat: | |||
360 | if (bit < sb->s_blocksize << 3) | 368 | if (bit < sb->s_blocksize << 3) |
361 | goto search_back; | 369 | goto search_back; |
362 | else | 370 | else |
363 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); | 371 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, |
372 | group_start << 3); | ||
364 | if (bit >= sb->s_blocksize << 3) { | 373 | if (bit >= sb->s_blocksize << 3) { |
365 | mutex_unlock(&sbi->s_alloc_mutex); | 374 | mutex_unlock(&sbi->s_alloc_mutex); |
366 | return 0; | 375 | return 0; |
367 | } | 376 | } |
368 | 377 | ||
369 | search_back: | 378 | search_back: |
370 | for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--) | 379 | i = 0; |
371 | ; /* empty loop */ | 380 | while (i < 7 && bit > (group_start << 3) && |
381 | udf_test_bit(bit - 1, bh->b_data)) { | ||
382 | ++i; | ||
383 | --bit; | ||
384 | } | ||
372 | 385 | ||
373 | got_block: | 386 | got_block: |
374 | 387 | ||
@@ -424,15 +437,17 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
424 | 437 | ||
425 | mutex_lock(&sbi->s_alloc_mutex); | 438 | mutex_lock(&sbi->s_alloc_mutex); |
426 | if (bloc.logicalBlockNum < 0 || | 439 | if (bloc.logicalBlockNum < 0 || |
427 | (bloc.logicalBlockNum + count) > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | 440 | (bloc.logicalBlockNum + count) > |
441 | sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | ||
428 | udf_debug("%d < %d || %d + %d > %d\n", | 442 | udf_debug("%d < %d || %d + %d > %d\n", |
429 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 443 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
430 | sbi->s_partmaps[bloc.partitionReferenceNum]->s_partition_len); | 444 | sbi->s_partmaps[bloc.partitionReferenceNum]. |
445 | s_partition_len); | ||
431 | goto error_return; | 446 | goto error_return; |
432 | } | 447 | } |
433 | 448 | ||
434 | /* We do this up front - There are some error conditions that could occure, | 449 | /* We do this up front - There are some error conditions that |
435 | but.. oh well */ | 450 | could occure, but.. oh well */ |
436 | if (inode) | 451 | if (inode) |
437 | DQUOT_FREE_BLOCK(inode, count); | 452 | DQUOT_FREE_BLOCK(inode, count); |
438 | if (sbi->s_lvid_bh) { | 453 | if (sbi->s_lvid_bh) { |
@@ -452,26 +467,39 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
452 | 467 | ||
453 | while (count && | 468 | while (count && |
454 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { | 469 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
455 | if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) { | 470 | if (((eloc.logicalBlockNum + |
456 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { | 471 | (elen >> sb->s_blocksize_bits)) == start)) { |
457 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 472 | if ((0x3FFFFFFF - elen) < |
458 | start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 473 | (count << sb->s_blocksize_bits)) { |
459 | 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); | ||
460 | } else { | 480 | } else { |
461 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); | 481 | elen = (etype << 30) | |
482 | (elen + | ||
483 | (count << sb->s_blocksize_bits)); | ||
462 | start += count; | 484 | start += count; |
463 | count = 0; | 485 | count = 0; |
464 | } | 486 | } |
465 | udf_write_aext(table, &oepos, eloc, elen, 1); | 487 | udf_write_aext(table, &oepos, eloc, elen, 1); |
466 | } else if (eloc.logicalBlockNum == (end + 1)) { | 488 | } else if (eloc.logicalBlockNum == (end + 1)) { |
467 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { | 489 | if ((0x3FFFFFFF - elen) < |
468 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 490 | (count << sb->s_blocksize_bits)) { |
469 | end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 491 | uint32_t tmp = ((0x3FFFFFFF - elen) >> |
470 | eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 492 | sb->s_blocksize_bits); |
471 | 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); | ||
472 | } else { | 498 | } else { |
473 | eloc.logicalBlockNum = start; | 499 | eloc.logicalBlockNum = start; |
474 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); | 500 | elen = (etype << 30) | |
501 | (elen + | ||
502 | (count << sb->s_blocksize_bits)); | ||
475 | end -= count; | 503 | end -= count; |
476 | count = 0; | 504 | count = 0; |
477 | } | 505 | } |
@@ -492,9 +520,9 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
492 | 520 | ||
493 | if (count) { | 521 | if (count) { |
494 | /* | 522 | /* |
495 | * 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 |
496 | * a new block, and since we hold the super block lock already | 524 | * allocate a new block, and since we hold the super block |
497 | * very bad things would happen :) | 525 | * lock already very bad things would happen :) |
498 | * | 526 | * |
499 | * We copy the behavior of udf_add_aext, but instead of | 527 | * We copy the behavior of udf_add_aext, but instead of |
500 | * trying to allocate a new block close to the existing one, | 528 | * trying to allocate a new block close to the existing one, |
@@ -535,27 +563,35 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
535 | eloc.logicalBlockNum++; | 563 | eloc.logicalBlockNum++; |
536 | elen -= sb->s_blocksize; | 564 | elen -= sb->s_blocksize; |
537 | 565 | ||
538 | 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) { | ||
539 | brelse(oepos.bh); | 569 | brelse(oepos.bh); |
540 | goto error_return; | 570 | goto error_return; |
541 | } | 571 | } |
542 | aed = (struct allocExtDesc *)(epos.bh->b_data); | 572 | aed = (struct allocExtDesc *)(epos.bh->b_data); |
543 | aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); | 573 | aed->previousAllocExtLocation = |
574 | cpu_to_le32(oepos.block.logicalBlockNum); | ||
544 | if (epos.offset + adsize > sb->s_blocksize) { | 575 | if (epos.offset + adsize > sb->s_blocksize) { |
545 | loffset = epos.offset; | 576 | loffset = epos.offset; |
546 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 577 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
547 | sptr = UDF_I_DATA(table) + epos.offset - adsize; | 578 | sptr = UDF_I_DATA(table) + epos.offset - adsize; |
548 | dptr = epos.bh->b_data + sizeof(struct allocExtDesc); | 579 | dptr = epos.bh->b_data + |
580 | sizeof(struct allocExtDesc); | ||
549 | memcpy(dptr, sptr, adsize); | 581 | memcpy(dptr, sptr, adsize); |
550 | epos.offset = sizeof(struct allocExtDesc) + adsize; | 582 | epos.offset = sizeof(struct allocExtDesc) + |
583 | adsize; | ||
551 | } else { | 584 | } else { |
552 | loffset = epos.offset + adsize; | 585 | loffset = epos.offset + adsize; |
553 | aed->lengthAllocDescs = cpu_to_le32(0); | 586 | aed->lengthAllocDescs = cpu_to_le32(0); |
554 | if (oepos.bh) { | 587 | if (oepos.bh) { |
555 | sptr = oepos.bh->b_data + epos.offset; | 588 | sptr = oepos.bh->b_data + epos.offset; |
556 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 589 | aed = (struct allocExtDesc *) |
590 | oepos.bh->b_data; | ||
557 | aed->lengthAllocDescs = | 591 | aed->lengthAllocDescs = |
558 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 592 | cpu_to_le32(le32_to_cpu( |
593 | aed->lengthAllocDescs) + | ||
594 | adsize); | ||
559 | } else { | 595 | } else { |
560 | sptr = UDF_I_DATA(table) + epos.offset; | 596 | sptr = UDF_I_DATA(table) + epos.offset; |
561 | UDF_I_LENALLOC(table) += adsize; | 597 | UDF_I_LENALLOC(table) += adsize; |
@@ -564,27 +600,31 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
564 | epos.offset = sizeof(struct allocExtDesc); | 600 | epos.offset = sizeof(struct allocExtDesc); |
565 | } | 601 | } |
566 | if (sbi->s_udfrev >= 0x0200) | 602 | if (sbi->s_udfrev >= 0x0200) |
567 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, | 603 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, |
568 | epos.block.logicalBlockNum, sizeof(tag)); | 604 | 3, 1, epos.block.logicalBlockNum, |
605 | sizeof(tag)); | ||
569 | else | 606 | else |
570 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, | 607 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, |
571 | epos.block.logicalBlockNum, sizeof(tag)); | 608 | 2, 1, epos.block.logicalBlockNum, |
609 | sizeof(tag)); | ||
572 | 610 | ||
573 | switch (UDF_I_ALLOCTYPE(table)) { | 611 | switch (UDF_I_ALLOCTYPE(table)) { |
574 | case ICBTAG_FLAG_AD_SHORT: | 612 | case ICBTAG_FLAG_AD_SHORT: |
575 | sad = (short_ad *)sptr; | 613 | sad = (short_ad *)sptr; |
576 | sad->extLength = cpu_to_le32( | 614 | sad->extLength = cpu_to_le32( |
577 | EXT_NEXT_EXTENT_ALLOCDECS | | 615 | EXT_NEXT_EXTENT_ALLOCDECS | |
578 | sb->s_blocksize); | 616 | sb->s_blocksize); |
579 | sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); | 617 | sad->extPosition = |
580 | break; | 618 | cpu_to_le32(epos.block.logicalBlockNum); |
581 | case ICBTAG_FLAG_AD_LONG: | 619 | break; |
582 | lad = (long_ad *)sptr; | 620 | case ICBTAG_FLAG_AD_LONG: |
583 | lad->extLength = cpu_to_le32( | 621 | lad = (long_ad *)sptr; |
584 | EXT_NEXT_EXTENT_ALLOCDECS | | 622 | lad->extLength = cpu_to_le32( |
585 | sb->s_blocksize); | 623 | EXT_NEXT_EXTENT_ALLOCDECS | |
586 | lad->extLocation = cpu_to_lelb(epos.block); | 624 | sb->s_blocksize); |
587 | break; | 625 | lad->extLocation = |
626 | cpu_to_lelb(epos.block); | ||
627 | break; | ||
588 | } | 628 | } |
589 | if (oepos.bh) { | 629 | if (oepos.bh) { |
590 | udf_update_tag(oepos.bh->b_data, loffset); | 630 | udf_update_tag(oepos.bh->b_data, loffset); |
@@ -594,7 +634,8 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
594 | } | 634 | } |
595 | } | 635 | } |
596 | 636 | ||
597 | if (elen) { /* It's possible that stealing the block emptied the extent */ | 637 | /* It's possible that stealing the block emptied the extent */ |
638 | if (elen) { | ||
598 | udf_write_aext(table, &epos, eloc, elen, 1); | 639 | udf_write_aext(table, &epos, eloc, elen, 1); |
599 | 640 | ||
600 | if (!epos.bh) { | 641 | if (!epos.bh) { |
@@ -603,7 +644,8 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
603 | } else { | 644 | } else { |
604 | aed = (struct allocExtDesc *)epos.bh->b_data; | 645 | aed = (struct allocExtDesc *)epos.bh->b_data; |
605 | aed->lengthAllocDescs = | 646 | aed->lengthAllocDescs = |
606 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 647 | cpu_to_le32(le32_to_cpu( |
648 | aed->lengthAllocDescs) + adsize); | ||
607 | udf_update_tag(epos.bh->b_data, epos.offset); | 649 | udf_update_tag(epos.bh->b_data, epos.offset); |
608 | mark_buffer_dirty(epos.bh); | 650 | mark_buffer_dirty(epos.bh); |
609 | } | 651 | } |
@@ -631,7 +673,8 @@ static int udf_table_prealloc_blocks(struct super_block *sb, | |||
631 | struct extent_position epos; | 673 | struct extent_position epos; |
632 | int8_t etype = -1; | 674 | int8_t etype = -1; |
633 | 675 | ||
634 | if (first_block < 0 || first_block >= sbi->s_partmaps[partition].s_partition_len) | 676 | if (first_block < 0 || |
677 | first_block >= sbi->s_partmaps[partition].s_partition_len) | ||
635 | return 0; | 678 | return 0; |
636 | 679 | ||
637 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) | 680 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) |
@@ -658,16 +701,18 @@ static int udf_table_prealloc_blocks(struct super_block *sb, | |||
658 | epos.offset -= adsize; | 701 | epos.offset -= adsize; |
659 | 702 | ||
660 | alloc_count = (elen >> sb->s_blocksize_bits); | 703 | alloc_count = (elen >> sb->s_blocksize_bits); |
661 | if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) { | 704 | if (inode && DQUOT_PREALLOC_BLOCK(inode, |
705 | alloc_count > block_count ? block_count : alloc_count)) | ||
662 | alloc_count = 0; | 706 | alloc_count = 0; |
663 | } else if (alloc_count > block_count) { | 707 | else if (alloc_count > block_count) { |
664 | alloc_count = block_count; | 708 | alloc_count = block_count; |
665 | eloc.logicalBlockNum += alloc_count; | 709 | eloc.logicalBlockNum += alloc_count; |
666 | elen -= (alloc_count << sb->s_blocksize_bits); | 710 | elen -= (alloc_count << sb->s_blocksize_bits); |
667 | udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); | 711 | udf_write_aext(table, &epos, eloc, |
668 | } else { | 712 | (etype << 30) | elen, 1); |
669 | udf_delete_aext(table, epos, eloc, (etype << 30) | elen); | 713 | } else |
670 | } | 714 | udf_delete_aext(table, epos, eloc, |
715 | (etype << 30) | elen); | ||
671 | } else { | 716 | } else { |
672 | alloc_count = 0; | 717 | alloc_count = 0; |
673 | } | 718 | } |
@@ -711,10 +756,10 @@ static int udf_table_new_block(struct super_block *sb, | |||
711 | if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) | 756 | if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) |
712 | goal = 0; | 757 | goal = 0; |
713 | 758 | ||
714 | /* We search for the closest matching block to goal. If we find a exact hit, | 759 | /* We search for the closest matching block to goal. If we find |
715 | we stop. Otherwise we keep going till we run out of extents. | 760 | a exact hit, we stop. Otherwise we keep going till we run out |
716 | We store the buffer_head, bloc, and extoffset of the current closest | 761 | of extents. We store the buffer_head, bloc, and extoffset |
717 | match and use that when we are done. | 762 | of the current closest match and use that when we are done. |
718 | */ | 763 | */ |
719 | epos.offset = sizeof(struct unallocSpaceEntry); | 764 | epos.offset = sizeof(struct unallocSpaceEntry); |
720 | epos.block = UDF_I_LOCATION(table); | 765 | epos.block = UDF_I_LOCATION(table); |
@@ -723,7 +768,8 @@ static int udf_table_new_block(struct super_block *sb, | |||
723 | while (spread && | 768 | while (spread && |
724 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { | 769 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
725 | if (goal >= eloc.logicalBlockNum) { | 770 | if (goal >= eloc.logicalBlockNum) { |
726 | if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) | 771 | if (goal < eloc.logicalBlockNum + |
772 | (elen >> sb->s_blocksize_bits)) | ||
727 | nspread = 0; | 773 | nspread = 0; |
728 | else | 774 | else |
729 | nspread = goal - eloc.logicalBlockNum - | 775 | nspread = goal - eloc.logicalBlockNum - |
@@ -825,52 +871,53 @@ inline int udf_prealloc_blocks(struct super_block *sb, | |||
825 | { | 871 | { |
826 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; | 872 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
827 | 873 | ||
828 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { | 874 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
829 | return udf_bitmap_prealloc_blocks(sb, inode, | 875 | return udf_bitmap_prealloc_blocks(sb, inode, |
830 | map->s_uspace.s_bitmap, | 876 | map->s_uspace.s_bitmap, |
831 | partition, first_block, block_count); | 877 | partition, first_block, |
832 | } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { | 878 | block_count); |
879 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) | ||
833 | return udf_table_prealloc_blocks(sb, inode, | 880 | return udf_table_prealloc_blocks(sb, inode, |
834 | map->s_uspace.s_table, | 881 | map->s_uspace.s_table, |
835 | partition, first_block, block_count); | 882 | partition, first_block, |
836 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { | 883 | block_count); |
884 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) | ||
837 | return udf_bitmap_prealloc_blocks(sb, inode, | 885 | return udf_bitmap_prealloc_blocks(sb, inode, |
838 | map->s_fspace.s_bitmap, | 886 | map->s_fspace.s_bitmap, |
839 | partition, first_block, block_count); | 887 | partition, first_block, |
840 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { | 888 | block_count); |
889 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) | ||
841 | return udf_table_prealloc_blocks(sb, inode, | 890 | return udf_table_prealloc_blocks(sb, inode, |
842 | map->s_fspace.s_table, | 891 | map->s_fspace.s_table, |
843 | partition, first_block, block_count); | 892 | partition, first_block, |
844 | } else { | 893 | block_count); |
894 | else | ||
845 | return 0; | 895 | return 0; |
846 | } | ||
847 | } | 896 | } |
848 | 897 | ||
849 | inline int udf_new_block(struct super_block *sb, | 898 | inline int udf_new_block(struct super_block *sb, |
850 | struct inode *inode, | 899 | struct inode *inode, |
851 | uint16_t partition, uint32_t goal, int *err) | 900 | uint16_t partition, uint32_t goal, int *err) |
852 | { | 901 | { |
853 | int ret; | ||
854 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; | 902 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
855 | 903 | ||
856 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { | 904 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
857 | ret = udf_bitmap_new_block(sb, inode, | 905 | return udf_bitmap_new_block(sb, inode, |
858 | map->s_uspace.s_bitmap, | 906 | map->s_uspace.s_bitmap, |
859 | partition, goal, err); | 907 | partition, goal, err); |
860 | return ret; | 908 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
861 | } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { | ||
862 | return udf_table_new_block(sb, inode, | 909 | return udf_table_new_block(sb, inode, |
863 | map->s_uspace.s_table, | 910 | map->s_uspace.s_table, |
864 | partition, goal, err); | 911 | partition, goal, err); |
865 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { | 912 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
866 | return udf_bitmap_new_block(sb, inode, | 913 | return udf_bitmap_new_block(sb, inode, |
867 | map->s_fspace.s_bitmap, | 914 | map->s_fspace.s_bitmap, |
868 | partition, goal, err); | 915 | partition, goal, err); |
869 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { | 916 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
870 | return udf_table_new_block(sb, inode, | 917 | return udf_table_new_block(sb, inode, |
871 | map->s_fspace.s_table, | 918 | map->s_fspace.s_table, |
872 | partition, goal, err); | 919 | partition, goal, err); |
873 | } else { | 920 | else { |
874 | *err = -EIO; | 921 | *err = -EIO; |
875 | return 0; | 922 | return 0; |
876 | } | 923 | } |
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/directory.c b/fs/udf/directory.c index ff8c08fd7bf5..ba79794abced 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,12 +71,12 @@ 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; |
@@ -86,7 +89,8 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
86 | (UDF_I_EFE(dir) ? | 89 | (UDF_I_EFE(dir) ? |
87 | sizeof(struct extendedFileEntry) : | 90 | sizeof(struct extendedFileEntry) : |
88 | sizeof(struct fileEntry)), | 91 | sizeof(struct fileEntry)), |
89 | dir->i_sb->s_blocksize, &(fibh->eoffset)); | 92 | dir->i_sb->s_blocksize, |
93 | &(fibh->eoffset)); | ||
90 | if (!fi) | 94 | if (!fi) |
91 | return NULL; | 95 | return NULL; |
92 | 96 | ||
@@ -100,6 +104,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
100 | 104 | ||
101 | if (fibh->eoffset == dir->i_sb->s_blocksize) { | 105 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
102 | int lextoffset = epos->offset; | 106 | int lextoffset = epos->offset; |
107 | unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits; | ||
103 | 108 | ||
104 | if (udf_next_aext(dir, epos, eloc, elen, 1) != | 109 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
105 | (EXT_RECORDED_ALLOCATED >> 30)) | 110 | (EXT_RECORDED_ALLOCATED >> 30)) |
@@ -109,24 +114,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
109 | 114 | ||
110 | (*offset)++; | 115 | (*offset)++; |
111 | 116 | ||
112 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) | 117 | if ((*offset << blocksize_bits) >= *elen) |
113 | *offset = 0; | 118 | *offset = 0; |
114 | else | 119 | else |
115 | epos->offset = lextoffset; | 120 | epos->offset = lextoffset; |
116 | 121 | ||
117 | brelse(fibh->sbh); | 122 | brelse(fibh->sbh); |
118 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) | 123 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
124 | if (!fibh->sbh) | ||
119 | return NULL; | 125 | return NULL; |
120 | fibh->soffset = fibh->eoffset = 0; | 126 | fibh->soffset = fibh->eoffset = 0; |
121 | 127 | ||
122 | if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { | 128 | if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) { |
123 | i = 16 >> (dir->i_sb->s_blocksize_bits - 9); | 129 | i = 16 >> (blocksize_bits - 9); |
124 | if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) | 130 | if (i + *offset > (*elen >> blocksize_bits)) |
125 | i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; | 131 | i = (*elen >> blocksize_bits)-*offset; |
126 | for (num = 0; i > 0; i--) { | 132 | for (num = 0; i > 0; i--) { |
127 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); | 133 | block = udf_get_lb_pblock(dir->i_sb, *eloc, |
134 | *offset + i); | ||
128 | tmp = udf_tgetblk(dir->i_sb, block); | 135 | tmp = udf_tgetblk(dir->i_sb, block); |
129 | if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) | 136 | if (tmp && !buffer_uptodate(tmp) && |
137 | !buffer_locked(tmp)) | ||
130 | bha[num++] = tmp; | 138 | bha[num++] = tmp; |
131 | else | 139 | else |
132 | brelse(tmp); | 140 | brelse(tmp); |
@@ -172,20 +180,24 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, | |||
172 | fibh->soffset -= dir->i_sb->s_blocksize; | 180 | fibh->soffset -= dir->i_sb->s_blocksize; |
173 | fibh->eoffset -= dir->i_sb->s_blocksize; | 181 | fibh->eoffset -= dir->i_sb->s_blocksize; |
174 | 182 | ||
175 | if (!(fibh->ebh = udf_tread(dir->i_sb, block))) | 183 | fibh->ebh = udf_tread(dir->i_sb, block); |
184 | if (!fibh->ebh) | ||
176 | return NULL; | 185 | return NULL; |
177 | 186 | ||
178 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { | 187 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
179 | int fi_len; | 188 | int fi_len; |
180 | 189 | ||
181 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); | 190 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); |
182 | memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, | 191 | memcpy((uint8_t *)cfi - fibh->soffset, |
192 | fibh->ebh->b_data, | ||
183 | sizeof(struct fileIdentDesc) + fibh->soffset); | 193 | sizeof(struct fileIdentDesc) + fibh->soffset); |
184 | 194 | ||
185 | fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + | 195 | fi_len = (sizeof(struct fileIdentDesc) + |
196 | cfi->lengthFileIdent + | ||
186 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; | 197 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; |
187 | 198 | ||
188 | *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); | 199 | *nf_pos += (fi_len - (fibh->eoffset - fibh->soffset)) |
200 | >> 2; | ||
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,9 +222,8 @@ 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 (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { |
218 | udf_debug("0x%x != TAG_IDENT_FID\n", | 229 | udf_debug("0x%x != TAG_IDENT_FID\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; |
@@ -258,11 +268,11 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) | |||
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 | ||
@@ -283,8 +293,11 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, | |||
283 | 293 | ||
284 | if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) | 294 | if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) |
285 | return NULL; | 295 | return NULL; |
286 | else if ((sa = (short_ad *)ptr)->extLength == 0) | 296 | else { |
287 | return NULL; | 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); |
@@ -302,8 +315,11 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) | |||
302 | 315 | ||
303 | if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) | 316 | if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) |
304 | return NULL; | 317 | return NULL; |
305 | else if ((la = (long_ad *)ptr)->extLength == 0) | 318 | else { |
306 | return NULL; | 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 3bd5068877fa..a984a8911167 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c | |||
@@ -59,7 +59,8 @@ static int udf_adinicb_readpage(struct file *file, struct page *page) | |||
59 | return 0; | 59 | return 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc) | 62 | static int udf_adinicb_writepage(struct page *page, |
63 | struct writeback_control *wbc) | ||
63 | { | 64 | { |
64 | struct inode *inode = page->mapping->host; | 65 | struct inode *inode = page->mapping->host; |
65 | char *kaddr; | 66 | char *kaddr; |
@@ -116,7 +117,8 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
116 | else | 117 | else |
117 | pos = ppos; | 118 | pos = ppos; |
118 | 119 | ||
119 | if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + | 120 | if (inode->i_sb->s_blocksize < |
121 | (udf_file_entry_alloc_offset(inode) + | ||
120 | pos + count)) { | 122 | pos + count)) { |
121 | udf_expand_file_adinicb(inode, pos + count, &err); | 123 | udf_expand_file_adinicb(inode, pos + count, &err); |
122 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 124 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { |
@@ -191,15 +193,19 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, | |||
191 | 193 | ||
192 | switch (cmd) { | 194 | switch (cmd) { |
193 | case UDF_GETVOLIDENT: | 195 | case UDF_GETVOLIDENT: |
194 | return copy_to_user((char __user *)arg, | 196 | if (copy_to_user((char __user *)arg, |
195 | UDF_SB(inode->i_sb)->s_volume_ident, 32) ? -EFAULT : 0; | 197 | UDF_SB(inode->i_sb)->s_volume_ident, 32)) |
198 | return -EFAULT; | ||
199 | else | ||
200 | return 0; | ||
196 | case UDF_RELOCATE_BLOCKS: | 201 | case UDF_RELOCATE_BLOCKS: |
197 | if (!capable(CAP_SYS_ADMIN)) | 202 | if (!capable(CAP_SYS_ADMIN)) |
198 | return -EACCES; | 203 | return -EACCES; |
199 | if (get_user(old_block, (long __user *)arg)) | 204 | if (get_user(old_block, (long __user *)arg)) |
200 | return -EFAULT; | 205 | return -EFAULT; |
201 | if ((result = udf_relocate_blocks(inode->i_sb, | 206 | result = udf_relocate_blocks(inode->i_sb, |
202 | old_block, &new_block)) == 0) | 207 | old_block, &new_block); |
208 | if (result == 0) | ||
203 | result = put_user(new_block, (long __user *)arg); | 209 | result = put_user(new_block, (long __user *)arg); |
204 | return result; | 210 | return result; |
205 | case UDF_GETEASIZE: | 211 | case UDF_GETEASIZE: |
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c index 8145e943be61..7697b489a292 100644 --- a/fs/udf/ialloc.c +++ b/fs/udf/ialloc.c | |||
@@ -82,7 +82,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
82 | UDF_I_NEXT_ALLOC_GOAL(inode) = 0; | 82 | UDF_I_NEXT_ALLOC_GOAL(inode) = 0; |
83 | UDF_I_STRAT4096(inode) = 0; | 83 | UDF_I_STRAT4096(inode) = 0; |
84 | 84 | ||
85 | block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, | 85 | block = udf_new_block(dir->i_sb, NULL, |
86 | UDF_I_LOCATION(dir).partitionReferenceNum, | ||
86 | start, err); | 87 | start, err); |
87 | if (*err) { | 88 | if (*err) { |
88 | iput(inode); | 89 | iput(inode); |
@@ -91,11 +92,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
91 | 92 | ||
92 | mutex_lock(&sbi->s_alloc_mutex); | 93 | mutex_lock(&sbi->s_alloc_mutex); |
93 | if (sbi->s_lvid_bh) { | 94 | if (sbi->s_lvid_bh) { |
94 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | 95 | struct logicalVolIntegrityDesc *lvid = |
95 | struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); | 96 | (struct logicalVolIntegrityDesc *) |
97 | sbi->s_lvid_bh->b_data; | ||
98 | struct logicalVolIntegrityDescImpUse *lvidiu = | ||
99 | udf_sb_lvidiu(sbi); | ||
96 | struct logicalVolHeaderDesc *lvhd; | 100 | struct logicalVolHeaderDesc *lvhd; |
97 | uint64_t uniqueID; | 101 | uint64_t uniqueID; |
98 | lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); | 102 | lvhd = (struct logicalVolHeaderDesc *) |
103 | (lvid->logicalVolContentsUse); | ||
99 | if (S_ISDIR(mode)) | 104 | if (S_ISDIR(mode)) |
100 | lvidiu->numDirs = | 105 | lvidiu->numDirs = |
101 | cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1); | 106 | cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1); |
@@ -119,7 +124,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
119 | } | 124 | } |
120 | 125 | ||
121 | UDF_I_LOCATION(inode).logicalBlockNum = block; | 126 | UDF_I_LOCATION(inode).logicalBlockNum = block; |
122 | UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; | 127 | UDF_I_LOCATION(inode).partitionReferenceNum = |
128 | UDF_I_LOCATION(dir).partitionReferenceNum; | ||
123 | inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); | 129 | inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); |
124 | inode->i_blocks = 0; | 130 | inode->i_blocks = 0; |
125 | UDF_I_LENEATTR(inode) = 0; | 131 | UDF_I_LENEATTR(inode) = 0; |
@@ -129,10 +135,14 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) | |||
129 | UDF_I_EFE(inode) = 1; | 135 | UDF_I_EFE(inode) = 1; |
130 | if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) | 136 | if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) |
131 | sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; | 137 | sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; |
132 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); | 138 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - |
139 | sizeof(struct extendedFileEntry), | ||
140 | GFP_KERNEL); | ||
133 | } else { | 141 | } else { |
134 | UDF_I_EFE(inode) = 0; | 142 | UDF_I_EFE(inode) = 0; |
135 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); | 143 | UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - |
144 | sizeof(struct fileEntry), | ||
145 | GFP_KERNEL); | ||
136 | } | 146 | } |
137 | if (!UDF_I_DATA(inode)) { | 147 | if (!UDF_I_DATA(inode)) { |
138 | iput(inode); | 148 | iput(inode); |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 2eb1220e4236..3ce2f6d1aafa 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 |
@@ -237,7 +238,8 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
237 | if (!(*block)) | 238 | if (!(*block)) |
238 | return NULL; | 239 | return NULL; |
239 | newblock = udf_get_pblock(inode->i_sb, *block, | 240 | newblock = udf_get_pblock(inode->i_sb, *block, |
240 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); | 241 | UDF_I_LOCATION(inode).partitionReferenceNum, |
242 | 0); | ||
241 | if (!newblock) | 243 | if (!newblock) |
242 | return NULL; | 244 | return NULL; |
243 | dbh = udf_tgetblk(inode->i_sb, newblock); | 245 | dbh = udf_tgetblk(inode->i_sb, newblock); |
@@ -249,13 +251,15 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
249 | unlock_buffer(dbh); | 251 | unlock_buffer(dbh); |
250 | mark_buffer_dirty_inode(dbh, inode); | 252 | mark_buffer_dirty_inode(dbh, inode); |
251 | 253 | ||
252 | sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; | 254 | sfibh.soffset = sfibh.eoffset = |
255 | (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; | ||
253 | sfibh.sbh = sfibh.ebh = NULL; | 256 | sfibh.sbh = sfibh.ebh = NULL; |
254 | dfibh.soffset = dfibh.eoffset = 0; | 257 | dfibh.soffset = dfibh.eoffset = 0; |
255 | dfibh.sbh = dfibh.ebh = dbh; | 258 | dfibh.sbh = dfibh.ebh = dbh; |
256 | while ((f_pos < size)) { | 259 | while ((f_pos < size)) { |
257 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 260 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; |
258 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); | 261 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, |
262 | NULL, NULL, NULL); | ||
259 | if (!sfi) { | 263 | if (!sfi) { |
260 | brelse(dbh); | 264 | brelse(dbh); |
261 | return NULL; | 265 | return NULL; |
@@ -266,7 +270,8 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
266 | dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); | 270 | dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); |
267 | dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); | 271 | dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); |
268 | if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, | 272 | if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, |
269 | sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) { | 273 | sfi->fileIdent + |
274 | le16_to_cpu(sfi->lengthOfImpUse))) { | ||
270 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 275 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; |
271 | brelse(dbh); | 276 | brelse(dbh); |
272 | return NULL; | 277 | return NULL; |
@@ -274,10 +279,12 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block, | |||
274 | } | 279 | } |
275 | mark_buffer_dirty_inode(dbh, inode); | 280 | mark_buffer_dirty_inode(dbh, inode); |
276 | 281 | ||
277 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); | 282 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, |
283 | UDF_I_LENALLOC(inode)); | ||
278 | UDF_I_LENALLOC(inode) = 0; | 284 | UDF_I_LENALLOC(inode) = 0; |
279 | eloc.logicalBlockNum = *block; | 285 | eloc.logicalBlockNum = *block; |
280 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 286 | eloc.partitionReferenceNum = |
287 | UDF_I_LOCATION(inode).partitionReferenceNum; | ||
281 | elen = inode->i_size; | 288 | elen = inode->i_size; |
282 | UDF_I_LENEXTENTS(inode) = elen; | 289 | UDF_I_LENEXTENTS(inode) = elen; |
283 | epos.bh = NULL; | 290 | epos.bh = NULL; |
@@ -366,7 +373,7 @@ static struct buffer_head *udf_getblk(struct inode *inode, long block, | |||
366 | 373 | ||
367 | /* Extend the file by 'blocks' blocks, return the number of extents added */ | 374 | /* 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, | 375 | int udf_extend_file(struct inode *inode, struct extent_position *last_pos, |
369 | kernel_long_ad * last_ext, sector_t blocks) | 376 | kernel_long_ad *last_ext, sector_t blocks) |
370 | { | 377 | { |
371 | sector_t add; | 378 | sector_t add; |
372 | int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | 379 | int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); |
@@ -391,7 +398,8 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
391 | } | 398 | } |
392 | 399 | ||
393 | /* Last extent are just preallocated blocks? */ | 400 | /* Last extent are just preallocated blocks? */ |
394 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { | 401 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == |
402 | EXT_NOT_RECORDED_ALLOCATED) { | ||
395 | /* Save the extent so that we can reattach it to the end */ | 403 | /* Save the extent so that we can reattach it to the end */ |
396 | prealloc_loc = last_ext->extLocation; | 404 | prealloc_loc = last_ext->extLocation; |
397 | prealloc_len = last_ext->extLength; | 405 | prealloc_len = last_ext->extLength; |
@@ -399,13 +407,15 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
399 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 407 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
400 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | 408 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); |
401 | last_ext->extLocation.logicalBlockNum = 0; | 409 | last_ext->extLocation.logicalBlockNum = 0; |
402 | last_ext->extLocation.partitionReferenceNum = 0; | 410 | last_ext->extLocation.partitionReferenceNum = 0; |
403 | } | 411 | } |
404 | 412 | ||
405 | /* Can we merge with the previous extent? */ | 413 | /* Can we merge with the previous extent? */ |
406 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { | 414 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == |
407 | add = ((1 << 30) - sb->s_blocksize - (last_ext->extLength & | 415 | EXT_NOT_RECORDED_NOT_ALLOCATED) { |
408 | UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; | 416 | add = ((1 << 30) - sb->s_blocksize - |
417 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> | ||
418 | sb->s_blocksize_bits; | ||
409 | if (add > blocks) | 419 | if (add > blocks) |
410 | add = blocks; | 420 | add = blocks; |
411 | blocks -= add; | 421 | blocks -= add; |
@@ -416,9 +426,9 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
416 | udf_add_aext(inode, last_pos, last_ext->extLocation, | 426 | udf_add_aext(inode, last_pos, last_ext->extLocation, |
417 | last_ext->extLength, 1); | 427 | last_ext->extLength, 1); |
418 | count++; | 428 | count++; |
419 | } else { | 429 | } else |
420 | udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); | 430 | udf_write_aext(inode, last_pos, last_ext->extLocation, |
421 | } | 431 | last_ext->extLength, 1); |
422 | 432 | ||
423 | /* Managed to do everything necessary? */ | 433 | /* Managed to do everything necessary? */ |
424 | if (!blocks) | 434 | if (!blocks) |
@@ -426,9 +436,10 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
426 | 436 | ||
427 | /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ | 437 | /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ |
428 | last_ext->extLocation.logicalBlockNum = 0; | 438 | last_ext->extLocation.logicalBlockNum = 0; |
429 | last_ext->extLocation.partitionReferenceNum = 0; | 439 | last_ext->extLocation.partitionReferenceNum = 0; |
430 | add = (1 << (30-sb->s_blocksize_bits)) - 1; | 440 | add = (1 << (30-sb->s_blocksize_bits)) - 1; |
431 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); | 441 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
442 | (add << sb->s_blocksize_bits); | ||
432 | 443 | ||
433 | /* Create enough extents to cover the whole hole */ | 444 | /* Create enough extents to cover the whole hole */ |
434 | while (blocks > add) { | 445 | while (blocks > add) { |
@@ -450,7 +461,8 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | |||
450 | out: | 461 | out: |
451 | /* Do we have some preallocated blocks saved? */ | 462 | /* Do we have some preallocated blocks saved? */ |
452 | if (prealloc_len) { | 463 | if (prealloc_len) { |
453 | if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1) | 464 | if (udf_add_aext(inode, last_pos, prealloc_loc, |
465 | prealloc_len, 1) == -1) | ||
454 | return -1; | 466 | return -1; |
455 | last_ext->extLocation = prealloc_loc; | 467 | last_ext->extLocation = prealloc_loc; |
456 | last_ext->extLength = prealloc_len; | 468 | last_ext->extLength = prealloc_len; |
@@ -515,7 +527,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
515 | prev_epos.offset = cur_epos.offset; | 527 | prev_epos.offset = cur_epos.offset; |
516 | cur_epos.offset = next_epos.offset; | 528 | cur_epos.offset = next_epos.offset; |
517 | 529 | ||
518 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1) | 530 | etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1); |
531 | if (etype == -1) | ||
519 | break; | 532 | break; |
520 | 533 | ||
521 | c = !c; | 534 | c = !c; |
@@ -569,9 +582,11 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
569 | startnum = 1; | 582 | startnum = 1; |
570 | } else { | 583 | } else { |
571 | /* Create a fake extent when there's not one */ | 584 | /* Create a fake extent when there's not one */ |
572 | memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); | 585 | memset(&laarr[0].extLocation, 0x00, |
586 | sizeof(kernel_lb_addr)); | ||
573 | laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; | 587 | laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; |
574 | /* Will udf_extend_file() create real extent from a fake one? */ | 588 | /* Will udf_extend_file() create real extent from |
589 | a fake one? */ | ||
575 | startnum = (offset > 0); | 590 | startnum = (offset > 0); |
576 | } | 591 | } |
577 | /* Create extents for the hole between EOF and offset */ | 592 | /* Create extents for the hole between EOF and offset */ |
@@ -589,14 +604,16 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
589 | offset = 0; | 604 | offset = 0; |
590 | count += ret; | 605 | count += ret; |
591 | /* We are not covered by a preallocated extent? */ | 606 | /* We are not covered by a preallocated extent? */ |
592 | if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) { | 607 | if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != |
608 | EXT_NOT_RECORDED_ALLOCATED) { | ||
593 | /* Is there any real extent? - otherwise we overwrite | 609 | /* Is there any real extent? - otherwise we overwrite |
594 | * the fake one... */ | 610 | * the fake one... */ |
595 | if (count) | 611 | if (count) |
596 | c = !c; | 612 | c = !c; |
597 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 613 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | |
598 | inode->i_sb->s_blocksize; | 614 | inode->i_sb->s_blocksize; |
599 | memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); | 615 | memset(&laarr[c].extLocation, 0x00, |
616 | sizeof(kernel_lb_addr)); | ||
600 | count++; | 617 | count++; |
601 | endnum++; | 618 | endnum++; |
602 | } | 619 | } |
@@ -605,7 +622,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
605 | } else { | 622 | } else { |
606 | endnum = startnum = ((count > 2) ? 2 : count); | 623 | endnum = startnum = ((count > 2) ? 2 : count); |
607 | 624 | ||
608 | /* if the current extent is in position 0, swap it with the previous */ | 625 | /* if the current extent is in position 0, |
626 | swap it with the previous */ | ||
609 | if (!c && count != 1) { | 627 | if (!c && count != 1) { |
610 | laarr[2] = laarr[0]; | 628 | laarr[2] = laarr[0]; |
611 | laarr[0] = laarr[1]; | 629 | laarr[0] = laarr[1]; |
@@ -613,34 +631,36 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
613 | c = 1; | 631 | c = 1; |
614 | } | 632 | } |
615 | 633 | ||
616 | /* if the current block is located in an extent, read the next extent */ | 634 | /* if the current block is located in an extent, |
617 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) { | 635 | read the next extent */ |
636 | etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0); | ||
637 | if (etype != -1) { | ||
618 | laarr[c + 1].extLength = (etype << 30) | elen; | 638 | laarr[c + 1].extLength = (etype << 30) | elen; |
619 | laarr[c + 1].extLocation = eloc; | 639 | laarr[c + 1].extLocation = eloc; |
620 | count++; | 640 | count++; |
621 | startnum++; | 641 | startnum++; |
622 | endnum++; | 642 | endnum++; |
623 | } else { | 643 | } else |
624 | lastblock = 1; | 644 | lastblock = 1; |
625 | } | ||
626 | } | 645 | } |
627 | 646 | ||
628 | /* if the current extent is not recorded but allocated, get the | 647 | /* if the current extent is not recorded but allocated, get the |
629 | * block in the extent corresponding to the requested block */ | 648 | * block in the extent corresponding to the requested block */ |
630 | if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 649 | if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) |
631 | newblocknum = laarr[c].extLocation.logicalBlockNum + offset; | 650 | newblocknum = laarr[c].extLocation.logicalBlockNum + offset; |
632 | } else { /* otherwise, allocate a new block */ | 651 | else { /* otherwise, allocate a new block */ |
633 | if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) | 652 | if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) |
634 | goal = UDF_I_NEXT_ALLOC_GOAL(inode); | 653 | goal = UDF_I_NEXT_ALLOC_GOAL(inode); |
635 | 654 | ||
636 | if (!goal) { | 655 | if (!goal) { |
637 | if (!(goal = pgoal)) | 656 | if (!(goal = pgoal)) /* XXX: what was intended here? */ |
638 | goal = UDF_I_LOCATION(inode).logicalBlockNum + 1; | 657 | goal = UDF_I_LOCATION(inode).logicalBlockNum+1; |
639 | } | 658 | } |
640 | 659 | ||
641 | if (!(newblocknum = udf_new_block(inode->i_sb, inode, | 660 | newblocknum = udf_new_block(inode->i_sb, inode, |
642 | UDF_I_LOCATION(inode).partitionReferenceNum, | 661 | UDF_I_LOCATION(inode).partitionReferenceNum, |
643 | goal, err))) { | 662 | goal, err); |
663 | if (!newblocknum) { | ||
644 | brelse(prev_epos.bh); | 664 | brelse(prev_epos.bh); |
645 | *err = -ENOSPC; | 665 | *err = -ENOSPC; |
646 | return NULL; | 666 | return NULL; |
@@ -648,9 +668,10 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
648 | UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize; | 668 | UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize; |
649 | } | 669 | } |
650 | 670 | ||
651 | /* if the extent the requsted block is located in contains multiple blocks, | 671 | /* if the extent the requsted block is located in contains multiple |
652 | * split the extent into at most three extents. blocks prior to requested | 672 | * blocks, split the extent into at most three extents. blocks prior |
653 | * block, requested block, and blocks after requested block */ | 673 | * to requested block, requested block, and blocks after requested |
674 | * block */ | ||
654 | udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); | 675 | udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); |
655 | 676 | ||
656 | #ifdef UDF_PREALLOCATE | 677 | #ifdef UDF_PREALLOCATE |
@@ -668,10 +689,10 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block, | |||
668 | 689 | ||
669 | brelse(prev_epos.bh); | 690 | brelse(prev_epos.bh); |
670 | 691 | ||
671 | if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, | 692 | newblock = udf_get_pblock(inode->i_sb, newblocknum, |
672 | UDF_I_LOCATION(inode).partitionReferenceNum, 0))) { | 693 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); |
694 | if (!newblock) | ||
673 | return NULL; | 695 | return NULL; |
674 | } | ||
675 | *phys = newblock; | 696 | *phys = newblock; |
676 | *err = 0; | 697 | *err = 0; |
677 | *new = 1; | 698 | *new = 1; |
@@ -692,16 +713,20 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
692 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], | 713 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], |
693 | int *endnum) | 714 | int *endnum) |
694 | { | 715 | { |
716 | unsigned long blocksize = inode->i_sb->s_blocksize; | ||
717 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
718 | |||
695 | if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || | 719 | if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || |
696 | (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | 720 | (laarr[*c].extLength >> 30) == |
721 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | ||
697 | int curr = *c; | 722 | int curr = *c; |
698 | int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + | 723 | int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + |
699 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; | 724 | blocksize - 1) >> blocksize_bits; |
700 | int8_t etype = (laarr[curr].extLength >> 30); | 725 | int8_t etype = (laarr[curr].extLength >> 30); |
701 | 726 | ||
702 | if (blen == 1) { | 727 | if (blen == 1) |
703 | ; | 728 | ; |
704 | } else if (!offset || blen == offset + 1) { | 729 | else if (!offset || blen == offset + 1) { |
705 | laarr[curr + 2] = laarr[curr + 1]; | 730 | laarr[curr + 2] = laarr[curr + 1]; |
706 | laarr[curr + 1] = laarr[curr]; | 731 | laarr[curr + 1] = laarr[curr]; |
707 | } else { | 732 | } else { |
@@ -711,15 +736,18 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
711 | 736 | ||
712 | if (offset) { | 737 | if (offset) { |
713 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 738 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
714 | udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); | 739 | udf_free_blocks(inode->i_sb, inode, |
715 | laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 740 | laarr[curr].extLocation, |
716 | (offset << inode->i_sb->s_blocksize_bits); | 741 | 0, offset); |
742 | laarr[curr].extLength = | ||
743 | EXT_NOT_RECORDED_NOT_ALLOCATED | | ||
744 | (offset << blocksize_bits); | ||
717 | laarr[curr].extLocation.logicalBlockNum = 0; | 745 | laarr[curr].extLocation.logicalBlockNum = 0; |
718 | laarr[curr].extLocation.partitionReferenceNum = 0; | 746 | laarr[curr].extLocation. |
719 | } else { | 747 | partitionReferenceNum = 0; |
748 | } else | ||
720 | laarr[curr].extLength = (etype << 30) | | 749 | laarr[curr].extLength = (etype << 30) | |
721 | (offset << inode->i_sb->s_blocksize_bits); | 750 | (offset << blocksize_bits); |
722 | } | ||
723 | curr++; | 751 | curr++; |
724 | (*c)++; | 752 | (*c)++; |
725 | (*endnum)++; | 753 | (*endnum)++; |
@@ -730,14 +758,15 @@ static void udf_split_extents(struct inode *inode, int *c, int offset, | |||
730 | laarr[curr].extLocation.partitionReferenceNum = | 758 | laarr[curr].extLocation.partitionReferenceNum = |
731 | UDF_I_LOCATION(inode).partitionReferenceNum; | 759 | UDF_I_LOCATION(inode).partitionReferenceNum; |
732 | laarr[curr].extLength = EXT_RECORDED_ALLOCATED | | 760 | laarr[curr].extLength = EXT_RECORDED_ALLOCATED | |
733 | inode->i_sb->s_blocksize; | 761 | blocksize; |
734 | curr++; | 762 | curr++; |
735 | 763 | ||
736 | if (blen != offset + 1) { | 764 | if (blen != offset + 1) { |
737 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) | 765 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) |
738 | laarr[curr].extLocation.logicalBlockNum += (offset + 1); | 766 | laarr[curr].extLocation.logicalBlockNum += |
767 | offset + 1; | ||
739 | laarr[curr].extLength = (etype << 30) | | 768 | laarr[curr].extLength = (etype << 30) | |
740 | ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); | 769 | ((blen - (offset + 1)) << blocksize_bits); |
741 | curr++; | 770 | curr++; |
742 | (*endnum)++; | 771 | (*endnum)++; |
743 | } | 772 | } |
@@ -756,69 +785,86 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock, | |||
756 | else | 785 | else |
757 | start = c; | 786 | start = c; |
758 | } else { | 787 | } else { |
759 | if ((laarr[c + 1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 788 | if ((laarr[c + 1].extLength >> 30) == |
789 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | ||
760 | start = c + 1; | 790 | start = c + 1; |
761 | length = currlength = (((laarr[c + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 791 | length = currlength = |
762 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 792 | (((laarr[c + 1].extLength & |
763 | } else { | 793 | UDF_EXTENT_LENGTH_MASK) + |
794 | inode->i_sb->s_blocksize - 1) >> | ||
795 | inode->i_sb->s_blocksize_bits); | ||
796 | } else | ||
764 | start = c; | 797 | start = c; |
765 | } | ||
766 | } | 798 | } |
767 | 799 | ||
768 | for (i = start + 1; i <= *endnum; i++) { | 800 | for (i = start + 1; i <= *endnum; i++) { |
769 | if (i == *endnum) { | 801 | if (i == *endnum) { |
770 | if (lastblock) | 802 | if (lastblock) |
771 | length += UDF_DEFAULT_PREALLOC_BLOCKS; | 803 | length += UDF_DEFAULT_PREALLOC_BLOCKS; |
772 | } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { | 804 | } else if ((laarr[i].extLength >> 30) == |
773 | length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 805 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) { |
774 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 806 | length += (((laarr[i].extLength & |
775 | } else { | 807 | UDF_EXTENT_LENGTH_MASK) + |
808 | inode->i_sb->s_blocksize - 1) >> | ||
809 | inode->i_sb->s_blocksize_bits); | ||
810 | } else | ||
776 | break; | 811 | break; |
777 | } | ||
778 | } | 812 | } |
779 | 813 | ||
780 | if (length) { | 814 | if (length) { |
781 | int next = laarr[start].extLocation.logicalBlockNum + | 815 | int next = laarr[start].extLocation.logicalBlockNum + |
782 | (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + | 816 | (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + |
783 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 817 | inode->i_sb->s_blocksize - 1) >> |
818 | inode->i_sb->s_blocksize_bits); | ||
784 | int numalloc = udf_prealloc_blocks(inode->i_sb, inode, | 819 | int numalloc = udf_prealloc_blocks(inode->i_sb, inode, |
785 | laarr[start].extLocation.partitionReferenceNum, | 820 | laarr[start].extLocation.partitionReferenceNum, |
786 | next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length : | 821 | next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? |
787 | UDF_DEFAULT_PREALLOC_BLOCKS) - currlength); | 822 | length : UDF_DEFAULT_PREALLOC_BLOCKS) - |
823 | currlength); | ||
788 | if (numalloc) { | 824 | if (numalloc) { |
789 | if (start == (c + 1)) { | 825 | if (start == (c + 1)) |
790 | laarr[start].extLength += | 826 | laarr[start].extLength += |
791 | (numalloc << inode->i_sb->s_blocksize_bits); | 827 | (numalloc << |
792 | } else { | 828 | inode->i_sb->s_blocksize_bits); |
829 | else { | ||
793 | memmove(&laarr[c + 2], &laarr[c + 1], | 830 | memmove(&laarr[c + 2], &laarr[c + 1], |
794 | sizeof(long_ad) * (*endnum - (c + 1))); | 831 | sizeof(long_ad) * (*endnum - (c + 1))); |
795 | (*endnum)++; | 832 | (*endnum)++; |
796 | laarr[c + 1].extLocation.logicalBlockNum = next; | 833 | laarr[c + 1].extLocation.logicalBlockNum = next; |
797 | laarr[c + 1].extLocation.partitionReferenceNum = | 834 | laarr[c + 1].extLocation.partitionReferenceNum = |
798 | laarr[c].extLocation.partitionReferenceNum; | 835 | laarr[c].extLocation. |
799 | laarr[c + 1].extLength = EXT_NOT_RECORDED_ALLOCATED | | 836 | partitionReferenceNum; |
800 | (numalloc << inode->i_sb->s_blocksize_bits); | 837 | laarr[c + 1].extLength = |
838 | EXT_NOT_RECORDED_ALLOCATED | | ||
839 | (numalloc << | ||
840 | inode->i_sb->s_blocksize_bits); | ||
801 | start = c + 1; | 841 | start = c + 1; |
802 | } | 842 | } |
803 | 843 | ||
804 | for (i = start + 1; numalloc && i < *endnum; i++) { | 844 | for (i = start + 1; numalloc && i < *endnum; i++) { |
805 | int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 845 | int elen = ((laarr[i].extLength & |
806 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; | 846 | UDF_EXTENT_LENGTH_MASK) + |
847 | inode->i_sb->s_blocksize - 1) >> | ||
848 | inode->i_sb->s_blocksize_bits; | ||
807 | 849 | ||
808 | if (elen > numalloc) { | 850 | if (elen > numalloc) { |
809 | laarr[i].extLength -= | 851 | laarr[i].extLength -= |
810 | (numalloc << inode->i_sb->s_blocksize_bits); | 852 | (numalloc << |
853 | inode->i_sb->s_blocksize_bits); | ||
811 | numalloc = 0; | 854 | numalloc = 0; |
812 | } else { | 855 | } else { |
813 | numalloc -= elen; | 856 | numalloc -= elen; |
814 | if (*endnum > (i + 1)) | 857 | if (*endnum > (i + 1)) |
815 | memmove(&laarr[i], &laarr[i + 1], | 858 | memmove(&laarr[i], |
816 | sizeof(long_ad) * (*endnum - (i + 1))); | 859 | &laarr[i + 1], |
860 | sizeof(long_ad) * | ||
861 | (*endnum - (i + 1))); | ||
817 | i--; | 862 | i--; |
818 | (*endnum)--; | 863 | (*endnum)--; |
819 | } | 864 | } |
820 | } | 865 | } |
821 | UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits; | 866 | UDF_I_LENEXTENTS(inode) += |
867 | numalloc << inode->i_sb->s_blocksize_bits; | ||
822 | } | 868 | } |
823 | } | 869 | } |
824 | } | 870 | } |
@@ -828,70 +874,97 @@ static void udf_merge_extents(struct inode *inode, | |||
828 | int *endnum) | 874 | int *endnum) |
829 | { | 875 | { |
830 | int i; | 876 | int i; |
877 | unsigned long blocksize = inode->i_sb->s_blocksize; | ||
878 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
831 | 879 | ||
832 | for (i = 0; i < (*endnum - 1); i++) { | 880 | for (i = 0; i < (*endnum - 1); i++) { |
833 | if ((laarr[i].extLength >> 30) == (laarr[i + 1].extLength >> 30)) { | 881 | kernel_long_ad *li /*l[i]*/ = &laarr[i]; |
834 | if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || | 882 | kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1]; |
835 | ((laarr[i + 1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) == | 883 | |
836 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 884 | if (((li->extLength >> 30) == (lip1->extLength >> 30)) && |
837 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) { | 885 | (((li->extLength >> 30) == |
838 | if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 886 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || |
839 | (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 887 | ((lip1->extLocation.logicalBlockNum - |
840 | inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { | 888 | li->extLocation.logicalBlockNum) == |
841 | laarr[i + 1].extLength = (laarr[i + 1].extLength - | 889 | (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
842 | (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 890 | blocksize - 1) >> blocksize_bits)))) { |
843 | UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1); | 891 | |
844 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + | 892 | if (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
845 | (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; | 893 | (lip1->extLength & UDF_EXTENT_LENGTH_MASK) + |
846 | laarr[i + 1].extLocation.logicalBlockNum = | 894 | blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { |
847 | laarr[i].extLocation.logicalBlockNum + | 895 | lip1->extLength = (lip1->extLength - |
848 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >> | 896 | (li->extLength & |
849 | inode->i_sb->s_blocksize_bits); | 897 | UDF_EXTENT_LENGTH_MASK) + |
850 | } else { | 898 | UDF_EXTENT_LENGTH_MASK) & |
851 | laarr[i].extLength = laarr[i + 1].extLength + | 899 | ~(blocksize - 1); |
852 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 900 | li->extLength = (li->extLength & |
853 | inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1)); | 901 | UDF_EXTENT_FLAG_MASK) + |
854 | if (*endnum > (i + 2)) | 902 | (UDF_EXTENT_LENGTH_MASK + 1) - |
855 | memmove(&laarr[i + 1], &laarr[i + 2], | 903 | blocksize; |
856 | sizeof(long_ad) * (*endnum - (i + 2))); | 904 | lip1->extLocation.logicalBlockNum = |
857 | i--; | 905 | li->extLocation.logicalBlockNum + |
858 | (*endnum)--; | 906 | ((li->extLength & |
859 | } | 907 | UDF_EXTENT_LENGTH_MASK) >> |
908 | blocksize_bits); | ||
909 | } else { | ||
910 | li->extLength = lip1->extLength + | ||
911 | (((li->extLength & | ||
912 | UDF_EXTENT_LENGTH_MASK) + | ||
913 | blocksize - 1) & ~(blocksize - 1)); | ||
914 | if (*endnum > (i + 2)) | ||
915 | memmove(&laarr[i + 1], &laarr[i + 2], | ||
916 | sizeof(long_ad) * | ||
917 | (*endnum - (i + 2))); | ||
918 | i--; | ||
919 | (*endnum)--; | ||
860 | } | 920 | } |
861 | } else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) && | 921 | } else if (((li->extLength >> 30) == |
862 | ((laarr[i + 1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) { | 922 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) && |
863 | udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, | 923 | ((lip1->extLength >> 30) == |
864 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 924 | (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) { |
865 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 925 | udf_free_blocks(inode->i_sb, inode, li->extLocation, 0, |
866 | laarr[i].extLocation.logicalBlockNum = 0; | 926 | ((li->extLength & |
867 | laarr[i].extLocation.partitionReferenceNum = 0; | 927 | UDF_EXTENT_LENGTH_MASK) + |
868 | 928 | blocksize - 1) >> blocksize_bits); | |
869 | if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 929 | li->extLocation.logicalBlockNum = 0; |
870 | (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) + | 930 | li->extLocation.partitionReferenceNum = 0; |
871 | inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { | 931 | |
872 | laarr[i + 1].extLength = (laarr[i + 1].extLength - | 932 | if (((li->extLength & UDF_EXTENT_LENGTH_MASK) + |
873 | (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 933 | (lip1->extLength & UDF_EXTENT_LENGTH_MASK) + |
874 | UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1); | 934 | blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) { |
875 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + | 935 | lip1->extLength = (lip1->extLength - |
876 | (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; | 936 | (li->extLength & |
937 | UDF_EXTENT_LENGTH_MASK) + | ||
938 | UDF_EXTENT_LENGTH_MASK) & | ||
939 | ~(blocksize - 1); | ||
940 | li->extLength = (li->extLength & | ||
941 | UDF_EXTENT_FLAG_MASK) + | ||
942 | (UDF_EXTENT_LENGTH_MASK + 1) - | ||
943 | blocksize; | ||
877 | } else { | 944 | } else { |
878 | laarr[i].extLength = laarr[i + 1].extLength + | 945 | li->extLength = lip1->extLength + |
879 | (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 946 | (((li->extLength & |
880 | inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1)); | 947 | UDF_EXTENT_LENGTH_MASK) + |
948 | blocksize - 1) & ~(blocksize - 1)); | ||
881 | if (*endnum > (i + 2)) | 949 | if (*endnum > (i + 2)) |
882 | memmove(&laarr[i + 1], &laarr[i + 2], | 950 | memmove(&laarr[i + 1], &laarr[i + 2], |
883 | sizeof(long_ad) * (*endnum - (i + 2))); | 951 | sizeof(long_ad) * |
952 | (*endnum - (i + 2))); | ||
884 | i--; | 953 | i--; |
885 | (*endnum)--; | 954 | (*endnum)--; |
886 | } | 955 | } |
887 | } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { | 956 | } else if ((li->extLength >> 30) == |
888 | udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, | 957 | (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
889 | ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + | 958 | udf_free_blocks(inode->i_sb, inode, |
890 | inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); | 959 | li->extLocation, 0, |
891 | laarr[i].extLocation.logicalBlockNum = 0; | 960 | ((li->extLength & |
892 | laarr[i].extLocation.partitionReferenceNum = 0; | 961 | UDF_EXTENT_LENGTH_MASK) + |
893 | laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) | | 962 | blocksize - 1) >> blocksize_bits); |
894 | EXT_NOT_RECORDED_NOT_ALLOCATED; | 963 | li->extLocation.logicalBlockNum = 0; |
964 | li->extLocation.partitionReferenceNum = 0; | ||
965 | li->extLength = (li->extLength & | ||
966 | UDF_EXTENT_LENGTH_MASK) | | ||
967 | EXT_NOT_RECORDED_NOT_ALLOCATED; | ||
895 | } | 968 | } |
896 | } | 969 | } |
897 | } | 970 | } |
@@ -962,24 +1035,26 @@ void udf_truncate(struct inode *inode) | |||
962 | 1035 | ||
963 | lock_kernel(); | 1036 | lock_kernel(); |
964 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1037 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { |
965 | if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + | 1038 | if (inode->i_sb->s_blocksize < |
966 | inode->i_size)) { | 1039 | (udf_file_entry_alloc_offset(inode) + |
1040 | inode->i_size)) { | ||
967 | udf_expand_file_adinicb(inode, inode->i_size, &err); | 1041 | udf_expand_file_adinicb(inode, inode->i_size, &err); |
968 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1042 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { |
969 | inode->i_size = UDF_I_LENALLOC(inode); | 1043 | inode->i_size = UDF_I_LENALLOC(inode); |
970 | unlock_kernel(); | 1044 | unlock_kernel(); |
971 | return; | 1045 | return; |
972 | } else { | 1046 | } else |
973 | udf_truncate_extents(inode); | 1047 | udf_truncate_extents(inode); |
974 | } | ||
975 | } else { | 1048 | } else { |
976 | offset = inode->i_size & (inode->i_sb->s_blocksize - 1); | 1049 | offset = inode->i_size & (inode->i_sb->s_blocksize - 1); |
977 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, | 1050 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + |
978 | inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode)); | 1051 | offset, 0x00, inode->i_sb->s_blocksize - |
1052 | offset - udf_file_entry_alloc_offset(inode)); | ||
979 | UDF_I_LENALLOC(inode) = inode->i_size; | 1053 | UDF_I_LENALLOC(inode) = inode->i_size; |
980 | } | 1054 | } |
981 | } else { | 1055 | } else { |
982 | block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block); | 1056 | block_truncate_page(inode->i_mapping, inode->i_size, |
1057 | udf_get_block); | ||
983 | udf_truncate_extents(inode); | 1058 | udf_truncate_extents(inode); |
984 | } | 1059 | } |
985 | 1060 | ||
@@ -1019,8 +1094,8 @@ static void __udf_read_inode(struct inode *inode) | |||
1019 | 1094 | ||
1020 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && | 1095 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && |
1021 | ident != TAG_IDENT_USE) { | 1096 | ident != TAG_IDENT_USE) { |
1022 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", | 1097 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) " |
1023 | inode->i_ino, ident); | 1098 | "failed ident=%d\n", inode->i_ino, ident); |
1024 | brelse(bh); | 1099 | brelse(bh); |
1025 | make_bad_inode(inode); | 1100 | make_bad_inode(inode); |
1026 | return; | 1101 | return; |
@@ -1032,7 +1107,8 @@ static void __udf_read_inode(struct inode *inode) | |||
1032 | struct buffer_head *ibh = NULL, *nbh = NULL; | 1107 | struct buffer_head *ibh = NULL, *nbh = NULL; |
1033 | struct indirectEntry *ie; | 1108 | struct indirectEntry *ie; |
1034 | 1109 | ||
1035 | ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident); | 1110 | ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, |
1111 | &ident); | ||
1036 | if (ident == TAG_IDENT_IE) { | 1112 | if (ident == TAG_IDENT_IE) { |
1037 | if (ibh) { | 1113 | if (ibh) { |
1038 | kernel_lb_addr loc; | 1114 | kernel_lb_addr loc; |
@@ -1041,10 +1117,12 @@ static void __udf_read_inode(struct inode *inode) | |||
1041 | loc = lelb_to_cpu(ie->indirectICB.extLocation); | 1117 | loc = lelb_to_cpu(ie->indirectICB.extLocation); |
1042 | 1118 | ||
1043 | if (ie->indirectICB.extLength && | 1119 | if (ie->indirectICB.extLength && |
1044 | (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) { | 1120 | (nbh = udf_read_ptagged(inode->i_sb, loc, 0, |
1121 | &ident))) { | ||
1045 | if (ident == TAG_IDENT_FE || | 1122 | if (ident == TAG_IDENT_FE || |
1046 | ident == TAG_IDENT_EFE) { | 1123 | ident == TAG_IDENT_EFE) { |
1047 | memcpy(&UDF_I_LOCATION(inode), &loc, | 1124 | memcpy(&UDF_I_LOCATION(inode), |
1125 | &loc, | ||
1048 | sizeof(kernel_lb_addr)); | 1126 | sizeof(kernel_lb_addr)); |
1049 | brelse(bh); | 1127 | brelse(bh); |
1050 | brelse(ibh); | 1128 | brelse(ibh); |
@@ -1091,7 +1169,8 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1091 | else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ | 1169 | else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ |
1092 | UDF_I_STRAT4096(inode) = 1; | 1170 | UDF_I_STRAT4096(inode) = 1; |
1093 | 1171 | ||
1094 | UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK; | 1172 | UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & |
1173 | ICBTAG_FLAG_AD_MASK; | ||
1095 | UDF_I_UNIQUE(inode) = 0; | 1174 | UDF_I_UNIQUE(inode) = 0; |
1096 | UDF_I_LENEATTR(inode) = 0; | 1175 | UDF_I_LENEATTR(inode) = 0; |
1097 | UDF_I_LENEXTENTS(inode) = 0; | 1176 | UDF_I_LENEXTENTS(inode) = 0; |
@@ -1101,16 +1180,20 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1101 | if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) { | 1180 | if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) { |
1102 | UDF_I_EFE(inode) = 1; | 1181 | UDF_I_EFE(inode) = 1; |
1103 | UDF_I_USE(inode) = 0; | 1182 | UDF_I_USE(inode) = 0; |
1104 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) { | 1183 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - |
1184 | sizeof(struct extendedFileEntry))) { | ||
1105 | make_bad_inode(inode); | 1185 | make_bad_inode(inode); |
1106 | return; | 1186 | return; |
1107 | } | 1187 | } |
1108 | memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), | 1188 | memcpy(UDF_I_DATA(inode), |
1109 | inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); | 1189 | bh->b_data + sizeof(struct extendedFileEntry), |
1190 | inode->i_sb->s_blocksize - | ||
1191 | sizeof(struct extendedFileEntry)); | ||
1110 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) { | 1192 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) { |
1111 | UDF_I_EFE(inode) = 0; | 1193 | UDF_I_EFE(inode) = 0; |
1112 | UDF_I_USE(inode) = 0; | 1194 | UDF_I_USE(inode) = 0; |
1113 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) { | 1195 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - |
1196 | sizeof(struct fileEntry))) { | ||
1114 | make_bad_inode(inode); | 1197 | make_bad_inode(inode); |
1115 | return; | 1198 | return; |
1116 | } | 1199 | } |
@@ -1119,14 +1202,18 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1119 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) { | 1202 | } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) { |
1120 | UDF_I_EFE(inode) = 0; | 1203 | UDF_I_EFE(inode) = 0; |
1121 | UDF_I_USE(inode) = 1; | 1204 | UDF_I_USE(inode) = 1; |
1122 | UDF_I_LENALLOC(inode) = | 1205 | UDF_I_LENALLOC(inode) = le32_to_cpu( |
1123 | le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs); | 1206 | ((struct unallocSpaceEntry *)bh->b_data)-> |
1124 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) { | 1207 | lengthAllocDescs); |
1208 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | ||
1209 | sizeof(struct unallocSpaceEntry))) { | ||
1125 | make_bad_inode(inode); | 1210 | make_bad_inode(inode); |
1126 | return; | 1211 | return; |
1127 | } | 1212 | } |
1128 | memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), | 1213 | memcpy(UDF_I_DATA(inode), |
1129 | inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); | 1214 | bh->b_data + sizeof(struct unallocSpaceEntry), |
1215 | inode->i_sb->s_blocksize - | ||
1216 | sizeof(struct unallocSpaceEntry)); | ||
1130 | return; | 1217 | return; |
1131 | } | 1218 | } |
1132 | 1219 | ||
@@ -1223,7 +1310,8 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1223 | UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); | 1310 | UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); |
1224 | UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); | 1311 | UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); |
1225 | UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); | 1312 | UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); |
1226 | offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode); | 1313 | offset = sizeof(struct extendedFileEntry) + |
1314 | UDF_I_LENEATTR(inode); | ||
1227 | } | 1315 | } |
1228 | 1316 | ||
1229 | switch (fe->icbTag.fileType) { | 1317 | switch (fe->icbTag.fileType) { |
@@ -1262,21 +1350,22 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1262 | inode->i_mode = S_IFLNK | S_IRWXUGO; | 1350 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
1263 | break; | 1351 | break; |
1264 | default: | 1352 | default: |
1265 | printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n", | 1353 | printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown " |
1266 | inode->i_ino, fe->icbTag.fileType); | 1354 | "file type=%d\n", inode->i_ino, |
1355 | fe->icbTag.fileType); | ||
1267 | make_bad_inode(inode); | 1356 | make_bad_inode(inode); |
1268 | return; | 1357 | return; |
1269 | } | 1358 | } |
1270 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { | 1359 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { |
1271 | struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1); | 1360 | struct deviceSpec *dsea = |
1361 | (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1); | ||
1272 | if (dsea) { | 1362 | if (dsea) { |
1273 | init_special_inode(inode, inode->i_mode, | 1363 | init_special_inode(inode, inode->i_mode, |
1274 | MKDEV(le32_to_cpu(dsea->majorDeviceIdent), | 1364 | MKDEV(le32_to_cpu(dsea->majorDeviceIdent), |
1275 | le32_to_cpu(dsea->minorDeviceIdent))); | 1365 | le32_to_cpu(dsea->minorDeviceIdent))); |
1276 | /* Developer ID ??? */ | 1366 | /* Developer ID ??? */ |
1277 | } else { | 1367 | } else |
1278 | make_bad_inode(inode); | 1368 | make_bad_inode(inode); |
1279 | } | ||
1280 | } | 1369 | } |
1281 | } | 1370 | } |
1282 | 1371 | ||
@@ -1285,8 +1374,8 @@ static int udf_alloc_i_data(struct inode *inode, size_t size) | |||
1285 | UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); | 1374 | UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); |
1286 | 1375 | ||
1287 | if (!UDF_I_DATA(inode)) { | 1376 | if (!UDF_I_DATA(inode)) { |
1288 | printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n", | 1377 | printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) " |
1289 | inode->i_ino); | 1378 | "no free memory\n", inode->i_ino); |
1290 | return -ENOMEM; | 1379 | return -ENOMEM; |
1291 | } | 1380 | } |
1292 | 1381 | ||
@@ -1302,12 +1391,12 @@ static mode_t udf_convert_permissions(struct fileEntry *fe) | |||
1302 | permissions = le32_to_cpu(fe->permissions); | 1391 | permissions = le32_to_cpu(fe->permissions); |
1303 | flags = le16_to_cpu(fe->icbTag.flags); | 1392 | flags = le16_to_cpu(fe->icbTag.flags); |
1304 | 1393 | ||
1305 | mode = (( permissions ) & S_IRWXO) | | 1394 | mode = ((permissions) & S_IRWXO) | |
1306 | (( permissions >> 2 ) & S_IRWXG) | | 1395 | ((permissions >> 2) & S_IRWXG) | |
1307 | (( permissions >> 4 ) & S_IRWXU) | | 1396 | ((permissions >> 4) & S_IRWXU) | |
1308 | (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | | 1397 | ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | |
1309 | (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | | 1398 | ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | |
1310 | (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); | 1399 | ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); |
1311 | 1400 | ||
1312 | return mode; | 1401 | return mode; |
1313 | } | 1402 | } |
@@ -1355,8 +1444,11 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1355 | kernel_timestamp cpu_time; | 1444 | kernel_timestamp cpu_time; |
1356 | int err = 0; | 1445 | int err = 0; |
1357 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | 1446 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); |
1447 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
1358 | 1448 | ||
1359 | bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0)); | 1449 | bh = udf_tread(inode->i_sb, |
1450 | udf_get_lb_pblock(inode->i_sb, | ||
1451 | UDF_I_LOCATION(inode), 0)); | ||
1360 | if (!bh) { | 1452 | if (!bh) { |
1361 | udf_debug("bread failure\n"); | 1453 | udf_debug("bread failure\n"); |
1362 | return -EIO; | 1454 | return -EIO; |
@@ -1372,18 +1464,24 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1372 | (struct unallocSpaceEntry *)bh->b_data; | 1464 | (struct unallocSpaceEntry *)bh->b_data; |
1373 | 1465 | ||
1374 | use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); | 1466 | use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); |
1375 | memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), | 1467 | memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), |
1376 | inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); | 1468 | UDF_I_DATA(inode), inode->i_sb->s_blocksize - |
1377 | crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - sizeof(tag); | 1469 | sizeof(struct unallocSpaceEntry)); |
1378 | use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); | 1470 | crclen = sizeof(struct unallocSpaceEntry) + |
1471 | UDF_I_LENALLOC(inode) - sizeof(tag); | ||
1472 | use->descTag.tagLocation = cpu_to_le32( | ||
1473 | UDF_I_LOCATION(inode). | ||
1474 | logicalBlockNum); | ||
1379 | use->descTag.descCRCLength = cpu_to_le16(crclen); | 1475 | use->descTag.descCRCLength = cpu_to_le16(crclen); |
1380 | use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0)); | 1476 | use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + |
1477 | sizeof(tag), crclen, | ||
1478 | 0)); | ||
1381 | 1479 | ||
1382 | use->descTag.tagChecksum = 0; | 1480 | use->descTag.tagChecksum = 0; |
1383 | for (i = 0; i < 16; i++) { | 1481 | for (i = 0; i < 16; i++) |
1384 | if (i != 4) | 1482 | if (i != 4) |
1385 | use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; | 1483 | use->descTag.tagChecksum += |
1386 | } | 1484 | ((uint8_t *)&(use->descTag))[i]; |
1387 | 1485 | ||
1388 | mark_buffer_dirty(bh); | 1486 | mark_buffer_dirty(bh); |
1389 | brelse(bh); | 1487 | brelse(bh); |
@@ -1400,14 +1498,14 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1400 | else | 1498 | else |
1401 | fe->gid = cpu_to_le32(inode->i_gid); | 1499 | fe->gid = cpu_to_le32(inode->i_gid); |
1402 | 1500 | ||
1403 | udfperms = ((inode->i_mode & S_IRWXO) ) | | 1501 | udfperms = ((inode->i_mode & S_IRWXO)) | |
1404 | ((inode->i_mode & S_IRWXG) << 2) | | 1502 | ((inode->i_mode & S_IRWXG) << 2) | |
1405 | ((inode->i_mode & S_IRWXU) << 4); | 1503 | ((inode->i_mode & S_IRWXU) << 4); |
1406 | 1504 | ||
1407 | udfperms |= (le32_to_cpu(fe->permissions) & | 1505 | udfperms |= (le32_to_cpu(fe->permissions) & |
1408 | (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | | 1506 | (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | |
1409 | FE_PERM_G_DELETE | FE_PERM_G_CHATTR | | 1507 | FE_PERM_G_DELETE | FE_PERM_G_CHATTR | |
1410 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); | 1508 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); |
1411 | fe->permissions = cpu_to_le32(udfperms); | 1509 | fe->permissions = cpu_to_le32(udfperms); |
1412 | 1510 | ||
1413 | if (S_ISDIR(inode->i_mode)) | 1511 | if (S_ISDIR(inode->i_mode)) |
@@ -1428,8 +1526,9 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1428 | sizeof(regid), 12, 0x3); | 1526 | sizeof(regid), 12, 0x3); |
1429 | dsea->attrType = cpu_to_le32(12); | 1527 | dsea->attrType = cpu_to_le32(12); |
1430 | dsea->attrSubtype = 1; | 1528 | dsea->attrSubtype = 1; |
1431 | dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + | 1529 | dsea->attrLength = cpu_to_le32( |
1432 | sizeof(regid)); | 1530 | sizeof(struct deviceSpec) + |
1531 | sizeof(regid)); | ||
1433 | dsea->impUseLength = cpu_to_le32(sizeof(regid)); | 1532 | dsea->impUseLength = cpu_to_le32(sizeof(regid)); |
1434 | } | 1533 | } |
1435 | eid = (regid *)dsea->impUse; | 1534 | eid = (regid *)dsea->impUse; |
@@ -1445,8 +1544,8 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1445 | memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), | 1544 | memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), |
1446 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); | 1545 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); |
1447 | fe->logicalBlocksRecorded = cpu_to_le64( | 1546 | fe->logicalBlocksRecorded = cpu_to_le64( |
1448 | (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> | 1547 | (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> |
1449 | (inode->i_sb->s_blocksize_bits - 9)); | 1548 | (blocksize_bits - 9)); |
1450 | 1549 | ||
1451 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) | 1550 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) |
1452 | fe->accessTime = cpu_to_lets(cpu_time); | 1551 | fe->accessTime = cpu_to_lets(cpu_time); |
@@ -1464,28 +1563,29 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1464 | fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); | 1563 | fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); |
1465 | crclen = sizeof(struct fileEntry); | 1564 | crclen = sizeof(struct fileEntry); |
1466 | } else { | 1565 | } else { |
1467 | memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), | 1566 | memcpy(bh->b_data + sizeof(struct extendedFileEntry), |
1468 | inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); | 1567 | UDF_I_DATA(inode), |
1568 | inode->i_sb->s_blocksize - | ||
1569 | sizeof(struct extendedFileEntry)); | ||
1469 | efe->objectSize = cpu_to_le64(inode->i_size); | 1570 | efe->objectSize = cpu_to_le64(inode->i_size); |
1470 | efe->logicalBlocksRecorded = cpu_to_le64( | 1571 | efe->logicalBlocksRecorded = cpu_to_le64( |
1471 | (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> | 1572 | (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> |
1472 | (inode->i_sb->s_blocksize_bits - 9)); | 1573 | (blocksize_bits - 9)); |
1473 | 1574 | ||
1474 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || | 1575 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || |
1475 | (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && | 1576 | (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && |
1476 | UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) { | 1577 | UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) |
1477 | UDF_I_CRTIME(inode) = inode->i_atime; | 1578 | UDF_I_CRTIME(inode) = inode->i_atime; |
1478 | } | 1579 | |
1479 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || | 1580 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || |
1480 | (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && | 1581 | (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && |
1481 | UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) { | 1582 | UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) |
1482 | UDF_I_CRTIME(inode) = inode->i_mtime; | 1583 | UDF_I_CRTIME(inode) = inode->i_mtime; |
1483 | } | 1584 | |
1484 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || | 1585 | if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || |
1485 | (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && | 1586 | (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && |
1486 | UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) { | 1587 | UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) |
1487 | UDF_I_CRTIME(inode) = inode->i_ctime; | 1588 | UDF_I_CRTIME(inode) = inode->i_ctime; |
1488 | } | ||
1489 | 1589 | ||
1490 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) | 1590 | if (udf_time_to_stamp(&cpu_time, inode->i_atime)) |
1491 | efe->accessTime = cpu_to_lets(cpu_time); | 1591 | efe->accessTime = cpu_to_lets(cpu_time); |
@@ -1544,24 +1644,27 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1544 | else | 1644 | else |
1545 | fe->descTag.descVersion = cpu_to_le16(2); | 1645 | fe->descTag.descVersion = cpu_to_le16(2); |
1546 | fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); | 1646 | fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); |
1547 | fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); | 1647 | fe->descTag.tagLocation = cpu_to_le32( |
1648 | UDF_I_LOCATION(inode).logicalBlockNum); | ||
1548 | crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); | 1649 | crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); |
1549 | fe->descTag.descCRCLength = cpu_to_le16(crclen); | 1650 | fe->descTag.descCRCLength = cpu_to_le16(crclen); |
1550 | fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0)); | 1651 | fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), |
1652 | crclen, 0)); | ||
1551 | 1653 | ||
1552 | fe->descTag.tagChecksum = 0; | 1654 | fe->descTag.tagChecksum = 0; |
1553 | for (i = 0; i < 16; i++) { | 1655 | for (i = 0; i < 16; i++) |
1554 | if (i != 4) | 1656 | if (i != 4) |
1555 | fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i]; | 1657 | fe->descTag.tagChecksum += |
1556 | } | 1658 | ((uint8_t *)&(fe->descTag))[i]; |
1557 | 1659 | ||
1558 | /* write the data blocks */ | 1660 | /* write the data blocks */ |
1559 | mark_buffer_dirty(bh); | 1661 | mark_buffer_dirty(bh); |
1560 | if (do_sync) { | 1662 | if (do_sync) { |
1561 | sync_dirty_buffer(bh); | 1663 | sync_dirty_buffer(bh); |
1562 | if (buffer_req(bh) && !buffer_uptodate(bh)) { | 1664 | if (buffer_req(bh) && !buffer_uptodate(bh)) { |
1563 | printk("IO error syncing udf inode [%s:%08lx]\n", | 1665 | printk(KERN_WARNING "IO error syncing udf inode " |
1564 | inode->i_sb->s_id, inode->i_ino); | 1666 | "[%s:%08lx]\n", inode->i_sb->s_id, |
1667 | inode->i_ino); | ||
1565 | err = -EIO; | 1668 | err = -EIO; |
1566 | } | 1669 | } |
1567 | } | 1670 | } |
@@ -1587,7 +1690,8 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
1587 | if (is_bad_inode(inode)) | 1690 | if (is_bad_inode(inode)) |
1588 | goto out_iput; | 1691 | goto out_iput; |
1589 | 1692 | ||
1590 | if (ino.logicalBlockNum >= UDF_SB(sb)->s_partmaps[ino.partitionReferenceNum].s_partition_len) { | 1693 | if (ino.logicalBlockNum >= UDF_SB(sb)-> |
1694 | s_partmaps[ino.partitionReferenceNum].s_partition_len) { | ||
1591 | udf_debug("block=%d, partition=%d out of range\n", | 1695 | udf_debug("block=%d, partition=%d out of range\n", |
1592 | ino.logicalBlockNum, ino.partitionReferenceNum); | 1696 | ino.logicalBlockNum, ino.partitionReferenceNum); |
1593 | make_bad_inode(inode); | 1697 | make_bad_inode(inode); |
@@ -1601,7 +1705,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
1601 | return NULL; | 1705 | return NULL; |
1602 | } | 1706 | } |
1603 | 1707 | ||
1604 | int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | 1708 | int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, |
1605 | kernel_lb_addr eloc, uint32_t elen, int inc) | 1709 | kernel_lb_addr eloc, uint32_t elen, int inc) |
1606 | { | 1710 | { |
1607 | int adsize; | 1711 | int adsize; |
@@ -1612,7 +1716,9 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1612 | uint8_t *ptr; | 1716 | uint8_t *ptr; |
1613 | 1717 | ||
1614 | if (!epos->bh) | 1718 | if (!epos->bh) |
1615 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1719 | ptr = UDF_I_DATA(inode) + epos->offset - |
1720 | udf_file_entry_alloc_offset(inode) + | ||
1721 | UDF_I_LENEATTR(inode); | ||
1616 | else | 1722 | else |
1617 | ptr = epos->bh->b_data + epos->offset; | 1723 | ptr = epos->bh->b_data + epos->offset; |
1618 | 1724 | ||
@@ -1629,15 +1735,16 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1629 | int err, loffset; | 1735 | int err, loffset; |
1630 | kernel_lb_addr obloc = epos->block; | 1736 | kernel_lb_addr obloc = epos->block; |
1631 | 1737 | ||
1632 | if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, | 1738 | epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, |
1633 | obloc.partitionReferenceNum, | 1739 | obloc.partitionReferenceNum, |
1634 | obloc.logicalBlockNum, &err))) { | 1740 | obloc.logicalBlockNum, &err); |
1741 | if (!epos->block.logicalBlockNum) | ||
1635 | return -1; | 1742 | return -1; |
1636 | } | 1743 | nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, |
1637 | if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, | 1744 | epos->block, |
1638 | epos->block, 0)))) { | 1745 | 0)); |
1746 | if (!nbh) | ||
1639 | return -1; | 1747 | return -1; |
1640 | } | ||
1641 | lock_buffer(nbh); | 1748 | lock_buffer(nbh); |
1642 | memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize); | 1749 | memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize); |
1643 | set_buffer_uptodate(nbh); | 1750 | set_buffer_uptodate(nbh); |
@@ -1646,7 +1753,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1646 | 1753 | ||
1647 | aed = (struct allocExtDesc *)(nbh->b_data); | 1754 | aed = (struct allocExtDesc *)(nbh->b_data); |
1648 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) | 1755 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
1649 | aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); | 1756 | aed->previousAllocExtLocation = |
1757 | cpu_to_le32(obloc.logicalBlockNum); | ||
1650 | if (epos->offset + adsize > inode->i_sb->s_blocksize) { | 1758 | if (epos->offset + adsize > inode->i_sb->s_blocksize) { |
1651 | loffset = epos->offset; | 1759 | loffset = epos->offset; |
1652 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 1760 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
@@ -1663,7 +1771,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1663 | if (epos->bh) { | 1771 | if (epos->bh) { |
1664 | aed = (struct allocExtDesc *)epos->bh->b_data; | 1772 | aed = (struct allocExtDesc *)epos->bh->b_data; |
1665 | aed->lengthAllocDescs = | 1773 | aed->lengthAllocDescs = |
1666 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1774 | cpu_to_le32(le32_to_cpu( |
1775 | aed->lengthAllocDescs) + adsize); | ||
1667 | } else { | 1776 | } else { |
1668 | UDF_I_LENALLOC(inode) += adsize; | 1777 | UDF_I_LENALLOC(inode) += adsize; |
1669 | mark_inode_dirty(inode); | 1778 | mark_inode_dirty(inode); |
@@ -1680,7 +1789,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1680 | sad = (short_ad *)sptr; | 1789 | sad = (short_ad *)sptr; |
1681 | sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | | 1790 | sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | |
1682 | inode->i_sb->s_blocksize); | 1791 | inode->i_sb->s_blocksize); |
1683 | sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); | 1792 | sad->extPosition = |
1793 | cpu_to_le32(epos->block.logicalBlockNum); | ||
1684 | break; | 1794 | break; |
1685 | case ICBTAG_FLAG_AD_LONG: | 1795 | case ICBTAG_FLAG_AD_LONG: |
1686 | lad = (long_ad *)sptr; | 1796 | lad = (long_ad *)sptr; |
@@ -1695,7 +1805,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1695 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | 1805 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
1696 | udf_update_tag(epos->bh->b_data, loffset); | 1806 | udf_update_tag(epos->bh->b_data, loffset); |
1697 | else | 1807 | else |
1698 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); | 1808 | udf_update_tag(epos->bh->b_data, |
1809 | sizeof(struct allocExtDesc)); | ||
1699 | mark_buffer_dirty_inode(epos->bh, inode); | 1810 | mark_buffer_dirty_inode(epos->bh, inode); |
1700 | brelse(epos->bh); | 1811 | brelse(epos->bh); |
1701 | } else { | 1812 | } else { |
@@ -1712,18 +1823,22 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos, | |||
1712 | } else { | 1823 | } else { |
1713 | aed = (struct allocExtDesc *)epos->bh->b_data; | 1824 | aed = (struct allocExtDesc *)epos->bh->b_data; |
1714 | aed->lengthAllocDescs = | 1825 | aed->lengthAllocDescs = |
1715 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1826 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + |
1716 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | 1827 | adsize); |
1717 | udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize)); | 1828 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
1829 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | ||
1830 | udf_update_tag(epos->bh->b_data, | ||
1831 | epos->offset + (inc ? 0 : adsize)); | ||
1718 | else | 1832 | else |
1719 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); | 1833 | udf_update_tag(epos->bh->b_data, |
1834 | sizeof(struct allocExtDesc)); | ||
1720 | mark_buffer_dirty_inode(epos->bh, inode); | 1835 | mark_buffer_dirty_inode(epos->bh, inode); |
1721 | } | 1836 | } |
1722 | 1837 | ||
1723 | return etype; | 1838 | return etype; |
1724 | } | 1839 | } |
1725 | 1840 | ||
1726 | int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | 1841 | int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, |
1727 | kernel_lb_addr eloc, uint32_t elen, int inc) | 1842 | kernel_lb_addr eloc, uint32_t elen, int inc) |
1728 | { | 1843 | { |
1729 | int adsize; | 1844 | int adsize; |
@@ -1732,7 +1847,9 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | |||
1732 | long_ad *lad; | 1847 | long_ad *lad; |
1733 | 1848 | ||
1734 | if (!epos->bh) | 1849 | if (!epos->bh) |
1735 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1850 | ptr = UDF_I_DATA(inode) + epos->offset - |
1851 | udf_file_entry_alloc_offset(inode) + | ||
1852 | UDF_I_LENEATTR(inode); | ||
1736 | else | 1853 | else |
1737 | ptr = epos->bh->b_data + epos->offset; | 1854 | ptr = epos->bh->b_data + epos->offset; |
1738 | 1855 | ||
@@ -1757,9 +1874,11 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | |||
1757 | if (epos->bh) { | 1874 | if (epos->bh) { |
1758 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 1875 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
1759 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) { | 1876 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) { |
1760 | struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; | 1877 | struct allocExtDesc *aed = |
1878 | (struct allocExtDesc *)epos->bh->b_data; | ||
1761 | udf_update_tag(epos->bh->b_data, | 1879 | udf_update_tag(epos->bh->b_data, |
1762 | le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); | 1880 | le32_to_cpu(aed->lengthAllocDescs) + |
1881 | sizeof(struct allocExtDesc)); | ||
1763 | } | 1882 | } |
1764 | mark_buffer_dirty_inode(epos->bh, inode); | 1883 | mark_buffer_dirty_inode(epos->bh, inode); |
1765 | } else { | 1884 | } else { |
@@ -1772,19 +1891,21 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos, | |||
1772 | return (elen >> 30); | 1891 | return (elen >> 30); |
1773 | } | 1892 | } |
1774 | 1893 | ||
1775 | int8_t udf_next_aext(struct inode * inode, struct extent_position * epos, | 1894 | int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, |
1776 | kernel_lb_addr * eloc, uint32_t * elen, int inc) | 1895 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
1777 | { | 1896 | { |
1778 | int8_t etype; | 1897 | int8_t etype; |
1779 | 1898 | ||
1780 | while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == | 1899 | while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == |
1781 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { | 1900 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
1901 | int block; | ||
1782 | epos->block = *eloc; | 1902 | epos->block = *eloc; |
1783 | epos->offset = sizeof(struct allocExtDesc); | 1903 | epos->offset = sizeof(struct allocExtDesc); |
1784 | brelse(epos->bh); | 1904 | brelse(epos->bh); |
1785 | if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) { | 1905 | block = udf_get_lb_pblock(inode->i_sb, epos->block, 0); |
1786 | udf_debug("reading block %d failed!\n", | 1906 | epos->bh = udf_tread(inode->i_sb, block); |
1787 | udf_get_lb_pblock(inode->i_sb, epos->block, 0)); | 1907 | if (!epos->bh) { |
1908 | udf_debug("reading block %d failed!\n", block); | ||
1788 | return -1; | 1909 | return -1; |
1789 | } | 1910 | } |
1790 | } | 1911 | } |
@@ -1792,8 +1913,8 @@ int8_t udf_next_aext(struct inode * inode, struct extent_position * epos, | |||
1792 | return etype; | 1913 | return etype; |
1793 | } | 1914 | } |
1794 | 1915 | ||
1795 | int8_t udf_current_aext(struct inode * inode, struct extent_position * epos, | 1916 | int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, |
1796 | kernel_lb_addr * eloc, uint32_t * elen, int inc) | 1917 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
1797 | { | 1918 | { |
1798 | int alen; | 1919 | int alen; |
1799 | int8_t etype; | 1920 | int8_t etype; |
@@ -1801,38 +1922,45 @@ int8_t udf_current_aext(struct inode * inode, struct extent_position * epos, | |||
1801 | short_ad *sad; | 1922 | short_ad *sad; |
1802 | long_ad *lad; | 1923 | long_ad *lad; |
1803 | 1924 | ||
1804 | |||
1805 | if (!epos->bh) { | 1925 | if (!epos->bh) { |
1806 | if (!epos->offset) | 1926 | if (!epos->offset) |
1807 | epos->offset = udf_file_entry_alloc_offset(inode); | 1927 | epos->offset = udf_file_entry_alloc_offset(inode); |
1808 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1928 | ptr = UDF_I_DATA(inode) + epos->offset - |
1809 | alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); | 1929 | udf_file_entry_alloc_offset(inode) + |
1930 | UDF_I_LENEATTR(inode); | ||
1931 | alen = udf_file_entry_alloc_offset(inode) + | ||
1932 | UDF_I_LENALLOC(inode); | ||
1810 | } else { | 1933 | } else { |
1811 | if (!epos->offset) | 1934 | if (!epos->offset) |
1812 | epos->offset = sizeof(struct allocExtDesc); | 1935 | epos->offset = sizeof(struct allocExtDesc); |
1813 | ptr = epos->bh->b_data + epos->offset; | 1936 | ptr = epos->bh->b_data + epos->offset; |
1814 | alen = sizeof(struct allocExtDesc) + | 1937 | alen = sizeof(struct allocExtDesc) + |
1815 | le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); | 1938 | le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)-> |
1939 | lengthAllocDescs); | ||
1816 | } | 1940 | } |
1817 | 1941 | ||
1818 | switch (UDF_I_ALLOCTYPE(inode)) { | 1942 | switch (UDF_I_ALLOCTYPE(inode)) { |
1819 | case ICBTAG_FLAG_AD_SHORT: | 1943 | case ICBTAG_FLAG_AD_SHORT: |
1820 | if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc))) | 1944 | sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc); |
1945 | if (!sad) | ||
1821 | return -1; | 1946 | return -1; |
1822 | etype = le32_to_cpu(sad->extLength) >> 30; | 1947 | etype = le32_to_cpu(sad->extLength) >> 30; |
1823 | eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); | 1948 | eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); |
1824 | eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 1949 | eloc->partitionReferenceNum = |
1950 | UDF_I_LOCATION(inode).partitionReferenceNum; | ||
1825 | *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; | 1951 | *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; |
1826 | break; | 1952 | break; |
1827 | case ICBTAG_FLAG_AD_LONG: | 1953 | case ICBTAG_FLAG_AD_LONG: |
1828 | if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc))) | 1954 | lad = udf_get_filelongad(ptr, alen, &epos->offset, inc); |
1955 | if (!lad) | ||
1829 | return -1; | 1956 | return -1; |
1830 | etype = le32_to_cpu(lad->extLength) >> 30; | 1957 | etype = le32_to_cpu(lad->extLength) >> 30; |
1831 | *eloc = lelb_to_cpu(lad->extLocation); | 1958 | *eloc = lelb_to_cpu(lad->extLocation); |
1832 | *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; | 1959 | *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; |
1833 | break; | 1960 | break; |
1834 | default: | 1961 | default: |
1835 | udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode)); | 1962 | udf_debug("alloc_type = %d unsupported\n", |
1963 | UDF_I_ALLOCTYPE(inode)); | ||
1836 | return -1; | 1964 | return -1; |
1837 | } | 1965 | } |
1838 | 1966 | ||
@@ -1860,7 +1988,7 @@ static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos, | |||
1860 | return (nelen >> 30); | 1988 | return (nelen >> 30); |
1861 | } | 1989 | } |
1862 | 1990 | ||
1863 | int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | 1991 | int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, |
1864 | kernel_lb_addr eloc, uint32_t elen) | 1992 | kernel_lb_addr eloc, uint32_t elen) |
1865 | { | 1993 | { |
1866 | struct extent_position oepos; | 1994 | struct extent_position oepos; |
@@ -1907,12 +2035,15 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | |||
1907 | } else { | 2035 | } else { |
1908 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 2036 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
1909 | aed->lengthAllocDescs = | 2037 | aed->lengthAllocDescs = |
1910 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2 * adsize)); | 2038 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - |
2039 | (2 * adsize)); | ||
1911 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 2040 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
1912 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | 2041 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
1913 | udf_update_tag(oepos.bh->b_data, oepos.offset - (2 * adsize)); | 2042 | udf_update_tag(oepos.bh->b_data, |
2043 | oepos.offset - (2 * adsize)); | ||
1914 | else | 2044 | else |
1915 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); | 2045 | udf_update_tag(oepos.bh->b_data, |
2046 | sizeof(struct allocExtDesc)); | ||
1916 | mark_buffer_dirty_inode(oepos.bh, inode); | 2047 | mark_buffer_dirty_inode(oepos.bh, inode); |
1917 | } | 2048 | } |
1918 | } else { | 2049 | } else { |
@@ -1923,12 +2054,15 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | |||
1923 | } else { | 2054 | } else { |
1924 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 2055 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
1925 | aed->lengthAllocDescs = | 2056 | aed->lengthAllocDescs = |
1926 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); | 2057 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - |
2058 | adsize); | ||
1927 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || | 2059 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
1928 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) | 2060 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
1929 | udf_update_tag(oepos.bh->b_data, epos.offset - adsize); | 2061 | udf_update_tag(oepos.bh->b_data, |
2062 | epos.offset - adsize); | ||
1930 | else | 2063 | else |
1931 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); | 2064 | udf_update_tag(oepos.bh->b_data, |
2065 | sizeof(struct allocExtDesc)); | ||
1932 | mark_buffer_dirty_inode(oepos.bh, inode); | 2066 | mark_buffer_dirty_inode(oepos.bh, inode); |
1933 | } | 2067 | } |
1934 | } | 2068 | } |
@@ -1939,12 +2073,13 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos, | |||
1939 | return (elen >> 30); | 2073 | return (elen >> 30); |
1940 | } | 2074 | } |
1941 | 2075 | ||
1942 | int8_t inode_bmap(struct inode * inode, sector_t block, | 2076 | int8_t inode_bmap(struct inode *inode, sector_t block, |
1943 | struct extent_position * pos, kernel_lb_addr * eloc, | 2077 | struct extent_position *pos, kernel_lb_addr *eloc, |
1944 | uint32_t * elen, sector_t * offset) | 2078 | uint32_t *elen, sector_t *offset) |
1945 | { | 2079 | { |
2080 | unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; | ||
1946 | loff_t lbcount = 0, bcount = | 2081 | loff_t lbcount = 0, bcount = |
1947 | (loff_t) block << inode->i_sb->s_blocksize_bits; | 2082 | (loff_t) block << blocksize_bits; |
1948 | int8_t etype; | 2083 | int8_t etype; |
1949 | 2084 | ||
1950 | if (block < 0) { | 2085 | if (block < 0) { |
@@ -1958,15 +2093,16 @@ int8_t inode_bmap(struct inode * inode, sector_t block, | |||
1958 | *elen = 0; | 2093 | *elen = 0; |
1959 | 2094 | ||
1960 | do { | 2095 | do { |
1961 | if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) { | 2096 | etype = udf_next_aext(inode, pos, eloc, elen, 1); |
1962 | *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits; | 2097 | if (etype == -1) { |
2098 | *offset = (bcount - lbcount) >> blocksize_bits; | ||
1963 | UDF_I_LENEXTENTS(inode) = lbcount; | 2099 | UDF_I_LENEXTENTS(inode) = lbcount; |
1964 | return -1; | 2100 | return -1; |
1965 | } | 2101 | } |
1966 | lbcount += *elen; | 2102 | lbcount += *elen; |
1967 | } while (lbcount <= bcount); | 2103 | } while (lbcount <= bcount); |
1968 | 2104 | ||
1969 | *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits; | 2105 | *offset = (bcount + *elen - lbcount) >> blocksize_bits; |
1970 | 2106 | ||
1971 | return etype; | 2107 | return etype; |
1972 | } | 2108 | } |
@@ -1981,7 +2117,8 @@ long udf_block_map(struct inode *inode, sector_t block) | |||
1981 | 2117 | ||
1982 | lock_kernel(); | 2118 | lock_kernel(); |
1983 | 2119 | ||
1984 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) | 2120 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == |
2121 | (EXT_RECORDED_ALLOCATED >> 30)) | ||
1985 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); | 2122 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); |
1986 | else | 2123 | else |
1987 | ret = 0; | 2124 | ret = 0; |
diff --git a/fs/udf/misc.c b/fs/udf/misc.c index 7cecb3098061..a0bf4158f1f1 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c | |||
@@ -70,71 +70,84 @@ 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 (UDF_I_LENALLOC(inode)) |
74 | memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); | 74 | memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); |
75 | } | ||
76 | 75 | ||
77 | if (UDF_I_LENEATTR(inode)) { | 76 | if (UDF_I_LENEATTR(inode)) { |
78 | /* check checksum/crc */ | 77 | /* check checksum/crc */ |
79 | if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || | 78 | if (le16_to_cpu(eahd->descTag.tagIdent) != |
80 | le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { | 79 | TAG_IDENT_EAHD || |
80 | le32_to_cpu(eahd->descTag.tagLocation) != | ||
81 | UDF_I_LOCATION(inode).logicalBlockNum) | ||
81 | return NULL; | 82 | return NULL; |
82 | } | ||
83 | } else { | 83 | } else { |
84 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | 84 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); |
85 | 85 | ||
86 | size -= sizeof(struct extendedAttrHeaderDesc); | 86 | size -= sizeof(struct extendedAttrHeaderDesc); |
87 | UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); | 87 | UDF_I_LENEATTR(inode) += |
88 | sizeof(struct extendedAttrHeaderDesc); | ||
88 | eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); | 89 | eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); |
89 | if (sbi->s_udfrev >= 0x0200) | 90 | if (sbi->s_udfrev >= 0x0200) |
90 | eahd->descTag.descVersion = cpu_to_le16(3); | 91 | eahd->descTag.descVersion = cpu_to_le16(3); |
91 | else | 92 | else |
92 | eahd->descTag.descVersion = cpu_to_le16(2); | 93 | eahd->descTag.descVersion = cpu_to_le16(2); |
93 | eahd->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); | 94 | eahd->descTag.tagSerialNum = |
94 | 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 | UDF_I_LOCATION(inode).logicalBlockNum); | ||
95 | eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); | 98 | eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); |
96 | eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); | 99 | eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); |
97 | } | 100 | } |
98 | 101 | ||
99 | offset = UDF_I_LENEATTR(inode); | 102 | offset = UDF_I_LENEATTR(inode); |
100 | if (type < 2048) { | 103 | if (type < 2048) { |
101 | if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { | 104 | if (le32_to_cpu(eahd->appAttrLocation) < |
102 | uint32_t aal = le32_to_cpu(eahd->appAttrLocation); | 105 | UDF_I_LENEATTR(inode)) { |
106 | uint32_t aal = | ||
107 | le32_to_cpu(eahd->appAttrLocation); | ||
103 | memmove(&ea[offset - aal + size], | 108 | memmove(&ea[offset - aal + size], |
104 | &ea[aal], offset - aal); | 109 | &ea[aal], offset - aal); |
105 | offset -= aal; | 110 | offset -= aal; |
106 | eahd->appAttrLocation = cpu_to_le32(aal + size); | 111 | eahd->appAttrLocation = |
112 | cpu_to_le32(aal + size); | ||
107 | } | 113 | } |
108 | if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) { | 114 | if (le32_to_cpu(eahd->impAttrLocation) < |
109 | uint32_t ial = le32_to_cpu(eahd->impAttrLocation); | 115 | UDF_I_LENEATTR(inode)) { |
116 | uint32_t ial = | ||
117 | le32_to_cpu(eahd->impAttrLocation); | ||
110 | memmove(&ea[offset - ial + size], | 118 | memmove(&ea[offset - ial + size], |
111 | &ea[ial], offset - ial); | 119 | &ea[ial], offset - ial); |
112 | offset -= ial; | 120 | offset -= ial; |
113 | eahd->impAttrLocation = cpu_to_le32(ial + size); | 121 | eahd->impAttrLocation = |
122 | cpu_to_le32(ial + size); | ||
114 | } | 123 | } |
115 | } else if (type < 65536) { | 124 | } else if (type < 65536) { |
116 | if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { | 125 | if (le32_to_cpu(eahd->appAttrLocation) < |
117 | uint32_t aal = le32_to_cpu(eahd->appAttrLocation); | 126 | UDF_I_LENEATTR(inode)) { |
127 | uint32_t aal = | ||
128 | le32_to_cpu(eahd->appAttrLocation); | ||
118 | memmove(&ea[offset - aal + size], | 129 | memmove(&ea[offset - aal + size], |
119 | &ea[aal], offset - aal); | 130 | &ea[aal], offset - aal); |
120 | offset -= aal; | 131 | offset -= aal; |
121 | eahd->appAttrLocation = cpu_to_le32(aal + size); | 132 | eahd->appAttrLocation = |
133 | cpu_to_le32(aal + size); | ||
122 | } | 134 | } |
123 | } | 135 | } |
124 | /* rewrite CRC + checksum of eahd */ | 136 | /* rewrite CRC + checksum of eahd */ |
125 | crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); | 137 | crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); |
126 | eahd->descTag.descCRCLength = cpu_to_le16(crclen); | 138 | eahd->descTag.descCRCLength = cpu_to_le16(crclen); |
127 | eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + | 139 | eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + |
128 | sizeof(tag), crclen, 0)); | 140 | sizeof(tag), crclen, 0)); |
129 | eahd->descTag.tagChecksum = 0; | 141 | eahd->descTag.tagChecksum = 0; |
130 | for (i = 0; i < 16; i++) | 142 | for (i = 0; i < 16; i++) |
131 | if (i != 4) | 143 | if (i != 4) |
132 | eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; | 144 | eahd->descTag.tagChecksum += |
145 | ((uint8_t *)&(eahd->descTag))[i]; | ||
133 | UDF_I_LENEATTR(inode) += size; | 146 | UDF_I_LENEATTR(inode) += size; |
134 | return (struct genericFormat *)&ea[offset]; | 147 | return (struct genericFormat *)&ea[offset]; |
135 | } | 148 | } |
136 | if (loc & 0x02) { | 149 | if (loc & 0x02) |
137 | } | 150 | ; |
138 | 151 | ||
139 | return NULL; | 152 | return NULL; |
140 | } | 153 | } |
@@ -153,10 +166,11 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
153 | eahd = (struct extendedAttrHeaderDesc *)ea; | 166 | eahd = (struct extendedAttrHeaderDesc *)ea; |
154 | 167 | ||
155 | /* check checksum/crc */ | 168 | /* check checksum/crc */ |
156 | if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || | 169 | if (le16_to_cpu(eahd->descTag.tagIdent) != |
157 | le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { | 170 | TAG_IDENT_EAHD || |
171 | le32_to_cpu(eahd->descTag.tagLocation) != | ||
172 | UDF_I_LOCATION(inode).logicalBlockNum) | ||
158 | return NULL; | 173 | return NULL; |
159 | } | ||
160 | 174 | ||
161 | if (type < 2048) | 175 | if (type < 2048) |
162 | offset = sizeof(struct extendedAttrHeaderDesc); | 176 | offset = sizeof(struct extendedAttrHeaderDesc); |
@@ -167,7 +181,8 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
167 | 181 | ||
168 | while (offset < UDF_I_LENEATTR(inode)) { | 182 | while (offset < UDF_I_LENEATTR(inode)) { |
169 | gaf = (struct genericFormat *)&ea[offset]; | 183 | gaf = (struct genericFormat *)&ea[offset]; |
170 | if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) | 184 | if (le32_to_cpu(gaf->attrType) == type && |
185 | gaf->attrSubtype == subtype) | ||
171 | return gaf; | 186 | return gaf; |
172 | else | 187 | else |
173 | offset += le32_to_cpu(gaf->attrLength); | 188 | offset += le32_to_cpu(gaf->attrLength); |
@@ -188,7 +203,7 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, | |||
188 | * Written, tested, and released. | 203 | * Written, tested, and released. |
189 | */ | 204 | */ |
190 | struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | 205 | struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, |
191 | uint32_t location, uint16_t * ident) | 206 | uint32_t location, uint16_t *ident) |
192 | { | 207 | { |
193 | tag *tag_p; | 208 | tag *tag_p; |
194 | struct buffer_head *bh = NULL; | 209 | struct buffer_head *bh = NULL; |
@@ -213,7 +228,8 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | |||
213 | 228 | ||
214 | if (location != le32_to_cpu(tag_p->tagLocation)) { | 229 | if (location != le32_to_cpu(tag_p->tagLocation)) { |
215 | udf_debug("location mismatch block %u, tag %u != %u\n", | 230 | udf_debug("location mismatch block %u, tag %u != %u\n", |
216 | block + sbi->s_session, le32_to_cpu(tag_p->tagLocation), location); | 231 | block + sbi->s_session, |
232 | le32_to_cpu(tag_p->tagLocation), location); | ||
217 | goto error_out; | 233 | goto error_out; |
218 | } | 234 | } |
219 | 235 | ||
@@ -239,9 +255,9 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, | |||
239 | /* Verify the descriptor CRC */ | 255 | /* Verify the descriptor CRC */ |
240 | if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || | 256 | if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || |
241 | le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), | 257 | le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), |
242 | le16_to_cpu(tag_p->descCRCLength), 0)) { | 258 | le16_to_cpu(tag_p->descCRCLength), 0)) |
243 | return bh; | 259 | return bh; |
244 | } | 260 | |
245 | udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", | 261 | udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", |
246 | block + sbi->s_session, le16_to_cpu(tag_p->descCRC), | 262 | block + sbi->s_session, le16_to_cpu(tag_p->descCRC), |
247 | le16_to_cpu(tag_p->descCRCLength)); | 263 | le16_to_cpu(tag_p->descCRCLength)); |
@@ -252,7 +268,7 @@ error_out: | |||
252 | } | 268 | } |
253 | 269 | ||
254 | struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, | 270 | struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, |
255 | uint32_t offset, uint16_t * ident) | 271 | uint32_t offset, uint16_t *ident) |
256 | { | 272 | { |
257 | return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), | 273 | return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), |
258 | loc.logicalBlockNum + offset, ident); | 274 | loc.logicalBlockNum + offset, ident); |
diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 86033d92824c..a126950d79e6 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c | |||
@@ -43,7 +43,7 @@ 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; |
@@ -68,7 +68,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
68 | memcpy(fibh->ebh->b_data + offset, impuse, liu); | 68 | memcpy(fibh->ebh->b_data + offset, impuse, liu); |
69 | } else { | 69 | } else { |
70 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); | 70 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); |
71 | memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); | 71 | memcpy(fibh->ebh->b_data, impuse - offset, |
72 | liu + offset); | ||
72 | } | 73 | } |
73 | } | 74 | } |
74 | 75 | ||
@@ -80,8 +81,10 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
80 | } else if (offset >= 0) { | 81 | } else if (offset >= 0) { |
81 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); | 82 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); |
82 | } else { | 83 | } else { |
83 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); | 84 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, |
84 | memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); | 85 | -offset); |
86 | memcpy(fibh->ebh->b_data, fileident - offset, | ||
87 | lfi + offset); | ||
85 | } | 88 | } |
86 | } | 89 | } |
87 | 90 | ||
@@ -101,13 +104,19 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
101 | 104 | ||
102 | if (fibh->sbh == fibh->ebh) { | 105 | if (fibh->sbh == fibh->ebh) { |
103 | crc = udf_crc((uint8_t *)sfi->impUse, | 106 | crc = udf_crc((uint8_t *)sfi->impUse, |
104 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); | 107 | crclen + sizeof(tag) - |
108 | sizeof(struct fileIdentDesc), crc); | ||
105 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { | 109 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { |
106 | crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, | 110 | crc = udf_crc(fibh->ebh->b_data + |
107 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); | 111 | sizeof(struct fileIdentDesc) + |
112 | fibh->soffset, | ||
113 | crclen + sizeof(tag) - | ||
114 | sizeof(struct fileIdentDesc), | ||
115 | crc); | ||
108 | } else { | 116 | } else { |
109 | crc = udf_crc((uint8_t *)sfi->impUse, | 117 | crc = udf_crc((uint8_t *)sfi->impUse, |
110 | -fibh->soffset - sizeof(struct fileIdentDesc), crc); | 118 | -fibh->soffset - sizeof(struct fileIdentDesc), |
119 | crc); | ||
111 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); | 120 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); |
112 | } | 121 | } |
113 | 122 | ||
@@ -121,7 +130,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
121 | 130 | ||
122 | cfi->descTag.tagChecksum = checksum; | 131 | cfi->descTag.tagChecksum = checksum; |
123 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { | 132 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { |
124 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); | 133 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, |
134 | sizeof(struct fileIdentDesc)); | ||
125 | } else { | 135 | } else { |
126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); | 136 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); |
127 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, | 137 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, |
@@ -159,22 +169,24 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
159 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; | 169 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; |
160 | f_pos = (udf_ext0_offset(dir) >> 2); | 170 | f_pos = (udf_ext0_offset(dir) >> 2); |
161 | 171 | ||
162 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 172 | fibh->soffset = fibh->eoffset = |
163 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 173 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
174 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | ||
164 | fibh->sbh = fibh->ebh = NULL; | 175 | fibh->sbh = fibh->ebh = NULL; |
165 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 176 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
166 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 177 | &epos, &eloc, &elen, &offset) == |
178 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
167 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 179 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
168 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 180 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
169 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 181 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
170 | epos.offset -= sizeof(short_ad); | 182 | epos.offset -= sizeof(short_ad); |
171 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 183 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
172 | epos.offset -= sizeof(long_ad); | 184 | epos.offset -= sizeof(long_ad); |
173 | } else { | 185 | } else |
174 | offset = 0; | 186 | offset = 0; |
175 | } | ||
176 | 187 | ||
177 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 188 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
189 | if (!fibh->sbh) { | ||
178 | brelse(epos.bh); | 190 | brelse(epos.bh); |
179 | return NULL; | 191 | return NULL; |
180 | } | 192 | } |
@@ -202,14 +214,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
202 | } else { | 214 | } else { |
203 | int poffset; /* Unpaded ending offset */ | 215 | int poffset; /* Unpaded ending offset */ |
204 | 216 | ||
205 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; | 217 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
218 | liu + lfi; | ||
206 | 219 | ||
207 | if (poffset >= lfi) { | 220 | if (poffset >= lfi) |
208 | nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); | 221 | nameptr = (uint8_t *)(fibh->ebh->b_data + |
209 | } else { | 222 | poffset - lfi); |
223 | else { | ||
210 | nameptr = fname; | 224 | nameptr = fname; |
211 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); | 225 | memcpy(nameptr, fi->fileIdent + liu, |
212 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); | 226 | lfi - poffset); |
227 | memcpy(nameptr + lfi - poffset, | ||
228 | fibh->ebh->b_data, poffset); | ||
213 | } | 229 | } |
214 | } | 230 | } |
215 | 231 | ||
@@ -226,11 +242,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
226 | if (!lfi) | 242 | if (!lfi) |
227 | continue; | 243 | continue; |
228 | 244 | ||
229 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { | 245 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
230 | if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { | 246 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
231 | brelse(epos.bh); | 247 | dentry->d_name.name)) { |
232 | return fi; | 248 | brelse(epos.bh); |
233 | } | 249 | return fi; |
234 | } | 250 | } |
235 | } | 251 | } |
236 | 252 | ||
@@ -291,16 +307,16 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
291 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { | 307 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { |
292 | kernel_lb_addr lb = { | 308 | kernel_lb_addr lb = { |
293 | .logicalBlockNum = 0, | 309 | .logicalBlockNum = 0, |
294 | .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3, | 310 | .partitionReferenceNum = |
295 | NULL, 0), | 311 | simple_strtoul(dentry->d_name.name + 3, |
312 | NULL, 0), | ||
296 | }; | 313 | }; |
297 | inode = udf_iget(dir->i_sb, lb); | 314 | inode = udf_iget(dir->i_sb, lb); |
298 | if (!inode) { | 315 | if (!inode) { |
299 | unlock_kernel(); | 316 | unlock_kernel(); |
300 | return ERR_PTR(-EACCES); | 317 | return ERR_PTR(-EACCES); |
301 | } | 318 | } |
302 | } | 319 | } else |
303 | else | ||
304 | #endif /* UDF_RECOVERY */ | 320 | #endif /* UDF_RECOVERY */ |
305 | 321 | ||
306 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { | 322 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { |
@@ -347,8 +363,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
347 | *err = -EINVAL; | 363 | *err = -EINVAL; |
348 | return NULL; | 364 | return NULL; |
349 | } | 365 | } |
350 | if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name, | 366 | namelen = udf_put_filename(sb, dentry->d_name.name, name, |
351 | dentry->d_name.len))) { | 367 | dentry->d_name.len); |
368 | if (!namelen) { | ||
352 | *err = -ENAMETOOLONG; | 369 | *err = -ENAMETOOLONG; |
353 | return NULL; | 370 | return NULL; |
354 | } | 371 | } |
@@ -360,22 +377,24 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
360 | 377 | ||
361 | f_pos = (udf_ext0_offset(dir) >> 2); | 378 | f_pos = (udf_ext0_offset(dir) >> 2); |
362 | 379 | ||
363 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 380 | fibh->soffset = fibh->eoffset = |
364 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 381 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
382 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | ||
365 | fibh->sbh = fibh->ebh = NULL; | 383 | fibh->sbh = fibh->ebh = NULL; |
366 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 384 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
367 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 385 | &epos, &eloc, &elen, &offset) == |
386 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
368 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 387 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
369 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 388 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
370 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 389 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
371 | epos.offset -= sizeof(short_ad); | 390 | epos.offset -= sizeof(short_ad); |
372 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 391 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
373 | epos.offset -= sizeof(long_ad); | 392 | epos.offset -= sizeof(long_ad); |
374 | } else { | 393 | } else |
375 | offset = 0; | 394 | offset = 0; |
376 | } | ||
377 | 395 | ||
378 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 396 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
397 | if (!fibh->sbh) { | ||
379 | brelse(epos.bh); | 398 | brelse(epos.bh); |
380 | *err = -EIO; | 399 | *err = -EIO; |
381 | return NULL; | 400 | return NULL; |
@@ -406,33 +425,39 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
406 | liu = le16_to_cpu(cfi->lengthOfImpUse); | 425 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
407 | lfi = cfi->lengthFileIdent; | 426 | lfi = cfi->lengthFileIdent; |
408 | 427 | ||
409 | if (fibh->sbh == fibh->ebh) { | 428 | if (fibh->sbh == fibh->ebh) |
410 | nameptr = fi->fileIdent + liu; | 429 | nameptr = fi->fileIdent + liu; |
411 | } else { | 430 | else { |
412 | int poffset; /* Unpaded ending offset */ | 431 | int poffset; /* Unpaded ending offset */ |
413 | 432 | ||
414 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; | 433 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
434 | liu + lfi; | ||
415 | 435 | ||
416 | if (poffset >= lfi) { | 436 | if (poffset >= lfi) |
417 | nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); | 437 | nameptr = (char *)(fibh->ebh->b_data + |
418 | } else { | 438 | poffset - lfi); |
439 | else { | ||
419 | nameptr = fname; | 440 | nameptr = fname; |
420 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); | 441 | memcpy(nameptr, fi->fileIdent + liu, |
421 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); | 442 | lfi - poffset); |
443 | memcpy(nameptr + lfi - poffset, | ||
444 | fibh->ebh->b_data, poffset); | ||
422 | } | 445 | } |
423 | } | 446 | } |
424 | 447 | ||
425 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { | 448 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
426 | if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) { | 449 | if (((sizeof(struct fileIdentDesc) + |
450 | liu + lfi + 3) & ~3) == nfidlen) { | ||
427 | brelse(epos.bh); | 451 | brelse(epos.bh); |
428 | cfi->descTag.tagSerialNum = cpu_to_le16(1); | 452 | cfi->descTag.tagSerialNum = cpu_to_le16(1); |
429 | cfi->fileVersionNum = cpu_to_le16(1); | 453 | cfi->fileVersionNum = cpu_to_le16(1); |
430 | cfi->fileCharacteristics = 0; | 454 | cfi->fileCharacteristics = 0; |
431 | cfi->lengthFileIdent = namelen; | 455 | cfi->lengthFileIdent = namelen; |
432 | cfi->lengthOfImpUse = cpu_to_le16(0); | 456 | cfi->lengthOfImpUse = cpu_to_le16(0); |
433 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { | 457 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, |
458 | name)) | ||
434 | return fi; | 459 | return fi; |
435 | } else { | 460 | else { |
436 | *err = -EIO; | 461 | *err = -EIO; |
437 | return NULL; | 462 | return NULL; |
438 | } | 463 | } |
@@ -442,8 +467,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
442 | if (!lfi || !dentry) | 467 | if (!lfi || !dentry) |
443 | continue; | 468 | continue; |
444 | 469 | ||
445 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && | 470 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
446 | udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { | 471 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
472 | dentry->d_name.name)) { | ||
447 | if (fibh->sbh != fibh->ebh) | 473 | if (fibh->sbh != fibh->ebh) |
448 | brelse(fibh->ebh); | 474 | brelse(fibh->ebh); |
449 | brelse(fibh->sbh); | 475 | brelse(fibh->sbh); |
@@ -466,11 +492,14 @@ add: | |||
466 | if (fibh->sbh != fibh->ebh) | 492 | if (fibh->sbh != fibh->ebh) |
467 | brelse(fibh->ebh); | 493 | brelse(fibh->ebh); |
468 | brelse(fibh->sbh); | 494 | brelse(fibh->sbh); |
469 | if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) | 495 | fibh->sbh = fibh->ebh = |
496 | udf_expand_dir_adinicb(dir, &block, err); | ||
497 | if (!fibh->sbh) | ||
470 | return NULL; | 498 | return NULL; |
471 | epos.block = UDF_I_LOCATION(dir); | 499 | epos.block = UDF_I_LOCATION(dir); |
472 | eloc.logicalBlockNum = block; | 500 | eloc.logicalBlockNum = block; |
473 | eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; | 501 | eloc.partitionReferenceNum = |
502 | UDF_I_LOCATION(dir).partitionReferenceNum; | ||
474 | elen = dir->i_sb->s_blocksize; | 503 | elen = dir->i_sb->s_blocksize; |
475 | epos.offset = udf_file_entry_alloc_offset(dir); | 504 | epos.offset = udf_file_entry_alloc_offset(dir); |
476 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 505 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
@@ -489,13 +518,16 @@ add: | |||
489 | 518 | ||
490 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 519 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
491 | block = UDF_I_LOCATION(dir).logicalBlockNum; | 520 | block = UDF_I_LOCATION(dir).logicalBlockNum; |
492 | fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - | 521 | fi = (struct fileIdentDesc *) |
493 | udf_ext0_offset(dir) + | 522 | (UDF_I_DATA(dir) + fibh->soffset - |
494 | UDF_I_LENEATTR(dir)); | 523 | udf_ext0_offset(dir) + |
524 | UDF_I_LENEATTR(dir)); | ||
495 | } else { | 525 | } else { |
496 | block = eloc.logicalBlockNum + ((elen - 1) >> | 526 | block = eloc.logicalBlockNum + |
497 | dir->i_sb->s_blocksize_bits); | 527 | ((elen - 1) >> |
498 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); | 528 | dir->i_sb->s_blocksize_bits); |
529 | fi = (struct fileIdentDesc *) | ||
530 | (fibh->sbh->b_data + fibh->soffset); | ||
499 | } | 531 | } |
500 | } else { | 532 | } else { |
501 | fibh->soffset = fibh->eoffset - sb->s_blocksize; | 533 | fibh->soffset = fibh->eoffset - sb->s_blocksize; |
@@ -507,7 +539,9 @@ add: | |||
507 | 539 | ||
508 | block = eloc.logicalBlockNum + ((elen - 1) >> | 540 | block = eloc.logicalBlockNum + ((elen - 1) >> |
509 | dir->i_sb->s_blocksize_bits); | 541 | dir->i_sb->s_blocksize_bits); |
510 | fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err); | 542 | fibh->ebh = udf_bread(dir, |
543 | f_pos >> (dir->i_sb->s_blocksize_bits - 2), | ||
544 | 1, err); | ||
511 | if (!fibh->ebh) { | 545 | if (!fibh->ebh) { |
512 | brelse(epos.bh); | 546 | brelse(epos.bh); |
513 | brelse(fibh->sbh); | 547 | brelse(fibh->sbh); |
@@ -519,24 +553,26 @@ add: | |||
519 | (EXT_RECORDED_ALLOCATED >> 30)) { | 553 | (EXT_RECORDED_ALLOCATED >> 30)) { |
520 | block = eloc.logicalBlockNum + ((elen - 1) >> | 554 | block = eloc.logicalBlockNum + ((elen - 1) >> |
521 | dir->i_sb->s_blocksize_bits); | 555 | dir->i_sb->s_blocksize_bits); |
522 | } else { | 556 | } else |
523 | block++; | 557 | block++; |
524 | } | ||
525 | 558 | ||
526 | brelse(fibh->sbh); | 559 | brelse(fibh->sbh); |
527 | fibh->sbh = fibh->ebh; | 560 | fibh->sbh = fibh->ebh; |
528 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); | 561 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); |
529 | } else { | 562 | } else { |
530 | fi = (struct fileIdentDesc *) | 563 | fi = (struct fileIdentDesc *) |
531 | (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); | 564 | (fibh->sbh->b_data + sb->s_blocksize + |
565 | fibh->soffset); | ||
532 | } | 566 | } |
533 | } | 567 | } |
534 | 568 | ||
535 | memset(cfi, 0, sizeof(struct fileIdentDesc)); | 569 | memset(cfi, 0, sizeof(struct fileIdentDesc)); |
536 | if (UDF_SB(sb)->s_udfrev >= 0x0200) | 570 | if (UDF_SB(sb)->s_udfrev >= 0x0200) |
537 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); | 571 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, |
572 | sizeof(tag)); | ||
538 | else | 573 | else |
539 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); | 574 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, |
575 | sizeof(tag)); | ||
540 | cfi->fileVersionNum = cpu_to_le16(1); | 576 | cfi->fileVersionNum = cpu_to_le16(1); |
541 | cfi->lengthFileIdent = namelen; | 577 | cfi->lengthFileIdent = namelen; |
542 | cfi->lengthOfImpUse = cpu_to_le16(0); | 578 | cfi->lengthOfImpUse = cpu_to_le16(0); |
@@ -593,7 +629,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
593 | inode->i_mode = mode; | 629 | inode->i_mode = mode; |
594 | mark_inode_dirty(inode); | 630 | mark_inode_dirty(inode); |
595 | 631 | ||
596 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 632 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
633 | if (!fi) { | ||
597 | inode->i_nlink--; | 634 | inode->i_nlink--; |
598 | mark_inode_dirty(inode); | 635 | mark_inode_dirty(inode); |
599 | iput(inode); | 636 | iput(inode); |
@@ -605,9 +642,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
605 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 642 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
606 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 643 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); |
607 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 644 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
608 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 645 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) |
609 | mark_inode_dirty(dir); | 646 | mark_inode_dirty(dir); |
610 | } | ||
611 | if (fibh.sbh != fibh.ebh) | 647 | if (fibh.sbh != fibh.ebh) |
612 | brelse(fibh.ebh); | 648 | brelse(fibh.ebh); |
613 | brelse(fibh.sbh); | 649 | brelse(fibh.sbh); |
@@ -636,7 +672,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
636 | 672 | ||
637 | inode->i_uid = current->fsuid; | 673 | inode->i_uid = current->fsuid; |
638 | init_special_inode(inode, mode, rdev); | 674 | init_special_inode(inode, mode, rdev); |
639 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 675 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
676 | if (!fi) { | ||
640 | inode->i_nlink--; | 677 | inode->i_nlink--; |
641 | mark_inode_dirty(inode); | 678 | mark_inode_dirty(inode); |
642 | iput(inode); | 679 | iput(inode); |
@@ -648,9 +685,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
648 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 685 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
649 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 686 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); |
650 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 687 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
651 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 688 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) |
652 | mark_inode_dirty(dir); | 689 | mark_inode_dirty(dir); |
653 | } | ||
654 | mark_inode_dirty(inode); | 690 | mark_inode_dirty(inode); |
655 | 691 | ||
656 | if (fibh.sbh != fibh.ebh) | 692 | if (fibh.sbh != fibh.ebh) |
@@ -683,7 +719,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
683 | 719 | ||
684 | inode->i_op = &udf_dir_inode_operations; | 720 | inode->i_op = &udf_dir_inode_operations; |
685 | inode->i_fop = &udf_dir_operations; | 721 | inode->i_fop = &udf_dir_operations; |
686 | if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) { | 722 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); |
723 | if (!fi) { | ||
687 | inode->i_nlink--; | 724 | inode->i_nlink--; |
688 | mark_inode_dirty(inode); | 725 | mark_inode_dirty(inode); |
689 | iput(inode); | 726 | iput(inode); |
@@ -694,7 +731,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
694 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); | 731 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); |
695 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 732 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
696 | cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); | 733 | cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); |
697 | cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; | 734 | cfi.fileCharacteristics = |
735 | FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; | ||
698 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); | 736 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); |
699 | brelse(fibh.sbh); | 737 | brelse(fibh.sbh); |
700 | inode->i_mode = S_IFDIR | mode; | 738 | inode->i_mode = S_IFDIR | mode; |
@@ -702,7 +740,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
702 | inode->i_mode |= S_ISGID; | 740 | inode->i_mode |= S_ISGID; |
703 | mark_inode_dirty(inode); | 741 | mark_inode_dirty(inode); |
704 | 742 | ||
705 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 743 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
744 | if (!fi) { | ||
706 | inode->i_nlink = 0; | 745 | inode->i_nlink = 0; |
707 | mark_inode_dirty(inode); | 746 | mark_inode_dirty(inode); |
708 | iput(inode); | 747 | iput(inode); |
@@ -741,23 +780,25 @@ static int empty_dir(struct inode *dir) | |||
741 | 780 | ||
742 | f_pos = (udf_ext0_offset(dir) >> 2); | 781 | f_pos = (udf_ext0_offset(dir) >> 2); |
743 | 782 | ||
744 | fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 783 | fibh.soffset = fibh.eoffset = |
784 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | ||
745 | 785 | ||
746 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 786 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) |
747 | fibh.sbh = fibh.ebh = NULL; | 787 | fibh.sbh = fibh.ebh = NULL; |
748 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 788 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
749 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | 789 | &epos, &eloc, &elen, &offset) == |
790 | (EXT_RECORDED_ALLOCATED >> 30)) { | ||
750 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 791 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
751 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 792 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
752 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 793 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
753 | epos.offset -= sizeof(short_ad); | 794 | epos.offset -= sizeof(short_ad); |
754 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 795 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
755 | epos.offset -= sizeof(long_ad); | 796 | epos.offset -= sizeof(long_ad); |
756 | } else { | 797 | } else |
757 | offset = 0; | 798 | offset = 0; |
758 | } | ||
759 | 799 | ||
760 | if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { | 800 | fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block); |
801 | if (!fibh.sbh) { | ||
761 | brelse(epos.bh); | 802 | brelse(epos.bh); |
762 | return 0; | 803 | return 0; |
763 | } | 804 | } |
@@ -826,7 +867,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry) | |||
826 | clear_nlink(inode); | 867 | clear_nlink(inode); |
827 | inode->i_size = 0; | 868 | inode->i_size = 0; |
828 | inode_dec_link_count(dir); | 869 | inode_dec_link_count(dir); |
829 | inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); | 870 | inode->i_ctime = dir->i_ctime = dir->i_mtime = |
871 | current_fs_time(dir->i_sb); | ||
830 | mark_inode_dirty(dir); | 872 | mark_inode_dirty(dir); |
831 | 873 | ||
832 | end_rmdir: | 874 | end_rmdir: |
@@ -902,7 +944,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
902 | struct buffer_head *bh; | 944 | struct buffer_head *bh; |
903 | 945 | ||
904 | lock_kernel(); | 946 | lock_kernel(); |
905 | if (!(inode = udf_new_inode(dir, S_IFLNK, &err))) | 947 | inode = udf_new_inode(dir, S_IFLNK, &err); |
948 | if (!inode) | ||
906 | goto out; | 949 | goto out; |
907 | 950 | ||
908 | inode->i_mode = S_IFLNK | S_IRWXUGO; | 951 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
@@ -914,22 +957,24 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
914 | uint32_t elen; | 957 | uint32_t elen; |
915 | 958 | ||
916 | block = udf_new_block(inode->i_sb, inode, | 959 | block = udf_new_block(inode->i_sb, inode, |
917 | UDF_I_LOCATION(inode).partitionReferenceNum, | 960 | UDF_I_LOCATION(inode).partitionReferenceNum, |
918 | UDF_I_LOCATION(inode).logicalBlockNum, &err); | 961 | UDF_I_LOCATION(inode).logicalBlockNum, &err); |
919 | if (!block) | 962 | if (!block) |
920 | goto out_no_entry; | 963 | goto out_no_entry; |
921 | epos.block = UDF_I_LOCATION(inode); | 964 | epos.block = UDF_I_LOCATION(inode); |
922 | epos.offset = udf_file_entry_alloc_offset(inode); | 965 | epos.offset = udf_file_entry_alloc_offset(inode); |
923 | epos.bh = NULL; | 966 | epos.bh = NULL; |
924 | eloc.logicalBlockNum = block; | 967 | eloc.logicalBlockNum = block; |
925 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 968 | eloc.partitionReferenceNum = |
969 | UDF_I_LOCATION(inode).partitionReferenceNum; | ||
926 | elen = inode->i_sb->s_blocksize; | 970 | elen = inode->i_sb->s_blocksize; |
927 | UDF_I_LENEXTENTS(inode) = elen; | 971 | UDF_I_LENEXTENTS(inode) = elen; |
928 | udf_add_aext(inode, &epos, eloc, elen, 0); | 972 | udf_add_aext(inode, &epos, eloc, elen, 0); |
929 | brelse(epos.bh); | 973 | brelse(epos.bh); |
930 | 974 | ||
931 | block = udf_get_pblock(inode->i_sb, block, | 975 | block = udf_get_pblock(inode->i_sb, block, |
932 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); | 976 | UDF_I_LOCATION(inode).partitionReferenceNum, |
977 | 0); | ||
933 | epos.bh = udf_tread(inode->i_sb, block); | 978 | epos.bh = udf_tread(inode->i_sb, block); |
934 | lock_buffer(epos.bh); | 979 | lock_buffer(epos.bh); |
935 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); | 980 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); |
@@ -976,7 +1021,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
976 | if (compstart[0] == '.') { | 1021 | if (compstart[0] == '.') { |
977 | if ((symname - compstart) == 1) | 1022 | if ((symname - compstart) == 1) |
978 | pc->componentType = 4; | 1023 | pc->componentType = 4; |
979 | else if ((symname - compstart) == 2 && compstart[1] == '.') | 1024 | else if ((symname - compstart) == 2 && |
1025 | compstart[1] == '.') | ||
980 | pc->componentType = 3; | 1026 | pc->componentType = 3; |
981 | } | 1027 | } |
982 | 1028 | ||
@@ -986,7 +1032,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
986 | if (!namelen) | 1032 | if (!namelen) |
987 | goto out_no_entry; | 1033 | goto out_no_entry; |
988 | 1034 | ||
989 | if (elen + sizeof(struct pathComponent) + namelen > eoffset) | 1035 | if (elen + sizeof(struct pathComponent) + namelen > |
1036 | eoffset) | ||
990 | goto out_no_entry; | 1037 | goto out_no_entry; |
991 | else | 1038 | else |
992 | pc->lengthComponentIdent = namelen; | 1039 | pc->lengthComponentIdent = namelen; |
@@ -1009,16 +1056,19 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1009 | UDF_I_LENALLOC(inode) = inode->i_size; | 1056 | UDF_I_LENALLOC(inode) = inode->i_size; |
1010 | mark_inode_dirty(inode); | 1057 | mark_inode_dirty(inode); |
1011 | 1058 | ||
1012 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) | 1059 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
1060 | if (!fi) | ||
1013 | goto out_no_entry; | 1061 | goto out_no_entry; |
1014 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 1062 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
1015 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 1063 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); |
1016 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; | 1064 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
1017 | if (bh) { | 1065 | if (bh) { |
1018 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | 1066 | struct logicalVolIntegrityDesc *lvid = |
1067 | (struct logicalVolIntegrityDesc *)bh->b_data; | ||
1019 | struct logicalVolHeaderDesc *lvhd; | 1068 | struct logicalVolHeaderDesc *lvhd; |
1020 | uint64_t uniqueID; | 1069 | uint64_t uniqueID; |
1021 | lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); | 1070 | lvhd = (struct logicalVolHeaderDesc *) |
1071 | lvid->logicalVolContentsUse; | ||
1022 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1072 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
1023 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1073 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
1024 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1074 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
@@ -1028,9 +1078,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1028 | mark_buffer_dirty(bh); | 1078 | mark_buffer_dirty(bh); |
1029 | } | 1079 | } |
1030 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 1080 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
1031 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 1081 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) |
1032 | mark_inode_dirty(dir); | 1082 | mark_inode_dirty(dir); |
1033 | } | ||
1034 | if (fibh.sbh != fibh.ebh) | 1083 | if (fibh.sbh != fibh.ebh) |
1035 | brelse(fibh.ebh); | 1084 | brelse(fibh.ebh); |
1036 | brelse(fibh.sbh); | 1085 | brelse(fibh.sbh); |
@@ -1062,7 +1111,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1062 | return -EMLINK; | 1111 | return -EMLINK; |
1063 | } | 1112 | } |
1064 | 1113 | ||
1065 | if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { | 1114 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
1115 | if (!fi) { | ||
1066 | unlock_kernel(); | 1116 | unlock_kernel(); |
1067 | return err; | 1117 | return err; |
1068 | } | 1118 | } |
@@ -1070,10 +1120,12 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1070 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 1120 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); |
1071 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; | 1121 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
1072 | if (bh) { | 1122 | if (bh) { |
1073 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | 1123 | struct logicalVolIntegrityDesc *lvid = |
1124 | (struct logicalVolIntegrityDesc *)bh->b_data; | ||
1074 | struct logicalVolHeaderDesc *lvhd; | 1125 | struct logicalVolHeaderDesc *lvhd; |
1075 | uint64_t uniqueID; | 1126 | uint64_t uniqueID; |
1076 | lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); | 1127 | lvhd = (struct logicalVolHeaderDesc *) |
1128 | (lvid->logicalVolContentsUse); | ||
1077 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1129 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
1078 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1130 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
1079 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1131 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
@@ -1083,9 +1135,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1083 | mark_buffer_dirty(bh); | 1135 | mark_buffer_dirty(bh); |
1084 | } | 1136 | } |
1085 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 1137 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
1086 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 1138 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) |
1087 | mark_inode_dirty(dir); | 1139 | mark_inode_dirty(dir); |
1088 | } | ||
1089 | 1140 | ||
1090 | if (fibh.sbh != fibh.ebh) | 1141 | if (fibh.sbh != fibh.ebh) |
1091 | brelse(fibh.ebh); | 1142 | brelse(fibh.ebh); |
@@ -1109,13 +1160,15 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1109 | struct inode *old_inode = old_dentry->d_inode; | 1160 | struct inode *old_inode = old_dentry->d_inode; |
1110 | struct inode *new_inode = new_dentry->d_inode; | 1161 | struct inode *new_inode = new_dentry->d_inode; |
1111 | struct udf_fileident_bh ofibh, nfibh; | 1162 | struct udf_fileident_bh ofibh, nfibh; |
1112 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; | 1163 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; |
1164 | struct fileIdentDesc ocfi, ncfi; | ||
1113 | struct buffer_head *dir_bh = NULL; | 1165 | struct buffer_head *dir_bh = NULL; |
1114 | int retval = -ENOENT; | 1166 | int retval = -ENOENT; |
1115 | kernel_lb_addr tloc; | 1167 | kernel_lb_addr tloc; |
1116 | 1168 | ||
1117 | lock_kernel(); | 1169 | lock_kernel(); |
1118 | if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) { | 1170 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
1171 | if (ofi) { | ||
1119 | if (ofibh.sbh != ofibh.ebh) | 1172 | if (ofibh.sbh != ofibh.ebh) |
1120 | brelse(ofibh.ebh); | 1173 | brelse(ofibh.ebh); |
1121 | brelse(ofibh.sbh); | 1174 | brelse(ofibh.sbh); |
@@ -1144,29 +1197,35 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1144 | } | 1197 | } |
1145 | retval = -EIO; | 1198 | retval = -EIO; |
1146 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1199 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { |
1147 | dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - | 1200 | dir_fi = udf_get_fileident( |
1148 | (UDF_I_EFE(old_inode) ? | 1201 | UDF_I_DATA(old_inode) - |
1149 | sizeof(struct extendedFileEntry) : | 1202 | (UDF_I_EFE(old_inode) ? |
1150 | sizeof(struct fileEntry)), | 1203 | sizeof(struct extendedFileEntry) : |
1151 | old_inode->i_sb->s_blocksize, &offset); | 1204 | sizeof(struct fileEntry)), |
1205 | old_inode->i_sb->s_blocksize, &offset); | ||
1152 | } else { | 1206 | } else { |
1153 | dir_bh = udf_bread(old_inode, 0, 0, &retval); | 1207 | dir_bh = udf_bread(old_inode, 0, 0, &retval); |
1154 | if (!dir_bh) | 1208 | if (!dir_bh) |
1155 | goto end_rename; | 1209 | goto end_rename; |
1156 | dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); | 1210 | dir_fi = udf_get_fileident(dir_bh->b_data, |
1211 | old_inode->i_sb->s_blocksize, &offset); | ||
1157 | } | 1212 | } |
1158 | if (!dir_fi) | 1213 | if (!dir_fi) |
1159 | goto end_rename; | 1214 | goto end_rename; |
1160 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); | 1215 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); |
1161 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino) | 1216 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != |
1217 | old_dir->i_ino) | ||
1162 | goto end_rename; | 1218 | goto end_rename; |
1163 | 1219 | ||
1164 | retval = -EMLINK; | 1220 | retval = -EMLINK; |
1165 | if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1) | 1221 | if (!new_inode && |
1222 | new_dir->i_nlink >= | ||
1223 | (256 << sizeof(new_dir->i_nlink)) - 1) | ||
1166 | goto end_rename; | 1224 | goto end_rename; |
1167 | } | 1225 | } |
1168 | if (!nfi) { | 1226 | if (!nfi) { |
1169 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); | 1227 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, |
1228 | &retval); | ||
1170 | if (!nfi) | 1229 | if (!nfi) |
1171 | goto end_rename; | 1230 | goto end_rename; |
1172 | } | 1231 | } |
@@ -1199,17 +1258,18 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1199 | 1258 | ||
1200 | if (dir_fi) { | 1259 | if (dir_fi) { |
1201 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); | 1260 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); |
1202 | udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + | 1261 | udf_update_tag((char *)dir_fi, |
1203 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); | 1262 | (sizeof(struct fileIdentDesc) + |
1204 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1263 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); |
1264 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) | ||
1205 | mark_inode_dirty(old_inode); | 1265 | mark_inode_dirty(old_inode); |
1206 | } else { | 1266 | else |
1207 | mark_buffer_dirty_inode(dir_bh, old_inode); | 1267 | mark_buffer_dirty_inode(dir_bh, old_inode); |
1208 | } | 1268 | |
1209 | inode_dec_link_count(old_dir); | 1269 | inode_dec_link_count(old_dir); |
1210 | if (new_inode) { | 1270 | if (new_inode) |
1211 | inode_dec_link_count(new_inode); | 1271 | inode_dec_link_count(new_inode); |
1212 | } else { | 1272 | else { |
1213 | inc_nlink(new_dir); | 1273 | inc_nlink(new_dir); |
1214 | mark_inode_dirty(new_dir); | 1274 | mark_inode_dirty(new_dir); |
1215 | } | 1275 | } |
diff --git a/fs/udf/partition.c b/fs/udf/partition.c index eeb4714b3641..027c879969f1 100644 --- a/fs/udf/partition.c +++ b/fs/udf/partition.c | |||
@@ -34,8 +34,8 @@ inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, | |||
34 | struct udf_sb_info *sbi = UDF_SB(sb); | 34 | struct udf_sb_info *sbi = UDF_SB(sb); |
35 | struct udf_part_map *map; | 35 | struct udf_part_map *map; |
36 | if (partition >= sbi->s_partitions) { | 36 | if (partition >= sbi->s_partitions) { |
37 | udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", | 37 | udf_debug("block=%d, partition=%d, offset=%d: " |
38 | block, partition, offset); | 38 | "invalid partition\n", block, partition, offset); |
39 | return 0xFFFFFFFF; | 39 | return 0xFFFFFFFF; |
40 | } | 40 | } |
41 | map = &sbi->s_partmaps[partition]; | 41 | map = &sbi->s_partmaps[partition]; |
@@ -54,13 +54,15 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
54 | uint32_t loc; | 54 | uint32_t loc; |
55 | struct udf_sb_info *sbi = UDF_SB(sb); | 55 | struct udf_sb_info *sbi = UDF_SB(sb); |
56 | struct udf_part_map *map; | 56 | struct udf_part_map *map; |
57 | struct udf_virtual_data *vdata; | ||
57 | 58 | ||
58 | map = &sbi->s_partmaps[partition]; | 59 | map = &sbi->s_partmaps[partition]; |
59 | index = (sb->s_blocksize - map->s_type_specific.s_virtual.s_start_offset) / sizeof(uint32_t); | 60 | vdata = &map->s_type_specific.s_virtual; |
61 | index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t); | ||
60 | 62 | ||
61 | if (block > map->s_type_specific.s_virtual.s_num_entries) { | 63 | if (block > vdata->s_num_entries) { |
62 | udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", | 64 | udf_debug("Trying to access block beyond end of VAT " |
63 | block, map->s_type_specific.s_virtual.s_num_entries); | 65 | "(%d max %d)\n", block, vdata->s_num_entries); |
64 | return 0xFFFFFFFF; | 66 | return 0xFFFFFFFF; |
65 | } | 67 | } |
66 | 68 | ||
@@ -70,12 +72,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
70 | index = block % (sb->s_blocksize / sizeof(uint32_t)); | 72 | index = block % (sb->s_blocksize / sizeof(uint32_t)); |
71 | } else { | 73 | } else { |
72 | newblock = 0; | 74 | newblock = 0; |
73 | index = map->s_type_specific.s_virtual.s_start_offset / sizeof(uint32_t) + block; | 75 | index = vdata->s_start_offset / sizeof(uint32_t) + block; |
74 | } | 76 | } |
75 | 77 | ||
76 | loc = udf_block_map(sbi->s_vat_inode, newblock); | 78 | loc = udf_block_map(sbi->s_vat_inode, newblock); |
77 | 79 | ||
78 | if (!(bh = sb_bread(sb, loc))) { | 80 | bh = sb_bread(sb, loc); |
81 | if (!bh) { | ||
79 | udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", | 82 | udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", |
80 | sb, block, partition, loc, index); | 83 | sb, block, partition, loc, index); |
81 | return 0xFFFFFFFF; | 84 | return 0xFFFFFFFF; |
@@ -85,17 +88,19 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, | |||
85 | 88 | ||
86 | brelse(bh); | 89 | brelse(bh); |
87 | 90 | ||
88 | if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum == partition) { | 91 | if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum == |
92 | partition) { | ||
89 | udf_debug("recursive call to udf_get_pblock!\n"); | 93 | udf_debug("recursive call to udf_get_pblock!\n"); |
90 | return 0xFFFFFFFF; | 94 | return 0xFFFFFFFF; |
91 | } | 95 | } |
92 | 96 | ||
93 | return udf_get_pblock(sb, loc, | 97 | return udf_get_pblock(sb, loc, |
94 | UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum, | 98 | UDF_I_LOCATION(sbi->s_vat_inode). |
99 | partitionReferenceNum, | ||
95 | offset); | 100 | offset); |
96 | } | 101 | } |
97 | 102 | ||
98 | 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, |
99 | uint16_t partition, uint32_t offset) | 104 | uint16_t partition, uint32_t offset) |
100 | { | 105 | { |
101 | return udf_get_pblock_virt15(sb, block, partition, offset); | 106 | return udf_get_pblock_virt15(sb, block, partition, offset); |
@@ -109,27 +114,32 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, | |||
109 | struct udf_sb_info *sbi = UDF_SB(sb); | 114 | struct udf_sb_info *sbi = UDF_SB(sb); |
110 | struct udf_part_map *map; | 115 | struct udf_part_map *map; |
111 | uint32_t packet; | 116 | uint32_t packet; |
117 | struct udf_sparing_data *sdata; | ||
112 | 118 | ||
113 | map = &sbi->s_partmaps[partition]; | 119 | map = &sbi->s_partmaps[partition]; |
114 | packet = (block + offset) & ~(map->s_type_specific.s_sparing.s_packet_len - 1); | 120 | sdata = &map->s_type_specific.s_sparing; |
121 | packet = (block + offset) & ~(sdata->s_packet_len - 1); | ||
115 | 122 | ||
116 | for (i = 0; i < 4; i++) { | 123 | for (i = 0; i < 4; i++) { |
117 | if (map->s_type_specific.s_sparing.s_spar_map[i] != NULL) { | 124 | if (sdata->s_spar_map[i] != NULL) { |
118 | st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[i]->b_data; | 125 | st = (struct sparingTable *) |
126 | sdata->s_spar_map[i]->b_data; | ||
119 | break; | 127 | break; |
120 | } | 128 | } |
121 | } | 129 | } |
122 | 130 | ||
123 | if (st) { | 131 | if (st) { |
124 | for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { | 132 | for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { |
125 | 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) | ||
126 | break; | 136 | break; |
127 | } else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) { | 137 | else if (origLoc == packet) |
128 | return le32_to_cpu(st->mapEntry[i].mappedLocation) + | 138 | return le32_to_cpu(entry->mappedLocation) + |
129 | ((block + offset) & (map->s_type_specific.s_sparing.s_packet_len - 1)); | 139 | ((block + offset) & |
130 | } else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) { | 140 | (sdata->s_packet_len - 1)); |
141 | else if (origLoc > packet) | ||
131 | break; | 142 | break; |
132 | } | ||
133 | } | 143 | } |
134 | } | 144 | } |
135 | 145 | ||
@@ -144,63 +154,101 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) | |||
144 | uint32_t packet; | 154 | uint32_t packet; |
145 | int i, j, k, l; | 155 | int i, j, k, l; |
146 | struct udf_sb_info *sbi = UDF_SB(sb); | 156 | struct udf_sb_info *sbi = UDF_SB(sb); |
157 | u16 reallocationTableLen; | ||
158 | struct buffer_head *bh; | ||
147 | 159 | ||
148 | for (i = 0; i < sbi->s_partitions; i++) { | 160 | for (i = 0; i < sbi->s_partitions; i++) { |
149 | struct udf_part_map *map = &sbi->s_partmaps[i]; | 161 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
150 | if (old_block > map->s_partition_root && | 162 | if (old_block > map->s_partition_root && |
151 | old_block < map->s_partition_root + map->s_partition_len) { | 163 | old_block < map->s_partition_root + map->s_partition_len) { |
152 | sdata = &map->s_type_specific.s_sparing; | 164 | sdata = &map->s_type_specific.s_sparing; |
153 | packet = (old_block - map->s_partition_root) & ~(sdata->s_packet_len - 1); | 165 | packet = (old_block - map->s_partition_root) & |
166 | ~(sdata->s_packet_len - 1); | ||
154 | 167 | ||
155 | for (j = 0; j < 4; j++) { | 168 | for (j = 0; j < 4; j++) |
156 | if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) { | 169 | if (sdata->s_spar_map[j] != NULL) { |
157 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 170 | st = (struct sparingTable *) |
171 | sdata->s_spar_map[j]->b_data; | ||
158 | break; | 172 | break; |
159 | } | 173 | } |
160 | } | ||
161 | 174 | ||
162 | if (!st) | 175 | if (!st) |
163 | return 1; | 176 | return 1; |
164 | 177 | ||
165 | for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) { | 178 | reallocationTableLen = |
166 | 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) { | ||
167 | for (; j < 4; j++) { | 185 | for (; j < 4; j++) { |
168 | if (sdata->s_spar_map[j]) { | 186 | int len; |
169 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 187 | bh = sdata->s_spar_map[j]; |
170 | st->mapEntry[k].origLocation = cpu_to_le32(packet); | 188 | if (!bh) |
171 | udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); | 189 | continue; |
172 | mark_buffer_dirty(sdata->s_spar_map[j]); | 190 | |
173 | } | 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); | ||
174 | } | 201 | } |
175 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 202 | *new_block = le32_to_cpu( |
176 | ((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); | 203 | entry->mappedLocation) + |
204 | ((old_block - | ||
205 | map->s_partition_root) & | ||
206 | (sdata->s_packet_len - 1)); | ||
177 | return 0; | 207 | return 0; |
178 | } else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) { | 208 | } else if (origLoc == packet) { |
179 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 209 | *new_block = le32_to_cpu( |
180 | ((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); | 210 | entry->mappedLocation) + |
211 | ((old_block - | ||
212 | map->s_partition_root) & | ||
213 | (sdata->s_packet_len - 1)); | ||
181 | return 0; | 214 | return 0; |
182 | } else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) { | 215 | } else if (origLoc > packet) |
183 | break; | 216 | break; |
184 | } | ||
185 | } | 217 | } |
186 | 218 | ||
187 | for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) { | 219 | for (l = k; l < reallocationTableLen; l++) { |
188 | if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) { | 220 | struct sparingEntry *entry = &st->mapEntry[l]; |
189 | for (; j < 4; j++) { | 221 | u32 origLoc = le32_to_cpu(entry->origLocation); |
190 | if (sdata->s_spar_map[j]) { | 222 | |
191 | st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; | 223 | if (origLoc != 0xFFFFFFFF) |
192 | mapEntry = st->mapEntry[l]; | 224 | continue; |
193 | mapEntry.origLocation = cpu_to_le32(packet); | 225 | |
194 | memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry)); | 226 | for (; j < 4; j++) { |
195 | st->mapEntry[k] = mapEntry; | 227 | bh = sdata->s_spar_map[j]; |
196 | udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); | 228 | if (!bh) |
197 | mark_buffer_dirty(sdata->s_spar_map[j]); | 229 | continue; |
198 | } | 230 | |
199 | } | 231 | st = (struct sparingTable *)bh->b_data; |
200 | *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + | 232 | mapEntry = st->mapEntry[l]; |
201 | ((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); | 233 | mapEntry.origLocation = |
202 | 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); | ||
203 | } | 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; | ||
204 | } | 252 | } |
205 | 253 | ||
206 | return 1; | 254 | return 1; |
diff --git a/fs/udf/super.c b/fs/udf/super.c index 3cd5a855033b..7f75a949e152 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c | |||
@@ -98,9 +98,11 @@ static int udf_statfs(struct dentry *, struct kstatfs *); | |||
98 | 98 | ||
99 | struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) | 99 | struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) |
100 | { | 100 | { |
101 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | 101 | struct logicalVolIntegrityDesc *lvid = |
102 | (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | ||
102 | __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions); | 103 | __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions); |
103 | __u32 offset = number_of_partitions * 2 * sizeof(uint32_t)/sizeof(uint8_t); | 104 | __u32 offset = number_of_partitions * 2 * |
105 | sizeof(uint32_t)/sizeof(uint8_t); | ||
104 | return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); | 106 | return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); |
105 | } | 107 | } |
106 | 108 | ||
@@ -713,16 +715,23 @@ static void udf_find_anchor(struct super_block *sb) | |||
713 | lastblock = last[i] - sbi->s_session; | 715 | lastblock = last[i] - sbi->s_session; |
714 | sbi->s_anchor[0] = lastblock; | 716 | sbi->s_anchor[0] = lastblock; |
715 | sbi->s_anchor[1] = lastblock - 256; | 717 | sbi->s_anchor[1] = lastblock - 256; |
716 | } else if (location == udf_variable_to_fixed(last[i]) - sbi->s_session) { | 718 | } else if (location == |
719 | udf_variable_to_fixed(last[i]) - | ||
720 | sbi->s_session) { | ||
717 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | 721 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); |
718 | lastblock = udf_variable_to_fixed(last[i]) - sbi->s_session; | 722 | lastblock = |
723 | udf_variable_to_fixed(last[i]) - | ||
724 | sbi->s_session; | ||
719 | sbi->s_anchor[0] = lastblock; | 725 | sbi->s_anchor[0] = lastblock; |
720 | sbi->s_anchor[1] = lastblock - 256 - sbi->s_session; | 726 | sbi->s_anchor[1] = lastblock - 256 - |
727 | sbi->s_session; | ||
721 | } else { | 728 | } else { |
722 | udf_debug("Anchor found at block %d, location mismatch %d.\n", | 729 | udf_debug("Anchor found at block %d, " |
730 | "location mismatch %d.\n", | ||
723 | last[i], location); | 731 | last[i], location); |
724 | } | 732 | } |
725 | } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) { | 733 | } else if (ident == TAG_IDENT_FE || |
734 | ident == TAG_IDENT_EFE) { | ||
726 | lastblock = last[i]; | 735 | lastblock = last[i]; |
727 | sbi->s_anchor[3] = 512; | 736 | sbi->s_anchor[3] = 512; |
728 | } else { | 737 | } else { |
@@ -731,31 +740,40 @@ static void udf_find_anchor(struct super_block *sb) | |||
731 | bh = sb_bread(sb, last[i] - 256); | 740 | bh = sb_bread(sb, last[i] - 256); |
732 | if (bh) { | 741 | if (bh) { |
733 | tag *t = (tag *)bh->b_data; | 742 | tag *t = (tag *)bh->b_data; |
734 | ident = le16_to_cpu(t->tagIdent); | 743 | ident = le16_to_cpu( |
735 | location = le32_to_cpu(t->tagLocation); | 744 | t->tagIdent); |
745 | location = le32_to_cpu( | ||
746 | t->tagLocation); | ||
736 | brelse(bh); | 747 | brelse(bh); |
737 | } | 748 | } |
738 | } | 749 | } |
739 | 750 | ||
740 | if (ident == TAG_IDENT_AVDP && | 751 | if (ident == TAG_IDENT_AVDP && |
741 | location == last[i] - 256 - sbi->s_session) { | 752 | location == last[i] - 256 - |
753 | sbi->s_session) { | ||
742 | lastblock = last[i]; | 754 | lastblock = last[i]; |
743 | sbi->s_anchor[1] = last[i] - 256; | 755 | sbi->s_anchor[1] = last[i] - 256; |
744 | } else { | 756 | } else { |
745 | ident = location = 0; | 757 | ident = location = 0; |
746 | if (last[i] >= 312 + sbi->s_session) { | 758 | if (last[i] >= 312 + sbi->s_session) { |
747 | bh = sb_bread(sb, last[i] - 312 - sbi->s_session); | 759 | bh = sb_bread(sb, |
760 | last[i] - 312 - | ||
761 | sbi->s_session); | ||
748 | if (bh) { | 762 | if (bh) { |
749 | tag *t = (tag *)bh->b_data; | 763 | tag *t = (tag *) |
750 | ident = le16_to_cpu(t->tagIdent); | 764 | bh->b_data; |
751 | location = le32_to_cpu(t->tagLocation); | 765 | ident = le16_to_cpu( |
766 | t->tagIdent); | ||
767 | location = le32_to_cpu( | ||
768 | t->tagLocation); | ||
752 | brelse(bh); | 769 | brelse(bh); |
753 | } | 770 | } |
754 | } | 771 | } |
755 | 772 | ||
756 | if (ident == TAG_IDENT_AVDP && | 773 | if (ident == TAG_IDENT_AVDP && |
757 | location == udf_variable_to_fixed(last[i]) - 256) { | 774 | location == udf_variable_to_fixed(last[i]) - 256) { |
758 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | 775 | UDF_SET_FLAG(sb, |
776 | UDF_FLAG_VARCONV); | ||
759 | lastblock = udf_variable_to_fixed(last[i]); | 777 | lastblock = udf_variable_to_fixed(last[i]); |
760 | sbi->s_anchor[1] = lastblock - 256; | 778 | sbi->s_anchor[1] = lastblock - 256; |
761 | } | 779 | } |
@@ -787,7 +805,8 @@ static void udf_find_anchor(struct super_block *sb) | |||
787 | else { | 805 | else { |
788 | brelse(bh); | 806 | brelse(bh); |
789 | if ((ident != TAG_IDENT_AVDP) && | 807 | if ((ident != TAG_IDENT_AVDP) && |
790 | (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) | 808 | (i || (ident != TAG_IDENT_FE && |
809 | ident != TAG_IDENT_EFE))) | ||
791 | sbi->s_anchor[i] = 0; | 810 | sbi->s_anchor[i] = 0; |
792 | } | 811 | } |
793 | } | 812 | } |
@@ -848,11 +867,12 @@ static int udf_find_fileset(struct super_block *sb, | |||
848 | case TAG_IDENT_SBD: | 867 | case TAG_IDENT_SBD: |
849 | { | 868 | { |
850 | struct spaceBitmapDesc *sp; | 869 | struct spaceBitmapDesc *sp; |
851 | sp = (struct spaceBitmapDesc *)bh->b_data; | 870 | sp = (struct spaceBitmapDesc *) |
871 | bh->b_data; | ||
852 | newfileset.logicalBlockNum += 1 + | 872 | newfileset.logicalBlockNum += 1 + |
853 | ((le32_to_cpu(sp->numOfBytes) + | 873 | ((le32_to_cpu(sp->numOfBytes) + |
854 | sizeof(struct spaceBitmapDesc) - 1) | 874 | sizeof(struct spaceBitmapDesc) |
855 | >> sb->s_blocksize_bits); | 875 | - 1) >> sb->s_blocksize_bits); |
856 | brelse(bh); | 876 | brelse(bh); |
857 | break; | 877 | break; |
858 | } | 878 | } |
@@ -908,18 +928,17 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh) | |||
908 | UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000; | 928 | UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000; |
909 | } | 929 | } |
910 | 930 | ||
911 | if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) { | 931 | if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) |
912 | if (udf_CS0toUTF8(&outstr, &instr)) { | 932 | if (udf_CS0toUTF8(&outstr, &instr)) { |
913 | strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name, | 933 | strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name, |
914 | outstr.u_len > 31 ? 31 : outstr.u_len); | 934 | outstr.u_len > 31 ? 31 : outstr.u_len); |
915 | udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident); | 935 | udf_debug("volIdent[] = '%s'\n", |
936 | UDF_SB(sb)->s_volume_ident); | ||
916 | } | 937 | } |
917 | } | ||
918 | 938 | ||
919 | if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) { | 939 | if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) |
920 | if (udf_CS0toUTF8(&outstr, &instr)) | 940 | if (udf_CS0toUTF8(&outstr, &instr)) |
921 | udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); | 941 | udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); |
922 | } | ||
923 | } | 942 | } |
924 | 943 | ||
925 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, | 944 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, |
@@ -987,18 +1006,30 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
987 | for (i = 0; i < sbi->s_partitions; i++) { | 1006 | for (i = 0; i < sbi->s_partitions; i++) { |
988 | map = &sbi->s_partmaps[i]; | 1007 | map = &sbi->s_partmaps[i]; |
989 | udf_debug("Searching map: (%d == %d)\n", | 1008 | udf_debug("Searching map: (%d == %d)\n", |
990 | map->s_partition_num, le16_to_cpu(p->partitionNumber)); | 1009 | map->s_partition_num, |
991 | if (map->s_partition_num == le16_to_cpu(p->partitionNumber)) { | 1010 | le16_to_cpu(p->partitionNumber)); |
992 | map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */ | 1011 | if (map->s_partition_num == |
993 | map->s_partition_root = le32_to_cpu(p->partitionStartingLocation); | 1012 | le16_to_cpu(p->partitionNumber)) { |
994 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) | 1013 | map->s_partition_len = |
995 | map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY; | 1014 | le32_to_cpu(p->partitionLength); /* blocks */ |
996 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE) | 1015 | map->s_partition_root = |
997 | map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE; | 1016 | le32_to_cpu(p->partitionStartingLocation); |
998 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE) | 1017 | if (le32_to_cpu(p->accessType) == |
999 | map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE; | 1018 | PD_ACCESS_TYPE_READ_ONLY) |
1000 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE) | 1019 | map->s_partition_flags |= |
1001 | map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE; | 1020 | UDF_PART_FLAG_READ_ONLY; |
1021 | if (le32_to_cpu(p->accessType) == | ||
1022 | PD_ACCESS_TYPE_WRITE_ONCE) | ||
1023 | map->s_partition_flags |= | ||
1024 | UDF_PART_FLAG_WRITE_ONCE; | ||
1025 | if (le32_to_cpu(p->accessType) == | ||
1026 | PD_ACCESS_TYPE_REWRITABLE) | ||
1027 | map->s_partition_flags |= | ||
1028 | UDF_PART_FLAG_REWRITABLE; | ||
1029 | if (le32_to_cpu(p->accessType) == | ||
1030 | PD_ACCESS_TYPE_OVERWRITABLE) | ||
1031 | map->s_partition_flags |= | ||
1032 | UDF_PART_FLAG_OVERWRITABLE; | ||
1002 | 1033 | ||
1003 | if (!strcmp(p->partitionContents.ident, | 1034 | if (!strcmp(p->partitionContents.ident, |
1004 | PD_PARTITION_CONTENTS_NSR02) || | 1035 | PD_PARTITION_CONTENTS_NSR02) || |
@@ -1006,7 +1037,8 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
1006 | PD_PARTITION_CONTENTS_NSR03)) { | 1037 | PD_PARTITION_CONTENTS_NSR03)) { |
1007 | struct partitionHeaderDesc *phd; | 1038 | struct partitionHeaderDesc *phd; |
1008 | 1039 | ||
1009 | phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); | 1040 | phd = (struct partitionHeaderDesc *) |
1041 | (p->partitionContentsUse); | ||
1010 | if (phd->unallocSpaceTable.extLength) { | 1042 | if (phd->unallocSpaceTable.extLength) { |
1011 | kernel_lb_addr loc = { | 1043 | kernel_lb_addr loc = { |
1012 | .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), | 1044 | .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), |
@@ -1019,20 +1051,23 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
1019 | udf_debug("cannot load unallocSpaceTable (part %d)\n", i); | 1051 | udf_debug("cannot load unallocSpaceTable (part %d)\n", i); |
1020 | return 1; | 1052 | return 1; |
1021 | } | 1053 | } |
1022 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; | 1054 | map->s_partition_flags |= |
1055 | UDF_PART_FLAG_UNALLOC_TABLE; | ||
1023 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", | 1056 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", |
1024 | i, map->s_uspace.s_table->i_ino); | 1057 | i, map->s_uspace.s_table->i_ino); |
1025 | } | 1058 | } |
1026 | if (phd->unallocSpaceBitmap.extLength) { | 1059 | if (phd->unallocSpaceBitmap.extLength) { |
1027 | map->s_uspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); | 1060 | struct udf_bitmap *bitmap = |
1028 | if (map->s_uspace.s_bitmap != NULL) { | 1061 | udf_sb_alloc_bitmap(sb, i); |
1029 | map->s_uspace.s_bitmap->s_extLength = | 1062 | map->s_uspace.s_bitmap = bitmap; |
1063 | if (bitmap != NULL) { | ||
1064 | bitmap->s_extLength = | ||
1030 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); | 1065 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); |
1031 | map->s_uspace.s_bitmap->s_extPosition = | 1066 | bitmap->s_extPosition = |
1032 | le32_to_cpu(phd->unallocSpaceBitmap.extPosition); | 1067 | le32_to_cpu(phd->unallocSpaceBitmap.extPosition); |
1033 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; | 1068 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; |
1034 | udf_debug("unallocSpaceBitmap (part %d) @ %d\n", | 1069 | udf_debug("unallocSpaceBitmap (part %d) @ %d\n", |
1035 | i, map->s_uspace.s_bitmap->s_extPosition); | 1070 | i, bitmap->s_extPosition); |
1036 | } | 1071 | } |
1037 | } | 1072 | } |
1038 | if (phd->partitionIntegrityTable.extLength) | 1073 | if (phd->partitionIntegrityTable.extLength) |
@@ -1049,37 +1084,39 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
1049 | udf_debug("cannot load freedSpaceTable (part %d)\n", i); | 1084 | udf_debug("cannot load freedSpaceTable (part %d)\n", i); |
1050 | return 1; | 1085 | return 1; |
1051 | } | 1086 | } |
1052 | map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; | 1087 | map->s_partition_flags |= |
1088 | UDF_PART_FLAG_FREED_TABLE; | ||
1053 | udf_debug("freedSpaceTable (part %d) @ %ld\n", | 1089 | udf_debug("freedSpaceTable (part %d) @ %ld\n", |
1054 | i, map->s_fspace.s_table->i_ino); | 1090 | i, map->s_fspace.s_table->i_ino); |
1055 | } | 1091 | } |
1056 | if (phd->freedSpaceBitmap.extLength) { | 1092 | if (phd->freedSpaceBitmap.extLength) { |
1057 | map->s_fspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); | 1093 | struct udf_bitmap *bitmap = |
1058 | if (map->s_fspace.s_bitmap != NULL) { | 1094 | udf_sb_alloc_bitmap(sb, i); |
1059 | map->s_fspace.s_bitmap->s_extLength = | 1095 | map->s_fspace.s_bitmap = bitmap; |
1096 | if (bitmap != NULL) { | ||
1097 | bitmap->s_extLength = | ||
1060 | le32_to_cpu(phd->freedSpaceBitmap.extLength); | 1098 | le32_to_cpu(phd->freedSpaceBitmap.extLength); |
1061 | map->s_fspace.s_bitmap->s_extPosition = | 1099 | bitmap->s_extPosition = |
1062 | le32_to_cpu(phd->freedSpaceBitmap.extPosition); | 1100 | le32_to_cpu(phd->freedSpaceBitmap.extPosition); |
1063 | map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; | 1101 | map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; |
1064 | udf_debug("freedSpaceBitmap (part %d) @ %d\n", | 1102 | udf_debug("freedSpaceBitmap (part %d) @ %d\n", |
1065 | i, map->s_fspace.s_bitmap->s_extPosition); | 1103 | i, bitmap->s_extPosition); |
1066 | } | 1104 | } |
1067 | } | 1105 | } |
1068 | } | 1106 | } |
1069 | break; | 1107 | break; |
1070 | } | 1108 | } |
1071 | } | 1109 | } |
1072 | if (i == sbi->s_partitions) { | 1110 | if (i == sbi->s_partitions) |
1073 | udf_debug("Partition (%d) not found in partition map\n", | 1111 | udf_debug("Partition (%d) not found in partition map\n", |
1074 | le16_to_cpu(p->partitionNumber)); | 1112 | le16_to_cpu(p->partitionNumber)); |
1075 | } else { | 1113 | else |
1076 | udf_debug("Partition (%d:%d type %x) starts at physical %d, " | 1114 | udf_debug("Partition (%d:%d type %x) starts at physical %d, " |
1077 | "block length %d\n", | 1115 | "block length %d\n", |
1078 | le16_to_cpu(p->partitionNumber), i, | 1116 | le16_to_cpu(p->partitionNumber), i, |
1079 | map->s_partition_type, | 1117 | map->s_partition_type, |
1080 | map->s_partition_root, | 1118 | map->s_partition_root, |
1081 | map->s_partition_len); | 1119 | map->s_partition_len); |
1082 | } | ||
1083 | return 0; | 1120 | return 0; |
1084 | } | 1121 | } |
1085 | 1122 | ||
@@ -1090,6 +1127,7 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh, | |||
1090 | int i, j, offset; | 1127 | int i, j, offset; |
1091 | uint8_t type; | 1128 | uint8_t type; |
1092 | struct udf_sb_info *sbi = UDF_SB(sb); | 1129 | struct udf_sb_info *sbi = UDF_SB(sb); |
1130 | struct genericPartitionMap *gpm; | ||
1093 | 1131 | ||
1094 | lvd = (struct logicalVolDesc *)bh->b_data; | 1132 | lvd = (struct logicalVolDesc *)bh->b_data; |
1095 | 1133 | ||
@@ -1099,43 +1137,71 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh, | |||
1099 | 1137 | ||
1100 | for (i = 0, offset = 0; | 1138 | for (i = 0, offset = 0; |
1101 | i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); | 1139 | i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); |
1102 | i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) { | 1140 | i++, offset += gpm->partitionMapLength) { |
1103 | struct udf_part_map *map = &sbi->s_partmaps[i]; | 1141 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
1104 | type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; | 1142 | gpm = (struct genericPartitionMap *) |
1143 | &(lvd->partitionMaps[offset]); | ||
1144 | type = gpm->partitionMapType; | ||
1105 | if (type == 1) { | 1145 | if (type == 1) { |
1106 | struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); | 1146 | struct genericPartitionMap1 *gpm1 = |
1147 | (struct genericPartitionMap1 *)gpm; | ||
1107 | map->s_partition_type = UDF_TYPE1_MAP15; | 1148 | map->s_partition_type = UDF_TYPE1_MAP15; |
1108 | map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum); | 1149 | map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum); |
1109 | map->s_partition_num = le16_to_cpu(gpm1->partitionNum); | 1150 | map->s_partition_num = le16_to_cpu(gpm1->partitionNum); |
1110 | map->s_partition_func = NULL; | 1151 | map->s_partition_func = NULL; |
1111 | } else if (type == 2) { | 1152 | } else if (type == 2) { |
1112 | struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); | 1153 | struct udfPartitionMap2 *upm2 = |
1113 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) { | 1154 | (struct udfPartitionMap2 *)gpm; |
1114 | if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) { | 1155 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, |
1115 | map->s_partition_type = UDF_VIRTUAL_MAP15; | 1156 | strlen(UDF_ID_VIRTUAL))) { |
1116 | map->s_partition_func = udf_get_pblock_virt15; | 1157 | u16 suf = |
1117 | } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) { | 1158 | le16_to_cpu(((__le16 *)upm2->partIdent. |
1118 | map->s_partition_type = UDF_VIRTUAL_MAP20; | 1159 | identSuffix)[0]); |
1119 | map->s_partition_func = udf_get_pblock_virt20; | 1160 | if (suf == 0x0150) { |
1161 | map->s_partition_type = | ||
1162 | UDF_VIRTUAL_MAP15; | ||
1163 | map->s_partition_func = | ||
1164 | udf_get_pblock_virt15; | ||
1165 | } else if (suf == 0x0200) { | ||
1166 | map->s_partition_type = | ||
1167 | UDF_VIRTUAL_MAP20; | ||
1168 | map->s_partition_func = | ||
1169 | udf_get_pblock_virt20; | ||
1120 | } | 1170 | } |
1121 | } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) { | 1171 | } else if (!strncmp(upm2->partIdent.ident, |
1172 | UDF_ID_SPARABLE, | ||
1173 | strlen(UDF_ID_SPARABLE))) { | ||
1122 | uint32_t loc; | 1174 | uint32_t loc; |
1123 | uint16_t ident; | 1175 | uint16_t ident; |
1124 | struct sparingTable *st; | 1176 | struct sparingTable *st; |
1125 | struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]); | 1177 | struct sparablePartitionMap *spm = |
1178 | (struct sparablePartitionMap *)gpm; | ||
1126 | 1179 | ||
1127 | map->s_partition_type = UDF_SPARABLE_MAP15; | 1180 | map->s_partition_type = UDF_SPARABLE_MAP15; |
1128 | map->s_type_specific.s_sparing.s_packet_len = le16_to_cpu(spm->packetLength); | 1181 | map->s_type_specific.s_sparing.s_packet_len = |
1182 | le16_to_cpu(spm->packetLength); | ||
1129 | for (j = 0; j < spm->numSparingTables; j++) { | 1183 | for (j = 0; j < spm->numSparingTables; j++) { |
1130 | loc = le32_to_cpu(spm->locSparingTable[j]); | 1184 | struct buffer_head *bh2; |
1131 | map->s_type_specific.s_sparing.s_spar_map[j] = | 1185 | |
1132 | udf_read_tagged(sb, loc, loc, &ident); | 1186 | loc = le32_to_cpu( |
1133 | if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) { | 1187 | spm->locSparingTable[j]); |
1134 | st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[j]->b_data; | 1188 | bh2 = udf_read_tagged(sb, loc, loc, |
1135 | if (ident != 0 || | 1189 | &ident); |
1136 | strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) { | 1190 | map->s_type_specific.s_sparing. |
1137 | brelse(map->s_type_specific.s_sparing.s_spar_map[j]); | 1191 | s_spar_map[j] = bh2; |
1138 | map->s_type_specific.s_sparing.s_spar_map[j] = NULL; | 1192 | |
1193 | if (bh2 != NULL) { | ||
1194 | st = (struct sparingTable *) | ||
1195 | bh2->b_data; | ||
1196 | if (ident != 0 || strncmp( | ||
1197 | st->sparingIdent.ident, | ||
1198 | UDF_ID_SPARING, | ||
1199 | strlen(UDF_ID_SPARING))) { | ||
1200 | brelse(bh2); | ||
1201 | map->s_type_specific. | ||
1202 | s_sparing. | ||
1203 | s_spar_map[j] = | ||
1204 | NULL; | ||
1139 | } | 1205 | } |
1140 | } | 1206 | } |
1141 | } | 1207 | } |
@@ -1218,6 +1284,7 @@ static int udf_process_sequence(struct super_block *sb, long block, | |||
1218 | { | 1284 | { |
1219 | struct buffer_head *bh = NULL; | 1285 | struct buffer_head *bh = NULL; |
1220 | struct udf_vds_record vds[VDS_POS_LENGTH]; | 1286 | struct udf_vds_record vds[VDS_POS_LENGTH]; |
1287 | struct udf_vds_record *curr; | ||
1221 | struct generic_desc *gd; | 1288 | struct generic_desc *gd; |
1222 | struct volDescPtr *vdp; | 1289 | struct volDescPtr *vdp; |
1223 | int done = 0; | 1290 | int done = 0; |
@@ -1240,43 +1307,51 @@ static int udf_process_sequence(struct super_block *sb, long block, | |||
1240 | vdsn = le32_to_cpu(gd->volDescSeqNum); | 1307 | vdsn = le32_to_cpu(gd->volDescSeqNum); |
1241 | switch (ident) { | 1308 | switch (ident) { |
1242 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ | 1309 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ |
1243 | if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) { | 1310 | curr = &vds[VDS_POS_PRIMARY_VOL_DESC]; |
1244 | vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; | 1311 | if (vdsn >= curr->volDescSeqNum) { |
1245 | vds[VDS_POS_PRIMARY_VOL_DESC].block = block; | 1312 | curr->volDescSeqNum = vdsn; |
1313 | curr->block = block; | ||
1246 | } | 1314 | } |
1247 | break; | 1315 | break; |
1248 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ | 1316 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ |
1249 | if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) { | 1317 | curr = &vds[VDS_POS_VOL_DESC_PTR]; |
1250 | vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; | 1318 | if (vdsn >= curr->volDescSeqNum) { |
1251 | vds[VDS_POS_VOL_DESC_PTR].block = block; | 1319 | curr->volDescSeqNum = vdsn; |
1320 | curr->block = block; | ||
1252 | 1321 | ||
1253 | vdp = (struct volDescPtr *)bh->b_data; | 1322 | vdp = (struct volDescPtr *)bh->b_data; |
1254 | next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); | 1323 | next_s = le32_to_cpu( |
1255 | next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); | 1324 | vdp->nextVolDescSeqExt.extLocation); |
1325 | next_e = le32_to_cpu( | ||
1326 | vdp->nextVolDescSeqExt.extLength); | ||
1256 | next_e = next_e >> sb->s_blocksize_bits; | 1327 | next_e = next_e >> sb->s_blocksize_bits; |
1257 | next_e += next_s; | 1328 | next_e += next_s; |
1258 | } | 1329 | } |
1259 | break; | 1330 | break; |
1260 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ | 1331 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ |
1261 | if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) { | 1332 | curr = &vds[VDS_POS_IMP_USE_VOL_DESC]; |
1262 | vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; | 1333 | if (vdsn >= curr->volDescSeqNum) { |
1263 | vds[VDS_POS_IMP_USE_VOL_DESC].block = block; | 1334 | curr->volDescSeqNum = vdsn; |
1335 | curr->block = block; | ||
1264 | } | 1336 | } |
1265 | break; | 1337 | break; |
1266 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ | 1338 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ |
1267 | if (!vds[VDS_POS_PARTITION_DESC].block) | 1339 | curr = &vds[VDS_POS_PARTITION_DESC]; |
1268 | vds[VDS_POS_PARTITION_DESC].block = block; | 1340 | if (!curr->block) |
1341 | curr->block = block; | ||
1269 | break; | 1342 | break; |
1270 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ | 1343 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ |
1271 | if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) { | 1344 | curr = &vds[VDS_POS_LOGICAL_VOL_DESC]; |
1272 | vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; | 1345 | if (vdsn >= curr->volDescSeqNum) { |
1273 | vds[VDS_POS_LOGICAL_VOL_DESC].block = block; | 1346 | curr->volDescSeqNum = vdsn; |
1347 | curr->block = block; | ||
1274 | } | 1348 | } |
1275 | break; | 1349 | break; |
1276 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ | 1350 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ |
1277 | if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) { | 1351 | curr = &vds[VDS_POS_UNALLOC_SPACE_DESC]; |
1278 | vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; | 1352 | if (vdsn >= curr->volDescSeqNum) { |
1279 | vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; | 1353 | curr->volDescSeqNum = vdsn; |
1354 | curr->block = block; | ||
1280 | } | 1355 | } |
1281 | break; | 1356 | break; |
1282 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ | 1357 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ |
@@ -1285,9 +1360,8 @@ static int udf_process_sequence(struct super_block *sb, long block, | |||
1285 | block = next_s; | 1360 | block = next_s; |
1286 | lastblock = next_e; | 1361 | lastblock = next_e; |
1287 | next_s = next_e = 0; | 1362 | next_s = next_e = 0; |
1288 | } else { | 1363 | } else |
1289 | done = 1; | 1364 | done = 1; |
1290 | } | ||
1291 | break; | 1365 | break; |
1292 | } | 1366 | } |
1293 | brelse(bh); | 1367 | brelse(bh); |
@@ -1379,14 +1453,18 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
1379 | anchor = (struct anchorVolDescPtr *)bh->b_data; | 1453 | anchor = (struct anchorVolDescPtr *)bh->b_data; |
1380 | 1454 | ||
1381 | /* Locate the main sequence */ | 1455 | /* Locate the main sequence */ |
1382 | main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); | 1456 | main_s = le32_to_cpu( |
1383 | main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength); | 1457 | anchor->mainVolDescSeqExt.extLocation); |
1458 | main_e = le32_to_cpu( | ||
1459 | anchor->mainVolDescSeqExt.extLength); | ||
1384 | main_e = main_e >> sb->s_blocksize_bits; | 1460 | main_e = main_e >> sb->s_blocksize_bits; |
1385 | main_e += main_s; | 1461 | main_e += main_s; |
1386 | 1462 | ||
1387 | /* Locate the reserve sequence */ | 1463 | /* Locate the reserve sequence */ |
1388 | reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); | 1464 | reserve_s = le32_to_cpu( |
1389 | reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); | 1465 | anchor->reserveVolDescSeqExt.extLocation); |
1466 | reserve_e = le32_to_cpu( | ||
1467 | anchor->reserveVolDescSeqExt.extLength); | ||
1390 | reserve_e = reserve_e >> sb->s_blocksize_bits; | 1468 | reserve_e = reserve_e >> sb->s_blocksize_bits; |
1391 | reserve_e += reserve_s; | 1469 | reserve_e += reserve_s; |
1392 | 1470 | ||
@@ -1394,8 +1472,10 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
1394 | 1472 | ||
1395 | /* Process the main & reserve sequences */ | 1473 | /* Process the main & reserve sequences */ |
1396 | /* responsible for finding the PartitionDesc(s) */ | 1474 | /* responsible for finding the PartitionDesc(s) */ |
1397 | if (!(udf_process_sequence(sb, main_s, main_e, fileset) && | 1475 | if (!(udf_process_sequence(sb, main_s, main_e, |
1398 | udf_process_sequence(sb, reserve_s, reserve_e, fileset))) | 1476 | fileset) && |
1477 | udf_process_sequence(sb, reserve_s, reserve_e, | ||
1478 | fileset))) | ||
1399 | break; | 1479 | break; |
1400 | } | 1480 | } |
1401 | } | 1481 | } |
@@ -1426,10 +1506,14 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
1426 | for (j = 0; j < sbi->s_partitions; j++) { | 1506 | for (j = 0; j < sbi->s_partitions; j++) { |
1427 | struct udf_part_map *map2 = &sbi->s_partmaps[j]; | 1507 | struct udf_part_map *map2 = &sbi->s_partmaps[j]; |
1428 | if (j != i && | 1508 | if (j != i && |
1429 | map->s_volumeseqnum == map2->s_volumeseqnum && | 1509 | map->s_volumeseqnum == |
1430 | map->s_partition_num == map2->s_partition_num) { | 1510 | map2->s_volumeseqnum && |
1511 | map->s_partition_num == | ||
1512 | map2->s_partition_num) { | ||
1431 | ino.partitionReferenceNum = j; | 1513 | ino.partitionReferenceNum = j; |
1432 | ino.logicalBlockNum = sbi->s_last_block - map2->s_partition_root; | 1514 | ino.logicalBlockNum = |
1515 | sbi->s_last_block - | ||
1516 | map2->s_partition_root; | ||
1433 | break; | 1517 | break; |
1434 | } | 1518 | } |
1435 | } | 1519 | } |
@@ -1448,17 +1532,22 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) | |||
1448 | (sbi->s_vat_inode->i_size - 36) >> 2; | 1532 | (sbi->s_vat_inode->i_size - 36) >> 2; |
1449 | } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { | 1533 | } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { |
1450 | uint32_t pos; | 1534 | uint32_t pos; |
1535 | struct virtualAllocationTable20 *vat20; | ||
1451 | 1536 | ||
1452 | pos = udf_block_map(sbi->s_vat_inode, 0); | 1537 | pos = udf_block_map(sbi->s_vat_inode, 0); |
1453 | bh = sb_bread(sb, pos); | 1538 | bh = sb_bread(sb, pos); |
1454 | if (!bh) | 1539 | if (!bh) |
1455 | return 1; | 1540 | return 1; |
1541 | vat20 = (struct virtualAllocationTable20 *) | ||
1542 | bh->b_data + | ||
1543 | udf_ext0_offset(sbi->s_vat_inode); | ||
1456 | map->s_type_specific.s_virtual.s_start_offset = | 1544 | map->s_type_specific.s_virtual.s_start_offset = |
1457 | le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + | 1545 | le16_to_cpu(vat20->lengthHeader) + |
1458 | udf_ext0_offset(sbi->s_vat_inode))->lengthHeader) + | ||
1459 | udf_ext0_offset(sbi->s_vat_inode); | 1546 | udf_ext0_offset(sbi->s_vat_inode); |
1460 | map->s_type_specific.s_virtual.s_num_entries = (sbi->s_vat_inode->i_size - | 1547 | map->s_type_specific.s_virtual.s_num_entries = |
1461 | map->s_type_specific.s_virtual.s_start_offset) >> 2; | 1548 | (sbi->s_vat_inode->i_size - |
1549 | map->s_type_specific.s_virtual. | ||
1550 | s_start_offset) >> 2; | ||
1462 | brelse(bh); | 1551 | brelse(bh); |
1463 | } | 1552 | } |
1464 | map->s_partition_root = udf_get_pblock(sb, 0, i, 0); | 1553 | map->s_partition_root = udf_get_pblock(sb, 0, i, 0); |
@@ -1477,8 +1566,10 @@ static void udf_open_lvid(struct super_block *sb) | |||
1477 | if (bh) { | 1566 | if (bh) { |
1478 | int i; | 1567 | int i; |
1479 | kernel_timestamp cpu_time; | 1568 | kernel_timestamp cpu_time; |
1480 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | 1569 | struct logicalVolIntegrityDesc *lvid = |
1481 | struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); | 1570 | (struct logicalVolIntegrityDesc *)bh->b_data; |
1571 | struct logicalVolIntegrityDescImpUse *lvidiu = | ||
1572 | udf_sb_lvidiu(sbi); | ||
1482 | 1573 | ||
1483 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1574 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
1484 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1575 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
@@ -1486,8 +1577,10 @@ static void udf_open_lvid(struct super_block *sb) | |||
1486 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); | 1577 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); |
1487 | lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; | 1578 | lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; |
1488 | 1579 | ||
1489 | lvid->descTag.descCRC = cpu_to_le16(udf_crc((char *)lvid + sizeof(tag), | 1580 | lvid->descTag.descCRC = cpu_to_le16( |
1490 | le16_to_cpu(lvid->descTag.descCRCLength), 0)); | 1581 | udf_crc((char *)lvid + sizeof(tag), |
1582 | le16_to_cpu(lvid->descTag.descCRCLength), | ||
1583 | 0)); | ||
1491 | 1584 | ||
1492 | lvid->descTag.tagChecksum = 0; | 1585 | lvid->descTag.tagChecksum = 0; |
1493 | for (i = 0; i < 16; i++) | 1586 | for (i = 0; i < 16; i++) |
@@ -1513,22 +1606,25 @@ static void udf_close_lvid(struct super_block *sb) | |||
1513 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; | 1606 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; |
1514 | 1607 | ||
1515 | if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) { | 1608 | if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) { |
1516 | struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); | 1609 | struct logicalVolIntegrityDescImpUse *lvidiu = |
1610 | udf_sb_lvidiu(sbi); | ||
1517 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | 1611 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
1518 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | 1612 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
1519 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) | 1613 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) |
1520 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); | 1614 | lvid->recordingDateAndTime = cpu_to_lets(cpu_time); |
1521 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) | 1615 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) |
1522 | lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); | 1616 | lvidiu->maxUDFWriteRev = |
1617 | cpu_to_le16(UDF_MAX_WRITE_VERSION); | ||
1523 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) | 1618 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) |
1524 | lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); | 1619 | lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); |
1525 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) | 1620 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) |
1526 | lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); | 1621 | lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); |
1527 | lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); | 1622 | lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); |
1528 | 1623 | ||
1529 | lvid->descTag.descCRC = | 1624 | lvid->descTag.descCRC = cpu_to_le16( |
1530 | cpu_to_le16(udf_crc((char *)lvid + sizeof(tag), | 1625 | udf_crc((char *)lvid + sizeof(tag), |
1531 | le16_to_cpu(lvid->descTag.descCRCLength), 0)); | 1626 | le16_to_cpu(lvid->descTag.descCRCLength), |
1627 | 0)); | ||
1532 | 1628 | ||
1533 | lvid->descTag.tagChecksum = 0; | 1629 | lvid->descTag.tagChecksum = 0; |
1534 | for (i = 0; i < 16; i++) | 1630 | for (i = 0; i < 16; i++) |
@@ -1544,7 +1640,8 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap) | |||
1544 | { | 1640 | { |
1545 | int i; | 1641 | int i; |
1546 | int nr_groups = bitmap->s_nr_groups; | 1642 | int nr_groups = bitmap->s_nr_groups; |
1547 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups); | 1643 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * |
1644 | nr_groups); | ||
1548 | 1645 | ||
1549 | for (i = 0; i < nr_groups; i++) | 1646 | for (i = 0; i < nr_groups; i++) |
1550 | if (bitmap->s_block_bitmap[i]) | 1647 | if (bitmap->s_block_bitmap[i]) |
@@ -1662,19 +1759,21 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
1662 | udf_debug("Lastblock=%d\n", sbi->s_last_block); | 1759 | udf_debug("Lastblock=%d\n", sbi->s_last_block); |
1663 | 1760 | ||
1664 | if (sbi->s_lvid_bh) { | 1761 | if (sbi->s_lvid_bh) { |
1665 | struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); | 1762 | struct logicalVolIntegrityDescImpUse *lvidiu = |
1763 | udf_sb_lvidiu(sbi); | ||
1666 | uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev); | 1764 | uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev); |
1667 | uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev); | 1765 | uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev); |
1668 | /* uint16_t maxUDFWriteRev = le16_to_cpu(lvidiu->maxUDFWriteRev); */ | 1766 | /* uint16_t maxUDFWriteRev = |
1767 | le16_to_cpu(lvidiu->maxUDFWriteRev); */ | ||
1669 | 1768 | ||
1670 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { | 1769 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { |
1671 | printk(KERN_ERR "UDF-fs: minUDFReadRev=%x (max is %x)\n", | 1770 | printk(KERN_ERR "UDF-fs: minUDFReadRev=%x " |
1771 | "(max is %x)\n", | ||
1672 | le16_to_cpu(lvidiu->minUDFReadRev), | 1772 | le16_to_cpu(lvidiu->minUDFReadRev), |
1673 | UDF_MAX_READ_VERSION); | 1773 | UDF_MAX_READ_VERSION); |
1674 | goto error_out; | 1774 | goto error_out; |
1675 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) { | 1775 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) |
1676 | sb->s_flags |= MS_RDONLY; | 1776 | sb->s_flags |= MS_RDONLY; |
1677 | } | ||
1678 | 1777 | ||
1679 | sbi->s_udfrev = minUDFWriteRev; | 1778 | sbi->s_udfrev = minUDFWriteRev; |
1680 | 1779 | ||
@@ -1689,8 +1788,10 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
1689 | goto error_out; | 1788 | goto error_out; |
1690 | } | 1789 | } |
1691 | 1790 | ||
1692 | if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & UDF_PART_FLAG_READ_ONLY) { | 1791 | if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & |
1693 | printk(KERN_NOTICE "UDF-fs: Partition marked readonly; forcing readonly mount\n"); | 1792 | UDF_PART_FLAG_READ_ONLY) { |
1793 | printk(KERN_NOTICE "UDF-fs: Partition marked readonly; " | ||
1794 | "forcing readonly mount\n"); | ||
1694 | sb->s_flags |= MS_RDONLY; | 1795 | sb->s_flags |= MS_RDONLY; |
1695 | } | 1796 | } |
1696 | 1797 | ||
@@ -1716,7 +1817,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
1716 | /* perhaps it's not extensible enough, but for now ... */ | 1817 | /* perhaps it's not extensible enough, but for now ... */ |
1717 | inode = udf_iget(sb, rootdir); | 1818 | inode = udf_iget(sb, rootdir); |
1718 | if (!inode) { | 1819 | if (!inode) { |
1719 | printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, partition=%d\n", | 1820 | printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, " |
1821 | "partition=%d\n", | ||
1720 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); | 1822 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); |
1721 | goto error_out; | 1823 | goto error_out; |
1722 | } | 1824 | } |
@@ -1746,7 +1848,8 @@ error_out: | |||
1746 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); | 1848 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
1747 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | 1849 | if (map->s_partition_type == UDF_SPARABLE_MAP15) |
1748 | for (i = 0; i < 4; i++) | 1850 | for (i = 0; i < 4; i++) |
1749 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); | 1851 | brelse(map->s_type_specific.s_sparing. |
1852 | s_spar_map[i]); | ||
1750 | } | 1853 | } |
1751 | #ifdef CONFIG_UDF_NLS | 1854 | #ifdef CONFIG_UDF_NLS |
1752 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 1855 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
@@ -1824,7 +1927,8 @@ static void udf_put_super(struct super_block *sb) | |||
1824 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); | 1927 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
1825 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | 1928 | if (map->s_partition_type == UDF_SPARABLE_MAP15) |
1826 | for (i = 0; i < 4; i++) | 1929 | for (i = 0; i < 4; i++) |
1827 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); | 1930 | brelse(map->s_type_specific.s_sparing. |
1931 | s_spar_map[i]); | ||
1828 | } | 1932 | } |
1829 | #ifdef CONFIG_UDF_NLS | 1933 | #ifdef CONFIG_UDF_NLS |
1830 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 1934 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
@@ -1881,7 +1985,8 @@ static unsigned char udf_bitmap_lookup[16] = { | |||
1881 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 | 1985 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 |
1882 | }; | 1986 | }; |
1883 | 1987 | ||
1884 | static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) | 1988 | static unsigned int udf_count_free_bitmap(struct super_block *sb, |
1989 | struct udf_bitmap *bitmap) | ||
1885 | { | 1990 | { |
1886 | struct buffer_head *bh = NULL; | 1991 | struct buffer_head *bh = NULL; |
1887 | unsigned int accum = 0; | 1992 | unsigned int accum = 0; |
@@ -1942,7 +2047,8 @@ out: | |||
1942 | return accum; | 2047 | return accum; |
1943 | } | 2048 | } |
1944 | 2049 | ||
1945 | static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table) | 2050 | static unsigned int udf_count_free_table(struct super_block *sb, |
2051 | struct inode *table) | ||
1946 | { | 2052 | { |
1947 | unsigned int accum = 0; | 2053 | unsigned int accum = 0; |
1948 | uint32_t elen; | 2054 | uint32_t elen; |
@@ -1974,9 +2080,12 @@ static unsigned int udf_count_free(struct super_block *sb) | |||
1974 | 2080 | ||
1975 | sbi = UDF_SB(sb); | 2081 | sbi = UDF_SB(sb); |
1976 | if (sbi->s_lvid_bh) { | 2082 | if (sbi->s_lvid_bh) { |
1977 | struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | 2083 | struct logicalVolIntegrityDesc *lvid = |
2084 | (struct logicalVolIntegrityDesc *) | ||
2085 | sbi->s_lvid_bh->b_data; | ||
1978 | if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { | 2086 | if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { |
1979 | accum = le32_to_cpu(lvid->freeSpaceTable[sbi->s_partition]); | 2087 | accum = le32_to_cpu( |
2088 | lvid->freeSpaceTable[sbi->s_partition]); | ||
1980 | if (accum == 0xFFFFFFFF) | 2089 | if (accum == 0xFFFFFFFF) |
1981 | accum = 0; | 2090 | accum = 0; |
1982 | } | 2091 | } |
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c index e6f933dd6a7b..dcf06ef84f0f 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; |
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index 6931f6bfa1ae..5c1bf921f400 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c | |||
@@ -154,7 +154,8 @@ void udf_discard_prealloc(struct inode *inode) | |||
154 | extent_trunc(inode, &epos, eloc, etype, elen, 0); | 154 | extent_trunc(inode, &epos, eloc, etype, elen, 0); |
155 | if (!epos.bh) { | 155 | if (!epos.bh) { |
156 | UDF_I_LENALLOC(inode) = | 156 | UDF_I_LENALLOC(inode) = |
157 | epos.offset - udf_file_entry_alloc_offset(inode); | 157 | epos.offset - |
158 | udf_file_entry_alloc_offset(inode); | ||
158 | mark_inode_dirty(inode); | 159 | mark_inode_dirty(inode); |
159 | } else { | 160 | } else { |
160 | struct allocExtDesc *aed = | 161 | struct allocExtDesc *aed = |
@@ -213,7 +214,8 @@ void udf_truncate_extents(struct inode *inode) | |||
213 | else | 214 | else |
214 | lenalloc -= sizeof(struct allocExtDesc); | 215 | lenalloc -= sizeof(struct allocExtDesc); |
215 | 216 | ||
216 | while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) { | 217 | while ((etype = udf_current_aext(inode, &epos, &eloc, |
218 | &elen, 0)) != -1) { | ||
217 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { | 219 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
218 | udf_write_aext(inode, &epos, neloc, nelen, 0); | 220 | udf_write_aext(inode, &epos, neloc, nelen, 0); |
219 | if (indirect_ext_len) { | 221 | if (indirect_ext_len) { |
@@ -225,35 +227,43 @@ void udf_truncate_extents(struct inode *inode) | |||
225 | 0, indirect_ext_len); | 227 | 0, indirect_ext_len); |
226 | } else { | 228 | } else { |
227 | if (!epos.bh) { | 229 | if (!epos.bh) { |
228 | UDF_I_LENALLOC(inode) = lenalloc; | 230 | UDF_I_LENALLOC(inode) = |
231 | lenalloc; | ||
229 | mark_inode_dirty(inode); | 232 | mark_inode_dirty(inode); |
230 | } else { | 233 | } else { |
231 | struct allocExtDesc *aed = | 234 | struct allocExtDesc *aed = |
232 | (struct allocExtDesc *)(epos.bh->b_data); | 235 | (struct allocExtDesc *) |
236 | (epos.bh->b_data); | ||
237 | int len = | ||
238 | sizeof(struct allocExtDesc); | ||
239 | |||
233 | aed->lengthAllocDescs = | 240 | aed->lengthAllocDescs = |
234 | cpu_to_le32(lenalloc); | 241 | cpu_to_le32(lenalloc); |
235 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || | 242 | if (!UDF_QUERY_FLAG(sb, |
243 | UDF_FLAG_STRICT) || | ||
236 | sbi->s_udfrev >= 0x0201) | 244 | sbi->s_udfrev >= 0x0201) |
237 | udf_update_tag(epos.bh->b_data, | 245 | len += lenalloc; |
238 | lenalloc + | 246 | |
239 | sizeof(struct allocExtDesc)); | 247 | udf_update_tag(epos.bh->b_data, |
240 | else | 248 | len); |
241 | udf_update_tag(epos.bh->b_data, | 249 | mark_buffer_dirty_inode( |
242 | sizeof(struct allocExtDesc)); | 250 | epos.bh, inode); |
243 | mark_buffer_dirty_inode(epos.bh, inode); | ||
244 | } | 251 | } |
245 | } | 252 | } |
246 | brelse(epos.bh); | 253 | brelse(epos.bh); |
247 | epos.offset = sizeof(struct allocExtDesc); | 254 | epos.offset = sizeof(struct allocExtDesc); |
248 | epos.block = eloc; | 255 | epos.block = eloc; |
249 | epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); | 256 | epos.bh = udf_tread(sb, |
257 | udf_get_lb_pblock(sb, eloc, 0)); | ||
250 | if (elen) | 258 | if (elen) |
251 | indirect_ext_len = (elen + sb->s_blocksize -1) >> | 259 | indirect_ext_len = |
260 | (elen + sb->s_blocksize - 1) >> | ||
252 | sb->s_blocksize_bits; | 261 | sb->s_blocksize_bits; |
253 | else | 262 | else |
254 | indirect_ext_len = 1; | 263 | indirect_ext_len = 1; |
255 | } else { | 264 | } else { |
256 | extent_trunc(inode, &epos, eloc, etype, elen, 0); | 265 | extent_trunc(inode, &epos, eloc, etype, |
266 | elen, 0); | ||
257 | epos.offset += adsize; | 267 | epos.offset += adsize; |
258 | } | 268 | } |
259 | } | 269 | } |
@@ -274,10 +284,11 @@ void udf_truncate_extents(struct inode *inode) | |||
274 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || | 284 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || |
275 | sbi->s_udfrev >= 0x0201) | 285 | sbi->s_udfrev >= 0x0201) |
276 | udf_update_tag(epos.bh->b_data, | 286 | udf_update_tag(epos.bh->b_data, |
277 | lenalloc + sizeof(struct allocExtDesc)); | 287 | lenalloc + |
288 | sizeof(struct allocExtDesc)); | ||
278 | else | 289 | else |
279 | udf_update_tag(epos.bh->b_data, | 290 | udf_update_tag(epos.bh->b_data, |
280 | sizeof(struct allocExtDesc)); | 291 | sizeof(struct allocExtDesc)); |
281 | mark_buffer_dirty_inode(epos.bh, inode); | 292 | mark_buffer_dirty_inode(epos.bh, inode); |
282 | } | 293 | } |
283 | } | 294 | } |
@@ -291,13 +302,16 @@ void udf_truncate_extents(struct inode *inode) | |||
291 | * extending the file by 'offset' blocks. | 302 | * extending the file by 'offset' blocks. |
292 | */ | 303 | */ |
293 | if ((!epos.bh && | 304 | if ((!epos.bh && |
294 | epos.offset == udf_file_entry_alloc_offset(inode)) || | 305 | epos.offset == |
295 | (epos.bh && epos.offset == sizeof(struct allocExtDesc))) { | 306 | udf_file_entry_alloc_offset(inode)) || |
307 | (epos.bh && epos.offset == | ||
308 | sizeof(struct allocExtDesc))) { | ||
296 | /* File has no extents at all or has empty last | 309 | /* File has no extents at all or has empty last |
297 | * indirect extent! Create a fake extent... */ | 310 | * indirect extent! Create a fake extent... */ |
298 | extent.extLocation.logicalBlockNum = 0; | 311 | extent.extLocation.logicalBlockNum = 0; |
299 | extent.extLocation.partitionReferenceNum = 0; | 312 | extent.extLocation.partitionReferenceNum = 0; |
300 | extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; | 313 | extent.extLength = |
314 | EXT_NOT_RECORDED_NOT_ALLOCATED; | ||
301 | } else { | 315 | } else { |
302 | epos.offset -= adsize; | 316 | epos.offset -= adsize; |
303 | etype = udf_next_aext(inode, &epos, | 317 | etype = udf_next_aext(inode, &epos, |
@@ -306,7 +320,9 @@ void udf_truncate_extents(struct inode *inode) | |||
306 | extent.extLength |= etype << 30; | 320 | extent.extLength |= etype << 30; |
307 | } | 321 | } |
308 | udf_extend_file(inode, &epos, &extent, | 322 | udf_extend_file(inode, &epos, &extent, |
309 | offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0)); | 323 | offset + |
324 | ((inode->i_size & | ||
325 | (sb->s_blocksize - 1)) != 0)); | ||
310 | } | 326 | } |
311 | } | 327 | } |
312 | UDF_I_LENEXTENTS(inode) = inode->i_size; | 328 | UDF_I_LENEXTENTS(inode) = inode->i_size; |
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]; |