aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf')
-rw-r--r--fs/udf/balloc.c543
-rw-r--r--fs/udf/crc.c19
-rw-r--r--fs/udf/dir.c108
-rw-r--r--fs/udf/directory.c173
-rw-r--r--fs/udf/ecma_167.h191
-rw-r--r--fs/udf/file.c102
-rw-r--r--fs/udf/fsync.c6
-rw-r--r--fs/udf/ialloc.c42
-rw-r--r--fs/udf/inode.c1239
-rw-r--r--fs/udf/lowlevel.c21
-rw-r--r--fs/udf/misc.c113
-rw-r--r--fs/udf/namei.c564
-rw-r--r--fs/udf/osta_udf.h75
-rw-r--r--fs/udf/partition.c119
-rw-r--r--fs/udf/super.c1256
-rw-r--r--fs/udf/symlink.c54
-rw-r--r--fs/udf/truncate.c166
-rw-r--r--fs/udf/udf_sb.h20
-rw-r--r--fs/udf/udfdecl.h102
-rw-r--r--fs/udf/udfend.h18
-rw-r--r--fs/udf/udftime.c87
-rw-r--r--fs/udf/unicode.c258
22 files changed, 2335 insertions, 2941 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 4cec91015681..276f7207a564 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -41,18 +41,17 @@
41#define uint(x) xuint(x) 41#define uint(x) xuint(x)
42#define xuint(x) __le ## x 42#define xuint(x) __le ## x
43 43
44static inline int find_next_one_bit (void * addr, int size, int offset) 44static inline int find_next_one_bit(void *addr, int size, int offset)
45{ 45{
46 uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); 46 uintBPL_t *p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG);
47 int result = offset & ~(BITS_PER_LONG-1); 47 int result = offset & ~(BITS_PER_LONG - 1);
48 unsigned long tmp; 48 unsigned long tmp;
49 49
50 if (offset >= size) 50 if (offset >= size)
51 return size; 51 return size;
52 size -= result; 52 size -= result;
53 offset &= (BITS_PER_LONG-1); 53 offset &= (BITS_PER_LONG - 1);
54 if (offset) 54 if (offset) {
55 {
56 tmp = leBPL_to_cpup(p++); 55 tmp = leBPL_to_cpup(p++);
57 tmp &= ~0UL << offset; 56 tmp &= ~0UL << offset;
58 if (size < BITS_PER_LONG) 57 if (size < BITS_PER_LONG)
@@ -62,8 +61,7 @@ static inline int find_next_one_bit (void * addr, int size, int offset)
62 size -= BITS_PER_LONG; 61 size -= BITS_PER_LONG;
63 result += BITS_PER_LONG; 62 result += BITS_PER_LONG;
64 } 63 }
65 while (size & ~(BITS_PER_LONG-1)) 64 while (size & ~(BITS_PER_LONG - 1)) {
66 {
67 if ((tmp = leBPL_to_cpup(p++))) 65 if ((tmp = leBPL_to_cpup(p++)))
68 goto found_middle; 66 goto found_middle;
69 result += BITS_PER_LONG; 67 result += BITS_PER_LONG;
@@ -73,7 +71,7 @@ static inline int find_next_one_bit (void * addr, int size, int offset)
73 return result; 71 return result;
74 tmp = leBPL_to_cpup(p); 72 tmp = leBPL_to_cpup(p);
75found_first: 73found_first:
76 tmp &= ~0UL >> (BITS_PER_LONG-size); 74 tmp &= ~0UL >> (BITS_PER_LONG - size);
77found_middle: 75found_middle:
78 return result + ffz(~tmp); 76 return result + ffz(~tmp);
79} 77}
@@ -81,8 +79,9 @@ found_middle:
81#define find_first_one_bit(addr, size)\ 79#define find_first_one_bit(addr, size)\
82 find_next_one_bit((addr), (size), 0) 80 find_next_one_bit((addr), (size), 0)
83 81
84static int read_block_bitmap(struct super_block * sb, 82static int read_block_bitmap(struct super_block *sb,
85 struct udf_bitmap *bitmap, unsigned int block, unsigned long bitmap_nr) 83 struct udf_bitmap *bitmap, unsigned int block,
84 unsigned long bitmap_nr)
86{ 85{
87 struct buffer_head *bh = NULL; 86 struct buffer_head *bh = NULL;
88 int retval = 0; 87 int retval = 0;
@@ -92,38 +91,39 @@ static int read_block_bitmap(struct super_block * sb,
92 loc.partitionReferenceNum = UDF_SB_PARTITION(sb); 91 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
93 92
94 bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); 93 bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
95 if (!bh) 94 if (!bh) {
96 {
97 retval = -EIO; 95 retval = -EIO;
98 } 96 }
99 bitmap->s_block_bitmap[bitmap_nr] = bh; 97 bitmap->s_block_bitmap[bitmap_nr] = bh;
100 return retval; 98 return retval;
101} 99}
102 100
103static int __load_block_bitmap(struct super_block * sb, 101static int __load_block_bitmap(struct super_block *sb,
104 struct udf_bitmap *bitmap, unsigned int block_group) 102 struct udf_bitmap *bitmap,
103 unsigned int block_group)
105{ 104{
106 int retval = 0; 105 int retval = 0;
107 int nr_groups = bitmap->s_nr_groups; 106 int nr_groups = bitmap->s_nr_groups;
108 107
109 if (block_group >= nr_groups) 108 if (block_group >= nr_groups) {
110 { 109 udf_debug("block_group (%d) > nr_groups (%d)\n", block_group,
111 udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, nr_groups); 110 nr_groups);
112 } 111 }
113 112
114 if (bitmap->s_block_bitmap[block_group]) 113 if (bitmap->s_block_bitmap[block_group]) {
115 return block_group; 114 return block_group;
116 else 115 } else {
117 { 116 retval = read_block_bitmap(sb, bitmap, block_group,
118 retval = read_block_bitmap(sb, bitmap, block_group, block_group); 117 block_group);
119 if (retval < 0) 118 if (retval < 0)
120 return retval; 119 return retval;
121 return block_group; 120 return block_group;
122 } 121 }
123} 122}
124 123
125static inline int load_block_bitmap(struct super_block * sb, 124static inline int load_block_bitmap(struct super_block *sb,
126 struct udf_bitmap *bitmap, unsigned int block_group) 125 struct udf_bitmap *bitmap,
126 unsigned int block_group)
127{ 127{
128 int slot; 128 int slot;
129 129
@@ -138,13 +138,14 @@ static inline int load_block_bitmap(struct super_block * sb,
138 return slot; 138 return slot;
139} 139}
140 140
141static void udf_bitmap_free_blocks(struct super_block * sb, 141static void udf_bitmap_free_blocks(struct super_block *sb,
142 struct inode * inode, 142 struct inode *inode,
143 struct udf_bitmap *bitmap, 143 struct udf_bitmap *bitmap,
144 kernel_lb_addr bloc, uint32_t offset, uint32_t count) 144 kernel_lb_addr bloc, uint32_t offset,
145 uint32_t count)
145{ 146{
146 struct udf_sb_info *sbi = UDF_SB(sb); 147 struct udf_sb_info *sbi = UDF_SB(sb);
147 struct buffer_head * bh = NULL; 148 struct buffer_head *bh = NULL;
148 unsigned long block; 149 unsigned long block;
149 unsigned long block_group; 150 unsigned long block_group;
150 unsigned long bit; 151 unsigned long bit;
@@ -154,11 +155,10 @@ static void udf_bitmap_free_blocks(struct super_block * sb,
154 155
155 mutex_lock(&sbi->s_alloc_mutex); 156 mutex_lock(&sbi->s_alloc_mutex);
156 if (bloc.logicalBlockNum < 0 || 157 if (bloc.logicalBlockNum < 0 ||
157 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) 158 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) {
158 {
159 udf_debug("%d < %d || %d + %d > %d\n", 159 udf_debug("%d < %d || %d + %d > %d\n",
160 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, 160 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
161 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); 161 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
162 goto error_return; 162 goto error_return;
163 } 163 }
164 164
@@ -172,8 +172,7 @@ do_more:
172 /* 172 /*
173 * Check to see if we are freeing blocks across a group boundary. 173 * Check to see if we are freeing blocks across a group boundary.
174 */ 174 */
175 if (bit + count > (sb->s_blocksize << 3)) 175 if (bit + count > (sb->s_blocksize << 3)) {
176 {
177 overflow = bit + count - (sb->s_blocksize << 3); 176 overflow = bit + count - (sb->s_blocksize << 3);
178 count -= overflow; 177 count -= overflow;
179 } 178 }
@@ -182,27 +181,21 @@ do_more:
182 goto error_return; 181 goto error_return;
183 182
184 bh = bitmap->s_block_bitmap[bitmap_nr]; 183 bh = bitmap->s_block_bitmap[bitmap_nr];
185 for (i=0; i < count; i++) 184 for (i = 0; i < count; i++) {
186 { 185 if (udf_set_bit(bit + i, bh->b_data)) {
187 if (udf_set_bit(bit + i, bh->b_data))
188 {
189 udf_debug("bit %ld already set\n", bit + i); 186 udf_debug("bit %ld already set\n", bit + i);
190 udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); 187 udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]);
191 } 188 } else {
192 else
193 {
194 if (inode) 189 if (inode)
195 DQUOT_FREE_BLOCK(inode, 1); 190 DQUOT_FREE_BLOCK(inode, 1);
196 if (UDF_SB_LVIDBH(sb)) 191 if (UDF_SB_LVIDBH(sb)) {
197 {
198 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = 192 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] =
199 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+1); 193 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + 1);
200 } 194 }
201 } 195 }
202 } 196 }
203 mark_buffer_dirty(bh); 197 mark_buffer_dirty(bh);
204 if (overflow) 198 if (overflow) {
205 {
206 block += count; 199 block += count;
207 count = overflow; 200 count = overflow;
208 goto do_more; 201 goto do_more;
@@ -215,10 +208,11 @@ error_return:
215 return; 208 return;
216} 209}
217 210
218static int udf_bitmap_prealloc_blocks(struct super_block * sb, 211static int udf_bitmap_prealloc_blocks(struct super_block *sb,
219 struct inode * inode, 212 struct inode *inode,
220 struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block, 213 struct udf_bitmap *bitmap,
221 uint32_t block_count) 214 uint16_t partition, uint32_t first_block,
215 uint32_t block_count)
222{ 216{
223 struct udf_sb_info *sbi = UDF_SB(sb); 217 struct udf_sb_info *sbi = UDF_SB(sb);
224 int alloc_count = 0; 218 int alloc_count = 0;
@@ -235,7 +229,8 @@ static int udf_bitmap_prealloc_blocks(struct super_block * sb,
235 229
236repeat: 230repeat:
237 nr_groups = (UDF_SB_PARTLEN(sb, partition) + 231 nr_groups = (UDF_SB_PARTLEN(sb, partition) +
238 (sizeof(struct spaceBitmapDesc) << 3) + (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8); 232 (sizeof(struct spaceBitmapDesc) << 3) +
233 (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8);
239 block = first_block + (sizeof(struct spaceBitmapDesc) << 3); 234 block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
240 block_group = block >> (sb->s_blocksize_bits + 3); 235 block_group = block >> (sb->s_blocksize_bits + 3);
241 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); 236 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
@@ -247,31 +242,28 @@ repeat:
247 242
248 bit = block % (sb->s_blocksize << 3); 243 bit = block % (sb->s_blocksize << 3);
249 244
250 while (bit < (sb->s_blocksize << 3) && block_count > 0) 245 while (bit < (sb->s_blocksize << 3) && block_count > 0) {
251 { 246 if (!udf_test_bit(bit, bh->b_data)) {
252 if (!udf_test_bit(bit, bh->b_data))
253 goto out; 247 goto out;
254 else if (DQUOT_PREALLOC_BLOCK(inode, 1)) 248 } else if (DQUOT_PREALLOC_BLOCK(inode, 1)) {
255 goto out; 249 goto out;
256 else if (!udf_clear_bit(bit, bh->b_data)) 250 } else if (!udf_clear_bit(bit, bh->b_data)) {
257 {
258 udf_debug("bit already cleared for block %d\n", bit); 251 udf_debug("bit already cleared for block %d\n", bit);
259 DQUOT_FREE_BLOCK(inode, 1); 252 DQUOT_FREE_BLOCK(inode, 1);
260 goto out; 253 goto out;
261 } 254 }
262 block_count --; 255 block_count--;
263 alloc_count ++; 256 alloc_count++;
264 bit ++; 257 bit++;
265 block ++; 258 block++;
266 } 259 }
267 mark_buffer_dirty(bh); 260 mark_buffer_dirty(bh);
268 if (block_count > 0) 261 if (block_count > 0)
269 goto repeat; 262 goto repeat;
270out: 263out:
271 if (UDF_SB_LVIDBH(sb)) 264 if (UDF_SB_LVIDBH(sb)) {
272 {
273 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 265 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
274 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); 266 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count);
275 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 267 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
276 } 268 }
277 sb->s_dirt = 1; 269 sb->s_dirt = 1;
@@ -279,12 +271,13 @@ out:
279 return alloc_count; 271 return alloc_count;
280} 272}
281 273
282static int udf_bitmap_new_block(struct super_block * sb, 274static int udf_bitmap_new_block(struct super_block *sb,
283 struct inode * inode, 275 struct inode *inode,
284 struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err) 276 struct udf_bitmap *bitmap, uint16_t partition,
277 uint32_t goal, int *err)
285{ 278{
286 struct udf_sb_info *sbi = UDF_SB(sb); 279 struct udf_sb_info *sbi = UDF_SB(sb);
287 int newbit, bit=0, block, block_group, group_start; 280 int newbit, bit = 0, block, block_group, group_start;
288 int end_goal, nr_groups, bitmap_nr, i; 281 int end_goal, nr_groups, bitmap_nr, i;
289 struct buffer_head *bh = NULL; 282 struct buffer_head *bh = NULL;
290 char *ptr; 283 char *ptr;
@@ -306,38 +299,35 @@ repeat:
306 if (bitmap_nr < 0) 299 if (bitmap_nr < 0)
307 goto error_return; 300 goto error_return;
308 bh = bitmap->s_block_bitmap[bitmap_nr]; 301 bh = bitmap->s_block_bitmap[bitmap_nr];
309 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); 302 ptr = memscan((char *)bh->b_data + group_start, 0xFF,
303 sb->s_blocksize - group_start);
310 304
311 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) 305 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
312 {
313 bit = block % (sb->s_blocksize << 3); 306 bit = block % (sb->s_blocksize << 3);
314
315 if (udf_test_bit(bit, bh->b_data)) 307 if (udf_test_bit(bit, bh->b_data))
316 {
317 goto got_block; 308 goto got_block;
318 } 309
319 end_goal = (bit + 63) & ~63; 310 end_goal = (bit + 63) & ~63;
320 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit); 311 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit);
321 if (bit < end_goal) 312 if (bit < end_goal)
322 goto got_block; 313 goto got_block;
314
323 ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); 315 ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3));
324 newbit = (ptr - ((char *)bh->b_data)) << 3; 316 newbit = (ptr - ((char *)bh->b_data)) << 3;
325 if (newbit < sb->s_blocksize << 3) 317 if (newbit < sb->s_blocksize << 3) {
326 {
327 bit = newbit; 318 bit = newbit;
328 goto search_back; 319 goto search_back;
329 } 320 }
321
330 newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); 322 newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit);
331 if (newbit < sb->s_blocksize << 3) 323 if (newbit < sb->s_blocksize << 3) {
332 {
333 bit = newbit; 324 bit = newbit;
334 goto got_block; 325 goto got_block;
335 } 326 }
336 } 327 }
337 328
338 for (i=0; i<(nr_groups*2); i++) 329 for (i = 0; i < (nr_groups * 2); i++) {
339 { 330 block_group++;
340 block_group ++;
341 if (block_group >= nr_groups) 331 if (block_group >= nr_groups)
342 block_group = 0; 332 block_group = 0;
343 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); 333 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
@@ -346,24 +336,22 @@ repeat:
346 if (bitmap_nr < 0) 336 if (bitmap_nr < 0)
347 goto error_return; 337 goto error_return;
348 bh = bitmap->s_block_bitmap[bitmap_nr]; 338 bh = bitmap->s_block_bitmap[bitmap_nr];
349 if (i < nr_groups) 339 if (i < nr_groups) {
350 { 340 ptr = memscan((char *)bh->b_data + group_start, 0xFF,
351 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); 341 sb->s_blocksize - group_start);
352 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) 342 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
353 {
354 bit = (ptr - ((char *)bh->b_data)) << 3; 343 bit = (ptr - ((char *)bh->b_data)) << 3;
355 break; 344 break;
356 } 345 }
357 } 346 } else {
358 else 347 bit = udf_find_next_one_bit((char *)bh->b_data,
359 { 348 sb->s_blocksize << 3,
360 bit = udf_find_next_one_bit((char *)bh->b_data, sb->s_blocksize << 3, group_start << 3); 349 group_start << 3);
361 if (bit < sb->s_blocksize << 3) 350 if (bit < sb->s_blocksize << 3)
362 break; 351 break;
363 } 352 }
364 } 353 }
365 if (i >= (nr_groups*2)) 354 if (i >= (nr_groups * 2)) {
366 {
367 mutex_unlock(&sbi->s_alloc_mutex); 355 mutex_unlock(&sbi->s_alloc_mutex);
368 return newblock; 356 return newblock;
369 } 357 }
@@ -371,22 +359,21 @@ repeat:
371 goto search_back; 359 goto search_back;
372 else 360 else
373 bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); 361 bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3);
374 if (bit >= sb->s_blocksize << 3) 362 if (bit >= sb->s_blocksize << 3) {
375 {
376 mutex_unlock(&sbi->s_alloc_mutex); 363 mutex_unlock(&sbi->s_alloc_mutex);
377 return 0; 364 return 0;
378 } 365 }
379 366
380search_back: 367search_back:
381 for (i=0; i<7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--); 368 for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--)
369 ; /* empty loop */
382 370
383got_block: 371got_block:
384 372
385 /* 373 /*
386 * Check quota for allocation of this block. 374 * Check quota for allocation of this block.
387 */ 375 */
388 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) 376 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) {
389 {
390 mutex_unlock(&sbi->s_alloc_mutex); 377 mutex_unlock(&sbi->s_alloc_mutex);
391 *err = -EDQUOT; 378 *err = -EDQUOT;
392 return 0; 379 return 0;
@@ -395,18 +382,16 @@ got_block:
395 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - 382 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
396 (sizeof(struct spaceBitmapDesc) << 3); 383 (sizeof(struct spaceBitmapDesc) << 3);
397 384
398 if (!udf_clear_bit(bit, bh->b_data)) 385 if (!udf_clear_bit(bit, bh->b_data)) {
399 {
400 udf_debug("bit already cleared for block %d\n", bit); 386 udf_debug("bit already cleared for block %d\n", bit);
401 goto repeat; 387 goto repeat;
402 } 388 }
403 389
404 mark_buffer_dirty(bh); 390 mark_buffer_dirty(bh);
405 391
406 if (UDF_SB_LVIDBH(sb)) 392 if (UDF_SB_LVIDBH(sb)) {
407 {
408 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 393 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
409 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); 394 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1);
410 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 395 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
411 } 396 }
412 sb->s_dirt = 1; 397 sb->s_dirt = 1;
@@ -420,10 +405,11 @@ error_return:
420 return 0; 405 return 0;
421} 406}
422 407
423static void udf_table_free_blocks(struct super_block * sb, 408static void udf_table_free_blocks(struct super_block *sb,
424 struct inode * inode, 409 struct inode *inode,
425 struct inode * table, 410 struct inode *table,
426 kernel_lb_addr bloc, uint32_t offset, uint32_t count) 411 kernel_lb_addr bloc, uint32_t offset,
412 uint32_t count)
427{ 413{
428 struct udf_sb_info *sbi = UDF_SB(sb); 414 struct udf_sb_info *sbi = UDF_SB(sb);
429 uint32_t start, end; 415 uint32_t start, end;
@@ -435,11 +421,10 @@ static void udf_table_free_blocks(struct super_block * sb,
435 421
436 mutex_lock(&sbi->s_alloc_mutex); 422 mutex_lock(&sbi->s_alloc_mutex);
437 if (bloc.logicalBlockNum < 0 || 423 if (bloc.logicalBlockNum < 0 ||
438 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) 424 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) {
439 {
440 udf_debug("%d < %d || %d + %d > %d\n", 425 udf_debug("%d < %d || %d + %d > %d\n",
441 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, 426 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
442 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); 427 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
443 goto error_return; 428 goto error_return;
444 } 429 }
445 430
@@ -447,10 +432,9 @@ static void udf_table_free_blocks(struct super_block * sb,
447 but.. oh well */ 432 but.. oh well */
448 if (inode) 433 if (inode)
449 DQUOT_FREE_BLOCK(inode, count); 434 DQUOT_FREE_BLOCK(inode, count);
450 if (UDF_SB_LVIDBH(sb)) 435 if (UDF_SB_LVIDBH(sb)) {
451 {
452 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = 436 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] =
453 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+count); 437 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + count);
454 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 438 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
455 } 439 }
456 440
@@ -462,74 +446,59 @@ static void udf_table_free_blocks(struct super_block * sb,
462 epos.block = oepos.block = UDF_I_LOCATION(table); 446 epos.block = oepos.block = UDF_I_LOCATION(table);
463 epos.bh = oepos.bh = NULL; 447 epos.bh = oepos.bh = NULL;
464 448
465 while (count && (etype = 449 while (count &&
466 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 450 (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
467 { 451 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) {
468 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == 452 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) {
469 start))
470 {
471 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
472 {
473 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 453 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
474 start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 454 start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
475 elen = (etype << 30) | (0x40000000 - sb->s_blocksize); 455 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
476 } 456 } else {
477 else 457 elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits));
478 {
479 elen = (etype << 30) |
480 (elen + (count << sb->s_blocksize_bits));
481 start += count; 458 start += count;
482 count = 0; 459 count = 0;
483 } 460 }
484 udf_write_aext(table, &oepos, eloc, elen, 1); 461 udf_write_aext(table, &oepos, eloc, elen, 1);
485 } 462 } else if (eloc.logicalBlockNum == (end + 1)) {
486 else if (eloc.logicalBlockNum == (end + 1)) 463 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) {
487 {
488 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
489 {
490 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 464 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
491 end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 465 end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
492 eloc.logicalBlockNum -= 466 eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
493 ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
494 elen = (etype << 30) | (0x40000000 - sb->s_blocksize); 467 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
495 } 468 } else {
496 else
497 {
498 eloc.logicalBlockNum = start; 469 eloc.logicalBlockNum = start;
499 elen = (etype << 30) | 470 elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits));
500 (elen + (count << sb->s_blocksize_bits));
501 end -= count; 471 end -= count;
502 count = 0; 472 count = 0;
503 } 473 }
504 udf_write_aext(table, &oepos, eloc, elen, 1); 474 udf_write_aext(table, &oepos, eloc, elen, 1);
505 } 475 }
506 476
507 if (epos.bh != oepos.bh) 477 if (epos.bh != oepos.bh) {
508 {
509 i = -1; 478 i = -1;
510 oepos.block = epos.block; 479 oepos.block = epos.block;
511 brelse(oepos.bh); 480 brelse(oepos.bh);
512 get_bh(epos.bh); 481 get_bh(epos.bh);
513 oepos.bh = epos.bh; 482 oepos.bh = epos.bh;
514 oepos.offset = 0; 483 oepos.offset = 0;
515 } 484 } else {
516 else
517 oepos.offset = epos.offset; 485 oepos.offset = epos.offset;
486 }
518 } 487 }
519 488
520 if (count) 489 if (count) {
521 { 490 /*
522 /* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate 491 * NOTE: we CANNOT use udf_add_aext here, as it can try to allocate
523 a new block, and since we hold the super block lock already 492 * a new block, and since we hold the super block lock already
524 very bad things would happen :) 493 * very bad things would happen :)
525 494 *
526 We copy the behavior of udf_add_aext, but instead of 495 * We copy the behavior of udf_add_aext, but instead of
527 trying to allocate a new block close to the existing one, 496 * trying to allocate a new block close to the existing one,
528 we just steal a block from the extent we are trying to add. 497 * we just steal a block from the extent we are trying to add.
529 498 *
530 It would be nice if the blocks were close together, but it 499 * It would be nice if the blocks were close together, but it
531 isn't required. 500 * isn't required.
532 */ 501 */
533 502
534 int adsize; 503 int adsize;
535 short_ad *sad = NULL; 504 short_ad *sad = NULL;
@@ -540,40 +509,35 @@ static void udf_table_free_blocks(struct super_block * sb,
540 elen = EXT_RECORDED_ALLOCATED | 509 elen = EXT_RECORDED_ALLOCATED |
541 (count << sb->s_blocksize_bits); 510 (count << sb->s_blocksize_bits);
542 511
543 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) 512 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) {
544 adsize = sizeof(short_ad); 513 adsize = sizeof(short_ad);
545 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) 514 } else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) {
546 adsize = sizeof(long_ad); 515 adsize = sizeof(long_ad);
547 else 516 } else {
548 {
549 brelse(oepos.bh); 517 brelse(oepos.bh);
550 brelse(epos.bh); 518 brelse(epos.bh);
551 goto error_return; 519 goto error_return;
552 } 520 }
553 521
554 if (epos.offset + (2 * adsize) > sb->s_blocksize) 522 if (epos.offset + (2 * adsize) > sb->s_blocksize) {
555 {
556 char *sptr, *dptr; 523 char *sptr, *dptr;
557 int loffset; 524 int loffset;
558 525
559 brelse(oepos.bh); 526 brelse(oepos.bh);
560 oepos = epos; 527 oepos = epos;
561 528
562 /* Steal a block from the extent being free'd */ 529 /* Steal a block from the extent being free'd */
563 epos.block.logicalBlockNum = eloc.logicalBlockNum; 530 epos.block.logicalBlockNum = eloc.logicalBlockNum;
564 eloc.logicalBlockNum ++; 531 eloc.logicalBlockNum++;
565 elen -= sb->s_blocksize; 532 elen -= sb->s_blocksize;
566 533
567 if (!(epos.bh = udf_tread(sb, 534 if (!(epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, epos.block, 0)))) {
568 udf_get_lb_pblock(sb, epos.block, 0))))
569 {
570 brelse(oepos.bh); 535 brelse(oepos.bh);
571 goto error_return; 536 goto error_return;
572 } 537 }
573 aed = (struct allocExtDesc *)(epos.bh->b_data); 538 aed = (struct allocExtDesc *)(epos.bh->b_data);
574 aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); 539 aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum);
575 if (epos.offset + adsize > sb->s_blocksize) 540 if (epos.offset + adsize > sb->s_blocksize) {
576 {
577 loffset = epos.offset; 541 loffset = epos.offset;
578 aed->lengthAllocDescs = cpu_to_le32(adsize); 542 aed->lengthAllocDescs = cpu_to_le32(adsize);
579 sptr = UDF_I_DATA(inode) + epos.offset - 543 sptr = UDF_I_DATA(inode) + epos.offset -
@@ -582,73 +546,59 @@ static void udf_table_free_blocks(struct super_block * sb,
582 dptr = epos.bh->b_data + sizeof(struct allocExtDesc); 546 dptr = epos.bh->b_data + sizeof(struct allocExtDesc);
583 memcpy(dptr, sptr, adsize); 547 memcpy(dptr, sptr, adsize);
584 epos.offset = sizeof(struct allocExtDesc) + adsize; 548 epos.offset = sizeof(struct allocExtDesc) + adsize;
585 } 549 } else {
586 else
587 {
588 loffset = epos.offset + adsize; 550 loffset = epos.offset + adsize;
589 aed->lengthAllocDescs = cpu_to_le32(0); 551 aed->lengthAllocDescs = cpu_to_le32(0);
590 sptr = oepos.bh->b_data + epos.offset; 552 sptr = oepos.bh->b_data + epos.offset;
591 epos.offset = sizeof(struct allocExtDesc); 553 epos.offset = sizeof(struct allocExtDesc);
592 554
593 if (oepos.bh) 555 if (oepos.bh) {
594 {
595 aed = (struct allocExtDesc *)oepos.bh->b_data; 556 aed = (struct allocExtDesc *)oepos.bh->b_data;
596 aed->lengthAllocDescs = 557 aed->lengthAllocDescs =
597 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 558 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
598 } 559 } else {
599 else
600 {
601 UDF_I_LENALLOC(table) += adsize; 560 UDF_I_LENALLOC(table) += adsize;
602 mark_inode_dirty(table); 561 mark_inode_dirty(table);
603 } 562 }
604 } 563 }
605 if (UDF_SB_UDFREV(sb) >= 0x0200) 564 if (UDF_SB_UDFREV(sb) >= 0x0200)
606 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, 565 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1,
607 epos.block.logicalBlockNum, sizeof(tag)); 566 epos.block.logicalBlockNum, sizeof(tag));
608 else 567 else
609 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, 568 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1,
610 epos.block.logicalBlockNum, sizeof(tag)); 569 epos.block.logicalBlockNum, sizeof(tag));
611 switch (UDF_I_ALLOCTYPE(table)) 570
612 { 571 switch (UDF_I_ALLOCTYPE(table)) {
613 case ICBTAG_FLAG_AD_SHORT: 572 case ICBTAG_FLAG_AD_SHORT:
614 {
615 sad = (short_ad *)sptr; 573 sad = (short_ad *)sptr;
616 sad->extLength = cpu_to_le32( 574 sad->extLength = cpu_to_le32(
617 EXT_NEXT_EXTENT_ALLOCDECS | 575 EXT_NEXT_EXTENT_ALLOCDECS |
618 sb->s_blocksize); 576 sb->s_blocksize);
619 sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); 577 sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum);
620 break; 578 break;
621 }
622 case ICBTAG_FLAG_AD_LONG: 579 case ICBTAG_FLAG_AD_LONG:
623 {
624 lad = (long_ad *)sptr; 580 lad = (long_ad *)sptr;
625 lad->extLength = cpu_to_le32( 581 lad->extLength = cpu_to_le32(
626 EXT_NEXT_EXTENT_ALLOCDECS | 582 EXT_NEXT_EXTENT_ALLOCDECS |
627 sb->s_blocksize); 583 sb->s_blocksize);
628 lad->extLocation = cpu_to_lelb(epos.block); 584 lad->extLocation = cpu_to_lelb(epos.block);
629 break; 585 break;
630 }
631 } 586 }
632 if (oepos.bh) 587 if (oepos.bh) {
633 {
634 udf_update_tag(oepos.bh->b_data, loffset); 588 udf_update_tag(oepos.bh->b_data, loffset);
635 mark_buffer_dirty(oepos.bh); 589 mark_buffer_dirty(oepos.bh);
636 } 590 } else {
637 else
638 mark_inode_dirty(table); 591 mark_inode_dirty(table);
592 }
639 } 593 }
640 594
641 if (elen) /* It's possible that stealing the block emptied the extent */ 595 if (elen) { /* It's possible that stealing the block emptied the extent */
642 {
643 udf_write_aext(table, &epos, eloc, elen, 1); 596 udf_write_aext(table, &epos, eloc, elen, 1);
644 597
645 if (!epos.bh) 598 if (!epos.bh) {
646 {
647 UDF_I_LENALLOC(table) += adsize; 599 UDF_I_LENALLOC(table) += adsize;
648 mark_inode_dirty(table); 600 mark_inode_dirty(table);
649 } 601 } else {
650 else
651 {
652 aed = (struct allocExtDesc *)epos.bh->b_data; 602 aed = (struct allocExtDesc *)epos.bh->b_data;
653 aed->lengthAllocDescs = 603 aed->lengthAllocDescs =
654 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 604 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
@@ -667,10 +617,10 @@ error_return:
667 return; 617 return;
668} 618}
669 619
670static int udf_table_prealloc_blocks(struct super_block * sb, 620static int udf_table_prealloc_blocks(struct super_block *sb,
671 struct inode * inode, 621 struct inode *inode,
672 struct inode *table, uint16_t partition, uint32_t first_block, 622 struct inode *table, uint16_t partition,
673 uint32_t block_count) 623 uint32_t first_block, uint32_t block_count)
674{ 624{
675 struct udf_sb_info *sbi = UDF_SB(sb); 625 struct udf_sb_info *sbi = UDF_SB(sb);
676 int alloc_count = 0; 626 int alloc_count = 0;
@@ -695,40 +645,36 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
695 epos.bh = NULL; 645 epos.bh = NULL;
696 eloc.logicalBlockNum = 0xFFFFFFFF; 646 eloc.logicalBlockNum = 0xFFFFFFFF;
697 647
698 while (first_block != eloc.logicalBlockNum && (etype = 648 while (first_block != eloc.logicalBlockNum &&
699 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 649 (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
700 {
701 udf_debug("eloc=%d, elen=%d, first_block=%d\n", 650 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
702 eloc.logicalBlockNum, elen, first_block); 651 eloc.logicalBlockNum, elen, first_block);
703 ; /* empty loop body */ 652 ; /* empty loop body */
704 } 653 }
705 654
706 if (first_block == eloc.logicalBlockNum) 655 if (first_block == eloc.logicalBlockNum) {
707 {
708 epos.offset -= adsize; 656 epos.offset -= adsize;
709 657
710 alloc_count = (elen >> sb->s_blocksize_bits); 658 alloc_count = (elen >> sb->s_blocksize_bits);
711 if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) 659 if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) {
712 alloc_count = 0; 660 alloc_count = 0;
713 else if (alloc_count > block_count) 661 } else if (alloc_count > block_count) {
714 {
715 alloc_count = block_count; 662 alloc_count = block_count;
716 eloc.logicalBlockNum += alloc_count; 663 eloc.logicalBlockNum += alloc_count;
717 elen -= (alloc_count << sb->s_blocksize_bits); 664 elen -= (alloc_count << sb->s_blocksize_bits);
718 udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); 665 udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1);
719 } 666 } else {
720 else
721 udf_delete_aext(table, epos, eloc, (etype << 30) | elen); 667 udf_delete_aext(table, epos, eloc, (etype << 30) | elen);
722 } 668 }
723 else 669 } else {
724 alloc_count = 0; 670 alloc_count = 0;
671 }
725 672
726 brelse(epos.bh); 673 brelse(epos.bh);
727 674
728 if (alloc_count && UDF_SB_LVIDBH(sb)) 675 if (alloc_count && UDF_SB_LVIDBH(sb)) {
729 {
730 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 676 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
731 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); 677 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count);
732 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 678 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
733 sb->s_dirt = 1; 679 sb->s_dirt = 1;
734 } 680 }
@@ -736,9 +682,10 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
736 return alloc_count; 682 return alloc_count;
737} 683}
738 684
739static int udf_table_new_block(struct super_block * sb, 685static int udf_table_new_block(struct super_block *sb,
740 struct inode * inode, 686 struct inode *inode,
741 struct inode *table, uint16_t partition, uint32_t goal, int *err) 687 struct inode *table, uint16_t partition,
688 uint32_t goal, int *err)
742{ 689{
743 struct udf_sb_info *sbi = UDF_SB(sb); 690 struct udf_sb_info *sbi = UDF_SB(sb);
744 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; 691 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
@@ -765,30 +712,26 @@ static int udf_table_new_block(struct super_block * sb,
765 we stop. Otherwise we keep going till we run out of extents. 712 we stop. Otherwise we keep going till we run out of extents.
766 We store the buffer_head, bloc, and extoffset of the current closest 713 We store the buffer_head, bloc, and extoffset of the current closest
767 match and use that when we are done. 714 match and use that when we are done.
768 */ 715 */
769 epos.offset = sizeof(struct unallocSpaceEntry); 716 epos.offset = sizeof(struct unallocSpaceEntry);
770 epos.block = UDF_I_LOCATION(table); 717 epos.block = UDF_I_LOCATION(table);
771 epos.bh = goal_epos.bh = NULL; 718 epos.bh = goal_epos.bh = NULL;
772 719
773 while (spread && (etype = 720 while (spread &&
774 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 721 (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
775 { 722 if (goal >= eloc.logicalBlockNum) {
776 if (goal >= eloc.logicalBlockNum)
777 {
778 if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) 723 if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits))
779 nspread = 0; 724 nspread = 0;
780 else 725 else
781 nspread = goal - eloc.logicalBlockNum - 726 nspread = goal - eloc.logicalBlockNum -
782 (elen >> sb->s_blocksize_bits); 727 (elen >> sb->s_blocksize_bits);
783 } 728 } else {
784 else
785 nspread = eloc.logicalBlockNum - goal; 729 nspread = eloc.logicalBlockNum - goal;
730 }
786 731
787 if (nspread < spread) 732 if (nspread < spread) {
788 {
789 spread = nspread; 733 spread = nspread;
790 if (goal_epos.bh != epos.bh) 734 if (goal_epos.bh != epos.bh) {
791 {
792 brelse(goal_epos.bh); 735 brelse(goal_epos.bh);
793 goal_epos.bh = epos.bh; 736 goal_epos.bh = epos.bh;
794 get_bh(goal_epos.bh); 737 get_bh(goal_epos.bh);
@@ -802,8 +745,7 @@ static int udf_table_new_block(struct super_block * sb,
802 745
803 brelse(epos.bh); 746 brelse(epos.bh);
804 747
805 if (spread == 0xFFFFFFFF) 748 if (spread == 0xFFFFFFFF) {
806 {
807 brelse(goal_epos.bh); 749 brelse(goal_epos.bh);
808 mutex_unlock(&sbi->s_alloc_mutex); 750 mutex_unlock(&sbi->s_alloc_mutex);
809 return 0; 751 return 0;
@@ -815,11 +757,10 @@ static int udf_table_new_block(struct super_block * sb,
815 /* This works, but very poorly.... */ 757 /* This works, but very poorly.... */
816 758
817 newblock = goal_eloc.logicalBlockNum; 759 newblock = goal_eloc.logicalBlockNum;
818 goal_eloc.logicalBlockNum ++; 760 goal_eloc.logicalBlockNum++;
819 goal_elen -= sb->s_blocksize; 761 goal_elen -= sb->s_blocksize;
820 762
821 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) 763 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) {
822 {
823 brelse(goal_epos.bh); 764 brelse(goal_epos.bh);
824 mutex_unlock(&sbi->s_alloc_mutex); 765 mutex_unlock(&sbi->s_alloc_mutex);
825 *err = -EDQUOT; 766 *err = -EDQUOT;
@@ -832,10 +773,9 @@ static int udf_table_new_block(struct super_block * sb,
832 udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); 773 udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
833 brelse(goal_epos.bh); 774 brelse(goal_epos.bh);
834 775
835 if (UDF_SB_LVIDBH(sb)) 776 if (UDF_SB_LVIDBH(sb)) {
836 {
837 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 777 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
838 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); 778 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1);
839 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 779 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
840 } 780 }
841 781
@@ -845,105 +785,84 @@ static int udf_table_new_block(struct super_block * sb,
845 return newblock; 785 return newblock;
846} 786}
847 787
848inline void udf_free_blocks(struct super_block * sb, 788inline void udf_free_blocks(struct super_block *sb,
849 struct inode * inode, 789 struct inode *inode,
850 kernel_lb_addr bloc, uint32_t offset, uint32_t count) 790 kernel_lb_addr bloc, uint32_t offset,
791 uint32_t count)
851{ 792{
852 uint16_t partition = bloc.partitionReferenceNum; 793 uint16_t partition = bloc.partitionReferenceNum;
853 794
854 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 795 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
855 {
856 return udf_bitmap_free_blocks(sb, inode, 796 return udf_bitmap_free_blocks(sb, inode,
857 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 797 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
858 bloc, offset, count); 798 bloc, offset, count);
859 } 799 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
860 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
861 {
862 return udf_table_free_blocks(sb, inode, 800 return udf_table_free_blocks(sb, inode,
863 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 801 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
864 bloc, offset, count); 802 bloc, offset, count);
865 } 803 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
866 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
867 {
868 return udf_bitmap_free_blocks(sb, inode, 804 return udf_bitmap_free_blocks(sb, inode,
869 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 805 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
870 bloc, offset, count); 806 bloc, offset, count);
871 } 807 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
872 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
873 {
874 return udf_table_free_blocks(sb, inode, 808 return udf_table_free_blocks(sb, inode,
875 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 809 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
876 bloc, offset, count); 810 bloc, offset, count);
877 } 811 } else {
878 else
879 return; 812 return;
813 }
880} 814}
881 815
882inline int udf_prealloc_blocks(struct super_block * sb, 816inline int udf_prealloc_blocks(struct super_block *sb,
883 struct inode * inode, 817 struct inode *inode,
884 uint16_t partition, uint32_t first_block, uint32_t block_count) 818 uint16_t partition, uint32_t first_block,
819 uint32_t block_count)
885{ 820{
886 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 821 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
887 {
888 return udf_bitmap_prealloc_blocks(sb, inode, 822 return udf_bitmap_prealloc_blocks(sb, inode,
889 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 823 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
890 partition, first_block, block_count); 824 partition, first_block, block_count);
891 } 825 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
892 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
893 {
894 return udf_table_prealloc_blocks(sb, inode, 826 return udf_table_prealloc_blocks(sb, inode,
895 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 827 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
896 partition, first_block, block_count); 828 partition, first_block, block_count);
897 } 829 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
898 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
899 {
900 return udf_bitmap_prealloc_blocks(sb, inode, 830 return udf_bitmap_prealloc_blocks(sb, inode,
901 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 831 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
902 partition, first_block, block_count); 832 partition, first_block, block_count);
903 } 833 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
904 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
905 {
906 return udf_table_prealloc_blocks(sb, inode, 834 return udf_table_prealloc_blocks(sb, inode,
907 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 835 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
908 partition, first_block, block_count); 836 partition, first_block, block_count);
909 } 837 } else {
910 else
911 return 0; 838 return 0;
839 }
912} 840}
913 841
914inline int udf_new_block(struct super_block * sb, 842inline int udf_new_block(struct super_block *sb,
915 struct inode * inode, 843 struct inode *inode,
916 uint16_t partition, uint32_t goal, int *err) 844 uint16_t partition, uint32_t goal, int *err)
917{ 845{
918 int ret; 846 int ret;
919 847
920 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 848 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
921 {
922 ret = udf_bitmap_new_block(sb, inode, 849 ret = udf_bitmap_new_block(sb, inode,
923 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 850 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
924 partition, goal, err); 851 partition, goal, err);
925 return ret; 852 return ret;
926 } 853 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
927 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
928 {
929 return udf_table_new_block(sb, inode, 854 return udf_table_new_block(sb, inode,
930 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 855 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
931 partition, goal, err); 856 partition, goal, err);
932 } 857 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
933 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
934 {
935 return udf_bitmap_new_block(sb, inode, 858 return udf_bitmap_new_block(sb, inode,
936 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 859 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
937 partition, goal, err); 860 partition, goal, err);
938 } 861 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
939 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
940 {
941 return udf_table_new_block(sb, inode, 862 return udf_table_new_block(sb, inode,
942 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 863 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
943 partition, goal, err); 864 partition, goal, err);
944 } 865 } else {
945 else
946 {
947 *err = -EIO; 866 *err = -EIO;
948 return 0; 867 return 0;
949 } 868 }
diff --git a/fs/udf/crc.c b/fs/udf/crc.c
index 1b82a4adc2f7..85aaee5fab26 100644
--- a/fs/udf/crc.c
+++ b/fs/udf/crc.c
@@ -79,8 +79,7 @@ static uint16_t crc_table[256] = {
79 * July 21, 1997 - Andrew E. Mileski 79 * July 21, 1997 - Andrew E. Mileski
80 * Adapted from OSTA-UDF(tm) 1.50 standard. 80 * Adapted from OSTA-UDF(tm) 1.50 standard.
81 */ 81 */
82uint16_t 82uint16_t udf_crc(uint8_t * data, uint32_t size, uint16_t crc)
83udf_crc(uint8_t *data, uint32_t size, uint16_t crc)
84{ 83{
85 while (size--) 84 while (size--)
86 crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); 85 crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8);
@@ -106,8 +105,8 @@ int main(void)
106{ 105{
107 unsigned short x; 106 unsigned short x;
108 107
109 x = udf_crc16(bytes, sizeof bytes); 108 x = udf_crc(bytes, sizeof bytes);
110 printf("udf_crc16: calculated = %4.4x, correct = %4.4x\n", x, 0x3299U); 109 printf("udf_crc: calculated = %4.4x, correct = %4.4x\n", x, 0x3299U);
111 110
112 return 0; 111 return 0;
113} 112}
@@ -138,7 +137,7 @@ int main(int argc, char **argv)
138 137
139 /* Get the polynomial */ 138 /* Get the polynomial */
140 sscanf(argv[1], "%lo", &poly); 139 sscanf(argv[1], "%lo", &poly);
141 if (poly & 0xffff0000U){ 140 if (poly & 0xffff0000U) {
142 fprintf(stderr, "polynomial is too large\en"); 141 fprintf(stderr, "polynomial is too large\en");
143 exit(1); 142 exit(1);
144 } 143 }
@@ -147,22 +146,22 @@ int main(int argc, char **argv)
147 146
148 /* Create a table */ 147 /* Create a table */
149 printf("static unsigned short crc_table[256] = {\n"); 148 printf("static unsigned short crc_table[256] = {\n");
150 for (n = 0; n < 256; n++){ 149 for (n = 0; n < 256; n++) {
151 if (n % 8 == 0) 150 if (n % 8 == 0)
152 printf("\t"); 151 printf("\t");
153 crc = n << 8; 152 crc = n << 8;
154 for (i = 0; i < 8; i++){ 153 for (i = 0; i < 8; i++) {
155 if(crc & 0x8000U) 154 if (crc & 0x8000U)
156 crc = (crc << 1) ^ poly; 155 crc = (crc << 1) ^ poly;
157 else 156 else
158 crc <<= 1; 157 crc <<= 1;
159 crc &= 0xFFFFU; 158 crc &= 0xFFFFU;
160 } 159 }
161 if (n == 255) 160 if (n == 255)
162 printf("0x%04xU ", crc); 161 printf("0x%04xU ", crc);
163 else 162 else
164 printf("0x%04xU, ", crc); 163 printf("0x%04xU, ", crc);
165 if(n % 8 == 7) 164 if (n % 8 == 7)
166 printf("\n"); 165 printf("\n");
167 } 166 }
168 printf("};\n"); 167 printf("};\n");
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index e45f86b5e7b0..9e3b9f97ddbc 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -82,14 +82,12 @@ int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
82 82
83 lock_kernel(); 83 lock_kernel();
84 84
85 if ( filp->f_pos == 0 ) 85 if (filp->f_pos == 0) {
86 { 86 if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) {
87 if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0)
88 {
89 unlock_kernel(); 87 unlock_kernel();
90 return 0; 88 return 0;
91 } 89 }
92 filp->f_pos ++; 90 filp->f_pos++;
93 } 91 }
94 92
95 result = do_udf_readdir(dir, filp, filldir, dirent); 93 result = do_udf_readdir(dir, filp, filldir, dirent);
@@ -97,11 +95,12 @@ int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
97 return result; 95 return result;
98} 96}
99 97
100static int 98static int
101do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *dirent) 99do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
100 void *dirent)
102{ 101{
103 struct udf_fileident_bh fibh; 102 struct udf_fileident_bh fibh;
104 struct fileIdentDesc *fi=NULL; 103 struct fileIdentDesc *fi = NULL;
105 struct fileIdentDesc cfi; 104 struct fileIdentDesc cfi;
106 int block, iblock; 105 int block, iblock;
107 loff_t nf_pos = filp->f_pos - 1; 106 loff_t nf_pos = filp->f_pos - 1;
@@ -117,7 +116,7 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
117 sector_t offset; 116 sector_t offset;
118 int i, num; 117 int i, num;
119 unsigned int dt_type; 118 unsigned int dt_type;
120 struct extent_position epos = { NULL, 0, {0, 0}}; 119 struct extent_position epos = { NULL, 0, {0, 0} };
121 120
122 if (nf_pos >= size) 121 if (nf_pos >= size)
123 return 0; 122 return 0;
@@ -126,64 +125,54 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
126 nf_pos = (udf_ext0_offset(dir) >> 2); 125 nf_pos = (udf_ext0_offset(dir) >> 2);
127 126
128 fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 127 fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
129 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 128 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
130 fibh.sbh = fibh.ebh = NULL; 129 fibh.sbh = fibh.ebh = NULL;
131 else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), 130 } else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
132 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 131 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
133 {
134 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 132 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
135 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 133 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
136 {
137 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 134 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
138 epos.offset -= sizeof(short_ad); 135 epos.offset -= sizeof(short_ad);
139 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 136 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
140 epos.offset -= sizeof(long_ad); 137 epos.offset -= sizeof(long_ad);
141 } 138 } else {
142 else
143 offset = 0; 139 offset = 0;
140 }
144 141
145 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) 142 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
146 {
147 brelse(epos.bh); 143 brelse(epos.bh);
148 return -EIO; 144 return -EIO;
149 } 145 }
150 146
151 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) 147 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
152 {
153 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 148 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
154 if (i+offset > (elen >> dir->i_sb->s_blocksize_bits)) 149 if (i + offset > (elen >> dir->i_sb->s_blocksize_bits))
155 i = (elen >> dir->i_sb->s_blocksize_bits)-offset; 150 i = (elen >> dir->i_sb->s_blocksize_bits) - offset;
156 for (num=0; i>0; i--) 151 for (num = 0; i > 0; i--) {
157 { 152 block = udf_get_lb_pblock(dir->i_sb, eloc, offset + i);
158 block = udf_get_lb_pblock(dir->i_sb, eloc, offset+i);
159 tmp = udf_tgetblk(dir->i_sb, block); 153 tmp = udf_tgetblk(dir->i_sb, block);
160 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 154 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
161 bha[num++] = tmp; 155 bha[num++] = tmp;
162 else 156 else
163 brelse(tmp); 157 brelse(tmp);
164 } 158 }
165 if (num) 159 if (num) {
166 {
167 ll_rw_block(READA, num, bha); 160 ll_rw_block(READA, num, bha);
168 for (i=0; i<num; i++) 161 for (i = 0; i < num; i++)
169 brelse(bha[i]); 162 brelse(bha[i]);
170 } 163 }
171 } 164 }
172 } 165 } else {
173 else
174 {
175 brelse(epos.bh); 166 brelse(epos.bh);
176 return -ENOENT; 167 return -ENOENT;
177 } 168 }
178 169
179 while ( nf_pos < size ) 170 while (nf_pos < size) {
180 {
181 filp->f_pos = nf_pos + 1; 171 filp->f_pos = nf_pos + 1;
182 172
183 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset); 173 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc,
184 174 &elen, &offset);
185 if (!fi) 175 if (!fi) {
186 {
187 if (fibh.sbh != fibh.ebh) 176 if (fibh.sbh != fibh.ebh)
188 brelse(fibh.ebh); 177 brelse(fibh.ebh);
189 brelse(fibh.sbh); 178 brelse(fibh.sbh);
@@ -194,45 +183,40 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
194 liu = le16_to_cpu(cfi.lengthOfImpUse); 183 liu = le16_to_cpu(cfi.lengthOfImpUse);
195 lfi = cfi.lengthFileIdent; 184 lfi = cfi.lengthFileIdent;
196 185
197 if (fibh.sbh == fibh.ebh) 186 if (fibh.sbh == fibh.ebh) {
198 nameptr = fi->fileIdent + liu; 187 nameptr = fi->fileIdent + liu;
199 else 188 } else {
200 {
201 int poffset; /* Unpaded ending offset */ 189 int poffset; /* Unpaded ending offset */
202 190
203 poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi; 191 poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi;
204 192
205 if (poffset >= lfi) 193 if (poffset >= lfi) {
206 nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); 194 nameptr = (char *)(fibh.ebh->b_data + poffset - lfi);
207 else 195 } else {
208 {
209 nameptr = fname; 196 nameptr = fname;
210 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 197 memcpy(nameptr, fi->fileIdent + liu,
211 memcpy(nameptr + lfi - poffset, fibh.ebh->b_data, poffset); 198 lfi - poffset);
199 memcpy(nameptr + lfi - poffset,
200 fibh.ebh->b_data, poffset);
212 } 201 }
213 } 202 }
214 203
215 if ( (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 204 if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
216 { 205 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
217 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE) )
218 continue; 206 continue;
219 } 207 }
220 208
221 if ( (cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0 ) 209 if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
222 { 210 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
223 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE) )
224 continue; 211 continue;
225 } 212 }
226 213
227 if ( cfi.fileCharacteristics & FID_FILE_CHAR_PARENT ) 214 if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) {
228 {
229 iblock = parent_ino(filp->f_path.dentry); 215 iblock = parent_ino(filp->f_path.dentry);
230 flen = 2; 216 flen = 2;
231 memcpy(fname, "..", flen); 217 memcpy(fname, "..", flen);
232 dt_type = DT_DIR; 218 dt_type = DT_DIR;
233 } 219 } else {
234 else
235 {
236 kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation); 220 kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation);
237 221
238 iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0); 222 iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0);
@@ -240,10 +224,8 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
240 dt_type = DT_UNKNOWN; 224 dt_type = DT_UNKNOWN;
241 } 225 }
242 226
243 if (flen) 227 if (flen) {
244 { 228 if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0) {
245 if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0)
246 {
247 if (fibh.sbh != fibh.ebh) 229 if (fibh.sbh != fibh.ebh)
248 brelse(fibh.ebh); 230 brelse(fibh.ebh);
249 brelse(fibh.sbh); 231 brelse(fibh.sbh);
diff --git a/fs/udf/directory.c b/fs/udf/directory.c
index 198caa33027a..ff8c08fd7bf5 100644
--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -19,10 +19,10 @@
19#include <linux/buffer_head.h> 19#include <linux/buffer_head.h>
20 20
21#if 0 21#if 0
22static uint8_t * 22static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
23udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size, 23 uint8_t ad_size, kernel_lb_addr fe_loc,
24 kernel_lb_addr fe_loc, int *pos, int *offset, 24 int *pos, int *offset, struct buffer_head **bh,
25 struct buffer_head **bh, int *error) 25 int *error)
26{ 26{
27 int loffset = *offset; 27 int loffset = *offset;
28 int block; 28 int block;
@@ -34,24 +34,20 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
34 ad = (uint8_t *)(*bh)->b_data + *offset; 34 ad = (uint8_t *)(*bh)->b_data + *offset;
35 *offset += ad_size; 35 *offset += ad_size;
36 36
37 if (!ad) 37 if (!ad) {
38 {
39 brelse(*bh); 38 brelse(*bh);
40 *error = 1; 39 *error = 1;
41 return NULL; 40 return NULL;
42 } 41 }
43 42
44 if (*offset == dir->i_sb->s_blocksize) 43 if (*offset == dir->i_sb->s_blocksize) {
45 {
46 brelse(*bh); 44 brelse(*bh);
47 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 45 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
48 if (!block) 46 if (!block)
49 return NULL; 47 return NULL;
50 if (!(*bh = udf_tread(dir->i_sb, block))) 48 if (!(*bh = udf_tread(dir->i_sb, block)))
51 return NULL; 49 return NULL;
52 } 50 } else if (*offset > dir->i_sb->s_blocksize) {
53 else if (*offset > dir->i_sb->s_blocksize)
54 {
55 ad = tmpad; 51 ad = tmpad;
56 52
57 remainder = dir->i_sb->s_blocksize - loffset; 53 remainder = dir->i_sb->s_blocksize - loffset;
@@ -67,53 +63,51 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
67 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); 63 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder);
68 *offset = ad_size - remainder; 64 *offset = ad_size - remainder;
69 } 65 }
66
70 return ad; 67 return ad;
71} 68}
72#endif 69#endif
73 70
74struct fileIdentDesc * 71struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
75udf_fileident_read(struct inode *dir, loff_t *nf_pos, 72 struct udf_fileident_bh *fibh,
76 struct udf_fileident_bh *fibh, 73 struct fileIdentDesc *cfi,
77 struct fileIdentDesc *cfi, 74 struct extent_position *epos,
78 struct extent_position *epos, 75 kernel_lb_addr * eloc, uint32_t * elen,
79 kernel_lb_addr *eloc, uint32_t *elen, 76 sector_t * offset)
80 sector_t *offset)
81{ 77{
82 struct fileIdentDesc *fi; 78 struct fileIdentDesc *fi;
83 int i, num, block; 79 int i, num, block;
84 struct buffer_head * tmp, * bha[16]; 80 struct buffer_head *tmp, *bha[16];
85 81
86 fibh->soffset = fibh->eoffset; 82 fibh->soffset = fibh->eoffset;
87 83
88 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 84 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
89 {
90 fi = udf_get_fileident(UDF_I_DATA(dir) - 85 fi = udf_get_fileident(UDF_I_DATA(dir) -
91 (UDF_I_EFE(dir) ? 86 (UDF_I_EFE(dir) ?
92 sizeof(struct extendedFileEntry) : 87 sizeof(struct extendedFileEntry) :
93 sizeof(struct fileEntry)), 88 sizeof(struct fileEntry)),
94 dir->i_sb->s_blocksize, &(fibh->eoffset)); 89 dir->i_sb->s_blocksize, &(fibh->eoffset));
95
96 if (!fi) 90 if (!fi)
97 return NULL; 91 return NULL;
98 92
99 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 93 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
100 94
101 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 95 memcpy((uint8_t *)cfi, (uint8_t *)fi,
96 sizeof(struct fileIdentDesc));
102 97
103 return fi; 98 return fi;
104 } 99 }
105 100
106 if (fibh->eoffset == dir->i_sb->s_blocksize) 101 if (fibh->eoffset == dir->i_sb->s_blocksize) {
107 {
108 int lextoffset = epos->offset; 102 int lextoffset = epos->offset;
109 103
110 if (udf_next_aext(dir, epos, eloc, elen, 1) != 104 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
111 (EXT_RECORDED_ALLOCATED >> 30)) 105 (EXT_RECORDED_ALLOCATED >> 30))
112 return NULL; 106 return NULL;
113 107
114 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 108 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
115 109
116 (*offset) ++; 110 (*offset)++;
117 111
118 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 112 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
119 *offset = 0; 113 *offset = 0;
@@ -125,57 +119,50 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
125 return NULL; 119 return NULL;
126 fibh->soffset = fibh->eoffset = 0; 120 fibh->soffset = fibh->eoffset = 0;
127 121
128 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) 122 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
129 {
130 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 123 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
131 if (i+*offset > (*elen >> dir->i_sb->s_blocksize_bits)) 124 if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits))
132 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; 125 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset;
133 for (num=0; i>0; i--) 126 for (num = 0; i > 0; i--) {
134 { 127 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i);
135 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset+i);
136 tmp = udf_tgetblk(dir->i_sb, block); 128 tmp = udf_tgetblk(dir->i_sb, block);
137 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 129 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
138 bha[num++] = tmp; 130 bha[num++] = tmp;
139 else 131 else
140 brelse(tmp); 132 brelse(tmp);
141 } 133 }
142 if (num) 134 if (num) {
143 {
144 ll_rw_block(READA, num, bha); 135 ll_rw_block(READA, num, bha);
145 for (i=0; i<num; i++) 136 for (i = 0; i < num; i++)
146 brelse(bha[i]); 137 brelse(bha[i]);
147 } 138 }
148 } 139 }
149 } 140 } else if (fibh->sbh != fibh->ebh) {
150 else if (fibh->sbh != fibh->ebh)
151 {
152 brelse(fibh->sbh); 141 brelse(fibh->sbh);
153 fibh->sbh = fibh->ebh; 142 fibh->sbh = fibh->ebh;
154 } 143 }
155 144
156 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize, 145 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
157 &(fibh->eoffset)); 146 &(fibh->eoffset));
158 147
159 if (!fi) 148 if (!fi)
160 return NULL; 149 return NULL;
161 150
162 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 151 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
163 152
164 if (fibh->eoffset <= dir->i_sb->s_blocksize) 153 if (fibh->eoffset <= dir->i_sb->s_blocksize) {
165 { 154 memcpy((uint8_t *)cfi, (uint8_t *)fi,
166 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 155 sizeof(struct fileIdentDesc));
167 } 156 } else if (fibh->eoffset > dir->i_sb->s_blocksize) {
168 else if (fibh->eoffset > dir->i_sb->s_blocksize)
169 {
170 int lextoffset = epos->offset; 157 int lextoffset = epos->offset;
171 158
172 if (udf_next_aext(dir, epos, eloc, elen, 1) != 159 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
173 (EXT_RECORDED_ALLOCATED >> 30)) 160 (EXT_RECORDED_ALLOCATED >> 30))
174 return NULL; 161 return NULL;
175 162
176 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 163 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
177 164
178 (*offset) ++; 165 (*offset)++;
179 166
180 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 167 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
181 *offset = 0; 168 *offset = 0;
@@ -188,62 +175,59 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
188 if (!(fibh->ebh = udf_tread(dir->i_sb, block))) 175 if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
189 return NULL; 176 return NULL;
190 177
191 if (sizeof(struct fileIdentDesc) > - fibh->soffset) 178 if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
192 {
193 int fi_len; 179 int fi_len;
194 180
195 memcpy((uint8_t *)cfi, (uint8_t *)fi, - fibh->soffset); 181 memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
196 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, 182 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data,
197 sizeof(struct fileIdentDesc) + fibh->soffset); 183 sizeof(struct fileIdentDesc) + fibh->soffset);
198 184
199 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + 185 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent +
200 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; 186 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
201 187
202 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); 188 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
203 fibh->eoffset = fibh->soffset + fi_len; 189 fibh->eoffset = fibh->soffset + fi_len;
204 } 190 } else {
205 else 191 memcpy((uint8_t *)cfi, (uint8_t *)fi,
206 { 192 sizeof(struct fileIdentDesc));
207 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
208 } 193 }
209 } 194 }
210 return fi; 195 return fi;
211} 196}
212 197
213struct fileIdentDesc * 198struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
214udf_get_fileident(void * buffer, int bufsize, int * offset)
215{ 199{
216 struct fileIdentDesc *fi; 200 struct fileIdentDesc *fi;
217 int lengthThisIdent; 201 int lengthThisIdent;
218 uint8_t * ptr; 202 uint8_t *ptr;
219 int padlen; 203 int padlen;
220 204
221 if ( (!buffer) || (!offset) ) { 205 if ((!buffer) || (!offset)) {
222 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, offset); 206 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer,
207 offset);
223 return NULL; 208 return NULL;
224 } 209 }
225 210
226 ptr = buffer; 211 ptr = buffer;
227 212
228 if ( (*offset > 0) && (*offset < bufsize) ) { 213 if ((*offset > 0) && (*offset < bufsize)) {
229 ptr += *offset; 214 ptr += *offset;
230 } 215 }
231 fi=(struct fileIdentDesc *)ptr; 216 fi = (struct fileIdentDesc *)ptr;
232 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) 217 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
233 {
234 udf_debug("0x%x != TAG_IDENT_FID\n", 218 udf_debug("0x%x != TAG_IDENT_FID\n",
235 le16_to_cpu(fi->descTag.tagIdent)); 219 le16_to_cpu(fi->descTag.tagIdent));
236 udf_debug("offset: %u sizeof: %lu bufsize: %u\n", 220 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
237 *offset, (unsigned long)sizeof(struct fileIdentDesc), bufsize); 221 *offset, (unsigned long)sizeof(struct fileIdentDesc),
222 bufsize);
238 return NULL; 223 return NULL;
239 } 224 }
240 if ( (*offset + sizeof(struct fileIdentDesc)) > bufsize ) 225 if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) {
241 {
242 lengthThisIdent = sizeof(struct fileIdentDesc); 226 lengthThisIdent = sizeof(struct fileIdentDesc);
243 } 227 } else {
244 else
245 lengthThisIdent = sizeof(struct fileIdentDesc) + 228 lengthThisIdent = sizeof(struct fileIdentDesc) +
246 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); 229 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
230 }
247 231
248 /* we need to figure padding, too! */ 232 /* we need to figure padding, too! */
249 padlen = lengthThisIdent % UDF_NAME_PAD; 233 padlen = lengthThisIdent % UDF_NAME_PAD;
@@ -255,32 +239,28 @@ udf_get_fileident(void * buffer, int bufsize, int * offset)
255} 239}
256 240
257#if 0 241#if 0
258static extent_ad * 242static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
259udf_get_fileextent(void * buffer, int bufsize, int * offset)
260{ 243{
261 extent_ad * ext; 244 extent_ad *ext;
262 struct fileEntry *fe; 245 struct fileEntry *fe;
263 uint8_t * ptr; 246 uint8_t *ptr;
264 247
265 if ( (!buffer) || (!offset) ) 248 if ((!buffer) || (!offset)) {
266 {
267 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); 249 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
268 return NULL; 250 return NULL;
269 } 251 }
270 252
271 fe = (struct fileEntry *)buffer; 253 fe = (struct fileEntry *)buffer;
272 254
273 if ( le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE ) 255 if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) {
274 {
275 udf_debug("0x%x != TAG_IDENT_FE\n", 256 udf_debug("0x%x != TAG_IDENT_FE\n",
276 le16_to_cpu(fe->descTag.tagIdent)); 257 le16_to_cpu(fe->descTag.tagIdent));
277 return NULL; 258 return NULL;
278 } 259 }
279 260
280 ptr=(uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); 261 ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr);
281 262
282 if ( (*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)) ) 263 if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) {
283 {
284 ptr += *offset; 264 ptr += *offset;
285 } 265 }
286 266
@@ -291,18 +271,17 @@ udf_get_fileextent(void * buffer, int bufsize, int * offset)
291} 271}
292#endif 272#endif
293 273
294short_ad * 274short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
295udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc) 275 int inc)
296{ 276{
297 short_ad *sa; 277 short_ad *sa;
298 278
299 if ( (!ptr) || (!offset) ) 279 if ((!ptr) || (!offset)) {
300 {
301 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); 280 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
302 return NULL; 281 return NULL;
303 } 282 }
304 283
305 if ( (*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset) ) 284 if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
306 return NULL; 285 return NULL;
307 else if ((sa = (short_ad *)ptr)->extLength == 0) 286 else if ((sa = (short_ad *)ptr)->extLength == 0)
308 return NULL; 287 return NULL;
@@ -312,18 +291,16 @@ udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc)
312 return sa; 291 return sa;
313} 292}
314 293
315long_ad * 294long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
316udf_get_filelongad(uint8_t *ptr, int maxoffset, int * offset, int inc)
317{ 295{
318 long_ad *la; 296 long_ad *la;
319 297
320 if ( (!ptr) || (!offset) ) 298 if ((!ptr) || (!offset)) {
321 {
322 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); 299 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
323 return NULL; 300 return NULL;
324 } 301 }
325 302
326 if ( (*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset) ) 303 if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
327 return NULL; 304 return NULL;
328 else if ((la = (long_ad *)ptr)->extLength == 0) 305 else if ((la = (long_ad *)ptr)->extLength == 0)
329 return NULL; 306 return NULL;
diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index f81f2ebbf508..56387711589b 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -38,8 +38,7 @@
38#define _ECMA_167_H 1 38#define _ECMA_167_H 1
39 39
40/* Character set specification (ECMA 167r3 1/7.2.1) */ 40/* Character set specification (ECMA 167r3 1/7.2.1) */
41typedef struct 41typedef struct {
42{
43 uint8_t charSetType; 42 uint8_t charSetType;
44 uint8_t charSetInfo[63]; 43 uint8_t charSetInfo[63];
45} __attribute__ ((packed)) charspec; 44} __attribute__ ((packed)) charspec;
@@ -58,8 +57,7 @@ typedef struct
58typedef uint8_t dstring; 57typedef uint8_t dstring;
59 58
60/* Timestamp (ECMA 167r3 1/7.3) */ 59/* Timestamp (ECMA 167r3 1/7.3) */
61typedef struct 60typedef struct {
62{
63 __le16 typeAndTimezone; 61 __le16 typeAndTimezone;
64 __le16 year; 62 __le16 year;
65 uint8_t month; 63 uint8_t month;
@@ -72,8 +70,7 @@ typedef struct
72 uint8_t microseconds; 70 uint8_t microseconds;
73} __attribute__ ((packed)) timestamp; 71} __attribute__ ((packed)) timestamp;
74 72
75typedef struct 73typedef struct {
76{
77 uint16_t typeAndTimezone; 74 uint16_t typeAndTimezone;
78 int16_t year; 75 int16_t year;
79 uint8_t month; 76 uint8_t month;
@@ -94,8 +91,7 @@ typedef struct
94#define TIMESTAMP_TIMEZONE_MASK 0x0FFF 91#define TIMESTAMP_TIMEZONE_MASK 0x0FFF
95 92
96/* Entity identifier (ECMA 167r3 1/7.4) */ 93/* Entity identifier (ECMA 167r3 1/7.4) */
97typedef struct 94typedef struct {
98{
99 uint8_t flags; 95 uint8_t flags;
100 uint8_t ident[23]; 96 uint8_t ident[23];
101 uint8_t identSuffix[8]; 97 uint8_t identSuffix[8];
@@ -107,8 +103,7 @@ typedef struct
107 103
108/* Volume Structure Descriptor (ECMA 167r3 2/9.1) */ 104/* Volume Structure Descriptor (ECMA 167r3 2/9.1) */
109#define VSD_STD_ID_LEN 5 105#define VSD_STD_ID_LEN 5
110struct volStructDesc 106struct volStructDesc {
111{
112 uint8_t structType; 107 uint8_t structType;
113 uint8_t stdIdent[VSD_STD_ID_LEN]; 108 uint8_t stdIdent[VSD_STD_ID_LEN];
114 uint8_t structVersion; 109 uint8_t structVersion;
@@ -127,8 +122,7 @@ struct volStructDesc
127#define VSD_STD_ID_TEA01 "TEA01" /* (2/9.3) */ 122#define VSD_STD_ID_TEA01 "TEA01" /* (2/9.3) */
128 123
129/* Beginning Extended Area Descriptor (ECMA 167r3 2/9.2) */ 124/* Beginning Extended Area Descriptor (ECMA 167r3 2/9.2) */
130struct beginningExtendedAreaDesc 125struct beginningExtendedAreaDesc {
131{
132 uint8_t structType; 126 uint8_t structType;
133 uint8_t stdIdent[VSD_STD_ID_LEN]; 127 uint8_t stdIdent[VSD_STD_ID_LEN];
134 uint8_t structVersion; 128 uint8_t structVersion;
@@ -136,8 +130,7 @@ struct beginningExtendedAreaDesc
136} __attribute__ ((packed)); 130} __attribute__ ((packed));
137 131
138/* Terminating Extended Area Descriptor (ECMA 167r3 2/9.3) */ 132/* Terminating Extended Area Descriptor (ECMA 167r3 2/9.3) */
139struct terminatingExtendedAreaDesc 133struct terminatingExtendedAreaDesc {
140{
141 uint8_t structType; 134 uint8_t structType;
142 uint8_t stdIdent[VSD_STD_ID_LEN]; 135 uint8_t stdIdent[VSD_STD_ID_LEN];
143 uint8_t structVersion; 136 uint8_t structVersion;
@@ -145,8 +138,7 @@ struct terminatingExtendedAreaDesc
145} __attribute__ ((packed)); 138} __attribute__ ((packed));
146 139
147/* Boot Descriptor (ECMA 167r3 2/9.4) */ 140/* Boot Descriptor (ECMA 167r3 2/9.4) */
148struct bootDesc 141struct bootDesc {
149{
150 uint8_t structType; 142 uint8_t structType;
151 uint8_t stdIdent[VSD_STD_ID_LEN]; 143 uint8_t stdIdent[VSD_STD_ID_LEN];
152 uint8_t structVersion; 144 uint8_t structVersion;
@@ -167,21 +159,18 @@ struct bootDesc
167#define BOOT_FLAGS_ERASE 0x01 159#define BOOT_FLAGS_ERASE 0x01
168 160
169/* Extent Descriptor (ECMA 167r3 3/7.1) */ 161/* Extent Descriptor (ECMA 167r3 3/7.1) */
170typedef struct 162typedef struct {
171{
172 __le32 extLength; 163 __le32 extLength;
173 __le32 extLocation; 164 __le32 extLocation;
174} __attribute__ ((packed)) extent_ad; 165} __attribute__ ((packed)) extent_ad;
175 166
176typedef struct 167typedef struct {
177{
178 uint32_t extLength; 168 uint32_t extLength;
179 uint32_t extLocation; 169 uint32_t extLocation;
180} kernel_extent_ad; 170} kernel_extent_ad;
181 171
182/* Descriptor Tag (ECMA 167r3 3/7.2) */ 172/* Descriptor Tag (ECMA 167r3 3/7.2) */
183typedef struct 173typedef struct {
184{
185 __le16 tagIdent; 174 __le16 tagIdent;
186 __le16 descVersion; 175 __le16 descVersion;
187 uint8_t tagChecksum; 176 uint8_t tagChecksum;
@@ -204,18 +193,16 @@ typedef struct
204#define TAG_IDENT_LVID 0x0009 193#define TAG_IDENT_LVID 0x0009
205 194
206/* NSR Descriptor (ECMA 167r3 3/9.1) */ 195/* NSR Descriptor (ECMA 167r3 3/9.1) */
207struct NSRDesc 196struct NSRDesc {
208{
209 uint8_t structType; 197 uint8_t structType;
210 uint8_t stdIdent[VSD_STD_ID_LEN]; 198 uint8_t stdIdent[VSD_STD_ID_LEN];
211 uint8_t structVersion; 199 uint8_t structVersion;
212 uint8_t reserved; 200 uint8_t reserved;
213 uint8_t structData[2040]; 201 uint8_t structData[2040];
214} __attribute__ ((packed)); 202} __attribute__ ((packed));
215 203
216/* Primary Volume Descriptor (ECMA 167r3 3/10.1) */ 204/* Primary Volume Descriptor (ECMA 167r3 3/10.1) */
217struct primaryVolDesc 205struct primaryVolDesc {
218{
219 tag descTag; 206 tag descTag;
220 __le32 volDescSeqNum; 207 __le32 volDescSeqNum;
221 __le32 primaryVolDescNum; 208 __le32 primaryVolDescNum;
@@ -244,8 +231,7 @@ struct primaryVolDesc
244#define PVD_FLAGS_VSID_COMMON 0x0001 231#define PVD_FLAGS_VSID_COMMON 0x0001
245 232
246/* Anchor Volume Descriptor Pointer (ECMA 167r3 3/10.2) */ 233/* Anchor Volume Descriptor Pointer (ECMA 167r3 3/10.2) */
247struct anchorVolDescPtr 234struct anchorVolDescPtr {
248{
249 tag descTag; 235 tag descTag;
250 extent_ad mainVolDescSeqExt; 236 extent_ad mainVolDescSeqExt;
251 extent_ad reserveVolDescSeqExt; 237 extent_ad reserveVolDescSeqExt;
@@ -253,8 +239,7 @@ struct anchorVolDescPtr
253} __attribute__ ((packed)); 239} __attribute__ ((packed));
254 240
255/* Volume Descriptor Pointer (ECMA 167r3 3/10.3) */ 241/* Volume Descriptor Pointer (ECMA 167r3 3/10.3) */
256struct volDescPtr 242struct volDescPtr {
257{
258 tag descTag; 243 tag descTag;
259 __le32 volDescSeqNum; 244 __le32 volDescSeqNum;
260 extent_ad nextVolDescSeqExt; 245 extent_ad nextVolDescSeqExt;
@@ -262,8 +247,7 @@ struct volDescPtr
262} __attribute__ ((packed)); 247} __attribute__ ((packed));
263 248
264/* Implementation Use Volume Descriptor (ECMA 167r3 3/10.4) */ 249/* Implementation Use Volume Descriptor (ECMA 167r3 3/10.4) */
265struct impUseVolDesc 250struct impUseVolDesc {
266{
267 tag descTag; 251 tag descTag;
268 __le32 volDescSeqNum; 252 __le32 volDescSeqNum;
269 regid impIdent; 253 regid impIdent;
@@ -271,20 +255,19 @@ struct impUseVolDesc
271} __attribute__ ((packed)); 255} __attribute__ ((packed));
272 256
273/* Partition Descriptor (ECMA 167r3 3/10.5) */ 257/* Partition Descriptor (ECMA 167r3 3/10.5) */
274struct partitionDesc 258struct partitionDesc {
275{ 259 tag descTag;
276 tag descTag; 260 __le32 volDescSeqNum;
277 __le32 volDescSeqNum; 261 __le16 partitionFlags;
278 __le16 partitionFlags; 262 __le16 partitionNumber;
279 __le16 partitionNumber; 263 regid partitionContents;
280 regid partitionContents; 264 uint8_t partitionContentsUse[128];
281 uint8_t partitionContentsUse[128]; 265 __le32 accessType;
282 __le32 accessType; 266 __le32 partitionStartingLocation;
283 __le32 partitionStartingLocation; 267 __le32 partitionLength;
284 __le32 partitionLength; 268 regid impIdent;
285 regid impIdent; 269 uint8_t impUse[128];
286 uint8_t impUse[128]; 270 uint8_t reserved[156];
287 uint8_t reserved[156];
288} __attribute__ ((packed)); 271} __attribute__ ((packed));
289 272
290/* Partition Flags (ECMA 167r3 3/10.5.3) */ 273/* Partition Flags (ECMA 167r3 3/10.5.3) */
@@ -307,8 +290,7 @@ struct partitionDesc
307#define PD_ACCESS_TYPE_OVERWRITABLE 0x00000004 290#define PD_ACCESS_TYPE_OVERWRITABLE 0x00000004
308 291
309/* Logical Volume Descriptor (ECMA 167r3 3/10.6) */ 292/* Logical Volume Descriptor (ECMA 167r3 3/10.6) */
310struct logicalVolDesc 293struct logicalVolDesc {
311{
312 tag descTag; 294 tag descTag;
313 __le32 volDescSeqNum; 295 __le32 volDescSeqNum;
314 charspec descCharSet; 296 charspec descCharSet;
@@ -325,8 +307,7 @@ struct logicalVolDesc
325} __attribute__ ((packed)); 307} __attribute__ ((packed));
326 308
327/* Generic Partition Map (ECMA 167r3 3/10.7.1) */ 309/* Generic Partition Map (ECMA 167r3 3/10.7.1) */
328struct genericPartitionMap 310struct genericPartitionMap {
329{
330 uint8_t partitionMapType; 311 uint8_t partitionMapType;
331 uint8_t partitionMapLength; 312 uint8_t partitionMapLength;
332 uint8_t partitionMapping[0]; 313 uint8_t partitionMapping[0];
@@ -338,8 +319,7 @@ struct genericPartitionMap
338#define GP_PARTITION_MAP_TYPE_2 0x02 319#define GP_PARTITION_MAP_TYPE_2 0x02
339 320
340/* Type 1 Partition Map (ECMA 167r3 3/10.7.2) */ 321/* Type 1 Partition Map (ECMA 167r3 3/10.7.2) */
341struct genericPartitionMap1 322struct genericPartitionMap1 {
342{
343 uint8_t partitionMapType; 323 uint8_t partitionMapType;
344 uint8_t partitionMapLength; 324 uint8_t partitionMapLength;
345 __le16 volSeqNum; 325 __le16 volSeqNum;
@@ -347,16 +327,14 @@ struct genericPartitionMap1
347} __attribute__ ((packed)); 327} __attribute__ ((packed));
348 328
349/* Type 2 Partition Map (ECMA 167r3 3/10.7.3) */ 329/* Type 2 Partition Map (ECMA 167r3 3/10.7.3) */
350struct genericPartitionMap2 330struct genericPartitionMap2 {
351{
352 uint8_t partitionMapType; 331 uint8_t partitionMapType;
353 uint8_t partitionMapLength; 332 uint8_t partitionMapLength;
354 uint8_t partitionIdent[62]; 333 uint8_t partitionIdent[62];
355} __attribute__ ((packed)); 334} __attribute__ ((packed));
356 335
357/* Unallocated Space Descriptor (ECMA 167r3 3/10.8) */ 336/* Unallocated Space Descriptor (ECMA 167r3 3/10.8) */
358struct unallocSpaceDesc 337struct unallocSpaceDesc {
359{
360 tag descTag; 338 tag descTag;
361 __le32 volDescSeqNum; 339 __le32 volDescSeqNum;
362 __le32 numAllocDescs; 340 __le32 numAllocDescs;
@@ -364,15 +342,13 @@ struct unallocSpaceDesc
364} __attribute__ ((packed)); 342} __attribute__ ((packed));
365 343
366/* Terminating Descriptor (ECMA 167r3 3/10.9) */ 344/* Terminating Descriptor (ECMA 167r3 3/10.9) */
367struct terminatingDesc 345struct terminatingDesc {
368{
369 tag descTag; 346 tag descTag;
370 uint8_t reserved[496]; 347 uint8_t reserved[496];
371} __attribute__ ((packed)); 348} __attribute__ ((packed));
372 349
373/* Logical Volume Integrity Descriptor (ECMA 167r3 3/10.10) */ 350/* Logical Volume Integrity Descriptor (ECMA 167r3 3/10.10) */
374struct logicalVolIntegrityDesc 351struct logicalVolIntegrityDesc {
375{
376 tag descTag; 352 tag descTag;
377 timestamp recordingDateAndTime; 353 timestamp recordingDateAndTime;
378 __le32 integrityType; 354 __le32 integrityType;
@@ -390,52 +366,45 @@ struct logicalVolIntegrityDesc
390#define LVID_INTEGRITY_TYPE_CLOSE 0x00000001 366#define LVID_INTEGRITY_TYPE_CLOSE 0x00000001
391 367
392/* Recorded Address (ECMA 167r3 4/7.1) */ 368/* Recorded Address (ECMA 167r3 4/7.1) */
393typedef struct 369typedef struct {
394{
395 __le32 logicalBlockNum; 370 __le32 logicalBlockNum;
396 __le16 partitionReferenceNum; 371 __le16 partitionReferenceNum;
397} __attribute__ ((packed)) lb_addr; 372} __attribute__ ((packed)) lb_addr;
398 373
399/* ... and its in-core analog */ 374/* ... and its in-core analog */
400typedef struct 375typedef struct {
401{
402 uint32_t logicalBlockNum; 376 uint32_t logicalBlockNum;
403 uint16_t partitionReferenceNum; 377 uint16_t partitionReferenceNum;
404} kernel_lb_addr; 378} kernel_lb_addr;
405 379
406/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */ 380/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */
407typedef struct 381typedef struct {
408{
409 __le32 extLength; 382 __le32 extLength;
410 __le32 extPosition; 383 __le32 extPosition;
411} __attribute__ ((packed)) short_ad; 384} __attribute__ ((packed)) short_ad;
412 385
413/* Long Allocation Descriptor (ECMA 167r3 4/14.14.2) */ 386/* Long Allocation Descriptor (ECMA 167r3 4/14.14.2) */
414typedef struct 387typedef struct {
415{
416 __le32 extLength; 388 __le32 extLength;
417 lb_addr extLocation; 389 lb_addr extLocation;
418 uint8_t impUse[6]; 390 uint8_t impUse[6];
419} __attribute__ ((packed)) long_ad; 391} __attribute__ ((packed)) long_ad;
420 392
421typedef struct 393typedef struct {
422{
423 uint32_t extLength; 394 uint32_t extLength;
424 kernel_lb_addr extLocation; 395 kernel_lb_addr extLocation;
425 uint8_t impUse[6]; 396 uint8_t impUse[6];
426} kernel_long_ad; 397} kernel_long_ad;
427 398
428/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */ 399/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */
429typedef struct 400typedef struct {
430{
431 __le32 extLength; 401 __le32 extLength;
432 __le32 recordedLength; 402 __le32 recordedLength;
433 __le32 informationLength; 403 __le32 informationLength;
434 lb_addr extLocation; 404 lb_addr extLocation;
435} __attribute__ ((packed)) ext_ad; 405} __attribute__ ((packed)) ext_ad;
436 406
437typedef struct 407typedef struct {
438{
439 uint32_t extLength; 408 uint32_t extLength;
440 uint32_t recordedLength; 409 uint32_t recordedLength;
441 uint32_t informationLength; 410 uint32_t informationLength;
@@ -458,8 +427,7 @@ typedef struct
458#define TAG_IDENT_EFE 0x010A 427#define TAG_IDENT_EFE 0x010A
459 428
460/* File Set Descriptor (ECMA 167r3 4/14.1) */ 429/* File Set Descriptor (ECMA 167r3 4/14.1) */
461struct fileSetDesc 430struct fileSetDesc {
462{
463 tag descTag; 431 tag descTag;
464 timestamp recordingDateAndTime; 432 timestamp recordingDateAndTime;
465 __le16 interchangeLvl; 433 __le16 interchangeLvl;
@@ -482,8 +450,7 @@ struct fileSetDesc
482} __attribute__ ((packed)); 450} __attribute__ ((packed));
483 451
484/* Partition Header Descriptor (ECMA 167r3 4/14.3) */ 452/* Partition Header Descriptor (ECMA 167r3 4/14.3) */
485struct partitionHeaderDesc 453struct partitionHeaderDesc {
486{
487 short_ad unallocSpaceTable; 454 short_ad unallocSpaceTable;
488 short_ad unallocSpaceBitmap; 455 short_ad unallocSpaceBitmap;
489 short_ad partitionIntegrityTable; 456 short_ad partitionIntegrityTable;
@@ -493,8 +460,7 @@ struct partitionHeaderDesc
493} __attribute__ ((packed)); 460} __attribute__ ((packed));
494 461
495/* File Identifier Descriptor (ECMA 167r3 4/14.4) */ 462/* File Identifier Descriptor (ECMA 167r3 4/14.4) */
496struct fileIdentDesc 463struct fileIdentDesc {
497{
498 tag descTag; 464 tag descTag;
499 __le16 fileVersionNum; 465 __le16 fileVersionNum;
500 uint8_t fileCharacteristics; 466 uint8_t fileCharacteristics;
@@ -514,16 +480,14 @@ struct fileIdentDesc
514#define FID_FILE_CHAR_METADATA 0x10 480#define FID_FILE_CHAR_METADATA 0x10
515 481
516/* Allocation Ext Descriptor (ECMA 167r3 4/14.5) */ 482/* Allocation Ext Descriptor (ECMA 167r3 4/14.5) */
517struct allocExtDesc 483struct allocExtDesc {
518{
519 tag descTag; 484 tag descTag;
520 __le32 previousAllocExtLocation; 485 __le32 previousAllocExtLocation;
521 __le32 lengthAllocDescs; 486 __le32 lengthAllocDescs;
522} __attribute__ ((packed)); 487} __attribute__ ((packed));
523 488
524/* ICB Tag (ECMA 167r3 4/14.6) */ 489/* ICB Tag (ECMA 167r3 4/14.6) */
525typedef struct 490typedef struct {
526{
527 __le32 priorRecordedNumDirectEntries; 491 __le32 priorRecordedNumDirectEntries;
528 __le16 strategyType; 492 __le16 strategyType;
529 __le16 strategyParameter; 493 __le16 strategyParameter;
@@ -576,23 +540,20 @@ typedef struct
576#define ICBTAG_FLAG_STREAM 0x2000 540#define ICBTAG_FLAG_STREAM 0x2000
577 541
578/* Indirect Entry (ECMA 167r3 4/14.7) */ 542/* Indirect Entry (ECMA 167r3 4/14.7) */
579struct indirectEntry 543struct indirectEntry {
580{
581 tag descTag; 544 tag descTag;
582 icbtag icbTag; 545 icbtag icbTag;
583 long_ad indirectICB; 546 long_ad indirectICB;
584} __attribute__ ((packed)); 547} __attribute__ ((packed));
585 548
586/* Terminal Entry (ECMA 167r3 4/14.8) */ 549/* Terminal Entry (ECMA 167r3 4/14.8) */
587struct terminalEntry 550struct terminalEntry {
588{
589 tag descTag; 551 tag descTag;
590 icbtag icbTag; 552 icbtag icbTag;
591} __attribute__ ((packed)); 553} __attribute__ ((packed));
592 554
593/* File Entry (ECMA 167r3 4/14.9) */ 555/* File Entry (ECMA 167r3 4/14.9) */
594struct fileEntry 556struct fileEntry {
595{
596 tag descTag; 557 tag descTag;
597 icbtag icbTag; 558 icbtag icbTag;
598 __le32 uid; 559 __le32 uid;
@@ -655,16 +616,14 @@ struct fileEntry
655#define FE_RECORD_DISPLAY_ATTR_3 0x03 616#define FE_RECORD_DISPLAY_ATTR_3 0x03
656 617
657/* Extended Attribute Header Descriptor (ECMA 167r3 4/14.10.1) */ 618/* Extended Attribute Header Descriptor (ECMA 167r3 4/14.10.1) */
658struct extendedAttrHeaderDesc 619struct extendedAttrHeaderDesc {
659{
660 tag descTag; 620 tag descTag;
661 __le32 impAttrLocation; 621 __le32 impAttrLocation;
662 __le32 appAttrLocation; 622 __le32 appAttrLocation;
663} __attribute__ ((packed)); 623} __attribute__ ((packed));
664 624
665/* Generic Format (ECMA 167r3 4/14.10.2) */ 625/* Generic Format (ECMA 167r3 4/14.10.2) */
666struct genericFormat 626struct genericFormat {
667{
668 __le32 attrType; 627 __le32 attrType;
669 uint8_t attrSubtype; 628 uint8_t attrSubtype;
670 uint8_t reserved[3]; 629 uint8_t reserved[3];
@@ -673,8 +632,7 @@ struct genericFormat
673} __attribute__ ((packed)); 632} __attribute__ ((packed));
674 633
675/* Character Set Information (ECMA 167r3 4/14.10.3) */ 634/* Character Set Information (ECMA 167r3 4/14.10.3) */
676struct charSetInfo 635struct charSetInfo {
677{
678 __le32 attrType; 636 __le32 attrType;
679 uint8_t attrSubtype; 637 uint8_t attrSubtype;
680 uint8_t reserved[3]; 638 uint8_t reserved[3];
@@ -685,8 +643,7 @@ struct charSetInfo
685} __attribute__ ((packed)); 643} __attribute__ ((packed));
686 644
687/* Alternate Permissions (ECMA 167r3 4/14.10.4) */ 645/* Alternate Permissions (ECMA 167r3 4/14.10.4) */
688struct altPerms 646struct altPerms {
689{
690 __le32 attrType; 647 __le32 attrType;
691 uint8_t attrSubtype; 648 uint8_t attrSubtype;
692 uint8_t reserved[3]; 649 uint8_t reserved[3];
@@ -697,8 +654,7 @@ struct altPerms
697} __attribute__ ((packed)); 654} __attribute__ ((packed));
698 655
699/* File Times Extended Attribute (ECMA 167r3 4/14.10.5) */ 656/* File Times Extended Attribute (ECMA 167r3 4/14.10.5) */
700struct fileTimesExtAttr 657struct fileTimesExtAttr {
701{
702 __le32 attrType; 658 __le32 attrType;
703 uint8_t attrSubtype; 659 uint8_t attrSubtype;
704 uint8_t reserved[3]; 660 uint8_t reserved[3];
@@ -715,8 +671,7 @@ struct fileTimesExtAttr
715#define FTE_BACKUP 0x00000002 671#define FTE_BACKUP 0x00000002
716 672
717/* Information Times Extended Attribute (ECMA 167r3 4/14.10.6) */ 673/* Information Times Extended Attribute (ECMA 167r3 4/14.10.6) */
718struct infoTimesExtAttr 674struct infoTimesExtAttr {
719{
720 __le32 attrType; 675 __le32 attrType;
721 uint8_t attrSubtype; 676 uint8_t attrSubtype;
722 uint8_t reserved[3]; 677 uint8_t reserved[3];
@@ -727,8 +682,7 @@ struct infoTimesExtAttr
727} __attribute__ ((packed)); 682} __attribute__ ((packed));
728 683
729/* Device Specification (ECMA 167r3 4/14.10.7) */ 684/* Device Specification (ECMA 167r3 4/14.10.7) */
730struct deviceSpec 685struct deviceSpec {
731{
732 __le32 attrType; 686 __le32 attrType;
733 uint8_t attrSubtype; 687 uint8_t attrSubtype;
734 uint8_t reserved[3]; 688 uint8_t reserved[3];
@@ -740,8 +694,7 @@ struct deviceSpec
740} __attribute__ ((packed)); 694} __attribute__ ((packed));
741 695
742/* Implementation Use Extended Attr (ECMA 167r3 4/14.10.8) */ 696/* Implementation Use Extended Attr (ECMA 167r3 4/14.10.8) */
743struct impUseExtAttr 697struct impUseExtAttr {
744{
745 __le32 attrType; 698 __le32 attrType;
746 uint8_t attrSubtype; 699 uint8_t attrSubtype;
747 uint8_t reserved[3]; 700 uint8_t reserved[3];
@@ -752,8 +705,7 @@ struct impUseExtAttr
752} __attribute__ ((packed)); 705} __attribute__ ((packed));
753 706
754/* Application Use Extended Attribute (ECMA 167r3 4/14.10.9) */ 707/* Application Use Extended Attribute (ECMA 167r3 4/14.10.9) */
755struct appUseExtAttr 708struct appUseExtAttr {
756{
757 __le32 attrType; 709 __le32 attrType;
758 uint8_t attrSubtype; 710 uint8_t attrSubtype;
759 uint8_t reserved[3]; 711 uint8_t reserved[3];
@@ -771,10 +723,8 @@ struct appUseExtAttr
771#define EXTATTR_IMP_USE 2048 723#define EXTATTR_IMP_USE 2048
772#define EXTATTR_APP_USE 65536 724#define EXTATTR_APP_USE 65536
773 725
774
775/* Unallocated Space Entry (ECMA 167r3 4/14.11) */ 726/* Unallocated Space Entry (ECMA 167r3 4/14.11) */
776struct unallocSpaceEntry 727struct unallocSpaceEntry {
777{
778 tag descTag; 728 tag descTag;
779 icbtag icbTag; 729 icbtag icbTag;
780 __le32 lengthAllocDescs; 730 __le32 lengthAllocDescs;
@@ -782,8 +732,7 @@ struct unallocSpaceEntry
782} __attribute__ ((packed)); 732} __attribute__ ((packed));
783 733
784/* Space Bitmap Descriptor (ECMA 167r3 4/14.12) */ 734/* Space Bitmap Descriptor (ECMA 167r3 4/14.12) */
785struct spaceBitmapDesc 735struct spaceBitmapDesc {
786{
787 tag descTag; 736 tag descTag;
788 __le32 numOfBits; 737 __le32 numOfBits;
789 __le32 numOfBytes; 738 __le32 numOfBytes;
@@ -791,8 +740,7 @@ struct spaceBitmapDesc
791} __attribute__ ((packed)); 740} __attribute__ ((packed));
792 741
793/* Partition Integrity Entry (ECMA 167r3 4/14.13) */ 742/* Partition Integrity Entry (ECMA 167r3 4/14.13) */
794struct partitionIntegrityEntry 743struct partitionIntegrityEntry {
795{
796 tag descTag; 744 tag descTag;
797 icbtag icbTag; 745 icbtag icbTag;
798 timestamp recordingDateAndTime; 746 timestamp recordingDateAndTime;
@@ -815,15 +763,13 @@ struct partitionIntegrityEntry
815/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */ 763/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */
816 764
817/* Logical Volume Header Descriptor (ECMA 167r3 4/14.15) */ 765/* Logical Volume Header Descriptor (ECMA 167r3 4/14.15) */
818struct logicalVolHeaderDesc 766struct logicalVolHeaderDesc {
819{
820 __le64 uniqueID; 767 __le64 uniqueID;
821 uint8_t reserved[24]; 768 uint8_t reserved[24];
822} __attribute__ ((packed)); 769} __attribute__ ((packed));
823 770
824/* Path Component (ECMA 167r3 4/14.16.1) */ 771/* Path Component (ECMA 167r3 4/14.16.1) */
825struct pathComponent 772struct pathComponent {
826{
827 uint8_t componentType; 773 uint8_t componentType;
828 uint8_t lengthComponentIdent; 774 uint8_t lengthComponentIdent;
829 __le16 componentFileVersionNum; 775 __le16 componentFileVersionNum;
@@ -831,8 +777,7 @@ struct pathComponent
831} __attribute__ ((packed)); 777} __attribute__ ((packed));
832 778
833/* File Entry (ECMA 167r3 4/14.17) */ 779/* File Entry (ECMA 167r3 4/14.17) */
834struct extendedFileEntry 780struct extendedFileEntry {
835{
836 tag descTag; 781 tag descTag;
837 icbtag icbTag; 782 icbtag icbTag;
838 __le32 uid; 783 __le32 uid;
diff --git a/fs/udf/file.c b/fs/udf/file.c
index df070bee8d4f..5d7a4ea27753 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -41,7 +41,7 @@
41#include "udf_i.h" 41#include "udf_i.h"
42#include "udf_sb.h" 42#include "udf_sb.h"
43 43
44static int udf_adinicb_readpage(struct file *file, struct page * page) 44static int udf_adinicb_readpage(struct file *file, struct page *page)
45{ 45{
46 struct inode *inode = page->mapping->host; 46 struct inode *inode = page->mapping->host;
47 char *kaddr; 47 char *kaddr;
@@ -55,6 +55,7 @@ static int udf_adinicb_readpage(struct file *file, struct page * page)
55 SetPageUptodate(page); 55 SetPageUptodate(page);
56 kunmap(page); 56 kunmap(page);
57 unlock_page(page); 57 unlock_page(page);
58
58 return 0; 59 return 0;
59} 60}
60 61
@@ -71,22 +72,25 @@ static int udf_adinicb_writepage(struct page *page, struct writeback_control *wb
71 SetPageUptodate(page); 72 SetPageUptodate(page);
72 kunmap(page); 73 kunmap(page);
73 unlock_page(page); 74 unlock_page(page);
75
74 return 0; 76 return 0;
75} 77}
76 78
77static int udf_adinicb_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to) 79static int udf_adinicb_prepare_write(struct file *file, struct page *page,
80 unsigned offset, unsigned to)
78{ 81{
79 kmap(page); 82 kmap(page);
80 return 0; 83 return 0;
81} 84}
82 85
83static int udf_adinicb_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to) 86static int udf_adinicb_commit_write(struct file *file, struct page *page,
87 unsigned offset, unsigned to)
84{ 88{
85 struct inode *inode = page->mapping->host; 89 struct inode *inode = page->mapping->host;
86 char *kaddr = page_address(page); 90 char *kaddr = page_address(page);
87 91
88 memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 92 memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset,
89 kaddr + offset, to - offset); 93 kaddr + offset, to - offset);
90 mark_inode_dirty(inode); 94 mark_inode_dirty(inode);
91 SetPageUptodate(page); 95 SetPageUptodate(page);
92 kunmap(page); 96 kunmap(page);
@@ -97,15 +101,15 @@ static int udf_adinicb_commit_write(struct file *file, struct page *page, unsign
97} 101}
98 102
99const struct address_space_operations udf_adinicb_aops = { 103const struct address_space_operations udf_adinicb_aops = {
100 .readpage = udf_adinicb_readpage, 104 .readpage = udf_adinicb_readpage,
101 .writepage = udf_adinicb_writepage, 105 .writepage = udf_adinicb_writepage,
102 .sync_page = block_sync_page, 106 .sync_page = block_sync_page,
103 .prepare_write = udf_adinicb_prepare_write, 107 .prepare_write = udf_adinicb_prepare_write,
104 .commit_write = udf_adinicb_commit_write, 108 .commit_write = udf_adinicb_commit_write,
105}; 109};
106 110
107static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 111static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
108 unsigned long nr_segs, loff_t ppos) 112 unsigned long nr_segs, loff_t ppos)
109{ 113{
110 ssize_t retval; 114 ssize_t retval;
111 struct file *file = iocb->ki_filp; 115 struct file *file = iocb->ki_filp;
@@ -113,25 +117,20 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
113 int err, pos; 117 int err, pos;
114 size_t count = iocb->ki_left; 118 size_t count = iocb->ki_left;
115 119
116 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 120 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
117 {
118 if (file->f_flags & O_APPEND) 121 if (file->f_flags & O_APPEND)
119 pos = inode->i_size; 122 pos = inode->i_size;
120 else 123 else
121 pos = ppos; 124 pos = ppos;
122 125
123 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + 126 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
124 pos + count)) 127 pos + count)) {
125 {
126 udf_expand_file_adinicb(inode, pos + count, &err); 128 udf_expand_file_adinicb(inode, pos + count, &err);
127 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 129 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
128 {
129 udf_debug("udf_expand_adinicb: err=%d\n", err); 130 udf_debug("udf_expand_adinicb: err=%d\n", err);
130 return err; 131 return err;
131 } 132 }
132 } 133 } else {
133 else
134 {
135 if (pos + count > inode->i_size) 134 if (pos + count > inode->i_size)
136 UDF_I_LENALLOC(inode) = pos + count; 135 UDF_I_LENALLOC(inode) = pos + count;
137 else 136 else
@@ -140,9 +139,9 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
140 } 139 }
141 140
142 retval = generic_file_aio_write(iocb, iov, nr_segs, ppos); 141 retval = generic_file_aio_write(iocb, iov, nr_segs, ppos);
143
144 if (retval > 0) 142 if (retval > 0)
145 mark_inode_dirty(inode); 143 mark_inode_dirty(inode);
144
146 return retval; 145 return retval;
147} 146}
148 147
@@ -181,48 +180,42 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
181 * Written, tested, and released. 180 * Written, tested, and released.
182 */ 181 */
183int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 182int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
184 unsigned long arg) 183 unsigned long arg)
185{ 184{
185 long old_block, new_block;
186 int result = -EINVAL; 186 int result = -EINVAL;
187 187
188 if ( file_permission(filp, MAY_READ) != 0 ) 188 if (file_permission(filp, MAY_READ) != 0) {
189 {
190 udf_debug("no permission to access inode %lu\n", 189 udf_debug("no permission to access inode %lu\n",
191 inode->i_ino); 190 inode->i_ino);
192 return -EPERM; 191 return -EPERM;
193 } 192 }
194 193
195 if ( !arg ) 194 if (!arg) {
196 {
197 udf_debug("invalid argument to udf_ioctl\n"); 195 udf_debug("invalid argument to udf_ioctl\n");
198 return -EINVAL; 196 return -EINVAL;
199 } 197 }
200 198
201 switch (cmd) 199 switch (cmd) {
202 { 200 case UDF_GETVOLIDENT:
203 case UDF_GETVOLIDENT: 201 return copy_to_user((char __user *)arg,
204 return copy_to_user((char __user *)arg, 202 UDF_SB_VOLIDENT(inode->i_sb), 32) ? -EFAULT : 0;
205 UDF_SB_VOLIDENT(inode->i_sb), 32) ? -EFAULT : 0; 203 case UDF_RELOCATE_BLOCKS:
206 case UDF_RELOCATE_BLOCKS: 204 if (!capable(CAP_SYS_ADMIN))
207 { 205 return -EACCES;
208 long old, new; 206 if (get_user(old_block, (long __user *)arg))
209 207 return -EFAULT;
210 if (!capable(CAP_SYS_ADMIN)) return -EACCES; 208 if ((result = udf_relocate_blocks(inode->i_sb,
211 if (get_user(old, (long __user *)arg)) return -EFAULT; 209 old_block, &new_block)) == 0)
212 if ((result = udf_relocate_blocks(inode->i_sb, 210 result = put_user(new_block, (long __user *)arg);
213 old, &new)) == 0) 211 return result;
214 result = put_user(new, (long __user *)arg); 212 case UDF_GETEASIZE:
215 213 result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg);
216 return result; 214 break;
217 } 215 case UDF_GETEABLOCK:
218 case UDF_GETEASIZE: 216 result = copy_to_user((char __user *)arg, UDF_I_DATA(inode),
219 result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg); 217 UDF_I_LENEATTR(inode)) ? -EFAULT : 0;
220 break; 218 break;
221
222 case UDF_GETEABLOCK:
223 result = copy_to_user((char __user *)arg, UDF_I_DATA(inode),
224 UDF_I_LENEATTR(inode)) ? -EFAULT : 0;
225 break;
226 } 219 }
227 220
228 return result; 221 return result;
@@ -240,10 +233,9 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
240 * HISTORY 233 * HISTORY
241 * 234 *
242 */ 235 */
243static int udf_release_file(struct inode * inode, struct file * filp) 236static int udf_release_file(struct inode *inode, struct file *filp)
244{ 237{
245 if (filp->f_mode & FMODE_WRITE) 238 if (filp->f_mode & FMODE_WRITE) {
246 {
247 lock_kernel(); 239 lock_kernel();
248 udf_discard_prealloc(inode); 240 udf_discard_prealloc(inode);
249 unlock_kernel(); 241 unlock_kernel();
@@ -265,5 +257,5 @@ const struct file_operations udf_file_operations = {
265}; 257};
266 258
267const struct inode_operations udf_file_inode_operations = { 259const struct inode_operations udf_file_inode_operations = {
268 .truncate = udf_truncate, 260 .truncate = udf_truncate,
269}; 261};
diff --git a/fs/udf/fsync.c b/fs/udf/fsync.c
index 6ded93e7c44f..b2c472b733b8 100644
--- a/fs/udf/fsync.c
+++ b/fs/udf/fsync.c
@@ -29,9 +29,10 @@ static int udf_fsync_inode(struct inode *, int);
29 * even pass file to fsync ? 29 * even pass file to fsync ?
30 */ 30 */
31 31
32int udf_fsync_file(struct file * file, struct dentry *dentry, int datasync) 32int udf_fsync_file(struct file *file, struct dentry *dentry, int datasync)
33{ 33{
34 struct inode *inode = dentry->d_inode; 34 struct inode *inode = dentry->d_inode;
35
35 return udf_fsync_inode(inode, datasync); 36 return udf_fsync_inode(inode, datasync);
36} 37}
37 38
@@ -45,6 +46,7 @@ static int udf_fsync_inode(struct inode *inode, int datasync)
45 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) 46 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
46 return err; 47 return err;
47 48
48 err |= udf_sync_inode (inode); 49 err |= udf_sync_inode(inode);
50
49 return err ? -EIO : 0; 51 return err ? -EIO : 0;
50} 52}
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index 8206983f2ebf..636d8f613929 100644
--- a/fs/udf/ialloc.c
+++ b/fs/udf/ialloc.c
@@ -28,7 +28,7 @@
28#include "udf_i.h" 28#include "udf_i.h"
29#include "udf_sb.h" 29#include "udf_sb.h"
30 30
31void udf_free_inode(struct inode * inode) 31void udf_free_inode(struct inode *inode)
32{ 32{
33 struct super_block *sb = inode->i_sb; 33 struct super_block *sb = inode->i_sb;
34 struct udf_sb_info *sbi = UDF_SB(sb); 34 struct udf_sb_info *sbi = UDF_SB(sb);
@@ -50,7 +50,7 @@ void udf_free_inode(struct inode * inode)
50 else 50 else
51 UDF_SB_LVIDIU(sb)->numFiles = 51 UDF_SB_LVIDIU(sb)->numFiles =
52 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1); 52 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1);
53 53
54 mark_buffer_dirty(sbi->s_lvidbh); 54 mark_buffer_dirty(sbi->s_lvidbh);
55 } 55 }
56 mutex_unlock(&sbi->s_alloc_mutex); 56 mutex_unlock(&sbi->s_alloc_mutex);
@@ -58,18 +58,17 @@ void udf_free_inode(struct inode * inode)
58 udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1); 58 udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1);
59} 59}
60 60
61struct inode * udf_new_inode (struct inode *dir, int mode, int * err) 61struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
62{ 62{
63 struct super_block *sb = dir->i_sb; 63 struct super_block *sb = dir->i_sb;
64 struct udf_sb_info *sbi = UDF_SB(sb); 64 struct udf_sb_info *sbi = UDF_SB(sb);
65 struct inode * inode; 65 struct inode *inode;
66 int block; 66 int block;
67 uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum; 67 uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum;
68 68
69 inode = new_inode(sb); 69 inode = new_inode(sb);
70 70
71 if (!inode) 71 if (!inode) {
72 {
73 *err = -ENOMEM; 72 *err = -ENOMEM;
74 return NULL; 73 return NULL;
75 } 74 }
@@ -82,16 +81,14 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
82 UDF_I_STRAT4096(inode) = 0; 81 UDF_I_STRAT4096(inode) = 0;
83 82
84 block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, 83 block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum,
85 start, err); 84 start, err);
86 if (*err) 85 if (*err) {
87 {
88 iput(inode); 86 iput(inode);
89 return NULL; 87 return NULL;
90 } 88 }
91 89
92 mutex_lock(&sbi->s_alloc_mutex); 90 mutex_lock(&sbi->s_alloc_mutex);
93 if (UDF_SB_LVIDBH(sb)) 91 if (UDF_SB_LVIDBH(sb)) {
94 {
95 struct logicalVolHeaderDesc *lvhd; 92 struct logicalVolHeaderDesc *lvhd;
96 uint64_t uniqueID; 93 uint64_t uniqueID;
97 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse); 94 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse);
@@ -109,14 +106,13 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
109 } 106 }
110 inode->i_mode = mode; 107 inode->i_mode = mode;
111 inode->i_uid = current->fsuid; 108 inode->i_uid = current->fsuid;
112 if (dir->i_mode & S_ISGID) 109 if (dir->i_mode & S_ISGID) {
113 {
114 inode->i_gid = dir->i_gid; 110 inode->i_gid = dir->i_gid;
115 if (S_ISDIR(mode)) 111 if (S_ISDIR(mode))
116 mode |= S_ISGID; 112 mode |= S_ISGID;
117 } 113 } else {
118 else
119 inode->i_gid = current->fsgid; 114 inode->i_gid = current->fsgid;
115 }
120 116
121 UDF_I_LOCATION(inode).logicalBlockNum = block; 117 UDF_I_LOCATION(inode).logicalBlockNum = block;
122 UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; 118 UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
@@ -125,17 +121,20 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
125 UDF_I_LENEATTR(inode) = 0; 121 UDF_I_LENEATTR(inode) = 0;
126 UDF_I_LENALLOC(inode) = 0; 122 UDF_I_LENALLOC(inode) = 0;
127 UDF_I_USE(inode) = 0; 123 UDF_I_USE(inode) = 0;
128 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) 124 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
129 {
130 UDF_I_EFE(inode) = 1; 125 UDF_I_EFE(inode) = 1;
131 UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE); 126 UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE);
132 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); 127 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
133 } 128 } else {
134 else
135 {
136 UDF_I_EFE(inode) = 0; 129 UDF_I_EFE(inode) = 0;
137 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); 130 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL);
138 } 131 }
132 if (!UDF_I_DATA(inode)) {
133 iput(inode);
134 *err = -ENOMEM;
135 mutex_unlock(&sbi->s_alloc_mutex);
136 return NULL;
137 }
139 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) 138 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
140 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 139 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
141 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 140 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
@@ -148,8 +147,7 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
148 mark_inode_dirty(inode); 147 mark_inode_dirty(inode);
149 mutex_unlock(&sbi->s_alloc_mutex); 148 mutex_unlock(&sbi->s_alloc_mutex);
150 149
151 if (DQUOT_ALLOC_INODE(inode)) 150 if (DQUOT_ALLOC_INODE(inode)) {
152 {
153 DQUOT_DROP(inode); 151 DQUOT_DROP(inode);
154 inode->i_flags |= S_NOQUOTA; 152 inode->i_flags |= S_NOQUOTA;
155 inode->i_nlink = 0; 153 inode->i_nlink = 0;
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index bf7de0bdbab3..0d2c41666cd2 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -49,19 +49,20 @@ MODULE_LICENSE("GPL");
49static mode_t udf_convert_permissions(struct fileEntry *); 49static mode_t udf_convert_permissions(struct fileEntry *);
50static int udf_update_inode(struct inode *, int); 50static int udf_update_inode(struct inode *, int);
51static void udf_fill_inode(struct inode *, struct buffer_head *); 51static void udf_fill_inode(struct inode *, struct buffer_head *);
52static int udf_alloc_i_data(struct inode *inode, size_t size);
52static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, 53static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
53 long *, int *); 54 long *, int *);
54static int8_t udf_insert_aext(struct inode *, struct extent_position, 55static int8_t udf_insert_aext(struct inode *, struct extent_position,
55 kernel_lb_addr, uint32_t); 56 kernel_lb_addr, uint32_t);
56static void udf_split_extents(struct inode *, int *, int, int, 57static void udf_split_extents(struct inode *, int *, int, int,
57 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 58 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
58static void udf_prealloc_extents(struct inode *, int, int, 59static void udf_prealloc_extents(struct inode *, int, int,
59 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 60 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
60static void udf_merge_extents(struct inode *, 61static void udf_merge_extents(struct inode *,
61 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 62 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
62static void udf_update_extents(struct inode *, 63static void udf_update_extents(struct inode *,
63 kernel_long_ad [EXTENT_MERGE_SIZE], int, int, 64 kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
64 struct extent_position *); 65 struct extent_position *);
65static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); 66static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
66 67
67/* 68/*
@@ -80,7 +81,7 @@ static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
80 * 81 *
81 * Called at the last iput() if i_nlink is zero. 82 * Called at the last iput() if i_nlink is zero.
82 */ 83 */
83void udf_delete_inode(struct inode * inode) 84void udf_delete_inode(struct inode *inode)
84{ 85{
85 truncate_inode_pages(&inode->i_data, 0); 86 truncate_inode_pages(&inode->i_data, 0);
86 87
@@ -96,6 +97,7 @@ void udf_delete_inode(struct inode * inode)
96 97
97 unlock_kernel(); 98 unlock_kernel();
98 return; 99 return;
100
99no_delete: 101no_delete:
100 clear_inode(inode); 102 clear_inode(inode);
101} 103}
@@ -131,26 +133,27 @@ static int udf_readpage(struct file *file, struct page *page)
131 return block_read_full_page(page, udf_get_block); 133 return block_read_full_page(page, udf_get_block);
132} 134}
133 135
134static int udf_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to) 136static int udf_prepare_write(struct file *file, struct page *page,
137 unsigned from, unsigned to)
135{ 138{
136 return block_prepare_write(page, from, to, udf_get_block); 139 return block_prepare_write(page, from, to, udf_get_block);
137} 140}
138 141
139static sector_t udf_bmap(struct address_space *mapping, sector_t block) 142static sector_t udf_bmap(struct address_space *mapping, sector_t block)
140{ 143{
141 return generic_block_bmap(mapping,block,udf_get_block); 144 return generic_block_bmap(mapping, block, udf_get_block);
142} 145}
143 146
144const struct address_space_operations udf_aops = { 147const struct address_space_operations udf_aops = {
145 .readpage = udf_readpage, 148 .readpage = udf_readpage,
146 .writepage = udf_writepage, 149 .writepage = udf_writepage,
147 .sync_page = block_sync_page, 150 .sync_page = block_sync_page,
148 .prepare_write = udf_prepare_write, 151 .prepare_write = udf_prepare_write,
149 .commit_write = generic_commit_write, 152 .commit_write = generic_commit_write,
150 .bmap = udf_bmap, 153 .bmap = udf_bmap,
151}; 154};
152 155
153void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err) 156void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
154{ 157{
155 struct page *page; 158 struct page *page;
156 char *kaddr; 159 char *kaddr;
@@ -162,8 +165,7 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
162 /* from now on we have normal address_space methods */ 165 /* from now on we have normal address_space methods */
163 inode->i_data.a_ops = &udf_aops; 166 inode->i_data.a_ops = &udf_aops;
164 167
165 if (!UDF_I_LENALLOC(inode)) 168 if (!UDF_I_LENALLOC(inode)) {
166 {
167 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 169 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
168 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 170 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
169 else 171 else
@@ -175,19 +177,18 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
175 page = grab_cache_page(inode->i_mapping, 0); 177 page = grab_cache_page(inode->i_mapping, 0);
176 BUG_ON(!PageLocked(page)); 178 BUG_ON(!PageLocked(page));
177 179
178 if (!PageUptodate(page)) 180 if (!PageUptodate(page)) {
179 {
180 kaddr = kmap(page); 181 kaddr = kmap(page);
181 memset(kaddr + UDF_I_LENALLOC(inode), 0x00, 182 memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
182 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode)); 183 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
183 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 184 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
184 UDF_I_LENALLOC(inode)); 185 UDF_I_LENALLOC(inode));
185 flush_dcache_page(page); 186 flush_dcache_page(page);
186 SetPageUptodate(page); 187 SetPageUptodate(page);
187 kunmap(page); 188 kunmap(page);
188 } 189 }
189 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00, 190 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
190 UDF_I_LENALLOC(inode)); 191 UDF_I_LENALLOC(inode));
191 UDF_I_LENALLOC(inode) = 0; 192 UDF_I_LENALLOC(inode) = 0;
192 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 193 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
193 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 194 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
@@ -200,7 +201,8 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
200 mark_inode_dirty(inode); 201 mark_inode_dirty(inode);
201} 202}
202 203
203struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err) 204struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
205 int *err)
204{ 206{
205 int newblock; 207 int newblock;
206 struct buffer_head *dbh = NULL; 208 struct buffer_head *dbh = NULL;
@@ -219,8 +221,7 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
219 else 221 else
220 alloctype = ICBTAG_FLAG_AD_LONG; 222 alloctype = ICBTAG_FLAG_AD_LONG;
221 223
222 if (!inode->i_size) 224 if (!inode->i_size) {
223 {
224 UDF_I_ALLOCTYPE(inode) = alloctype; 225 UDF_I_ALLOCTYPE(inode) = alloctype;
225 mark_inode_dirty(inode); 226 mark_inode_dirty(inode);
226 return NULL; 227 return NULL;
@@ -228,13 +229,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
228 229
229 /* alloc block, and copy data to it */ 230 /* alloc block, and copy data to it */
230 *block = udf_new_block(inode->i_sb, inode, 231 *block = udf_new_block(inode->i_sb, inode,
231 UDF_I_LOCATION(inode).partitionReferenceNum, 232 UDF_I_LOCATION(inode).partitionReferenceNum,
232 UDF_I_LOCATION(inode).logicalBlockNum, err); 233 UDF_I_LOCATION(inode).logicalBlockNum, err);
233
234 if (!(*block)) 234 if (!(*block))
235 return NULL; 235 return NULL;
236 newblock = udf_get_pblock(inode->i_sb, *block, 236 newblock = udf_get_pblock(inode->i_sb, *block,
237 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 237 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
238 if (!newblock) 238 if (!newblock)
239 return NULL; 239 return NULL;
240 dbh = udf_tgetblk(inode->i_sb, newblock); 240 dbh = udf_tgetblk(inode->i_sb, newblock);
@@ -250,12 +250,10 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
250 sfibh.sbh = sfibh.ebh = NULL; 250 sfibh.sbh = sfibh.ebh = NULL;
251 dfibh.soffset = dfibh.eoffset = 0; 251 dfibh.soffset = dfibh.eoffset = 0;
252 dfibh.sbh = dfibh.ebh = dbh; 252 dfibh.sbh = dfibh.ebh = dbh;
253 while ( (f_pos < size) ) 253 while ((f_pos < size)) {
254 {
255 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 254 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
256 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); 255 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL);
257 if (!sfi) 256 if (!sfi) {
258 {
259 brelse(dbh); 257 brelse(dbh);
260 return NULL; 258 return NULL;
261 } 259 }
@@ -265,8 +263,7 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
265 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); 263 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
266 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); 264 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
267 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, 265 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
268 sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) 266 sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) {
269 {
270 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 267 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
271 brelse(dbh); 268 brelse(dbh);
272 return NULL; 269 return NULL;
@@ -291,14 +288,14 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
291 return dbh; 288 return dbh;
292} 289}
293 290
294static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) 291static int udf_get_block(struct inode *inode, sector_t block,
292 struct buffer_head *bh_result, int create)
295{ 293{
296 int err, new; 294 int err, new;
297 struct buffer_head *bh; 295 struct buffer_head *bh;
298 unsigned long phys; 296 unsigned long phys;
299 297
300 if (!create) 298 if (!create) {
301 {
302 phys = udf_block_map(inode, block); 299 phys = udf_block_map(inode, block);
303 if (phys) 300 if (phys)
304 map_bh(bh_result, inode->i_sb, phys); 301 map_bh(bh_result, inode->i_sb, phys);
@@ -314,10 +311,9 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
314 if (block < 0) 311 if (block < 0)
315 goto abort_negative; 312 goto abort_negative;
316 313
317 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) 314 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
318 { 315 UDF_I_NEXT_ALLOC_BLOCK(inode)++;
319 UDF_I_NEXT_ALLOC_BLOCK(inode) ++; 316 UDF_I_NEXT_ALLOC_GOAL(inode)++;
320 UDF_I_NEXT_ALLOC_GOAL(inode) ++;
321 } 317 }
322 318
323 err = 0; 319 err = 0;
@@ -331,6 +327,7 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
331 if (new) 327 if (new)
332 set_buffer_new(bh_result); 328 set_buffer_new(bh_result);
333 map_bh(bh_result, inode->i_sb, phys); 329 map_bh(bh_result, inode->i_sb, phys);
330
334abort: 331abort:
335 unlock_kernel(); 332 unlock_kernel();
336 return err; 333 return err;
@@ -340,20 +337,18 @@ abort_negative:
340 goto abort; 337 goto abort;
341} 338}
342 339
343static struct buffer_head * 340static struct buffer_head *udf_getblk(struct inode *inode, long block,
344udf_getblk(struct inode *inode, long block, int create, int *err) 341 int create, int *err)
345{ 342{
343 struct buffer_head *bh;
346 struct buffer_head dummy; 344 struct buffer_head dummy;
347 345
348 dummy.b_state = 0; 346 dummy.b_state = 0;
349 dummy.b_blocknr = -1000; 347 dummy.b_blocknr = -1000;
350 *err = udf_get_block(inode, block, &dummy, create); 348 *err = udf_get_block(inode, block, &dummy, create);
351 if (!*err && buffer_mapped(&dummy)) 349 if (!*err && buffer_mapped(&dummy)) {
352 {
353 struct buffer_head *bh;
354 bh = sb_getblk(inode->i_sb, dummy.b_blocknr); 350 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
355 if (buffer_new(&dummy)) 351 if (buffer_new(&dummy)) {
356 {
357 lock_buffer(bh); 352 lock_buffer(bh);
358 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); 353 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
359 set_buffer_uptodate(bh); 354 set_buffer_uptodate(bh);
@@ -362,33 +357,36 @@ udf_getblk(struct inode *inode, long block, int create, int *err)
362 } 357 }
363 return bh; 358 return bh;
364 } 359 }
360
365 return NULL; 361 return NULL;
366} 362}
367 363
368/* Extend the file by 'blocks' blocks, return the number of extents added */ 364/* Extend the file by 'blocks' blocks, return the number of extents added */
369int udf_extend_file(struct inode *inode, struct extent_position *last_pos, 365int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
370 kernel_long_ad *last_ext, sector_t blocks) 366 kernel_long_ad * last_ext, sector_t blocks)
371{ 367{
372 sector_t add; 368 sector_t add;
373 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 369 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
374 struct super_block *sb = inode->i_sb; 370 struct super_block *sb = inode->i_sb;
375 kernel_lb_addr prealloc_loc = {0, 0}; 371 kernel_lb_addr prealloc_loc = {};
376 int prealloc_len = 0; 372 int prealloc_len = 0;
377 373
378 /* The previous extent is fake and we should not extend by anything 374 /* The previous extent is fake and we should not extend by anything
379 * - there's nothing to do... */ 375 * - there's nothing to do... */
380 if (!blocks && fake) 376 if (!blocks && fake)
381 return 0; 377 return 0;
378
382 /* Round the last extent up to a multiple of block size */ 379 /* Round the last extent up to a multiple of block size */
383 if (last_ext->extLength & (sb->s_blocksize - 1)) { 380 if (last_ext->extLength & (sb->s_blocksize - 1)) {
384 last_ext->extLength = 381 last_ext->extLength =
385 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | 382 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
386 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + 383 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
387 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); 384 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
388 UDF_I_LENEXTENTS(inode) = 385 UDF_I_LENEXTENTS(inode) =
389 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & 386 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
390 ~(sb->s_blocksize - 1); 387 ~(sb->s_blocksize - 1);
391 } 388 }
389
392 /* Last extent are just preallocated blocks? */ 390 /* Last extent are just preallocated blocks? */
393 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { 391 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) {
394 /* Save the extent so that we can reattach it to the end */ 392 /* Save the extent so that we can reattach it to the end */
@@ -400,10 +398,11 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
400 last_ext->extLocation.logicalBlockNum = 0; 398 last_ext->extLocation.logicalBlockNum = 0;
401 last_ext->extLocation.partitionReferenceNum = 0; 399 last_ext->extLocation.partitionReferenceNum = 0;
402 } 400 }
401
403 /* Can we merge with the previous extent? */ 402 /* Can we merge with the previous extent? */
404 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { 403 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) {
405 add = ((1<<30) - sb->s_blocksize - (last_ext->extLength & 404 add = ((1 << 30) - sb->s_blocksize - (last_ext->extLength &
406 UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; 405 UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits;
407 if (add > blocks) 406 if (add > blocks)
408 add = blocks; 407 add = blocks;
409 blocks -= add; 408 blocks -= add;
@@ -412,11 +411,12 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
412 411
413 if (fake) { 412 if (fake) {
414 udf_add_aext(inode, last_pos, last_ext->extLocation, 413 udf_add_aext(inode, last_pos, last_ext->extLocation,
415 last_ext->extLength, 1); 414 last_ext->extLength, 1);
416 count++; 415 count++;
417 } 416 } else {
418 else
419 udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); 417 udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1);
418 }
419
420 /* Managed to do everything necessary? */ 420 /* Managed to do everything necessary? */
421 if (!blocks) 421 if (!blocks)
422 goto out; 422 goto out;
@@ -426,11 +426,12 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
426 last_ext->extLocation.partitionReferenceNum = 0; 426 last_ext->extLocation.partitionReferenceNum = 0;
427 add = (1 << (30-sb->s_blocksize_bits)) - 1; 427 add = (1 << (30-sb->s_blocksize_bits)) - 1;
428 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); 428 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
429
429 /* Create enough extents to cover the whole hole */ 430 /* Create enough extents to cover the whole hole */
430 while (blocks > add) { 431 while (blocks > add) {
431 blocks -= add; 432 blocks -= add;
432 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 433 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
433 last_ext->extLength, 1) == -1) 434 last_ext->extLength, 1) == -1)
434 return -1; 435 return -1;
435 count++; 436 count++;
436 } 437 }
@@ -438,10 +439,11 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
438 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 439 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
439 (blocks << sb->s_blocksize_bits); 440 (blocks << sb->s_blocksize_bits);
440 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 441 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
441 last_ext->extLength, 1) == -1) 442 last_ext->extLength, 1) == -1)
442 return -1; 443 return -1;
443 count++; 444 count++;
444 } 445 }
446
445out: 447out:
446 /* Do we have some preallocated blocks saved? */ 448 /* Do we have some preallocated blocks saved? */
447 if (prealloc_len) { 449 if (prealloc_len) {
@@ -451,6 +453,7 @@ out:
451 last_ext->extLength = prealloc_len; 453 last_ext->extLength = prealloc_len;
452 count++; 454 count++;
453 } 455 }
456
454 /* last_pos should point to the last written extent... */ 457 /* last_pos should point to the last written extent... */
455 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) 458 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
456 last_pos->offset -= sizeof(short_ad); 459 last_pos->offset -= sizeof(short_ad);
@@ -458,11 +461,12 @@ out:
458 last_pos->offset -= sizeof(long_ad); 461 last_pos->offset -= sizeof(long_ad);
459 else 462 else
460 return -1; 463 return -1;
464
461 return count; 465 return count;
462} 466}
463 467
464static struct buffer_head * inode_getblk(struct inode * inode, sector_t block, 468static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
465 int *err, long *phys, int *new) 469 int *err, long *phys, int *new)
466{ 470{
467 static sector_t last_block; 471 static sector_t last_block;
468 struct buffer_head *result = NULL; 472 struct buffer_head *result = NULL;
@@ -486,18 +490,15 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
486 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; 490 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
487 491
488 /* find the extent which contains the block we are looking for. 492 /* find the extent which contains the block we are looking for.
489 alternate between laarr[0] and laarr[1] for locations of the 493 alternate between laarr[0] and laarr[1] for locations of the
490 current extent, and the previous extent */ 494 current extent, and the previous extent */
491 do 495 do {
492 { 496 if (prev_epos.bh != cur_epos.bh) {
493 if (prev_epos.bh != cur_epos.bh)
494 {
495 brelse(prev_epos.bh); 497 brelse(prev_epos.bh);
496 get_bh(cur_epos.bh); 498 get_bh(cur_epos.bh);
497 prev_epos.bh = cur_epos.bh; 499 prev_epos.bh = cur_epos.bh;
498 } 500 }
499 if (cur_epos.bh != next_epos.bh) 501 if (cur_epos.bh != next_epos.bh) {
500 {
501 brelse(cur_epos.bh); 502 brelse(cur_epos.bh);
502 get_bh(next_epos.bh); 503 get_bh(next_epos.bh);
503 cur_epos.bh = next_epos.bh; 504 cur_epos.bh = next_epos.bh;
@@ -522,9 +523,9 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
522 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 523 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
523 pgoal = eloc.logicalBlockNum + 524 pgoal = eloc.logicalBlockNum +
524 ((elen + inode->i_sb->s_blocksize - 1) >> 525 ((elen + inode->i_sb->s_blocksize - 1) >>
525 inode->i_sb->s_blocksize_bits); 526 inode->i_sb->s_blocksize_bits);
526 527
527 count ++; 528 count++;
528 } while (lbcount + elen <= b_off); 529 } while (lbcount + elen <= b_off);
529 530
530 b_off -= lbcount; 531 b_off -= lbcount;
@@ -537,15 +538,13 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
537 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0); 538 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
538 539
539 /* if the extent is allocated and recorded, return the block 540 /* if the extent is allocated and recorded, return the block
540 if the extent is not a multiple of the blocksize, round up */ 541 if the extent is not a multiple of the blocksize, round up */
541 542
542 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) 543 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
543 { 544 if (elen & (inode->i_sb->s_blocksize - 1)) {
544 if (elen & (inode->i_sb->s_blocksize - 1))
545 {
546 elen = EXT_RECORDED_ALLOCATED | 545 elen = EXT_RECORDED_ALLOCATED |
547 ((elen + inode->i_sb->s_blocksize - 1) & 546 ((elen + inode->i_sb->s_blocksize - 1) &
548 ~(inode->i_sb->s_blocksize - 1)); 547 ~(inode->i_sb->s_blocksize - 1));
549 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1); 548 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
550 } 549 }
551 brelse(prev_epos.bh); 550 brelse(prev_epos.bh);
@@ -558,16 +557,14 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
558 557
559 last_block = block; 558 last_block = block;
560 /* Are we beyond EOF? */ 559 /* Are we beyond EOF? */
561 if (etype == -1) 560 if (etype == -1) {
562 {
563 int ret; 561 int ret;
564 562
565 if (count) { 563 if (count) {
566 if (c) 564 if (c)
567 laarr[0] = laarr[1]; 565 laarr[0] = laarr[1];
568 startnum = 1; 566 startnum = 1;
569 } 567 } else {
570 else {
571 /* Create a fake extent when there's not one */ 568 /* Create a fake extent when there's not one */
572 memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); 569 memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr));
573 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 570 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
@@ -597,18 +594,16 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
597 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 594 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
598 inode->i_sb->s_blocksize; 595 inode->i_sb->s_blocksize;
599 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); 596 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
600 count ++; 597 count++;
601 endnum ++; 598 endnum++;
602 } 599 }
603 endnum = c+1; 600 endnum = c + 1;
604 lastblock = 1; 601 lastblock = 1;
605 } 602 } else {
606 else {
607 endnum = startnum = ((count > 2) ? 2 : count); 603 endnum = startnum = ((count > 2) ? 2 : count);
608 604
609 /* if the current extent is in position 0, swap it with the previous */ 605 /* if the current extent is in position 0, swap it with the previous */
610 if (!c && count != 1) 606 if (!c && count != 1) {
611 {
612 laarr[2] = laarr[0]; 607 laarr[2] = laarr[0];
613 laarr[0] = laarr[1]; 608 laarr[0] = laarr[1];
614 laarr[1] = laarr[2]; 609 laarr[1] = laarr[2];
@@ -616,37 +611,33 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
616 } 611 }
617 612
618 /* if the current block is located in an extent, read the next extent */ 613 /* if the current block is located in an extent, read the next extent */
619 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) 614 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
620 { 615 laarr[c + 1].extLength = (etype << 30) | elen;
621 laarr[c+1].extLength = (etype << 30) | elen; 616 laarr[c + 1].extLocation = eloc;
622 laarr[c+1].extLocation = eloc; 617 count++;
623 count ++; 618 startnum++;
624 startnum ++; 619 endnum++;
625 endnum ++; 620 } else {
626 }
627 else {
628 lastblock = 1; 621 lastblock = 1;
629 } 622 }
630 } 623 }
631 624
632 /* if the current extent is not recorded but allocated, get the 625 /* if the current extent is not recorded but allocated, get the
633 block in the extent corresponding to the requested block */ 626 * block in the extent corresponding to the requested block */
634 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 627 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
635 newblocknum = laarr[c].extLocation.logicalBlockNum + offset; 628 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
636 else /* otherwise, allocate a new block */ 629 } else { /* otherwise, allocate a new block */
637 {
638 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) 630 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
639 goal = UDF_I_NEXT_ALLOC_GOAL(inode); 631 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
640 632
641 if (!goal) 633 if (!goal) {
642 {
643 if (!(goal = pgoal)) 634 if (!(goal = pgoal))
644 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1; 635 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
645 } 636 }
646 637
647 if (!(newblocknum = udf_new_block(inode->i_sb, inode, 638 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
648 UDF_I_LOCATION(inode).partitionReferenceNum, goal, err))) 639 UDF_I_LOCATION(inode).partitionReferenceNum,
649 { 640 goal, err))) {
650 brelse(prev_epos.bh); 641 brelse(prev_epos.bh);
651 *err = -ENOSPC; 642 *err = -ENOSPC;
652 return NULL; 643 return NULL;
@@ -655,8 +646,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
655 } 646 }
656 647
657 /* if the extent the requsted block is located in contains multiple blocks, 648 /* if the extent the requsted block is located in contains multiple blocks,
658 split the extent into at most three extents. blocks prior to requested 649 * split the extent into at most three extents. blocks prior to requested
659 block, requested block, and blocks after requested block */ 650 * block, requested block, and blocks after requested block */
660 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); 651 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
661 652
662#ifdef UDF_PREALLOCATE 653#ifdef UDF_PREALLOCATE
@@ -668,15 +659,14 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
668 udf_merge_extents(inode, laarr, &endnum); 659 udf_merge_extents(inode, laarr, &endnum);
669 660
670 /* write back the new extents, inserting new extents if the new number 661 /* write back the new extents, inserting new extents if the new number
671 of extents is greater than the old number, and deleting extents if 662 * of extents is greater than the old number, and deleting extents if
672 the new number of extents is less than the old number */ 663 * the new number of extents is less than the old number */
673 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); 664 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
674 665
675 brelse(prev_epos.bh); 666 brelse(prev_epos.bh);
676 667
677 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, 668 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
678 UDF_I_LOCATION(inode).partitionReferenceNum, 0))) 669 UDF_I_LOCATION(inode).partitionReferenceNum, 0))) {
679 {
680 return NULL; 670 return NULL;
681 } 671 }
682 *phys = newblock; 672 *phys = newblock;
@@ -690,156 +680,139 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
690 udf_sync_inode(inode); 680 udf_sync_inode(inode);
691 else 681 else
692 mark_inode_dirty(inode); 682 mark_inode_dirty(inode);
683
693 return result; 684 return result;
694} 685}
695 686
696static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum, 687static void udf_split_extents(struct inode *inode, int *c, int offset,
697 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 688 int newblocknum,
689 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
690 int *endnum)
698{ 691{
699 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || 692 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
700 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 693 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
701 {
702 int curr = *c; 694 int curr = *c;
703 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + 695 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
704 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 696 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
705 int8_t etype = (laarr[curr].extLength >> 30); 697 int8_t etype = (laarr[curr].extLength >> 30);
706 698
707 if (blen == 1) 699 if (blen == 1) {
708 ; 700 ;
709 else if (!offset || blen == offset + 1) 701 } else if (!offset || blen == offset + 1) {
710 { 702 laarr[curr + 2] = laarr[curr + 1];
711 laarr[curr+2] = laarr[curr+1]; 703 laarr[curr + 1] = laarr[curr];
712 laarr[curr+1] = laarr[curr]; 704 } else {
713 } 705 laarr[curr + 3] = laarr[curr + 1];
714 else 706 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
715 {
716 laarr[curr+3] = laarr[curr+1];
717 laarr[curr+2] = laarr[curr+1] = laarr[curr];
718 } 707 }
719 708
720 if (offset) 709 if (offset) {
721 { 710 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
722 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
723 {
724 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); 711 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
725 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 712 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
726 (offset << inode->i_sb->s_blocksize_bits); 713 (offset << inode->i_sb->s_blocksize_bits);
727 laarr[curr].extLocation.logicalBlockNum = 0; 714 laarr[curr].extLocation.logicalBlockNum = 0;
728 laarr[curr].extLocation.partitionReferenceNum = 0; 715 laarr[curr].extLocation.partitionReferenceNum = 0;
729 } 716 } else {
730 else
731 laarr[curr].extLength = (etype << 30) | 717 laarr[curr].extLength = (etype << 30) |
732 (offset << inode->i_sb->s_blocksize_bits); 718 (offset << inode->i_sb->s_blocksize_bits);
733 curr ++; 719 }
734 (*c) ++; 720 curr++;
735 (*endnum) ++; 721 (*c)++;
722 (*endnum)++;
736 } 723 }
737 724
738 laarr[curr].extLocation.logicalBlockNum = newblocknum; 725 laarr[curr].extLocation.logicalBlockNum = newblocknum;
739 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 726 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
740 laarr[curr].extLocation.partitionReferenceNum = 727 laarr[curr].extLocation.partitionReferenceNum =
741 UDF_I_LOCATION(inode).partitionReferenceNum; 728 UDF_I_LOCATION(inode).partitionReferenceNum;
742 laarr[curr].extLength = EXT_RECORDED_ALLOCATED | 729 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
743 inode->i_sb->s_blocksize; 730 inode->i_sb->s_blocksize;
744 curr ++; 731 curr++;
745 732
746 if (blen != offset + 1) 733 if (blen != offset + 1) {
747 {
748 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 734 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
749 laarr[curr].extLocation.logicalBlockNum += (offset + 1); 735 laarr[curr].extLocation.logicalBlockNum += (offset + 1);
750 laarr[curr].extLength = (etype << 30) | 736 laarr[curr].extLength = (etype << 30) |
751 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); 737 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
752 curr ++; 738 curr++;
753 (*endnum) ++; 739 (*endnum)++;
754 } 740 }
755 } 741 }
756} 742}
757 743
758static void udf_prealloc_extents(struct inode *inode, int c, int lastblock, 744static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
759 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 745 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
746 int *endnum)
760{ 747{
761 int start, length = 0, currlength = 0, i; 748 int start, length = 0, currlength = 0, i;
762 749
763 if (*endnum >= (c+1)) 750 if (*endnum >= (c + 1)) {
764 {
765 if (!lastblock) 751 if (!lastblock)
766 return; 752 return;
767 else 753 else
768 start = c; 754 start = c;
769 } 755 } else {
770 else 756 if ((laarr[c + 1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
771 { 757 start = c + 1;
772 if ((laarr[c+1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 758 length = currlength = (((laarr[c + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
773 { 759 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
774 start = c+1; 760 } else {
775 length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) +
776 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
777 }
778 else
779 start = c; 761 start = c;
762 }
780 } 763 }
781 764
782 for (i=start+1; i<=*endnum; i++) 765 for (i = start + 1; i <= *endnum; i++) {
783 { 766 if (i == *endnum) {
784 if (i == *endnum)
785 {
786 if (lastblock) 767 if (lastblock)
787 length += UDF_DEFAULT_PREALLOC_BLOCKS; 768 length += UDF_DEFAULT_PREALLOC_BLOCKS;
788 } 769 } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
789 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
790 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 770 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
791 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 771 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
792 else 772 } else {
793 break; 773 break;
774 }
794 } 775 }
795 776
796 if (length) 777 if (length) {
797 {
798 int next = laarr[start].extLocation.logicalBlockNum + 778 int next = laarr[start].extLocation.logicalBlockNum +
799 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + 779 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
800 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 780 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
801 int numalloc = udf_prealloc_blocks(inode->i_sb, inode, 781 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
802 laarr[start].extLocation.partitionReferenceNum, 782 laarr[start].extLocation.partitionReferenceNum,
803 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length : 783 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
804 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength); 784 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
805 785 if (numalloc) {
806 if (numalloc) 786 if (start == (c + 1)) {
807 {
808 if (start == (c+1))
809 laarr[start].extLength += 787 laarr[start].extLength +=
810 (numalloc << inode->i_sb->s_blocksize_bits); 788 (numalloc << inode->i_sb->s_blocksize_bits);
811 else 789 } else {
812 { 790 memmove(&laarr[c + 2], &laarr[c + 1],
813 memmove(&laarr[c+2], &laarr[c+1], 791 sizeof(long_ad) * (*endnum - (c + 1)));
814 sizeof(long_ad) * (*endnum - (c+1))); 792 (*endnum)++;
815 (*endnum) ++; 793 laarr[c + 1].extLocation.logicalBlockNum = next;
816 laarr[c+1].extLocation.logicalBlockNum = next; 794 laarr[c + 1].extLocation.partitionReferenceNum =
817 laarr[c+1].extLocation.partitionReferenceNum =
818 laarr[c].extLocation.partitionReferenceNum; 795 laarr[c].extLocation.partitionReferenceNum;
819 laarr[c+1].extLength = EXT_NOT_RECORDED_ALLOCATED | 796 laarr[c + 1].extLength = EXT_NOT_RECORDED_ALLOCATED |
820 (numalloc << inode->i_sb->s_blocksize_bits); 797 (numalloc << inode->i_sb->s_blocksize_bits);
821 start = c+1; 798 start = c + 1;
822 } 799 }
823 800
824 for (i=start+1; numalloc && i<*endnum; i++) 801 for (i = start + 1; numalloc && i < *endnum; i++) {
825 {
826 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 802 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
827 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 803 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
828 804
829 if (elen > numalloc) 805 if (elen > numalloc) {
830 {
831 laarr[i].extLength -= 806 laarr[i].extLength -=
832 (numalloc << inode->i_sb->s_blocksize_bits); 807 (numalloc << inode->i_sb->s_blocksize_bits);
833 numalloc = 0; 808 numalloc = 0;
834 } 809 } else {
835 else
836 {
837 numalloc -= elen; 810 numalloc -= elen;
838 if (*endnum > (i+1)) 811 if (*endnum > (i + 1))
839 memmove(&laarr[i], &laarr[i+1], 812 memmove(&laarr[i], &laarr[i + 1],
840 sizeof(long_ad) * (*endnum - (i+1))); 813 sizeof(long_ad) * (*endnum - (i + 1)));
841 i --; 814 i--;
842 (*endnum) --; 815 (*endnum)--;
843 } 816 }
844 } 817 }
845 UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits; 818 UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits;
@@ -848,82 +821,70 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
848} 821}
849 822
850static void udf_merge_extents(struct inode *inode, 823static void udf_merge_extents(struct inode *inode,
851 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 824 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
825 int *endnum)
852{ 826{
853 int i; 827 int i;
854 828
855 for (i=0; i<(*endnum-1); i++) 829 for (i = 0; i < (*endnum - 1); i++) {
856 { 830 if ((laarr[i].extLength >> 30) == (laarr[i + 1].extLength >> 30)) {
857 if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30))
858 {
859 if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || 831 if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
860 ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) == 832 ((laarr[i + 1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
861 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 833 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
862 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) 834 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) {
863 {
864 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 835 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
865 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 836 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
866 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 837 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
867 { 838 laarr[i + 1].extLength = (laarr[i + 1].extLength -
868 laarr[i+1].extLength = (laarr[i+1].extLength - 839 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
869 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 840 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
870 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
871 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 841 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
872 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 842 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
873 laarr[i+1].extLocation.logicalBlockNum = 843 laarr[i + 1].extLocation.logicalBlockNum =
874 laarr[i].extLocation.logicalBlockNum + 844 laarr[i].extLocation.logicalBlockNum +
875 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >> 845 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >>
876 inode->i_sb->s_blocksize_bits); 846 inode->i_sb->s_blocksize_bits);
877 } 847 } else {
878 else 848 laarr[i].extLength = laarr[i + 1].extLength +
879 {
880 laarr[i].extLength = laarr[i+1].extLength +
881 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 849 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
882 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 850 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
883 if (*endnum > (i+2)) 851 if (*endnum > (i + 2))
884 memmove(&laarr[i+1], &laarr[i+2], 852 memmove(&laarr[i + 1], &laarr[i + 2],
885 sizeof(long_ad) * (*endnum - (i+2))); 853 sizeof(long_ad) * (*endnum - (i + 2)));
886 i --; 854 i--;
887 (*endnum) --; 855 (*endnum)--;
888 } 856 }
889 } 857 }
890 } 858 } else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
891 else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) && 859 ((laarr[i + 1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
892 ((laarr[i+1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)))
893 {
894 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, 860 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
895 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 861 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
896 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 862 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
897 laarr[i].extLocation.logicalBlockNum = 0; 863 laarr[i].extLocation.logicalBlockNum = 0;
898 laarr[i].extLocation.partitionReferenceNum = 0; 864 laarr[i].extLocation.partitionReferenceNum = 0;
899 865
900 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 866 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
901 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 867 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
902 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 868 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
903 { 869 laarr[i + 1].extLength = (laarr[i + 1].extLength -
904 laarr[i+1].extLength = (laarr[i+1].extLength - 870 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
905 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 871 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
906 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
907 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 872 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
908 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 873 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
909 } 874 } else {
910 else 875 laarr[i].extLength = laarr[i + 1].extLength +
911 {
912 laarr[i].extLength = laarr[i+1].extLength +
913 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 876 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
914 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 877 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
915 if (*endnum > (i+2)) 878 if (*endnum > (i + 2))
916 memmove(&laarr[i+1], &laarr[i+2], 879 memmove(&laarr[i + 1], &laarr[i + 2],
917 sizeof(long_ad) * (*endnum - (i+2))); 880 sizeof(long_ad) * (*endnum - (i + 2)));
918 i --; 881 i--;
919 (*endnum) --; 882 (*endnum)--;
920 } 883 }
921 } 884 } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
922 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
923 {
924 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, 885 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
925 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 886 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
926 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 887 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
927 laarr[i].extLocation.logicalBlockNum = 0; 888 laarr[i].extLocation.logicalBlockNum = 0;
928 laarr[i].extLocation.partitionReferenceNum = 0; 889 laarr[i].extLocation.partitionReferenceNum = 0;
929 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) | 890 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) |
@@ -933,43 +894,39 @@ static void udf_merge_extents(struct inode *inode,
933} 894}
934 895
935static void udf_update_extents(struct inode *inode, 896static void udf_update_extents(struct inode *inode,
936 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum, 897 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
937 struct extent_position *epos) 898 int startnum, int endnum,
899 struct extent_position *epos)
938{ 900{
939 int start = 0, i; 901 int start = 0, i;
940 kernel_lb_addr tmploc; 902 kernel_lb_addr tmploc;
941 uint32_t tmplen; 903 uint32_t tmplen;
942 904
943 if (startnum > endnum) 905 if (startnum > endnum) {
944 { 906 for (i = 0; i < (startnum - endnum); i++)
945 for (i=0; i<(startnum-endnum); i++)
946 udf_delete_aext(inode, *epos, laarr[i].extLocation, 907 udf_delete_aext(inode, *epos, laarr[i].extLocation,
947 laarr[i].extLength); 908 laarr[i].extLength);
948 } 909 } else if (startnum < endnum) {
949 else if (startnum < endnum) 910 for (i = 0; i < (endnum - startnum); i++) {
950 {
951 for (i=0; i<(endnum-startnum); i++)
952 {
953 udf_insert_aext(inode, *epos, laarr[i].extLocation, 911 udf_insert_aext(inode, *epos, laarr[i].extLocation,
954 laarr[i].extLength); 912 laarr[i].extLength);
955 udf_next_aext(inode, epos, &laarr[i].extLocation, 913 udf_next_aext(inode, epos, &laarr[i].extLocation,
956 &laarr[i].extLength, 1); 914 &laarr[i].extLength, 1);
957 start ++; 915 start++;
958 } 916 }
959 } 917 }
960 918
961 for (i=start; i<endnum; i++) 919 for (i = start; i < endnum; i++) {
962 {
963 udf_next_aext(inode, epos, &tmploc, &tmplen, 0); 920 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
964 udf_write_aext(inode, epos, laarr[i].extLocation, 921 udf_write_aext(inode, epos, laarr[i].extLocation,
965 laarr[i].extLength, 1); 922 laarr[i].extLength, 1);
966 } 923 }
967} 924}
968 925
969struct buffer_head * udf_bread(struct inode * inode, int block, 926struct buffer_head *udf_bread(struct inode *inode, int block,
970 int create, int * err) 927 int create, int *err)
971{ 928{
972 struct buffer_head * bh = NULL; 929 struct buffer_head *bh = NULL;
973 930
974 bh = udf_getblk(inode, block, create, err); 931 bh = udf_getblk(inode, block, create, err);
975 if (!bh) 932 if (!bh)
@@ -977,65 +934,61 @@ struct buffer_head * udf_bread(struct inode * inode, int block,
977 934
978 if (buffer_uptodate(bh)) 935 if (buffer_uptodate(bh))
979 return bh; 936 return bh;
937
980 ll_rw_block(READ, 1, &bh); 938 ll_rw_block(READ, 1, &bh);
939
981 wait_on_buffer(bh); 940 wait_on_buffer(bh);
982 if (buffer_uptodate(bh)) 941 if (buffer_uptodate(bh))
983 return bh; 942 return bh;
943
984 brelse(bh); 944 brelse(bh);
985 *err = -EIO; 945 *err = -EIO;
986 return NULL; 946 return NULL;
987} 947}
988 948
989void udf_truncate(struct inode * inode) 949void udf_truncate(struct inode *inode)
990{ 950{
991 int offset; 951 int offset;
992 int err; 952 int err;
993 953
994 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 954 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
995 S_ISLNK(inode->i_mode))) 955 S_ISLNK(inode->i_mode)))
996 return; 956 return;
997 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) 957 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
998 return; 958 return;
999 959
1000 lock_kernel(); 960 lock_kernel();
1001 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 961 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1002 {
1003 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + 962 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
1004 inode->i_size)) 963 inode->i_size)) {
1005 {
1006 udf_expand_file_adinicb(inode, inode->i_size, &err); 964 udf_expand_file_adinicb(inode, inode->i_size, &err);
1007 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 965 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1008 {
1009 inode->i_size = UDF_I_LENALLOC(inode); 966 inode->i_size = UDF_I_LENALLOC(inode);
1010 unlock_kernel(); 967 unlock_kernel();
1011 return; 968 return;
1012 } 969 } else {
1013 else
1014 udf_truncate_extents(inode); 970 udf_truncate_extents(inode);
1015 } 971 }
1016 else 972 } else {
1017 {
1018 offset = inode->i_size & (inode->i_sb->s_blocksize - 1); 973 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1019 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode)); 974 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00,
975 inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode));
1020 UDF_I_LENALLOC(inode) = inode->i_size; 976 UDF_I_LENALLOC(inode) = inode->i_size;
1021 } 977 }
1022 } 978 } else {
1023 else
1024 {
1025 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block); 979 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
1026 udf_truncate_extents(inode); 980 udf_truncate_extents(inode);
1027 } 981 }
1028 982
1029 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb); 983 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1030 if (IS_SYNC(inode)) 984 if (IS_SYNC(inode))
1031 udf_sync_inode (inode); 985 udf_sync_inode(inode);
1032 else 986 else
1033 mark_inode_dirty(inode); 987 mark_inode_dirty(inode);
1034 unlock_kernel(); 988 unlock_kernel();
1035} 989}
1036 990
1037static void 991static void __udf_read_inode(struct inode *inode)
1038__udf_read_inode(struct inode *inode)
1039{ 992{
1040 struct buffer_head *bh = NULL; 993 struct buffer_head *bh = NULL;
1041 struct fileEntry *fe; 994 struct fileEntry *fe;
@@ -1054,20 +1007,17 @@ __udf_read_inode(struct inode *inode)
1054 * i_op = NULL; 1007 * i_op = NULL;
1055 */ 1008 */
1056 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident); 1009 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1057 1010 if (!bh) {
1058 if (!bh)
1059 {
1060 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", 1011 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1061 inode->i_ino); 1012 inode->i_ino);
1062 make_bad_inode(inode); 1013 make_bad_inode(inode);
1063 return; 1014 return;
1064 } 1015 }
1065 1016
1066 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && 1017 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1067 ident != TAG_IDENT_USE) 1018 ident != TAG_IDENT_USE) {
1068 {
1069 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", 1019 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1070 inode->i_ino, ident); 1020 inode->i_ino, ident);
1071 brelse(bh); 1021 brelse(bh);
1072 make_bad_inode(inode); 1022 make_bad_inode(inode);
1073 return; 1023 return;
@@ -1075,51 +1025,43 @@ __udf_read_inode(struct inode *inode)
1075 1025
1076 fe = (struct fileEntry *)bh->b_data; 1026 fe = (struct fileEntry *)bh->b_data;
1077 1027
1078 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) 1028 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
1079 {
1080 struct buffer_head *ibh = NULL, *nbh = NULL; 1029 struct buffer_head *ibh = NULL, *nbh = NULL;
1081 struct indirectEntry *ie; 1030 struct indirectEntry *ie;
1082 1031
1083 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident); 1032 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
1084 if (ident == TAG_IDENT_IE) 1033 if (ident == TAG_IDENT_IE) {
1085 { 1034 if (ibh) {
1086 if (ibh)
1087 {
1088 kernel_lb_addr loc; 1035 kernel_lb_addr loc;
1089 ie = (struct indirectEntry *)ibh->b_data; 1036 ie = (struct indirectEntry *)ibh->b_data;
1090 1037
1091 loc = lelb_to_cpu(ie->indirectICB.extLocation); 1038 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1092 1039
1093 if (ie->indirectICB.extLength && 1040 if (ie->indirectICB.extLength &&
1094 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) 1041 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) {
1095 {
1096 if (ident == TAG_IDENT_FE || 1042 if (ident == TAG_IDENT_FE ||
1097 ident == TAG_IDENT_EFE) 1043 ident == TAG_IDENT_EFE) {
1098 { 1044 memcpy(&UDF_I_LOCATION(inode), &loc,
1099 memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr)); 1045 sizeof(kernel_lb_addr));
1100 brelse(bh); 1046 brelse(bh);
1101 brelse(ibh); 1047 brelse(ibh);
1102 brelse(nbh); 1048 brelse(nbh);
1103 __udf_read_inode(inode); 1049 __udf_read_inode(inode);
1104 return; 1050 return;
1105 } 1051 } else {
1106 else
1107 {
1108 brelse(nbh); 1052 brelse(nbh);
1109 brelse(ibh); 1053 brelse(ibh);
1110 } 1054 }
1111 } 1055 } else {
1112 else
1113 brelse(ibh); 1056 brelse(ibh);
1057 }
1114 } 1058 }
1115 } 1059 } else {
1116 else
1117 brelse(ibh); 1060 brelse(ibh);
1118 } 1061 }
1119 else if (le16_to_cpu(fe->icbTag.strategyType) != 4) 1062 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1120 {
1121 printk(KERN_ERR "udf: unsupported strategy type: %d\n", 1063 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1122 le16_to_cpu(fe->icbTag.strategyType)); 1064 le16_to_cpu(fe->icbTag.strategyType));
1123 brelse(bh); 1065 brelse(bh);
1124 make_bad_inode(inode); 1066 make_bad_inode(inode);
1125 return; 1067 return;
@@ -1152,87 +1094,83 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1152 UDF_I_LENALLOC(inode) = 0; 1094 UDF_I_LENALLOC(inode) = 0;
1153 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0; 1095 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
1154 UDF_I_NEXT_ALLOC_GOAL(inode) = 0; 1096 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
1155 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) 1097 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1156 {
1157 UDF_I_EFE(inode) = 1; 1098 UDF_I_EFE(inode) = 1;
1158 UDF_I_USE(inode) = 0; 1099 UDF_I_USE(inode) = 0;
1159 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); 1100 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) {
1160 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); 1101 make_bad_inode(inode);
1161 } 1102 return;
1162 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) 1103 }
1163 { 1104 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry),
1105 inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
1106 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1164 UDF_I_EFE(inode) = 0; 1107 UDF_I_EFE(inode) = 0;
1165 UDF_I_USE(inode) = 0; 1108 UDF_I_USE(inode) = 0;
1166 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); 1109 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1167 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1110 make_bad_inode(inode);
1168 } 1111 return;
1169 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1112 }
1170 { 1113 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
1114 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1115 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1171 UDF_I_EFE(inode) = 0; 1116 UDF_I_EFE(inode) = 0;
1172 UDF_I_USE(inode) = 1; 1117 UDF_I_USE(inode) = 1;
1173 UDF_I_LENALLOC(inode) = 1118 UDF_I_LENALLOC(inode) =
1174 le32_to_cpu( 1119 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs);
1175 ((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs); 1120 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) {
1176 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry), GFP_KERNEL); 1121 make_bad_inode(inode);
1177 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1122 return;
1123 }
1124 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry),
1125 inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
1178 return; 1126 return;
1179 } 1127 }
1180 1128
1181 inode->i_uid = le32_to_cpu(fe->uid); 1129 inode->i_uid = le32_to_cpu(fe->uid);
1182 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1130 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1183 UDF_FLAG_UID_IGNORE)) 1131 UDF_FLAG_UID_IGNORE))
1184 inode->i_uid = UDF_SB(inode->i_sb)->s_uid; 1132 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1185 1133
1186 inode->i_gid = le32_to_cpu(fe->gid); 1134 inode->i_gid = le32_to_cpu(fe->gid);
1187 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1135 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1188 UDF_FLAG_GID_IGNORE)) 1136 UDF_FLAG_GID_IGNORE))
1189 inode->i_gid = UDF_SB(inode->i_sb)->s_gid; 1137 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1190 1138
1191 inode->i_nlink = le16_to_cpu(fe->fileLinkCount); 1139 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1192 if (!inode->i_nlink) 1140 if (!inode->i_nlink)
1193 inode->i_nlink = 1; 1141 inode->i_nlink = 1;
1194 1142
1195 inode->i_size = le64_to_cpu(fe->informationLength); 1143 inode->i_size = le64_to_cpu(fe->informationLength);
1196 UDF_I_LENEXTENTS(inode) = inode->i_size; 1144 UDF_I_LENEXTENTS(inode) = inode->i_size;
1197 1145
1198 inode->i_mode = udf_convert_permissions(fe); 1146 inode->i_mode = udf_convert_permissions(fe);
1199 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask; 1147 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1200 1148
1201 if (UDF_I_EFE(inode) == 0) 1149 if (UDF_I_EFE(inode) == 0) {
1202 {
1203 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << 1150 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1204 (inode->i_sb->s_blocksize_bits - 9); 1151 (inode->i_sb->s_blocksize_bits - 9);
1205 1152
1206 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1153 if (udf_stamp_to_time(&convtime, &convtime_usec,
1207 lets_to_cpu(fe->accessTime)) ) 1154 lets_to_cpu(fe->accessTime))) {
1208 {
1209 inode->i_atime.tv_sec = convtime; 1155 inode->i_atime.tv_sec = convtime;
1210 inode->i_atime.tv_nsec = convtime_usec * 1000; 1156 inode->i_atime.tv_nsec = convtime_usec * 1000;
1211 } 1157 } else {
1212 else
1213 {
1214 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1158 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1215 } 1159 }
1216 1160
1217 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1161 if (udf_stamp_to_time(&convtime, &convtime_usec,
1218 lets_to_cpu(fe->modificationTime)) ) 1162 lets_to_cpu(fe->modificationTime))) {
1219 {
1220 inode->i_mtime.tv_sec = convtime; 1163 inode->i_mtime.tv_sec = convtime;
1221 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1164 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1222 } 1165 } else {
1223 else
1224 {
1225 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1166 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1226 } 1167 }
1227 1168
1228 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1169 if (udf_stamp_to_time(&convtime, &convtime_usec,
1229 lets_to_cpu(fe->attrTime)) ) 1170 lets_to_cpu(fe->attrTime))) {
1230 {
1231 inode->i_ctime.tv_sec = convtime; 1171 inode->i_ctime.tv_sec = convtime;
1232 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1172 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1233 } 1173 } else {
1234 else
1235 {
1236 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1174 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1237 } 1175 }
1238 1176
@@ -1240,53 +1178,39 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1240 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr); 1178 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1241 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs); 1179 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1242 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode); 1180 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
1243 } 1181 } else {
1244 else 1182 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1245 { 1183 (inode->i_sb->s_blocksize_bits - 9);
1246 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1247 (inode->i_sb->s_blocksize_bits - 9);
1248 1184
1249 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1185 if (udf_stamp_to_time(&convtime, &convtime_usec,
1250 lets_to_cpu(efe->accessTime)) ) 1186 lets_to_cpu(efe->accessTime))) {
1251 {
1252 inode->i_atime.tv_sec = convtime; 1187 inode->i_atime.tv_sec = convtime;
1253 inode->i_atime.tv_nsec = convtime_usec * 1000; 1188 inode->i_atime.tv_nsec = convtime_usec * 1000;
1254 } 1189 } else {
1255 else
1256 {
1257 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1190 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1258 } 1191 }
1259 1192
1260 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1193 if (udf_stamp_to_time(&convtime, &convtime_usec,
1261 lets_to_cpu(efe->modificationTime)) ) 1194 lets_to_cpu(efe->modificationTime))) {
1262 {
1263 inode->i_mtime.tv_sec = convtime; 1195 inode->i_mtime.tv_sec = convtime;
1264 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1196 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1265 } 1197 } else {
1266 else
1267 {
1268 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1198 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1269 } 1199 }
1270 1200
1271 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1201 if (udf_stamp_to_time(&convtime, &convtime_usec,
1272 lets_to_cpu(efe->createTime)) ) 1202 lets_to_cpu(efe->createTime))) {
1273 {
1274 UDF_I_CRTIME(inode).tv_sec = convtime; 1203 UDF_I_CRTIME(inode).tv_sec = convtime;
1275 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000; 1204 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
1276 } 1205 } else {
1277 else
1278 {
1279 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb); 1206 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
1280 } 1207 }
1281 1208
1282 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1209 if (udf_stamp_to_time(&convtime, &convtime_usec,
1283 lets_to_cpu(efe->attrTime)) ) 1210 lets_to_cpu(efe->attrTime))) {
1284 {
1285 inode->i_ctime.tv_sec = convtime; 1211 inode->i_ctime.tv_sec = convtime;
1286 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1212 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1287 } 1213 } else {
1288 else
1289 {
1290 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1214 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1291 } 1215 }
1292 1216
@@ -1296,86 +1220,74 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1296 offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode); 1220 offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1297 } 1221 }
1298 1222
1299 switch (fe->icbTag.fileType) 1223 switch (fe->icbTag.fileType) {
1300 { 1224 case ICBTAG_FILE_TYPE_DIRECTORY:
1301 case ICBTAG_FILE_TYPE_DIRECTORY: 1225 inode->i_op = &udf_dir_inode_operations;
1302 { 1226 inode->i_fop = &udf_dir_operations;
1303 inode->i_op = &udf_dir_inode_operations; 1227 inode->i_mode |= S_IFDIR;
1304 inode->i_fop = &udf_dir_operations; 1228 inc_nlink(inode);
1305 inode->i_mode |= S_IFDIR; 1229 break;
1306 inc_nlink(inode); 1230 case ICBTAG_FILE_TYPE_REALTIME:
1307 break; 1231 case ICBTAG_FILE_TYPE_REGULAR:
1308 } 1232 case ICBTAG_FILE_TYPE_UNDEF:
1309 case ICBTAG_FILE_TYPE_REALTIME: 1233 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1310 case ICBTAG_FILE_TYPE_REGULAR: 1234 inode->i_data.a_ops = &udf_adinicb_aops;
1311 case ICBTAG_FILE_TYPE_UNDEF: 1235 else
1312 { 1236 inode->i_data.a_ops = &udf_aops;
1313 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1237 inode->i_op = &udf_file_inode_operations;
1314 inode->i_data.a_ops = &udf_adinicb_aops; 1238 inode->i_fop = &udf_file_operations;
1315 else 1239 inode->i_mode |= S_IFREG;
1316 inode->i_data.a_ops = &udf_aops; 1240 break;
1317 inode->i_op = &udf_file_inode_operations; 1241 case ICBTAG_FILE_TYPE_BLOCK:
1318 inode->i_fop = &udf_file_operations; 1242 inode->i_mode |= S_IFBLK;
1319 inode->i_mode |= S_IFREG; 1243 break;
1320 break; 1244 case ICBTAG_FILE_TYPE_CHAR:
1321 } 1245 inode->i_mode |= S_IFCHR;
1322 case ICBTAG_FILE_TYPE_BLOCK: 1246 break;
1323 { 1247 case ICBTAG_FILE_TYPE_FIFO:
1324 inode->i_mode |= S_IFBLK; 1248 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1325 break; 1249 break;
1326 } 1250 case ICBTAG_FILE_TYPE_SOCKET:
1327 case ICBTAG_FILE_TYPE_CHAR: 1251 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1328 { 1252 break;
1329 inode->i_mode |= S_IFCHR; 1253 case ICBTAG_FILE_TYPE_SYMLINK:
1330 break; 1254 inode->i_data.a_ops = &udf_symlink_aops;
1331 } 1255 inode->i_op = &page_symlink_inode_operations;
1332 case ICBTAG_FILE_TYPE_FIFO: 1256 inode->i_mode = S_IFLNK | S_IRWXUGO;
1333 { 1257 break;
1334 init_special_inode(inode, inode->i_mode | S_IFIFO, 0); 1258 default:
1335 break; 1259 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1336 } 1260 inode->i_ino, fe->icbTag.fileType);
1337 case ICBTAG_FILE_TYPE_SOCKET: 1261 make_bad_inode(inode);
1338 { 1262 return;
1339 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1340 break;
1341 }
1342 case ICBTAG_FILE_TYPE_SYMLINK:
1343 {
1344 inode->i_data.a_ops = &udf_symlink_aops;
1345 inode->i_op = &page_symlink_inode_operations;
1346 inode->i_mode = S_IFLNK|S_IRWXUGO;
1347 break;
1348 }
1349 default:
1350 {
1351 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1352 inode->i_ino, fe->icbTag.fileType);
1353 make_bad_inode(inode);
1354 return;
1355 }
1356 } 1263 }
1357 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1264 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1358 { 1265 struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1359 struct deviceSpec *dsea = 1266 if (dsea) {
1360 (struct deviceSpec *) 1267 init_special_inode(inode, inode->i_mode,
1361 udf_get_extendedattr(inode, 12, 1); 1268 MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
1362 1269 le32_to_cpu(dsea->minorDeviceIdent)));
1363 if (dsea)
1364 {
1365 init_special_inode(inode, inode->i_mode, MKDEV(
1366 le32_to_cpu(dsea->majorDeviceIdent),
1367 le32_to_cpu(dsea->minorDeviceIdent)));
1368 /* Developer ID ??? */ 1270 /* Developer ID ??? */
1369 } 1271 } else {
1370 else
1371 {
1372 make_bad_inode(inode); 1272 make_bad_inode(inode);
1373 } 1273 }
1374 } 1274 }
1375} 1275}
1376 1276
1377static mode_t 1277static int udf_alloc_i_data(struct inode *inode, size_t size)
1378udf_convert_permissions(struct fileEntry *fe) 1278{
1279 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1280
1281 if (!UDF_I_DATA(inode)) {
1282 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n",
1283 inode->i_ino);
1284 return -ENOMEM;
1285 }
1286
1287 return 0;
1288}
1289
1290static mode_t udf_convert_permissions(struct fileEntry *fe)
1379{ 1291{
1380 mode_t mode; 1292 mode_t mode;
1381 uint32_t permissions; 1293 uint32_t permissions;
@@ -1409,22 +1321,23 @@ udf_convert_permissions(struct fileEntry *fe)
1409 * Written, tested, and released. 1321 * Written, tested, and released.
1410 */ 1322 */
1411 1323
1412int udf_write_inode(struct inode * inode, int sync) 1324int udf_write_inode(struct inode *inode, int sync)
1413{ 1325{
1414 int ret; 1326 int ret;
1327
1415 lock_kernel(); 1328 lock_kernel();
1416 ret = udf_update_inode(inode, sync); 1329 ret = udf_update_inode(inode, sync);
1417 unlock_kernel(); 1330 unlock_kernel();
1331
1418 return ret; 1332 return ret;
1419} 1333}
1420 1334
1421int udf_sync_inode(struct inode * inode) 1335int udf_sync_inode(struct inode *inode)
1422{ 1336{
1423 return udf_update_inode(inode, 1); 1337 return udf_update_inode(inode, 1);
1424} 1338}
1425 1339
1426static int 1340static int udf_update_inode(struct inode *inode, int do_sync)
1427udf_update_inode(struct inode *inode, int do_sync)
1428{ 1341{
1429 struct buffer_head *bh = NULL; 1342 struct buffer_head *bh = NULL;
1430 struct fileEntry *fe; 1343 struct fileEntry *fe;
@@ -1436,11 +1349,8 @@ udf_update_inode(struct inode *inode, int do_sync)
1436 kernel_timestamp cpu_time; 1349 kernel_timestamp cpu_time;
1437 int err = 0; 1350 int err = 0;
1438 1351
1439 bh = udf_tread(inode->i_sb, 1352 bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0));
1440 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0)); 1353 if (!bh) {
1441
1442 if (!bh)
1443 {
1444 udf_debug("bread failure\n"); 1354 udf_debug("bread failure\n");
1445 return -EIO; 1355 return -EIO;
1446 } 1356 }
@@ -1450,23 +1360,23 @@ udf_update_inode(struct inode *inode, int do_sync)
1450 fe = (struct fileEntry *)bh->b_data; 1360 fe = (struct fileEntry *)bh->b_data;
1451 efe = (struct extendedFileEntry *)bh->b_data; 1361 efe = (struct extendedFileEntry *)bh->b_data;
1452 1362
1453 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1363 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1454 {
1455 struct unallocSpaceEntry *use = 1364 struct unallocSpaceEntry *use =
1456 (struct unallocSpaceEntry *)bh->b_data; 1365 (struct unallocSpaceEntry *)bh->b_data;
1457 1366
1458 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1367 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1459 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1368 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode),
1460 crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - 1369 inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
1461 sizeof(tag); 1370 crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - sizeof(tag);
1462 use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 1371 use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1463 use->descTag.descCRCLength = cpu_to_le16(crclen); 1372 use->descTag.descCRCLength = cpu_to_le16(crclen);
1464 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0)); 1373 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1465 1374
1466 use->descTag.tagChecksum = 0; 1375 use->descTag.tagChecksum = 0;
1467 for (i=0; i<16; i++) 1376 for (i = 0; i < 16; i++) {
1468 if (i != 4) 1377 if (i != 4)
1469 use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; 1378 use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i];
1379 }
1470 1380
1471 mark_buffer_dirty(bh); 1381 mark_buffer_dirty(bh);
1472 brelse(bh); 1382 brelse(bh);
@@ -1475,11 +1385,13 @@ udf_update_inode(struct inode *inode, int do_sync)
1475 1385
1476 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) 1386 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1477 fe->uid = cpu_to_le32(-1); 1387 fe->uid = cpu_to_le32(-1);
1478 else fe->uid = cpu_to_le32(inode->i_uid); 1388 else
1389 fe->uid = cpu_to_le32(inode->i_uid);
1479 1390
1480 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) 1391 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1481 fe->gid = cpu_to_le32(-1); 1392 fe->gid = cpu_to_le32(-1);
1482 else fe->gid = cpu_to_le32(inode->i_gid); 1393 else
1394 fe->gid = cpu_to_le32(inode->i_gid);
1483 1395
1484 udfperms = ((inode->i_mode & S_IRWXO) ) | 1396 udfperms = ((inode->i_mode & S_IRWXO) ) |
1485 ((inode->i_mode & S_IRWXG) << 2) | 1397 ((inode->i_mode & S_IRWXG) << 2) |
@@ -1498,23 +1410,19 @@ udf_update_inode(struct inode *inode, int do_sync)
1498 1410
1499 fe->informationLength = cpu_to_le64(inode->i_size); 1411 fe->informationLength = cpu_to_le64(inode->i_size);
1500 1412
1501 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1413 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1502 {
1503 regid *eid; 1414 regid *eid;
1504 struct deviceSpec *dsea = 1415 struct deviceSpec *dsea =
1505 (struct deviceSpec *) 1416 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1506 udf_get_extendedattr(inode, 12, 1); 1417 if (!dsea) {
1507
1508 if (!dsea)
1509 {
1510 dsea = (struct deviceSpec *) 1418 dsea = (struct deviceSpec *)
1511 udf_add_extendedattr(inode, 1419 udf_add_extendedattr(inode,
1512 sizeof(struct deviceSpec) + 1420 sizeof(struct deviceSpec) +
1513 sizeof(regid), 12, 0x3); 1421 sizeof(regid), 12, 0x3);
1514 dsea->attrType = cpu_to_le32(12); 1422 dsea->attrType = cpu_to_le32(12);
1515 dsea->attrSubtype = 1; 1423 dsea->attrSubtype = 1;
1516 dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + 1424 dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) +
1517 sizeof(regid)); 1425 sizeof(regid));
1518 dsea->impUseLength = cpu_to_le32(sizeof(regid)); 1426 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1519 } 1427 }
1520 eid = (regid *)dsea->impUse; 1428 eid = (regid *)dsea->impUse;
@@ -1526,9 +1434,9 @@ udf_update_inode(struct inode *inode, int do_sync)
1526 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode)); 1434 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1527 } 1435 }
1528 1436
1529 if (UDF_I_EFE(inode) == 0) 1437 if (UDF_I_EFE(inode) == 0) {
1530 { 1438 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1531 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1439 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1532 fe->logicalBlocksRecorded = cpu_to_le64( 1440 fe->logicalBlocksRecorded = cpu_to_le64(
1533 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1441 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1534 (inode->i_sb->s_blocksize_bits - 9)); 1442 (inode->i_sb->s_blocksize_bits - 9));
@@ -1548,31 +1456,27 @@ udf_update_inode(struct inode *inode, int do_sync)
1548 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1456 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1549 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); 1457 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1550 crclen = sizeof(struct fileEntry); 1458 crclen = sizeof(struct fileEntry);
1551 } 1459 } else {
1552 else 1460 memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode),
1553 { 1461 inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
1554 memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
1555 efe->objectSize = cpu_to_le64(inode->i_size); 1462 efe->objectSize = cpu_to_le64(inode->i_size);
1556 efe->logicalBlocksRecorded = cpu_to_le64( 1463 efe->logicalBlocksRecorded = cpu_to_le64(
1557 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1464 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1558 (inode->i_sb->s_blocksize_bits - 9)); 1465 (inode->i_sb->s_blocksize_bits - 9));
1559 1466
1560 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || 1467 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1561 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && 1468 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
1562 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) 1469 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) {
1563 {
1564 UDF_I_CRTIME(inode) = inode->i_atime; 1470 UDF_I_CRTIME(inode) = inode->i_atime;
1565 } 1471 }
1566 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || 1472 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
1567 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && 1473 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
1568 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) 1474 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) {
1569 {
1570 UDF_I_CRTIME(inode) = inode->i_mtime; 1475 UDF_I_CRTIME(inode) = inode->i_mtime;
1571 } 1476 }
1572 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || 1477 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
1573 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && 1478 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
1574 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) 1479 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) {
1575 {
1576 UDF_I_CRTIME(inode) = inode->i_ctime; 1480 UDF_I_CRTIME(inode) = inode->i_ctime;
1577 } 1481 }
1578 1482
@@ -1595,14 +1499,11 @@ udf_update_inode(struct inode *inode, int do_sync)
1595 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE); 1499 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1596 crclen = sizeof(struct extendedFileEntry); 1500 crclen = sizeof(struct extendedFileEntry);
1597 } 1501 }
1598 if (UDF_I_STRAT4096(inode)) 1502 if (UDF_I_STRAT4096(inode)) {
1599 {
1600 fe->icbTag.strategyType = cpu_to_le16(4096); 1503 fe->icbTag.strategyType = cpu_to_le16(4096);
1601 fe->icbTag.strategyParameter = cpu_to_le16(1); 1504 fe->icbTag.strategyParameter = cpu_to_le16(1);
1602 fe->icbTag.numEntries = cpu_to_le16(2); 1505 fe->icbTag.numEntries = cpu_to_le16(2);
1603 } 1506 } else {
1604 else
1605 {
1606 fe->icbTag.strategyType = cpu_to_le16(4); 1507 fe->icbTag.strategyType = cpu_to_le16(4);
1607 fe->icbTag.numEntries = cpu_to_le16(1); 1508 fe->icbTag.numEntries = cpu_to_le16(1);
1608 } 1509 }
@@ -1642,28 +1543,27 @@ udf_update_inode(struct inode *inode, int do_sync)
1642 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0)); 1543 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1643 1544
1644 fe->descTag.tagChecksum = 0; 1545 fe->descTag.tagChecksum = 0;
1645 for (i=0; i<16; i++) 1546 for (i = 0; i < 16; i++) {
1646 if (i != 4) 1547 if (i != 4)
1647 fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i]; 1548 fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i];
1549 }
1648 1550
1649 /* write the data blocks */ 1551 /* write the data blocks */
1650 mark_buffer_dirty(bh); 1552 mark_buffer_dirty(bh);
1651 if (do_sync) 1553 if (do_sync) {
1652 {
1653 sync_dirty_buffer(bh); 1554 sync_dirty_buffer(bh);
1654 if (buffer_req(bh) && !buffer_uptodate(bh)) 1555 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1655 {
1656 printk("IO error syncing udf inode [%s:%08lx]\n", 1556 printk("IO error syncing udf inode [%s:%08lx]\n",
1657 inode->i_sb->s_id, inode->i_ino); 1557 inode->i_sb->s_id, inode->i_ino);
1658 err = -EIO; 1558 err = -EIO;
1659 } 1559 }
1660 } 1560 }
1661 brelse(bh); 1561 brelse(bh);
1562
1662 return err; 1563 return err;
1663} 1564}
1664 1565
1665struct inode * 1566struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1666udf_iget(struct super_block *sb, kernel_lb_addr ino)
1667{ 1567{
1668 unsigned long block = udf_get_lb_pblock(sb, ino, 0); 1568 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1669 struct inode *inode = iget_locked(sb, block); 1569 struct inode *inode = iget_locked(sb, block);
@@ -1682,7 +1582,7 @@ udf_iget(struct super_block *sb, kernel_lb_addr ino)
1682 1582
1683 if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) { 1583 if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1684 udf_debug("block=%d, partition=%d out of range\n", 1584 udf_debug("block=%d, partition=%d out of range\n",
1685 ino.logicalBlockNum, ino.partitionReferenceNum); 1585 ino.logicalBlockNum, ino.partitionReferenceNum);
1686 make_bad_inode(inode); 1586 make_bad_inode(inode);
1687 goto out_iput; 1587 goto out_iput;
1688 } 1588 }
@@ -1694,8 +1594,8 @@ udf_iget(struct super_block *sb, kernel_lb_addr ino)
1694 return NULL; 1594 return NULL;
1695} 1595}
1696 1596
1697int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, 1597int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1698 kernel_lb_addr eloc, uint32_t elen, int inc) 1598 kernel_lb_addr eloc, uint32_t elen, int inc)
1699{ 1599{
1700 int adsize; 1600 int adsize;
1701 short_ad *sad = NULL; 1601 short_ad *sad = NULL;
@@ -1716,21 +1616,19 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1716 else 1616 else
1717 return -1; 1617 return -1;
1718 1618
1719 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) 1619 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1720 {
1721 char *sptr, *dptr; 1620 char *sptr, *dptr;
1722 struct buffer_head *nbh; 1621 struct buffer_head *nbh;
1723 int err, loffset; 1622 int err, loffset;
1724 kernel_lb_addr obloc = epos->block; 1623 kernel_lb_addr obloc = epos->block;
1725 1624
1726 if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, 1625 if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
1727 obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) 1626 obloc.partitionReferenceNum,
1728 { 1627 obloc.logicalBlockNum, &err))) {
1729 return -1; 1628 return -1;
1730 } 1629 }
1731 if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, 1630 if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1732 epos->block, 0)))) 1631 epos->block, 0)))) {
1733 {
1734 return -1; 1632 return -1;
1735 } 1633 }
1736 lock_buffer(nbh); 1634 lock_buffer(nbh);
@@ -1742,85 +1640,69 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1742 aed = (struct allocExtDesc *)(nbh->b_data); 1640 aed = (struct allocExtDesc *)(nbh->b_data);
1743 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 1641 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1744 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); 1642 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
1745 if (epos->offset + adsize > inode->i_sb->s_blocksize) 1643 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1746 {
1747 loffset = epos->offset; 1644 loffset = epos->offset;
1748 aed->lengthAllocDescs = cpu_to_le32(adsize); 1645 aed->lengthAllocDescs = cpu_to_le32(adsize);
1749 sptr = ptr - adsize; 1646 sptr = ptr - adsize;
1750 dptr = nbh->b_data + sizeof(struct allocExtDesc); 1647 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1751 memcpy(dptr, sptr, adsize); 1648 memcpy(dptr, sptr, adsize);
1752 epos->offset = sizeof(struct allocExtDesc) + adsize; 1649 epos->offset = sizeof(struct allocExtDesc) + adsize;
1753 } 1650 } else {
1754 else
1755 {
1756 loffset = epos->offset + adsize; 1651 loffset = epos->offset + adsize;
1757 aed->lengthAllocDescs = cpu_to_le32(0); 1652 aed->lengthAllocDescs = cpu_to_le32(0);
1758 sptr = ptr; 1653 sptr = ptr;
1759 epos->offset = sizeof(struct allocExtDesc); 1654 epos->offset = sizeof(struct allocExtDesc);
1760 1655
1761 if (epos->bh) 1656 if (epos->bh) {
1762 {
1763 aed = (struct allocExtDesc *)epos->bh->b_data; 1657 aed = (struct allocExtDesc *)epos->bh->b_data;
1764 aed->lengthAllocDescs = 1658 aed->lengthAllocDescs =
1765 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1659 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1766 } 1660 } else {
1767 else
1768 {
1769 UDF_I_LENALLOC(inode) += adsize; 1661 UDF_I_LENALLOC(inode) += adsize;
1770 mark_inode_dirty(inode); 1662 mark_inode_dirty(inode);
1771 } 1663 }
1772 } 1664 }
1773 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1665 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
1774 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, 1666 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1775 epos->block.logicalBlockNum, sizeof(tag)); 1667 epos->block.logicalBlockNum, sizeof(tag));
1776 else 1668 else
1777 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, 1669 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1778 epos->block.logicalBlockNum, sizeof(tag)); 1670 epos->block.logicalBlockNum, sizeof(tag));
1779 switch (UDF_I_ALLOCTYPE(inode)) 1671 switch (UDF_I_ALLOCTYPE(inode)) {
1780 { 1672 case ICBTAG_FLAG_AD_SHORT:
1781 case ICBTAG_FLAG_AD_SHORT: 1673 sad = (short_ad *)sptr;
1782 { 1674 sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1783 sad = (short_ad *)sptr; 1675 inode->i_sb->s_blocksize);
1784 sad->extLength = cpu_to_le32( 1676 sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum);
1785 EXT_NEXT_EXTENT_ALLOCDECS | 1677 break;
1786 inode->i_sb->s_blocksize); 1678 case ICBTAG_FLAG_AD_LONG:
1787 sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); 1679 lad = (long_ad *)sptr;
1788 break; 1680 lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1789 } 1681 inode->i_sb->s_blocksize);
1790 case ICBTAG_FLAG_AD_LONG: 1682 lad->extLocation = cpu_to_lelb(epos->block);
1791 { 1683 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1792 lad = (long_ad *)sptr; 1684 break;
1793 lad->extLength = cpu_to_le32(
1794 EXT_NEXT_EXTENT_ALLOCDECS |
1795 inode->i_sb->s_blocksize);
1796 lad->extLocation = cpu_to_lelb(epos->block);
1797 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1798 break;
1799 }
1800 } 1685 }
1801 if (epos->bh) 1686 if (epos->bh) {
1802 { 1687 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1803 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1688 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1804 udf_update_tag(epos->bh->b_data, loffset); 1689 udf_update_tag(epos->bh->b_data, loffset);
1805 else 1690 else
1806 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); 1691 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
1807 mark_buffer_dirty_inode(epos->bh, inode); 1692 mark_buffer_dirty_inode(epos->bh, inode);
1808 brelse(epos->bh); 1693 brelse(epos->bh);
1809 } 1694 } else {
1810 else
1811 mark_inode_dirty(inode); 1695 mark_inode_dirty(inode);
1696 }
1812 epos->bh = nbh; 1697 epos->bh = nbh;
1813 } 1698 }
1814 1699
1815 etype = udf_write_aext(inode, epos, eloc, elen, inc); 1700 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1816 1701
1817 if (!epos->bh) 1702 if (!epos->bh) {
1818 {
1819 UDF_I_LENALLOC(inode) += adsize; 1703 UDF_I_LENALLOC(inode) += adsize;
1820 mark_inode_dirty(inode); 1704 mark_inode_dirty(inode);
1821 } 1705 } else {
1822 else
1823 {
1824 aed = (struct allocExtDesc *)epos->bh->b_data; 1706 aed = (struct allocExtDesc *)epos->bh->b_data;
1825 aed->lengthAllocDescs = 1707 aed->lengthAllocDescs =
1826 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1708 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
@@ -1834,73 +1716,68 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1834 return etype; 1716 return etype;
1835} 1717}
1836 1718
1837int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, 1719int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
1838 kernel_lb_addr eloc, uint32_t elen, int inc) 1720 kernel_lb_addr eloc, uint32_t elen, int inc)
1839{ 1721{
1840 int adsize; 1722 int adsize;
1841 uint8_t *ptr; 1723 uint8_t *ptr;
1724 short_ad *sad;
1725 long_ad *lad;
1842 1726
1843 if (!epos->bh) 1727 if (!epos->bh)
1844 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1728 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1845 else 1729 else
1846 ptr = epos->bh->b_data + epos->offset; 1730 ptr = epos->bh->b_data + epos->offset;
1847 1731
1848 switch (UDF_I_ALLOCTYPE(inode)) 1732 switch (UDF_I_ALLOCTYPE(inode)) {
1849 { 1733 case ICBTAG_FLAG_AD_SHORT:
1850 case ICBTAG_FLAG_AD_SHORT: 1734 sad = (short_ad *)ptr;
1851 { 1735 sad->extLength = cpu_to_le32(elen);
1852 short_ad *sad = (short_ad *)ptr; 1736 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1853 sad->extLength = cpu_to_le32(elen); 1737 adsize = sizeof(short_ad);
1854 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum); 1738 break;
1855 adsize = sizeof(short_ad); 1739 case ICBTAG_FLAG_AD_LONG:
1856 break; 1740 lad = (long_ad *)ptr;
1857 } 1741 lad->extLength = cpu_to_le32(elen);
1858 case ICBTAG_FLAG_AD_LONG: 1742 lad->extLocation = cpu_to_lelb(eloc);
1859 { 1743 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1860 long_ad *lad = (long_ad *)ptr; 1744 adsize = sizeof(long_ad);
1861 lad->extLength = cpu_to_le32(elen); 1745 break;
1862 lad->extLocation = cpu_to_lelb(eloc); 1746 default:
1863 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1747 return -1;
1864 adsize = sizeof(long_ad);
1865 break;
1866 }
1867 default:
1868 return -1;
1869 } 1748 }
1870 1749
1871 if (epos->bh) 1750 if (epos->bh) {
1872 { 1751 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1873 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1752 UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
1874 {
1875 struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; 1753 struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data;
1876 udf_update_tag(epos->bh->b_data, 1754 udf_update_tag(epos->bh->b_data,
1877 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); 1755 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc));
1878 } 1756 }
1879 mark_buffer_dirty_inode(epos->bh, inode); 1757 mark_buffer_dirty_inode(epos->bh, inode);
1880 } 1758 } else {
1881 else
1882 mark_inode_dirty(inode); 1759 mark_inode_dirty(inode);
1760 }
1883 1761
1884 if (inc) 1762 if (inc)
1885 epos->offset += adsize; 1763 epos->offset += adsize;
1764
1886 return (elen >> 30); 1765 return (elen >> 30);
1887} 1766}
1888 1767
1889int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, 1768int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
1890 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1769 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1891{ 1770{
1892 int8_t etype; 1771 int8_t etype;
1893 1772
1894 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == 1773 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1895 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) 1774 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1896 {
1897 epos->block = *eloc; 1775 epos->block = *eloc;
1898 epos->offset = sizeof(struct allocExtDesc); 1776 epos->offset = sizeof(struct allocExtDesc);
1899 brelse(epos->bh); 1777 brelse(epos->bh);
1900 if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) 1778 if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) {
1901 {
1902 udf_debug("reading block %d failed!\n", 1779 udf_debug("reading block %d failed!\n",
1903 udf_get_lb_pblock(inode->i_sb, epos->block, 0)); 1780 udf_get_lb_pblock(inode->i_sb, epos->block, 0));
1904 return -1; 1781 return -1;
1905 } 1782 }
1906 } 1783 }
@@ -1908,68 +1785,55 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1908 return etype; 1785 return etype;
1909} 1786}
1910 1787
1911int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, 1788int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
1912 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1789 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1913{ 1790{
1914 int alen; 1791 int alen;
1915 int8_t etype; 1792 int8_t etype;
1916 uint8_t *ptr; 1793 uint8_t *ptr;
1794 short_ad *sad;
1795 long_ad *lad;
1917 1796
1918 if (!epos->bh) 1797
1919 { 1798 if (!epos->bh) {
1920 if (!epos->offset) 1799 if (!epos->offset)
1921 epos->offset = udf_file_entry_alloc_offset(inode); 1800 epos->offset = udf_file_entry_alloc_offset(inode);
1922 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1801 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1923 alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); 1802 alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1924 } 1803 } else {
1925 else
1926 {
1927 if (!epos->offset) 1804 if (!epos->offset)
1928 epos->offset = sizeof(struct allocExtDesc); 1805 epos->offset = sizeof(struct allocExtDesc);
1929 ptr = epos->bh->b_data + epos->offset; 1806 ptr = epos->bh->b_data + epos->offset;
1930 alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); 1807 alen = sizeof(struct allocExtDesc) +
1808 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs);
1931 } 1809 }
1932 1810
1933 switch (UDF_I_ALLOCTYPE(inode)) 1811 switch (UDF_I_ALLOCTYPE(inode)) {
1934 { 1812 case ICBTAG_FLAG_AD_SHORT:
1935 case ICBTAG_FLAG_AD_SHORT: 1813 if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc)))
1936 {
1937 short_ad *sad;
1938
1939 if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc)))
1940 return -1;
1941
1942 etype = le32_to_cpu(sad->extLength) >> 30;
1943 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1944 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1945 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1946 break;
1947 }
1948 case ICBTAG_FLAG_AD_LONG:
1949 {
1950 long_ad *lad;
1951
1952 if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc)))
1953 return -1;
1954
1955 etype = le32_to_cpu(lad->extLength) >> 30;
1956 *eloc = lelb_to_cpu(lad->extLocation);
1957 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1958 break;
1959 }
1960 default:
1961 {
1962 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
1963 return -1; 1814 return -1;
1964 } 1815 etype = le32_to_cpu(sad->extLength) >> 30;
1816 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1817 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1818 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1819 break;
1820 case ICBTAG_FLAG_AD_LONG:
1821 if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc)))
1822 return -1;
1823 etype = le32_to_cpu(lad->extLength) >> 30;
1824 *eloc = lelb_to_cpu(lad->extLocation);
1825 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1826 break;
1827 default:
1828 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
1829 return -1;
1965 } 1830 }
1966 1831
1967 return etype; 1832 return etype;
1968} 1833}
1969 1834
1970static int8_t 1835static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
1971udf_insert_aext(struct inode *inode, struct extent_position epos, 1836 kernel_lb_addr neloc, uint32_t nelen)
1972 kernel_lb_addr neloc, uint32_t nelen)
1973{ 1837{
1974 kernel_lb_addr oeloc; 1838 kernel_lb_addr oeloc;
1975 uint32_t oelen; 1839 uint32_t oelen;
@@ -1978,28 +1842,26 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
1978 if (epos.bh) 1842 if (epos.bh)
1979 get_bh(epos.bh); 1843 get_bh(epos.bh);
1980 1844
1981 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) 1845 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
1982 {
1983 udf_write_aext(inode, &epos, neloc, nelen, 1); 1846 udf_write_aext(inode, &epos, neloc, nelen, 1);
1984
1985 neloc = oeloc; 1847 neloc = oeloc;
1986 nelen = (etype << 30) | oelen; 1848 nelen = (etype << 30) | oelen;
1987 } 1849 }
1988 udf_add_aext(inode, &epos, neloc, nelen, 1); 1850 udf_add_aext(inode, &epos, neloc, nelen, 1);
1989 brelse(epos.bh); 1851 brelse(epos.bh);
1852
1990 return (nelen >> 30); 1853 return (nelen >> 30);
1991} 1854}
1992 1855
1993int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, 1856int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
1994 kernel_lb_addr eloc, uint32_t elen) 1857 kernel_lb_addr eloc, uint32_t elen)
1995{ 1858{
1996 struct extent_position oepos; 1859 struct extent_position oepos;
1997 int adsize; 1860 int adsize;
1998 int8_t etype; 1861 int8_t etype;
1999 struct allocExtDesc *aed; 1862 struct allocExtDesc *aed;
2000 1863
2001 if (epos.bh) 1864 if (epos.bh) {
2002 {
2003 get_bh(epos.bh); 1865 get_bh(epos.bh);
2004 get_bh(epos.bh); 1866 get_bh(epos.bh);
2005 } 1867 }
@@ -2015,11 +1877,9 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2015 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1) 1877 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2016 return -1; 1878 return -1;
2017 1879
2018 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) 1880 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2019 {
2020 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1); 1881 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2021 if (oepos.bh != epos.bh) 1882 if (oepos.bh != epos.bh) {
2022 {
2023 oepos.block = epos.block; 1883 oepos.block = epos.block;
2024 brelse(oepos.bh); 1884 brelse(oepos.bh);
2025 get_bh(epos.bh); 1885 get_bh(epos.bh);
@@ -2030,62 +1890,57 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2030 memset(&eloc, 0x00, sizeof(kernel_lb_addr)); 1890 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2031 elen = 0; 1891 elen = 0;
2032 1892
2033 if (epos.bh != oepos.bh) 1893 if (epos.bh != oepos.bh) {
2034 {
2035 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1); 1894 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2036 udf_write_aext(inode, &oepos, eloc, elen, 1); 1895 udf_write_aext(inode, &oepos, eloc, elen, 1);
2037 udf_write_aext(inode, &oepos, eloc, elen, 1); 1896 udf_write_aext(inode, &oepos, eloc, elen, 1);
2038 if (!oepos.bh) 1897 if (!oepos.bh) {
2039 {
2040 UDF_I_LENALLOC(inode) -= (adsize * 2); 1898 UDF_I_LENALLOC(inode) -= (adsize * 2);
2041 mark_inode_dirty(inode); 1899 mark_inode_dirty(inode);
2042 } 1900 } else {
2043 else
2044 {
2045 aed = (struct allocExtDesc *)oepos.bh->b_data; 1901 aed = (struct allocExtDesc *)oepos.bh->b_data;
2046 aed->lengthAllocDescs = 1902 aed->lengthAllocDescs =
2047 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize)); 1903 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2 * adsize));
2048 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1904 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2049 udf_update_tag(oepos.bh->b_data, oepos.offset - (2*adsize)); 1905 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1906 udf_update_tag(oepos.bh->b_data, oepos.offset - (2 * adsize));
2050 else 1907 else
2051 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 1908 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
2052 mark_buffer_dirty_inode(oepos.bh, inode); 1909 mark_buffer_dirty_inode(oepos.bh, inode);
2053 } 1910 }
2054 } 1911 } else {
2055 else
2056 {
2057 udf_write_aext(inode, &oepos, eloc, elen, 1); 1912 udf_write_aext(inode, &oepos, eloc, elen, 1);
2058 if (!oepos.bh) 1913 if (!oepos.bh) {
2059 {
2060 UDF_I_LENALLOC(inode) -= adsize; 1914 UDF_I_LENALLOC(inode) -= adsize;
2061 mark_inode_dirty(inode); 1915 mark_inode_dirty(inode);
2062 } 1916 } else {
2063 else
2064 {
2065 aed = (struct allocExtDesc *)oepos.bh->b_data; 1917 aed = (struct allocExtDesc *)oepos.bh->b_data;
2066 aed->lengthAllocDescs = 1918 aed->lengthAllocDescs =
2067 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); 1919 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize);
2068 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1920 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1921 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2069 udf_update_tag(oepos.bh->b_data, epos.offset - adsize); 1922 udf_update_tag(oepos.bh->b_data, epos.offset - adsize);
2070 else 1923 else
2071 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 1924 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
2072 mark_buffer_dirty_inode(oepos.bh, inode); 1925 mark_buffer_dirty_inode(oepos.bh, inode);
2073 } 1926 }
2074 } 1927 }
2075 1928
2076 brelse(epos.bh); 1929 brelse(epos.bh);
2077 brelse(oepos.bh); 1930 brelse(oepos.bh);
1931
2078 return (elen >> 30); 1932 return (elen >> 30);
2079} 1933}
2080 1934
2081int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *pos, 1935int8_t inode_bmap(struct inode * inode, sector_t block,
2082 kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset) 1936 struct extent_position * pos, kernel_lb_addr * eloc,
1937 uint32_t * elen, sector_t * offset)
2083{ 1938{
2084 loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits; 1939 loff_t lbcount = 0, bcount =
1940 (loff_t) block << inode->i_sb->s_blocksize_bits;
2085 int8_t etype; 1941 int8_t etype;
2086 1942
2087 if (block < 0) 1943 if (block < 0) {
2088 {
2089 printk(KERN_ERR "udf: inode_bmap: block < 0\n"); 1944 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2090 return -1; 1945 return -1;
2091 } 1946 }
@@ -2095,10 +1950,8 @@ int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *p
2095 pos->bh = NULL; 1950 pos->bh = NULL;
2096 *elen = 0; 1951 *elen = 0;
2097 1952
2098 do 1953 do {
2099 { 1954 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
2100 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1)
2101 {
2102 *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits; 1955 *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2103 UDF_I_LENEXTENTS(inode) = lbcount; 1956 UDF_I_LENEXTENTS(inode) = lbcount;
2104 return -1; 1957 return -1;
@@ -2116,7 +1969,7 @@ long udf_block_map(struct inode *inode, sector_t block)
2116 kernel_lb_addr eloc; 1969 kernel_lb_addr eloc;
2117 uint32_t elen; 1970 uint32_t elen;
2118 sector_t offset; 1971 sector_t offset;
2119 struct extent_position epos = { NULL, 0, { 0, 0}}; 1972 struct extent_position epos = {};
2120 int ret; 1973 int ret;
2121 1974
2122 lock_kernel(); 1975 lock_kernel();
diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c
index 084216107667..579bae71e67e 100644
--- a/fs/udf/lowlevel.c
+++ b/fs/udf/lowlevel.c
@@ -26,38 +26,33 @@
26#include <linux/udf_fs.h> 26#include <linux/udf_fs.h>
27#include "udf_sb.h" 27#include "udf_sb.h"
28 28
29unsigned int 29unsigned int udf_get_last_session(struct super_block *sb)
30udf_get_last_session(struct super_block *sb)
31{ 30{
32 struct cdrom_multisession ms_info; 31 struct cdrom_multisession ms_info;
33 unsigned int vol_desc_start; 32 unsigned int vol_desc_start;
34 struct block_device *bdev = sb->s_bdev; 33 struct block_device *bdev = sb->s_bdev;
35 int i; 34 int i;
36 35
37 vol_desc_start=0; 36 vol_desc_start = 0;
38 ms_info.addr_format=CDROM_LBA; 37 ms_info.addr_format = CDROM_LBA;
39 i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info); 38 i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long)&ms_info);
40 39
41#define WE_OBEY_THE_WRITTEN_STANDARDS 1 40#define WE_OBEY_THE_WRITTEN_STANDARDS 1
42 41
43 if (i == 0) 42 if (i == 0) {
44 {
45 udf_debug("XA disk: %s, vol_desc_start=%d\n", 43 udf_debug("XA disk: %s, vol_desc_start=%d\n",
46 (ms_info.xa_flag ? "yes" : "no"), ms_info.addr.lba); 44 (ms_info.xa_flag ? "yes" : "no"), ms_info.addr.lba);
47#if WE_OBEY_THE_WRITTEN_STANDARDS 45#if WE_OBEY_THE_WRITTEN_STANDARDS
48 if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ 46 if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
49#endif 47#endif
50 vol_desc_start = ms_info.addr.lba; 48 vol_desc_start = ms_info.addr.lba;
51 } 49 } else {
52 else
53 {
54 udf_debug("CDROMMULTISESSION not supported: rc=%d\n", i); 50 udf_debug("CDROMMULTISESSION not supported: rc=%d\n", i);
55 } 51 }
56 return vol_desc_start; 52 return vol_desc_start;
57} 53}
58 54
59unsigned long 55unsigned long udf_get_last_block(struct super_block *sb)
60udf_get_last_block(struct super_block *sb)
61{ 56{
62 struct block_device *bdev = sb->s_bdev; 57 struct block_device *bdev = sb->s_bdev;
63 unsigned long lblock = 0; 58 unsigned long lblock = 0;
diff --git a/fs/udf/misc.c b/fs/udf/misc.c
index a2b2a98ce78a..15297deb5051 100644
--- a/fs/udf/misc.c
+++ b/fs/udf/misc.c
@@ -29,8 +29,7 @@
29#include "udf_i.h" 29#include "udf_i.h"
30#include "udf_sb.h" 30#include "udf_sb.h"
31 31
32struct buffer_head * 32struct buffer_head *udf_tgetblk(struct super_block *sb, int block)
33udf_tgetblk(struct super_block *sb, int block)
34{ 33{
35 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV)) 34 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV))
36 return sb_getblk(sb, udf_fixed_to_variable(block)); 35 return sb_getblk(sb, udf_fixed_to_variable(block));
@@ -38,8 +37,7 @@ udf_tgetblk(struct super_block *sb, int block)
38 return sb_getblk(sb, block); 37 return sb_getblk(sb, block);
39} 38}
40 39
41struct buffer_head * 40struct buffer_head *udf_tread(struct super_block *sb, int block)
42udf_tread(struct super_block *sb, int block)
43{ 41{
44 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV)) 42 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV))
45 return sb_bread(sb, udf_fixed_to_variable(block)); 43 return sb_bread(sb, udf_fixed_to_variable(block));
@@ -47,9 +45,8 @@ udf_tread(struct super_block *sb, int block)
47 return sb_bread(sb, block); 45 return sb_bread(sb, block);
48} 46}
49 47
50struct genericFormat * 48struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
51udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type, 49 uint32_t type, uint8_t loc)
52 uint8_t loc)
53{ 50{
54 uint8_t *ea = NULL, *ad = NULL; 51 uint8_t *ea = NULL, *ad = NULL;
55 int offset; 52 int offset;
@@ -57,10 +54,9 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
57 int i; 54 int i;
58 55
59 ea = UDF_I_DATA(inode); 56 ea = UDF_I_DATA(inode);
60 if (UDF_I_LENEATTR(inode)) 57 if (UDF_I_LENEATTR(inode)) {
61 ad = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 58 ad = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
62 else 59 } else {
63 {
64 ad = ea; 60 ad = ea;
65 size += sizeof(struct extendedAttrHeaderDesc); 61 size += sizeof(struct extendedAttrHeaderDesc);
66 } 62 }
@@ -70,27 +66,21 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
70 66
71 /* TODO - Check for FreeEASpace */ 67 /* TODO - Check for FreeEASpace */
72 68
73 if (loc & 0x01 && offset >= size) 69 if (loc & 0x01 && offset >= size) {
74 {
75 struct extendedAttrHeaderDesc *eahd; 70 struct extendedAttrHeaderDesc *eahd;
76 eahd = (struct extendedAttrHeaderDesc *)ea; 71 eahd = (struct extendedAttrHeaderDesc *)ea;
77 72
78 if (UDF_I_LENALLOC(inode)) 73 if (UDF_I_LENALLOC(inode)) {
79 {
80 memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); 74 memmove(&ad[size], ad, UDF_I_LENALLOC(inode));
81 } 75 }
82 76
83 if (UDF_I_LENEATTR(inode)) 77 if (UDF_I_LENEATTR(inode)) {
84 {
85 /* check checksum/crc */ 78 /* check checksum/crc */
86 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || 79 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
87 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) 80 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
88 {
89 return NULL; 81 return NULL;
90 } 82 }
91 } 83 } else {
92 else
93 {
94 size -= sizeof(struct extendedAttrHeaderDesc); 84 size -= sizeof(struct extendedAttrHeaderDesc);
95 UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); 85 UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc);
96 eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); 86 eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
@@ -105,29 +95,23 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
105 } 95 }
106 96
107 offset = UDF_I_LENEATTR(inode); 97 offset = UDF_I_LENEATTR(inode);
108 if (type < 2048) 98 if (type < 2048) {
109 { 99 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
110 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode))
111 {
112 uint32_t aal = le32_to_cpu(eahd->appAttrLocation); 100 uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
113 memmove(&ea[offset - aal + size], 101 memmove(&ea[offset - aal + size],
114 &ea[aal], offset - aal); 102 &ea[aal], offset - aal);
115 offset -= aal; 103 offset -= aal;
116 eahd->appAttrLocation = cpu_to_le32(aal + size); 104 eahd->appAttrLocation = cpu_to_le32(aal + size);
117 } 105 }
118 if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) 106 if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) {
119 {
120 uint32_t ial = le32_to_cpu(eahd->impAttrLocation); 107 uint32_t ial = le32_to_cpu(eahd->impAttrLocation);
121 memmove(&ea[offset - ial + size], 108 memmove(&ea[offset - ial + size],
122 &ea[ial], offset - ial); 109 &ea[ial], offset - ial);
123 offset -= ial; 110 offset -= ial;
124 eahd->impAttrLocation = cpu_to_le32(ial + size); 111 eahd->impAttrLocation = cpu_to_le32(ial + size);
125 } 112 }
126 } 113 } else if (type < 65536) {
127 else if (type < 65536) 114 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
128 {
129 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode))
130 {
131 uint32_t aal = le32_to_cpu(eahd->appAttrLocation); 115 uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
132 memmove(&ea[offset - aal + size], 116 memmove(&ea[offset - aal + size],
133 &ea[aal], offset - aal); 117 &ea[aal], offset - aal);
@@ -138,22 +122,23 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
138 /* rewrite CRC + checksum of eahd */ 122 /* rewrite CRC + checksum of eahd */
139 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); 123 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
140 eahd->descTag.descCRCLength = cpu_to_le16(crclen); 124 eahd->descTag.descCRCLength = cpu_to_le16(crclen);
141 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + sizeof(tag), crclen, 0)); 125 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
126 sizeof(tag), crclen, 0));
142 eahd->descTag.tagChecksum = 0; 127 eahd->descTag.tagChecksum = 0;
143 for (i=0; i<16; i++) 128 for (i = 0; i < 16; i++)
144 if (i != 4) 129 if (i != 4)
145 eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; 130 eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i];
146 UDF_I_LENEATTR(inode) += size; 131 UDF_I_LENEATTR(inode) += size;
147 return (struct genericFormat *)&ea[offset]; 132 return (struct genericFormat *)&ea[offset];
148 } 133 }
149 if (loc & 0x02) 134 if (loc & 0x02) {
150 {
151 } 135 }
136
152 return NULL; 137 return NULL;
153} 138}
154 139
155struct genericFormat * 140struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
156udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype) 141 uint8_t subtype)
157{ 142{
158 struct genericFormat *gaf; 143 struct genericFormat *gaf;
159 uint8_t *ea = NULL; 144 uint8_t *ea = NULL;
@@ -161,18 +146,16 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
161 146
162 ea = UDF_I_DATA(inode); 147 ea = UDF_I_DATA(inode);
163 148
164 if (UDF_I_LENEATTR(inode)) 149 if (UDF_I_LENEATTR(inode)) {
165 {
166 struct extendedAttrHeaderDesc *eahd; 150 struct extendedAttrHeaderDesc *eahd;
167 eahd = (struct extendedAttrHeaderDesc *)ea; 151 eahd = (struct extendedAttrHeaderDesc *)ea;
168 152
169 /* check checksum/crc */ 153 /* check checksum/crc */
170 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || 154 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
171 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) 155 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
172 {
173 return NULL; 156 return NULL;
174 } 157 }
175 158
176 if (type < 2048) 159 if (type < 2048)
177 offset = sizeof(struct extendedAttrHeaderDesc); 160 offset = sizeof(struct extendedAttrHeaderDesc);
178 else if (type < 65536) 161 else if (type < 65536)
@@ -180,8 +163,7 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
180 else 163 else
181 offset = le32_to_cpu(eahd->appAttrLocation); 164 offset = le32_to_cpu(eahd->appAttrLocation);
182 165
183 while (offset < UDF_I_LENEATTR(inode)) 166 while (offset < UDF_I_LENEATTR(inode)) {
184 {
185 gaf = (struct genericFormat *)&ea[offset]; 167 gaf = (struct genericFormat *)&ea[offset];
186 if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) 168 if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype)
187 return gaf; 169 return gaf;
@@ -189,6 +171,7 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
189 offset += le32_to_cpu(gaf->attrLength); 171 offset += le32_to_cpu(gaf->attrLength);
190 } 172 }
191 } 173 }
174
192 return NULL; 175 return NULL;
193} 176}
194 177
@@ -202,8 +185,8 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
202 * July 1, 1997 - Andrew E. Mileski 185 * July 1, 1997 - Andrew E. Mileski
203 * Written, tested, and released. 186 * Written, tested, and released.
204 */ 187 */
205struct buffer_head * 188struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
206udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint16_t *ident) 189 uint32_t location, uint16_t * ident)
207{ 190{
208 tag *tag_p; 191 tag *tag_p;
209 struct buffer_head *bh = NULL; 192 struct buffer_head *bh = NULL;
@@ -215,9 +198,9 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
215 return NULL; 198 return NULL;
216 199
217 bh = udf_tread(sb, block + UDF_SB_SESSION(sb)); 200 bh = udf_tread(sb, block + UDF_SB_SESSION(sb));
218 if (!bh) 201 if (!bh) {
219 { 202 udf_debug("block=%d, location=%d: read failed\n",
220 udf_debug("block=%d, location=%d: read failed\n", block + UDF_SB_SESSION(sb), location); 203 block + UDF_SB_SESSION(sb), location);
221 return NULL; 204 return NULL;
222 } 205 }
223 206
@@ -225,13 +208,12 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
225 208
226 *ident = le16_to_cpu(tag_p->tagIdent); 209 *ident = le16_to_cpu(tag_p->tagIdent);
227 210
228 if ( location != le32_to_cpu(tag_p->tagLocation) ) 211 if (location != le32_to_cpu(tag_p->tagLocation)) {
229 {
230 udf_debug("location mismatch block %u, tag %u != %u\n", 212 udf_debug("location mismatch block %u, tag %u != %u\n",
231 block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location); 213 block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location);
232 goto error_out; 214 goto error_out;
233 } 215 }
234 216
235 /* Verify the tag checksum */ 217 /* Verify the tag checksum */
236 checksum = 0U; 218 checksum = 0U;
237 for (i = 0; i < 4; i++) 219 for (i = 0; i < 4; i++)
@@ -245,33 +227,32 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
245 227
246 /* Verify the tag version */ 228 /* Verify the tag version */
247 if (le16_to_cpu(tag_p->descVersion) != 0x0002U && 229 if (le16_to_cpu(tag_p->descVersion) != 0x0002U &&
248 le16_to_cpu(tag_p->descVersion) != 0x0003U) 230 le16_to_cpu(tag_p->descVersion) != 0x0003U) {
249 {
250 udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n", 231 udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n",
251 le16_to_cpu(tag_p->descVersion), block); 232 le16_to_cpu(tag_p->descVersion), block);
252 goto error_out; 233 goto error_out;
253 } 234 }
254 235
255 /* Verify the descriptor CRC */ 236 /* Verify the descriptor CRC */
256 if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || 237 if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
257 le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), 238 le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
258 le16_to_cpu(tag_p->descCRCLength), 0)) 239 le16_to_cpu(tag_p->descCRCLength), 0)) {
259 {
260 return bh; 240 return bh;
261 } 241 }
262 udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", 242 udf_debug("Crc failure block %d: crc = %d, crclen = %d\n",
263 block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC), le16_to_cpu(tag_p->descCRCLength)); 243 block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC),
244 le16_to_cpu(tag_p->descCRCLength));
264 245
265error_out: 246error_out:
266 brelse(bh); 247 brelse(bh);
267 return NULL; 248 return NULL;
268} 249}
269 250
270struct buffer_head * 251struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
271udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, uint32_t offset, uint16_t *ident) 252 uint32_t offset, uint16_t * ident)
272{ 253{
273 return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), 254 return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
274 loc.logicalBlockNum + offset, ident); 255 loc.logicalBlockNum + offset, ident);
275} 256}
276 257
277void udf_update_tag(char *data, int length) 258void udf_update_tag(char *data, int length)
@@ -285,13 +266,13 @@ void udf_update_tag(char *data, int length)
285 tptr->descCRCLength = cpu_to_le16(length); 266 tptr->descCRCLength = cpu_to_le16(length);
286 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); 267 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
287 268
288 for (i=0; i<16; i++) 269 for (i = 0; i < 16; i++)
289 if (i != 4) 270 if (i != 4)
290 tptr->tagChecksum += (uint8_t)(data[i]); 271 tptr->tagChecksum += (uint8_t)(data[i]);
291} 272}
292 273
293void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, 274void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
294 uint32_t loc, int length) 275 uint32_t loc, int length)
295{ 276{
296 tag *tptr = (tag *)data; 277 tag *tptr = (tag *)data;
297 tptr->tagIdent = cpu_to_le16(ident); 278 tptr->tagIdent = cpu_to_le16(ident);
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 51fe307dc0ec..bec96a6b3343 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -32,16 +32,18 @@
32#include <linux/buffer_head.h> 32#include <linux/buffer_head.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34 34
35static inline int udf_match(int len1, const char *name1, int len2, const char *name2) 35static inline int udf_match(int len1, const char *name1, int len2,
36 const char *name2)
36{ 37{
37 if (len1 != len2) 38 if (len1 != len2)
38 return 0; 39 return 0;
40
39 return !memcmp(name1, name2, len1); 41 return !memcmp(name1, name2, len1);
40} 42}
41 43
42int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, 44int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
43 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, 45 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
44 uint8_t *impuse, uint8_t *fileident) 46 uint8_t * impuse, uint8_t * fileident)
45{ 47{
46 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); 48 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
47 uint16_t crc; 49 uint16_t crc;
@@ -59,14 +61,12 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
59 61
60 offset = fibh->soffset + sizeof(struct fileIdentDesc); 62 offset = fibh->soffset + sizeof(struct fileIdentDesc);
61 63
62 if (impuse) 64 if (impuse) {
63 { 65 if (adinicb || (offset + liu < 0)) {
64 if (adinicb || (offset + liu < 0))
65 memcpy((uint8_t *)sfi->impUse, impuse, liu); 66 memcpy((uint8_t *)sfi->impUse, impuse, liu);
66 else if (offset >= 0) 67 } else if (offset >= 0) {
67 memcpy(fibh->ebh->b_data + offset, impuse, liu); 68 memcpy(fibh->ebh->b_data + offset, impuse, liu);
68 else 69 } else {
69 {
70 memcpy((uint8_t *)sfi->impUse, impuse, -offset); 70 memcpy((uint8_t *)sfi->impUse, impuse, -offset);
71 memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); 71 memcpy(fibh->ebh->b_data, impuse - offset, liu + offset);
72 } 72 }
@@ -74,14 +74,12 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
74 74
75 offset += liu; 75 offset += liu;
76 76
77 if (fileident) 77 if (fileident) {
78 { 78 if (adinicb || (offset + lfi < 0)) {
79 if (adinicb || (offset + lfi < 0))
80 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); 79 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi);
81 else if (offset >= 0) 80 } else if (offset >= 0) {
82 memcpy(fibh->ebh->b_data + offset, fileident, lfi); 81 memcpy(fibh->ebh->b_data + offset, fileident, lfi);
83 else 82 } else {
84 {
85 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); 83 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset);
86 memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); 84 memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset);
87 } 85 }
@@ -89,53 +87,50 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
89 87
90 offset += lfi; 88 offset += lfi;
91 89
92 if (adinicb || (offset + padlen < 0)) 90 if (adinicb || (offset + padlen < 0)) {
93 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); 91 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen);
94 else if (offset >= 0) 92 } else if (offset >= 0) {
95 memset(fibh->ebh->b_data + offset, 0x00, padlen); 93 memset(fibh->ebh->b_data + offset, 0x00, padlen);
96 else 94 } else {
97 {
98 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset); 95 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
99 memset(fibh->ebh->b_data, 0x00, padlen + offset); 96 memset(fibh->ebh->b_data, 0x00, padlen + offset);
100 } 97 }
101 98
102 crc = udf_crc((uint8_t *)cfi + sizeof(tag), sizeof(struct fileIdentDesc) - 99 crc = udf_crc((uint8_t *)cfi + sizeof(tag),
103 sizeof(tag), 0); 100 sizeof(struct fileIdentDesc) - sizeof(tag), 0);
104 101
105 if (fibh->sbh == fibh->ebh) 102 if (fibh->sbh == fibh->ebh) {
106 crc = udf_crc((uint8_t *)sfi->impUse, 103 crc = udf_crc((uint8_t *)sfi->impUse,
107 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 104 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc);
108 else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) 105 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
109 crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, 106 crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset,
110 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 107 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc);
111 else 108 } else {
112 {
113 crc = udf_crc((uint8_t *)sfi->impUse, 109 crc = udf_crc((uint8_t *)sfi->impUse,
114 -fibh->soffset - sizeof(struct fileIdentDesc), crc); 110 -fibh->soffset - sizeof(struct fileIdentDesc), crc);
115 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); 111 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
116 } 112 }
117 113
118 cfi->descTag.descCRC = cpu_to_le16(crc); 114 cfi->descTag.descCRC = cpu_to_le16(crc);
119 cfi->descTag.descCRCLength = cpu_to_le16(crclen); 115 cfi->descTag.descCRCLength = cpu_to_le16(crclen);
120 116
121 for (i=0; i<16; i++) 117 for (i = 0; i < 16; i++) {
122 if (i != 4) 118 if (i != 4)
123 checksum += ((uint8_t *)&cfi->descTag)[i]; 119 checksum += ((uint8_t *)&cfi->descTag)[i];
120 }
124 121
125 cfi->descTag.tagChecksum = checksum; 122 cfi->descTag.tagChecksum = checksum;
126 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) 123 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
127 memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); 124 memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc));
128 else 125 } else {
129 {
130 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); 126 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
131 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, 127 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
132 sizeof(struct fileIdentDesc) + fibh->soffset); 128 sizeof(struct fileIdentDesc) + fibh->soffset);
133 } 129 }
134 130
135 if (adinicb) 131 if (adinicb) {
136 mark_inode_dirty(inode); 132 mark_inode_dirty(inode);
137 else 133 } else {
138 {
139 if (fibh->sbh != fibh->ebh) 134 if (fibh->sbh != fibh->ebh)
140 mark_buffer_dirty_inode(fibh->ebh, inode); 135 mark_buffer_dirty_inode(fibh->ebh, inode);
141 mark_buffer_dirty_inode(fibh->sbh, inode); 136 mark_buffer_dirty_inode(fibh->sbh, inode);
@@ -143,12 +138,12 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
143 return 0; 138 return 0;
144} 139}
145 140
146static struct fileIdentDesc * 141static struct fileIdentDesc *udf_find_entry(struct inode *dir,
147udf_find_entry(struct inode *dir, struct dentry *dentry, 142 struct dentry *dentry,
148 struct udf_fileident_bh *fibh, 143 struct udf_fileident_bh *fibh,
149 struct fileIdentDesc *cfi) 144 struct fileIdentDesc *cfi)
150{ 145{
151 struct fileIdentDesc *fi=NULL; 146 struct fileIdentDesc *fi = NULL;
152 loff_t f_pos; 147 loff_t f_pos;
153 int block, flen; 148 int block, flen;
154 char fname[UDF_NAME_LEN]; 149 char fname[UDF_NAME_LEN];
@@ -159,46 +154,39 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
159 kernel_lb_addr eloc; 154 kernel_lb_addr eloc;
160 uint32_t elen; 155 uint32_t elen;
161 sector_t offset; 156 sector_t offset;
162 struct extent_position epos = { NULL, 0, { 0, 0}}; 157 struct extent_position epos = {};
163 158
164 size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 159 size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
165 f_pos = (udf_ext0_offset(dir) >> 2); 160 f_pos = (udf_ext0_offset(dir) >> 2);
166 161
167 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 162 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
168 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 163 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
169 fibh->sbh = fibh->ebh = NULL; 164 fibh->sbh = fibh->ebh = NULL;
170 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 165 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
171 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 166 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
172 {
173 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 167 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
174 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 168 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
175 {
176 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 169 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
177 epos.offset -= sizeof(short_ad); 170 epos.offset -= sizeof(short_ad);
178 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 171 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
179 epos.offset -= sizeof(long_ad); 172 epos.offset -= sizeof(long_ad);
180 } 173 } else {
181 else
182 offset = 0; 174 offset = 0;
175 }
183 176
184 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) 177 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
185 {
186 brelse(epos.bh); 178 brelse(epos.bh);
187 return NULL; 179 return NULL;
188 } 180 }
189 } 181 } else {
190 else
191 {
192 brelse(epos.bh); 182 brelse(epos.bh);
193 return NULL; 183 return NULL;
194 } 184 }
195 185
196 while ( (f_pos < size) ) 186 while ((f_pos < size)) {
197 { 187 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
198 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, &elen, &offset); 188 &elen, &offset);
199 189 if (!fi) {
200 if (!fi)
201 {
202 if (fibh->sbh != fibh->ebh) 190 if (fibh->sbh != fibh->ebh)
203 brelse(fibh->ebh); 191 brelse(fibh->ebh);
204 brelse(fibh->sbh); 192 brelse(fibh->sbh);
@@ -209,54 +197,48 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
209 liu = le16_to_cpu(cfi->lengthOfImpUse); 197 liu = le16_to_cpu(cfi->lengthOfImpUse);
210 lfi = cfi->lengthFileIdent; 198 lfi = cfi->lengthFileIdent;
211 199
212 if (fibh->sbh == fibh->ebh) 200 if (fibh->sbh == fibh->ebh) {
213 {
214 nameptr = fi->fileIdent + liu; 201 nameptr = fi->fileIdent + liu;
215 } 202 } else {
216 else
217 {
218 int poffset; /* Unpaded ending offset */ 203 int poffset; /* Unpaded ending offset */
219 204
220 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 205 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi;
221 206
222 if (poffset >= lfi) 207 if (poffset >= lfi) {
223 nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); 208 nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi);
224 else 209 } else {
225 {
226 nameptr = fname; 210 nameptr = fname;
227 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 211 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset);
228 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 212 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset);
229 } 213 }
230 } 214 }
231 215
232 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 216 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
233 { 217 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
234 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE) )
235 continue; 218 continue;
236 } 219 }
237 220
238 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0 ) 221 if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
239 { 222 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
240 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE) )
241 continue; 223 continue;
242 } 224 }
243 225
244 if (!lfi) 226 if (!lfi)
245 continue; 227 continue;
246 228
247 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) 229 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) {
248 { 230 if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) {
249 if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name))
250 {
251 brelse(epos.bh); 231 brelse(epos.bh);
252 return fi; 232 return fi;
253 } 233 }
254 } 234 }
255 } 235 }
236
256 if (fibh->sbh != fibh->ebh) 237 if (fibh->sbh != fibh->ebh)
257 brelse(fibh->ebh); 238 brelse(fibh->ebh);
258 brelse(fibh->sbh); 239 brelse(fibh->sbh);
259 brelse(epos.bh); 240 brelse(epos.bh);
241
260 return NULL; 242 return NULL;
261} 243}
262 244
@@ -293,25 +275,27 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
293 * Written, tested, and released. 275 * Written, tested, and released.
294 */ 276 */
295 277
296static struct dentry * 278static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
297udf_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 279 struct nameidata *nd)
298{ 280{
299 struct inode *inode = NULL; 281 struct inode *inode = NULL;
300 struct fileIdentDesc cfi; 282 struct fileIdentDesc cfi;
301 struct udf_fileident_bh fibh; 283 struct udf_fileident_bh fibh;
302 284
303 if (dentry->d_name.len > UDF_NAME_LEN-2) 285 if (dentry->d_name.len > UDF_NAME_LEN - 2)
304 return ERR_PTR(-ENAMETOOLONG); 286 return ERR_PTR(-ENAMETOOLONG);
305 287
306 lock_kernel(); 288 lock_kernel();
307#ifdef UDF_RECOVERY 289#ifdef UDF_RECOVERY
308 /* temporary shorthand for specifying files by inode number */ 290 /* temporary shorthand for specifying files by inode number */
309 if (!strncmp(dentry->d_name.name, ".B=", 3) ) 291 if (!strncmp(dentry->d_name.name, ".B=", 3)) {
310 { 292 kernel_lb_addr lb = {
311 kernel_lb_addr lb = { 0, simple_strtoul(dentry->d_name.name+3, NULL, 0) }; 293 .logicalBlockNum = 0,
294 .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3,
295 NULL, 0),
296 };
312 inode = udf_iget(dir->i_sb, lb); 297 inode = udf_iget(dir->i_sb, lb);
313 if (!inode) 298 if (!inode) {
314 {
315 unlock_kernel(); 299 unlock_kernel();
316 return ERR_PTR(-EACCES); 300 return ERR_PTR(-EACCES);
317 } 301 }
@@ -319,31 +303,30 @@ udf_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
319 else 303 else
320#endif /* UDF_RECOVERY */ 304#endif /* UDF_RECOVERY */
321 305
322 if (udf_find_entry(dir, dentry, &fibh, &cfi)) 306 if (udf_find_entry(dir, dentry, &fibh, &cfi)) {
323 {
324 if (fibh.sbh != fibh.ebh) 307 if (fibh.sbh != fibh.ebh)
325 brelse(fibh.ebh); 308 brelse(fibh.ebh);
326 brelse(fibh.sbh); 309 brelse(fibh.sbh);
327 310
328 inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation)); 311 inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation));
329 if ( !inode ) 312 if (!inode) {
330 {
331 unlock_kernel(); 313 unlock_kernel();
332 return ERR_PTR(-EACCES); 314 return ERR_PTR(-EACCES);
333 } 315 }
334 } 316 }
335 unlock_kernel(); 317 unlock_kernel();
336 d_add(dentry, inode); 318 d_add(dentry, inode);
319
337 return NULL; 320 return NULL;
338} 321}
339 322
340static struct fileIdentDesc * 323static struct fileIdentDesc *udf_add_entry(struct inode *dir,
341udf_add_entry(struct inode *dir, struct dentry *dentry, 324 struct dentry *dentry,
342 struct udf_fileident_bh *fibh, 325 struct udf_fileident_bh *fibh,
343 struct fileIdentDesc *cfi, int *err) 326 struct fileIdentDesc *cfi, int *err)
344{ 327{
345 struct super_block *sb; 328 struct super_block *sb;
346 struct fileIdentDesc *fi=NULL; 329 struct fileIdentDesc *fi = NULL;
347 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; 330 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN];
348 int namelen; 331 int namelen;
349 loff_t f_pos; 332 loff_t f_pos;
@@ -357,50 +340,44 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
357 kernel_lb_addr eloc; 340 kernel_lb_addr eloc;
358 uint32_t elen; 341 uint32_t elen;
359 sector_t offset; 342 sector_t offset;
360 struct extent_position epos = { NULL, 0, { 0, 0 }}; 343 struct extent_position epos = {};
361 344
362 sb = dir->i_sb; 345 sb = dir->i_sb;
363 346
364 if (dentry) 347 if (dentry) {
365 { 348 if (!dentry->d_name.len) {
366 if (!dentry->d_name.len)
367 {
368 *err = -EINVAL; 349 *err = -EINVAL;
369 return NULL; 350 return NULL;
370 } 351 }
371 352 if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name,
372 if ( !(namelen = udf_put_filename(sb, dentry->d_name.name, name, dentry->d_name.len))) 353 dentry->d_name.len))) {
373 {
374 *err = -ENAMETOOLONG; 354 *err = -ENAMETOOLONG;
375 return NULL; 355 return NULL;
376 } 356 }
377 } 357 } else {
378 else
379 namelen = 0; 358 namelen = 0;
359 }
380 360
381 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; 361 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
382 362
383 f_pos = (udf_ext0_offset(dir) >> 2); 363 f_pos = (udf_ext0_offset(dir) >> 2);
384 364
385 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 365 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
386 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 366 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
387 fibh->sbh = fibh->ebh = NULL; 367 fibh->sbh = fibh->ebh = NULL;
388 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 368 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
389 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 369 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
390 {
391 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 370 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
392 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 371 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
393 {
394 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 372 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
395 epos.offset -= sizeof(short_ad); 373 epos.offset -= sizeof(short_ad);
396 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 374 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
397 epos.offset -= sizeof(long_ad); 375 epos.offset -= sizeof(long_ad);
398 } 376 } else {
399 else
400 offset = 0; 377 offset = 0;
378 }
401 379
402 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) 380 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
403 {
404 brelse(epos.bh); 381 brelse(epos.bh);
405 *err = -EIO; 382 *err = -EIO;
406 return NULL; 383 return NULL;
@@ -408,21 +385,18 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
408 385
409 block = UDF_I_LOCATION(dir).logicalBlockNum; 386 block = UDF_I_LOCATION(dir).logicalBlockNum;
410 387
411 } 388 } else {
412 else
413 {
414 block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0); 389 block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0);
415 fibh->sbh = fibh->ebh = NULL; 390 fibh->sbh = fibh->ebh = NULL;
416 fibh->soffset = fibh->eoffset = sb->s_blocksize; 391 fibh->soffset = fibh->eoffset = sb->s_blocksize;
417 goto add; 392 goto add;
418 } 393 }
419 394
420 while ( (f_pos < size) ) 395 while ((f_pos < size)) {
421 { 396 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
422 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, &elen, &offset); 397 &elen, &offset);
423 398
424 if (!fi) 399 if (!fi) {
425 {
426 if (fibh->sbh != fibh->ebh) 400 if (fibh->sbh != fibh->ebh)
427 brelse(fibh->ebh); 401 brelse(fibh->ebh);
428 brelse(fibh->sbh); 402 brelse(fibh->sbh);
@@ -434,38 +408,33 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
434 liu = le16_to_cpu(cfi->lengthOfImpUse); 408 liu = le16_to_cpu(cfi->lengthOfImpUse);
435 lfi = cfi->lengthFileIdent; 409 lfi = cfi->lengthFileIdent;
436 410
437 if (fibh->sbh == fibh->ebh) 411 if (fibh->sbh == fibh->ebh) {
438 nameptr = fi->fileIdent + liu; 412 nameptr = fi->fileIdent + liu;
439 else 413 } else {
440 {
441 int poffset; /* Unpaded ending offset */ 414 int poffset; /* Unpaded ending offset */
442 415
443 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 416 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi;
444 417
445 if (poffset >= lfi) 418 if (poffset >= lfi) {
446 nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); 419 nameptr = (char *)(fibh->ebh->b_data + poffset - lfi);
447 else 420 } else {
448 {
449 nameptr = fname; 421 nameptr = fname;
450 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 422 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset);
451 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 423 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset);
452 } 424 }
453 } 425 }
454 426
455 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 427 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
456 { 428 if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) {
457 if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen)
458 {
459 brelse(epos.bh); 429 brelse(epos.bh);
460 cfi->descTag.tagSerialNum = cpu_to_le16(1); 430 cfi->descTag.tagSerialNum = cpu_to_le16(1);
461 cfi->fileVersionNum = cpu_to_le16(1); 431 cfi->fileVersionNum = cpu_to_le16(1);
462 cfi->fileCharacteristics = 0; 432 cfi->fileCharacteristics = 0;
463 cfi->lengthFileIdent = namelen; 433 cfi->lengthFileIdent = namelen;
464 cfi->lengthOfImpUse = cpu_to_le16(0); 434 cfi->lengthOfImpUse = cpu_to_le16(0);
465 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) 435 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
466 return fi; 436 return fi;
467 else 437 } else {
468 {
469 *err = -EIO; 438 *err = -EIO;
470 return NULL; 439 return NULL;
471 } 440 }
@@ -476,8 +445,7 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
476 continue; 445 continue;
477 446
478 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && 447 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) &&
479 udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) 448 udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) {
480 {
481 if (fibh->sbh != fibh->ebh) 449 if (fibh->sbh != fibh->ebh)
482 brelse(fibh->ebh); 450 brelse(fibh->ebh);
483 brelse(fibh->sbh); 451 brelse(fibh->sbh);
@@ -491,8 +459,7 @@ add:
491 f_pos += nfidlen; 459 f_pos += nfidlen;
492 460
493 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && 461 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB &&
494 sb->s_blocksize - fibh->eoffset < nfidlen) 462 sb->s_blocksize - fibh->eoffset < nfidlen) {
495 {
496 brelse(epos.bh); 463 brelse(epos.bh);
497 epos.bh = NULL; 464 epos.bh = NULL;
498 fibh->soffset -= udf_ext0_offset(dir); 465 fibh->soffset -= udf_ext0_offset(dir);
@@ -514,65 +481,54 @@ add:
514 epos.offset += sizeof(long_ad); 481 epos.offset += sizeof(long_ad);
515 } 482 }
516 483
517 if (sb->s_blocksize - fibh->eoffset >= nfidlen) 484 if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
518 {
519 fibh->soffset = fibh->eoffset; 485 fibh->soffset = fibh->eoffset;
520 fibh->eoffset += nfidlen; 486 fibh->eoffset += nfidlen;
521 if (fibh->sbh != fibh->ebh) 487 if (fibh->sbh != fibh->ebh) {
522 {
523 brelse(fibh->sbh); 488 brelse(fibh->sbh);
524 fibh->sbh = fibh->ebh; 489 fibh->sbh = fibh->ebh;
525 } 490 }
526 491
527 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 492 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
528 {
529 block = UDF_I_LOCATION(dir).logicalBlockNum; 493 block = UDF_I_LOCATION(dir).logicalBlockNum;
530 fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - udf_ext0_offset(dir) + UDF_I_LENEATTR(dir)); 494 fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset -
531 } 495 udf_ext0_offset(dir) +
532 else 496 UDF_I_LENEATTR(dir));
533 { 497 } else {
534 block = eloc.logicalBlockNum + ((elen - 1) >> 498 block = eloc.logicalBlockNum + ((elen - 1) >>
535 dir->i_sb->s_blocksize_bits); 499 dir->i_sb->s_blocksize_bits);
536 fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); 500 fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset);
537 } 501 }
538 } 502 } else {
539 else
540 {
541 fibh->soffset = fibh->eoffset - sb->s_blocksize; 503 fibh->soffset = fibh->eoffset - sb->s_blocksize;
542 fibh->eoffset += nfidlen - sb->s_blocksize; 504 fibh->eoffset += nfidlen - sb->s_blocksize;
543 if (fibh->sbh != fibh->ebh) 505 if (fibh->sbh != fibh->ebh) {
544 {
545 brelse(fibh->sbh); 506 brelse(fibh->sbh);
546 fibh->sbh = fibh->ebh; 507 fibh->sbh = fibh->ebh;
547 } 508 }
548 509
549 block = eloc.logicalBlockNum + ((elen - 1) >> 510 block = eloc.logicalBlockNum + ((elen - 1) >>
550 dir->i_sb->s_blocksize_bits); 511 dir->i_sb->s_blocksize_bits);
551 512 fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err);
552 if (!(fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err))) 513 if (!fibh->ebh) {
553 {
554 brelse(epos.bh); 514 brelse(epos.bh);
555 brelse(fibh->sbh); 515 brelse(fibh->sbh);
556 return NULL; 516 return NULL;
557 } 517 }
558 518
559 if (!(fibh->soffset)) 519 if (!fibh->soffset) {
560 {
561 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == 520 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
562 (EXT_RECORDED_ALLOCATED >> 30)) 521 (EXT_RECORDED_ALLOCATED >> 30)) {
563 {
564 block = eloc.logicalBlockNum + ((elen - 1) >> 522 block = eloc.logicalBlockNum + ((elen - 1) >>
565 dir->i_sb->s_blocksize_bits); 523 dir->i_sb->s_blocksize_bits);
524 } else {
525 block++;
566 } 526 }
567 else
568 block ++;
569 527
570 brelse(fibh->sbh); 528 brelse(fibh->sbh);
571 fibh->sbh = fibh->ebh; 529 fibh->sbh = fibh->ebh;
572 fi = (struct fileIdentDesc *)(fibh->sbh->b_data); 530 fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
573 } 531 } else {
574 else
575 {
576 fi = (struct fileIdentDesc *) 532 fi = (struct fileIdentDesc *)
577 (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); 533 (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset);
578 } 534 }
@@ -586,17 +542,14 @@ add:
586 cfi->fileVersionNum = cpu_to_le16(1); 542 cfi->fileVersionNum = cpu_to_le16(1);
587 cfi->lengthFileIdent = namelen; 543 cfi->lengthFileIdent = namelen;
588 cfi->lengthOfImpUse = cpu_to_le16(0); 544 cfi->lengthOfImpUse = cpu_to_le16(0);
589 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) 545 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
590 {
591 brelse(epos.bh); 546 brelse(epos.bh);
592 dir->i_size += nfidlen; 547 dir->i_size += nfidlen;
593 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 548 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
594 UDF_I_LENALLOC(dir) += nfidlen; 549 UDF_I_LENALLOC(dir) += nfidlen;
595 mark_inode_dirty(dir); 550 mark_inode_dirty(dir);
596 return fi; 551 return fi;
597 } 552 } else {
598 else
599 {
600 brelse(epos.bh); 553 brelse(epos.bh);
601 if (fibh->sbh != fibh->ebh) 554 if (fibh->sbh != fibh->ebh)
602 brelse(fibh->ebh); 555 brelse(fibh->ebh);
@@ -607,15 +560,19 @@ add:
607} 560}
608 561
609static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, 562static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
610 struct udf_fileident_bh *fibh, struct fileIdentDesc *cfi) 563 struct udf_fileident_bh *fibh,
564 struct fileIdentDesc *cfi)
611{ 565{
612 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; 566 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED;
567
613 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 568 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
614 memset(&(cfi->icb), 0x00, sizeof(long_ad)); 569 memset(&(cfi->icb), 0x00, sizeof(long_ad));
570
615 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); 571 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
616} 572}
617 573
618static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) 574static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
575 struct nameidata *nd)
619{ 576{
620 struct udf_fileident_bh fibh; 577 struct udf_fileident_bh fibh;
621 struct inode *inode; 578 struct inode *inode;
@@ -624,8 +581,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
624 581
625 lock_kernel(); 582 lock_kernel();
626 inode = udf_new_inode(dir, mode, &err); 583 inode = udf_new_inode(dir, mode, &err);
627 if (!inode) 584 if (!inode) {
628 {
629 unlock_kernel(); 585 unlock_kernel();
630 return err; 586 return err;
631 } 587 }
@@ -639,9 +595,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
639 inode->i_mode = mode; 595 inode->i_mode = mode;
640 mark_inode_dirty(inode); 596 mark_inode_dirty(inode);
641 597
642 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 598 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
643 { 599 inode->i_nlink--;
644 inode->i_nlink --;
645 mark_inode_dirty(inode); 600 mark_inode_dirty(inode);
646 iput(inode); 601 iput(inode);
647 unlock_kernel(); 602 unlock_kernel();
@@ -652,8 +607,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
652 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 607 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
653 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 608 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
654 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 609 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
655 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 610 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
656 {
657 mark_inode_dirty(dir); 611 mark_inode_dirty(dir);
658 } 612 }
659 if (fibh.sbh != fibh.ebh) 613 if (fibh.sbh != fibh.ebh)
@@ -661,12 +615,14 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
661 brelse(fibh.sbh); 615 brelse(fibh.sbh);
662 unlock_kernel(); 616 unlock_kernel();
663 d_instantiate(dentry, inode); 617 d_instantiate(dentry, inode);
618
664 return 0; 619 return 0;
665} 620}
666 621
667static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t rdev) 622static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
623 dev_t rdev)
668{ 624{
669 struct inode * inode; 625 struct inode *inode;
670 struct udf_fileident_bh fibh; 626 struct udf_fileident_bh fibh;
671 struct fileIdentDesc cfi, *fi; 627 struct fileIdentDesc cfi, *fi;
672 int err; 628 int err;
@@ -682,9 +638,8 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
682 638
683 inode->i_uid = current->fsuid; 639 inode->i_uid = current->fsuid;
684 init_special_inode(inode, mode, rdev); 640 init_special_inode(inode, mode, rdev);
685 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 641 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
686 { 642 inode->i_nlink--;
687 inode->i_nlink --;
688 mark_inode_dirty(inode); 643 mark_inode_dirty(inode);
689 iput(inode); 644 iput(inode);
690 unlock_kernel(); 645 unlock_kernel();
@@ -695,8 +650,7 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
695 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 650 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
696 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 651 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
697 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 652 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
698 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 653 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
699 {
700 mark_inode_dirty(dir); 654 mark_inode_dirty(dir);
701 } 655 }
702 mark_inode_dirty(inode); 656 mark_inode_dirty(inode);
@@ -706,21 +660,22 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
706 brelse(fibh.sbh); 660 brelse(fibh.sbh);
707 d_instantiate(dentry, inode); 661 d_instantiate(dentry, inode);
708 err = 0; 662 err = 0;
663
709out: 664out:
710 unlock_kernel(); 665 unlock_kernel();
711 return err; 666 return err;
712} 667}
713 668
714static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode) 669static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
715{ 670{
716 struct inode * inode; 671 struct inode *inode;
717 struct udf_fileident_bh fibh; 672 struct udf_fileident_bh fibh;
718 struct fileIdentDesc cfi, *fi; 673 struct fileIdentDesc cfi, *fi;
719 int err; 674 int err;
720 675
721 lock_kernel(); 676 lock_kernel();
722 err = -EMLINK; 677 err = -EMLINK;
723 if (dir->i_nlink >= (256<<sizeof(dir->i_nlink))-1) 678 if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1)
724 goto out; 679 goto out;
725 680
726 err = -EIO; 681 err = -EIO;
@@ -730,8 +685,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
730 685
731 inode->i_op = &udf_dir_inode_operations; 686 inode->i_op = &udf_dir_inode_operations;
732 inode->i_fop = &udf_dir_operations; 687 inode->i_fop = &udf_dir_operations;
733 if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) 688 if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) {
734 {
735 inode->i_nlink--; 689 inode->i_nlink--;
736 mark_inode_dirty(inode); 690 mark_inode_dirty(inode);
737 iput(inode); 691 iput(inode);
@@ -750,8 +704,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
750 inode->i_mode |= S_ISGID; 704 inode->i_mode |= S_ISGID;
751 mark_inode_dirty(inode); 705 mark_inode_dirty(inode);
752 706
753 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 707 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
754 {
755 inode->i_nlink = 0; 708 inode->i_nlink = 0;
756 mark_inode_dirty(inode); 709 mark_inode_dirty(inode);
757 iput(inode); 710 iput(inode);
@@ -770,6 +723,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
770 brelse(fibh.ebh); 723 brelse(fibh.ebh);
771 brelse(fibh.sbh); 724 brelse(fibh.sbh);
772 err = 0; 725 err = 0;
726
773out: 727out:
774 unlock_kernel(); 728 unlock_kernel();
775 return err; 729 return err;
@@ -785,47 +739,39 @@ static int empty_dir(struct inode *dir)
785 kernel_lb_addr eloc; 739 kernel_lb_addr eloc;
786 uint32_t elen; 740 uint32_t elen;
787 sector_t offset; 741 sector_t offset;
788 struct extent_position epos = { NULL, 0, { 0, 0}}; 742 struct extent_position epos = {};
789 743
790 f_pos = (udf_ext0_offset(dir) >> 2); 744 f_pos = (udf_ext0_offset(dir) >> 2);
791 745
792 fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 746 fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
793 747
794 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 748 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
795 fibh.sbh = fibh.ebh = NULL; 749 fibh.sbh = fibh.ebh = NULL;
796 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 750 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
797 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 751 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
798 {
799 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 752 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
800 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 753 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
801 {
802 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 754 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
803 epos.offset -= sizeof(short_ad); 755 epos.offset -= sizeof(short_ad);
804 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 756 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
805 epos.offset -= sizeof(long_ad); 757 epos.offset -= sizeof(long_ad);
806 } 758 } else {
807 else
808 offset = 0; 759 offset = 0;
760 }
809 761
810 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) 762 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
811 {
812 brelse(epos.bh); 763 brelse(epos.bh);
813 return 0; 764 return 0;
814 } 765 }
815 } 766 } else {
816 else
817 {
818 brelse(epos.bh); 767 brelse(epos.bh);
819 return 0; 768 return 0;
820 } 769 }
821 770
822 771 while ((f_pos < size)) {
823 while ( (f_pos < size) ) 772 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
824 { 773 &elen, &offset);
825 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset); 774 if (!fi) {
826
827 if (!fi)
828 {
829 if (fibh.sbh != fibh.ebh) 775 if (fibh.sbh != fibh.ebh)
830 brelse(fibh.ebh); 776 brelse(fibh.ebh);
831 brelse(fibh.sbh); 777 brelse(fibh.sbh);
@@ -833,8 +779,8 @@ static int empty_dir(struct inode *dir)
833 return 0; 779 return 0;
834 } 780 }
835 781
836 if (cfi.lengthFileIdent && (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) 782 if (cfi.lengthFileIdent &&
837 { 783 (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) {
838 if (fibh.sbh != fibh.ebh) 784 if (fibh.sbh != fibh.ebh)
839 brelse(fibh.ebh); 785 brelse(fibh.ebh);
840 brelse(fibh.sbh); 786 brelse(fibh.sbh);
@@ -842,17 +788,19 @@ static int empty_dir(struct inode *dir)
842 return 0; 788 return 0;
843 } 789 }
844 } 790 }
791
845 if (fibh.sbh != fibh.ebh) 792 if (fibh.sbh != fibh.ebh)
846 brelse(fibh.ebh); 793 brelse(fibh.ebh);
847 brelse(fibh.sbh); 794 brelse(fibh.sbh);
848 brelse(epos.bh); 795 brelse(epos.bh);
796
849 return 1; 797 return 1;
850} 798}
851 799
852static int udf_rmdir(struct inode * dir, struct dentry * dentry) 800static int udf_rmdir(struct inode *dir, struct dentry *dentry)
853{ 801{
854 int retval; 802 int retval;
855 struct inode * inode = dentry->d_inode; 803 struct inode *inode = dentry->d_inode;
856 struct udf_fileident_bh fibh; 804 struct udf_fileident_bh fibh;
857 struct fileIdentDesc *fi, cfi; 805 struct fileIdentDesc *fi, cfi;
858 kernel_lb_addr tloc; 806 kernel_lb_addr tloc;
@@ -875,8 +823,8 @@ static int udf_rmdir(struct inode * dir, struct dentry * dentry)
875 goto end_rmdir; 823 goto end_rmdir;
876 if (inode->i_nlink != 2) 824 if (inode->i_nlink != 2)
877 udf_warning(inode->i_sb, "udf_rmdir", 825 udf_warning(inode->i_sb, "udf_rmdir",
878 "empty directory has nlink != 2 (%d)", 826 "empty directory has nlink != 2 (%d)",
879 inode->i_nlink); 827 inode->i_nlink);
880 clear_nlink(inode); 828 clear_nlink(inode);
881 inode->i_size = 0; 829 inode->i_size = 0;
882 inode_dec_link_count(dir); 830 inode_dec_link_count(dir);
@@ -887,15 +835,16 @@ end_rmdir:
887 if (fibh.sbh != fibh.ebh) 835 if (fibh.sbh != fibh.ebh)
888 brelse(fibh.ebh); 836 brelse(fibh.ebh);
889 brelse(fibh.sbh); 837 brelse(fibh.sbh);
838
890out: 839out:
891 unlock_kernel(); 840 unlock_kernel();
892 return retval; 841 return retval;
893} 842}
894 843
895static int udf_unlink(struct inode * dir, struct dentry * dentry) 844static int udf_unlink(struct inode *dir, struct dentry *dentry)
896{ 845{
897 int retval; 846 int retval;
898 struct inode * inode = dentry->d_inode; 847 struct inode *inode = dentry->d_inode;
899 struct udf_fileident_bh fibh; 848 struct udf_fileident_bh fibh;
900 struct fileIdentDesc *fi; 849 struct fileIdentDesc *fi;
901 struct fileIdentDesc cfi; 850 struct fileIdentDesc cfi;
@@ -912,10 +861,9 @@ static int udf_unlink(struct inode * dir, struct dentry * dentry)
912 if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino) 861 if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino)
913 goto end_unlink; 862 goto end_unlink;
914 863
915 if (!inode->i_nlink) 864 if (!inode->i_nlink) {
916 {
917 udf_debug("Deleting nonexistent file (%lu), %d\n", 865 udf_debug("Deleting nonexistent file (%lu), %d\n",
918 inode->i_ino, inode->i_nlink); 866 inode->i_ino, inode->i_nlink);
919 inode->i_nlink = 1; 867 inode->i_nlink = 1;
920 } 868 }
921 retval = udf_delete_entry(dir, fi, &fibh, &cfi); 869 retval = udf_delete_entry(dir, fi, &fibh, &cfi);
@@ -931,18 +879,20 @@ end_unlink:
931 if (fibh.sbh != fibh.ebh) 879 if (fibh.sbh != fibh.ebh)
932 brelse(fibh.ebh); 880 brelse(fibh.ebh);
933 brelse(fibh.sbh); 881 brelse(fibh.sbh);
882
934out: 883out:
935 unlock_kernel(); 884 unlock_kernel();
936 return retval; 885 return retval;
937} 886}
938 887
939static int udf_symlink(struct inode * dir, struct dentry * dentry, const char * symname) 888static int udf_symlink(struct inode *dir, struct dentry *dentry,
889 const char *symname)
940{ 890{
941 struct inode * inode; 891 struct inode *inode;
942 struct pathComponent *pc; 892 struct pathComponent *pc;
943 char *compstart; 893 char *compstart;
944 struct udf_fileident_bh fibh; 894 struct udf_fileident_bh fibh;
945 struct extent_position epos = { NULL, 0, {0, 0}}; 895 struct extent_position epos = {};
946 int eoffset, elen = 0; 896 int eoffset, elen = 0;
947 struct fileIdentDesc *fi; 897 struct fileIdentDesc *fi;
948 struct fileIdentDesc cfi; 898 struct fileIdentDesc cfi;
@@ -960,14 +910,13 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
960 inode->i_data.a_ops = &udf_symlink_aops; 910 inode->i_data.a_ops = &udf_symlink_aops;
961 inode->i_op = &page_symlink_inode_operations; 911 inode->i_op = &page_symlink_inode_operations;
962 912
963 if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) 913 if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) {
964 {
965 kernel_lb_addr eloc; 914 kernel_lb_addr eloc;
966 uint32_t elen; 915 uint32_t elen;
967 916
968 block = udf_new_block(inode->i_sb, inode, 917 block = udf_new_block(inode->i_sb, inode,
969 UDF_I_LOCATION(inode).partitionReferenceNum, 918 UDF_I_LOCATION(inode).partitionReferenceNum,
970 UDF_I_LOCATION(inode).logicalBlockNum, &err); 919 UDF_I_LOCATION(inode).logicalBlockNum, &err);
971 if (!block) 920 if (!block)
972 goto out_no_entry; 921 goto out_no_entry;
973 epos.block = UDF_I_LOCATION(inode); 922 epos.block = UDF_I_LOCATION(inode);
@@ -981,7 +930,7 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
981 brelse(epos.bh); 930 brelse(epos.bh);
982 931
983 block = udf_get_pblock(inode->i_sb, block, 932 block = udf_get_pblock(inode->i_sb, block,
984 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 933 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
985 epos.bh = udf_tread(inode->i_sb, block); 934 epos.bh = udf_tread(inode->i_sb, block);
986 lock_buffer(epos.bh); 935 lock_buffer(epos.bh);
987 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); 936 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize);
@@ -989,17 +938,15 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
989 unlock_buffer(epos.bh); 938 unlock_buffer(epos.bh);
990 mark_buffer_dirty_inode(epos.bh, inode); 939 mark_buffer_dirty_inode(epos.bh, inode);
991 ea = epos.bh->b_data + udf_ext0_offset(inode); 940 ea = epos.bh->b_data + udf_ext0_offset(inode);
992 } 941 } else {
993 else
994 ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 942 ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
943 }
995 944
996 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); 945 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode);
997 pc = (struct pathComponent *)ea; 946 pc = (struct pathComponent *)ea;
998 947
999 if (*symname == '/') 948 if (*symname == '/') {
1000 { 949 do {
1001 do
1002 {
1003 symname++; 950 symname++;
1004 } while (*symname == '/'); 951 } while (*symname == '/');
1005 952
@@ -1012,8 +959,7 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1012 959
1013 err = -ENAMETOOLONG; 960 err = -ENAMETOOLONG;
1014 961
1015 while (*symname) 962 while (*symname) {
1016 {
1017 if (elen + sizeof(struct pathComponent) > eoffset) 963 if (elen + sizeof(struct pathComponent) > eoffset)
1018 goto out_no_entry; 964 goto out_no_entry;
1019 965
@@ -1021,25 +967,24 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1021 967
1022 compstart = (char *)symname; 968 compstart = (char *)symname;
1023 969
1024 do 970 do {
1025 {
1026 symname++; 971 symname++;
1027 } while (*symname && *symname != '/'); 972 } while (*symname && *symname != '/');
1028 973
1029 pc->componentType = 5; 974 pc->componentType = 5;
1030 pc->lengthComponentIdent = 0; 975 pc->lengthComponentIdent = 0;
1031 pc->componentFileVersionNum = 0; 976 pc->componentFileVersionNum = 0;
1032 if (compstart[0] == '.') 977 if (compstart[0] == '.') {
1033 { 978 if ((symname - compstart) == 1)
1034 if ((symname-compstart) == 1)
1035 pc->componentType = 4; 979 pc->componentType = 4;
1036 else if ((symname-compstart) == 2 && compstart[1] == '.') 980 else if ((symname - compstart) == 2 && compstart[1] == '.')
1037 pc->componentType = 3; 981 pc->componentType = 3;
1038 } 982 }
1039 983
1040 if (pc->componentType == 5) 984 if (pc->componentType == 5) {
1041 { 985 namelen = udf_put_filename(inode->i_sb, compstart, name,
1042 if ( !(namelen = udf_put_filename(inode->i_sb, compstart, name, symname-compstart))) 986 symname - compstart);
987 if (!namelen)
1043 goto out_no_entry; 988 goto out_no_entry;
1044 989
1045 if (elen + sizeof(struct pathComponent) + namelen > eoffset) 990 if (elen + sizeof(struct pathComponent) + namelen > eoffset)
@@ -1052,10 +997,8 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1052 997
1053 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; 998 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
1054 999
1055 if (*symname) 1000 if (*symname) {
1056 { 1001 do {
1057 do
1058 {
1059 symname++; 1002 symname++;
1060 } while (*symname == '/'); 1003 } while (*symname == '/');
1061 } 1004 }
@@ -1071,8 +1014,7 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1071 goto out_no_entry; 1014 goto out_no_entry;
1072 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1015 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1073 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1016 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
1074 if (UDF_SB_LVIDBH(inode->i_sb)) 1017 if (UDF_SB_LVIDBH(inode->i_sb)) {
1075 {
1076 struct logicalVolHeaderDesc *lvhd; 1018 struct logicalVolHeaderDesc *lvhd;
1077 uint64_t uniqueID; 1019 uint64_t uniqueID;
1078 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1020 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);
@@ -1085,8 +1027,7 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1085 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1027 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
1086 } 1028 }
1087 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1029 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1088 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 1030 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
1089 {
1090 mark_inode_dirty(dir); 1031 mark_inode_dirty(dir);
1091 } 1032 }
1092 if (fibh.sbh != fibh.ebh) 1033 if (fibh.sbh != fibh.ebh)
@@ -1105,8 +1046,8 @@ out_no_entry:
1105 goto out; 1046 goto out;
1106} 1047}
1107 1048
1108static int udf_link(struct dentry * old_dentry, struct inode * dir, 1049static int udf_link(struct dentry *old_dentry, struct inode *dir,
1109 struct dentry *dentry) 1050 struct dentry *dentry)
1110{ 1051{
1111 struct inode *inode = old_dentry->d_inode; 1052 struct inode *inode = old_dentry->d_inode;
1112 struct udf_fileident_bh fibh; 1053 struct udf_fileident_bh fibh;
@@ -1114,21 +1055,18 @@ static int udf_link(struct dentry * old_dentry, struct inode * dir,
1114 int err; 1055 int err;
1115 1056
1116 lock_kernel(); 1057 lock_kernel();
1117 if (inode->i_nlink >= (256<<sizeof(inode->i_nlink))-1) 1058 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
1118 {
1119 unlock_kernel(); 1059 unlock_kernel();
1120 return -EMLINK; 1060 return -EMLINK;
1121 } 1061 }
1122 1062
1123 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 1063 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
1124 {
1125 unlock_kernel(); 1064 unlock_kernel();
1126 return err; 1065 return err;
1127 } 1066 }
1128 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1067 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1129 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1068 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
1130 if (UDF_SB_LVIDBH(inode->i_sb)) 1069 if (UDF_SB_LVIDBH(inode->i_sb)) {
1131 {
1132 struct logicalVolHeaderDesc *lvhd; 1070 struct logicalVolHeaderDesc *lvhd;
1133 uint64_t uniqueID; 1071 uint64_t uniqueID;
1134 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1072 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);
@@ -1141,10 +1079,10 @@ static int udf_link(struct dentry * old_dentry, struct inode * dir,
1141 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1079 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
1142 } 1080 }
1143 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1081 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1144 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 1082 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
1145 {
1146 mark_inode_dirty(dir); 1083 mark_inode_dirty(dir);
1147 } 1084 }
1085
1148 if (fibh.sbh != fibh.ebh) 1086 if (fibh.sbh != fibh.ebh)
1149 brelse(fibh.ebh); 1087 brelse(fibh.ebh);
1150 brelse(fibh.sbh); 1088 brelse(fibh.sbh);
@@ -1154,17 +1092,18 @@ static int udf_link(struct dentry * old_dentry, struct inode * dir,
1154 atomic_inc(&inode->i_count); 1092 atomic_inc(&inode->i_count);
1155 d_instantiate(dentry, inode); 1093 d_instantiate(dentry, inode);
1156 unlock_kernel(); 1094 unlock_kernel();
1095
1157 return 0; 1096 return 0;
1158} 1097}
1159 1098
1160/* Anybody can rename anything with this: the permission checks are left to the 1099/* Anybody can rename anything with this: the permission checks are left to the
1161 * higher-level routines. 1100 * higher-level routines.
1162 */ 1101 */
1163static int udf_rename (struct inode * old_dir, struct dentry * old_dentry, 1102static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1164 struct inode * new_dir, struct dentry * new_dentry) 1103 struct inode *new_dir, struct dentry *new_dentry)
1165{ 1104{
1166 struct inode * old_inode = old_dentry->d_inode; 1105 struct inode *old_inode = old_dentry->d_inode;
1167 struct inode * new_inode = new_dentry->d_inode; 1106 struct inode *new_inode = new_dentry->d_inode;
1168 struct udf_fileident_bh ofibh, nfibh; 1107 struct udf_fileident_bh ofibh, nfibh;
1169 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; 1108 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi;
1170 struct buffer_head *dir_bh = NULL; 1109 struct buffer_head *dir_bh = NULL;
@@ -1172,49 +1111,41 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1172 kernel_lb_addr tloc; 1111 kernel_lb_addr tloc;
1173 1112
1174 lock_kernel(); 1113 lock_kernel();
1175 if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) 1114 if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) {
1176 {
1177 if (ofibh.sbh != ofibh.ebh) 1115 if (ofibh.sbh != ofibh.ebh)
1178 brelse(ofibh.ebh); 1116 brelse(ofibh.ebh);
1179 brelse(ofibh.sbh); 1117 brelse(ofibh.sbh);
1180 } 1118 }
1181 tloc = lelb_to_cpu(ocfi.icb.extLocation); 1119 tloc = lelb_to_cpu(ocfi.icb.extLocation);
1182 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0) 1120 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0)
1183 != old_inode->i_ino) 1121 != old_inode->i_ino)
1184 goto end_rename; 1122 goto end_rename;
1185 1123
1186 nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi); 1124 nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi);
1187 if (nfi) 1125 if (nfi) {
1188 { 1126 if (!new_inode) {
1189 if (!new_inode)
1190 {
1191 if (nfibh.sbh != nfibh.ebh) 1127 if (nfibh.sbh != nfibh.ebh)
1192 brelse(nfibh.ebh); 1128 brelse(nfibh.ebh);
1193 brelse(nfibh.sbh); 1129 brelse(nfibh.sbh);
1194 nfi = NULL; 1130 nfi = NULL;
1195 } 1131 }
1196 } 1132 }
1197 if (S_ISDIR(old_inode->i_mode)) 1133 if (S_ISDIR(old_inode->i_mode)) {
1198 {
1199 uint32_t offset = udf_ext0_offset(old_inode); 1134 uint32_t offset = udf_ext0_offset(old_inode);
1200 1135
1201 if (new_inode) 1136 if (new_inode) {
1202 {
1203 retval = -ENOTEMPTY; 1137 retval = -ENOTEMPTY;
1204 if (!empty_dir(new_inode)) 1138 if (!empty_dir(new_inode))
1205 goto end_rename; 1139 goto end_rename;
1206 } 1140 }
1207 retval = -EIO; 1141 retval = -EIO;
1208 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) 1142 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
1209 {
1210 dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - 1143 dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) -
1211 (UDF_I_EFE(old_inode) ? 1144 (UDF_I_EFE(old_inode) ?
1212 sizeof(struct extendedFileEntry) : 1145 sizeof(struct extendedFileEntry) :
1213 sizeof(struct fileEntry)), 1146 sizeof(struct fileEntry)),
1214 old_inode->i_sb->s_blocksize, &offset); 1147 old_inode->i_sb->s_blocksize, &offset);
1215 } 1148 } else {
1216 else
1217 {
1218 dir_bh = udf_bread(old_inode, 0, 0, &retval); 1149 dir_bh = udf_bread(old_inode, 0, 0, &retval);
1219 if (!dir_bh) 1150 if (!dir_bh)
1220 goto end_rename; 1151 goto end_rename;
@@ -1223,16 +1154,14 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1223 if (!dir_fi) 1154 if (!dir_fi)
1224 goto end_rename; 1155 goto end_rename;
1225 tloc = lelb_to_cpu(dir_fi->icb.extLocation); 1156 tloc = lelb_to_cpu(dir_fi->icb.extLocation);
1226 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) 1157 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino)
1227 != old_dir->i_ino)
1228 goto end_rename; 1158 goto end_rename;
1229 1159
1230 retval = -EMLINK; 1160 retval = -EMLINK;
1231 if (!new_inode && new_dir->i_nlink >= (256<<sizeof(new_dir->i_nlink))-1) 1161 if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1)
1232 goto end_rename; 1162 goto end_rename;
1233 } 1163 }
1234 if (!nfi) 1164 if (!nfi) {
1235 {
1236 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); 1165 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval);
1237 if (!nfi) 1166 if (!nfi)
1238 goto end_rename; 1167 goto end_rename;
@@ -1257,39 +1186,32 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1257 ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); 1186 ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);
1258 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); 1187 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
1259 1188
1260 if (new_inode) 1189 if (new_inode) {
1261 {
1262 new_inode->i_ctime = current_fs_time(new_inode->i_sb); 1190 new_inode->i_ctime = current_fs_time(new_inode->i_sb);
1263 inode_dec_link_count(new_inode); 1191 inode_dec_link_count(new_inode);
1264 } 1192 }
1265 old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb); 1193 old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb);
1266 mark_inode_dirty(old_dir); 1194 mark_inode_dirty(old_dir);
1267 1195
1268 if (dir_fi) 1196 if (dir_fi) {
1269 {
1270 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); 1197 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir));
1271 udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + 1198 udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) +
1272 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); 1199 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
1273 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) 1200 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
1274 {
1275 mark_inode_dirty(old_inode); 1201 mark_inode_dirty(old_inode);
1276 } 1202 } else {
1277 else
1278 mark_buffer_dirty_inode(dir_bh, old_inode); 1203 mark_buffer_dirty_inode(dir_bh, old_inode);
1204 }
1279 inode_dec_link_count(old_dir); 1205 inode_dec_link_count(old_dir);
1280 if (new_inode) 1206 if (new_inode) {
1281 {
1282 inode_dec_link_count(new_inode); 1207 inode_dec_link_count(new_inode);
1283 } 1208 } else {
1284 else
1285 {
1286 inc_nlink(new_dir); 1209 inc_nlink(new_dir);
1287 mark_inode_dirty(new_dir); 1210 mark_inode_dirty(new_dir);
1288 } 1211 }
1289 } 1212 }
1290 1213
1291 if (ofi) 1214 if (ofi) {
1292 {
1293 if (ofibh.sbh != ofibh.ebh) 1215 if (ofibh.sbh != ofibh.ebh)
1294 brelse(ofibh.ebh); 1216 brelse(ofibh.ebh);
1295 brelse(ofibh.sbh); 1217 brelse(ofibh.sbh);
@@ -1299,13 +1221,13 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1299 1221
1300end_rename: 1222end_rename:
1301 brelse(dir_bh); 1223 brelse(dir_bh);
1302 if (nfi) 1224 if (nfi) {
1303 {
1304 if (nfibh.sbh != nfibh.ebh) 1225 if (nfibh.sbh != nfibh.ebh)
1305 brelse(nfibh.ebh); 1226 brelse(nfibh.ebh);
1306 brelse(nfibh.sbh); 1227 brelse(nfibh.sbh);
1307 } 1228 }
1308 unlock_kernel(); 1229 unlock_kernel();
1230
1309 return retval; 1231 return retval;
1310} 1232}
1311 1233
diff --git a/fs/udf/osta_udf.h b/fs/udf/osta_udf.h
index e82aae652697..65ff47902bd2 100644
--- a/fs/udf/osta_udf.h
+++ b/fs/udf/osta_udf.h
@@ -65,30 +65,26 @@
65#define IS_DF_HARD_WRITE_PROTECT 0x01 65#define IS_DF_HARD_WRITE_PROTECT 0x01
66#define IS_DF_SOFT_WRITE_PROTECT 0x02 66#define IS_DF_SOFT_WRITE_PROTECT 0x02
67 67
68struct UDFIdentSuffix 68struct UDFIdentSuffix {
69{
70 __le16 UDFRevision; 69 __le16 UDFRevision;
71 uint8_t OSClass; 70 uint8_t OSClass;
72 uint8_t OSIdentifier; 71 uint8_t OSIdentifier;
73 uint8_t reserved[4]; 72 uint8_t reserved[4];
74} __attribute__ ((packed)); 73} __attribute__ ((packed));
75 74
76struct impIdentSuffix 75struct impIdentSuffix {
77{
78 uint8_t OSClass; 76 uint8_t OSClass;
79 uint8_t OSIdentifier; 77 uint8_t OSIdentifier;
80 uint8_t reserved[6]; 78 uint8_t reserved[6];
81} __attribute__ ((packed)); 79} __attribute__ ((packed));
82 80
83struct appIdentSuffix 81struct appIdentSuffix {
84{
85 uint8_t impUse[8]; 82 uint8_t impUse[8];
86} __attribute__ ((packed)); 83} __attribute__ ((packed));
87 84
88/* Logical Volume Integrity Descriptor (UDF 2.50 2.2.6) */ 85/* Logical Volume Integrity Descriptor (UDF 2.50 2.2.6) */
89/* Implementation Use (UDF 2.50 2.2.6.4) */ 86/* Implementation Use (UDF 2.50 2.2.6.4) */
90struct logicalVolIntegrityDescImpUse 87struct logicalVolIntegrityDescImpUse {
91{
92 regid impIdent; 88 regid impIdent;
93 __le32 numFiles; 89 __le32 numFiles;
94 __le32 numDirs; 90 __le32 numDirs;
@@ -100,8 +96,7 @@ struct logicalVolIntegrityDescImpUse
100 96
101/* Implementation Use Volume Descriptor (UDF 2.50 2.2.7) */ 97/* Implementation Use Volume Descriptor (UDF 2.50 2.2.7) */
102/* Implementation Use (UDF 2.50 2.2.7.2) */ 98/* Implementation Use (UDF 2.50 2.2.7.2) */
103struct impUseVolDescImpUse 99struct impUseVolDescImpUse {
104{
105 charspec LVICharset; 100 charspec LVICharset;
106 dstring logicalVolIdent[128]; 101 dstring logicalVolIdent[128];
107 dstring LVInfo1[36]; 102 dstring LVInfo1[36];
@@ -111,8 +106,7 @@ struct impUseVolDescImpUse
111 uint8_t impUse[128]; 106 uint8_t impUse[128];
112} __attribute__ ((packed)); 107} __attribute__ ((packed));
113 108
114struct udfPartitionMap2 109struct udfPartitionMap2 {
115{
116 uint8_t partitionMapType; 110 uint8_t partitionMapType;
117 uint8_t partitionMapLength; 111 uint8_t partitionMapLength;
118 uint8_t reserved1[2]; 112 uint8_t reserved1[2];
@@ -122,8 +116,7 @@ struct udfPartitionMap2
122} __attribute__ ((packed)); 116} __attribute__ ((packed));
123 117
124/* Virtual Partition Map (UDF 2.50 2.2.8) */ 118/* Virtual Partition Map (UDF 2.50 2.2.8) */
125struct virtualPartitionMap 119struct virtualPartitionMap {
126{
127 uint8_t partitionMapType; 120 uint8_t partitionMapType;
128 uint8_t partitionMapLength; 121 uint8_t partitionMapLength;
129 uint8_t reserved1[2]; 122 uint8_t reserved1[2];
@@ -134,24 +127,22 @@ struct virtualPartitionMap
134} __attribute__ ((packed)); 127} __attribute__ ((packed));
135 128
136/* Sparable Partition Map (UDF 2.50 2.2.9) */ 129/* Sparable Partition Map (UDF 2.50 2.2.9) */
137struct sparablePartitionMap 130struct sparablePartitionMap {
138{ 131 uint8_t partitionMapType;
139 uint8_t partitionMapType; 132 uint8_t partitionMapLength;
140 uint8_t partitionMapLength; 133 uint8_t reserved1[2];
141 uint8_t reserved1[2]; 134 regid partIdent;
142 regid partIdent; 135 __le16 volSeqNum;
143 __le16 volSeqNum; 136 __le16 partitionNum;
144 __le16 partitionNum; 137 __le16 packetLength;
145 __le16 packetLength; 138 uint8_t numSparingTables;
146 uint8_t numSparingTables; 139 uint8_t reserved2[1];
147 uint8_t reserved2[1]; 140 __le32 sizeSparingTable;
148 __le32 sizeSparingTable; 141 __le32 locSparingTable[4];
149 __le32 locSparingTable[4];
150} __attribute__ ((packed)); 142} __attribute__ ((packed));
151 143
152/* Metadata Partition Map (UDF 2.4.0 2.2.10) */ 144/* Metadata Partition Map (UDF 2.4.0 2.2.10) */
153struct metadataPartitionMap 145struct metadataPartitionMap {
154{
155 uint8_t partitionMapType; 146 uint8_t partitionMapType;
156 uint8_t partitionMapLength; 147 uint8_t partitionMapLength;
157 uint8_t reserved1[2]; 148 uint8_t reserved1[2];
@@ -168,18 +159,16 @@ struct metadataPartitionMap
168} __attribute__ ((packed)); 159} __attribute__ ((packed));
169 160
170/* Virtual Allocation Table (UDF 1.5 2.2.10) */ 161/* Virtual Allocation Table (UDF 1.5 2.2.10) */
171struct virtualAllocationTable15 162struct virtualAllocationTable15 {
172{
173 __le32 VirtualSector[0]; 163 __le32 VirtualSector[0];
174 regid vatIdent; 164 regid vatIdent;
175 __le32 previousVATICBLoc; 165 __le32 previousVATICBLoc;
176} __attribute__ ((packed)); 166} __attribute__ ((packed));
177 167
178#define ICBTAG_FILE_TYPE_VAT15 0x00U 168#define ICBTAG_FILE_TYPE_VAT15 0x00U
179 169
180/* Virtual Allocation Table (UDF 2.50 2.2.11) */ 170/* Virtual Allocation Table (UDF 2.50 2.2.11) */
181struct virtualAllocationTable20 171struct virtualAllocationTable20 {
182{
183 __le16 lengthHeader; 172 __le16 lengthHeader;
184 __le16 lengthImpUse; 173 __le16 lengthImpUse;
185 dstring logicalVolIdent[128]; 174 dstring logicalVolIdent[128];
@@ -197,14 +186,12 @@ struct virtualAllocationTable20
197#define ICBTAG_FILE_TYPE_VAT20 0xF8U 186#define ICBTAG_FILE_TYPE_VAT20 0xF8U
198 187
199/* Sparing Table (UDF 2.50 2.2.12) */ 188/* Sparing Table (UDF 2.50 2.2.12) */
200struct sparingEntry 189struct sparingEntry {
201{
202 __le32 origLocation; 190 __le32 origLocation;
203 __le32 mappedLocation; 191 __le32 mappedLocation;
204} __attribute__ ((packed)); 192} __attribute__ ((packed));
205 193
206struct sparingTable 194struct sparingTable {
207{
208 tag descTag; 195 tag descTag;
209 regid sparingIdent; 196 regid sparingIdent;
210 __le16 reallocationTableLen; 197 __le16 reallocationTableLen;
@@ -220,8 +207,7 @@ struct sparingTable
220#define ICBTAG_FILE_TYPE_BITMAP 0xFC 207#define ICBTAG_FILE_TYPE_BITMAP 0xFC
221 208
222/* struct long_ad ICB - ADImpUse (UDF 2.50 2.2.4.3) */ 209/* struct long_ad ICB - ADImpUse (UDF 2.50 2.2.4.3) */
223struct allocDescImpUse 210struct allocDescImpUse {
224{
225 __le16 flags; 211 __le16 flags;
226 uint8_t impUse[4]; 212 uint8_t impUse[4];
227} __attribute__ ((packed)); 213} __attribute__ ((packed));
@@ -233,15 +219,13 @@ struct allocDescImpUse
233 219
234/* Implementation Use Extended Attribute (UDF 2.50 3.3.4.5) */ 220/* Implementation Use Extended Attribute (UDF 2.50 3.3.4.5) */
235/* FreeEASpace (UDF 2.50 3.3.4.5.1.1) */ 221/* FreeEASpace (UDF 2.50 3.3.4.5.1.1) */
236struct freeEaSpace 222struct freeEaSpace {
237{
238 __le16 headerChecksum; 223 __le16 headerChecksum;
239 uint8_t freeEASpace[0]; 224 uint8_t freeEASpace[0];
240} __attribute__ ((packed)); 225} __attribute__ ((packed));
241 226
242/* DVD Copyright Management Information (UDF 2.50 3.3.4.5.1.2) */ 227/* DVD Copyright Management Information (UDF 2.50 3.3.4.5.1.2) */
243struct DVDCopyrightImpUse 228struct DVDCopyrightImpUse {
244{
245 __le16 headerChecksum; 229 __le16 headerChecksum;
246 uint8_t CGMSInfo; 230 uint8_t CGMSInfo;
247 uint8_t dataType; 231 uint8_t dataType;
@@ -250,8 +234,7 @@ struct DVDCopyrightImpUse
250 234
251/* Application Use Extended Attribute (UDF 2.50 3.3.4.6) */ 235/* Application Use Extended Attribute (UDF 2.50 3.3.4.6) */
252/* FreeAppEASpace (UDF 2.50 3.3.4.6.1) */ 236/* FreeAppEASpace (UDF 2.50 3.3.4.6.1) */
253struct freeAppEASpace 237struct freeAppEASpace {
254{
255 __le16 headerChecksum; 238 __le16 headerChecksum;
256 uint8_t freeEASpace[0]; 239 uint8_t freeEASpace[0];
257} __attribute__ ((packed)); 240} __attribute__ ((packed));
diff --git a/fs/udf/partition.c b/fs/udf/partition.c
index 467a26171cd9..aaab24c8c498 100644
--- a/fs/udf/partition.c
+++ b/fs/udf/partition.c
@@ -14,7 +14,7 @@
14 * 14 *
15 * HISTORY 15 * HISTORY
16 * 16 *
17 * 12/06/98 blf Created file. 17 * 12/06/98 blf Created file.
18 * 18 *
19 */ 19 */
20 20
@@ -28,12 +28,12 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/buffer_head.h> 29#include <linux/buffer_head.h>
30 30
31inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 31inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block,
32 uint16_t partition, uint32_t offset)
32{ 33{
33 if (partition >= UDF_SB_NUMPARTS(sb)) 34 if (partition >= UDF_SB_NUMPARTS(sb)) {
34 {
35 udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", 35 udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n",
36 block, partition, offset); 36 block, partition, offset);
37 return 0xFFFFFFFF; 37 return 0xFFFFFFFF;
38 } 38 }
39 if (UDF_SB_PARTFUNC(sb, partition)) 39 if (UDF_SB_PARTFUNC(sb, partition))
@@ -42,7 +42,8 @@ inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, uint16_t
42 return UDF_SB_PARTROOT(sb, partition) + block + offset; 42 return UDF_SB_PARTROOT(sb, partition) + block + offset;
43} 43}
44 44
45uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 45uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
46 uint16_t partition, uint32_t offset)
46{ 47{
47 struct buffer_head *bh = NULL; 48 struct buffer_head *bh = NULL;
48 uint32_t newblock; 49 uint32_t newblock;
@@ -51,31 +52,26 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, uint16_t
51 52
52 index = (sb->s_blocksize - UDF_SB_TYPEVIRT(sb,partition).s_start_offset) / sizeof(uint32_t); 53 index = (sb->s_blocksize - UDF_SB_TYPEVIRT(sb,partition).s_start_offset) / sizeof(uint32_t);
53 54
54 if (block > UDF_SB_TYPEVIRT(sb,partition).s_num_entries) 55 if (block > UDF_SB_TYPEVIRT(sb,partition).s_num_entries) {
55 {
56 udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", 56 udf_debug("Trying to access block beyond end of VAT (%d max %d)\n",
57 block, UDF_SB_TYPEVIRT(sb,partition).s_num_entries); 57 block, UDF_SB_TYPEVIRT(sb,partition).s_num_entries);
58 return 0xFFFFFFFF; 58 return 0xFFFFFFFF;
59 } 59 }
60 60
61 if (block >= index) 61 if (block >= index) {
62 {
63 block -= index; 62 block -= index;
64 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t))); 63 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t)));
65 index = block % (sb->s_blocksize / sizeof(uint32_t)); 64 index = block % (sb->s_blocksize / sizeof(uint32_t));
66 } 65 } else {
67 else
68 {
69 newblock = 0; 66 newblock = 0;
70 index = UDF_SB_TYPEVIRT(sb,partition).s_start_offset / sizeof(uint32_t) + block; 67 index = UDF_SB_TYPEVIRT(sb,partition).s_start_offset / sizeof(uint32_t) + block;
71 } 68 }
72 69
73 loc = udf_block_map(UDF_SB_VAT(sb), newblock); 70 loc = udf_block_map(UDF_SB_VAT(sb), newblock);
74 71
75 if (!(bh = sb_bread(sb, loc))) 72 if (!(bh = sb_bread(sb, loc))) {
76 {
77 udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", 73 udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n",
78 sb, block, partition, loc, index); 74 sb, block, partition, loc, index);
79 return 0xFFFFFFFF; 75 return 0xFFFFFFFF;
80 } 76 }
81 77
@@ -83,50 +79,49 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, uint16_t
83 79
84 brelse(bh); 80 brelse(bh);
85 81
86 if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) 82 if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) {
87 {
88 udf_debug("recursive call to udf_get_pblock!\n"); 83 udf_debug("recursive call to udf_get_pblock!\n");
89 return 0xFFFFFFFF; 84 return 0xFFFFFFFF;
90 } 85 }
91 86
92 return udf_get_pblock(sb, loc, UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum, offset); 87 return udf_get_pblock(sb, loc,
88 UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum,
89 offset);
93} 90}
94 91
95inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 92inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block,
93 uint16_t partition, uint32_t offset)
96{ 94{
97 return udf_get_pblock_virt15(sb, block, partition, offset); 95 return udf_get_pblock_virt15(sb, block, partition, offset);
98} 96}
99 97
100uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 98uint32_t udf_get_pblock_spar15(struct super_block * sb, uint32_t block,
99 uint16_t partition, uint32_t offset)
101{ 100{
102 int i; 101 int i;
103 struct sparingTable *st = NULL; 102 struct sparingTable *st = NULL;
104 uint32_t packet = (block + offset) & ~(UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1); 103 uint32_t packet = (block + offset) & ~(UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1);
105 104
106 for (i=0; i<4; i++) 105 for (i = 0; i < 4; i++) {
107 { 106 if (UDF_SB_TYPESPAR(sb,partition).s_spar_map[i] != NULL) {
108 if (UDF_SB_TYPESPAR(sb,partition).s_spar_map[i] != NULL)
109 {
110 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,partition).s_spar_map[i]->b_data; 107 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,partition).s_spar_map[i]->b_data;
111 break; 108 break;
112 } 109 }
113 } 110 }
114 111
115 if (st) 112 if (st) {
116 { 113 for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
117 for (i=0; i<le16_to_cpu(st->reallocationTableLen); i++) 114 if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) {
118 {
119 if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0)
120 break; 115 break;
121 else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) 116 } else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) {
122 {
123 return le32_to_cpu(st->mapEntry[i].mappedLocation) + 117 return le32_to_cpu(st->mapEntry[i].mappedLocation) +
124 ((block + offset) & (UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1)); 118 ((block + offset) & (UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1));
125 } 119 } else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) {
126 else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet)
127 break; 120 break;
121 }
128 } 122 }
129 } 123 }
124
130 return UDF_SB_PARTROOT(sb,partition) + block + offset; 125 return UDF_SB_PARTROOT(sb,partition) + block + offset;
131} 126}
132 127
@@ -138,18 +133,14 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
138 uint32_t packet; 133 uint32_t packet;
139 int i, j, k, l; 134 int i, j, k, l;
140 135
141 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 136 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
142 {
143 if (old_block > UDF_SB_PARTROOT(sb,i) && 137 if (old_block > UDF_SB_PARTROOT(sb,i) &&
144 old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i)) 138 old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i)) {
145 {
146 sdata = &UDF_SB_TYPESPAR(sb,i); 139 sdata = &UDF_SB_TYPESPAR(sb,i);
147 packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1); 140 packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1);
148 141
149 for (j=0; j<4; j++) 142 for (j = 0; j < 4; j++) {
150 { 143 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) {
151 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL)
152 {
153 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 144 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
154 break; 145 break;
155 } 146 }
@@ -158,14 +149,10 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
158 if (!st) 149 if (!st)
159 return 1; 150 return 1;
160 151
161 for (k=0; k<le16_to_cpu(st->reallocationTableLen); k++) 152 for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) {
162 { 153 if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) {
163 if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) 154 for (; j < 4; j++) {
164 { 155 if (sdata->s_spar_map[j]) {
165 for (; j<4; j++)
166 {
167 if (sdata->s_spar_map[j])
168 {
169 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 156 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
170 st->mapEntry[k].origLocation = cpu_to_le32(packet); 157 st->mapEntry[k].origLocation = cpu_to_le32(packet);
171 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); 158 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
@@ -175,28 +162,23 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
175 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + 162 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) +
176 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); 163 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1));
177 return 0; 164 return 0;
178 } 165 } else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) {
179 else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet)
180 {
181 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + 166 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) +
182 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); 167 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1));
183 return 0; 168 return 0;
184 } 169 } else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) {
185 else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet)
186 break; 170 break;
171 }
187 } 172 }
188 for (l=k; l<le16_to_cpu(st->reallocationTableLen); l++) 173
189 { 174 for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) {
190 if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) 175 if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) {
191 { 176 for (; j < 4; j++) {
192 for (; j<4; j++) 177 if (sdata->s_spar_map[j]) {
193 {
194 if (sdata->s_spar_map[j])
195 {
196 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 178 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
197 mapEntry = st->mapEntry[l]; 179 mapEntry = st->mapEntry[l];
198 mapEntry.origLocation = cpu_to_le32(packet); 180 mapEntry.origLocation = cpu_to_le32(packet);
199 memmove(&st->mapEntry[k+1], &st->mapEntry[k], (l-k)*sizeof(struct sparingEntry)); 181 memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry));
200 st->mapEntry[k] = mapEntry; 182 st->mapEntry[k] = mapEntry;
201 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); 183 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
202 mark_buffer_dirty(sdata->s_spar_map[j]); 184 mark_buffer_dirty(sdata->s_spar_map[j]);
@@ -207,11 +189,12 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
207 return 0; 189 return 0;
208 } 190 }
209 } 191 }
192
210 return 1; 193 return 1;
211 } 194 } /* if old_block */
212 } 195 }
213 if (i == UDF_SB_NUMPARTS(sb)) 196
214 { 197 if (i == UDF_SB_NUMPARTS(sb)) {
215 /* outside of partitions */ 198 /* outside of partitions */
216 /* for now, fail =) */ 199 /* for now, fail =) */
217 return 1; 200 return 1;
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 6658afb41cc7..7b30964665db 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -38,7 +38,7 @@
38 * 12/20/98 find the free space bitmap (if it exists) 38 * 12/20/98 find the free space bitmap (if it exists)
39 */ 39 */
40 40
41#include "udfdecl.h" 41#include "udfdecl.h"
42 42
43#include <linux/blkdev.h> 43#include <linux/blkdev.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
@@ -80,12 +80,15 @@ static int udf_remount_fs(struct super_block *, int *, char *);
80static int udf_check_valid(struct super_block *, int, int); 80static int udf_check_valid(struct super_block *, int, int);
81static int udf_vrs(struct super_block *sb, int silent); 81static int udf_vrs(struct super_block *sb, int silent);
82static int udf_load_partition(struct super_block *, kernel_lb_addr *); 82static int udf_load_partition(struct super_block *, kernel_lb_addr *);
83static int udf_load_logicalvol(struct super_block *, struct buffer_head *, kernel_lb_addr *); 83static int udf_load_logicalvol(struct super_block *, struct buffer_head *,
84 kernel_lb_addr *);
84static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad); 85static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
85static void udf_find_anchor(struct super_block *); 86static void udf_find_anchor(struct super_block *);
86static int udf_find_fileset(struct super_block *, kernel_lb_addr *, kernel_lb_addr *); 87static int udf_find_fileset(struct super_block *, kernel_lb_addr *,
88 kernel_lb_addr *);
87static void udf_load_pvoldesc(struct super_block *, struct buffer_head *); 89static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
88static void udf_load_fileset(struct super_block *, struct buffer_head *, kernel_lb_addr *); 90static void udf_load_fileset(struct super_block *, struct buffer_head *,
91 kernel_lb_addr *);
89static void udf_load_partdesc(struct super_block *, struct buffer_head *); 92static void udf_load_partdesc(struct super_block *, struct buffer_head *);
90static void udf_open_lvid(struct super_block *); 93static void udf_open_lvid(struct super_block *);
91static void udf_close_lvid(struct super_block *); 94static void udf_close_lvid(struct super_block *);
@@ -94,7 +97,8 @@ static int udf_statfs(struct dentry *, struct kstatfs *);
94 97
95/* UDF filesystem type */ 98/* UDF filesystem type */
96static int udf_get_sb(struct file_system_type *fs_type, 99static int udf_get_sb(struct file_system_type *fs_type,
97 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 100 int flags, const char *dev_name, void *data,
101 struct vfsmount *mnt)
98{ 102{
99 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt); 103 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
100} 104}
@@ -107,7 +111,7 @@ static struct file_system_type udf_fstype = {
107 .fs_flags = FS_REQUIRES_DEV, 111 .fs_flags = FS_REQUIRES_DEV,
108}; 112};
109 113
110static struct kmem_cache * udf_inode_cachep; 114static struct kmem_cache *udf_inode_cachep;
111 115
112static struct inode *udf_alloc_inode(struct super_block *sb) 116static struct inode *udf_alloc_inode(struct super_block *sb)
113{ 117{
@@ -130,9 +134,9 @@ static void udf_destroy_inode(struct inode *inode)
130 kmem_cache_free(udf_inode_cachep, UDF_I(inode)); 134 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
131} 135}
132 136
133static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags) 137static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
134{ 138{
135 struct udf_inode_info *ei = (struct udf_inode_info *) foo; 139 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
136 140
137 ei->i_ext.i_data = NULL; 141 ei->i_ext.i_data = NULL;
138 inode_init_once(&ei->vfs_inode); 142 inode_init_once(&ei->vfs_inode);
@@ -142,10 +146,10 @@ static int init_inodecache(void)
142{ 146{
143 udf_inode_cachep = kmem_cache_create("udf_inode_cache", 147 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
144 sizeof(struct udf_inode_info), 148 sizeof(struct udf_inode_info),
145 0, (SLAB_RECLAIM_ACCOUNT| 149 0, (SLAB_RECLAIM_ACCOUNT |
146 SLAB_MEM_SPREAD), 150 SLAB_MEM_SPREAD),
147 init_once, NULL); 151 init_once);
148 if (udf_inode_cachep == NULL) 152 if (!udf_inode_cachep)
149 return -ENOMEM; 153 return -ENOMEM;
150 return 0; 154 return 0;
151} 155}
@@ -157,19 +161,18 @@ static void destroy_inodecache(void)
157 161
158/* Superblock operations */ 162/* Superblock operations */
159static const struct super_operations udf_sb_ops = { 163static const struct super_operations udf_sb_ops = {
160 .alloc_inode = udf_alloc_inode, 164 .alloc_inode = udf_alloc_inode,
161 .destroy_inode = udf_destroy_inode, 165 .destroy_inode = udf_destroy_inode,
162 .write_inode = udf_write_inode, 166 .write_inode = udf_write_inode,
163 .delete_inode = udf_delete_inode, 167 .delete_inode = udf_delete_inode,
164 .clear_inode = udf_clear_inode, 168 .clear_inode = udf_clear_inode,
165 .put_super = udf_put_super, 169 .put_super = udf_put_super,
166 .write_super = udf_write_super, 170 .write_super = udf_write_super,
167 .statfs = udf_statfs, 171 .statfs = udf_statfs,
168 .remount_fs = udf_remount_fs, 172 .remount_fs = udf_remount_fs,
169}; 173};
170 174
171struct udf_options 175struct udf_options {
172{
173 unsigned char novrs; 176 unsigned char novrs;
174 unsigned int blocksize; 177 unsigned int blocksize;
175 unsigned int session; 178 unsigned int session;
@@ -189,15 +192,19 @@ struct udf_options
189static int __init init_udf_fs(void) 192static int __init init_udf_fs(void)
190{ 193{
191 int err; 194 int err;
195
192 err = init_inodecache(); 196 err = init_inodecache();
193 if (err) 197 if (err)
194 goto out1; 198 goto out1;
195 err = register_filesystem(&udf_fstype); 199 err = register_filesystem(&udf_fstype);
196 if (err) 200 if (err)
197 goto out; 201 goto out;
202
198 return 0; 203 return 0;
204
199out: 205out:
200 destroy_inodecache(); 206 destroy_inodecache();
207
201out1: 208out1:
202 return err; 209 return err;
203} 210}
@@ -235,7 +242,7 @@ module_exit(exit_udf_fs)
235 * 242 *
236 * The remaining are for debugging and disaster recovery: 243 * The remaining are for debugging and disaster recovery:
237 * 244 *
238 * novrs Skip volume sequence recognition 245 * novrs Skip volume sequence recognition
239 * 246 *
240 * The following expect a offset from 0. 247 * The following expect a offset from 0.
241 * 248 *
@@ -275,36 +282,35 @@ enum {
275}; 282};
276 283
277static match_table_t tokens = { 284static match_table_t tokens = {
278 {Opt_novrs, "novrs"}, 285 {Opt_novrs, "novrs"},
279 {Opt_nostrict, "nostrict"}, 286 {Opt_nostrict, "nostrict"},
280 {Opt_bs, "bs=%u"}, 287 {Opt_bs, "bs=%u"},
281 {Opt_unhide, "unhide"}, 288 {Opt_unhide, "unhide"},
282 {Opt_undelete, "undelete"}, 289 {Opt_undelete, "undelete"},
283 {Opt_noadinicb, "noadinicb"}, 290 {Opt_noadinicb, "noadinicb"},
284 {Opt_adinicb, "adinicb"}, 291 {Opt_adinicb, "adinicb"},
285 {Opt_shortad, "shortad"}, 292 {Opt_shortad, "shortad"},
286 {Opt_longad, "longad"}, 293 {Opt_longad, "longad"},
287 {Opt_uforget, "uid=forget"}, 294 {Opt_uforget, "uid=forget"},
288 {Opt_uignore, "uid=ignore"}, 295 {Opt_uignore, "uid=ignore"},
289 {Opt_gforget, "gid=forget"}, 296 {Opt_gforget, "gid=forget"},
290 {Opt_gignore, "gid=ignore"}, 297 {Opt_gignore, "gid=ignore"},
291 {Opt_gid, "gid=%u"}, 298 {Opt_gid, "gid=%u"},
292 {Opt_uid, "uid=%u"}, 299 {Opt_uid, "uid=%u"},
293 {Opt_umask, "umask=%o"}, 300 {Opt_umask, "umask=%o"},
294 {Opt_session, "session=%u"}, 301 {Opt_session, "session=%u"},
295 {Opt_lastblock, "lastblock=%u"}, 302 {Opt_lastblock, "lastblock=%u"},
296 {Opt_anchor, "anchor=%u"}, 303 {Opt_anchor, "anchor=%u"},
297 {Opt_volume, "volume=%u"}, 304 {Opt_volume, "volume=%u"},
298 {Opt_partition, "partition=%u"}, 305 {Opt_partition, "partition=%u"},
299 {Opt_fileset, "fileset=%u"}, 306 {Opt_fileset, "fileset=%u"},
300 {Opt_rootdir, "rootdir=%u"}, 307 {Opt_rootdir, "rootdir=%u"},
301 {Opt_utf8, "utf8"}, 308 {Opt_utf8, "utf8"},
302 {Opt_iocharset, "iocharset=%s"}, 309 {Opt_iocharset, "iocharset=%s"},
303 {Opt_err, NULL} 310 {Opt_err, NULL}
304}; 311};
305 312
306static int 313static int udf_parse_options(char *options, struct udf_options *uopt)
307udf_parse_options(char *options, struct udf_options *uopt)
308{ 314{
309 char *p; 315 char *p;
310 int option; 316 int option;
@@ -323,145 +329,143 @@ udf_parse_options(char *options, struct udf_options *uopt)
323 if (!options) 329 if (!options)
324 return 1; 330 return 1;
325 331
326 while ((p = strsep(&options, ",")) != NULL) 332 while ((p = strsep(&options, ",")) != NULL) {
327 {
328 substring_t args[MAX_OPT_ARGS]; 333 substring_t args[MAX_OPT_ARGS];
329 int token; 334 int token;
330 if (!*p) 335 if (!*p)
331 continue; 336 continue;
332 337
333 token = match_token(p, tokens, args); 338 token = match_token(p, tokens, args);
334 switch (token) 339 switch (token) {
335 { 340 case Opt_novrs:
336 case Opt_novrs: 341 uopt->novrs = 1;
337 uopt->novrs = 1; 342 case Opt_bs:
338 case Opt_bs: 343 if (match_int(&args[0], &option))
339 if (match_int(&args[0], &option)) 344 return 0;
340 return 0; 345 uopt->blocksize = option;
341 uopt->blocksize = option; 346 break;
342 break; 347 case Opt_unhide:
343 case Opt_unhide: 348 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
344 uopt->flags |= (1 << UDF_FLAG_UNHIDE); 349 break;
345 break; 350 case Opt_undelete:
346 case Opt_undelete: 351 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
347 uopt->flags |= (1 << UDF_FLAG_UNDELETE); 352 break;
348 break; 353 case Opt_noadinicb:
349 case Opt_noadinicb: 354 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
350 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB); 355 break;
351 break; 356 case Opt_adinicb:
352 case Opt_adinicb: 357 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
353 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB); 358 break;
354 break; 359 case Opt_shortad:
355 case Opt_shortad: 360 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
356 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD); 361 break;
357 break; 362 case Opt_longad:
358 case Opt_longad: 363 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
359 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD); 364 break;
360 break; 365 case Opt_gid:
361 case Opt_gid: 366 if (match_int(args, &option))
362 if (match_int(args, &option)) 367 return 0;
363 return 0; 368 uopt->gid = option;
364 uopt->gid = option; 369 break;
365 break; 370 case Opt_uid:
366 case Opt_uid: 371 if (match_int(args, &option))
367 if (match_int(args, &option)) 372 return 0;
368 return 0; 373 uopt->uid = option;
369 uopt->uid = option; 374 break;
370 break; 375 case Opt_umask:
371 case Opt_umask: 376 if (match_octal(args, &option))
372 if (match_octal(args, &option)) 377 return 0;
373 return 0; 378 uopt->umask = option;
374 uopt->umask = option; 379 break;
375 break; 380 case Opt_nostrict:
376 case Opt_nostrict: 381 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
377 uopt->flags &= ~(1 << UDF_FLAG_STRICT); 382 break;
378 break; 383 case Opt_session:
379 case Opt_session: 384 if (match_int(args, &option))
380 if (match_int(args, &option)) 385 return 0;
381 return 0; 386 uopt->session = option;
382 uopt->session = option; 387 break;
383 break; 388 case Opt_lastblock:
384 case Opt_lastblock: 389 if (match_int(args, &option))
385 if (match_int(args, &option)) 390 return 0;
386 return 0; 391 uopt->lastblock = option;
387 uopt->lastblock = option; 392 break;
388 break; 393 case Opt_anchor:
389 case Opt_anchor: 394 if (match_int(args, &option))
390 if (match_int(args, &option)) 395 return 0;
391 return 0; 396 uopt->anchor = option;
392 uopt->anchor = option; 397 break;
393 break; 398 case Opt_volume:
394 case Opt_volume: 399 if (match_int(args, &option))
395 if (match_int(args, &option)) 400 return 0;
396 return 0; 401 uopt->volume = option;
397 uopt->volume = option; 402 break;
398 break; 403 case Opt_partition:
399 case Opt_partition: 404 if (match_int(args, &option))
400 if (match_int(args, &option)) 405 return 0;
401 return 0; 406 uopt->partition = option;
402 uopt->partition = option; 407 break;
403 break; 408 case Opt_fileset:
404 case Opt_fileset: 409 if (match_int(args, &option))
405 if (match_int(args, &option)) 410 return 0;
406 return 0; 411 uopt->fileset = option;
407 uopt->fileset = option; 412 break;
408 break; 413 case Opt_rootdir:
409 case Opt_rootdir: 414 if (match_int(args, &option))
410 if (match_int(args, &option)) 415 return 0;
411 return 0; 416 uopt->rootdir = option;
412 uopt->rootdir = option; 417 break;
413 break; 418 case Opt_utf8:
414 case Opt_utf8: 419 uopt->flags |= (1 << UDF_FLAG_UTF8);
415 uopt->flags |= (1 << UDF_FLAG_UTF8); 420 break;
416 break;
417#ifdef CONFIG_UDF_NLS 421#ifdef CONFIG_UDF_NLS
418 case Opt_iocharset: 422 case Opt_iocharset:
419 uopt->nls_map = load_nls(args[0].from); 423 uopt->nls_map = load_nls(args[0].from);
420 uopt->flags |= (1 << UDF_FLAG_NLS_MAP); 424 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
421 break; 425 break;
422#endif 426#endif
423 case Opt_uignore: 427 case Opt_uignore:
424 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE); 428 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
425 break; 429 break;
426 case Opt_uforget: 430 case Opt_uforget:
427 uopt->flags |= (1 << UDF_FLAG_UID_FORGET); 431 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
428 break; 432 break;
429 case Opt_gignore: 433 case Opt_gignore:
430 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE); 434 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
431 break; 435 break;
432 case Opt_gforget: 436 case Opt_gforget:
433 uopt->flags |= (1 << UDF_FLAG_GID_FORGET); 437 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
434 break; 438 break;
435 default: 439 default:
436 printk(KERN_ERR "udf: bad mount option \"%s\" " 440 printk(KERN_ERR "udf: bad mount option \"%s\" "
437 "or missing value\n", p); 441 "or missing value\n", p);
438 return 0; 442 return 0;
439 } 443 }
440 } 444 }
441 return 1; 445 return 1;
442} 446}
443 447
444void 448void udf_write_super(struct super_block *sb)
445udf_write_super(struct super_block *sb)
446{ 449{
447 lock_kernel(); 450 lock_kernel();
451
448 if (!(sb->s_flags & MS_RDONLY)) 452 if (!(sb->s_flags & MS_RDONLY))
449 udf_open_lvid(sb); 453 udf_open_lvid(sb);
450 sb->s_dirt = 0; 454 sb->s_dirt = 0;
455
451 unlock_kernel(); 456 unlock_kernel();
452} 457}
453 458
454static int 459static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
455udf_remount_fs(struct super_block *sb, int *flags, char *options)
456{ 460{
457 struct udf_options uopt; 461 struct udf_options uopt;
458 462
459 uopt.flags = UDF_SB(sb)->s_flags ; 463 uopt.flags = UDF_SB(sb)->s_flags;
460 uopt.uid = UDF_SB(sb)->s_uid ; 464 uopt.uid = UDF_SB(sb)->s_uid;
461 uopt.gid = UDF_SB(sb)->s_gid ; 465 uopt.gid = UDF_SB(sb)->s_gid;
462 uopt.umask = UDF_SB(sb)->s_umask ; 466 uopt.umask = UDF_SB(sb)->s_umask;
463 467
464 if ( !udf_parse_options(options, &uopt) ) 468 if (!udf_parse_options(options, &uopt))
465 return -EINVAL; 469 return -EINVAL;
466 470
467 UDF_SB(sb)->s_flags = uopt.flags; 471 UDF_SB(sb)->s_flags = uopt.flags;
@@ -512,27 +516,26 @@ udf_remount_fs(struct super_block *sb, int *flags, char *options)
512 * July 1, 1997 - Andrew E. Mileski 516 * July 1, 1997 - Andrew E. Mileski
513 * Written, tested, and released. 517 * Written, tested, and released.
514 */ 518 */
515static int 519static int udf_set_blocksize(struct super_block *sb, int bsize)
516udf_set_blocksize(struct super_block *sb, int bsize)
517{ 520{
518 if (!sb_min_blocksize(sb, bsize)) { 521 if (!sb_min_blocksize(sb, bsize)) {
519 udf_debug("Bad block size (%d)\n", bsize); 522 udf_debug("Bad block size (%d)\n", bsize);
520 printk(KERN_ERR "udf: bad block size (%d)\n", bsize); 523 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
521 return 0; 524 return 0;
522 } 525 }
526
523 return sb->s_blocksize; 527 return sb->s_blocksize;
524} 528}
525 529
526static int 530static int udf_vrs(struct super_block *sb, int silent)
527udf_vrs(struct super_block *sb, int silent)
528{ 531{
529 struct volStructDesc *vsd = NULL; 532 struct volStructDesc *vsd = NULL;
530 int sector = 32768; 533 int sector = 32768;
531 int sectorsize; 534 int sectorsize;
532 struct buffer_head *bh = NULL; 535 struct buffer_head *bh = NULL;
533 int iso9660=0; 536 int iso9660 = 0;
534 int nsr02=0; 537 int nsr02 = 0;
535 int nsr03=0; 538 int nsr03 = 0;
536 539
537 /* Block size must be a multiple of 512 */ 540 /* Block size must be a multiple of 512 */
538 if (sb->s_blocksize & 511) 541 if (sb->s_blocksize & 511)
@@ -546,10 +549,9 @@ udf_vrs(struct super_block *sb, int silent)
546 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits); 549 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
547 550
548 udf_debug("Starting at sector %u (%ld byte sectors)\n", 551 udf_debug("Starting at sector %u (%ld byte sectors)\n",
549 (sector >> sb->s_blocksize_bits), sb->s_blocksize); 552 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
550 /* Process the sequence (if applicable) */ 553 /* Process the sequence (if applicable) */
551 for (;!nsr02 && !nsr03; sector += sectorsize) 554 for (; !nsr02 && !nsr03; sector += sectorsize) {
552 {
553 /* Read a block */ 555 /* Read a block */
554 bh = udf_tread(sb, sector >> sb->s_blocksize_bits); 556 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
555 if (!bh) 557 if (!bh)
@@ -557,52 +559,45 @@ udf_vrs(struct super_block *sb, int silent)
557 559
558 /* Look for ISO descriptors */ 560 /* Look for ISO descriptors */
559 vsd = (struct volStructDesc *)(bh->b_data + 561 vsd = (struct volStructDesc *)(bh->b_data +
560 (sector & (sb->s_blocksize - 1))); 562 (sector & (sb->s_blocksize - 1)));
561 563
562 if (vsd->stdIdent[0] == 0) 564 if (vsd->stdIdent[0] == 0) {
563 {
564 brelse(bh); 565 brelse(bh);
565 break; 566 break;
566 } 567 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
567 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN))
568 {
569 iso9660 = sector; 568 iso9660 = sector;
570 switch (vsd->structType) 569 switch (vsd->structType) {
571 { 570 case 0:
572 case 0: 571 udf_debug("ISO9660 Boot Record found\n");
573 udf_debug("ISO9660 Boot Record found\n"); 572 break;
574 break; 573 case 1:
575 case 1: 574 udf_debug
576 udf_debug("ISO9660 Primary Volume Descriptor found\n"); 575 ("ISO9660 Primary Volume Descriptor found\n");
577 break; 576 break;
578 case 2: 577 case 2:
579 udf_debug("ISO9660 Supplementary Volume Descriptor found\n"); 578 udf_debug
580 break; 579 ("ISO9660 Supplementary Volume Descriptor found\n");
581 case 3: 580 break;
582 udf_debug("ISO9660 Volume Partition Descriptor found\n"); 581 case 3:
583 break; 582 udf_debug
584 case 255: 583 ("ISO9660 Volume Partition Descriptor found\n");
585 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n"); 584 break;
586 break; 585 case 255:
587 default: 586 udf_debug
588 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType); 587 ("ISO9660 Volume Descriptor Set Terminator found\n");
589 break; 588 break;
589 default:
590 udf_debug("ISO9660 VRS (%u) found\n",
591 vsd->structType);
592 break;
590 } 593 }
591 } 594 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) {
592 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) 595 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) {
593 {
594 }
595 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN))
596 {
597 brelse(bh); 596 brelse(bh);
598 break; 597 break;
599 } 598 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) {
600 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
601 {
602 nsr02 = sector; 599 nsr02 = sector;
603 } 600 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) {
604 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
605 {
606 nsr03 = sector; 601 nsr03 = sector;
607 } 602 }
608 brelse(bh); 603 brelse(bh);
@@ -635,8 +630,7 @@ udf_vrs(struct super_block *sb, int silent)
635 * July 1, 1997 - Andrew E. Mileski 630 * July 1, 1997 - Andrew E. Mileski
636 * Written, tested, and released. 631 * Written, tested, and released.
637 */ 632 */
638static void 633static void udf_find_anchor(struct super_block *sb)
639udf_find_anchor(struct super_block *sb)
640{ 634{
641 int lastblock = UDF_SB_LASTBLOCK(sb); 635 int lastblock = UDF_SB_LASTBLOCK(sb);
642 struct buffer_head *bh = NULL; 636 struct buffer_head *bh = NULL;
@@ -644,8 +638,7 @@ udf_find_anchor(struct super_block *sb)
644 uint32_t location; 638 uint32_t location;
645 int i; 639 int i;
646 640
647 if (lastblock) 641 if (lastblock) {
648 {
649 int varlastblock = udf_variable_to_fixed(lastblock); 642 int varlastblock = udf_variable_to_fixed(lastblock);
650 int last[] = { lastblock, lastblock - 2, 643 int last[] = { lastblock, lastblock - 2,
651 lastblock - 150, lastblock - 152, 644 lastblock - 150, lastblock - 152,
@@ -663,74 +656,54 @@ udf_find_anchor(struct super_block *sb)
663 * however, if the disc isn't closed, it could be 512 */ 656 * however, if the disc isn't closed, it could be 512 */
664 657
665 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) { 658 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
666 if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) 659 if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) {
667 {
668 ident = location = 0; 660 ident = location = 0;
669 } 661 } else {
670 else
671 {
672 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 662 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
673 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 663 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
674 brelse(bh); 664 brelse(bh);
675 } 665 }
676 666
677 if (ident == TAG_IDENT_AVDP) 667 if (ident == TAG_IDENT_AVDP) {
678 { 668 if (location == last[i] - UDF_SB_SESSION(sb)) {
679 if (location == last[i] - UDF_SB_SESSION(sb))
680 {
681 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb); 669 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb);
682 UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb); 670 UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb);
683 } 671 } else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) {
684 else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb))
685 {
686 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 672 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
687 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb); 673 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
688 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb); 674 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
689 } 675 } else {
690 else
691 udf_debug("Anchor found at block %d, location mismatch %d.\n", 676 udf_debug("Anchor found at block %d, location mismatch %d.\n",
692 last[i], location); 677 last[i], location);
693 } 678 }
694 else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) 679 } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) {
695 {
696 lastblock = last[i]; 680 lastblock = last[i];
697 UDF_SB_ANCHOR(sb)[3] = 512; 681 UDF_SB_ANCHOR(sb)[3] = 512;
698 } 682 } else {
699 else 683 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256))) {
700 {
701 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
702 {
703 ident = location = 0; 684 ident = location = 0;
704 } 685 } else {
705 else
706 {
707 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 686 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
708 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 687 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
709 brelse(bh); 688 brelse(bh);
710 } 689 }
711 690
712 if (ident == TAG_IDENT_AVDP && 691 if (ident == TAG_IDENT_AVDP &&
713 location == last[i] - 256 - UDF_SB_SESSION(sb)) 692 location == last[i] - 256 - UDF_SB_SESSION(sb)) {
714 {
715 lastblock = last[i]; 693 lastblock = last[i];
716 UDF_SB_ANCHOR(sb)[1] = last[i] - 256; 694 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
717 } 695 } else {
718 else 696 if (last[i] < 312 + UDF_SB_SESSION(sb) ||
719 { 697 !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb)))) {
720 if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb))))
721 {
722 ident = location = 0; 698 ident = location = 0;
723 } 699 } else {
724 else
725 {
726 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 700 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
727 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 701 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
728 brelse(bh); 702 brelse(bh);
729 } 703 }
730 704
731 if (ident == TAG_IDENT_AVDP && 705 if (ident == TAG_IDENT_AVDP &&
732 location == udf_variable_to_fixed(last[i]) - 256) 706 location == udf_variable_to_fixed(last[i]) - 256) {
733 {
734 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 707 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
735 lastblock = udf_variable_to_fixed(last[i]); 708 lastblock = udf_variable_to_fixed(last[i]);
736 UDF_SB_ANCHOR(sb)[1] = lastblock - 256; 709 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
@@ -740,11 +713,9 @@ udf_find_anchor(struct super_block *sb)
740 } 713 }
741 } 714 }
742 715
743 if (!lastblock) 716 if (!lastblock) {
744 {
745 /* We havn't found the lastblock. check 312 */ 717 /* We havn't found the lastblock. check 312 */
746 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) 718 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) {
747 {
748 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 719 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
749 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 720 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
750 brelse(bh); 721 brelse(bh);
@@ -755,19 +726,14 @@ udf_find_anchor(struct super_block *sb)
755 } 726 }
756 727
757 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { 728 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
758 if (UDF_SB_ANCHOR(sb)[i]) 729 if (UDF_SB_ANCHOR(sb)[i]) {
759 { 730 if (!(bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
760 if (!(bh = udf_read_tagged(sb, 731 UDF_SB_ANCHOR(sb)[i], &ident))) {
761 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
762 {
763 UDF_SB_ANCHOR(sb)[i] = 0; 732 UDF_SB_ANCHOR(sb)[i] = 0;
764 } 733 } else {
765 else
766 {
767 brelse(bh); 734 brelse(bh);
768 if ((ident != TAG_IDENT_AVDP) && (i || 735 if ((ident != TAG_IDENT_AVDP) &&
769 (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) 736 (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) {
770 {
771 UDF_SB_ANCHOR(sb)[i] = 0; 737 UDF_SB_ANCHOR(sb)[i] = 0;
772 } 738 }
773 } 739 }
@@ -777,89 +743,78 @@ udf_find_anchor(struct super_block *sb)
777 UDF_SB_LASTBLOCK(sb) = lastblock; 743 UDF_SB_LASTBLOCK(sb) = lastblock;
778} 744}
779 745
780static int 746static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
781udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
782{ 747{
783 struct buffer_head *bh = NULL; 748 struct buffer_head *bh = NULL;
784 long lastblock; 749 long lastblock;
785 uint16_t ident; 750 uint16_t ident;
786 751
787 if (fileset->logicalBlockNum != 0xFFFFFFFF || 752 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
788 fileset->partitionReferenceNum != 0xFFFF) 753 fileset->partitionReferenceNum != 0xFFFF) {
789 {
790 bh = udf_read_ptagged(sb, *fileset, 0, &ident); 754 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
791 755
792 if (!bh) 756 if (!bh) {
793 return 1; 757 return 1;
794 else if (ident != TAG_IDENT_FSD) 758 } else if (ident != TAG_IDENT_FSD) {
795 {
796 brelse(bh); 759 brelse(bh);
797 return 1; 760 return 1;
798 } 761 }
799 762
800 } 763 }
801 764
802 if (!bh) /* Search backwards through the partitions */ 765 if (!bh) { /* Search backwards through the partitions */
803 {
804 kernel_lb_addr newfileset; 766 kernel_lb_addr newfileset;
805 767
768/* --> cvg: FIXME - is it reasonable? */
806 return 1; 769 return 1;
807 770
808 for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1; 771 for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
809 (newfileset.partitionReferenceNum != 0xFFFF && 772 (newfileset.partitionReferenceNum != 0xFFFF &&
810 fileset->logicalBlockNum == 0xFFFFFFFF && 773 fileset->logicalBlockNum == 0xFFFFFFFF &&
811 fileset->partitionReferenceNum == 0xFFFF); 774 fileset->partitionReferenceNum == 0xFFFF);
812 newfileset.partitionReferenceNum--) 775 newfileset.partitionReferenceNum--) {
813 {
814 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum); 776 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
815 newfileset.logicalBlockNum = 0; 777 newfileset.logicalBlockNum = 0;
816 778
817 do 779 do {
818 {
819 bh = udf_read_ptagged(sb, newfileset, 0, &ident); 780 bh = udf_read_ptagged(sb, newfileset, 0, &ident);
820 if (!bh) 781 if (!bh) {
821 { 782 newfileset.logicalBlockNum++;
822 newfileset.logicalBlockNum ++;
823 continue; 783 continue;
824 } 784 }
825 785
826 switch (ident) 786 switch (ident) {
787 case TAG_IDENT_SBD:
827 { 788 {
828 case TAG_IDENT_SBD: 789 struct spaceBitmapDesc *sp;
829 { 790 sp = (struct spaceBitmapDesc *)bh->b_data;
830 struct spaceBitmapDesc *sp; 791 newfileset.logicalBlockNum += 1 +
831 sp = (struct spaceBitmapDesc *)bh->b_data; 792 ((le32_to_cpu(sp->numOfBytes) +
832 newfileset.logicalBlockNum += 1 + 793 sizeof(struct spaceBitmapDesc) - 1)
833 ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1) 794 >> sb->s_blocksize_bits);
834 >> sb->s_blocksize_bits); 795 brelse(bh);
835 brelse(bh); 796 break;
836 break;
837 }
838 case TAG_IDENT_FSD:
839 {
840 *fileset = newfileset;
841 break;
842 }
843 default:
844 {
845 newfileset.logicalBlockNum ++;
846 brelse(bh);
847 bh = NULL;
848 break;
849 }
850 } 797 }
851 } 798 case TAG_IDENT_FSD:
852 while (newfileset.logicalBlockNum < lastblock && 799 *fileset = newfileset;
853 fileset->logicalBlockNum == 0xFFFFFFFF && 800 break;
854 fileset->partitionReferenceNum == 0xFFFF); 801 default:
802 newfileset.logicalBlockNum++;
803 brelse(bh);
804 bh = NULL;
805 break;
806 }
807 } while (newfileset.logicalBlockNum < lastblock &&
808 fileset->logicalBlockNum == 0xFFFFFFFF &&
809 fileset->partitionReferenceNum == 0xFFFF);
855 } 810 }
856 } 811 }
857 812
858 if ((fileset->logicalBlockNum != 0xFFFFFFFF || 813 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
859 fileset->partitionReferenceNum != 0xFFFF) && bh) 814 fileset->partitionReferenceNum != 0xFFFF) && bh) {
860 {
861 udf_debug("Fileset at block=%d, partition=%d\n", 815 udf_debug("Fileset at block=%d, partition=%d\n",
862 fileset->logicalBlockNum, fileset->partitionReferenceNum); 816 fileset->logicalBlockNum,
817 fileset->partitionReferenceNum);
863 818
864 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum; 819 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
865 udf_load_fileset(sb, bh, root); 820 udf_load_fileset(sb, bh, root);
@@ -869,8 +824,7 @@ udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr
869 return 1; 824 return 1;
870} 825}
871 826
872static void 827static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
873udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
874{ 828{
875 struct primaryVolDesc *pvoldesc; 829 struct primaryVolDesc *pvoldesc;
876 time_t recording; 830 time_t recording;
@@ -880,37 +834,34 @@ udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
880 834
881 pvoldesc = (struct primaryVolDesc *)bh->b_data; 835 pvoldesc = (struct primaryVolDesc *)bh->b_data;
882 836
883 if ( udf_stamp_to_time(&recording, &recording_usec, 837 if (udf_stamp_to_time(&recording, &recording_usec,
884 lets_to_cpu(pvoldesc->recordingDateAndTime)) ) 838 lets_to_cpu(pvoldesc->recordingDateAndTime))) {
885 {
886 kernel_timestamp ts; 839 kernel_timestamp ts;
887 ts = lets_to_cpu(pvoldesc->recordingDateAndTime); 840 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
888 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n", 841 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
889 recording, recording_usec, 842 recording, recording_usec,
890 ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone); 843 ts.year, ts.month, ts.day, ts.hour,
844 ts.minute, ts.typeAndTimezone);
891 UDF_SB_RECORDTIME(sb).tv_sec = recording; 845 UDF_SB_RECORDTIME(sb).tv_sec = recording;
892 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000; 846 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
893 } 847 }
894 848
895 if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) ) 849 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
896 { 850 if (udf_CS0toUTF8(&outstr, &instr)) {
897 if (udf_CS0toUTF8(&outstr, &instr)) 851 strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name,
898 {
899 strncpy( UDF_SB_VOLIDENT(sb), outstr.u_name,
900 outstr.u_len > 31 ? 31 : outstr.u_len); 852 outstr.u_len > 31 ? 31 : outstr.u_len);
901 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb)); 853 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
902 } 854 }
903 } 855 }
904 856
905 if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) ) 857 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
906 {
907 if (udf_CS0toUTF8(&outstr, &instr)) 858 if (udf_CS0toUTF8(&outstr, &instr))
908 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); 859 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
909 } 860 }
910} 861}
911 862
912static void 863static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
913udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr *root) 864 kernel_lb_addr *root)
914{ 865{
915 struct fileSetDesc *fset; 866 struct fileSetDesc *fset;
916 867
@@ -920,24 +871,21 @@ udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr
920 871
921 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum); 872 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
922 873
923 udf_debug("Rootdir at block=%d, partition=%d\n", 874 udf_debug("Rootdir at block=%d, partition=%d\n",
924 root->logicalBlockNum, root->partitionReferenceNum); 875 root->logicalBlockNum, root->partitionReferenceNum);
925} 876}
926 877
927static void 878static void udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
928udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
929{ 879{
930 struct partitionDesc *p; 880 struct partitionDesc *p;
931 int i; 881 int i;
932 882
933 p = (struct partitionDesc *)bh->b_data; 883 p = (struct partitionDesc *)bh->b_data;
934 884
935 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 885 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
936 { 886 udf_debug("Searching map: (%d == %d)\n",
937 udf_debug("Searching map: (%d == %d)\n", 887 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
938 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber)); 888 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) {
939 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber))
940 {
941 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */ 889 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
942 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation); 890 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation);
943 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) 891 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
@@ -950,79 +898,76 @@ udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
950 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE; 898 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
951 899
952 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) || 900 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
953 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) 901 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) {
954 {
955 struct partitionHeaderDesc *phd; 902 struct partitionHeaderDesc *phd;
956 903
957 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); 904 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
958 if (phd->unallocSpaceTable.extLength) 905 if (phd->unallocSpaceTable.extLength) {
959 { 906 kernel_lb_addr loc = {
960 kernel_lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i }; 907 .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
908 .partitionReferenceNum = i,
909 };
961 910
962 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table = 911 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
963 udf_iget(sb, loc); 912 udf_iget(sb, loc);
964 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE; 913 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
965 udf_debug("unallocSpaceTable (part %d) @ %ld\n", 914 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
966 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino); 915 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
967 } 916 }
968 if (phd->unallocSpaceBitmap.extLength) 917 if (phd->unallocSpaceBitmap.extLength) {
969 {
970 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace); 918 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
971 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) 919 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) {
972 {
973 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength = 920 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
974 le32_to_cpu(phd->unallocSpaceBitmap.extLength); 921 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
975 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition = 922 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
976 le32_to_cpu(phd->unallocSpaceBitmap.extPosition); 923 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
977 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP; 924 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
978 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", 925 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
979 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition); 926 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
980 } 927 }
981 } 928 }
982 if (phd->partitionIntegrityTable.extLength) 929 if (phd->partitionIntegrityTable.extLength)
983 udf_debug("partitionIntegrityTable (part %d)\n", i); 930 udf_debug("partitionIntegrityTable (part %d)\n", i);
984 if (phd->freedSpaceTable.extLength) 931 if (phd->freedSpaceTable.extLength) {
985 { 932 kernel_lb_addr loc = {
986 kernel_lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i }; 933 .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
934 .partitionReferenceNum = i,
935 };
987 936
988 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table = 937 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
989 udf_iget(sb, loc); 938 udf_iget(sb, loc);
990 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE; 939 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
991 udf_debug("freedSpaceTable (part %d) @ %ld\n", 940 udf_debug("freedSpaceTable (part %d) @ %ld\n",
992 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino); 941 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
993 } 942 }
994 if (phd->freedSpaceBitmap.extLength) 943 if (phd->freedSpaceBitmap.extLength) {
995 {
996 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace); 944 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
997 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) 945 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) {
998 {
999 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength = 946 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
1000 le32_to_cpu(phd->freedSpaceBitmap.extLength); 947 le32_to_cpu(phd->freedSpaceBitmap.extLength);
1001 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition = 948 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
1002 le32_to_cpu(phd->freedSpaceBitmap.extPosition); 949 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
1003 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP; 950 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
1004 udf_debug("freedSpaceBitmap (part %d) @ %d\n", 951 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1005 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition); 952 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
1006 } 953 }
1007 } 954 }
1008 } 955 }
1009 break; 956 break;
1010 } 957 }
1011 } 958 }
1012 if (i == UDF_SB_NUMPARTS(sb)) 959 if (i == UDF_SB_NUMPARTS(sb)) {
1013 { 960 udf_debug("Partition (%d) not found in partition map\n",
1014 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p->partitionNumber)); 961 le16_to_cpu(p->partitionNumber));
1015 } 962 } else {
1016 else
1017 {
1018 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n", 963 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1019 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i), 964 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
1020 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i)); 965 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
1021 } 966 }
1022} 967}
1023 968
1024static int 969static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1025udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_addr *fileset) 970 kernel_lb_addr *fileset)
1026{ 971{
1027 struct logicalVolDesc *lvd; 972 struct logicalVolDesc *lvd;
1028 int i, j, offset; 973 int i, j, offset;
@@ -1032,37 +977,27 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1032 977
1033 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps)); 978 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1034 979
1035 for (i=0,offset=0; 980 for (i = 0, offset = 0;
1036 i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength); 981 i < UDF_SB_NUMPARTS(sb) && offset < le32_to_cpu(lvd->mapTableLength);
1037 i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) 982 i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) {
1038 {
1039 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; 983 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
1040 if (type == 1) 984 if (type == 1) {
1041 {
1042 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); 985 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
1043 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15; 986 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
1044 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum); 987 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
1045 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum); 988 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
1046 UDF_SB_PARTFUNC(sb,i) = NULL; 989 UDF_SB_PARTFUNC(sb,i) = NULL;
1047 } 990 } else if (type == 2) {
1048 else if (type == 2)
1049 {
1050 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); 991 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
1051 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) 992 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) {
1052 { 993 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) {
1053 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150)
1054 {
1055 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15; 994 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
1056 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15; 995 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
1057 } 996 } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) {
1058 else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200)
1059 {
1060 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20; 997 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
1061 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20; 998 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
1062 } 999 }
1063 } 1000 } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) {
1064 else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))
1065 {
1066 uint32_t loc; 1001 uint32_t loc;
1067 uint16_t ident; 1002 uint16_t ident;
1068 struct sparingTable *st; 1003 struct sparingTable *st;
@@ -1070,26 +1005,21 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1070 1005
1071 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15; 1006 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
1072 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength); 1007 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
1073 for (j=0; j<spm->numSparingTables; j++) 1008 for (j = 0; j < spm->numSparingTables; j++) {
1074 {
1075 loc = le32_to_cpu(spm->locSparingTable[j]); 1009 loc = le32_to_cpu(spm->locSparingTable[j]);
1076 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = 1010 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
1077 udf_read_tagged(sb, loc, loc, &ident); 1011 udf_read_tagged(sb, loc, loc, &ident);
1078 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) 1012 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) {
1079 {
1080 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data; 1013 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
1081 if (ident != 0 || 1014 if (ident != 0 ||
1082 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) 1015 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) {
1083 {
1084 brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]); 1016 brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
1085 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL; 1017 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
1086 } 1018 }
1087 } 1019 }
1088 } 1020 }
1089 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15; 1021 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
1090 } 1022 } else {
1091 else
1092 {
1093 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident); 1023 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
1094 continue; 1024 continue;
1095 } 1025 }
@@ -1097,20 +1027,20 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1097 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum); 1027 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
1098 } 1028 }
1099 udf_debug("Partition (%d:%d) type %d on volume %d\n", 1029 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1100 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i)); 1030 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
1101 } 1031 }
1102 1032
1103 if (fileset) 1033 if (fileset) {
1104 {
1105 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]); 1034 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1106 1035
1107 *fileset = lelb_to_cpu(la->extLocation); 1036 *fileset = lelb_to_cpu(la->extLocation);
1108 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n", 1037 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1109 fileset->logicalBlockNum, 1038 fileset->logicalBlockNum,
1110 fileset->partitionReferenceNum); 1039 fileset->partitionReferenceNum);
1111 } 1040 }
1112 if (lvd->integritySeqExt.extLength) 1041 if (lvd->integritySeqExt.extLength)
1113 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); 1042 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1043
1114 return 0; 1044 return 0;
1115} 1045}
1116 1046
@@ -1118,26 +1048,24 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1118 * udf_load_logicalvolint 1048 * udf_load_logicalvolint
1119 * 1049 *
1120 */ 1050 */
1121static void 1051static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1122udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1123{ 1052{
1124 struct buffer_head *bh = NULL; 1053 struct buffer_head *bh = NULL;
1125 uint16_t ident; 1054 uint16_t ident;
1126 1055
1127 while (loc.extLength > 0 && 1056 while (loc.extLength > 0 &&
1128 (bh = udf_read_tagged(sb, loc.extLocation, 1057 (bh = udf_read_tagged(sb, loc.extLocation,
1129 loc.extLocation, &ident)) && 1058 loc.extLocation, &ident)) &&
1130 ident == TAG_IDENT_LVID) 1059 ident == TAG_IDENT_LVID) {
1131 {
1132 UDF_SB_LVIDBH(sb) = bh; 1060 UDF_SB_LVIDBH(sb) = bh;
1133 1061
1134 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength) 1062 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
1135 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt)); 1063 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
1136 1064
1137 if (UDF_SB_LVIDBH(sb) != bh) 1065 if (UDF_SB_LVIDBH(sb) != bh)
1138 brelse(bh); 1066 brelse(bh);
1139 loc.extLength -= sb->s_blocksize; 1067 loc.extLength -= sb->s_blocksize;
1140 loc.extLocation ++; 1068 loc.extLocation++;
1141 } 1069 }
1142 if (UDF_SB_LVIDBH(sb) != bh) 1070 if (UDF_SB_LVIDBH(sb) != bh)
1143 brelse(bh); 1071 brelse(bh);
@@ -1158,15 +1086,15 @@ udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1158 * July 1, 1997 - Andrew E. Mileski 1086 * July 1, 1997 - Andrew E. Mileski
1159 * Written, tested, and released. 1087 * Written, tested, and released.
1160 */ 1088 */
1161static int 1089static int udf_process_sequence(struct super_block *sb, long block, long lastblock,
1162udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_lb_addr *fileset) 1090 kernel_lb_addr *fileset)
1163{ 1091{
1164 struct buffer_head *bh = NULL; 1092 struct buffer_head *bh = NULL;
1165 struct udf_vds_record vds[VDS_POS_LENGTH]; 1093 struct udf_vds_record vds[VDS_POS_LENGTH];
1166 struct generic_desc *gd; 1094 struct generic_desc *gd;
1167 struct volDescPtr *vdp; 1095 struct volDescPtr *vdp;
1168 int done=0; 1096 int done = 0;
1169 int i,j; 1097 int i, j;
1170 uint32_t vdsn; 1098 uint32_t vdsn;
1171 uint16_t ident; 1099 uint16_t ident;
1172 long next_s = 0, next_e = 0; 1100 long next_s = 0, next_e = 0;
@@ -1174,93 +1102,81 @@ udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_
1174 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); 1102 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1175 1103
1176 /* Read the main descriptor sequence */ 1104 /* Read the main descriptor sequence */
1177 for (;(!done && block <= lastblock); block++) 1105 for (; (!done && block <= lastblock); block++) {
1178 {
1179 1106
1180 bh = udf_read_tagged(sb, block, block, &ident); 1107 bh = udf_read_tagged(sb, block, block, &ident);
1181 if (!bh) 1108 if (!bh)
1182 break; 1109 break;
1183 1110
1184 /* Process each descriptor (ISO 13346 3/8.3-8.4) */ 1111 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1185 gd = (struct generic_desc *)bh->b_data; 1112 gd = (struct generic_desc *)bh->b_data;
1186 vdsn = le32_to_cpu(gd->volDescSeqNum); 1113 vdsn = le32_to_cpu(gd->volDescSeqNum);
1187 switch (ident) 1114 switch (ident) {
1188 { 1115 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1189 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ 1116 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
1190 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) 1117 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
1191 { 1118 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1192 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; 1119 }
1193 vds[VDS_POS_PRIMARY_VOL_DESC].block = block; 1120 break;
1194 } 1121 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1195 break; 1122 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
1196 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ 1123 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1197 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) 1124 vds[VDS_POS_VOL_DESC_PTR].block = block;
1198 { 1125
1199 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; 1126 vdp = (struct volDescPtr *)bh->b_data;
1200 vds[VDS_POS_VOL_DESC_PTR].block = block; 1127 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1201 1128 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
1202 vdp = (struct volDescPtr *)bh->b_data; 1129 next_e = next_e >> sb->s_blocksize_bits;
1203 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); 1130 next_e += next_s;
1204 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); 1131 }
1205 next_e = next_e >> sb->s_blocksize_bits; 1132 break;
1206 next_e += next_s; 1133 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1207 } 1134 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
1208 break; 1135 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
1209 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ 1136 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1210 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) 1137 }
1211 { 1138 break;
1212 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; 1139 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1213 vds[VDS_POS_IMP_USE_VOL_DESC].block = block; 1140 if (!vds[VDS_POS_PARTITION_DESC].block)
1214 } 1141 vds[VDS_POS_PARTITION_DESC].block = block;
1215 break; 1142 break;
1216 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ 1143 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1217 if (!vds[VDS_POS_PARTITION_DESC].block) 1144 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
1218 vds[VDS_POS_PARTITION_DESC].block = block; 1145 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
1219 break; 1146 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1220 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ 1147 }
1221 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) 1148 break;
1222 { 1149 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1223 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; 1150 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
1224 vds[VDS_POS_LOGICAL_VOL_DESC].block = block; 1151 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
1225 } 1152 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1226 break; 1153 }
1227 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ 1154 break;
1228 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) 1155 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1229 { 1156 vds[VDS_POS_TERMINATING_DESC].block = block;
1230 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; 1157 if (next_e) {
1231 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; 1158 block = next_s;
1232 } 1159 lastblock = next_e;
1233 break; 1160 next_s = next_e = 0;
1234 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ 1161 } else {
1235 vds[VDS_POS_TERMINATING_DESC].block = block; 1162 done = 1;
1236 if (next_e) 1163 }
1237 { 1164 break;
1238 block = next_s;
1239 lastblock = next_e;
1240 next_s = next_e = 0;
1241 }
1242 else
1243 done = 1;
1244 break;
1245 } 1165 }
1246 brelse(bh); 1166 brelse(bh);
1247 } 1167 }
1248 for (i=0; i<VDS_POS_LENGTH; i++) 1168 for (i = 0; i < VDS_POS_LENGTH; i++) {
1249 { 1169 if (vds[i].block) {
1250 if (vds[i].block)
1251 {
1252 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident); 1170 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
1253 1171
1254 if (i == VDS_POS_PRIMARY_VOL_DESC) 1172 if (i == VDS_POS_PRIMARY_VOL_DESC) {
1255 udf_load_pvoldesc(sb, bh); 1173 udf_load_pvoldesc(sb, bh);
1256 else if (i == VDS_POS_LOGICAL_VOL_DESC) 1174 } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
1257 udf_load_logicalvol(sb, bh, fileset); 1175 udf_load_logicalvol(sb, bh, fileset);
1258 else if (i == VDS_POS_PARTITION_DESC) 1176 } else if (i == VDS_POS_PARTITION_DESC) {
1259 {
1260 struct buffer_head *bh2 = NULL; 1177 struct buffer_head *bh2 = NULL;
1261 udf_load_partdesc(sb, bh); 1178 udf_load_partdesc(sb, bh);
1262 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++) 1179 for (j = vds[i].block + 1; j < vds[VDS_POS_TERMINATING_DESC].block; j++) {
1263 {
1264 bh2 = udf_read_tagged(sb, j, j, &ident); 1180 bh2 = udf_read_tagged(sb, j, j, &ident);
1265 gd = (struct generic_desc *)bh2->b_data; 1181 gd = (struct generic_desc *)bh2->b_data;
1266 if (ident == TAG_IDENT_PD) 1182 if (ident == TAG_IDENT_PD)
@@ -1278,31 +1194,28 @@ udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_
1278/* 1194/*
1279 * udf_check_valid() 1195 * udf_check_valid()
1280 */ 1196 */
1281static int 1197static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1282udf_check_valid(struct super_block *sb, int novrs, int silent)
1283{ 1198{
1284 long block; 1199 long block;
1285 1200
1286 if (novrs) 1201 if (novrs) {
1287 {
1288 udf_debug("Validity check skipped because of novrs option\n"); 1202 udf_debug("Validity check skipped because of novrs option\n");
1289 return 0; 1203 return 0;
1290 } 1204 }
1291 /* Check that it is NSR02 compliant */ 1205 /* Check that it is NSR02 compliant */
1292 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ 1206 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1293 else if ((block = udf_vrs(sb, silent)) == -1) 1207 else if ((block = udf_vrs(sb, silent)) == -1) {
1294 { 1208 udf_debug("Failed to read byte 32768. Assuming open disc. "
1295 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n"); 1209 "Skipping validity check\n");
1296 if (!UDF_SB_LASTBLOCK(sb)) 1210 if (!UDF_SB_LASTBLOCK(sb))
1297 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); 1211 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1298 return 0; 1212 return 0;
1299 } 1213 } else {
1300 else
1301 return !block; 1214 return !block;
1215 }
1302} 1216}
1303 1217
1304static int 1218static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1305udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1306{ 1219{
1307 struct anchorVolDescPtr *anchor; 1220 struct anchorVolDescPtr *anchor;
1308 uint16_t ident; 1221 uint16_t ident;
@@ -1314,14 +1227,14 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1314 return 1; 1227 return 1;
1315 1228
1316 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { 1229 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
1317 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb, 1230 if (UDF_SB_ANCHOR(sb)[i] &&
1318 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident))) 1231 (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
1319 { 1232 UDF_SB_ANCHOR(sb)[i], &ident))) {
1320 anchor = (struct anchorVolDescPtr *)bh->b_data; 1233 anchor = (struct anchorVolDescPtr *)bh->b_data;
1321 1234
1322 /* Locate the main sequence */ 1235 /* Locate the main sequence */
1323 main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation ); 1236 main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1324 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength ); 1237 main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength );
1325 main_e = main_e >> sb->s_blocksize_bits; 1238 main_e = main_e >> sb->s_blocksize_bits;
1326 main_e += main_s; 1239 main_e += main_s;
1327 1240
@@ -1336,8 +1249,7 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1336 /* Process the main & reserve sequences */ 1249 /* Process the main & reserve sequences */
1337 /* responsible for finding the PartitionDesc(s) */ 1250 /* responsible for finding the PartitionDesc(s) */
1338 if (!(udf_process_sequence(sb, main_s, main_e, fileset) && 1251 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
1339 udf_process_sequence(sb, reserve_s, reserve_e, fileset))) 1252 udf_process_sequence(sb, reserve_s, reserve_e, fileset))) {
1340 {
1341 break; 1253 break;
1342 } 1254 }
1343 } 1255 }
@@ -1349,70 +1261,68 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1349 } else 1261 } else
1350 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]); 1262 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1351 1263
1352 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 1264 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
1353 { 1265 kernel_lb_addr uninitialized_var(ino);
1354 switch (UDF_SB_PARTTYPE(sb, i)) 1266 switch (UDF_SB_PARTTYPE(sb, i)) {
1355 { 1267 case UDF_VIRTUAL_MAP15:
1356 case UDF_VIRTUAL_MAP15: 1268 case UDF_VIRTUAL_MAP20:
1357 case UDF_VIRTUAL_MAP20: 1269 if (!UDF_SB_LASTBLOCK(sb)) {
1358 { 1270 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1359 kernel_lb_addr ino; 1271 udf_find_anchor(sb);
1272 }
1360 1273
1361 if (!UDF_SB_LASTBLOCK(sb)) 1274 if (!UDF_SB_LASTBLOCK(sb)) {
1362 { 1275 udf_debug("Unable to determine Lastblock (For "
1363 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); 1276 "Virtual Partition)\n");
1364 udf_find_anchor(sb); 1277 return 1;
1365 } 1278 }
1366 1279
1367 if (!UDF_SB_LASTBLOCK(sb)) 1280 for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
1368 { 1281 if (j != i && UDF_SB_PARTVSN(sb, i) ==
1369 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n"); 1282 UDF_SB_PARTVSN(sb, j) &&
1370 return 1; 1283 UDF_SB_PARTNUM(sb, i) ==
1284 UDF_SB_PARTNUM(sb, j)) {
1285 ino.partitionReferenceNum = j;
1286 ino.logicalBlockNum =
1287 UDF_SB_LASTBLOCK(sb) -
1288 UDF_SB_PARTROOT(sb, j);
1289 break;
1371 } 1290 }
1291 }
1372 1292
1373 for (j=0; j<UDF_SB_NUMPARTS(sb); j++) 1293 if (j == UDF_SB_NUMPARTS(sb))
1374 { 1294 return 1;
1375 if (j != i &&
1376 UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) &&
1377 UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j))
1378 {
1379 ino.partitionReferenceNum = j;
1380 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) -
1381 UDF_SB_PARTROOT(sb,j);
1382 break;
1383 }
1384 }
1385 1295
1386 if (j == UDF_SB_NUMPARTS(sb)) 1296 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1387 return 1; 1297 return 1;
1388 1298
1389 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino))) 1299 if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
1390 return 1; 1300 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
1301 udf_ext0_offset(UDF_SB_VAT(sb));
1302 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1303 (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1304 } else if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP20) {
1305 struct buffer_head *bh = NULL;
1306 uint32_t pos;
1391 1307
1392 if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15) 1308 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1393 { 1309 bh = sb_bread(sb, pos);
1394 UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb)); 1310 if (!bh)
1395 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2; 1311 return 1;
1396 } 1312 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
1397 else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20) 1313 le16_to_cpu(((struct
1398 { 1314 virtualAllocationTable20 *)bh->b_data +
1399 struct buffer_head *bh = NULL; 1315 udf_ext0_offset(UDF_SB_VAT(sb)))->
1400 uint32_t pos; 1316 lengthHeader) +
1401 1317 udf_ext0_offset(UDF_SB_VAT(sb));
1402 pos = udf_block_map(UDF_SB_VAT(sb), 0); 1318 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1403 bh = sb_bread(sb, pos); 1319 (UDF_SB_VAT(sb)->i_size -
1404 if (!bh) 1320 UDF_SB_TYPEVIRT(sb, i).s_start_offset) >> 2;
1405 return 1; 1321 brelse(bh);
1406 UDF_SB_TYPEVIRT(sb,i).s_start_offset =
1407 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
1408 udf_ext0_offset(UDF_SB_VAT(sb));
1409 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
1410 UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2;
1411 brelse(bh);
1412 }
1413 UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0);
1414 UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum);
1415 } 1322 }
1323 UDF_SB_PARTROOT(sb, i) = udf_get_pblock(sb, 0, i, 0);
1324 UDF_SB_PARTLEN(sb, i) = UDF_SB_PARTLEN(sb,
1325 ino.partitionReferenceNum);
1416 } 1326 }
1417 } 1327 }
1418 return 0; 1328 return 0;
@@ -1420,26 +1330,28 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1420 1330
1421static void udf_open_lvid(struct super_block *sb) 1331static void udf_open_lvid(struct super_block *sb)
1422{ 1332{
1423 if (UDF_SB_LVIDBH(sb)) 1333 if (UDF_SB_LVIDBH(sb)) {
1424 {
1425 int i; 1334 int i;
1426 kernel_timestamp cpu_time; 1335 kernel_timestamp cpu_time;
1427 1336
1428 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1337 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1429 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1338 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1430 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) 1339 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1431 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); 1340 UDF_SB_LVID(sb)->recordingDateAndTime =
1341 cpu_to_lets(cpu_time);
1432 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN; 1342 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1433 1343
1434 UDF_SB_LVID(sb)->descTag.descCRC = 1344 UDF_SB_LVID(sb)->descTag.descCRC =
1435 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), 1345 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1436 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); 1346 le16_to_cpu(UDF_SB_LVID(sb)->descTag.
1347 descCRCLength), 0));
1437 1348
1438 UDF_SB_LVID(sb)->descTag.tagChecksum = 0; 1349 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1439 for (i=0; i<16; i++) 1350 for (i = 0; i < 16; i++)
1440 if (i != 4) 1351 if (i != 4)
1441 UDF_SB_LVID(sb)->descTag.tagChecksum += 1352 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1442 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; 1353 ((uint8_t *) &
1354 (UDF_SB_LVID(sb)->descTag))[i];
1443 1355
1444 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 1356 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1445 } 1357 }
@@ -1447,12 +1359,11 @@ static void udf_open_lvid(struct super_block *sb)
1447 1359
1448static void udf_close_lvid(struct super_block *sb) 1360static void udf_close_lvid(struct super_block *sb)
1449{ 1361{
1450 if (UDF_SB_LVIDBH(sb) && 1362 kernel_timestamp cpu_time;
1451 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) 1363 int i;
1452 {
1453 int i;
1454 kernel_timestamp cpu_time;
1455 1364
1365 if (UDF_SB_LVIDBH(sb) &&
1366 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
1456 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1367 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1457 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1368 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1458 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) 1369 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
@@ -1467,10 +1378,10 @@ static void udf_close_lvid(struct super_block *sb)
1467 1378
1468 UDF_SB_LVID(sb)->descTag.descCRC = 1379 UDF_SB_LVID(sb)->descTag.descCRC =
1469 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), 1380 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1470 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); 1381 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1471 1382
1472 UDF_SB_LVID(sb)->descTag.tagChecksum = 0; 1383 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1473 for (i=0; i<16; i++) 1384 for (i = 0; i < 16; i++)
1474 if (i != 4) 1385 if (i != 4)
1475 UDF_SB_LVID(sb)->descTag.tagChecksum += 1386 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1476 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; 1387 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
@@ -1498,7 +1409,7 @@ static void udf_close_lvid(struct super_block *sb)
1498static int udf_fill_super(struct super_block *sb, void *options, int silent) 1409static int udf_fill_super(struct super_block *sb, void *options, int silent)
1499{ 1410{
1500 int i; 1411 int i;
1501 struct inode *inode=NULL; 1412 struct inode *inode = NULL;
1502 struct udf_options uopt; 1413 struct udf_options uopt;
1503 kernel_lb_addr rootdir, fileset; 1414 kernel_lb_addr rootdir, fileset;
1504 struct udf_sb_info *sbi; 1415 struct udf_sb_info *sbi;
@@ -1511,6 +1422,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1511 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL); 1422 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1512 if (!sbi) 1423 if (!sbi)
1513 return -ENOMEM; 1424 return -ENOMEM;
1425
1514 sb->s_fs_info = sbi; 1426 sb->s_fs_info = sbi;
1515 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info)); 1427 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1516 1428
@@ -1520,15 +1432,13 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1520 goto error_out; 1432 goto error_out;
1521 1433
1522 if (uopt.flags & (1 << UDF_FLAG_UTF8) && 1434 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1523 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) 1435 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
1524 {
1525 udf_error(sb, "udf_read_super", 1436 udf_error(sb, "udf_read_super",
1526 "utf8 cannot be combined with iocharset\n"); 1437 "utf8 cannot be combined with iocharset\n");
1527 goto error_out; 1438 goto error_out;
1528 } 1439 }
1529#ifdef CONFIG_UDF_NLS 1440#ifdef CONFIG_UDF_NLS
1530 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) 1441 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
1531 {
1532 uopt.nls_map = load_nls_default(); 1442 uopt.nls_map = load_nls_default();
1533 if (!uopt.nls_map) 1443 if (!uopt.nls_map)
1534 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP); 1444 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
@@ -1552,7 +1462,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1552 if (!udf_set_blocksize(sb, uopt.blocksize)) 1462 if (!udf_set_blocksize(sb, uopt.blocksize))
1553 goto error_out; 1463 goto error_out;
1554 1464
1555 if ( uopt.session == 0xFFFFFFFF ) 1465 if (uopt.session == 0xFFFFFFFF)
1556 UDF_SB_SESSION(sb) = udf_get_last_session(sb); 1466 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1557 else 1467 else
1558 UDF_SB_SESSION(sb) = uopt.session; 1468 UDF_SB_SESSION(sb) = uopt.session;
@@ -1564,10 +1474,9 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1564 UDF_SB_ANCHOR(sb)[2] = uopt.anchor; 1474 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1565 UDF_SB_ANCHOR(sb)[3] = 256; 1475 UDF_SB_ANCHOR(sb)[3] = 256;
1566 1476
1567 if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */ 1477 if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */
1568 {
1569 printk("UDF-fs: No VRS found\n"); 1478 printk("UDF-fs: No VRS found\n");
1570 goto error_out; 1479 goto error_out;
1571 } 1480 }
1572 1481
1573 udf_find_anchor(sb); 1482 udf_find_anchor(sb);
@@ -1579,29 +1488,24 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1579 sb->s_magic = UDF_SUPER_MAGIC; 1488 sb->s_magic = UDF_SUPER_MAGIC;
1580 sb->s_time_gran = 1000; 1489 sb->s_time_gran = 1000;
1581 1490
1582 if (udf_load_partition(sb, &fileset)) 1491 if (udf_load_partition(sb, &fileset)) {
1583 {
1584 printk("UDF-fs: No partition found (1)\n"); 1492 printk("UDF-fs: No partition found (1)\n");
1585 goto error_out; 1493 goto error_out;
1586 } 1494 }
1587 1495
1588 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb)); 1496 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1589 1497
1590 if ( UDF_SB_LVIDBH(sb) ) 1498 if (UDF_SB_LVIDBH(sb)) {
1591 {
1592 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev); 1499 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1593 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); 1500 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1594 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */ 1501 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1595 1502
1596 if (minUDFReadRev > UDF_MAX_READ_VERSION) 1503 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
1597 {
1598 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n", 1504 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1599 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev), 1505 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1600 UDF_MAX_READ_VERSION); 1506 UDF_MAX_READ_VERSION);
1601 goto error_out; 1507 goto error_out;
1602 } 1508 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
1603 else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1604 {
1605 sb->s_flags |= MS_RDONLY; 1509 sb->s_flags |= MS_RDONLY;
1606 } 1510 }
1607 1511
@@ -1613,8 +1517,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1613 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); 1517 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1614 } 1518 }
1615 1519
1616 if ( !UDF_SB_NUMPARTS(sb) ) 1520 if (!UDF_SB_NUMPARTS(sb)) {
1617 {
1618 printk("UDF-fs: No partition found (2)\n"); 1521 printk("UDF-fs: No partition found (2)\n");
1619 goto error_out; 1522 goto error_out;
1620 } 1523 }
@@ -1624,20 +1527,19 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1624 sb->s_flags |= MS_RDONLY; 1527 sb->s_flags |= MS_RDONLY;
1625 } 1528 }
1626 1529
1627 if ( udf_find_fileset(sb, &fileset, &rootdir) ) 1530 if (udf_find_fileset(sb, &fileset, &rootdir)) {
1628 {
1629 printk("UDF-fs: No fileset found\n"); 1531 printk("UDF-fs: No fileset found\n");
1630 goto error_out; 1532 goto error_out;
1631 } 1533 }
1632 1534
1633 if (!silent) 1535 if (!silent) {
1634 {
1635 kernel_timestamp ts; 1536 kernel_timestamp ts;
1636 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb)); 1537 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
1637 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n", 1538 udf_info("UDF %s (%s) Mounting volume '%s', "
1638 UDFFS_VERSION, UDFFS_DATE, 1539 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1639 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute, 1540 UDFFS_VERSION, UDFFS_DATE,
1640 ts.typeAndTimezone); 1541 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
1542 ts.typeAndTimezone);
1641 } 1543 }
1642 if (!(sb->s_flags & MS_RDONLY)) 1544 if (!(sb->s_flags & MS_RDONLY))
1643 udf_open_lvid(sb); 1545 udf_open_lvid(sb);
@@ -1645,18 +1547,16 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1645 /* Assign the root inode */ 1547 /* Assign the root inode */
1646 /* assign inodes by physical block number */ 1548 /* assign inodes by physical block number */
1647 /* perhaps it's not extensible enough, but for now ... */ 1549 /* perhaps it's not extensible enough, but for now ... */
1648 inode = udf_iget(sb, rootdir); 1550 inode = udf_iget(sb, rootdir);
1649 if (!inode) 1551 if (!inode) {
1650 {
1651 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n", 1552 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1652 rootdir.logicalBlockNum, rootdir.partitionReferenceNum); 1553 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1653 goto error_out; 1554 goto error_out;
1654 } 1555 }
1655 1556
1656 /* Allocate a dentry for the root inode */ 1557 /* Allocate a dentry for the root inode */
1657 sb->s_root = d_alloc_root(inode); 1558 sb->s_root = d_alloc_root(inode);
1658 if (!sb->s_root) 1559 if (!sb->s_root) {
1659 {
1660 printk("UDF-fs: Couldn't allocate root dentry\n"); 1560 printk("UDF-fs: Couldn't allocate root dentry\n");
1661 iput(inode); 1561 iput(inode);
1662 goto error_out; 1562 goto error_out;
@@ -1667,19 +1567,17 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1667error_out: 1567error_out:
1668 if (UDF_SB_VAT(sb)) 1568 if (UDF_SB_VAT(sb))
1669 iput(UDF_SB_VAT(sb)); 1569 iput(UDF_SB_VAT(sb));
1670 if (UDF_SB_NUMPARTS(sb)) 1570 if (UDF_SB_NUMPARTS(sb)) {
1671 {
1672 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 1571 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1673 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 1572 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1674 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 1573 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1675 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 1574 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1676 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 1575 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1677 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace); 1576 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace);
1678 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 1577 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1679 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace); 1578 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace);
1680 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) 1579 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
1681 { 1580 for (i = 0; i < 4; i++)
1682 for (i=0; i<4; i++)
1683 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); 1581 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1684 } 1582 }
1685 } 1583 }
@@ -1693,16 +1591,16 @@ error_out:
1693 UDF_SB_FREE(sb); 1591 UDF_SB_FREE(sb);
1694 kfree(sbi); 1592 kfree(sbi);
1695 sb->s_fs_info = NULL; 1593 sb->s_fs_info = NULL;
1594
1696 return -EINVAL; 1595 return -EINVAL;
1697} 1596}
1698 1597
1699void udf_error(struct super_block *sb, const char *function, 1598void udf_error(struct super_block *sb, const char *function,
1700 const char *fmt, ...) 1599 const char *fmt, ...)
1701{ 1600{
1702 va_list args; 1601 va_list args;
1703 1602
1704 if (!(sb->s_flags & MS_RDONLY)) 1603 if (!(sb->s_flags & MS_RDONLY)) {
1705 {
1706 /* mark sb error */ 1604 /* mark sb error */
1707 sb->s_dirt = 1; 1605 sb->s_dirt = 1;
1708 } 1606 }
@@ -1714,15 +1612,15 @@ void udf_error(struct super_block *sb, const char *function,
1714} 1612}
1715 1613
1716void udf_warning(struct super_block *sb, const char *function, 1614void udf_warning(struct super_block *sb, const char *function,
1717 const char *fmt, ...) 1615 const char *fmt, ...)
1718{ 1616{
1719 va_list args; 1617 va_list args;
1720 1618
1721 va_start (args, fmt); 1619 va_start(args, fmt);
1722 vsnprintf(error_buf, sizeof(error_buf), fmt, args); 1620 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1723 va_end(args); 1621 va_end(args);
1724 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n", 1622 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1725 sb->s_id, function, error_buf); 1623 sb->s_id, function, error_buf);
1726} 1624}
1727 1625
1728/* 1626/*
@@ -1738,26 +1636,23 @@ void udf_warning(struct super_block *sb, const char *function,
1738 * July 1, 1997 - Andrew E. Mileski 1636 * July 1, 1997 - Andrew E. Mileski
1739 * Written, tested, and released. 1637 * Written, tested, and released.
1740 */ 1638 */
1741static void 1639static void udf_put_super(struct super_block *sb)
1742udf_put_super(struct super_block *sb)
1743{ 1640{
1744 int i; 1641 int i;
1745 1642
1746 if (UDF_SB_VAT(sb)) 1643 if (UDF_SB_VAT(sb))
1747 iput(UDF_SB_VAT(sb)); 1644 iput(UDF_SB_VAT(sb));
1748 if (UDF_SB_NUMPARTS(sb)) 1645 if (UDF_SB_NUMPARTS(sb)) {
1749 {
1750 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 1646 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1751 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 1647 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1752 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 1648 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1753 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 1649 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1754 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 1650 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1755 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace); 1651 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace);
1756 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 1652 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1757 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace); 1653 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace);
1758 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) 1654 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
1759 { 1655 for (i = 0; i < 4; i++)
1760 for (i=0; i<4; i++)
1761 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); 1656 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1762 } 1657 }
1763 } 1658 }
@@ -1786,8 +1681,7 @@ udf_put_super(struct super_block *sb)
1786 * July 1, 1997 - Andrew E. Mileski 1681 * July 1, 1997 - Andrew E. Mileski
1787 * Written, tested, and released. 1682 * Written, tested, and released.
1788 */ 1683 */
1789static int 1684static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1790udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1791{ 1685{
1792 struct super_block *sb = dentry->d_sb; 1686 struct super_block *sb = dentry->d_sb;
1793 1687
@@ -1797,11 +1691,11 @@ udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1797 buf->f_bfree = udf_count_free(sb); 1691 buf->f_bfree = udf_count_free(sb);
1798 buf->f_bavail = buf->f_bfree; 1692 buf->f_bavail = buf->f_bfree;
1799 buf->f_files = (UDF_SB_LVIDBH(sb) ? 1693 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1800 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1694 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1801 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree; 1695 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
1802 buf->f_ffree = buf->f_bfree; 1696 buf->f_ffree = buf->f_bfree;
1803 /* __kernel_fsid_t f_fsid */ 1697 /* __kernel_fsid_t f_fsid */
1804 buf->f_namelen = UDF_NAME_LEN-2; 1698 buf->f_namelen = UDF_NAME_LEN - 2;
1805 1699
1806 return 0; 1700 return 0;
1807} 1701}
@@ -1810,8 +1704,7 @@ static unsigned char udf_bitmap_lookup[16] = {
1810 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 1704 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1811}; 1705};
1812 1706
1813static unsigned int 1707static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1814udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1815{ 1708{
1816 struct buffer_head *bh = NULL; 1709 struct buffer_head *bh = NULL;
1817 unsigned int accum = 0; 1710 unsigned int accum = 0;
@@ -1830,13 +1723,10 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1830 loc.partitionReferenceNum = UDF_SB_PARTITION(sb); 1723 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1831 bh = udf_read_ptagged(sb, loc, 0, &ident); 1724 bh = udf_read_ptagged(sb, loc, 0, &ident);
1832 1725
1833 if (!bh) 1726 if (!bh) {
1834 {
1835 printk(KERN_ERR "udf: udf_count_free failed\n"); 1727 printk(KERN_ERR "udf: udf_count_free failed\n");
1836 goto out; 1728 goto out;
1837 } 1729 } else if (ident != TAG_IDENT_SBD) {
1838 else if (ident != TAG_IDENT_SBD)
1839 {
1840 brelse(bh); 1730 brelse(bh);
1841 printk(KERN_ERR "udf: udf_count_free failed\n"); 1731 printk(KERN_ERR "udf: udf_count_free failed\n");
1842 goto out; 1732 goto out;
@@ -1847,23 +1737,19 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1847 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ 1737 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1848 ptr = (uint8_t *)bh->b_data; 1738 ptr = (uint8_t *)bh->b_data;
1849 1739
1850 while ( bytes > 0 ) 1740 while (bytes > 0) {
1851 { 1741 while ((bytes > 0) && (index < sb->s_blocksize)) {
1852 while ((bytes > 0) && (index < sb->s_blocksize))
1853 {
1854 value = ptr[index]; 1742 value = ptr[index];
1855 accum += udf_bitmap_lookup[ value & 0x0f ]; 1743 accum += udf_bitmap_lookup[value & 0x0f];
1856 accum += udf_bitmap_lookup[ value >> 4 ]; 1744 accum += udf_bitmap_lookup[value >> 4];
1857 index++; 1745 index++;
1858 bytes--; 1746 bytes--;
1859 } 1747 }
1860 if ( bytes ) 1748 if (bytes) {
1861 {
1862 brelse(bh); 1749 brelse(bh);
1863 newblock = udf_get_lb_pblock(sb, loc, ++block); 1750 newblock = udf_get_lb_pblock(sb, loc, ++block);
1864 bh = udf_tread(sb, newblock); 1751 bh = udf_tread(sb, newblock);
1865 if (!bh) 1752 if (!bh) {
1866 {
1867 udf_debug("read failed\n"); 1753 udf_debug("read failed\n");
1868 goto out; 1754 goto out;
1869 } 1755 }
@@ -1879,8 +1765,7 @@ out:
1879 return accum; 1765 return accum;
1880} 1766}
1881 1767
1882static unsigned int 1768static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table)
1883udf_count_free_table(struct super_block *sb, struct inode * table)
1884{ 1769{
1885 unsigned int accum = 0; 1770 unsigned int accum = 0;
1886 uint32_t elen; 1771 uint32_t elen;
@@ -1894,26 +1779,23 @@ udf_count_free_table(struct super_block *sb, struct inode * table)
1894 epos.offset = sizeof(struct unallocSpaceEntry); 1779 epos.offset = sizeof(struct unallocSpaceEntry);
1895 epos.bh = NULL; 1780 epos.bh = NULL;
1896 1781
1897 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 1782 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
1898 accum += (elen >> table->i_sb->s_blocksize_bits); 1783 accum += (elen >> table->i_sb->s_blocksize_bits);
1784 }
1899 brelse(epos.bh); 1785 brelse(epos.bh);
1900 1786
1901 unlock_kernel(); 1787 unlock_kernel();
1902 1788
1903 return accum; 1789 return accum;
1904} 1790}
1905 1791
1906static unsigned int 1792static unsigned int udf_count_free(struct super_block *sb)
1907udf_count_free(struct super_block *sb)
1908{ 1793{
1909 unsigned int accum = 0; 1794 unsigned int accum = 0;
1910 1795
1911 if (UDF_SB_LVIDBH(sb)) 1796 if (UDF_SB_LVIDBH(sb)) {
1912 { 1797 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) {
1913 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb))
1914 {
1915 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]); 1798 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
1916
1917 if (accum == 0xFFFFFFFF) 1799 if (accum == 0xFFFFFFFF)
1918 accum = 0; 1800 accum = 0;
1919 } 1801 }
@@ -1922,28 +1804,24 @@ udf_count_free(struct super_block *sb)
1922 if (accum) 1804 if (accum)
1923 return accum; 1805 return accum;
1924 1806
1925 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 1807 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) {
1926 {
1927 accum += udf_count_free_bitmap(sb, 1808 accum += udf_count_free_bitmap(sb,
1928 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap); 1809 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1929 } 1810 }
1930 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 1811 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) {
1931 {
1932 accum += udf_count_free_bitmap(sb, 1812 accum += udf_count_free_bitmap(sb,
1933 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap); 1813 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1934 } 1814 }
1935 if (accum) 1815 if (accum)
1936 return accum; 1816 return accum;
1937 1817
1938 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 1818 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) {
1939 {
1940 accum += udf_count_free_table(sb, 1819 accum += udf_count_free_table(sb,
1941 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 1820 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1942 } 1821 }
1943 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 1822 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) {
1944 {
1945 accum += udf_count_free_table(sb, 1823 accum += udf_count_free_table(sb,
1946 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 1824 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1947 } 1825 }
1948 1826
1949 return accum; 1827 return accum;
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
index 12613b680cc4..e6f933dd6a7b 100644
--- a/fs/udf/symlink.c
+++ b/fs/udf/symlink.c
@@ -11,7 +11,7 @@
11 * Each contributing author retains all rights to their own work. 11 * Each contributing author retains all rights to their own work.
12 * 12 *
13 * (C) 1998-2001 Ben Fennema 13 * (C) 1998-2001 Ben Fennema
14 * (C) 1999 Stelias Computing Inc 14 * (C) 1999 Stelias Computing Inc
15 * 15 *
16 * HISTORY 16 * HISTORY
17 * 17 *
@@ -39,35 +39,33 @@ static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char
39 int elen = 0; 39 int elen = 0;
40 char *p = to; 40 char *p = to;
41 41
42 while (elen < fromlen) 42 while (elen < fromlen) {
43 {
44 pc = (struct pathComponent *)(from + elen); 43 pc = (struct pathComponent *)(from + elen);
45 switch (pc->componentType) 44 switch (pc->componentType) {
46 { 45 case 1:
47 case 1: 46 if (pc->lengthComponentIdent == 0) {
48 if (pc->lengthComponentIdent == 0) 47 p = to;
49 {
50 p = to;
51 *p++ = '/';
52 }
53 break;
54 case 3:
55 memcpy(p, "../", 3);
56 p += 3;
57 break;
58 case 4:
59 memcpy(p, "./", 2);
60 p += 2;
61 /* that would be . - just ignore */
62 break;
63 case 5:
64 p += udf_get_filename(sb, pc->componentIdent, p, pc->lengthComponentIdent);
65 *p++ = '/'; 48 *p++ = '/';
66 break; 49 }
50 break;
51 case 3:
52 memcpy(p, "../", 3);
53 p += 3;
54 break;
55 case 4:
56 memcpy(p, "./", 2);
57 p += 2;
58 /* that would be . - just ignore */
59 break;
60 case 5:
61 p += udf_get_filename(sb, pc->componentIdent, p,
62 pc->lengthComponentIdent);
63 *p++ = '/';
64 break;
67 } 65 }
68 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; 66 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
69 } 67 }
70 if (p > to+1) 68 if (p > to + 1)
71 p[-1] = '\0'; 69 p[-1] = '\0';
72 else 70 else
73 p[0] = '\0'; 71 p[0] = '\0';
@@ -82,10 +80,9 @@ static int udf_symlink_filler(struct file *file, struct page *page)
82 char *p = kmap(page); 80 char *p = kmap(page);
83 81
84 lock_kernel(); 82 lock_kernel();
85 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 83 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
86 symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 84 symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
87 else 85 } else {
88 {
89 bh = sb_bread(inode->i_sb, udf_block_map(inode, 0)); 86 bh = sb_bread(inode->i_sb, udf_block_map(inode, 0));
90 87
91 if (!bh) 88 if (!bh)
@@ -102,6 +99,7 @@ static int udf_symlink_filler(struct file *file, struct page *page)
102 kunmap(page); 99 kunmap(page);
103 unlock_page(page); 100 unlock_page(page);
104 return 0; 101 return 0;
102
105out: 103out:
106 unlock_kernel(); 104 unlock_kernel();
107 SetPageError(page); 105 SetPageError(page);
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index 60d277644248..7fc3912885a5 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -28,35 +28,36 @@
28#include "udf_i.h" 28#include "udf_i.h"
29#include "udf_sb.h" 29#include "udf_sb.h"
30 30
31static void extent_trunc(struct inode * inode, struct extent_position *epos, 31static void extent_trunc(struct inode *inode, struct extent_position *epos,
32 kernel_lb_addr eloc, int8_t etype, uint32_t elen, uint32_t nelen) 32 kernel_lb_addr eloc, int8_t etype, uint32_t elen,
33 uint32_t nelen)
33{ 34{
34 kernel_lb_addr neloc = { 0, 0 }; 35 kernel_lb_addr neloc = {};
35 int last_block = (elen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 36 int last_block = (elen + inode->i_sb->s_blocksize - 1) >>
36 int first_block = (nelen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 37 inode->i_sb->s_blocksize_bits;
38 int first_block = (nelen + inode->i_sb->s_blocksize - 1) >>
39 inode->i_sb->s_blocksize_bits;
37 40
38 if (nelen) 41 if (nelen) {
39 { 42 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
40 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 43 udf_free_blocks(inode->i_sb, inode, eloc, 0,
41 { 44 last_block);
42 udf_free_blocks(inode->i_sb, inode, eloc, 0, last_block);
43 etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30); 45 etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30);
44 } 46 } else
45 else
46 neloc = eloc; 47 neloc = eloc;
47 nelen = (etype << 30) | nelen; 48 nelen = (etype << 30) | nelen;
48 } 49 }
49 50
50 if (elen != nelen) 51 if (elen != nelen) {
51 {
52 udf_write_aext(inode, epos, neloc, nelen, 0); 52 udf_write_aext(inode, epos, neloc, nelen, 0);
53 if (last_block - first_block > 0) 53 if (last_block - first_block > 0) {
54 {
55 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) 54 if (etype == (EXT_RECORDED_ALLOCATED >> 30))
56 mark_inode_dirty(inode); 55 mark_inode_dirty(inode);
57 56
58 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 57 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
59 udf_free_blocks(inode->i_sb, inode, eloc, first_block, last_block - first_block); 58 udf_free_blocks(inode->i_sb, inode, eloc,
59 first_block,
60 last_block - first_block);
60 } 61 }
61 } 62 }
62} 63}
@@ -67,7 +68,7 @@ static void extent_trunc(struct inode * inode, struct extent_position *epos,
67 */ 68 */
68void udf_truncate_tail_extent(struct inode *inode) 69void udf_truncate_tail_extent(struct inode *inode)
69{ 70{
70 struct extent_position epos = { NULL, 0, {0, 0}}; 71 struct extent_position epos = {};
71 kernel_lb_addr eloc; 72 kernel_lb_addr eloc;
72 uint32_t elen, nelen; 73 uint32_t elen, nelen;
73 uint64_t lbcount = 0; 74 uint64_t lbcount = 0;
@@ -89,8 +90,7 @@ void udf_truncate_tail_extent(struct inode *inode)
89 BUG(); 90 BUG();
90 91
91 /* Find the last extent in the file */ 92 /* Find the last extent in the file */
92 while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) 93 while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
93 {
94 etype = netype; 94 etype = netype;
95 lbcount += elen; 95 lbcount += elen;
96 if (lbcount > inode->i_size) { 96 if (lbcount > inode->i_size) {
@@ -123,7 +123,7 @@ void udf_truncate_tail_extent(struct inode *inode)
123 123
124void udf_discard_prealloc(struct inode *inode) 124void udf_discard_prealloc(struct inode *inode)
125{ 125{
126 struct extent_position epos = { NULL, 0, {0, 0}}; 126 struct extent_position epos = { NULL, 0, {0, 0} };
127 kernel_lb_addr eloc; 127 kernel_lb_addr eloc;
128 uint32_t elen; 128 uint32_t elen;
129 uint64_t lbcount = 0; 129 uint64_t lbcount = 0;
@@ -131,7 +131,7 @@ void udf_discard_prealloc(struct inode *inode)
131 int adsize; 131 int adsize;
132 132
133 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || 133 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
134 inode->i_size == UDF_I_LENEXTENTS(inode)) 134 inode->i_size == UDF_I_LENEXTENTS(inode))
135 return; 135 return;
136 136
137 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) 137 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
@@ -153,15 +153,21 @@ void udf_discard_prealloc(struct inode *inode)
153 lbcount -= elen; 153 lbcount -= elen;
154 extent_trunc(inode, &epos, eloc, etype, elen, 0); 154 extent_trunc(inode, &epos, eloc, etype, elen, 0);
155 if (!epos.bh) { 155 if (!epos.bh) {
156 UDF_I_LENALLOC(inode) = epos.offset - udf_file_entry_alloc_offset(inode); 156 UDF_I_LENALLOC(inode) =
157 epos.offset - udf_file_entry_alloc_offset(inode);
157 mark_inode_dirty(inode); 158 mark_inode_dirty(inode);
158 } else { 159 } else {
159 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data); 160 struct allocExtDesc *aed =
160 aed->lengthAllocDescs = cpu_to_le32(epos.offset - sizeof(struct allocExtDesc)); 161 (struct allocExtDesc *)(epos.bh->b_data);
161 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 162 aed->lengthAllocDescs =
163 cpu_to_le32(epos.offset -
164 sizeof(struct allocExtDesc));
165 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
166 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
162 udf_update_tag(epos.bh->b_data, epos.offset); 167 udf_update_tag(epos.bh->b_data, epos.offset);
163 else 168 else
164 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 169 udf_update_tag(epos.bh->b_data,
170 sizeof(struct allocExtDesc));
165 mark_buffer_dirty_inode(epos.bh, inode); 171 mark_buffer_dirty_inode(epos.bh, inode);
166 } 172 }
167 } 173 }
@@ -171,10 +177,10 @@ void udf_discard_prealloc(struct inode *inode)
171 brelse(epos.bh); 177 brelse(epos.bh);
172} 178}
173 179
174void udf_truncate_extents(struct inode * inode) 180void udf_truncate_extents(struct inode *inode)
175{ 181{
176 struct extent_position epos; 182 struct extent_position epos;
177 kernel_lb_addr eloc, neloc = { 0, 0 }; 183 kernel_lb_addr eloc, neloc = {};
178 uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; 184 uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc;
179 int8_t etype; 185 int8_t etype;
180 struct super_block *sb = inode->i_sb; 186 struct super_block *sb = inode->i_sb;
@@ -190,9 +196,9 @@ void udf_truncate_extents(struct inode * inode)
190 BUG(); 196 BUG();
191 197
192 etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset); 198 etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset);
193 byte_offset = (offset << sb->s_blocksize_bits) + (inode->i_size & (sb->s_blocksize-1)); 199 byte_offset = (offset << sb->s_blocksize_bits) +
194 if (etype != -1) 200 (inode->i_size & (sb->s_blocksize - 1));
195 { 201 if (etype != -1) {
196 epos.offset -= adsize; 202 epos.offset -= adsize;
197 extent_trunc(inode, &epos, eloc, etype, elen, byte_offset); 203 extent_trunc(inode, &epos, eloc, etype, elen, byte_offset);
198 epos.offset += adsize; 204 epos.offset += adsize;
@@ -206,35 +212,33 @@ void udf_truncate_extents(struct inode * inode)
206 else 212 else
207 lenalloc -= sizeof(struct allocExtDesc); 213 lenalloc -= sizeof(struct allocExtDesc);
208 214
209 while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) 215 while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) {
210 { 216 if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
211 if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30))
212 {
213 udf_write_aext(inode, &epos, neloc, nelen, 0); 217 udf_write_aext(inode, &epos, neloc, nelen, 0);
214 if (indirect_ext_len) 218 if (indirect_ext_len) {
215 {
216 /* We managed to free all extents in the 219 /* We managed to free all extents in the
217 * indirect extent - free it too */ 220 * indirect extent - free it too */
218 if (!epos.bh) 221 if (!epos.bh)
219 BUG(); 222 BUG();
220 udf_free_blocks(sb, inode, epos.block, 0, indirect_ext_len); 223 udf_free_blocks(sb, inode, epos.block,
221 } 224 0, indirect_ext_len);
222 else 225 } else {
223 { 226 if (!epos.bh) {
224 if (!epos.bh)
225 {
226 UDF_I_LENALLOC(inode) = lenalloc; 227 UDF_I_LENALLOC(inode) = lenalloc;
227 mark_inode_dirty(inode); 228 mark_inode_dirty(inode);
228 } 229 } else {
229 else 230 struct allocExtDesc *aed =
230 { 231 (struct allocExtDesc *)(epos.bh->b_data);
231 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data); 232 aed->lengthAllocDescs =
232 aed->lengthAllocDescs = cpu_to_le32(lenalloc); 233 cpu_to_le32(lenalloc);
233 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(sb) >= 0x0201) 234 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
234 udf_update_tag(epos.bh->b_data, lenalloc + 235 UDF_SB_UDFREV(sb) >= 0x0201)
235 sizeof(struct allocExtDesc)); 236 udf_update_tag(epos.bh->b_data,
237 lenalloc +
238 sizeof(struct allocExtDesc));
236 else 239 else
237 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 240 udf_update_tag(epos.bh->b_data,
241 sizeof(struct allocExtDesc));
238 mark_buffer_dirty_inode(epos.bh, inode); 242 mark_buffer_dirty_inode(epos.bh, inode);
239 } 243 }
240 } 244 }
@@ -243,49 +247,41 @@ void udf_truncate_extents(struct inode * inode)
243 epos.block = eloc; 247 epos.block = eloc;
244 epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); 248 epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0));
245 if (elen) 249 if (elen)
246 indirect_ext_len = (elen + 250 indirect_ext_len = (elen + sb->s_blocksize -1) >>
247 sb->s_blocksize - 1) >>
248 sb->s_blocksize_bits; 251 sb->s_blocksize_bits;
249 else 252 else
250 indirect_ext_len = 1; 253 indirect_ext_len = 1;
251 } 254 } else {
252 else
253 {
254 extent_trunc(inode, &epos, eloc, etype, elen, 0); 255 extent_trunc(inode, &epos, eloc, etype, elen, 0);
255 epos.offset += adsize; 256 epos.offset += adsize;
256 } 257 }
257 } 258 }
258 259
259 if (indirect_ext_len) 260 if (indirect_ext_len) {
260 {
261 if (!epos.bh) 261 if (!epos.bh)
262 BUG(); 262 BUG();
263 udf_free_blocks(sb, inode, epos.block, 0, indirect_ext_len); 263 udf_free_blocks(sb, inode, epos.block, 0,
264 } 264 indirect_ext_len);
265 else 265 } else {
266 { 266 if (!epos.bh) {
267 if (!epos.bh)
268 {
269 UDF_I_LENALLOC(inode) = lenalloc; 267 UDF_I_LENALLOC(inode) = lenalloc;
270 mark_inode_dirty(inode); 268 mark_inode_dirty(inode);
271 } 269 } else {
272 else 270 struct allocExtDesc *aed =
273 { 271 (struct allocExtDesc *)(epos.bh->b_data);
274 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data);
275 aed->lengthAllocDescs = cpu_to_le32(lenalloc); 272 aed->lengthAllocDescs = cpu_to_le32(lenalloc);
276 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(sb) >= 0x0201) 273 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
277 udf_update_tag(epos.bh->b_data, lenalloc + 274 UDF_SB_UDFREV(sb) >= 0x0201)
278 sizeof(struct allocExtDesc)); 275 udf_update_tag(epos.bh->b_data,
276 lenalloc + sizeof(struct allocExtDesc));
279 else 277 else
280 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 278 udf_update_tag(epos.bh->b_data,
279 sizeof(struct allocExtDesc));
281 mark_buffer_dirty_inode(epos.bh, inode); 280 mark_buffer_dirty_inode(epos.bh, inode);
282 } 281 }
283 } 282 }
284 } 283 } else if (inode->i_size) {
285 else if (inode->i_size) 284 if (byte_offset) {
286 {
287 if (byte_offset)
288 {
289 kernel_long_ad extent; 285 kernel_long_ad extent;
290 286
291 /* 287 /*
@@ -293,21 +289,23 @@ void udf_truncate_extents(struct inode * inode)
293 * no extent above inode->i_size => truncate is 289 * no extent above inode->i_size => truncate is
294 * extending the file by 'offset' blocks. 290 * extending the file by 'offset' blocks.
295 */ 291 */
296 if ((!epos.bh && epos.offset == udf_file_entry_alloc_offset(inode)) || 292 if ((!epos.bh &&
293 epos.offset == udf_file_entry_alloc_offset(inode)) ||
297 (epos.bh && epos.offset == sizeof(struct allocExtDesc))) { 294 (epos.bh && epos.offset == sizeof(struct allocExtDesc))) {
298 /* File has no extents at all or has empty last 295 /* File has no extents at all or has empty last
299 * indirect extent! Create a fake extent... */ 296 * indirect extent! Create a fake extent... */
300 extent.extLocation.logicalBlockNum = 0; 297 extent.extLocation.logicalBlockNum = 0;
301 extent.extLocation.partitionReferenceNum = 0; 298 extent.extLocation.partitionReferenceNum = 0;
302 extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 299 extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
303 } 300 } else {
304 else {
305 epos.offset -= adsize; 301 epos.offset -= adsize;
306 etype = udf_next_aext(inode, &epos, 302 etype = udf_next_aext(inode, &epos,
307 &extent.extLocation, &extent.extLength, 0); 303 &extent.extLocation,
304 &extent.extLength, 0);
308 extent.extLength |= etype << 30; 305 extent.extLength |= etype << 30;
309 } 306 }
310 udf_extend_file(inode, &epos, &extent, offset+((inode->i_size & (sb->s_blocksize-1)) != 0)); 307 udf_extend_file(inode, &epos, &extent,
308 offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0));
311 } 309 }
312 } 310 }
313 UDF_I_LENEXTENTS(inode) = inode->i_size; 311 UDF_I_LENEXTENTS(inode) = inode->i_size;
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h
index 3b2e6c8cb151..3e937d3fb8f9 100644
--- a/fs/udf/udf_sb.h
+++ b/fs/udf/udf_sb.h
@@ -41,8 +41,7 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
41 41
42#define UDF_SB_FREE(X)\ 42#define UDF_SB_FREE(X)\
43{\ 43{\
44 if (UDF_SB(X))\ 44 if (UDF_SB(X)) {\
45 {\
46 kfree(UDF_SB_PARTMAPS(X));\ 45 kfree(UDF_SB_PARTMAPS(X));\
47 UDF_SB_PARTMAPS(X) = NULL;\ 46 UDF_SB_PARTMAPS(X) = NULL;\
48 }\ 47 }\
@@ -51,13 +50,10 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
51#define UDF_SB_ALLOC_PARTMAPS(X,Y)\ 50#define UDF_SB_ALLOC_PARTMAPS(X,Y)\
52{\ 51{\
53 UDF_SB_PARTMAPS(X) = kmalloc(sizeof(struct udf_part_map) * Y, GFP_KERNEL);\ 52 UDF_SB_PARTMAPS(X) = kmalloc(sizeof(struct udf_part_map) * Y, GFP_KERNEL);\
54 if (UDF_SB_PARTMAPS(X) != NULL)\ 53 if (UDF_SB_PARTMAPS(X) != NULL) {\
55 {\
56 UDF_SB_NUMPARTS(X) = Y;\ 54 UDF_SB_NUMPARTS(X) = Y;\
57 memset(UDF_SB_PARTMAPS(X), 0x00, sizeof(struct udf_part_map) * Y);\ 55 memset(UDF_SB_PARTMAPS(X), 0x00, sizeof(struct udf_part_map) * Y);\
58 }\ 56 } else {\
59 else\
60 {\
61 UDF_SB_NUMPARTS(X) = 0;\ 57 UDF_SB_NUMPARTS(X) = 0;\
62 udf_error(X, __FUNCTION__, "Unable to allocate space for %d partition maps", Y);\ 58 udf_error(X, __FUNCTION__, "Unable to allocate space for %d partition maps", Y);\
63 }\ 59 }\
@@ -72,15 +68,12 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
72 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = kmalloc(size, GFP_KERNEL);\ 68 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = kmalloc(size, GFP_KERNEL);\
73 else\ 69 else\
74 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = vmalloc(size);\ 70 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = vmalloc(size);\
75 if (UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap != NULL)\ 71 if (UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap != NULL) {\
76 {\
77 memset(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap, 0x00, size);\ 72 memset(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap, 0x00, size);\
78 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap =\ 73 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap =\
79 (struct buffer_head **)(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap + 1);\ 74 (struct buffer_head **)(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap + 1);\
80 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups = nr_groups;\ 75 UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups = nr_groups;\
81 }\ 76 } else {\
82 else\
83 {\
84 udf_error(X, __FUNCTION__, "Unable to allocate space for bitmap and %d buffer_head pointers", nr_groups);\ 77 udf_error(X, __FUNCTION__, "Unable to allocate space for bitmap and %d buffer_head pointers", nr_groups);\
85 }\ 78 }\
86} 79}
@@ -90,8 +83,7 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
90 int i;\ 83 int i;\
91 int nr_groups = UDF_SB_BITMAP_NR_GROUPS(X,Y,Z);\ 84 int nr_groups = UDF_SB_BITMAP_NR_GROUPS(X,Y,Z);\
92 int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\ 85 int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\
93 for (i=0; i<nr_groups; i++)\ 86 for (i = 0; i < nr_groups; i++) {\
94 {\
95 if (UDF_SB_BITMAP(X,Y,Z,i))\ 87 if (UDF_SB_BITMAP(X,Y,Z,i))\
96 brelse(UDF_SB_BITMAP(X,Y,Z,i));\ 88 brelse(UDF_SB_BITMAP(X,Y,Z,i));\
97 }\ 89 }\
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index f581f2f69c0f..c8016cc9e7e6 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -50,30 +50,26 @@ extern const struct address_space_operations udf_aops;
50extern const struct address_space_operations udf_adinicb_aops; 50extern const struct address_space_operations udf_adinicb_aops;
51extern const struct address_space_operations udf_symlink_aops; 51extern const struct address_space_operations udf_symlink_aops;
52 52
53struct udf_fileident_bh 53struct udf_fileident_bh {
54{
55 struct buffer_head *sbh; 54 struct buffer_head *sbh;
56 struct buffer_head *ebh; 55 struct buffer_head *ebh;
57 int soffset; 56 int soffset;
58 int eoffset; 57 int eoffset;
59}; 58};
60 59
61struct udf_vds_record 60struct udf_vds_record {
62{
63 uint32_t block; 61 uint32_t block;
64 uint32_t volDescSeqNum; 62 uint32_t volDescSeqNum;
65}; 63};
66 64
67struct generic_desc 65struct generic_desc {
68{
69 tag descTag; 66 tag descTag;
70 __le32 volDescSeqNum; 67 __le32 volDescSeqNum;
71}; 68};
72 69
73struct ustr 70struct ustr {
74{
75 uint8_t u_cmpID; 71 uint8_t u_cmpID;
76 uint8_t u_name[UDF_NAME_LEN-2]; 72 uint8_t u_name[UDF_NAME_LEN - 2];
77 uint8_t u_len; 73 uint8_t u_len;
78}; 74};
79 75
@@ -83,44 +79,58 @@ struct extent_position {
83 kernel_lb_addr block; 79 kernel_lb_addr block;
84}; 80};
85 81
86
87/* super.c */ 82/* super.c */
88extern void udf_error(struct super_block *, const char *, const char *, ...); 83extern void udf_error(struct super_block *, const char *, const char *, ...);
89extern void udf_warning(struct super_block *, const char *, const char *, ...); 84extern void udf_warning(struct super_block *, const char *, const char *, ...);
90 85
91/* namei.c */ 86/* namei.c */
92extern int udf_write_fi(struct inode *inode, struct fileIdentDesc *, struct fileIdentDesc *, struct udf_fileident_bh *, uint8_t *, uint8_t *); 87extern int udf_write_fi(struct inode *inode, struct fileIdentDesc *,
88 struct fileIdentDesc *, struct udf_fileident_bh *,
89 uint8_t *, uint8_t *);
93 90
94/* file.c */ 91/* file.c */
95extern int udf_ioctl(struct inode *, struct file *, unsigned int, unsigned long); 92extern int udf_ioctl(struct inode *, struct file *, unsigned int,
93 unsigned long);
96 94
97/* inode.c */ 95/* inode.c */
98extern struct inode *udf_iget(struct super_block *, kernel_lb_addr); 96extern struct inode *udf_iget(struct super_block *, kernel_lb_addr);
99extern int udf_sync_inode(struct inode *); 97extern int udf_sync_inode(struct inode *);
100extern void udf_expand_file_adinicb(struct inode *, int, int *); 98extern void udf_expand_file_adinicb(struct inode *, int, int *);
101extern struct buffer_head * udf_expand_dir_adinicb(struct inode *, int *, int *); 99extern struct buffer_head *udf_expand_dir_adinicb(struct inode *, int *, int *);
102extern struct buffer_head * udf_bread(struct inode *, int, int, int *); 100extern struct buffer_head *udf_bread(struct inode *, int, int, int *);
103extern void udf_truncate(struct inode *); 101extern void udf_truncate(struct inode *);
104extern void udf_read_inode(struct inode *); 102extern void udf_read_inode(struct inode *);
105extern void udf_delete_inode(struct inode *); 103extern void udf_delete_inode(struct inode *);
106extern void udf_clear_inode(struct inode *); 104extern void udf_clear_inode(struct inode *);
107extern int udf_write_inode(struct inode *, int); 105extern int udf_write_inode(struct inode *, int);
108extern long udf_block_map(struct inode *, sector_t); 106extern long udf_block_map(struct inode *, sector_t);
109extern int udf_extend_file(struct inode *, struct extent_position *, kernel_long_ad *, sector_t); 107extern int udf_extend_file(struct inode *, struct extent_position *,
110extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, kernel_lb_addr *, uint32_t *, sector_t *); 108 kernel_long_ad *, sector_t);
111extern int8_t udf_add_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int); 109extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *,
112extern int8_t udf_write_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int); 110 kernel_lb_addr *, uint32_t *, sector_t *);
113extern int8_t udf_delete_aext(struct inode *, struct extent_position, kernel_lb_addr, uint32_t); 111extern int8_t udf_add_aext(struct inode *, struct extent_position *,
114extern int8_t udf_next_aext(struct inode *, struct extent_position *, kernel_lb_addr *, uint32_t *, int); 112 kernel_lb_addr, uint32_t, int);
115extern int8_t udf_current_aext(struct inode *, struct extent_position *, kernel_lb_addr *, uint32_t *, int); 113extern int8_t udf_write_aext(struct inode *, struct extent_position *,
114 kernel_lb_addr, uint32_t, int);
115extern int8_t udf_delete_aext(struct inode *, struct extent_position,
116 kernel_lb_addr, uint32_t);
117extern int8_t udf_next_aext(struct inode *, struct extent_position *,
118 kernel_lb_addr *, uint32_t *, int);
119extern int8_t udf_current_aext(struct inode *, struct extent_position *,
120 kernel_lb_addr *, uint32_t *, int);
116 121
117/* misc.c */ 122/* misc.c */
118extern struct buffer_head *udf_tgetblk(struct super_block *, int); 123extern struct buffer_head *udf_tgetblk(struct super_block *, int);
119extern struct buffer_head *udf_tread(struct super_block *, int); 124extern struct buffer_head *udf_tread(struct super_block *, int);
120extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t, uint32_t, uint8_t); 125extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t,
121extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t, uint8_t); 126 uint32_t, uint8_t);
122extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t, uint32_t, uint16_t *); 127extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t,
123extern struct buffer_head *udf_read_ptagged(struct super_block *, kernel_lb_addr, uint32_t, uint16_t *); 128 uint8_t);
129extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t,
130 uint32_t, uint16_t *);
131extern struct buffer_head *udf_read_ptagged(struct super_block *,
132 kernel_lb_addr, uint32_t,
133 uint16_t *);
124extern void udf_update_tag(char *, int); 134extern void udf_update_tag(char *, int);
125extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int); 135extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int);
126 136
@@ -129,21 +139,26 @@ extern unsigned int udf_get_last_session(struct super_block *);
129extern unsigned long udf_get_last_block(struct super_block *); 139extern unsigned long udf_get_last_block(struct super_block *);
130 140
131/* partition.c */ 141/* partition.c */
132extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t, uint32_t); 142extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t,
133extern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t, uint32_t); 143 uint32_t);
134extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t, uint32_t); 144extern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t,
135extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t, uint32_t); 145 uint32_t);
146extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t,
147 uint32_t);
148extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t,
149 uint32_t);
136extern int udf_relocate_blocks(struct super_block *, long, long *); 150extern int udf_relocate_blocks(struct super_block *, long, long *);
137 151
138/* unicode.c */ 152/* unicode.c */
139extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int); 153extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int);
140extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *, int); 154extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *,
155 int);
141extern int udf_build_ustr(struct ustr *, dstring *, int); 156extern int udf_build_ustr(struct ustr *, dstring *, int);
142extern int udf_CS0toUTF8(struct ustr *, struct ustr *); 157extern int udf_CS0toUTF8(struct ustr *, struct ustr *);
143 158
144/* ialloc.c */ 159/* ialloc.c */
145extern void udf_free_inode(struct inode *); 160extern void udf_free_inode(struct inode *);
146extern struct inode * udf_new_inode (struct inode *, int, int *); 161extern struct inode *udf_new_inode(struct inode *, int, int *);
147 162
148/* truncate.c */ 163/* truncate.c */
149extern void udf_truncate_tail_extent(struct inode *); 164extern void udf_truncate_tail_extent(struct inode *);
@@ -151,18 +166,27 @@ extern void udf_discard_prealloc(struct inode *);
151extern void udf_truncate_extents(struct inode *); 166extern void udf_truncate_extents(struct inode *);
152 167
153/* balloc.c */ 168/* balloc.c */
154extern void udf_free_blocks(struct super_block *, struct inode *, kernel_lb_addr, uint32_t, uint32_t); 169extern void udf_free_blocks(struct super_block *, struct inode *,
155extern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t, uint32_t, uint32_t); 170 kernel_lb_addr, uint32_t, uint32_t);
156extern int udf_new_block(struct super_block *, struct inode *, uint16_t, uint32_t, int *); 171extern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t,
172 uint32_t, uint32_t);
173extern int udf_new_block(struct super_block *, struct inode *, uint16_t,
174 uint32_t, int *);
157 175
158/* fsync.c */ 176/* fsync.c */
159extern int udf_fsync_file(struct file *, struct dentry *, int); 177extern int udf_fsync_file(struct file *, struct dentry *, int);
160 178
161/* directory.c */ 179/* directory.c */
162extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, struct extent_position *, kernel_lb_addr *, uint32_t *, sector_t *); 180extern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *,
163extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset); 181 struct udf_fileident_bh *,
164extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int); 182 struct fileIdentDesc *,
165extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int); 183 struct extent_position *,
184 kernel_lb_addr *, uint32_t *,
185 sector_t *);
186extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
187 int *offset);
188extern long_ad *udf_get_filelongad(uint8_t *, int, int *, int);
189extern short_ad *udf_get_fileshortad(uint8_t *, int, int *, int);
166 190
167/* crc.c */ 191/* crc.c */
168extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t); 192extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t);
@@ -171,4 +195,4 @@ extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t);
171extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp); 195extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp);
172extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec); 196extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec);
173 197
174#endif /* __UDF_DECL_H */ 198#endif /* __UDF_DECL_H */
diff --git a/fs/udf/udfend.h b/fs/udf/udfend.h
index 17d378879561..c4bd1203f857 100644
--- a/fs/udf/udfend.h
+++ b/fs/udf/udfend.h
@@ -7,74 +7,92 @@
7static inline kernel_lb_addr lelb_to_cpu(lb_addr in) 7static inline kernel_lb_addr lelb_to_cpu(lb_addr in)
8{ 8{
9 kernel_lb_addr out; 9 kernel_lb_addr out;
10
10 out.logicalBlockNum = le32_to_cpu(in.logicalBlockNum); 11 out.logicalBlockNum = le32_to_cpu(in.logicalBlockNum);
11 out.partitionReferenceNum = le16_to_cpu(in.partitionReferenceNum); 12 out.partitionReferenceNum = le16_to_cpu(in.partitionReferenceNum);
13
12 return out; 14 return out;
13} 15}
14 16
15static inline lb_addr cpu_to_lelb(kernel_lb_addr in) 17static inline lb_addr cpu_to_lelb(kernel_lb_addr in)
16{ 18{
17 lb_addr out; 19 lb_addr out;
20
18 out.logicalBlockNum = cpu_to_le32(in.logicalBlockNum); 21 out.logicalBlockNum = cpu_to_le32(in.logicalBlockNum);
19 out.partitionReferenceNum = cpu_to_le16(in.partitionReferenceNum); 22 out.partitionReferenceNum = cpu_to_le16(in.partitionReferenceNum);
23
20 return out; 24 return out;
21} 25}
22 26
23static inline kernel_timestamp lets_to_cpu(timestamp in) 27static inline kernel_timestamp lets_to_cpu(timestamp in)
24{ 28{
25 kernel_timestamp out; 29 kernel_timestamp out;
30
26 memcpy(&out, &in, sizeof(timestamp)); 31 memcpy(&out, &in, sizeof(timestamp));
27 out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone); 32 out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
28 out.year = le16_to_cpu(in.year); 33 out.year = le16_to_cpu(in.year);
34
29 return out; 35 return out;
30} 36}
31 37
32static inline short_ad lesa_to_cpu(short_ad in) 38static inline short_ad lesa_to_cpu(short_ad in)
33{ 39{
34 short_ad out; 40 short_ad out;
41
35 out.extLength = le32_to_cpu(in.extLength); 42 out.extLength = le32_to_cpu(in.extLength);
36 out.extPosition = le32_to_cpu(in.extPosition); 43 out.extPosition = le32_to_cpu(in.extPosition);
44
37 return out; 45 return out;
38} 46}
39 47
40static inline short_ad cpu_to_lesa(short_ad in) 48static inline short_ad cpu_to_lesa(short_ad in)
41{ 49{
42 short_ad out; 50 short_ad out;
51
43 out.extLength = cpu_to_le32(in.extLength); 52 out.extLength = cpu_to_le32(in.extLength);
44 out.extPosition = cpu_to_le32(in.extPosition); 53 out.extPosition = cpu_to_le32(in.extPosition);
54
45 return out; 55 return out;
46} 56}
47 57
48static inline kernel_long_ad lela_to_cpu(long_ad in) 58static inline kernel_long_ad lela_to_cpu(long_ad in)
49{ 59{
50 kernel_long_ad out; 60 kernel_long_ad out;
61
51 out.extLength = le32_to_cpu(in.extLength); 62 out.extLength = le32_to_cpu(in.extLength);
52 out.extLocation = lelb_to_cpu(in.extLocation); 63 out.extLocation = lelb_to_cpu(in.extLocation);
64
53 return out; 65 return out;
54} 66}
55 67
56static inline long_ad cpu_to_lela(kernel_long_ad in) 68static inline long_ad cpu_to_lela(kernel_long_ad in)
57{ 69{
58 long_ad out; 70 long_ad out;
71
59 out.extLength = cpu_to_le32(in.extLength); 72 out.extLength = cpu_to_le32(in.extLength);
60 out.extLocation = cpu_to_lelb(in.extLocation); 73 out.extLocation = cpu_to_lelb(in.extLocation);
74
61 return out; 75 return out;
62} 76}
63 77
64static inline kernel_extent_ad leea_to_cpu(extent_ad in) 78static inline kernel_extent_ad leea_to_cpu(extent_ad in)
65{ 79{
66 kernel_extent_ad out; 80 kernel_extent_ad out;
81
67 out.extLength = le32_to_cpu(in.extLength); 82 out.extLength = le32_to_cpu(in.extLength);
68 out.extLocation = le32_to_cpu(in.extLocation); 83 out.extLocation = le32_to_cpu(in.extLocation);
84
69 return out; 85 return out;
70} 86}
71 87
72static inline timestamp cpu_to_lets(kernel_timestamp in) 88static inline timestamp cpu_to_lets(kernel_timestamp in)
73{ 89{
74 timestamp out; 90 timestamp out;
91
75 memcpy(&out, &in, sizeof(timestamp)); 92 memcpy(&out, &in, sizeof(timestamp));
76 out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone); 93 out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
77 out.year = cpu_to_le16(in.year); 94 out.year = cpu_to_le16(in.year);
95
78 return out; 96 return out;
79} 97}
80 98
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index 85d8dbe843f1..3fd80eb66af3 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -18,18 +18,18 @@
18 Boston, MA 02111-1307, USA. */ 18 Boston, MA 02111-1307, USA. */
19 19
20/* 20/*
21 * dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time 21 * dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time
22 * 10/04/98: added new table-based lookup after seeing how ugly the gnu code is 22 * 10/04/98: added new table-based lookup after seeing how ugly the gnu code is
23 * blf 09/27/99: ripped out all the old code and inserted new table from 23 * blf 09/27/99: ripped out all the old code and inserted new table from
24 * John Brockmeyer (without leap second corrections) 24 * John Brockmeyer (without leap second corrections)
25 * rewrote udf_stamp_to_time and fixed timezone accounting in 25 * rewrote udf_stamp_to_time and fixed timezone accounting in
26 udf_time_to_stamp. 26 * udf_time_to_stamp.
27 */ 27 */
28 28
29/* 29/*
30 * We don't take into account leap seconds. This may be correct or incorrect. 30 * We don't take into account leap seconds. This may be correct or incorrect.
31 * For more NIST information (especially dealing with leap seconds), see: 31 * For more NIST information (especially dealing with leap seconds), see:
32 * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm 32 * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm
33 */ 33 */
34 34
35#include <linux/types.h> 35#include <linux/types.h>
@@ -46,36 +46,35 @@
46#endif 46#endif
47 47
48/* How many days come before each month (0-12). */ 48/* How many days come before each month (0-12). */
49static const unsigned short int __mon_yday[2][13] = 49static const unsigned short int __mon_yday[2][13] = {
50{
51 /* Normal years. */ 50 /* Normal years. */
52 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, 51 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
53 /* Leap years. */ 52 /* Leap years. */
54 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 53 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
55}; 54};
56 55
57#define MAX_YEAR_SECONDS 69 56#define MAX_YEAR_SECONDS 69
58#define SPD 0x15180 /*3600*24*/ 57#define SPD 0x15180 /*3600*24 */
59#define SPY(y,l,s) (SPD * (365*y+l)+s) 58#define SPY(y,l,s) (SPD * (365*y+l)+s)
60 59
61static time_t year_seconds[MAX_YEAR_SECONDS]= { 60static time_t year_seconds[MAX_YEAR_SECONDS]= {
62/*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0), 61/*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0),
63/*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0), 62/*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0),
64/*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0), 63/*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0),
65/*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0), 64/*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0),
66/*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0), 65/*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0),
67/*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0), 66/*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0),
68/*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0), 67/*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0),
69/*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0), 68/*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0),
70/*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0), 69/*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0),
71/*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0), 70/*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0),
72/*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0), 71/*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0),
73/*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0), 72/*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0),
74/*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0), 73/*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0),
75/*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0), 74/*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0),
76/*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0), 75/*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0),
77/*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0), 76/*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0),
78/*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0), 77/*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0),
79/*2038*/ SPY(68,17,0) 78/*2038*/ SPY(68,17,0)
80}; 79};
81 80
@@ -84,27 +83,24 @@ extern struct timezone sys_tz;
84#define SECS_PER_HOUR (60 * 60) 83#define SECS_PER_HOUR (60 * 60)
85#define SECS_PER_DAY (SECS_PER_HOUR * 24) 84#define SECS_PER_DAY (SECS_PER_HOUR * 24)
86 85
87time_t * 86time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
88udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
89{ 87{
90 int yday; 88 int yday;
91 uint8_t type = src.typeAndTimezone >> 12; 89 uint8_t type = src.typeAndTimezone >> 12;
92 int16_t offset; 90 int16_t offset;
93 91
94 if (type == 1) 92 if (type == 1) {
95 {
96 offset = src.typeAndTimezone << 4; 93 offset = src.typeAndTimezone << 4;
97 /* sign extent offset */ 94 /* sign extent offset */
98 offset = (offset >> 4); 95 offset = (offset >> 4);
99 if (offset == -2047) /* unspecified offset */ 96 if (offset == -2047) /* unspecified offset */
100 offset = 0; 97 offset = 0;
101 } 98 } else {
102 else
103 offset = 0; 99 offset = 0;
100 }
104 101
105 if ((src.year < EPOCH_YEAR) || 102 if ((src.year < EPOCH_YEAR) ||
106 (src.year >= EPOCH_YEAR+MAX_YEAR_SECONDS)) 103 (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
107 {
108 *dest = -1; 104 *dest = -1;
109 *dest_usec = -1; 105 *dest_usec = -1;
110 return NULL; 106 return NULL;
@@ -113,15 +109,13 @@ udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
113 *dest -= offset * 60; 109 *dest -= offset * 60;
114 110
115 yday = ((__mon_yday[__isleap (src.year)] 111 yday = ((__mon_yday[__isleap (src.year)]
116 [src.month-1]) + (src.day-1)); 112 [src.month - 1]) + (src.day - 1));
117 *dest += ( ( (yday* 24) + src.hour ) * 60 + src.minute ) * 60 + src.second; 113 *dest += ( ( (yday * 24) + src.hour ) * 60 + src.minute ) * 60 + src.second;
118 *dest_usec = src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 + src.microseconds; 114 *dest_usec = src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 + src.microseconds;
119 return dest; 115 return dest;
120} 116}
121 117
122 118kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
123kernel_timestamp *
124udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
125{ 119{
126 long int days, rem, y; 120 long int days, rem, y;
127 const unsigned short int *ip; 121 const unsigned short int *ip;
@@ -146,19 +140,18 @@ udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
146#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) 140#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0))
147#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) 141#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
148 142
149 while (days < 0 || days >= (__isleap(y) ? 366 : 365)) 143 while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
150 {
151 long int yg = y + days / 365 - (days % 365 < 0); 144 long int yg = y + days / 365 - (days % 365 < 0);
152 145
153 /* Adjust DAYS and Y to match the guessed year. */ 146 /* Adjust DAYS and Y to match the guessed year. */
154 days -= ((yg - y) * 365 147 days -= ((yg - y) * 365
155 + LEAPS_THRU_END_OF (yg - 1) 148 + LEAPS_THRU_END_OF (yg - 1)
156 - LEAPS_THRU_END_OF (y - 1)); 149 - LEAPS_THRU_END_OF (y - 1));
157 y = yg; 150 y = yg;
158 } 151 }
159 dest->year = y; 152 dest->year = y;
160 ip = __mon_yday[__isleap(y)]; 153 ip = __mon_yday[__isleap(y)];
161 for (y = 11; days < (long int) ip[y]; --y) 154 for (y = 11; days < (long int)ip[y]; --y)
162 continue; 155 continue;
163 days -= ip[y]; 156 days -= ip[y];
164 dest->month = y + 1; 157 dest->month = y + 1;
@@ -167,7 +160,7 @@ udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
167 dest->centiseconds = ts.tv_nsec / 10000000; 160 dest->centiseconds = ts.tv_nsec / 10000000;
168 dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; 161 dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100;
169 dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - 162 dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
170 dest->hundredsOfMicroseconds * 100); 163 dest->hundredsOfMicroseconds * 100);
171 return dest; 164 return dest;
172} 165}
173 166
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
index 706c92e1dcc9..9e6099c26c27 100644
--- a/fs/udf/unicode.c
+++ b/fs/udf/unicode.c
@@ -31,12 +31,14 @@ static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int);
31 31
32static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen) 32static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
33{ 33{
34 if ( (!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN-2) ) 34 if ((!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN - 2))
35 return 0; 35 return 0;
36
36 memset(dest, 0, sizeof(struct ustr)); 37 memset(dest, 0, sizeof(struct ustr));
37 memcpy(dest->u_name, src, strlen); 38 memcpy(dest->u_name, src, strlen);
38 dest->u_cmpID = 0x08; 39 dest->u_cmpID = 0x08;
39 dest->u_len = strlen; 40 dest->u_len = strlen;
41
40 return strlen; 42 return strlen;
41} 43}
42 44
@@ -47,14 +49,15 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size)
47{ 49{
48 int usesize; 50 int usesize;
49 51
50 if ( (!dest) || (!ptr) || (!size) ) 52 if ((!dest) || (!ptr) || (!size))
51 return -1; 53 return -1;
52 54
53 memset(dest, 0, sizeof(struct ustr)); 55 memset(dest, 0, sizeof(struct ustr));
54 usesize= (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size; 56 usesize = (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size;
55 dest->u_cmpID=ptr[0]; 57 dest->u_cmpID = ptr[0];
56 dest->u_len=ptr[size-1]; 58 dest->u_len = ptr[size - 1];
57 memcpy(dest->u_name, ptr+1, usesize-1); 59 memcpy(dest->u_name, ptr + 1, usesize - 1);
60
58 return 0; 61 return 0;
59} 62}
60 63
@@ -63,13 +66,14 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size)
63 */ 66 */
64static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) 67static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
65{ 68{
66 if ( (!dest) || (!ptr) || (!exactsize) ) 69 if ((!dest) || (!ptr) || (!exactsize))
67 return -1; 70 return -1;
68 71
69 memset(dest, 0, sizeof(struct ustr)); 72 memset(dest, 0, sizeof(struct ustr));
70 dest->u_cmpID=ptr[0]; 73 dest->u_cmpID = ptr[0];
71 dest->u_len=exactsize-1; 74 dest->u_len = exactsize - 1;
72 memcpy(dest->u_name, ptr+1, exactsize-1); 75 memcpy(dest->u_name, ptr + 1, exactsize - 1);
76
73 return 0; 77 return 0;
74} 78}
75 79
@@ -108,22 +112,20 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
108 cmp_id = ocu_i->u_cmpID; 112 cmp_id = ocu_i->u_cmpID;
109 utf_o->u_len = 0; 113 utf_o->u_len = 0;
110 114
111 if (ocu_len == 0) 115 if (ocu_len == 0) {
112 {
113 memset(utf_o, 0, sizeof(struct ustr)); 116 memset(utf_o, 0, sizeof(struct ustr));
114 utf_o->u_cmpID = 0; 117 utf_o->u_cmpID = 0;
115 utf_o->u_len = 0; 118 utf_o->u_len = 0;
116 return 0; 119 return 0;
117 } 120 }
118 121
119 if ((cmp_id != 8) && (cmp_id != 16)) 122 if ((cmp_id != 8) && (cmp_id != 16)) {
120 { 123 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n",
121 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", cmp_id, ocu_i->u_name); 124 cmp_id, ocu_i->u_name);
122 return 0; 125 return 0;
123 } 126 }
124 127
125 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) 128 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
126 {
127 129
128 /* Expand OSTA compressed Unicode to Unicode */ 130 /* Expand OSTA compressed Unicode to Unicode */
129 c = ocu[i++]; 131 c = ocu[i++];
@@ -131,21 +133,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
131 c = (c << 8) | ocu[i++]; 133 c = (c << 8) | ocu[i++];
132 134
133 /* Compress Unicode to UTF-8 */ 135 /* Compress Unicode to UTF-8 */
134 if (c < 0x80U) 136 if (c < 0x80U) {
135 utf_o->u_name[utf_o->u_len++] = (uint8_t)c; 137 utf_o->u_name[utf_o->u_len++] = (uint8_t)c;
136 else if (c < 0x800U) 138 } else if (c < 0x800U) {
137 {
138 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); 139 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6));
139 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); 140 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f));
140 } 141 } else {
141 else
142 {
143 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); 142 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12));
144 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); 143 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f));
145 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); 144 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f));
146 } 145 }
147 } 146 }
148 utf_o->u_cmpID=8; 147 utf_o->u_cmpID = 8;
149 148
150 return utf_o->u_len; 149 return utf_o->u_len;
151} 150}
@@ -186,61 +185,46 @@ try_again:
186 u_len = 0U; 185 u_len = 0U;
187 utf_char = 0U; 186 utf_char = 0U;
188 utf_cnt = 0U; 187 utf_cnt = 0U;
189 for (i = 0U; i < utf->u_len; i++) 188 for (i = 0U; i < utf->u_len; i++) {
190 {
191 c = (uint8_t)utf->u_name[i]; 189 c = (uint8_t)utf->u_name[i];
192 190
193 /* Complete a multi-byte UTF-8 character */ 191 /* Complete a multi-byte UTF-8 character */
194 if (utf_cnt) 192 if (utf_cnt) {
195 {
196 utf_char = (utf_char << 6) | (c & 0x3fU); 193 utf_char = (utf_char << 6) | (c & 0x3fU);
197 if (--utf_cnt) 194 if (--utf_cnt)
198 continue; 195 continue;
199 } 196 } else {
200 else
201 {
202 /* Check for a multi-byte UTF-8 character */ 197 /* Check for a multi-byte UTF-8 character */
203 if (c & 0x80U) 198 if (c & 0x80U) {
204 {
205 /* Start a multi-byte UTF-8 character */ 199 /* Start a multi-byte UTF-8 character */
206 if ((c & 0xe0U) == 0xc0U) 200 if ((c & 0xe0U) == 0xc0U) {
207 {
208 utf_char = c & 0x1fU; 201 utf_char = c & 0x1fU;
209 utf_cnt = 1; 202 utf_cnt = 1;
210 } 203 } else if ((c & 0xf0U) == 0xe0U) {
211 else if ((c & 0xf0U) == 0xe0U)
212 {
213 utf_char = c & 0x0fU; 204 utf_char = c & 0x0fU;
214 utf_cnt = 2; 205 utf_cnt = 2;
215 } 206 } else if ((c & 0xf8U) == 0xf0U) {
216 else if ((c & 0xf8U) == 0xf0U)
217 {
218 utf_char = c & 0x07U; 207 utf_char = c & 0x07U;
219 utf_cnt = 3; 208 utf_cnt = 3;
220 } 209 } else if ((c & 0xfcU) == 0xf8U) {
221 else if ((c & 0xfcU) == 0xf8U)
222 {
223 utf_char = c & 0x03U; 210 utf_char = c & 0x03U;
224 utf_cnt = 4; 211 utf_cnt = 4;
225 } 212 } else if ((c & 0xfeU) == 0xfcU) {
226 else if ((c & 0xfeU) == 0xfcU)
227 {
228 utf_char = c & 0x01U; 213 utf_char = c & 0x01U;
229 utf_cnt = 5; 214 utf_cnt = 5;
230 } 215 } else {
231 else
232 goto error_out; 216 goto error_out;
217 }
233 continue; 218 continue;
234 } else 219 } else {
235 /* Single byte UTF-8 character (most common) */ 220 /* Single byte UTF-8 character (most common) */
236 utf_char = c; 221 utf_char = c;
222 }
237 } 223 }
238 224
239 /* Choose no compression if necessary */ 225 /* Choose no compression if necessary */
240 if (utf_char > max_val) 226 if (utf_char > max_val) {
241 { 227 if (max_val == 0xffU) {
242 if ( 0xffU == max_val )
243 {
244 max_val = 0xffffU; 228 max_val = 0xffffU;
245 ocu[0] = (uint8_t)0x10U; 229 ocu[0] = (uint8_t)0x10U;
246 goto try_again; 230 goto try_again;
@@ -248,26 +232,25 @@ try_again:
248 goto error_out; 232 goto error_out;
249 } 233 }
250 234
251 if (max_val == 0xffffU) 235 if (max_val == 0xffffU) {
252 {
253 ocu[++u_len] = (uint8_t)(utf_char >> 8); 236 ocu[++u_len] = (uint8_t)(utf_char >> 8);
254 } 237 }
255 ocu[++u_len] = (uint8_t)(utf_char & 0xffU); 238 ocu[++u_len] = (uint8_t)(utf_char & 0xffU);
256 } 239 }
257 240
258 241 if (utf_cnt) {
259 if (utf_cnt)
260 {
261error_out: 242error_out:
262 ocu[++u_len] = '?'; 243 ocu[++u_len] = '?';
263 printk(KERN_DEBUG "udf: bad UTF-8 character\n"); 244 printk(KERN_DEBUG "udf: bad UTF-8 character\n");
264 } 245 }
265 246
266 ocu[length - 1] = (uint8_t)u_len + 1; 247 ocu[length - 1] = (uint8_t)u_len + 1;
248
267 return u_len + 1; 249 return u_len + 1;
268} 250}
269 251
270static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr *ocu_i) 252static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o,
253 struct ustr *ocu_i)
271{ 254{
272 uint8_t *ocu; 255 uint8_t *ocu;
273 uint32_t c; 256 uint32_t c;
@@ -280,36 +263,35 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr *
280 cmp_id = ocu_i->u_cmpID; 263 cmp_id = ocu_i->u_cmpID;
281 utf_o->u_len = 0; 264 utf_o->u_len = 0;
282 265
283 if (ocu_len == 0) 266 if (ocu_len == 0) {
284 {
285 memset(utf_o, 0, sizeof(struct ustr)); 267 memset(utf_o, 0, sizeof(struct ustr));
286 utf_o->u_cmpID = 0; 268 utf_o->u_cmpID = 0;
287 utf_o->u_len = 0; 269 utf_o->u_len = 0;
288 return 0; 270 return 0;
289 } 271 }
290 272
291 if ((cmp_id != 8) && (cmp_id != 16)) 273 if ((cmp_id != 8) && (cmp_id != 16)) {
292 { 274 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n",
293 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", cmp_id, ocu_i->u_name); 275 cmp_id, ocu_i->u_name);
294 return 0; 276 return 0;
295 } 277 }
296 278
297 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) 279 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
298 {
299 /* Expand OSTA compressed Unicode to Unicode */ 280 /* Expand OSTA compressed Unicode to Unicode */
300 c = ocu[i++]; 281 c = ocu[i++];
301 if (cmp_id == 16) 282 if (cmp_id == 16)
302 c = (c << 8) | ocu[i++]; 283 c = (c << 8) | ocu[i++];
303 284
304 utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len], 285 utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len],
305 UDF_NAME_LEN - utf_o->u_len); 286 UDF_NAME_LEN - utf_o->u_len);
306 } 287 }
307 utf_o->u_cmpID=8; 288 utf_o->u_cmpID = 8;
308 289
309 return utf_o->u_len; 290 return utf_o->u_len;
310} 291}
311 292
312static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, int length) 293static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni,
294 int length)
313{ 295{
314 unsigned len, i, max_val; 296 unsigned len, i, max_val;
315 uint16_t uni_char; 297 uint16_t uni_char;
@@ -321,19 +303,17 @@ static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, i
321 303
322try_again: 304try_again:
323 u_len = 0U; 305 u_len = 0U;
324 for (i = 0U; i < uni->u_len; i++) 306 for (i = 0U; i < uni->u_len; i++) {
325 { 307 len = nls->char2uni(&uni->u_name[i], uni->u_len - i, &uni_char);
326 len = nls->char2uni(&uni->u_name[i], uni->u_len-i, &uni_char);
327 if (len <= 0) 308 if (len <= 0)
328 continue; 309 continue;
329 310
330 if (uni_char > max_val) 311 if (uni_char > max_val) {
331 {
332 max_val = 0xffffU; 312 max_val = 0xffffU;
333 ocu[0] = (uint8_t)0x10U; 313 ocu[0] = (uint8_t)0x10U;
334 goto try_again; 314 goto try_again;
335 } 315 }
336 316
337 if (max_val == 0xffffU) 317 if (max_val == 0xffffU)
338 ocu[++u_len] = (uint8_t)(uni_char >> 8); 318 ocu[++u_len] = (uint8_t)(uni_char >> 8);
339 ocu[++u_len] = (uint8_t)(uni_char & 0xffU); 319 ocu[++u_len] = (uint8_t)(uni_char & 0xffU);
@@ -344,112 +324,98 @@ try_again:
344 return u_len + 1; 324 return u_len + 1;
345} 325}
346 326
347int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, int flen) 327int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
328 int flen)
348{ 329{
349 struct ustr filename, unifilename; 330 struct ustr filename, unifilename;
350 int len; 331 int len;
351 332
352 if (udf_build_ustr_exact(&unifilename, sname, flen)) 333 if (udf_build_ustr_exact(&unifilename, sname, flen)) {
353 {
354 return 0; 334 return 0;
355 } 335 }
356 336
357 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) 337 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
358 { 338 if (!udf_CS0toUTF8(&filename, &unifilename)) {
359 if (!udf_CS0toUTF8(&filename, &unifilename) )
360 {
361 udf_debug("Failed in udf_get_filename: sname = %s\n", sname); 339 udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
362 return 0; 340 return 0;
363 } 341 }
364 } 342 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
365 else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) 343 if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) {
366 {
367 if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename) )
368 {
369 udf_debug("Failed in udf_get_filename: sname = %s\n", sname); 344 udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
370 return 0; 345 return 0;
371 } 346 }
372 } 347 } else {
373 else
374 return 0; 348 return 0;
349 }
375 350
376 if ((len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, 351 len = udf_translate_to_linux(dname, filename.u_name, filename.u_len,
377 unifilename.u_name, unifilename.u_len))) 352 unifilename.u_name, unifilename.u_len);
378 { 353 if (len) {
379 return len; 354 return len;
380 } 355 }
356
381 return 0; 357 return 0;
382} 358}
383 359
384int udf_put_filename(struct super_block *sb, const uint8_t *sname, uint8_t *dname, int flen) 360int udf_put_filename(struct super_block *sb, const uint8_t *sname,
361 uint8_t *dname, int flen)
385{ 362{
386 struct ustr unifilename; 363 struct ustr unifilename;
387 int namelen; 364 int namelen;
388 365
389 if ( !(udf_char_to_ustr(&unifilename, sname, flen)) ) 366 if (!(udf_char_to_ustr(&unifilename, sname, flen))) {
390 {
391 return 0; 367 return 0;
392 } 368 }
393 369
394 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) 370 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
395 { 371 namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN);
396 if ( !(namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN)) ) 372 if (!namelen) {
397 {
398 return 0; 373 return 0;
399 } 374 }
400 } 375 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
401 else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) 376 namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN);
402 { 377 if (!namelen) {
403 if ( !(namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN)) )
404 {
405 return 0; 378 return 0;
406 } 379 }
407 } 380 } else {
408 else
409 return 0; 381 return 0;
382 }
410 383
411 return namelen; 384 return namelen;
412} 385}
413 386
414#define ILLEGAL_CHAR_MARK '_' 387#define ILLEGAL_CHAR_MARK '_'
415#define EXT_MARK '.' 388#define EXT_MARK '.'
416#define CRC_MARK '#' 389#define CRC_MARK '#'
417#define EXT_SIZE 5 390#define EXT_SIZE 5
418 391
419static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, uint8_t *fidName, int fidNameLen) 392static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen,
393 uint8_t *fidName, int fidNameLen)
420{ 394{
421 int index, newIndex = 0, needsCRC = 0; 395 int index, newIndex = 0, needsCRC = 0;
422 int extIndex = 0, newExtIndex = 0, hasExt = 0; 396 int extIndex = 0, newExtIndex = 0, hasExt = 0;
423 unsigned short valueCRC; 397 unsigned short valueCRC;
424 uint8_t curr; 398 uint8_t curr;
425 const uint8_t hexChar[] = "0123456789ABCDEF"; 399 const uint8_t hexChar[] = "0123456789ABCDEF";
426 400
427 if (udfName[0] == '.' && (udfLen == 1 || 401 if (udfName[0] == '.' &&
428 (udfLen == 2 && udfName[1] == '.'))) 402 (udfLen == 1 || (udfLen == 2 && udfName[1] == '.'))) {
429 {
430 needsCRC = 1; 403 needsCRC = 1;
431 newIndex = udfLen; 404 newIndex = udfLen;
432 memcpy(newName, udfName, udfLen); 405 memcpy(newName, udfName, udfLen);
433 } 406 } else {
434 else 407 for (index = 0; index < udfLen; index++) {
435 {
436 for (index = 0; index < udfLen; index++)
437 {
438 curr = udfName[index]; 408 curr = udfName[index];
439 if (curr == '/' || curr == 0) 409 if (curr == '/' || curr == 0) {
440 {
441 needsCRC = 1; 410 needsCRC = 1;
442 curr = ILLEGAL_CHAR_MARK; 411 curr = ILLEGAL_CHAR_MARK;
443 while (index+1 < udfLen && (udfName[index+1] == '/' || 412 while (index + 1 < udfLen && (udfName[index + 1] == '/' ||
444 udfName[index+1] == 0)) 413 udfName[index + 1] == 0))
445 index++; 414 index++;
446 } 415 } if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) {
447 if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) 416 if (udfLen == index + 1) {
448 {
449 if (udfLen == index + 1)
450 hasExt = 0; 417 hasExt = 0;
451 else 418 } else {
452 {
453 hasExt = 1; 419 hasExt = 1;
454 extIndex = index; 420 extIndex = index;
455 newExtIndex = newIndex; 421 newExtIndex = newIndex;
@@ -461,26 +427,22 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
461 needsCRC = 1; 427 needsCRC = 1;
462 } 428 }
463 } 429 }
464 if (needsCRC) 430 if (needsCRC) {
465 {
466 uint8_t ext[EXT_SIZE]; 431 uint8_t ext[EXT_SIZE];
467 int localExtIndex = 0; 432 int localExtIndex = 0;
468 433
469 if (hasExt) 434 if (hasExt) {
470 {
471 int maxFilenameLen; 435 int maxFilenameLen;
472 for(index = 0; index<EXT_SIZE && extIndex + index +1 < udfLen; 436 for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) {
473 index++ )
474 {
475 curr = udfName[extIndex + index + 1]; 437 curr = udfName[extIndex + index + 1];
476 438
477 if (curr == '/' || curr == 0) 439 if (curr == '/' || curr == 0) {
478 {
479 needsCRC = 1; 440 needsCRC = 1;
480 curr = ILLEGAL_CHAR_MARK; 441 curr = ILLEGAL_CHAR_MARK;
481 while(extIndex + index + 2 < udfLen && (index + 1 < EXT_SIZE 442 while(extIndex + index + 2 < udfLen &&
482 && (udfName[extIndex + index + 2] == '/' || 443 (index + 1 < EXT_SIZE
483 udfName[extIndex + index + 2] == 0))) 444 && (udfName[extIndex + index + 2] == '/' ||
445 udfName[extIndex + index + 2] == 0)))
484 index++; 446 index++;
485 } 447 }
486 ext[localExtIndex++] = curr; 448 ext[localExtIndex++] = curr;
@@ -490,9 +452,9 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
490 newIndex = maxFilenameLen; 452 newIndex = maxFilenameLen;
491 else 453 else
492 newIndex = newExtIndex; 454 newIndex = newExtIndex;
493 } 455 } else if (newIndex > 250) {
494 else if (newIndex > 250)
495 newIndex = 250; 456 newIndex = 250;
457 }
496 newName[newIndex++] = CRC_MARK; 458 newName[newIndex++] = CRC_MARK;
497 valueCRC = udf_crc(fidName, fidNameLen, 0); 459 valueCRC = udf_crc(fidName, fidNameLen, 0);
498 newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; 460 newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
@@ -500,12 +462,12 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
500 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4]; 462 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4];
501 newName[newIndex++] = hexChar[(valueCRC & 0x000f)]; 463 newName[newIndex++] = hexChar[(valueCRC & 0x000f)];
502 464
503 if (hasExt) 465 if (hasExt) {
504 {
505 newName[newIndex++] = EXT_MARK; 466 newName[newIndex++] = EXT_MARK;
506 for (index = 0;index < localExtIndex ;index++ ) 467 for (index = 0; index < localExtIndex; index++)
507 newName[newIndex++] = ext[index]; 468 newName[newIndex++] = ext[index];
508 } 469 }
509 } 470 }
471
510 return newIndex; 472 return newIndex;
511} 473}