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>
This commit is contained in:
Marcin Slusarz 2008-02-08 04:20:36 -08:00 committed by Linus Torvalds
parent bd45a420f9
commit 4b11111aba
14 changed files with 1306 additions and 830 deletions

View File

@ -28,15 +28,16 @@
#include "udf_i.h" #include "udf_i.h"
#include "udf_sb.h" #include "udf_sb.h"
#define udf_clear_bit(nr,addr) ext2_clear_bit(nr,addr) #define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr)
#define udf_set_bit(nr,addr) ext2_set_bit(nr,addr) #define udf_set_bit(nr, addr) ext2_set_bit(nr, addr)
#define udf_test_bit(nr, addr) ext2_test_bit(nr, addr) #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr)
#define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size) #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size)
#define udf_find_next_one_bit(addr, size, offset) find_next_one_bit(addr, size, offset) #define udf_find_next_one_bit(addr, size, offset) \
find_next_one_bit(addr, size, offset)
#define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x) #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
#define leNUM_to_cpup(x,y) xleNUM_to_cpup(x,y) #define leNUM_to_cpup(x, y) xleNUM_to_cpup(x, y)
#define xleNUM_to_cpup(x,y) (le ## x ## _to_cpup(y)) #define xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y))
#define uintBPL_t uint(BITS_PER_LONG) #define uintBPL_t uint(BITS_PER_LONG)
#define uint(x) xuint(x) #define uint(x) xuint(x)
#define xuint(x) __le ## x #define xuint(x) __le ## x
@ -62,7 +63,8 @@ static inline int find_next_one_bit(void *addr, int size, int offset)
result += BITS_PER_LONG; result += BITS_PER_LONG;
} }
while (size & ~(BITS_PER_LONG - 1)) { while (size & ~(BITS_PER_LONG - 1)) {
if ((tmp = leBPL_to_cpup(p++))) tmp = leBPL_to_cpup(p++);
if (tmp)
goto found_middle; goto found_middle;
result += BITS_PER_LONG; result += BITS_PER_LONG;
size -= BITS_PER_LONG; size -= BITS_PER_LONG;
@ -91,9 +93,9 @@ static int read_block_bitmap(struct super_block *sb,
loc.partitionReferenceNum = UDF_SB(sb)->s_partition; loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
if (!bh) { if (!bh)
retval = -EIO; retval = -EIO;
}
bitmap->s_block_bitmap[bitmap_nr] = bh; bitmap->s_block_bitmap[bitmap_nr] = bh;
return retval; return retval;
} }
@ -155,14 +157,17 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
mutex_lock(&sbi->s_alloc_mutex); mutex_lock(&sbi->s_alloc_mutex);
if (bloc.logicalBlockNum < 0 || if (bloc.logicalBlockNum < 0 ||
(bloc.logicalBlockNum + count) > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { (bloc.logicalBlockNum + count) >
sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n", udf_debug("%d < %d || %d + %d > %d\n",
bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len); sbi->s_partmaps[bloc.partitionReferenceNum].
s_partition_len);
goto error_return; goto error_return;
} }
block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3); block = bloc.logicalBlockNum + offset +
(sizeof(struct spaceBitmapDesc) << 3);
do_more: do_more:
overflow = 0; overflow = 0;
@ -184,7 +189,8 @@ do_more:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (udf_set_bit(bit + i, bh->b_data)) { if (udf_set_bit(bit + i, bh->b_data)) {
udf_debug("bit %ld already set\n", bit + i); udf_debug("bit %ld already set\n", bit + i);
udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); udf_debug("byte=%2x\n",
((char *)bh->b_data)[(bit + i) >> 3]);
} else { } else {
if (inode) if (inode)
DQUOT_FREE_BLOCK(inode, 1); DQUOT_FREE_BLOCK(inode, 1);
@ -314,14 +320,16 @@ repeat:
if (bit < end_goal) if (bit < end_goal)
goto got_block; goto got_block;
ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF,
sb->s_blocksize - ((bit + 7) >> 3));
newbit = (ptr - ((char *)bh->b_data)) << 3; newbit = (ptr - ((char *)bh->b_data)) << 3;
if (newbit < sb->s_blocksize << 3) { if (newbit < sb->s_blocksize << 3) {
bit = newbit; bit = newbit;
goto search_back; goto search_back;
} }
newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); newbit = udf_find_next_one_bit(bh->b_data,
sb->s_blocksize << 3, bit);
if (newbit < sb->s_blocksize << 3) { if (newbit < sb->s_blocksize << 3) {
bit = newbit; bit = newbit;
goto got_block; goto got_block;
@ -360,15 +368,20 @@ repeat:
if (bit < sb->s_blocksize << 3) if (bit < sb->s_blocksize << 3)
goto search_back; goto search_back;
else else
bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3,
group_start << 3);
if (bit >= sb->s_blocksize << 3) { if (bit >= sb->s_blocksize << 3) {
mutex_unlock(&sbi->s_alloc_mutex); mutex_unlock(&sbi->s_alloc_mutex);
return 0; return 0;
} }
search_back: search_back:
for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--) i = 0;
; /* empty loop */ while (i < 7 && bit > (group_start << 3) &&
udf_test_bit(bit - 1, bh->b_data)) {
++i;
--bit;
}
got_block: got_block:
@ -424,15 +437,17 @@ static void udf_table_free_blocks(struct super_block *sb,
mutex_lock(&sbi->s_alloc_mutex); mutex_lock(&sbi->s_alloc_mutex);
if (bloc.logicalBlockNum < 0 || if (bloc.logicalBlockNum < 0 ||
(bloc.logicalBlockNum + count) > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { (bloc.logicalBlockNum + count) >
sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n", udf_debug("%d < %d || %d + %d > %d\n",
bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
sbi->s_partmaps[bloc.partitionReferenceNum]->s_partition_len); sbi->s_partmaps[bloc.partitionReferenceNum].
s_partition_len);
goto error_return; goto error_return;
} }
/* We do this up front - There are some error conditions that could occure, /* We do this up front - There are some error conditions that
but.. oh well */ could occure, but.. oh well */
if (inode) if (inode)
DQUOT_FREE_BLOCK(inode, count); DQUOT_FREE_BLOCK(inode, count);
if (sbi->s_lvid_bh) { if (sbi->s_lvid_bh) {
@ -452,26 +467,39 @@ static void udf_table_free_blocks(struct super_block *sb,
while (count && while (count &&
(etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) { if (((eloc.logicalBlockNum +
if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { (elen >> sb->s_blocksize_bits)) == start)) {
count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); if ((0x3FFFFFFF - elen) <
start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); (count << sb->s_blocksize_bits)) {
elen = (etype << 30) | (0x40000000 - sb->s_blocksize); uint32_t tmp = ((0x3FFFFFFF - elen) >>
sb->s_blocksize_bits);
count -= tmp;
start += tmp;
elen = (etype << 30) |
(0x40000000 - sb->s_blocksize);
} else { } else {
elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); elen = (etype << 30) |
(elen +
(count << sb->s_blocksize_bits));
start += count; start += count;
count = 0; count = 0;
} }
udf_write_aext(table, &oepos, eloc, elen, 1); udf_write_aext(table, &oepos, eloc, elen, 1);
} else if (eloc.logicalBlockNum == (end + 1)) { } else if (eloc.logicalBlockNum == (end + 1)) {
if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { if ((0x3FFFFFFF - elen) <
count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); (count << sb->s_blocksize_bits)) {
end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); uint32_t tmp = ((0x3FFFFFFF - elen) >>
eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); sb->s_blocksize_bits);
elen = (etype << 30) | (0x40000000 - sb->s_blocksize); count -= tmp;
end -= tmp;
eloc.logicalBlockNum -= tmp;
elen = (etype << 30) |
(0x40000000 - sb->s_blocksize);
} else { } else {
eloc.logicalBlockNum = start; eloc.logicalBlockNum = start;
elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); elen = (etype << 30) |
(elen +
(count << sb->s_blocksize_bits));
end -= count; end -= count;
count = 0; count = 0;
} }
@ -492,9 +520,9 @@ static void udf_table_free_blocks(struct super_block *sb,
if (count) { if (count) {
/* /*
* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate * NOTE: we CANNOT use udf_add_aext here, as it can try to
* a new block, and since we hold the super block lock already * allocate a new block, and since we hold the super block
* very bad things would happen :) * lock already very bad things would happen :)
* *
* We copy the behavior of udf_add_aext, but instead of * We copy the behavior of udf_add_aext, but instead of
* trying to allocate a new block close to the existing one, * 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,
eloc.logicalBlockNum++; eloc.logicalBlockNum++;
elen -= sb->s_blocksize; elen -= sb->s_blocksize;
if (!(epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, epos.block, 0)))) { epos.bh = udf_tread(sb,
udf_get_lb_pblock(sb, epos.block, 0));
if (!epos.bh) {
brelse(oepos.bh); brelse(oepos.bh);
goto error_return; goto error_return;
} }
aed = (struct allocExtDesc *)(epos.bh->b_data); aed = (struct allocExtDesc *)(epos.bh->b_data);
aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); aed->previousAllocExtLocation =
cpu_to_le32(oepos.block.logicalBlockNum);
if (epos.offset + adsize > sb->s_blocksize) { if (epos.offset + adsize > sb->s_blocksize) {
loffset = epos.offset; loffset = epos.offset;
aed->lengthAllocDescs = cpu_to_le32(adsize); aed->lengthAllocDescs = cpu_to_le32(adsize);
sptr = UDF_I_DATA(table) + epos.offset - adsize; sptr = UDF_I_DATA(table) + epos.offset - adsize;
dptr = epos.bh->b_data + sizeof(struct allocExtDesc); dptr = epos.bh->b_data +
sizeof(struct allocExtDesc);
memcpy(dptr, sptr, adsize); memcpy(dptr, sptr, adsize);
epos.offset = sizeof(struct allocExtDesc) + adsize; epos.offset = sizeof(struct allocExtDesc) +
adsize;
} else { } else {
loffset = epos.offset + adsize; loffset = epos.offset + adsize;
aed->lengthAllocDescs = cpu_to_le32(0); aed->lengthAllocDescs = cpu_to_le32(0);
if (oepos.bh) { if (oepos.bh) {
sptr = oepos.bh->b_data + epos.offset; sptr = oepos.bh->b_data + epos.offset;
aed = (struct allocExtDesc *)oepos.bh->b_data; aed = (struct allocExtDesc *)
oepos.bh->b_data;
aed->lengthAllocDescs = aed->lengthAllocDescs =
cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); cpu_to_le32(le32_to_cpu(
aed->lengthAllocDescs) +
adsize);
} else { } else {
sptr = UDF_I_DATA(table) + epos.offset; sptr = UDF_I_DATA(table) + epos.offset;
UDF_I_LENALLOC(table) += adsize; UDF_I_LENALLOC(table) += adsize;
@ -564,27 +600,31 @@ static void udf_table_free_blocks(struct super_block *sb,
epos.offset = sizeof(struct allocExtDesc); epos.offset = sizeof(struct allocExtDesc);
} }
if (sbi->s_udfrev >= 0x0200) if (sbi->s_udfrev >= 0x0200)
udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, udf_new_tag(epos.bh->b_data, TAG_IDENT_AED,
epos.block.logicalBlockNum, sizeof(tag)); 3, 1, epos.block.logicalBlockNum,
sizeof(tag));
else else
udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, udf_new_tag(epos.bh->b_data, TAG_IDENT_AED,
epos.block.logicalBlockNum, sizeof(tag)); 2, 1, epos.block.logicalBlockNum,
sizeof(tag));
switch (UDF_I_ALLOCTYPE(table)) { switch (UDF_I_ALLOCTYPE(table)) {
case ICBTAG_FLAG_AD_SHORT: case ICBTAG_FLAG_AD_SHORT:
sad = (short_ad *)sptr; sad = (short_ad *)sptr;
sad->extLength = cpu_to_le32( sad->extLength = cpu_to_le32(
EXT_NEXT_EXTENT_ALLOCDECS | EXT_NEXT_EXTENT_ALLOCDECS |
sb->s_blocksize); sb->s_blocksize);
sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); sad->extPosition =
break; cpu_to_le32(epos.block.logicalBlockNum);
case ICBTAG_FLAG_AD_LONG: break;
lad = (long_ad *)sptr; case ICBTAG_FLAG_AD_LONG:
lad->extLength = cpu_to_le32( lad = (long_ad *)sptr;
EXT_NEXT_EXTENT_ALLOCDECS | lad->extLength = cpu_to_le32(
sb->s_blocksize); EXT_NEXT_EXTENT_ALLOCDECS |
lad->extLocation = cpu_to_lelb(epos.block); sb->s_blocksize);
break; lad->extLocation =
cpu_to_lelb(epos.block);
break;
} }
if (oepos.bh) { if (oepos.bh) {
udf_update_tag(oepos.bh->b_data, loffset); udf_update_tag(oepos.bh->b_data, loffset);
@ -594,7 +634,8 @@ static void udf_table_free_blocks(struct super_block *sb,
} }
} }
if (elen) { /* It's possible that stealing the block emptied the extent */ /* It's possible that stealing the block emptied the extent */
if (elen) {
udf_write_aext(table, &epos, eloc, elen, 1); udf_write_aext(table, &epos, eloc, elen, 1);
if (!epos.bh) { if (!epos.bh) {
@ -603,7 +644,8 @@ static void udf_table_free_blocks(struct super_block *sb,
} else { } else {
aed = (struct allocExtDesc *)epos.bh->b_data; aed = (struct allocExtDesc *)epos.bh->b_data;
aed->lengthAllocDescs = aed->lengthAllocDescs =
cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); cpu_to_le32(le32_to_cpu(
aed->lengthAllocDescs) + adsize);
udf_update_tag(epos.bh->b_data, epos.offset); udf_update_tag(epos.bh->b_data, epos.offset);
mark_buffer_dirty(epos.bh); mark_buffer_dirty(epos.bh);
} }
@ -631,7 +673,8 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
struct extent_position epos; struct extent_position epos;
int8_t etype = -1; int8_t etype = -1;
if (first_block < 0 || first_block >= sbi->s_partmaps[partition].s_partition_len) if (first_block < 0 ||
first_block >= sbi->s_partmaps[partition].s_partition_len)
return 0; return 0;
if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
@ -658,16 +701,18 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
epos.offset -= adsize; epos.offset -= adsize;
alloc_count = (elen >> sb->s_blocksize_bits); alloc_count = (elen >> sb->s_blocksize_bits);
if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) { if (inode && DQUOT_PREALLOC_BLOCK(inode,
alloc_count > block_count ? block_count : alloc_count))
alloc_count = 0; alloc_count = 0;
} else if (alloc_count > block_count) { else if (alloc_count > block_count) {
alloc_count = block_count; alloc_count = block_count;
eloc.logicalBlockNum += alloc_count; eloc.logicalBlockNum += alloc_count;
elen -= (alloc_count << sb->s_blocksize_bits); elen -= (alloc_count << sb->s_blocksize_bits);
udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); udf_write_aext(table, &epos, eloc,
} else { (etype << 30) | elen, 1);
udf_delete_aext(table, epos, eloc, (etype << 30) | elen); } else
} udf_delete_aext(table, epos, eloc,
(etype << 30) | elen);
} else { } else {
alloc_count = 0; alloc_count = 0;
} }
@ -711,10 +756,10 @@ static int udf_table_new_block(struct super_block *sb,
if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
goal = 0; goal = 0;
/* We search for the closest matching block to goal. If we find a exact hit, /* We search for the closest matching block to goal. If we find
we stop. Otherwise we keep going till we run out of extents. a exact hit, we stop. Otherwise we keep going till we run out
We store the buffer_head, bloc, and extoffset of the current closest of extents. We store the buffer_head, bloc, and extoffset
match and use that when we are done. of the current closest match and use that when we are done.
*/ */
epos.offset = sizeof(struct unallocSpaceEntry); epos.offset = sizeof(struct unallocSpaceEntry);
epos.block = UDF_I_LOCATION(table); epos.block = UDF_I_LOCATION(table);
@ -723,7 +768,8 @@ static int udf_table_new_block(struct super_block *sb,
while (spread && while (spread &&
(etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
if (goal >= eloc.logicalBlockNum) { if (goal >= eloc.logicalBlockNum) {
if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) if (goal < eloc.logicalBlockNum +
(elen >> sb->s_blocksize_bits))
nspread = 0; nspread = 0;
else else
nspread = goal - eloc.logicalBlockNum - nspread = goal - eloc.logicalBlockNum -
@ -825,52 +871,53 @@ inline int udf_prealloc_blocks(struct super_block *sb,
{ {
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
return udf_bitmap_prealloc_blocks(sb, inode, return udf_bitmap_prealloc_blocks(sb, inode,
map->s_uspace.s_bitmap, map->s_uspace.s_bitmap,
partition, first_block, block_count); partition, first_block,
} else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { block_count);
else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
return udf_table_prealloc_blocks(sb, inode, return udf_table_prealloc_blocks(sb, inode,
map->s_uspace.s_table, map->s_uspace.s_table,
partition, first_block, block_count); partition, first_block,
} else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { block_count);
else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
return udf_bitmap_prealloc_blocks(sb, inode, return udf_bitmap_prealloc_blocks(sb, inode,
map->s_fspace.s_bitmap, map->s_fspace.s_bitmap,
partition, first_block, block_count); partition, first_block,
} else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { block_count);
else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
return udf_table_prealloc_blocks(sb, inode, return udf_table_prealloc_blocks(sb, inode,
map->s_fspace.s_table, map->s_fspace.s_table,
partition, first_block, block_count); partition, first_block,
} else { block_count);
else
return 0; return 0;
}
} }
inline int udf_new_block(struct super_block *sb, inline int udf_new_block(struct super_block *sb,
struct inode *inode, struct inode *inode,
uint16_t partition, uint32_t goal, int *err) uint16_t partition, uint32_t goal, int *err)
{ {
int ret;
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
ret = udf_bitmap_new_block(sb, inode, return udf_bitmap_new_block(sb, inode,
map->s_uspace.s_bitmap, map->s_uspace.s_bitmap,
partition, goal, err); partition, goal, err);
return ret; else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
} else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
return udf_table_new_block(sb, inode, return udf_table_new_block(sb, inode,
map->s_uspace.s_table, map->s_uspace.s_table,
partition, goal, err); partition, goal, err);
} else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
return udf_bitmap_new_block(sb, inode, return udf_bitmap_new_block(sb, inode,
map->s_fspace.s_bitmap, map->s_fspace.s_bitmap,
partition, goal, err); partition, goal, err);
} else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
return udf_table_new_block(sb, inode, return udf_table_new_block(sb, inode,
map->s_fspace.s_table, map->s_fspace.s_table,
partition, goal, err); partition, goal, err);
} else { else {
*err = -EIO; *err = -EIO;
return 0; return 0;
} }

View File

@ -79,7 +79,7 @@ static uint16_t crc_table[256] = {
* July 21, 1997 - Andrew E. Mileski * July 21, 1997 - Andrew E. Mileski
* Adapted from OSTA-UDF(tm) 1.50 standard. * Adapted from OSTA-UDF(tm) 1.50 standard.
*/ */
uint16_t udf_crc(uint8_t * data, uint32_t size, uint16_t crc) uint16_t udf_crc(uint8_t *data, uint32_t size, uint16_t crc)
{ {
while (size--) while (size--)
crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8);

View File

@ -19,7 +19,7 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#if 0 #if 0
static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad,
uint8_t ad_size, kernel_lb_addr fe_loc, uint8_t ad_size, kernel_lb_addr fe_loc,
int *pos, int *offset, struct buffer_head **bh, int *pos, int *offset, struct buffer_head **bh,
int *error) int *error)
@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
if (!block) if (!block)
return NULL; return NULL;
if (!(*bh = udf_tread(dir->i_sb, block))) *bh = udf_tread(dir->i_sb, block);
if (!*bh)
return NULL; return NULL;
} else if (*offset > dir->i_sb->s_blocksize) { } else if (*offset > dir->i_sb->s_blocksize) {
ad = tmpad; ad = tmpad;
@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
if (!block) if (!block)
return NULL; return NULL;
if (!((*bh) = udf_tread(dir->i_sb, block))) (*bh) = udf_tread(dir->i_sb, block);
if (!*bh)
return NULL; return NULL;
memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); memcpy((uint8_t *)ad + remainder, (*bh)->b_data,
ad_size - remainder);
*offset = ad_size - remainder; *offset = ad_size - remainder;
} }
@ -68,12 +71,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
} }
#endif #endif
struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
struct udf_fileident_bh *fibh, struct udf_fileident_bh *fibh,
struct fileIdentDesc *cfi, struct fileIdentDesc *cfi,
struct extent_position *epos, struct extent_position *epos,
kernel_lb_addr * eloc, uint32_t * elen, kernel_lb_addr *eloc, uint32_t *elen,
sector_t * offset) sector_t *offset)
{ {
struct fileIdentDesc *fi; struct fileIdentDesc *fi;
int i, num, block; int i, num, block;
@ -86,7 +89,8 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
(UDF_I_EFE(dir) ? (UDF_I_EFE(dir) ?
sizeof(struct extendedFileEntry) : sizeof(struct extendedFileEntry) :
sizeof(struct fileEntry)), sizeof(struct fileEntry)),
dir->i_sb->s_blocksize, &(fibh->eoffset)); dir->i_sb->s_blocksize,
&(fibh->eoffset));
if (!fi) if (!fi)
return NULL; return NULL;
@ -100,6 +104,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
if (fibh->eoffset == dir->i_sb->s_blocksize) { if (fibh->eoffset == dir->i_sb->s_blocksize) {
int lextoffset = epos->offset; int lextoffset = epos->offset;
unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
if (udf_next_aext(dir, epos, eloc, elen, 1) != if (udf_next_aext(dir, epos, eloc, elen, 1) !=
(EXT_RECORDED_ALLOCATED >> 30)) (EXT_RECORDED_ALLOCATED >> 30))
@ -109,24 +114,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
(*offset)++; (*offset)++;
if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) if ((*offset << blocksize_bits) >= *elen)
*offset = 0; *offset = 0;
else else
epos->offset = lextoffset; epos->offset = lextoffset;
brelse(fibh->sbh); brelse(fibh->sbh);
if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->sbh)
return NULL; return NULL;
fibh->soffset = fibh->eoffset = 0; fibh->soffset = fibh->eoffset = 0;
if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
i = 16 >> (dir->i_sb->s_blocksize_bits - 9); i = 16 >> (blocksize_bits - 9);
if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) if (i + *offset > (*elen >> blocksize_bits))
i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; i = (*elen >> blocksize_bits)-*offset;
for (num = 0; i > 0; i--) { for (num = 0; i > 0; i--) {
block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); block = udf_get_lb_pblock(dir->i_sb, *eloc,
*offset + i);
tmp = udf_tgetblk(dir->i_sb, block); tmp = udf_tgetblk(dir->i_sb, block);
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) if (tmp && !buffer_uptodate(tmp) &&
!buffer_locked(tmp))
bha[num++] = tmp; bha[num++] = tmp;
else else
brelse(tmp); brelse(tmp);
@ -172,20 +180,24 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
fibh->soffset -= dir->i_sb->s_blocksize; fibh->soffset -= dir->i_sb->s_blocksize;
fibh->eoffset -= dir->i_sb->s_blocksize; fibh->eoffset -= dir->i_sb->s_blocksize;
if (!(fibh->ebh = udf_tread(dir->i_sb, block))) fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->ebh)
return NULL; return NULL;
if (sizeof(struct fileIdentDesc) > -fibh->soffset) { if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
int fi_len; int fi_len;
memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, memcpy((uint8_t *)cfi - fibh->soffset,
fibh->ebh->b_data,
sizeof(struct fileIdentDesc) + fibh->soffset); sizeof(struct fileIdentDesc) + fibh->soffset);
fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + fi_len = (sizeof(struct fileIdentDesc) +
cfi->lengthFileIdent +
le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
*nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); *nf_pos += (fi_len - (fibh->eoffset - fibh->soffset))
>> 2;
fibh->eoffset = fibh->soffset + fi_len; fibh->eoffset = fibh->soffset + fi_len;
} else { } else {
memcpy((uint8_t *)cfi, (uint8_t *)fi, memcpy((uint8_t *)cfi, (uint8_t *)fi,
@ -210,9 +222,8 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
ptr = buffer; ptr = buffer;
if ((*offset > 0) && (*offset < bufsize)) { if ((*offset > 0) && (*offset < bufsize))
ptr += *offset; ptr += *offset;
}
fi = (struct fileIdentDesc *)ptr; fi = (struct fileIdentDesc *)ptr;
if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
udf_debug("0x%x != TAG_IDENT_FID\n", udf_debug("0x%x != TAG_IDENT_FID\n",
@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
bufsize); bufsize);
return NULL; return NULL;
} }
if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
lengthThisIdent = sizeof(struct fileIdentDesc); lengthThisIdent = sizeof(struct fileIdentDesc);
} else { else
lengthThisIdent = sizeof(struct fileIdentDesc) + lengthThisIdent = sizeof(struct fileIdentDesc) +
fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
}
/* we need to figure padding, too! */ /* we need to figure padding, too! */
padlen = lengthThisIdent % UDF_NAME_PAD; padlen = lengthThisIdent % UDF_NAME_PAD;
@ -258,11 +268,11 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
return NULL; return NULL;
} }
ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); ptr = (uint8_t *)(fe->extendedAttr) +
le32_to_cpu(fe->lengthExtendedAttr);
if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)))
ptr += *offset; ptr += *offset;
}
ext = (extent_ad *)ptr; ext = (extent_ad *)ptr;
@ -283,8 +293,11 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
return NULL; return NULL;
else if ((sa = (short_ad *)ptr)->extLength == 0) else {
return NULL; sa = (short_ad *)ptr;
if (sa->extLength == 0)
return NULL;
}
if (inc) if (inc)
*offset += sizeof(short_ad); *offset += sizeof(short_ad);
@ -302,8 +315,11 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
return NULL; return NULL;
else if ((la = (long_ad *)ptr)->extLength == 0) else {
return NULL; la = (long_ad *)ptr;
if (la->extLength == 0)
return NULL;
}
if (inc) if (inc)
*offset += sizeof(long_ad); *offset += sizeof(long_ad);

View File

@ -59,7 +59,8 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)
return 0; return 0;
} }
static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc) static int udf_adinicb_writepage(struct page *page,
struct writeback_control *wbc)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
char *kaddr; char *kaddr;
@ -116,7 +117,8 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
else else
pos = ppos; pos = ppos;
if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + if (inode->i_sb->s_blocksize <
(udf_file_entry_alloc_offset(inode) +
pos + count)) { pos + count)) {
udf_expand_file_adinicb(inode, pos + count, &err); udf_expand_file_adinicb(inode, pos + count, &err);
if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { 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,
switch (cmd) { switch (cmd) {
case UDF_GETVOLIDENT: case UDF_GETVOLIDENT:
return copy_to_user((char __user *)arg, if (copy_to_user((char __user *)arg,
UDF_SB(inode->i_sb)->s_volume_ident, 32) ? -EFAULT : 0; UDF_SB(inode->i_sb)->s_volume_ident, 32))
return -EFAULT;
else
return 0;
case UDF_RELOCATE_BLOCKS: case UDF_RELOCATE_BLOCKS:
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
if (get_user(old_block, (long __user *)arg)) if (get_user(old_block, (long __user *)arg))
return -EFAULT; return -EFAULT;
if ((result = udf_relocate_blocks(inode->i_sb, result = udf_relocate_blocks(inode->i_sb,
old_block, &new_block)) == 0) old_block, &new_block);
if (result == 0)
result = put_user(new_block, (long __user *)arg); result = put_user(new_block, (long __user *)arg);
return result; return result;
case UDF_GETEASIZE: case UDF_GETEASIZE:

View File

@ -82,7 +82,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
UDF_I_NEXT_ALLOC_GOAL(inode) = 0; UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
UDF_I_STRAT4096(inode) = 0; UDF_I_STRAT4096(inode) = 0;
block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, block = udf_new_block(dir->i_sb, NULL,
UDF_I_LOCATION(dir).partitionReferenceNum,
start, err); start, err);
if (*err) { if (*err) {
iput(inode); iput(inode);
@ -91,11 +92,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
mutex_lock(&sbi->s_alloc_mutex); mutex_lock(&sbi->s_alloc_mutex);
if (sbi->s_lvid_bh) { if (sbi->s_lvid_bh) {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; struct logicalVolIntegrityDesc *lvid =
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); (struct logicalVolIntegrityDesc *)
sbi->s_lvid_bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu =
udf_sb_lvidiu(sbi);
struct logicalVolHeaderDesc *lvhd; struct logicalVolHeaderDesc *lvhd;
uint64_t uniqueID; uint64_t uniqueID;
lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); lvhd = (struct logicalVolHeaderDesc *)
(lvid->logicalVolContentsUse);
if (S_ISDIR(mode)) if (S_ISDIR(mode))
lvidiu->numDirs = lvidiu->numDirs =
cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1); 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)
} }
UDF_I_LOCATION(inode).logicalBlockNum = block; UDF_I_LOCATION(inode).logicalBlockNum = block;
UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; UDF_I_LOCATION(inode).partitionReferenceNum =
UDF_I_LOCATION(dir).partitionReferenceNum;
inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
inode->i_blocks = 0; inode->i_blocks = 0;
UDF_I_LENEATTR(inode) = 0; UDF_I_LENEATTR(inode) = 0;
@ -129,10 +135,14 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
UDF_I_EFE(inode) = 1; UDF_I_EFE(inode) = 1;
if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize -
sizeof(struct extendedFileEntry),
GFP_KERNEL);
} else { } else {
UDF_I_EFE(inode) = 0; UDF_I_EFE(inode) = 0;
UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize -
sizeof(struct fileEntry),
GFP_KERNEL);
} }
if (!UDF_I_DATA(inode)) { if (!UDF_I_DATA(inode)) {
iput(inode); iput(inode);

File diff suppressed because it is too large Load Diff

View File

@ -70,71 +70,84 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
struct extendedAttrHeaderDesc *eahd; struct extendedAttrHeaderDesc *eahd;
eahd = (struct extendedAttrHeaderDesc *)ea; eahd = (struct extendedAttrHeaderDesc *)ea;
if (UDF_I_LENALLOC(inode)) { if (UDF_I_LENALLOC(inode))
memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); memmove(&ad[size], ad, UDF_I_LENALLOC(inode));
}
if (UDF_I_LENEATTR(inode)) { if (UDF_I_LENEATTR(inode)) {
/* check checksum/crc */ /* check checksum/crc */
if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || if (le16_to_cpu(eahd->descTag.tagIdent) !=
le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { TAG_IDENT_EAHD ||
le32_to_cpu(eahd->descTag.tagLocation) !=
UDF_I_LOCATION(inode).logicalBlockNum)
return NULL; return NULL;
}
} else { } else {
struct udf_sb_info *sbi = UDF_SB(inode->i_sb); struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
size -= sizeof(struct extendedAttrHeaderDesc); size -= sizeof(struct extendedAttrHeaderDesc);
UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); UDF_I_LENEATTR(inode) +=
sizeof(struct extendedAttrHeaderDesc);
eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
if (sbi->s_udfrev >= 0x0200) if (sbi->s_udfrev >= 0x0200)
eahd->descTag.descVersion = cpu_to_le16(3); eahd->descTag.descVersion = cpu_to_le16(3);
else else
eahd->descTag.descVersion = cpu_to_le16(2); eahd->descTag.descVersion = cpu_to_le16(2);
eahd->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); eahd->descTag.tagSerialNum =
eahd->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); cpu_to_le16(sbi->s_serial_number);
eahd->descTag.tagLocation = cpu_to_le32(
UDF_I_LOCATION(inode).logicalBlockNum);
eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF);
eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF);
} }
offset = UDF_I_LENEATTR(inode); offset = UDF_I_LENEATTR(inode);
if (type < 2048) { if (type < 2048) {
if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->appAttrLocation) <
uint32_t aal = le32_to_cpu(eahd->appAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t aal =
le32_to_cpu(eahd->appAttrLocation);
memmove(&ea[offset - aal + size], memmove(&ea[offset - aal + size],
&ea[aal], offset - aal); &ea[aal], offset - aal);
offset -= aal; offset -= aal;
eahd->appAttrLocation = cpu_to_le32(aal + size); eahd->appAttrLocation =
cpu_to_le32(aal + size);
} }
if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->impAttrLocation) <
uint32_t ial = le32_to_cpu(eahd->impAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t ial =
le32_to_cpu(eahd->impAttrLocation);
memmove(&ea[offset - ial + size], memmove(&ea[offset - ial + size],
&ea[ial], offset - ial); &ea[ial], offset - ial);
offset -= ial; offset -= ial;
eahd->impAttrLocation = cpu_to_le32(ial + size); eahd->impAttrLocation =
cpu_to_le32(ial + size);
} }
} else if (type < 65536) { } else if (type < 65536) {
if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->appAttrLocation) <
uint32_t aal = le32_to_cpu(eahd->appAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t aal =
le32_to_cpu(eahd->appAttrLocation);
memmove(&ea[offset - aal + size], memmove(&ea[offset - aal + size],
&ea[aal], offset - aal); &ea[aal], offset - aal);
offset -= aal; offset -= aal;
eahd->appAttrLocation = cpu_to_le32(aal + size); eahd->appAttrLocation =
cpu_to_le32(aal + size);
} }
} }
/* rewrite CRC + checksum of eahd */ /* rewrite CRC + checksum of eahd */
crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
eahd->descTag.descCRCLength = cpu_to_le16(crclen); eahd->descTag.descCRCLength = cpu_to_le16(crclen);
eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
sizeof(tag), crclen, 0)); sizeof(tag), crclen, 0));
eahd->descTag.tagChecksum = 0; eahd->descTag.tagChecksum = 0;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
if (i != 4) if (i != 4)
eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; eahd->descTag.tagChecksum +=
((uint8_t *)&(eahd->descTag))[i];
UDF_I_LENEATTR(inode) += size; UDF_I_LENEATTR(inode) += size;
return (struct genericFormat *)&ea[offset]; return (struct genericFormat *)&ea[offset];
} }
if (loc & 0x02) { if (loc & 0x02)
} ;
return NULL; return NULL;
} }
@ -153,10 +166,11 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
eahd = (struct extendedAttrHeaderDesc *)ea; eahd = (struct extendedAttrHeaderDesc *)ea;
/* check checksum/crc */ /* check checksum/crc */
if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || if (le16_to_cpu(eahd->descTag.tagIdent) !=
le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { TAG_IDENT_EAHD ||
le32_to_cpu(eahd->descTag.tagLocation) !=
UDF_I_LOCATION(inode).logicalBlockNum)
return NULL; return NULL;
}
if (type < 2048) if (type < 2048)
offset = sizeof(struct extendedAttrHeaderDesc); offset = sizeof(struct extendedAttrHeaderDesc);
@ -167,7 +181,8 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
while (offset < UDF_I_LENEATTR(inode)) { while (offset < UDF_I_LENEATTR(inode)) {
gaf = (struct genericFormat *)&ea[offset]; gaf = (struct genericFormat *)&ea[offset];
if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) if (le32_to_cpu(gaf->attrType) == type &&
gaf->attrSubtype == subtype)
return gaf; return gaf;
else else
offset += le32_to_cpu(gaf->attrLength); offset += le32_to_cpu(gaf->attrLength);
@ -188,7 +203,7 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
* Written, tested, and released. * Written, tested, and released.
*/ */
struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
uint32_t location, uint16_t * ident) uint32_t location, uint16_t *ident)
{ {
tag *tag_p; tag *tag_p;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
@ -213,7 +228,8 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
if (location != le32_to_cpu(tag_p->tagLocation)) { if (location != le32_to_cpu(tag_p->tagLocation)) {
udf_debug("location mismatch block %u, tag %u != %u\n", udf_debug("location mismatch block %u, tag %u != %u\n",
block + sbi->s_session, le32_to_cpu(tag_p->tagLocation), location); block + sbi->s_session,
le32_to_cpu(tag_p->tagLocation), location);
goto error_out; goto error_out;
} }
@ -239,9 +255,9 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
/* Verify the descriptor CRC */ /* Verify the descriptor CRC */
if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
le16_to_cpu(tag_p->descCRCLength), 0)) { le16_to_cpu(tag_p->descCRCLength), 0))
return bh; return bh;
}
udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", udf_debug("Crc failure block %d: crc = %d, crclen = %d\n",
block + sbi->s_session, le16_to_cpu(tag_p->descCRC), block + sbi->s_session, le16_to_cpu(tag_p->descCRC),
le16_to_cpu(tag_p->descCRCLength)); le16_to_cpu(tag_p->descCRCLength));
@ -252,7 +268,7 @@ error_out:
} }
struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
uint32_t offset, uint16_t * ident) uint32_t offset, uint16_t *ident)
{ {
return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
loc.logicalBlockNum + offset, ident); loc.logicalBlockNum + offset, ident);

View File

@ -43,7 +43,7 @@ static inline int udf_match(int len1, const char *name1, int len2,
int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
uint8_t * impuse, uint8_t * fileident) uint8_t *impuse, uint8_t *fileident)
{ {
uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
uint16_t crc; uint16_t crc;
@ -68,7 +68,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
memcpy(fibh->ebh->b_data + offset, impuse, liu); memcpy(fibh->ebh->b_data + offset, impuse, liu);
} else { } else {
memcpy((uint8_t *)sfi->impUse, impuse, -offset); memcpy((uint8_t *)sfi->impUse, impuse, -offset);
memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); memcpy(fibh->ebh->b_data, impuse - offset,
liu + offset);
} }
} }
@ -80,8 +81,10 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
} else if (offset >= 0) { } else if (offset >= 0) {
memcpy(fibh->ebh->b_data + offset, fileident, lfi); memcpy(fibh->ebh->b_data + offset, fileident, lfi);
} else { } else {
memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); -offset);
memcpy(fibh->ebh->b_data, fileident - offset,
lfi + offset);
} }
} }
@ -101,13 +104,19 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
if (fibh->sbh == fibh->ebh) { if (fibh->sbh == fibh->ebh) {
crc = udf_crc((uint8_t *)sfi->impUse, crc = udf_crc((uint8_t *)sfi->impUse,
crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); crclen + sizeof(tag) -
sizeof(struct fileIdentDesc), crc);
} else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, crc = udf_crc(fibh->ebh->b_data +
crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); sizeof(struct fileIdentDesc) +
fibh->soffset,
crclen + sizeof(tag) -
sizeof(struct fileIdentDesc),
crc);
} else { } else {
crc = udf_crc((uint8_t *)sfi->impUse, crc = udf_crc((uint8_t *)sfi->impUse,
-fibh->soffset - sizeof(struct fileIdentDesc), crc); -fibh->soffset - sizeof(struct fileIdentDesc),
crc);
crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
} }
@ -121,7 +130,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
cfi->descTag.tagChecksum = checksum; cfi->descTag.tagChecksum = checksum;
if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); memcpy((uint8_t *)sfi, (uint8_t *)cfi,
sizeof(struct fileIdentDesc));
} else { } else {
memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
@ -159,22 +169,24 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
size = (udf_ext0_offset(dir) + dir->i_size) >> 2; size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
f_pos = (udf_ext0_offset(dir) >> 2); f_pos = (udf_ext0_offset(dir) >> 2);
fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; fibh->soffset = fibh->eoffset =
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
fibh->sbh = fibh->ebh = NULL; fibh->sbh = fibh->ebh = NULL;
} else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { &epos, &eloc, &elen, &offset) ==
(EXT_RECORDED_ALLOCATED >> 30)) {
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
epos.offset -= sizeof(short_ad); epos.offset -= sizeof(short_ad);
else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
epos.offset -= sizeof(long_ad); epos.offset -= sizeof(long_ad);
} else { } else
offset = 0; offset = 0;
}
if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->sbh) {
brelse(epos.bh); brelse(epos.bh);
return NULL; return NULL;
} }
@ -202,14 +214,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
} else { } else {
int poffset; /* Unpaded ending offset */ int poffset; /* Unpaded ending offset */
poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
liu + lfi;
if (poffset >= lfi) { if (poffset >= lfi)
nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); nameptr = (uint8_t *)(fibh->ebh->b_data +
} else { poffset - lfi);
else {
nameptr = fname; nameptr = fname;
memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh->ebh->b_data, poffset);
} }
} }
@ -226,11 +242,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
if (!lfi) if (!lfi)
continue; continue;
if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { if (flen && udf_match(flen, fname, dentry->d_name.len,
brelse(epos.bh); dentry->d_name.name)) {
return fi; brelse(epos.bh);
} return fi;
} }
} }
@ -291,16 +307,16 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
if (!strncmp(dentry->d_name.name, ".B=", 3)) { if (!strncmp(dentry->d_name.name, ".B=", 3)) {
kernel_lb_addr lb = { kernel_lb_addr lb = {
.logicalBlockNum = 0, .logicalBlockNum = 0,
.partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3, .partitionReferenceNum =
NULL, 0), simple_strtoul(dentry->d_name.name + 3,
NULL, 0),
}; };
inode = udf_iget(dir->i_sb, lb); inode = udf_iget(dir->i_sb, lb);
if (!inode) { if (!inode) {
unlock_kernel(); unlock_kernel();
return ERR_PTR(-EACCES); return ERR_PTR(-EACCES);
} }
} } else
else
#endif /* UDF_RECOVERY */ #endif /* UDF_RECOVERY */
if (udf_find_entry(dir, dentry, &fibh, &cfi)) { if (udf_find_entry(dir, dentry, &fibh, &cfi)) {
@ -347,8 +363,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
*err = -EINVAL; *err = -EINVAL;
return NULL; return NULL;
} }
if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name, namelen = udf_put_filename(sb, dentry->d_name.name, name,
dentry->d_name.len))) { dentry->d_name.len);
if (!namelen) {
*err = -ENAMETOOLONG; *err = -ENAMETOOLONG;
return NULL; return NULL;
} }
@ -360,22 +377,24 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
f_pos = (udf_ext0_offset(dir) >> 2); f_pos = (udf_ext0_offset(dir) >> 2);
fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; fibh->soffset = fibh->eoffset =
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
fibh->sbh = fibh->ebh = NULL; fibh->sbh = fibh->ebh = NULL;
} else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { &epos, &eloc, &elen, &offset) ==
(EXT_RECORDED_ALLOCATED >> 30)) {
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
epos.offset -= sizeof(short_ad); epos.offset -= sizeof(short_ad);
else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
epos.offset -= sizeof(long_ad); epos.offset -= sizeof(long_ad);
} else { } else
offset = 0; offset = 0;
}
if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->sbh) {
brelse(epos.bh); brelse(epos.bh);
*err = -EIO; *err = -EIO;
return NULL; return NULL;
@ -406,33 +425,39 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
liu = le16_to_cpu(cfi->lengthOfImpUse); liu = le16_to_cpu(cfi->lengthOfImpUse);
lfi = cfi->lengthFileIdent; lfi = cfi->lengthFileIdent;
if (fibh->sbh == fibh->ebh) { if (fibh->sbh == fibh->ebh)
nameptr = fi->fileIdent + liu; nameptr = fi->fileIdent + liu;
} else { else {
int poffset; /* Unpaded ending offset */ int poffset; /* Unpaded ending offset */
poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
liu + lfi;
if (poffset >= lfi) { if (poffset >= lfi)
nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); nameptr = (char *)(fibh->ebh->b_data +
} else { poffset - lfi);
else {
nameptr = fname; nameptr = fname;
memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh->ebh->b_data, poffset);
} }
} }
if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) { if (((sizeof(struct fileIdentDesc) +
liu + lfi + 3) & ~3) == nfidlen) {
brelse(epos.bh); brelse(epos.bh);
cfi->descTag.tagSerialNum = cpu_to_le16(1); cfi->descTag.tagSerialNum = cpu_to_le16(1);
cfi->fileVersionNum = cpu_to_le16(1); cfi->fileVersionNum = cpu_to_le16(1);
cfi->fileCharacteristics = 0; cfi->fileCharacteristics = 0;
cfi->lengthFileIdent = namelen; cfi->lengthFileIdent = namelen;
cfi->lengthOfImpUse = cpu_to_le16(0); cfi->lengthOfImpUse = cpu_to_le16(0);
if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
name))
return fi; return fi;
} else { else {
*err = -EIO; *err = -EIO;
return NULL; return NULL;
} }
@ -442,8 +467,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
if (!lfi || !dentry) if (!lfi || !dentry)
continue; continue;
if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { if (flen && udf_match(flen, fname, dentry->d_name.len,
dentry->d_name.name)) {
if (fibh->sbh != fibh->ebh) if (fibh->sbh != fibh->ebh)
brelse(fibh->ebh); brelse(fibh->ebh);
brelse(fibh->sbh); brelse(fibh->sbh);
@ -466,11 +492,14 @@ add:
if (fibh->sbh != fibh->ebh) if (fibh->sbh != fibh->ebh)
brelse(fibh->ebh); brelse(fibh->ebh);
brelse(fibh->sbh); brelse(fibh->sbh);
if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) fibh->sbh = fibh->ebh =
udf_expand_dir_adinicb(dir, &block, err);
if (!fibh->sbh)
return NULL; return NULL;
epos.block = UDF_I_LOCATION(dir); epos.block = UDF_I_LOCATION(dir);
eloc.logicalBlockNum = block; eloc.logicalBlockNum = block;
eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; eloc.partitionReferenceNum =
UDF_I_LOCATION(dir).partitionReferenceNum;
elen = dir->i_sb->s_blocksize; elen = dir->i_sb->s_blocksize;
epos.offset = udf_file_entry_alloc_offset(dir); epos.offset = udf_file_entry_alloc_offset(dir);
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
@ -489,13 +518,16 @@ add:
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
block = UDF_I_LOCATION(dir).logicalBlockNum; block = UDF_I_LOCATION(dir).logicalBlockNum;
fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - fi = (struct fileIdentDesc *)
udf_ext0_offset(dir) + (UDF_I_DATA(dir) + fibh->soffset -
UDF_I_LENEATTR(dir)); udf_ext0_offset(dir) +
UDF_I_LENEATTR(dir));
} else { } else {
block = eloc.logicalBlockNum + ((elen - 1) >> block = eloc.logicalBlockNum +
dir->i_sb->s_blocksize_bits); ((elen - 1) >>
fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); dir->i_sb->s_blocksize_bits);
fi = (struct fileIdentDesc *)
(fibh->sbh->b_data + fibh->soffset);
} }
} else { } else {
fibh->soffset = fibh->eoffset - sb->s_blocksize; fibh->soffset = fibh->eoffset - sb->s_blocksize;
@ -507,7 +539,9 @@ add:
block = eloc.logicalBlockNum + ((elen - 1) >> block = eloc.logicalBlockNum + ((elen - 1) >>
dir->i_sb->s_blocksize_bits); dir->i_sb->s_blocksize_bits);
fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err); fibh->ebh = udf_bread(dir,
f_pos >> (dir->i_sb->s_blocksize_bits - 2),
1, err);
if (!fibh->ebh) { if (!fibh->ebh) {
brelse(epos.bh); brelse(epos.bh);
brelse(fibh->sbh); brelse(fibh->sbh);
@ -519,24 +553,26 @@ add:
(EXT_RECORDED_ALLOCATED >> 30)) { (EXT_RECORDED_ALLOCATED >> 30)) {
block = eloc.logicalBlockNum + ((elen - 1) >> block = eloc.logicalBlockNum + ((elen - 1) >>
dir->i_sb->s_blocksize_bits); dir->i_sb->s_blocksize_bits);
} else { } else
block++; block++;
}
brelse(fibh->sbh); brelse(fibh->sbh);
fibh->sbh = fibh->ebh; fibh->sbh = fibh->ebh;
fi = (struct fileIdentDesc *)(fibh->sbh->b_data); fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
} else { } else {
fi = (struct fileIdentDesc *) fi = (struct fileIdentDesc *)
(fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); (fibh->sbh->b_data + sb->s_blocksize +
fibh->soffset);
} }
} }
memset(cfi, 0, sizeof(struct fileIdentDesc)); memset(cfi, 0, sizeof(struct fileIdentDesc));
if (UDF_SB(sb)->s_udfrev >= 0x0200) if (UDF_SB(sb)->s_udfrev >= 0x0200)
udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
sizeof(tag));
else else
udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
sizeof(tag));
cfi->fileVersionNum = cpu_to_le16(1); cfi->fileVersionNum = cpu_to_le16(1);
cfi->lengthFileIdent = namelen; cfi->lengthFileIdent = namelen;
cfi->lengthOfImpUse = cpu_to_le16(0); cfi->lengthOfImpUse = cpu_to_le16(0);
@ -593,7 +629,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
inode->i_mode = mode; inode->i_mode = mode;
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
inode->i_nlink--; inode->i_nlink--;
mark_inode_dirty(inode); mark_inode_dirty(inode);
iput(inode); iput(inode);
@ -605,9 +642,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir); mark_inode_dirty(dir);
}
if (fibh.sbh != fibh.ebh) if (fibh.sbh != fibh.ebh)
brelse(fibh.ebh); brelse(fibh.ebh);
brelse(fibh.sbh); brelse(fibh.sbh);
@ -636,7 +672,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
inode->i_uid = current->fsuid; inode->i_uid = current->fsuid;
init_special_inode(inode, mode, rdev); init_special_inode(inode, mode, rdev);
if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
inode->i_nlink--; inode->i_nlink--;
mark_inode_dirty(inode); mark_inode_dirty(inode);
iput(inode); iput(inode);
@ -648,9 +685,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir); mark_inode_dirty(dir);
}
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (fibh.sbh != fibh.ebh) if (fibh.sbh != fibh.ebh)
@ -683,7 +719,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
inode->i_op = &udf_dir_inode_operations; inode->i_op = &udf_dir_inode_operations;
inode->i_fop = &udf_dir_operations; inode->i_fop = &udf_dir_operations;
if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) { fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err);
if (!fi) {
inode->i_nlink--; inode->i_nlink--;
mark_inode_dirty(inode); mark_inode_dirty(inode);
iput(inode); iput(inode);
@ -694,7 +731,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir));
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL);
cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; cfi.fileCharacteristics =
FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
brelse(fibh.sbh); brelse(fibh.sbh);
inode->i_mode = S_IFDIR | mode; inode->i_mode = S_IFDIR | mode;
@ -702,7 +740,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
inode->i_mode |= S_ISGID; inode->i_mode |= S_ISGID;
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
inode->i_nlink = 0; inode->i_nlink = 0;
mark_inode_dirty(inode); mark_inode_dirty(inode);
iput(inode); iput(inode);
@ -741,23 +780,25 @@ static int empty_dir(struct inode *dir)
f_pos = (udf_ext0_offset(dir) >> 2); f_pos = (udf_ext0_offset(dir) >> 2);
fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; fibh.soffset = fibh.eoffset =
(f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
fibh.sbh = fibh.ebh = NULL; fibh.sbh = fibh.ebh = NULL;
} else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { &epos, &eloc, &elen, &offset) ==
(EXT_RECORDED_ALLOCATED >> 30)) {
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
epos.offset -= sizeof(short_ad); epos.offset -= sizeof(short_ad);
else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
epos.offset -= sizeof(long_ad); epos.offset -= sizeof(long_ad);
} else { } else
offset = 0; offset = 0;
}
if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block);
if (!fibh.sbh) {
brelse(epos.bh); brelse(epos.bh);
return 0; return 0;
} }
@ -826,7 +867,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
clear_nlink(inode); clear_nlink(inode);
inode->i_size = 0; inode->i_size = 0;
inode_dec_link_count(dir); inode_dec_link_count(dir);
inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); inode->i_ctime = dir->i_ctime = dir->i_mtime =
current_fs_time(dir->i_sb);
mark_inode_dirty(dir); mark_inode_dirty(dir);
end_rmdir: end_rmdir:
@ -902,7 +944,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
struct buffer_head *bh; struct buffer_head *bh;
lock_kernel(); lock_kernel();
if (!(inode = udf_new_inode(dir, S_IFLNK, &err))) inode = udf_new_inode(dir, S_IFLNK, &err);
if (!inode)
goto out; goto out;
inode->i_mode = S_IFLNK | S_IRWXUGO; inode->i_mode = S_IFLNK | S_IRWXUGO;
@ -914,22 +957,24 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
uint32_t elen; uint32_t elen;
block = udf_new_block(inode->i_sb, inode, block = udf_new_block(inode->i_sb, inode,
UDF_I_LOCATION(inode).partitionReferenceNum, UDF_I_LOCATION(inode).partitionReferenceNum,
UDF_I_LOCATION(inode).logicalBlockNum, &err); UDF_I_LOCATION(inode).logicalBlockNum, &err);
if (!block) if (!block)
goto out_no_entry; goto out_no_entry;
epos.block = UDF_I_LOCATION(inode); epos.block = UDF_I_LOCATION(inode);
epos.offset = udf_file_entry_alloc_offset(inode); epos.offset = udf_file_entry_alloc_offset(inode);
epos.bh = NULL; epos.bh = NULL;
eloc.logicalBlockNum = block; eloc.logicalBlockNum = block;
eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; eloc.partitionReferenceNum =
UDF_I_LOCATION(inode).partitionReferenceNum;
elen = inode->i_sb->s_blocksize; elen = inode->i_sb->s_blocksize;
UDF_I_LENEXTENTS(inode) = elen; UDF_I_LENEXTENTS(inode) = elen;
udf_add_aext(inode, &epos, eloc, elen, 0); udf_add_aext(inode, &epos, eloc, elen, 0);
brelse(epos.bh); brelse(epos.bh);
block = udf_get_pblock(inode->i_sb, block, block = udf_get_pblock(inode->i_sb, block,
UDF_I_LOCATION(inode).partitionReferenceNum, 0); UDF_I_LOCATION(inode).partitionReferenceNum,
0);
epos.bh = udf_tread(inode->i_sb, block); epos.bh = udf_tread(inode->i_sb, block);
lock_buffer(epos.bh); lock_buffer(epos.bh);
memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); 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,
if (compstart[0] == '.') { if (compstart[0] == '.') {
if ((symname - compstart) == 1) if ((symname - compstart) == 1)
pc->componentType = 4; pc->componentType = 4;
else if ((symname - compstart) == 2 && compstart[1] == '.') else if ((symname - compstart) == 2 &&
compstart[1] == '.')
pc->componentType = 3; pc->componentType = 3;
} }
@ -986,7 +1032,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
if (!namelen) if (!namelen)
goto out_no_entry; goto out_no_entry;
if (elen + sizeof(struct pathComponent) + namelen > eoffset) if (elen + sizeof(struct pathComponent) + namelen >
eoffset)
goto out_no_entry; goto out_no_entry;
else else
pc->lengthComponentIdent = namelen; pc->lengthComponentIdent = namelen;
@ -1009,16 +1056,19 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
UDF_I_LENALLOC(inode) = inode->i_size; UDF_I_LENALLOC(inode) = inode->i_size;
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi)
goto out_no_entry; goto out_no_entry;
cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
bh = UDF_SB(inode->i_sb)->s_lvid_bh; bh = UDF_SB(inode->i_sb)->s_lvid_bh;
if (bh) { if (bh) {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolHeaderDesc *lvhd; struct logicalVolHeaderDesc *lvhd;
uint64_t uniqueID; uint64_t uniqueID;
lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); lvhd = (struct logicalVolHeaderDesc *)
lvid->logicalVolContentsUse;
uniqueID = le64_to_cpu(lvhd->uniqueID); uniqueID = le64_to_cpu(lvhd->uniqueID);
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
@ -1028,9 +1078,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir); mark_inode_dirty(dir);
}
if (fibh.sbh != fibh.ebh) if (fibh.sbh != fibh.ebh)
brelse(fibh.ebh); brelse(fibh.ebh);
brelse(fibh.sbh); brelse(fibh.sbh);
@ -1062,7 +1111,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
return -EMLINK; return -EMLINK;
} }
if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
unlock_kernel(); unlock_kernel();
return err; return err;
} }
@ -1070,10 +1120,12 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
bh = UDF_SB(inode->i_sb)->s_lvid_bh; bh = UDF_SB(inode->i_sb)->s_lvid_bh;
if (bh) { if (bh) {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolHeaderDesc *lvhd; struct logicalVolHeaderDesc *lvhd;
uint64_t uniqueID; uint64_t uniqueID;
lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); lvhd = (struct logicalVolHeaderDesc *)
(lvid->logicalVolContentsUse);
uniqueID = le64_to_cpu(lvhd->uniqueID); uniqueID = le64_to_cpu(lvhd->uniqueID);
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
@ -1083,9 +1135,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir); mark_inode_dirty(dir);
}
if (fibh.sbh != fibh.ebh) if (fibh.sbh != fibh.ebh)
brelse(fibh.ebh); brelse(fibh.ebh);
@ -1109,13 +1160,15 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *old_inode = old_dentry->d_inode; struct inode *old_inode = old_dentry->d_inode;
struct inode *new_inode = new_dentry->d_inode; struct inode *new_inode = new_dentry->d_inode;
struct udf_fileident_bh ofibh, nfibh; struct udf_fileident_bh ofibh, nfibh;
struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
struct fileIdentDesc ocfi, ncfi;
struct buffer_head *dir_bh = NULL; struct buffer_head *dir_bh = NULL;
int retval = -ENOENT; int retval = -ENOENT;
kernel_lb_addr tloc; kernel_lb_addr tloc;
lock_kernel(); lock_kernel();
if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) { ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);
if (ofi) {
if (ofibh.sbh != ofibh.ebh) if (ofibh.sbh != ofibh.ebh)
brelse(ofibh.ebh); brelse(ofibh.ebh);
brelse(ofibh.sbh); brelse(ofibh.sbh);
@ -1144,29 +1197,35 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
} }
retval = -EIO; retval = -EIO;
if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - dir_fi = udf_get_fileident(
(UDF_I_EFE(old_inode) ? UDF_I_DATA(old_inode) -
sizeof(struct extendedFileEntry) : (UDF_I_EFE(old_inode) ?
sizeof(struct fileEntry)), sizeof(struct extendedFileEntry) :
old_inode->i_sb->s_blocksize, &offset); sizeof(struct fileEntry)),
old_inode->i_sb->s_blocksize, &offset);
} else { } else {
dir_bh = udf_bread(old_inode, 0, 0, &retval); dir_bh = udf_bread(old_inode, 0, 0, &retval);
if (!dir_bh) if (!dir_bh)
goto end_rename; goto end_rename;
dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); dir_fi = udf_get_fileident(dir_bh->b_data,
old_inode->i_sb->s_blocksize, &offset);
} }
if (!dir_fi) if (!dir_fi)
goto end_rename; goto end_rename;
tloc = lelb_to_cpu(dir_fi->icb.extLocation); tloc = lelb_to_cpu(dir_fi->icb.extLocation);
if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino) if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) !=
old_dir->i_ino)
goto end_rename; goto end_rename;
retval = -EMLINK; retval = -EMLINK;
if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1) if (!new_inode &&
new_dir->i_nlink >=
(256 << sizeof(new_dir->i_nlink)) - 1)
goto end_rename; goto end_rename;
} }
if (!nfi) { if (!nfi) {
nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
&retval);
if (!nfi) if (!nfi)
goto end_rename; goto end_rename;
} }
@ -1199,17 +1258,18 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
if (dir_fi) { if (dir_fi) {
dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir));
udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + udf_update_tag((char *)dir_fi,
le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); (sizeof(struct fileIdentDesc) +
if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(old_inode); mark_inode_dirty(old_inode);
} else { else
mark_buffer_dirty_inode(dir_bh, old_inode); mark_buffer_dirty_inode(dir_bh, old_inode);
}
inode_dec_link_count(old_dir); inode_dec_link_count(old_dir);
if (new_inode) { if (new_inode)
inode_dec_link_count(new_inode); inode_dec_link_count(new_inode);
} else { else {
inc_nlink(new_dir); inc_nlink(new_dir);
mark_inode_dirty(new_dir); mark_inode_dirty(new_dir);
} }

View File

@ -34,8 +34,8 @@ inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block,
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
if (partition >= sbi->s_partitions) { if (partition >= sbi->s_partitions) {
udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", udf_debug("block=%d, partition=%d, offset=%d: "
block, partition, offset); "invalid partition\n", block, partition, offset);
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
@ -54,13 +54,15 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
uint32_t loc; uint32_t loc;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
struct udf_virtual_data *vdata;
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
index = (sb->s_blocksize - map->s_type_specific.s_virtual.s_start_offset) / sizeof(uint32_t); vdata = &map->s_type_specific.s_virtual;
index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
if (block > map->s_type_specific.s_virtual.s_num_entries) { if (block > vdata->s_num_entries) {
udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", udf_debug("Trying to access block beyond end of VAT "
block, map->s_type_specific.s_virtual.s_num_entries); "(%d max %d)\n", block, vdata->s_num_entries);
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
@ -70,12 +72,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
index = block % (sb->s_blocksize / sizeof(uint32_t)); index = block % (sb->s_blocksize / sizeof(uint32_t));
} else { } else {
newblock = 0; newblock = 0;
index = map->s_type_specific.s_virtual.s_start_offset / sizeof(uint32_t) + block; index = vdata->s_start_offset / sizeof(uint32_t) + block;
} }
loc = udf_block_map(sbi->s_vat_inode, newblock); loc = udf_block_map(sbi->s_vat_inode, newblock);
if (!(bh = sb_bread(sb, loc))) { bh = sb_bread(sb, loc);
if (!bh) {
udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n",
sb, block, partition, loc, index); sb, block, partition, loc, index);
return 0xFFFFFFFF; return 0xFFFFFFFF;
@ -85,17 +88,19 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
brelse(bh); brelse(bh);
if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum == partition) { if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum ==
partition) {
udf_debug("recursive call to udf_get_pblock!\n"); udf_debug("recursive call to udf_get_pblock!\n");
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
return udf_get_pblock(sb, loc, return udf_get_pblock(sb, loc,
UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum, UDF_I_LOCATION(sbi->s_vat_inode).
partitionReferenceNum,
offset); offset);
} }
inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block, inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block,
uint16_t partition, uint32_t offset) uint16_t partition, uint32_t offset)
{ {
return udf_get_pblock_virt15(sb, block, partition, offset); 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,
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
uint32_t packet; uint32_t packet;
struct udf_sparing_data *sdata;
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
packet = (block + offset) & ~(map->s_type_specific.s_sparing.s_packet_len - 1); sdata = &map->s_type_specific.s_sparing;
packet = (block + offset) & ~(sdata->s_packet_len - 1);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (map->s_type_specific.s_sparing.s_spar_map[i] != NULL) { if (sdata->s_spar_map[i] != NULL) {
st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[i]->b_data; st = (struct sparingTable *)
sdata->s_spar_map[i]->b_data;
break; break;
} }
} }
if (st) { if (st) {
for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) { struct sparingEntry *entry = &st->mapEntry[i];
u32 origLoc = le32_to_cpu(entry->origLocation);
if (origLoc >= 0xFFFFFFF0)
break; break;
} else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) { else if (origLoc == packet)
return le32_to_cpu(st->mapEntry[i].mappedLocation) + return le32_to_cpu(entry->mappedLocation) +
((block + offset) & (map->s_type_specific.s_sparing.s_packet_len - 1)); ((block + offset) &
} else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) { (sdata->s_packet_len - 1));
else if (origLoc > packet)
break; break;
}
} }
} }
@ -144,63 +154,101 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
uint32_t packet; uint32_t packet;
int i, j, k, l; int i, j, k, l;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
u16 reallocationTableLen;
struct buffer_head *bh;
for (i = 0; i < sbi->s_partitions; i++) { for (i = 0; i < sbi->s_partitions; i++) {
struct udf_part_map *map = &sbi->s_partmaps[i]; struct udf_part_map *map = &sbi->s_partmaps[i];
if (old_block > map->s_partition_root && if (old_block > map->s_partition_root &&
old_block < map->s_partition_root + map->s_partition_len) { old_block < map->s_partition_root + map->s_partition_len) {
sdata = &map->s_type_specific.s_sparing; sdata = &map->s_type_specific.s_sparing;
packet = (old_block - map->s_partition_root) & ~(sdata->s_packet_len - 1); packet = (old_block - map->s_partition_root) &
~(sdata->s_packet_len - 1);
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++)
if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) { if (sdata->s_spar_map[j] != NULL) {
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; st = (struct sparingTable *)
sdata->s_spar_map[j]->b_data;
break; break;
} }
}
if (!st) if (!st)
return 1; return 1;
for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) { reallocationTableLen =
if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) { le16_to_cpu(st->reallocationTableLen);
for (k = 0; k < reallocationTableLen; k++) {
struct sparingEntry *entry = &st->mapEntry[k];
u32 origLoc = le32_to_cpu(entry->origLocation);
if (origLoc == 0xFFFFFFFF) {
for (; j < 4; j++) { for (; j < 4; j++) {
if (sdata->s_spar_map[j]) { int len;
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; bh = sdata->s_spar_map[j];
st->mapEntry[k].origLocation = cpu_to_le32(packet); if (!bh)
udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); continue;
mark_buffer_dirty(sdata->s_spar_map[j]);
} st = (struct sparingTable *)
bh->b_data;
entry->origLocation =
cpu_to_le32(packet);
len =
sizeof(struct sparingTable) +
reallocationTableLen *
sizeof(struct sparingEntry);
udf_update_tag((char *)st, len);
mark_buffer_dirty(bh);
} }
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + *new_block = le32_to_cpu(
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); entry->mappedLocation) +
((old_block -
map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0; return 0;
} else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) { } else if (origLoc == packet) {
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + *new_block = le32_to_cpu(
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); entry->mappedLocation) +
((old_block -
map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0; return 0;
} else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) { } else if (origLoc > packet)
break; break;
}
} }
for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) { for (l = k; l < reallocationTableLen; l++) {
if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) { struct sparingEntry *entry = &st->mapEntry[l];
for (; j < 4; j++) { u32 origLoc = le32_to_cpu(entry->origLocation);
if (sdata->s_spar_map[j]) {
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; if (origLoc != 0xFFFFFFFF)
mapEntry = st->mapEntry[l]; continue;
mapEntry.origLocation = cpu_to_le32(packet);
memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry)); for (; j < 4; j++) {
st->mapEntry[k] = mapEntry; bh = sdata->s_spar_map[j];
udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); if (!bh)
mark_buffer_dirty(sdata->s_spar_map[j]); continue;
}
} st = (struct sparingTable *)bh->b_data;
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + mapEntry = st->mapEntry[l];
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); mapEntry.origLocation =
return 0; cpu_to_le32(packet);
memmove(&st->mapEntry[k + 1],
&st->mapEntry[k],
(l - k) *
sizeof(struct sparingEntry));
st->mapEntry[k] = mapEntry;
udf_update_tag((char *)st,
sizeof(struct sparingTable) +
reallocationTableLen *
sizeof(struct sparingEntry));
mark_buffer_dirty(bh);
} }
*new_block =
le32_to_cpu(
st->mapEntry[k].mappedLocation) +
((old_block - map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0;
} }
return 1; return 1;

View File

@ -98,9 +98,11 @@ static int udf_statfs(struct dentry *, struct kstatfs *);
struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
{ {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
__u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions); __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
__u32 offset = number_of_partitions * 2 * sizeof(uint32_t)/sizeof(uint8_t); __u32 offset = number_of_partitions * 2 *
sizeof(uint32_t)/sizeof(uint8_t);
return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
} }
@ -713,16 +715,23 @@ static void udf_find_anchor(struct super_block *sb)
lastblock = last[i] - sbi->s_session; lastblock = last[i] - sbi->s_session;
sbi->s_anchor[0] = lastblock; sbi->s_anchor[0] = lastblock;
sbi->s_anchor[1] = lastblock - 256; sbi->s_anchor[1] = lastblock - 256;
} else if (location == udf_variable_to_fixed(last[i]) - sbi->s_session) { } else if (location ==
udf_variable_to_fixed(last[i]) -
sbi->s_session) {
UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
lastblock = udf_variable_to_fixed(last[i]) - sbi->s_session; lastblock =
udf_variable_to_fixed(last[i]) -
sbi->s_session;
sbi->s_anchor[0] = lastblock; sbi->s_anchor[0] = lastblock;
sbi->s_anchor[1] = lastblock - 256 - sbi->s_session; sbi->s_anchor[1] = lastblock - 256 -
sbi->s_session;
} else { } else {
udf_debug("Anchor found at block %d, location mismatch %d.\n", udf_debug("Anchor found at block %d, "
"location mismatch %d.\n",
last[i], location); last[i], location);
} }
} else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) { } else if (ident == TAG_IDENT_FE ||
ident == TAG_IDENT_EFE) {
lastblock = last[i]; lastblock = last[i];
sbi->s_anchor[3] = 512; sbi->s_anchor[3] = 512;
} else { } else {
@ -731,31 +740,40 @@ static void udf_find_anchor(struct super_block *sb)
bh = sb_bread(sb, last[i] - 256); bh = sb_bread(sb, last[i] - 256);
if (bh) { if (bh) {
tag *t = (tag *)bh->b_data; tag *t = (tag *)bh->b_data;
ident = le16_to_cpu(t->tagIdent); ident = le16_to_cpu(
location = le32_to_cpu(t->tagLocation); t->tagIdent);
location = le32_to_cpu(
t->tagLocation);
brelse(bh); brelse(bh);
} }
} }
if (ident == TAG_IDENT_AVDP && if (ident == TAG_IDENT_AVDP &&
location == last[i] - 256 - sbi->s_session) { location == last[i] - 256 -
sbi->s_session) {
lastblock = last[i]; lastblock = last[i];
sbi->s_anchor[1] = last[i] - 256; sbi->s_anchor[1] = last[i] - 256;
} else { } else {
ident = location = 0; ident = location = 0;
if (last[i] >= 312 + sbi->s_session) { if (last[i] >= 312 + sbi->s_session) {
bh = sb_bread(sb, last[i] - 312 - sbi->s_session); bh = sb_bread(sb,
last[i] - 312 -
sbi->s_session);
if (bh) { if (bh) {
tag *t = (tag *)bh->b_data; tag *t = (tag *)
ident = le16_to_cpu(t->tagIdent); bh->b_data;
location = le32_to_cpu(t->tagLocation); ident = le16_to_cpu(
t->tagIdent);
location = le32_to_cpu(
t->tagLocation);
brelse(bh); brelse(bh);
} }
} }
if (ident == TAG_IDENT_AVDP && if (ident == TAG_IDENT_AVDP &&
location == udf_variable_to_fixed(last[i]) - 256) { location == udf_variable_to_fixed(last[i]) - 256) {
UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); UDF_SET_FLAG(sb,
UDF_FLAG_VARCONV);
lastblock = udf_variable_to_fixed(last[i]); lastblock = udf_variable_to_fixed(last[i]);
sbi->s_anchor[1] = lastblock - 256; sbi->s_anchor[1] = lastblock - 256;
} }
@ -787,7 +805,8 @@ static void udf_find_anchor(struct super_block *sb)
else { else {
brelse(bh); brelse(bh);
if ((ident != TAG_IDENT_AVDP) && if ((ident != TAG_IDENT_AVDP) &&
(i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) (i || (ident != TAG_IDENT_FE &&
ident != TAG_IDENT_EFE)))
sbi->s_anchor[i] = 0; sbi->s_anchor[i] = 0;
} }
} }
@ -848,11 +867,12 @@ static int udf_find_fileset(struct super_block *sb,
case TAG_IDENT_SBD: case TAG_IDENT_SBD:
{ {
struct spaceBitmapDesc *sp; struct spaceBitmapDesc *sp;
sp = (struct spaceBitmapDesc *)bh->b_data; sp = (struct spaceBitmapDesc *)
bh->b_data;
newfileset.logicalBlockNum += 1 + newfileset.logicalBlockNum += 1 +
((le32_to_cpu(sp->numOfBytes) + ((le32_to_cpu(sp->numOfBytes) +
sizeof(struct spaceBitmapDesc) - 1) sizeof(struct spaceBitmapDesc)
>> sb->s_blocksize_bits); - 1) >> sb->s_blocksize_bits);
brelse(bh); brelse(bh);
break; break;
} }
@ -908,18 +928,17 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000; UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
} }
if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) { if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
if (udf_CS0toUTF8(&outstr, &instr)) { if (udf_CS0toUTF8(&outstr, &instr)) {
strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name, strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name,
outstr.u_len > 31 ? 31 : outstr.u_len); outstr.u_len > 31 ? 31 : outstr.u_len);
udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident); udf_debug("volIdent[] = '%s'\n",
UDF_SB(sb)->s_volume_ident);
} }
}
if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) { if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128))
if (udf_CS0toUTF8(&outstr, &instr)) if (udf_CS0toUTF8(&outstr, &instr))
udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
}
} }
static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, 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)
for (i = 0; i < sbi->s_partitions; i++) { for (i = 0; i < sbi->s_partitions; i++) {
map = &sbi->s_partmaps[i]; map = &sbi->s_partmaps[i];
udf_debug("Searching map: (%d == %d)\n", udf_debug("Searching map: (%d == %d)\n",
map->s_partition_num, le16_to_cpu(p->partitionNumber)); map->s_partition_num,
if (map->s_partition_num == le16_to_cpu(p->partitionNumber)) { le16_to_cpu(p->partitionNumber));
map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */ if (map->s_partition_num ==
map->s_partition_root = le32_to_cpu(p->partitionStartingLocation); le16_to_cpu(p->partitionNumber)) {
if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) map->s_partition_len =
map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY; le32_to_cpu(p->partitionLength); /* blocks */
if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE) map->s_partition_root =
map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE; le32_to_cpu(p->partitionStartingLocation);
if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE) if (le32_to_cpu(p->accessType) ==
map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE; PD_ACCESS_TYPE_READ_ONLY)
if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE) map->s_partition_flags |=
map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE; UDF_PART_FLAG_READ_ONLY;
if (le32_to_cpu(p->accessType) ==
PD_ACCESS_TYPE_WRITE_ONCE)
map->s_partition_flags |=
UDF_PART_FLAG_WRITE_ONCE;
if (le32_to_cpu(p->accessType) ==
PD_ACCESS_TYPE_REWRITABLE)
map->s_partition_flags |=
UDF_PART_FLAG_REWRITABLE;
if (le32_to_cpu(p->accessType) ==
PD_ACCESS_TYPE_OVERWRITABLE)
map->s_partition_flags |=
UDF_PART_FLAG_OVERWRITABLE;
if (!strcmp(p->partitionContents.ident, if (!strcmp(p->partitionContents.ident,
PD_PARTITION_CONTENTS_NSR02) || PD_PARTITION_CONTENTS_NSR02) ||
@ -1006,7 +1037,8 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
PD_PARTITION_CONTENTS_NSR03)) { PD_PARTITION_CONTENTS_NSR03)) {
struct partitionHeaderDesc *phd; struct partitionHeaderDesc *phd;
phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); phd = (struct partitionHeaderDesc *)
(p->partitionContentsUse);
if (phd->unallocSpaceTable.extLength) { if (phd->unallocSpaceTable.extLength) {
kernel_lb_addr loc = { kernel_lb_addr loc = {
.logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
@ -1019,20 +1051,23 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
udf_debug("cannot load unallocSpaceTable (part %d)\n", i); udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
return 1; return 1;
} }
map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; map->s_partition_flags |=
UDF_PART_FLAG_UNALLOC_TABLE;
udf_debug("unallocSpaceTable (part %d) @ %ld\n", udf_debug("unallocSpaceTable (part %d) @ %ld\n",
i, map->s_uspace.s_table->i_ino); i, map->s_uspace.s_table->i_ino);
} }
if (phd->unallocSpaceBitmap.extLength) { if (phd->unallocSpaceBitmap.extLength) {
map->s_uspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); struct udf_bitmap *bitmap =
if (map->s_uspace.s_bitmap != NULL) { udf_sb_alloc_bitmap(sb, i);
map->s_uspace.s_bitmap->s_extLength = map->s_uspace.s_bitmap = bitmap;
if (bitmap != NULL) {
bitmap->s_extLength =
le32_to_cpu(phd->unallocSpaceBitmap.extLength); le32_to_cpu(phd->unallocSpaceBitmap.extLength);
map->s_uspace.s_bitmap->s_extPosition = bitmap->s_extPosition =
le32_to_cpu(phd->unallocSpaceBitmap.extPosition); le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
udf_debug("unallocSpaceBitmap (part %d) @ %d\n", udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
i, map->s_uspace.s_bitmap->s_extPosition); i, bitmap->s_extPosition);
} }
} }
if (phd->partitionIntegrityTable.extLength) if (phd->partitionIntegrityTable.extLength)
@ -1049,37 +1084,39 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
udf_debug("cannot load freedSpaceTable (part %d)\n", i); udf_debug("cannot load freedSpaceTable (part %d)\n", i);
return 1; return 1;
} }
map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; map->s_partition_flags |=
UDF_PART_FLAG_FREED_TABLE;
udf_debug("freedSpaceTable (part %d) @ %ld\n", udf_debug("freedSpaceTable (part %d) @ %ld\n",
i, map->s_fspace.s_table->i_ino); i, map->s_fspace.s_table->i_ino);
} }
if (phd->freedSpaceBitmap.extLength) { if (phd->freedSpaceBitmap.extLength) {
map->s_fspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); struct udf_bitmap *bitmap =
if (map->s_fspace.s_bitmap != NULL) { udf_sb_alloc_bitmap(sb, i);
map->s_fspace.s_bitmap->s_extLength = map->s_fspace.s_bitmap = bitmap;
if (bitmap != NULL) {
bitmap->s_extLength =
le32_to_cpu(phd->freedSpaceBitmap.extLength); le32_to_cpu(phd->freedSpaceBitmap.extLength);
map->s_fspace.s_bitmap->s_extPosition = bitmap->s_extPosition =
le32_to_cpu(phd->freedSpaceBitmap.extPosition); le32_to_cpu(phd->freedSpaceBitmap.extPosition);
map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
udf_debug("freedSpaceBitmap (part %d) @ %d\n", udf_debug("freedSpaceBitmap (part %d) @ %d\n",
i, map->s_fspace.s_bitmap->s_extPosition); i, bitmap->s_extPosition);
} }
} }
} }
break; break;
} }
} }
if (i == sbi->s_partitions) { if (i == sbi->s_partitions)
udf_debug("Partition (%d) not found in partition map\n", udf_debug("Partition (%d) not found in partition map\n",
le16_to_cpu(p->partitionNumber)); le16_to_cpu(p->partitionNumber));
} else { else
udf_debug("Partition (%d:%d type %x) starts at physical %d, " udf_debug("Partition (%d:%d type %x) starts at physical %d, "
"block length %d\n", "block length %d\n",
le16_to_cpu(p->partitionNumber), i, le16_to_cpu(p->partitionNumber), i,
map->s_partition_type, map->s_partition_type,
map->s_partition_root, map->s_partition_root,
map->s_partition_len); map->s_partition_len);
}
return 0; return 0;
} }
@ -1090,6 +1127,7 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
int i, j, offset; int i, j, offset;
uint8_t type; uint8_t type;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct genericPartitionMap *gpm;
lvd = (struct logicalVolDesc *)bh->b_data; lvd = (struct logicalVolDesc *)bh->b_data;
@ -1099,43 +1137,71 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
for (i = 0, offset = 0; for (i = 0, offset = 0;
i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) { i++, offset += gpm->partitionMapLength) {
struct udf_part_map *map = &sbi->s_partmaps[i]; struct udf_part_map *map = &sbi->s_partmaps[i];
type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; gpm = (struct genericPartitionMap *)
&(lvd->partitionMaps[offset]);
type = gpm->partitionMapType;
if (type == 1) { if (type == 1) {
struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); struct genericPartitionMap1 *gpm1 =
(struct genericPartitionMap1 *)gpm;
map->s_partition_type = UDF_TYPE1_MAP15; map->s_partition_type = UDF_TYPE1_MAP15;
map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum); map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
map->s_partition_num = le16_to_cpu(gpm1->partitionNum); map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
map->s_partition_func = NULL; map->s_partition_func = NULL;
} else if (type == 2) { } else if (type == 2) {
struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); struct udfPartitionMap2 *upm2 =
if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) { (struct udfPartitionMap2 *)gpm;
if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) { if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
map->s_partition_type = UDF_VIRTUAL_MAP15; strlen(UDF_ID_VIRTUAL))) {
map->s_partition_func = udf_get_pblock_virt15; u16 suf =
} else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) { le16_to_cpu(((__le16 *)upm2->partIdent.
map->s_partition_type = UDF_VIRTUAL_MAP20; identSuffix)[0]);
map->s_partition_func = udf_get_pblock_virt20; if (suf == 0x0150) {
map->s_partition_type =
UDF_VIRTUAL_MAP15;
map->s_partition_func =
udf_get_pblock_virt15;
} else if (suf == 0x0200) {
map->s_partition_type =
UDF_VIRTUAL_MAP20;
map->s_partition_func =
udf_get_pblock_virt20;
} }
} else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) { } else if (!strncmp(upm2->partIdent.ident,
UDF_ID_SPARABLE,
strlen(UDF_ID_SPARABLE))) {
uint32_t loc; uint32_t loc;
uint16_t ident; uint16_t ident;
struct sparingTable *st; struct sparingTable *st;
struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]); struct sparablePartitionMap *spm =
(struct sparablePartitionMap *)gpm;
map->s_partition_type = UDF_SPARABLE_MAP15; map->s_partition_type = UDF_SPARABLE_MAP15;
map->s_type_specific.s_sparing.s_packet_len = le16_to_cpu(spm->packetLength); map->s_type_specific.s_sparing.s_packet_len =
le16_to_cpu(spm->packetLength);
for (j = 0; j < spm->numSparingTables; j++) { for (j = 0; j < spm->numSparingTables; j++) {
loc = le32_to_cpu(spm->locSparingTable[j]); struct buffer_head *bh2;
map->s_type_specific.s_sparing.s_spar_map[j] =
udf_read_tagged(sb, loc, loc, &ident); loc = le32_to_cpu(
if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) { spm->locSparingTable[j]);
st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[j]->b_data; bh2 = udf_read_tagged(sb, loc, loc,
if (ident != 0 || &ident);
strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) { map->s_type_specific.s_sparing.
brelse(map->s_type_specific.s_sparing.s_spar_map[j]); s_spar_map[j] = bh2;
map->s_type_specific.s_sparing.s_spar_map[j] = NULL;
if (bh2 != NULL) {
st = (struct sparingTable *)
bh2->b_data;
if (ident != 0 || strncmp(
st->sparingIdent.ident,
UDF_ID_SPARING,
strlen(UDF_ID_SPARING))) {
brelse(bh2);
map->s_type_specific.
s_sparing.
s_spar_map[j] =
NULL;
} }
} }
} }
@ -1218,6 +1284,7 @@ static int udf_process_sequence(struct super_block *sb, long block,
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
struct udf_vds_record vds[VDS_POS_LENGTH]; struct udf_vds_record vds[VDS_POS_LENGTH];
struct udf_vds_record *curr;
struct generic_desc *gd; struct generic_desc *gd;
struct volDescPtr *vdp; struct volDescPtr *vdp;
int done = 0; int done = 0;
@ -1240,43 +1307,51 @@ static int udf_process_sequence(struct super_block *sb, long block,
vdsn = le32_to_cpu(gd->volDescSeqNum); vdsn = le32_to_cpu(gd->volDescSeqNum);
switch (ident) { switch (ident) {
case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) { curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; if (vdsn >= curr->volDescSeqNum) {
vds[VDS_POS_PRIMARY_VOL_DESC].block = block; curr->volDescSeqNum = vdsn;
curr->block = block;
} }
break; break;
case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) { curr = &vds[VDS_POS_VOL_DESC_PTR];
vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; if (vdsn >= curr->volDescSeqNum) {
vds[VDS_POS_VOL_DESC_PTR].block = block; curr->volDescSeqNum = vdsn;
curr->block = block;
vdp = (struct volDescPtr *)bh->b_data; vdp = (struct volDescPtr *)bh->b_data;
next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); next_s = le32_to_cpu(
next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); vdp->nextVolDescSeqExt.extLocation);
next_e = le32_to_cpu(
vdp->nextVolDescSeqExt.extLength);
next_e = next_e >> sb->s_blocksize_bits; next_e = next_e >> sb->s_blocksize_bits;
next_e += next_s; next_e += next_s;
} }
break; break;
case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) { curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; if (vdsn >= curr->volDescSeqNum) {
vds[VDS_POS_IMP_USE_VOL_DESC].block = block; curr->volDescSeqNum = vdsn;
curr->block = block;
} }
break; break;
case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
if (!vds[VDS_POS_PARTITION_DESC].block) curr = &vds[VDS_POS_PARTITION_DESC];
vds[VDS_POS_PARTITION_DESC].block = block; if (!curr->block)
curr->block = block;
break; break;
case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) { curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; if (vdsn >= curr->volDescSeqNum) {
vds[VDS_POS_LOGICAL_VOL_DESC].block = block; curr->volDescSeqNum = vdsn;
curr->block = block;
} }
break; break;
case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) { curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; if (vdsn >= curr->volDescSeqNum) {
vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; curr->volDescSeqNum = vdsn;
curr->block = block;
} }
break; break;
case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
@ -1285,9 +1360,8 @@ static int udf_process_sequence(struct super_block *sb, long block,
block = next_s; block = next_s;
lastblock = next_e; lastblock = next_e;
next_s = next_e = 0; next_s = next_e = 0;
} else { } else
done = 1; done = 1;
}
break; break;
} }
brelse(bh); brelse(bh);
@ -1379,14 +1453,18 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
anchor = (struct anchorVolDescPtr *)bh->b_data; anchor = (struct anchorVolDescPtr *)bh->b_data;
/* Locate the main sequence */ /* Locate the main sequence */
main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); main_s = le32_to_cpu(
main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength); anchor->mainVolDescSeqExt.extLocation);
main_e = le32_to_cpu(
anchor->mainVolDescSeqExt.extLength);
main_e = main_e >> sb->s_blocksize_bits; main_e = main_e >> sb->s_blocksize_bits;
main_e += main_s; main_e += main_s;
/* Locate the reserve sequence */ /* Locate the reserve sequence */
reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); reserve_s = le32_to_cpu(
reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); anchor->reserveVolDescSeqExt.extLocation);
reserve_e = le32_to_cpu(
anchor->reserveVolDescSeqExt.extLength);
reserve_e = reserve_e >> sb->s_blocksize_bits; reserve_e = reserve_e >> sb->s_blocksize_bits;
reserve_e += reserve_s; reserve_e += reserve_s;
@ -1394,8 +1472,10 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
/* Process the main & reserve sequences */ /* Process the main & reserve sequences */
/* responsible for finding the PartitionDesc(s) */ /* responsible for finding the PartitionDesc(s) */
if (!(udf_process_sequence(sb, main_s, main_e, fileset) && if (!(udf_process_sequence(sb, main_s, main_e,
udf_process_sequence(sb, reserve_s, reserve_e, fileset))) fileset) &&
udf_process_sequence(sb, reserve_s, reserve_e,
fileset)))
break; break;
} }
} }
@ -1426,10 +1506,14 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
for (j = 0; j < sbi->s_partitions; j++) { for (j = 0; j < sbi->s_partitions; j++) {
struct udf_part_map *map2 = &sbi->s_partmaps[j]; struct udf_part_map *map2 = &sbi->s_partmaps[j];
if (j != i && if (j != i &&
map->s_volumeseqnum == map2->s_volumeseqnum && map->s_volumeseqnum ==
map->s_partition_num == map2->s_partition_num) { map2->s_volumeseqnum &&
map->s_partition_num ==
map2->s_partition_num) {
ino.partitionReferenceNum = j; ino.partitionReferenceNum = j;
ino.logicalBlockNum = sbi->s_last_block - map2->s_partition_root; ino.logicalBlockNum =
sbi->s_last_block -
map2->s_partition_root;
break; break;
} }
} }
@ -1448,17 +1532,22 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
(sbi->s_vat_inode->i_size - 36) >> 2; (sbi->s_vat_inode->i_size - 36) >> 2;
} else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
uint32_t pos; uint32_t pos;
struct virtualAllocationTable20 *vat20;
pos = udf_block_map(sbi->s_vat_inode, 0); pos = udf_block_map(sbi->s_vat_inode, 0);
bh = sb_bread(sb, pos); bh = sb_bread(sb, pos);
if (!bh) if (!bh)
return 1; return 1;
map->s_type_specific.s_virtual.s_start_offset = vat20 = (struct virtualAllocationTable20 *)
le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + bh->b_data +
udf_ext0_offset(sbi->s_vat_inode))->lengthHeader) +
udf_ext0_offset(sbi->s_vat_inode); udf_ext0_offset(sbi->s_vat_inode);
map->s_type_specific.s_virtual.s_num_entries = (sbi->s_vat_inode->i_size - map->s_type_specific.s_virtual.s_start_offset =
map->s_type_specific.s_virtual.s_start_offset) >> 2; le16_to_cpu(vat20->lengthHeader) +
udf_ext0_offset(sbi->s_vat_inode);
map->s_type_specific.s_virtual.s_num_entries =
(sbi->s_vat_inode->i_size -
map->s_type_specific.s_virtual.
s_start_offset) >> 2;
brelse(bh); brelse(bh);
} }
map->s_partition_root = udf_get_pblock(sb, 0, i, 0); map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
@ -1477,8 +1566,10 @@ static void udf_open_lvid(struct super_block *sb)
if (bh) { if (bh) {
int i; int i;
kernel_timestamp cpu_time; kernel_timestamp cpu_time;
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data; struct logicalVolIntegrityDesc *lvid =
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); (struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu =
udf_sb_lvidiu(sbi);
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
@ -1486,8 +1577,10 @@ static void udf_open_lvid(struct super_block *sb)
lvid->recordingDateAndTime = cpu_to_lets(cpu_time); lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
lvid->descTag.descCRC = cpu_to_le16(udf_crc((char *)lvid + sizeof(tag), lvid->descTag.descCRC = cpu_to_le16(
le16_to_cpu(lvid->descTag.descCRCLength), 0)); udf_crc((char *)lvid + sizeof(tag),
le16_to_cpu(lvid->descTag.descCRCLength),
0));
lvid->descTag.tagChecksum = 0; lvid->descTag.tagChecksum = 0;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
@ -1513,22 +1606,25 @@ static void udf_close_lvid(struct super_block *sb)
lvid = (struct logicalVolIntegrityDesc *)bh->b_data; lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) { if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); struct logicalVolIntegrityDescImpUse *lvidiu =
udf_sb_lvidiu(sbi);
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
lvid->recordingDateAndTime = cpu_to_lets(cpu_time); lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); lvidiu->maxUDFWriteRev =
cpu_to_le16(UDF_MAX_WRITE_VERSION);
if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
lvid->descTag.descCRC = lvid->descTag.descCRC = cpu_to_le16(
cpu_to_le16(udf_crc((char *)lvid + sizeof(tag), udf_crc((char *)lvid + sizeof(tag),
le16_to_cpu(lvid->descTag.descCRCLength), 0)); le16_to_cpu(lvid->descTag.descCRCLength),
0));
lvid->descTag.tagChecksum = 0; lvid->descTag.tagChecksum = 0;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
@ -1544,7 +1640,8 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
{ {
int i; int i;
int nr_groups = bitmap->s_nr_groups; int nr_groups = bitmap->s_nr_groups;
int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups); int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
nr_groups);
for (i = 0; i < nr_groups; i++) for (i = 0; i < nr_groups; i++)
if (bitmap->s_block_bitmap[i]) if (bitmap->s_block_bitmap[i])
@ -1662,19 +1759,21 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
udf_debug("Lastblock=%d\n", sbi->s_last_block); udf_debug("Lastblock=%d\n", sbi->s_last_block);
if (sbi->s_lvid_bh) { if (sbi->s_lvid_bh) {
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); struct logicalVolIntegrityDescImpUse *lvidiu =
udf_sb_lvidiu(sbi);
uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev); uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev); uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
/* uint16_t maxUDFWriteRev = le16_to_cpu(lvidiu->maxUDFWriteRev); */ /* uint16_t maxUDFWriteRev =
le16_to_cpu(lvidiu->maxUDFWriteRev); */
if (minUDFReadRev > UDF_MAX_READ_VERSION) { if (minUDFReadRev > UDF_MAX_READ_VERSION) {
printk(KERN_ERR "UDF-fs: minUDFReadRev=%x (max is %x)\n", printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
"(max is %x)\n",
le16_to_cpu(lvidiu->minUDFReadRev), le16_to_cpu(lvidiu->minUDFReadRev),
UDF_MAX_READ_VERSION); UDF_MAX_READ_VERSION);
goto error_out; goto error_out;
} else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) { } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
}
sbi->s_udfrev = minUDFWriteRev; sbi->s_udfrev = minUDFWriteRev;
@ -1689,8 +1788,10 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
goto error_out; goto error_out;
} }
if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & UDF_PART_FLAG_READ_ONLY) { if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
printk(KERN_NOTICE "UDF-fs: Partition marked readonly; forcing readonly mount\n"); UDF_PART_FLAG_READ_ONLY) {
printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
"forcing readonly mount\n");
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
} }
@ -1716,7 +1817,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
/* perhaps it's not extensible enough, but for now ... */ /* perhaps it's not extensible enough, but for now ... */
inode = udf_iget(sb, rootdir); inode = udf_iget(sb, rootdir);
if (!inode) { if (!inode) {
printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, partition=%d\n", printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
"partition=%d\n",
rootdir.logicalBlockNum, rootdir.partitionReferenceNum); rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
goto error_out; goto error_out;
} }
@ -1746,7 +1848,8 @@ error_out:
udf_sb_free_bitmap(map->s_fspace.s_bitmap); udf_sb_free_bitmap(map->s_fspace.s_bitmap);
if (map->s_partition_type == UDF_SPARABLE_MAP15) if (map->s_partition_type == UDF_SPARABLE_MAP15)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
brelse(map->s_type_specific.s_sparing.s_spar_map[i]); brelse(map->s_type_specific.s_sparing.
s_spar_map[i]);
} }
#ifdef CONFIG_UDF_NLS #ifdef CONFIG_UDF_NLS
if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
@ -1824,7 +1927,8 @@ static void udf_put_super(struct super_block *sb)
udf_sb_free_bitmap(map->s_fspace.s_bitmap); udf_sb_free_bitmap(map->s_fspace.s_bitmap);
if (map->s_partition_type == UDF_SPARABLE_MAP15) if (map->s_partition_type == UDF_SPARABLE_MAP15)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
brelse(map->s_type_specific.s_sparing.s_spar_map[i]); brelse(map->s_type_specific.s_sparing.
s_spar_map[i]);
} }
#ifdef CONFIG_UDF_NLS #ifdef CONFIG_UDF_NLS
if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
@ -1881,7 +1985,8 @@ static unsigned char udf_bitmap_lookup[16] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
}; };
static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) static unsigned int udf_count_free_bitmap(struct super_block *sb,
struct udf_bitmap *bitmap)
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
unsigned int accum = 0; unsigned int accum = 0;
@ -1942,7 +2047,8 @@ out:
return accum; return accum;
} }
static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table) static unsigned int udf_count_free_table(struct super_block *sb,
struct inode *table)
{ {
unsigned int accum = 0; unsigned int accum = 0;
uint32_t elen; uint32_t elen;
@ -1974,9 +2080,12 @@ static unsigned int udf_count_free(struct super_block *sb)
sbi = UDF_SB(sb); sbi = UDF_SB(sb);
if (sbi->s_lvid_bh) { if (sbi->s_lvid_bh) {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)
sbi->s_lvid_bh->b_data;
if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
accum = le32_to_cpu(lvid->freeSpaceTable[sbi->s_partition]); accum = le32_to_cpu(
lvid->freeSpaceTable[sbi->s_partition]);
if (accum == 0xFFFFFFFF) if (accum == 0xFFFFFFFF)
accum = 0; accum = 0;
} }

View File

@ -33,7 +33,8 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include "udf_i.h" #include "udf_i.h"
static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to) static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen,
char *to)
{ {
struct pathComponent *pc; struct pathComponent *pc;
int elen = 0; int elen = 0;

View File

@ -154,7 +154,8 @@ void udf_discard_prealloc(struct inode *inode)
extent_trunc(inode, &epos, eloc, etype, elen, 0); extent_trunc(inode, &epos, eloc, etype, elen, 0);
if (!epos.bh) { if (!epos.bh) {
UDF_I_LENALLOC(inode) = UDF_I_LENALLOC(inode) =
epos.offset - udf_file_entry_alloc_offset(inode); epos.offset -
udf_file_entry_alloc_offset(inode);
mark_inode_dirty(inode); mark_inode_dirty(inode);
} else { } else {
struct allocExtDesc *aed = struct allocExtDesc *aed =
@ -213,7 +214,8 @@ void udf_truncate_extents(struct inode *inode)
else else
lenalloc -= sizeof(struct allocExtDesc); lenalloc -= sizeof(struct allocExtDesc);
while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) { while ((etype = udf_current_aext(inode, &epos, &eloc,
&elen, 0)) != -1) {
if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
udf_write_aext(inode, &epos, neloc, nelen, 0); udf_write_aext(inode, &epos, neloc, nelen, 0);
if (indirect_ext_len) { if (indirect_ext_len) {
@ -225,35 +227,43 @@ void udf_truncate_extents(struct inode *inode)
0, indirect_ext_len); 0, indirect_ext_len);
} else { } else {
if (!epos.bh) { if (!epos.bh) {
UDF_I_LENALLOC(inode) = lenalloc; UDF_I_LENALLOC(inode) =
lenalloc;
mark_inode_dirty(inode); mark_inode_dirty(inode);
} else { } else {
struct allocExtDesc *aed = struct allocExtDesc *aed =
(struct allocExtDesc *)(epos.bh->b_data); (struct allocExtDesc *)
(epos.bh->b_data);
int len =
sizeof(struct allocExtDesc);
aed->lengthAllocDescs = aed->lengthAllocDescs =
cpu_to_le32(lenalloc); cpu_to_le32(lenalloc);
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || if (!UDF_QUERY_FLAG(sb,
UDF_FLAG_STRICT) ||
sbi->s_udfrev >= 0x0201) sbi->s_udfrev >= 0x0201)
udf_update_tag(epos.bh->b_data, len += lenalloc;
lenalloc +
sizeof(struct allocExtDesc)); udf_update_tag(epos.bh->b_data,
else len);
udf_update_tag(epos.bh->b_data, mark_buffer_dirty_inode(
sizeof(struct allocExtDesc)); epos.bh, inode);
mark_buffer_dirty_inode(epos.bh, inode);
} }
} }
brelse(epos.bh); brelse(epos.bh);
epos.offset = sizeof(struct allocExtDesc); epos.offset = sizeof(struct allocExtDesc);
epos.block = eloc; epos.block = eloc;
epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); epos.bh = udf_tread(sb,
udf_get_lb_pblock(sb, eloc, 0));
if (elen) if (elen)
indirect_ext_len = (elen + sb->s_blocksize -1) >> indirect_ext_len =
(elen + sb->s_blocksize - 1) >>
sb->s_blocksize_bits; sb->s_blocksize_bits;
else else
indirect_ext_len = 1; indirect_ext_len = 1;
} else { } else {
extent_trunc(inode, &epos, eloc, etype, elen, 0); extent_trunc(inode, &epos, eloc, etype,
elen, 0);
epos.offset += adsize; epos.offset += adsize;
} }
} }
@ -274,10 +284,11 @@ void udf_truncate_extents(struct inode *inode)
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
sbi->s_udfrev >= 0x0201) sbi->s_udfrev >= 0x0201)
udf_update_tag(epos.bh->b_data, udf_update_tag(epos.bh->b_data,
lenalloc + sizeof(struct allocExtDesc)); lenalloc +
sizeof(struct allocExtDesc));
else else
udf_update_tag(epos.bh->b_data, udf_update_tag(epos.bh->b_data,
sizeof(struct allocExtDesc)); sizeof(struct allocExtDesc));
mark_buffer_dirty_inode(epos.bh, inode); mark_buffer_dirty_inode(epos.bh, inode);
} }
} }
@ -291,13 +302,16 @@ void udf_truncate_extents(struct inode *inode)
* extending the file by 'offset' blocks. * extending the file by 'offset' blocks.
*/ */
if ((!epos.bh && if ((!epos.bh &&
epos.offset == udf_file_entry_alloc_offset(inode)) || epos.offset ==
(epos.bh && epos.offset == sizeof(struct allocExtDesc))) { udf_file_entry_alloc_offset(inode)) ||
(epos.bh && epos.offset ==
sizeof(struct allocExtDesc))) {
/* File has no extents at all or has empty last /* File has no extents at all or has empty last
* indirect extent! Create a fake extent... */ * indirect extent! Create a fake extent... */
extent.extLocation.logicalBlockNum = 0; extent.extLocation.logicalBlockNum = 0;
extent.extLocation.partitionReferenceNum = 0; extent.extLocation.partitionReferenceNum = 0;
extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; extent.extLength =
EXT_NOT_RECORDED_NOT_ALLOCATED;
} else { } else {
epos.offset -= adsize; epos.offset -= adsize;
etype = udf_next_aext(inode, &epos, etype = udf_next_aext(inode, &epos,
@ -306,7 +320,9 @@ void udf_truncate_extents(struct inode *inode)
extent.extLength |= etype << 30; extent.extLength |= etype << 30;
} }
udf_extend_file(inode, &epos, &extent, udf_extend_file(inode, &epos, &extent,
offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0)); offset +
((inode->i_size &
(sb->s_blocksize - 1)) != 0));
} }
} }
UDF_I_LENEXTENTS(inode) = inode->i_size; UDF_I_LENEXTENTS(inode) = inode->i_size;

View File

@ -18,8 +18,10 @@
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
/* /*
* dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time * dgb 10/02/98: ripped this from glibc source to help convert timestamps
* 10/04/98: added new table-based lookup after seeing how ugly the gnu code is * to unix time
* 10/04/98: added new table-based lookup after seeing how ugly
* the gnu code is
* blf 09/27/99: ripped out all the old code and inserted new table from * blf 09/27/99: ripped out all the old code and inserted new table from
* John Brockmeyer (without leap second corrections) * John Brockmeyer (without leap second corrections)
* rewrote udf_stamp_to_time and fixed timezone accounting in * rewrote udf_stamp_to_time and fixed timezone accounting in
@ -55,27 +57,27 @@ static const unsigned short int __mon_yday[2][13] = {
#define MAX_YEAR_SECONDS 69 #define MAX_YEAR_SECONDS 69
#define SPD 0x15180 /*3600*24 */ #define SPD 0x15180 /*3600*24 */
#define SPY(y,l,s) (SPD * (365*y+l)+s) #define SPY(y, l, s) (SPD * (365 * y + l) + s)
static time_t year_seconds[MAX_YEAR_SECONDS]= { static time_t year_seconds[MAX_YEAR_SECONDS] = {
/*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0), /*1970*/ SPY(0, 0, 0), SPY(1, 0, 0), SPY(2, 0, 0), SPY(3, 1, 0),
/*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0), /*1974*/ SPY(4, 1, 0), SPY(5, 1, 0), SPY(6, 1, 0), SPY(7, 2, 0),
/*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0), /*1978*/ SPY(8, 2, 0), SPY(9, 2, 0), SPY(10, 2, 0), SPY(11, 3, 0),
/*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0), /*1982*/ SPY(12, 3, 0), SPY(13, 3, 0), SPY(14, 3, 0), SPY(15, 4, 0),
/*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0), /*1986*/ SPY(16, 4, 0), SPY(17, 4, 0), SPY(18, 4, 0), SPY(19, 5, 0),
/*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0), /*1990*/ SPY(20, 5, 0), SPY(21, 5, 0), SPY(22, 5, 0), SPY(23, 6, 0),
/*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0), /*1994*/ SPY(24, 6, 0), SPY(25, 6, 0), SPY(26, 6, 0), SPY(27, 7, 0),
/*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0), /*1998*/ SPY(28, 7, 0), SPY(29, 7, 0), SPY(30, 7, 0), SPY(31, 8, 0),
/*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0), /*2002*/ SPY(32, 8, 0), SPY(33, 8, 0), SPY(34, 8, 0), SPY(35, 9, 0),
/*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0), /*2006*/ SPY(36, 9, 0), SPY(37, 9, 0), SPY(38, 9, 0), SPY(39, 10, 0),
/*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0), /*2010*/ SPY(40, 10, 0), SPY(41, 10, 0), SPY(42, 10, 0), SPY(43, 11, 0),
/*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0), /*2014*/ SPY(44, 11, 0), SPY(45, 11, 0), SPY(46, 11, 0), SPY(47, 12, 0),
/*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0), /*2018*/ SPY(48, 12, 0), SPY(49, 12, 0), SPY(50, 12, 0), SPY(51, 13, 0),
/*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0), /*2022*/ SPY(52, 13, 0), SPY(53, 13, 0), SPY(54, 13, 0), SPY(55, 14, 0),
/*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0), /*2026*/ SPY(56, 14, 0), SPY(57, 14, 0), SPY(58, 14, 0), SPY(59, 15, 0),
/*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0), /*2030*/ SPY(60, 15, 0), SPY(61, 15, 0), SPY(62, 15, 0), SPY(63, 16, 0),
/*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0), /*2034*/ SPY(64, 16, 0), SPY(65, 16, 0), SPY(66, 16, 0), SPY(67, 17, 0),
/*2038*/ SPY(68,17,0) /*2038*/ SPY(68, 17, 0)
}; };
extern struct timezone sys_tz; extern struct timezone sys_tz;
@ -115,7 +117,7 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
return dest; return dest;
} }
kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
{ {
long int days, rem, y; long int days, rem, y;
const unsigned short int *ip; const unsigned short int *ip;
@ -137,7 +139,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
dest->second = rem % 60; dest->second = rem % 60;
y = 1970; y = 1970;
#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
@ -145,8 +147,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
/* Adjust DAYS and Y to match the guessed year. */ /* Adjust DAYS and Y to match the guessed year. */
days -= ((yg - y) * 365 days -= ((yg - y) * 365
+ LEAPS_THRU_END_OF (yg - 1) + LEAPS_THRU_END_OF(yg - 1)
- LEAPS_THRU_END_OF (y - 1)); - LEAPS_THRU_END_OF(y - 1));
y = yg; y = yg;
} }
dest->year = y; dest->year = y;
@ -158,7 +160,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
dest->day = days + 1; dest->day = days + 1;
dest->centiseconds = ts.tv_nsec / 10000000; dest->centiseconds = ts.tv_nsec / 10000000;
dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
dest->centiseconds * 10000) / 100;
dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
dest->hundredsOfMicroseconds * 100); dest->hundredsOfMicroseconds * 100);
return dest; return dest;

View File

@ -136,12 +136,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
if (c < 0x80U) { if (c < 0x80U) {
utf_o->u_name[utf_o->u_len++] = (uint8_t)c; utf_o->u_name[utf_o->u_len++] = (uint8_t)c;
} else if (c < 0x800U) { } else if (c < 0x800U) {
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); utf_o->u_name[utf_o->u_len++] =
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); (uint8_t)(0xc0 | (c >> 6));
utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 | (c & 0x3f));
} else { } else {
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); utf_o->u_name[utf_o->u_len++] =
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); (uint8_t)(0xe0 | (c >> 12));
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 |
((c >> 6) & 0x3f));
utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 | (c & 0x3f));
} }
} }
utf_o->u_cmpID = 8; utf_o->u_cmpID = 8;
@ -232,9 +238,8 @@ try_again:
goto error_out; goto error_out;
} }
if (max_val == 0xffffU) { if (max_val == 0xffffU)
ocu[++u_len] = (uint8_t)(utf_char >> 8); ocu[++u_len] = (uint8_t)(utf_char >> 8);
}
ocu[++u_len] = (uint8_t)(utf_char & 0xffU); ocu[++u_len] = (uint8_t)(utf_char & 0xffU);
} }
@ -330,29 +335,29 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
struct ustr filename, unifilename; struct ustr filename, unifilename;
int len; int len;
if (udf_build_ustr_exact(&unifilename, sname, flen)) { if (udf_build_ustr_exact(&unifilename, sname, flen))
return 0; return 0;
}
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
if (!udf_CS0toUTF8(&filename, &unifilename)) { if (!udf_CS0toUTF8(&filename, &unifilename)) {
udf_debug("Failed in udf_get_filename: sname = %s\n", sname); udf_debug("Failed in udf_get_filename: sname = %s\n",
sname);
return 0; return 0;
} }
} else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) { if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename,
udf_debug("Failed in udf_get_filename: sname = %s\n", sname); &unifilename)) {
udf_debug("Failed in udf_get_filename: sname = %s\n",
sname);
return 0; return 0;
} }
} else { } else
return 0; return 0;
}
len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, len = udf_translate_to_linux(dname, filename.u_name, filename.u_len,
unifilename.u_name, unifilename.u_len); unifilename.u_name, unifilename.u_len);
if (len) { if (len)
return len; return len;
}
return 0; return 0;
} }
@ -363,23 +368,20 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
struct ustr unifilename; struct ustr unifilename;
int namelen; int namelen;
if (!(udf_char_to_ustr(&unifilename, sname, flen))) { if (!udf_char_to_ustr(&unifilename, sname, flen))
return 0; return 0;
}
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN);
if (!namelen) { if (!namelen)
return 0; return 0;
}
} else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN); namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname,
if (!namelen) { &unifilename, UDF_NAME_LEN);
if (!namelen)
return 0; return 0;
} } else
} else {
return 0; return 0;
}
return namelen; return namelen;
} }
@ -389,8 +391,9 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
#define CRC_MARK '#' #define CRC_MARK '#'
#define EXT_SIZE 5 #define EXT_SIZE 5
static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
uint8_t *fidName, int fidNameLen) int udfLen, uint8_t *fidName,
int fidNameLen)
{ {
int index, newIndex = 0, needsCRC = 0; int index, newIndex = 0, needsCRC = 0;
int extIndex = 0, newExtIndex = 0, hasExt = 0; 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
if (curr == '/' || curr == 0) { if (curr == '/' || curr == 0) {
needsCRC = 1; needsCRC = 1;
curr = ILLEGAL_CHAR_MARK; curr = ILLEGAL_CHAR_MARK;
while (index + 1 < udfLen && (udfName[index + 1] == '/' || while (index + 1 < udfLen &&
udfName[index + 1] == 0)) (udfName[index + 1] == '/' ||
udfName[index + 1] == 0))
index++; index++;
} if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) { }
if (udfLen == index + 1) { if (curr == EXT_MARK &&
(udfLen - index - 1) <= EXT_SIZE) {
if (udfLen == index + 1)
hasExt = 0; hasExt = 0;
} else { else {
hasExt = 1; hasExt = 1;
extIndex = index; extIndex = index;
newExtIndex = newIndex; newExtIndex = newIndex;
@ -433,16 +439,18 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
if (hasExt) { if (hasExt) {
int maxFilenameLen; int maxFilenameLen;
for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) { for (index = 0;
index < EXT_SIZE && extIndex + index + 1 < udfLen;
index++) {
curr = udfName[extIndex + index + 1]; curr = udfName[extIndex + index + 1];
if (curr == '/' || curr == 0) { if (curr == '/' || curr == 0) {
needsCRC = 1; needsCRC = 1;
curr = ILLEGAL_CHAR_MARK; curr = ILLEGAL_CHAR_MARK;
while(extIndex + index + 2 < udfLen && while (extIndex + index + 2 < udfLen &&
(index + 1 < EXT_SIZE (index + 1 < EXT_SIZE &&
&& (udfName[extIndex + index + 2] == '/' || (udfName[extIndex + index + 2] == '/' ||
udfName[extIndex + index + 2] == 0))) udfName[extIndex + index + 2] == 0)))
index++; index++;
} }
ext[localExtIndex++] = curr; ext[localExtIndex++] = curr;
@ -452,9 +460,8 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
newIndex = maxFilenameLen; newIndex = maxFilenameLen;
else else
newIndex = newExtIndex; newIndex = newExtIndex;
} else if (newIndex > 250) { } else if (newIndex > 250)
newIndex = 250; newIndex = 250;
}
newName[newIndex++] = CRC_MARK; newName[newIndex++] = CRC_MARK;
valueCRC = udf_crc(fidName, fidNameLen, 0); valueCRC = udf_crc(fidName, fidNameLen, 0);
newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];