aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/udf/balloc.c709
-rw-r--r--fs/udf/crc.c19
-rw-r--r--fs/udf/dir.c132
-rw-r--r--fs/udf/directory.c207
-rw-r--r--fs/udf/ecma_167.h875
-rw-r--r--fs/udf/file.c114
-rw-r--r--fs/udf/fsync.c4
-rw-r--r--fs/udf/ialloc.c69
-rw-r--r--fs/udf/inode.c1494
-rw-r--r--fs/udf/lowlevel.c25
-rw-r--r--fs/udf/misc.c172
-rw-r--r--fs/udf/namei.c720
-rw-r--r--fs/udf/osta_udf.h239
-rw-r--r--fs/udf/partition.c273
-rw-r--r--fs/udf/super.c1625
-rw-r--r--fs/udf/symlink.c56
-rw-r--r--fs/udf/truncate.c209
-rw-r--r--fs/udf/udf_i.h2
-rw-r--r--fs/udf/udf_sb.h6
-rw-r--r--fs/udf/udfdecl.h106
-rw-r--r--fs/udf/udfend.h2
-rw-r--r--fs/udf/udftime.c93
-rw-r--r--fs/udf/unicode.c299
23 files changed, 3801 insertions, 3649 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 4cec91015681..ef48d094dd2b 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;
@@ -72,17 +70,18 @@ static inline int find_next_one_bit (void * addr, int size, int offset)
72 if (!size) 70 if (!size)
73 return result; 71 return result;
74 tmp = leBPL_to_cpup(p); 72 tmp = leBPL_to_cpup(p);
75found_first: 73 found_first:
76 tmp &= ~0UL >> (BITS_PER_LONG-size); 74 tmp &= ~0UL >> (BITS_PER_LONG - size);
77found_middle: 75 found_middle:
78 return result + ffz(~tmp); 76 return result + ffz(~tmp);
79} 77}
80 78
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 =
118 retval = read_block_bitmap(sb, bitmap, block_group, block_group); 117 read_block_bitmap(sb, bitmap, block_group, 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,17 +155,22 @@ 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,
158 { 159 bloc.
159 udf_debug("%d < %d || %d + %d > %d\n", 160 partitionReferenceNum))
160 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, 161 {
161 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); 162 udf_debug("%d < %d || %d + %d > %d\n", bloc.logicalBlockNum, 0,
163 bloc.logicalBlockNum, count, UDF_SB_PARTLEN(sb,
164 bloc.
165 partitionReferenceNum));
162 goto error_return; 166 goto error_return;
163 } 167 }
164 168
165 block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3); 169 block =
170 bloc.logicalBlockNum + offset +
171 (sizeof(struct spaceBitmapDesc) << 3);
166 172
167do_more: 173 do_more:
168 overflow = 0; 174 overflow = 0;
169 block_group = block >> (sb->s_blocksize_bits + 3); 175 block_group = block >> (sb->s_blocksize_bits + 3);
170 bit = block % (sb->s_blocksize << 3); 176 bit = block % (sb->s_blocksize << 3);
@@ -172,8 +178,7 @@ do_more:
172 /* 178 /*
173 * Check to see if we are freeing blocks across a group boundary. 179 * Check to see if we are freeing blocks across a group boundary.
174 */ 180 */
175 if (bit + count > (sb->s_blocksize << 3)) 181 if (bit + count > (sb->s_blocksize << 3)) {
176 {
177 overflow = bit + count - (sb->s_blocksize << 3); 182 overflow = bit + count - (sb->s_blocksize << 3);
178 count -= overflow; 183 count -= overflow;
179 } 184 }
@@ -182,32 +187,31 @@ do_more:
182 goto error_return; 187 goto error_return;
183 188
184 bh = bitmap->s_block_bitmap[bitmap_nr]; 189 bh = bitmap->s_block_bitmap[bitmap_nr];
185 for (i=0; i < count; i++) 190 for (i = 0; i < count; i++) {
186 { 191 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); 192 udf_debug("bit %ld already set\n", bit + i);
190 udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); 193 udf_debug("byte=%2x\n",
191 } 194 ((char *)bh->b_data)[(bit + i) >> 3]);
192 else 195 } else {
193 {
194 if (inode) 196 if (inode)
195 DQUOT_FREE_BLOCK(inode, 1); 197 DQUOT_FREE_BLOCK(inode, 1);
196 if (UDF_SB_LVIDBH(sb)) 198 if (UDF_SB_LVIDBH(sb)) {
197 { 199 UDF_SB_LVID(sb)->
198 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = 200 freeSpaceTable[UDF_SB_PARTITION(sb)] =
199 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+1); 201 cpu_to_le32(le32_to_cpu
202 (UDF_SB_LVID(sb)->
203 freeSpaceTable[UDF_SB_PARTITION
204 (sb)]) + 1);
200 } 205 }
201 } 206 }
202 } 207 }
203 mark_buffer_dirty(bh); 208 mark_buffer_dirty(bh);
204 if (overflow) 209 if (overflow) {
205 {
206 block += count; 210 block += count;
207 count = overflow; 211 count = overflow;
208 goto do_more; 212 goto do_more;
209 } 213 }
210error_return: 214 error_return:
211 sb->s_dirt = 1; 215 sb->s_dirt = 1;
212 if (UDF_SB_LVIDBH(sb)) 216 if (UDF_SB_LVIDBH(sb))
213 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 217 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
@@ -215,10 +219,11 @@ error_return:
215 return; 219 return;
216} 220}
217 221
218static int udf_bitmap_prealloc_blocks(struct super_block * sb, 222static int udf_bitmap_prealloc_blocks(struct super_block *sb,
219 struct inode * inode, 223 struct inode *inode,
220 struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block, 224 struct udf_bitmap *bitmap,
221 uint32_t block_count) 225 uint16_t partition, uint32_t first_block,
226 uint32_t block_count)
222{ 227{
223 struct udf_sb_info *sbi = UDF_SB(sb); 228 struct udf_sb_info *sbi = UDF_SB(sb);
224 int alloc_count = 0; 229 int alloc_count = 0;
@@ -233,9 +238,10 @@ static int udf_bitmap_prealloc_blocks(struct super_block * sb,
233 if (first_block + block_count > UDF_SB_PARTLEN(sb, partition)) 238 if (first_block + block_count > UDF_SB_PARTLEN(sb, partition))
234 block_count = UDF_SB_PARTLEN(sb, partition) - first_block; 239 block_count = UDF_SB_PARTLEN(sb, partition) - first_block;
235 240
236repeat: 241 repeat:
237 nr_groups = (UDF_SB_PARTLEN(sb, partition) + 242 nr_groups = (UDF_SB_PARTLEN(sb, partition) +
238 (sizeof(struct spaceBitmapDesc) << 3) + (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8); 243 (sizeof(struct spaceBitmapDesc) << 3) +
244 (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8);
239 block = first_block + (sizeof(struct spaceBitmapDesc) << 3); 245 block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
240 block_group = block >> (sb->s_blocksize_bits + 3); 246 block_group = block >> (sb->s_blocksize_bits + 3);
241 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); 247 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
@@ -247,31 +253,30 @@ repeat:
247 253
248 bit = block % (sb->s_blocksize << 3); 254 bit = block % (sb->s_blocksize << 3);
249 255
250 while (bit < (sb->s_blocksize << 3) && block_count > 0) 256 while (bit < (sb->s_blocksize << 3) && block_count > 0) {
251 {
252 if (!udf_test_bit(bit, bh->b_data)) 257 if (!udf_test_bit(bit, bh->b_data))
253 goto out; 258 goto out;
254 else if (DQUOT_PREALLOC_BLOCK(inode, 1)) 259 else if (DQUOT_PREALLOC_BLOCK(inode, 1))
255 goto out; 260 goto out;
256 else if (!udf_clear_bit(bit, bh->b_data)) 261 else if (!udf_clear_bit(bit, bh->b_data)) {
257 {
258 udf_debug("bit already cleared for block %d\n", bit); 262 udf_debug("bit already cleared for block %d\n", bit);
259 DQUOT_FREE_BLOCK(inode, 1); 263 DQUOT_FREE_BLOCK(inode, 1);
260 goto out; 264 goto out;
261 } 265 }
262 block_count --; 266 block_count--;
263 alloc_count ++; 267 alloc_count++;
264 bit ++; 268 bit++;
265 block ++; 269 block++;
266 } 270 }
267 mark_buffer_dirty(bh); 271 mark_buffer_dirty(bh);
268 if (block_count > 0) 272 if (block_count > 0)
269 goto repeat; 273 goto repeat;
270out: 274 out:
271 if (UDF_SB_LVIDBH(sb)) 275 if (UDF_SB_LVIDBH(sb)) {
272 {
273 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 276 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
274 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); 277 cpu_to_le32(le32_to_cpu
278 (UDF_SB_LVID(sb)->freeSpaceTable[partition]) -
279 alloc_count);
275 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 280 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
276 } 281 }
277 sb->s_dirt = 1; 282 sb->s_dirt = 1;
@@ -279,12 +284,13 @@ out:
279 return alloc_count; 284 return alloc_count;
280} 285}
281 286
282static int udf_bitmap_new_block(struct super_block * sb, 287static int udf_bitmap_new_block(struct super_block *sb,
283 struct inode * inode, 288 struct inode *inode,
284 struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err) 289 struct udf_bitmap *bitmap, uint16_t partition,
290 uint32_t goal, int *err)
285{ 291{
286 struct udf_sb_info *sbi = UDF_SB(sb); 292 struct udf_sb_info *sbi = UDF_SB(sb);
287 int newbit, bit=0, block, block_group, group_start; 293 int newbit, bit = 0, block, block_group, group_start;
288 int end_goal, nr_groups, bitmap_nr, i; 294 int end_goal, nr_groups, bitmap_nr, i;
289 struct buffer_head *bh = NULL; 295 struct buffer_head *bh = NULL;
290 char *ptr; 296 char *ptr;
@@ -293,7 +299,7 @@ static int udf_bitmap_new_block(struct super_block * sb,
293 *err = -ENOSPC; 299 *err = -ENOSPC;
294 mutex_lock(&sbi->s_alloc_mutex); 300 mutex_lock(&sbi->s_alloc_mutex);
295 301
296repeat: 302 repeat:
297 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition)) 303 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
298 goal = 0; 304 goal = 0;
299 305
@@ -306,38 +312,39 @@ repeat:
306 if (bitmap_nr < 0) 312 if (bitmap_nr < 0)
307 goto error_return; 313 goto error_return;
308 bh = bitmap->s_block_bitmap[bitmap_nr]; 314 bh = bitmap->s_block_bitmap[bitmap_nr];
309 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); 315 ptr =
316 memscan((char *)bh->b_data + group_start, 0xFF,
317 sb->s_blocksize - group_start);
310 318
311 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) 319 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
312 {
313 bit = block % (sb->s_blocksize << 3); 320 bit = block % (sb->s_blocksize << 3);
314 321
315 if (udf_test_bit(bit, bh->b_data)) 322 if (udf_test_bit(bit, bh->b_data)) {
316 {
317 goto got_block; 323 goto got_block;
318 } 324 }
319 end_goal = (bit + 63) & ~63; 325 end_goal = (bit + 63) & ~63;
320 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit); 326 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit);
321 if (bit < end_goal) 327 if (bit < end_goal)
322 goto got_block; 328 goto got_block;
323 ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); 329 ptr =
330 memscan((char *)bh->b_data + (bit >> 3), 0xFF,
331 sb->s_blocksize - ((bit + 7) >> 3));
324 newbit = (ptr - ((char *)bh->b_data)) << 3; 332 newbit = (ptr - ((char *)bh->b_data)) << 3;
325 if (newbit < sb->s_blocksize << 3) 333 if (newbit < sb->s_blocksize << 3) {
326 {
327 bit = newbit; 334 bit = newbit;
328 goto search_back; 335 goto search_back;
329 } 336 }
330 newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); 337 newbit =
331 if (newbit < sb->s_blocksize << 3) 338 udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3,
332 { 339 bit);
340 if (newbit < sb->s_blocksize << 3) {
333 bit = newbit; 341 bit = newbit;
334 goto got_block; 342 goto got_block;
335 } 343 }
336 } 344 }
337 345
338 for (i=0; i<(nr_groups*2); i++) 346 for (i = 0; i < (nr_groups * 2); i++) {
339 { 347 block_group++;
340 block_group ++;
341 if (block_group >= nr_groups) 348 if (block_group >= nr_groups)
342 block_group = 0; 349 block_group = 0;
343 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); 350 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
@@ -346,67 +353,69 @@ repeat:
346 if (bitmap_nr < 0) 353 if (bitmap_nr < 0)
347 goto error_return; 354 goto error_return;
348 bh = bitmap->s_block_bitmap[bitmap_nr]; 355 bh = bitmap->s_block_bitmap[bitmap_nr];
349 if (i < nr_groups) 356 if (i < nr_groups) {
350 { 357 ptr =
351 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); 358 memscan((char *)bh->b_data + group_start, 0xFF,
352 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) 359 sb->s_blocksize - group_start);
353 { 360 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
354 bit = (ptr - ((char *)bh->b_data)) << 3; 361 bit = (ptr - ((char *)bh->b_data)) << 3;
355 break; 362 break;
356 } 363 }
357 } 364 } else {
358 else 365 bit =
359 { 366 udf_find_next_one_bit((char *)bh->b_data,
360 bit = udf_find_next_one_bit((char *)bh->b_data, sb->s_blocksize << 3, group_start << 3); 367 sb->s_blocksize << 3,
368 group_start << 3);
361 if (bit < sb->s_blocksize << 3) 369 if (bit < sb->s_blocksize << 3)
362 break; 370 break;
363 } 371 }
364 } 372 }
365 if (i >= (nr_groups*2)) 373 if (i >= (nr_groups * 2)) {
366 {
367 mutex_unlock(&sbi->s_alloc_mutex); 374 mutex_unlock(&sbi->s_alloc_mutex);
368 return newblock; 375 return newblock;
369 } 376 }
370 if (bit < sb->s_blocksize << 3) 377 if (bit < sb->s_blocksize << 3)
371 goto search_back; 378 goto search_back;
372 else 379 else
373 bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); 380 bit =
374 if (bit >= sb->s_blocksize << 3) 381 udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3,
375 { 382 group_start << 3);
383 if (bit >= sb->s_blocksize << 3) {
376 mutex_unlock(&sbi->s_alloc_mutex); 384 mutex_unlock(&sbi->s_alloc_mutex);
377 return 0; 385 return 0;
378 } 386 }
379 387
380search_back: 388 search_back:
381 for (i=0; i<7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--); 389 for (i = 0;
390 i < 7 && bit > (group_start << 3)
391 && udf_test_bit(bit - 1, bh->b_data); i++, bit--) ;
382 392
383got_block: 393 got_block:
384 394
385 /* 395 /*
386 * Check quota for allocation of this block. 396 * Check quota for allocation of this block.
387 */ 397 */
388 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) 398 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) {
389 {
390 mutex_unlock(&sbi->s_alloc_mutex); 399 mutex_unlock(&sbi->s_alloc_mutex);
391 *err = -EDQUOT; 400 *err = -EDQUOT;
392 return 0; 401 return 0;
393 } 402 }
394 403
395 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - 404 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
396 (sizeof(struct spaceBitmapDesc) << 3); 405 (sizeof(struct spaceBitmapDesc) << 3);
397 406
398 if (!udf_clear_bit(bit, bh->b_data)) 407 if (!udf_clear_bit(bit, bh->b_data)) {
399 {
400 udf_debug("bit already cleared for block %d\n", bit); 408 udf_debug("bit already cleared for block %d\n", bit);
401 goto repeat; 409 goto repeat;
402 } 410 }
403 411
404 mark_buffer_dirty(bh); 412 mark_buffer_dirty(bh);
405 413
406 if (UDF_SB_LVIDBH(sb)) 414 if (UDF_SB_LVIDBH(sb)) {
407 {
408 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 415 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
409 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); 416 cpu_to_le32(le32_to_cpu
417 (UDF_SB_LVID(sb)->freeSpaceTable[partition]) -
418 1);
410 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 419 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
411 } 420 }
412 sb->s_dirt = 1; 421 sb->s_dirt = 1;
@@ -414,16 +423,17 @@ got_block:
414 *err = 0; 423 *err = 0;
415 return newblock; 424 return newblock;
416 425
417error_return: 426 error_return:
418 *err = -EIO; 427 *err = -EIO;
419 mutex_unlock(&sbi->s_alloc_mutex); 428 mutex_unlock(&sbi->s_alloc_mutex);
420 return 0; 429 return 0;
421} 430}
422 431
423static void udf_table_free_blocks(struct super_block * sb, 432static void udf_table_free_blocks(struct super_block *sb,
424 struct inode * inode, 433 struct inode *inode,
425 struct inode * table, 434 struct inode *table,
426 kernel_lb_addr bloc, uint32_t offset, uint32_t count) 435 kernel_lb_addr bloc, uint32_t offset,
436 uint32_t count)
427{ 437{
428 struct udf_sb_info *sbi = UDF_SB(sb); 438 struct udf_sb_info *sbi = UDF_SB(sb);
429 uint32_t start, end; 439 uint32_t start, end;
@@ -435,11 +445,14 @@ static void udf_table_free_blocks(struct super_block * sb,
435 445
436 mutex_lock(&sbi->s_alloc_mutex); 446 mutex_lock(&sbi->s_alloc_mutex);
437 if (bloc.logicalBlockNum < 0 || 447 if (bloc.logicalBlockNum < 0 ||
438 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) 448 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb,
439 { 449 bloc.
440 udf_debug("%d < %d || %d + %d > %d\n", 450 partitionReferenceNum))
441 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, 451 {
442 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); 452 udf_debug("%d < %d || %d + %d > %d\n", bloc.logicalBlockNum, 0,
453 bloc.logicalBlockNum, count, UDF_SB_PARTLEN(sb,
454 bloc.
455 partitionReferenceNum));
443 goto error_return; 456 goto error_return;
444 } 457 }
445 458
@@ -447,10 +460,11 @@ static void udf_table_free_blocks(struct super_block * sb,
447 but.. oh well */ 460 but.. oh well */
448 if (inode) 461 if (inode)
449 DQUOT_FREE_BLOCK(inode, count); 462 DQUOT_FREE_BLOCK(inode, count);
450 if (UDF_SB_LVIDBH(sb)) 463 if (UDF_SB_LVIDBH(sb)) {
451 {
452 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = 464 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); 465 cpu_to_le32(le32_to_cpu
466 (UDF_SB_LVID(sb)->
467 freeSpaceTable[UDF_SB_PARTITION(sb)]) + count);
454 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 468 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
455 } 469 }
456 470
@@ -463,73 +477,75 @@ static void udf_table_free_blocks(struct super_block * sb,
463 epos.bh = oepos.bh = NULL; 477 epos.bh = oepos.bh = NULL;
464 478
465 while (count && (etype = 479 while (count && (etype =
466 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 480 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
467 {
468 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == 481 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) ==
469 start)) 482 start)) {
470 { 483 if ((0x3FFFFFFF - elen) <
471 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) 484 (count << sb->s_blocksize_bits)) {
472 { 485 count -=
473 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 486 ((0x3FFFFFFF -
474 start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 487 elen) >> sb->s_blocksize_bits);
475 elen = (etype << 30) | (0x40000000 - sb->s_blocksize); 488 start +=
476 } 489 ((0x3FFFFFFF -
477 else 490 elen) >> sb->s_blocksize_bits);
478 { 491 elen =
492 (etype << 30) | (0x40000000 -
493 sb->s_blocksize);
494 } else {
479 elen = (etype << 30) | 495 elen = (etype << 30) |
480 (elen + (count << sb->s_blocksize_bits)); 496 (elen + (count << sb->s_blocksize_bits));
481 start += count; 497 start += count;
482 count = 0; 498 count = 0;
483 } 499 }
484 udf_write_aext(table, &oepos, eloc, elen, 1); 500 udf_write_aext(table, &oepos, eloc, elen, 1);
485 } 501 } else if (eloc.logicalBlockNum == (end + 1)) {
486 else if (eloc.logicalBlockNum == (end + 1)) 502 if ((0x3FFFFFFF - elen) <
487 { 503 (count << sb->s_blocksize_bits)) {
488 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) 504 count -=
489 { 505 ((0x3FFFFFFF -
490 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 506 elen) >> sb->s_blocksize_bits);
491 end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 507 end -=
508 ((0x3FFFFFFF -
509 elen) >> sb->s_blocksize_bits);
492 eloc.logicalBlockNum -= 510 eloc.logicalBlockNum -=
493 ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); 511 ((0x3FFFFFFF -
494 elen = (etype << 30) | (0x40000000 - sb->s_blocksize); 512 elen) >> sb->s_blocksize_bits);
495 } 513 elen =
496 else 514 (etype << 30) | (0x40000000 -
497 { 515 sb->s_blocksize);
516 } else {
498 eloc.logicalBlockNum = start; 517 eloc.logicalBlockNum = start;
499 elen = (etype << 30) | 518 elen = (etype << 30) |
500 (elen + (count << sb->s_blocksize_bits)); 519 (elen + (count << sb->s_blocksize_bits));
501 end -= count; 520 end -= count;
502 count = 0; 521 count = 0;
503 } 522 }
504 udf_write_aext(table, &oepos, eloc, elen, 1); 523 udf_write_aext(table, &oepos, eloc, elen, 1);
505 } 524 }
506 525
507 if (epos.bh != oepos.bh) 526 if (epos.bh != oepos.bh) {
508 {
509 i = -1; 527 i = -1;
510 oepos.block = epos.block; 528 oepos.block = epos.block;
511 brelse(oepos.bh); 529 brelse(oepos.bh);
512 get_bh(epos.bh); 530 get_bh(epos.bh);
513 oepos.bh = epos.bh; 531 oepos.bh = epos.bh;
514 oepos.offset = 0; 532 oepos.offset = 0;
515 } 533 } else
516 else
517 oepos.offset = epos.offset; 534 oepos.offset = epos.offset;
518 } 535 }
519 536
520 if (count) 537 if (count) {
521 {
522 /* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate 538 /* 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 539 a new block, and since we hold the super block lock already
524 very bad things would happen :) 540 very bad things would happen :)
525 541
526 We copy the behavior of udf_add_aext, but instead of 542 We copy the behavior of udf_add_aext, but instead of
527 trying to allocate a new block close to the existing one, 543 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. 544 we just steal a block from the extent we are trying to add.
529 545
530 It would be nice if the blocks were close together, but it 546 It would be nice if the blocks were close together, but it
531 isn't required. 547 isn't required.
532 */ 548 */
533 549
534 int adsize; 550 int adsize;
535 short_ad *sad = NULL; 551 short_ad *sad = NULL;
@@ -537,121 +553,124 @@ static void udf_table_free_blocks(struct super_block * sb,
537 struct allocExtDesc *aed; 553 struct allocExtDesc *aed;
538 554
539 eloc.logicalBlockNum = start; 555 eloc.logicalBlockNum = start;
540 elen = EXT_RECORDED_ALLOCATED | 556 elen = EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits);
541 (count << sb->s_blocksize_bits);
542 557
543 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) 558 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
544 adsize = sizeof(short_ad); 559 adsize = sizeof(short_ad);
545 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) 560 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
546 adsize = sizeof(long_ad); 561 adsize = sizeof(long_ad);
547 else 562 else {
548 {
549 brelse(oepos.bh); 563 brelse(oepos.bh);
550 brelse(epos.bh); 564 brelse(epos.bh);
551 goto error_return; 565 goto error_return;
552 } 566 }
553 567
554 if (epos.offset + (2 * adsize) > sb->s_blocksize) 568 if (epos.offset + (2 * adsize) > sb->s_blocksize) {
555 {
556 char *sptr, *dptr; 569 char *sptr, *dptr;
557 int loffset; 570 int loffset;
558 571
559 brelse(oepos.bh); 572 brelse(oepos.bh);
560 oepos = epos; 573 oepos = epos;
561 574
562 /* Steal a block from the extent being free'd */ 575 /* Steal a block from the extent being free'd */
563 epos.block.logicalBlockNum = eloc.logicalBlockNum; 576 epos.block.logicalBlockNum = eloc.logicalBlockNum;
564 eloc.logicalBlockNum ++; 577 eloc.logicalBlockNum++;
565 elen -= sb->s_blocksize; 578 elen -= sb->s_blocksize;
566 579
567 if (!(epos.bh = udf_tread(sb, 580 if (!(epos.bh = udf_tread(sb,
568 udf_get_lb_pblock(sb, epos.block, 0)))) 581 udf_get_lb_pblock(sb,
569 { 582 epos.block,
583 0)))) {
570 brelse(oepos.bh); 584 brelse(oepos.bh);
571 goto error_return; 585 goto error_return;
572 } 586 }
573 aed = (struct allocExtDesc *)(epos.bh->b_data); 587 aed = (struct allocExtDesc *)(epos.bh->b_data);
574 aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); 588 aed->previousAllocExtLocation =
575 if (epos.offset + adsize > sb->s_blocksize) 589 cpu_to_le32(oepos.block.logicalBlockNum);
576 { 590 if (epos.offset + adsize > sb->s_blocksize) {
577 loffset = epos.offset; 591 loffset = epos.offset;
578 aed->lengthAllocDescs = cpu_to_le32(adsize); 592 aed->lengthAllocDescs = cpu_to_le32(adsize);
579 sptr = UDF_I_DATA(inode) + epos.offset - 593 sptr = UDF_I_DATA(inode) + epos.offset -
580 udf_file_entry_alloc_offset(inode) + 594 udf_file_entry_alloc_offset(inode) +
581 UDF_I_LENEATTR(inode) - adsize; 595 UDF_I_LENEATTR(inode) - adsize;
582 dptr = epos.bh->b_data + sizeof(struct allocExtDesc); 596 dptr =
597 epos.bh->b_data +
598 sizeof(struct allocExtDesc);
583 memcpy(dptr, sptr, adsize); 599 memcpy(dptr, sptr, adsize);
584 epos.offset = sizeof(struct allocExtDesc) + adsize; 600 epos.offset =
585 } 601 sizeof(struct allocExtDesc) + adsize;
586 else 602 } else {
587 {
588 loffset = epos.offset + adsize; 603 loffset = epos.offset + adsize;
589 aed->lengthAllocDescs = cpu_to_le32(0); 604 aed->lengthAllocDescs = cpu_to_le32(0);
590 sptr = oepos.bh->b_data + epos.offset; 605 sptr = oepos.bh->b_data + epos.offset;
591 epos.offset = sizeof(struct allocExtDesc); 606 epos.offset = sizeof(struct allocExtDesc);
592 607
593 if (oepos.bh) 608 if (oepos.bh) {
594 { 609 aed =
595 aed = (struct allocExtDesc *)oepos.bh->b_data; 610 (struct allocExtDesc *)oepos.bh->
611 b_data;
596 aed->lengthAllocDescs = 612 aed->lengthAllocDescs =
597 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 613 cpu_to_le32(le32_to_cpu
598 } 614 (aed->
599 else 615 lengthAllocDescs) +
600 { 616 adsize);
617 } else {
601 UDF_I_LENALLOC(table) += adsize; 618 UDF_I_LENALLOC(table) += adsize;
602 mark_inode_dirty(table); 619 mark_inode_dirty(table);
603 } 620 }
604 } 621 }
605 if (UDF_SB_UDFREV(sb) >= 0x0200) 622 if (UDF_SB_UDFREV(sb) >= 0x0200)
606 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, 623 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3,
607 epos.block.logicalBlockNum, sizeof(tag)); 624 1, epos.block.logicalBlockNum,
625 sizeof(tag));
608 else 626 else
609 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, 627 udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2,
610 epos.block.logicalBlockNum, sizeof(tag)); 628 1, epos.block.logicalBlockNum,
611 switch (UDF_I_ALLOCTYPE(table)) 629 sizeof(tag));
612 { 630 switch (UDF_I_ALLOCTYPE(table)) {
613 case ICBTAG_FLAG_AD_SHORT: 631 case ICBTAG_FLAG_AD_SHORT:
614 { 632 {
615 sad = (short_ad *)sptr; 633 sad = (short_ad *) sptr;
616 sad->extLength = cpu_to_le32( 634 sad->extLength =
617 EXT_NEXT_EXTENT_ALLOCDECS | 635 cpu_to_le32
618 sb->s_blocksize); 636 (EXT_NEXT_EXTENT_ALLOCDECS | sb->
619 sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); 637 s_blocksize);
638 sad->extPosition =
639 cpu_to_le32(epos.block.
640 logicalBlockNum);
620 break; 641 break;
621 } 642 }
622 case ICBTAG_FLAG_AD_LONG: 643 case ICBTAG_FLAG_AD_LONG:
623 { 644 {
624 lad = (long_ad *)sptr; 645 lad = (long_ad *) sptr;
625 lad->extLength = cpu_to_le32( 646 lad->extLength =
626 EXT_NEXT_EXTENT_ALLOCDECS | 647 cpu_to_le32
627 sb->s_blocksize); 648 (EXT_NEXT_EXTENT_ALLOCDECS | sb->
628 lad->extLocation = cpu_to_lelb(epos.block); 649 s_blocksize);
650 lad->extLocation =
651 cpu_to_lelb(epos.block);
629 break; 652 break;
630 } 653 }
631 } 654 }
632 if (oepos.bh) 655 if (oepos.bh) {
633 {
634 udf_update_tag(oepos.bh->b_data, loffset); 656 udf_update_tag(oepos.bh->b_data, loffset);
635 mark_buffer_dirty(oepos.bh); 657 mark_buffer_dirty(oepos.bh);
636 } 658 } else
637 else
638 mark_inode_dirty(table); 659 mark_inode_dirty(table);
639 } 660 }
640 661
641 if (elen) /* It's possible that stealing the block emptied the extent */ 662 if (elen) { /* It's possible that stealing the block emptied the extent */
642 {
643 udf_write_aext(table, &epos, eloc, elen, 1); 663 udf_write_aext(table, &epos, eloc, elen, 1);
644 664
645 if (!epos.bh) 665 if (!epos.bh) {
646 {
647 UDF_I_LENALLOC(table) += adsize; 666 UDF_I_LENALLOC(table) += adsize;
648 mark_inode_dirty(table); 667 mark_inode_dirty(table);
649 } 668 } else {
650 else
651 {
652 aed = (struct allocExtDesc *)epos.bh->b_data; 669 aed = (struct allocExtDesc *)epos.bh->b_data;
653 aed->lengthAllocDescs = 670 aed->lengthAllocDescs =
654 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 671 cpu_to_le32(le32_to_cpu
672 (aed->lengthAllocDescs) +
673 adsize);
655 udf_update_tag(epos.bh->b_data, epos.offset); 674 udf_update_tag(epos.bh->b_data, epos.offset);
656 mark_buffer_dirty(epos.bh); 675 mark_buffer_dirty(epos.bh);
657 } 676 }
@@ -661,16 +680,16 @@ static void udf_table_free_blocks(struct super_block * sb,
661 brelse(epos.bh); 680 brelse(epos.bh);
662 brelse(oepos.bh); 681 brelse(oepos.bh);
663 682
664error_return: 683 error_return:
665 sb->s_dirt = 1; 684 sb->s_dirt = 1;
666 mutex_unlock(&sbi->s_alloc_mutex); 685 mutex_unlock(&sbi->s_alloc_mutex);
667 return; 686 return;
668} 687}
669 688
670static int udf_table_prealloc_blocks(struct super_block * sb, 689static int udf_table_prealloc_blocks(struct super_block *sb,
671 struct inode * inode, 690 struct inode *inode,
672 struct inode *table, uint16_t partition, uint32_t first_block, 691 struct inode *table, uint16_t partition,
673 uint32_t block_count) 692 uint32_t first_block, uint32_t block_count)
674{ 693{
675 struct udf_sb_info *sbi = UDF_SB(sb); 694 struct udf_sb_info *sbi = UDF_SB(sb);
676 int alloc_count = 0; 695 int alloc_count = 0;
@@ -696,39 +715,46 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
696 eloc.logicalBlockNum = 0xFFFFFFFF; 715 eloc.logicalBlockNum = 0xFFFFFFFF;
697 716
698 while (first_block != eloc.logicalBlockNum && (etype = 717 while (first_block != eloc.logicalBlockNum && (etype =
699 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 718 udf_next_aext(table,
700 { 719 &epos,
720 &eloc,
721 &elen,
722 1)) !=
723 -1) {
701 udf_debug("eloc=%d, elen=%d, first_block=%d\n", 724 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
702 eloc.logicalBlockNum, elen, first_block); 725 eloc.logicalBlockNum, elen, first_block);
703 ; /* empty loop body */ 726 ; /* empty loop body */
704 } 727 }
705 728
706 if (first_block == eloc.logicalBlockNum) 729 if (first_block == eloc.logicalBlockNum) {
707 {
708 epos.offset -= adsize; 730 epos.offset -= adsize;
709 731
710 alloc_count = (elen >> sb->s_blocksize_bits); 732 alloc_count = (elen >> sb->s_blocksize_bits);
711 if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) 733 if (inode
734 && DQUOT_PREALLOC_BLOCK(inode,
735 alloc_count >
736 block_count ? block_count :
737 alloc_count))
712 alloc_count = 0; 738 alloc_count = 0;
713 else if (alloc_count > block_count) 739 else if (alloc_count > block_count) {
714 {
715 alloc_count = block_count; 740 alloc_count = block_count;
716 eloc.logicalBlockNum += alloc_count; 741 eloc.logicalBlockNum += alloc_count;
717 elen -= (alloc_count << sb->s_blocksize_bits); 742 elen -= (alloc_count << sb->s_blocksize_bits);
718 udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); 743 udf_write_aext(table, &epos, eloc, (etype << 30) | elen,
719 } 744 1);
720 else 745 } else
721 udf_delete_aext(table, epos, eloc, (etype << 30) | elen); 746 udf_delete_aext(table, epos, eloc,
722 } 747 (etype << 30) | elen);
723 else 748 } else
724 alloc_count = 0; 749 alloc_count = 0;
725 750
726 brelse(epos.bh); 751 brelse(epos.bh);
727 752
728 if (alloc_count && UDF_SB_LVIDBH(sb)) 753 if (alloc_count && UDF_SB_LVIDBH(sb)) {
729 {
730 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 754 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
731 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); 755 cpu_to_le32(le32_to_cpu
756 (UDF_SB_LVID(sb)->freeSpaceTable[partition]) -
757 alloc_count);
732 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 758 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
733 sb->s_dirt = 1; 759 sb->s_dirt = 1;
734 } 760 }
@@ -736,9 +762,10 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
736 return alloc_count; 762 return alloc_count;
737} 763}
738 764
739static int udf_table_new_block(struct super_block * sb, 765static int udf_table_new_block(struct super_block *sb,
740 struct inode * inode, 766 struct inode *inode,
741 struct inode *table, uint16_t partition, uint32_t goal, int *err) 767 struct inode *table, uint16_t partition,
768 uint32_t goal, int *err)
742{ 769{
743 struct udf_sb_info *sbi = UDF_SB(sb); 770 struct udf_sb_info *sbi = UDF_SB(sb);
744 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; 771 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
@@ -765,30 +792,27 @@ static int udf_table_new_block(struct super_block * sb,
765 we stop. Otherwise we keep going till we run out of extents. 792 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 793 We store the buffer_head, bloc, and extoffset of the current closest
767 match and use that when we are done. 794 match and use that when we are done.
768 */ 795 */
769 epos.offset = sizeof(struct unallocSpaceEntry); 796 epos.offset = sizeof(struct unallocSpaceEntry);
770 epos.block = UDF_I_LOCATION(table); 797 epos.block = UDF_I_LOCATION(table);
771 epos.bh = goal_epos.bh = NULL; 798 epos.bh = goal_epos.bh = NULL;
772 799
773 while (spread && (etype = 800 while (spread && (etype =
774 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) 801 udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
775 { 802 if (goal >= eloc.logicalBlockNum) {
776 if (goal >= eloc.logicalBlockNum) 803 if (goal <
777 { 804 eloc.logicalBlockNum +
778 if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) 805 (elen >> sb->s_blocksize_bits))
779 nspread = 0; 806 nspread = 0;
780 else 807 else
781 nspread = goal - eloc.logicalBlockNum - 808 nspread = goal - eloc.logicalBlockNum -
782 (elen >> sb->s_blocksize_bits); 809 (elen >> sb->s_blocksize_bits);
783 } 810 } else
784 else
785 nspread = eloc.logicalBlockNum - goal; 811 nspread = eloc.logicalBlockNum - goal;
786 812
787 if (nspread < spread) 813 if (nspread < spread) {
788 {
789 spread = nspread; 814 spread = nspread;
790 if (goal_epos.bh != epos.bh) 815 if (goal_epos.bh != epos.bh) {
791 {
792 brelse(goal_epos.bh); 816 brelse(goal_epos.bh);
793 goal_epos.bh = epos.bh; 817 goal_epos.bh = epos.bh;
794 get_bh(goal_epos.bh); 818 get_bh(goal_epos.bh);
@@ -802,8 +826,7 @@ static int udf_table_new_block(struct super_block * sb,
802 826
803 brelse(epos.bh); 827 brelse(epos.bh);
804 828
805 if (spread == 0xFFFFFFFF) 829 if (spread == 0xFFFFFFFF) {
806 {
807 brelse(goal_epos.bh); 830 brelse(goal_epos.bh);
808 mutex_unlock(&sbi->s_alloc_mutex); 831 mutex_unlock(&sbi->s_alloc_mutex);
809 return 0; 832 return 0;
@@ -815,11 +838,10 @@ static int udf_table_new_block(struct super_block * sb,
815 /* This works, but very poorly.... */ 838 /* This works, but very poorly.... */
816 839
817 newblock = goal_eloc.logicalBlockNum; 840 newblock = goal_eloc.logicalBlockNum;
818 goal_eloc.logicalBlockNum ++; 841 goal_eloc.logicalBlockNum++;
819 goal_elen -= sb->s_blocksize; 842 goal_elen -= sb->s_blocksize;
820 843
821 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) 844 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) {
822 {
823 brelse(goal_epos.bh); 845 brelse(goal_epos.bh);
824 mutex_unlock(&sbi->s_alloc_mutex); 846 mutex_unlock(&sbi->s_alloc_mutex);
825 *err = -EDQUOT; 847 *err = -EDQUOT;
@@ -832,10 +854,11 @@ static int udf_table_new_block(struct super_block * sb,
832 udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); 854 udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
833 brelse(goal_epos.bh); 855 brelse(goal_epos.bh);
834 856
835 if (UDF_SB_LVIDBH(sb)) 857 if (UDF_SB_LVIDBH(sb)) {
836 {
837 UDF_SB_LVID(sb)->freeSpaceTable[partition] = 858 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
838 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); 859 cpu_to_le32(le32_to_cpu
860 (UDF_SB_LVID(sb)->freeSpaceTable[partition]) -
861 1);
839 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 862 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
840 } 863 }
841 864
@@ -845,105 +868,99 @@ static int udf_table_new_block(struct super_block * sb,
845 return newblock; 868 return newblock;
846} 869}
847 870
848inline void udf_free_blocks(struct super_block * sb, 871inline void udf_free_blocks(struct super_block *sb,
849 struct inode * inode, 872 struct inode *inode,
850 kernel_lb_addr bloc, uint32_t offset, uint32_t count) 873 kernel_lb_addr bloc, uint32_t offset,
874 uint32_t count)
851{ 875{
852 uint16_t partition = bloc.partitionReferenceNum; 876 uint16_t partition = bloc.partitionReferenceNum;
853 877
854 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 878 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
855 {
856 return udf_bitmap_free_blocks(sb, inode, 879 return udf_bitmap_free_blocks(sb, inode,
857 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 880 UDF_SB_PARTMAPS(sb)[partition].
858 bloc, offset, count); 881 s_uspace.s_bitmap, bloc, offset,
859 } 882 count);
860 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) 883 } else if (UDF_SB_PARTFLAGS(sb, partition) &
861 { 884 UDF_PART_FLAG_UNALLOC_TABLE) {
862 return udf_table_free_blocks(sb, inode, 885 return udf_table_free_blocks(sb, inode,
863 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 886 UDF_SB_PARTMAPS(sb)[partition].
864 bloc, offset, count); 887 s_uspace.s_table, bloc, offset,
865 } 888 count);
866 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) 889 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
867 {
868 return udf_bitmap_free_blocks(sb, inode, 890 return udf_bitmap_free_blocks(sb, inode,
869 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 891 UDF_SB_PARTMAPS(sb)[partition].
870 bloc, offset, count); 892 s_fspace.s_bitmap, bloc, offset,
871 } 893 count);
872 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) 894 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
873 {
874 return udf_table_free_blocks(sb, inode, 895 return udf_table_free_blocks(sb, inode,
875 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 896 UDF_SB_PARTMAPS(sb)[partition].
876 bloc, offset, count); 897 s_fspace.s_table, bloc, offset,
877 } 898 count);
878 else 899 } else
879 return; 900 return;
880} 901}
881 902
882inline int udf_prealloc_blocks(struct super_block * sb, 903inline int udf_prealloc_blocks(struct super_block *sb,
883 struct inode * inode, 904 struct inode *inode,
884 uint16_t partition, uint32_t first_block, uint32_t block_count) 905 uint16_t partition, uint32_t first_block,
906 uint32_t block_count)
885{ 907{
886 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 908 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
887 {
888 return udf_bitmap_prealloc_blocks(sb, inode, 909 return udf_bitmap_prealloc_blocks(sb, inode,
889 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 910 UDF_SB_PARTMAPS(sb)
890 partition, first_block, block_count); 911 [partition].s_uspace.s_bitmap,
891 } 912 partition, first_block,
892 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) 913 block_count);
893 { 914 } else if (UDF_SB_PARTFLAGS(sb, partition) &
915 UDF_PART_FLAG_UNALLOC_TABLE) {
894 return udf_table_prealloc_blocks(sb, inode, 916 return udf_table_prealloc_blocks(sb, inode,
895 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 917 UDF_SB_PARTMAPS(sb)[partition].
896 partition, first_block, block_count); 918 s_uspace.s_table, partition,
897 } 919 first_block, block_count);
898 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) 920 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
899 {
900 return udf_bitmap_prealloc_blocks(sb, inode, 921 return udf_bitmap_prealloc_blocks(sb, inode,
901 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 922 UDF_SB_PARTMAPS(sb)
902 partition, first_block, block_count); 923 [partition].s_fspace.s_bitmap,
903 } 924 partition, first_block,
904 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) 925 block_count);
905 { 926 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
906 return udf_table_prealloc_blocks(sb, inode, 927 return udf_table_prealloc_blocks(sb, inode,
907 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 928 UDF_SB_PARTMAPS(sb)[partition].
908 partition, first_block, block_count); 929 s_fspace.s_table, partition,
909 } 930 first_block, block_count);
910 else 931 } else
911 return 0; 932 return 0;
912} 933}
913 934
914inline int udf_new_block(struct super_block * sb, 935inline int udf_new_block(struct super_block *sb,
915 struct inode * inode, 936 struct inode *inode,
916 uint16_t partition, uint32_t goal, int *err) 937 uint16_t partition, uint32_t goal, int *err)
917{ 938{
918 int ret; 939 int ret;
919 940
920 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) 941 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
921 {
922 ret = udf_bitmap_new_block(sb, inode, 942 ret = udf_bitmap_new_block(sb, inode,
923 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, 943 UDF_SB_PARTMAPS(sb)[partition].
924 partition, goal, err); 944 s_uspace.s_bitmap, partition, goal,
945 err);
925 return ret; 946 return ret;
926 } 947 } else if (UDF_SB_PARTFLAGS(sb, partition) &
927 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) 948 UDF_PART_FLAG_UNALLOC_TABLE) {
928 {
929 return udf_table_new_block(sb, inode, 949 return udf_table_new_block(sb, inode,
930 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, 950 UDF_SB_PARTMAPS(sb)[partition].
931 partition, goal, err); 951 s_uspace.s_table, partition, goal,
932 } 952 err);
933 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) 953 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
934 {
935 return udf_bitmap_new_block(sb, inode, 954 return udf_bitmap_new_block(sb, inode,
936 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, 955 UDF_SB_PARTMAPS(sb)[partition].
937 partition, goal, err); 956 s_fspace.s_bitmap, partition, goal,
938 } 957 err);
939 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) 958 } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
940 {
941 return udf_table_new_block(sb, inode, 959 return udf_table_new_block(sb, inode,
942 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, 960 UDF_SB_PARTMAPS(sb)[partition].
943 partition, goal, err); 961 s_fspace.s_table, partition, goal,
944 } 962 err);
945 else 963 } else {
946 {
947 *err = -EIO; 964 *err = -EIO;
948 return 0; 965 return 0;
949 } 966 }
diff --git a/fs/udf/crc.c b/fs/udf/crc.c
index ef2bfaa19d75..ae3d49790941 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);
@@ -112,7 +111,7 @@ int main(void)
112 return 0; 111 return 0;
113} 112}
114 113
115#endif /* defined(TEST) */ 114#endif /* defined(TEST) */
116 115
117/****************************************************************************/ 116/****************************************************************************/
118#if defined(GENERATE) 117#if defined(GENERATE)
@@ -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");
@@ -170,4 +169,4 @@ int main(int argc, char **argv)
170 return 0; 169 return 0;
171} 170}
172 171
173#endif /* defined(GENERATE) */ 172#endif /* defined(GENERATE) */
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index e45f86b5e7b0..79bab9fe120c 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -43,10 +43,10 @@ static int do_udf_readdir(struct inode *, struct file *, filldir_t, void *);
43/* readdir and lookup functions */ 43/* readdir and lookup functions */
44 44
45const struct file_operations udf_dir_operations = { 45const struct file_operations udf_dir_operations = {
46 .read = generic_read_dir, 46 .read = generic_read_dir,
47 .readdir = udf_readdir, 47 .readdir = udf_readdir,
48 .ioctl = udf_ioctl, 48 .ioctl = udf_ioctl,
49 .fsync = udf_fsync_file, 49 .fsync = udf_fsync_file,
50}; 50};
51 51
52/* 52/*
@@ -82,26 +82,26 @@ 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) <
87 if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) 87 0) {
88 {
89 unlock_kernel(); 88 unlock_kernel();
90 return 0; 89 return 0;
91 } 90 }
92 filp->f_pos ++; 91 filp->f_pos++;
93 } 92 }
94 93
95 result = do_udf_readdir(dir, filp, filldir, dirent); 94 result = do_udf_readdir(dir, filp, filldir, dirent);
96 unlock_kernel(); 95 unlock_kernel();
97 return result; 96 return result;
98} 97}
99 98
100static int 99static int
101do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *dirent) 100do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
101 void *dirent)
102{ 102{
103 struct udf_fileident_bh fibh; 103 struct udf_fileident_bh fibh;
104 struct fileIdentDesc *fi=NULL; 104 struct fileIdentDesc *fi = NULL;
105 struct fileIdentDesc cfi; 105 struct fileIdentDesc cfi;
106 int block, iblock; 106 int block, iblock;
107 loff_t nf_pos = filp->f_pos - 1; 107 loff_t nf_pos = filp->f_pos - 1;
@@ -117,7 +117,7 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
117 sector_t offset; 117 sector_t offset;
118 int i, num; 118 int i, num;
119 unsigned int dt_type; 119 unsigned int dt_type;
120 struct extent_position epos = { NULL, 0, {0, 0}}; 120 struct extent_position epos = { NULL, 0, {0, 0} };
121 121
122 if (nf_pos >= size) 122 if (nf_pos >= size)
123 return 0; 123 return 0;
@@ -125,65 +125,61 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
125 if (nf_pos == 0) 125 if (nf_pos == 0)
126 nf_pos = (udf_ext0_offset(dir) >> 2); 126 nf_pos = (udf_ext0_offset(dir) >> 2);
127 127
128 fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 128 fibh.soffset = fibh.eoffset =
129 (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
129 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 130 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
130 fibh.sbh = fibh.ebh = NULL; 131 fibh.sbh = fibh.ebh = NULL;
131 else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), 132 else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
132 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 133 &epos, &eloc, &elen,
133 { 134 &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
134 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 135 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
135 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 136 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
136 {
137 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 137 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
138 epos.offset -= sizeof(short_ad); 138 epos.offset -= sizeof(short_ad);
139 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 139 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
140 epos.offset -= sizeof(long_ad); 140 epos.offset -= sizeof(long_ad);
141 } 141 } else
142 else
143 offset = 0; 142 offset = 0;
144 143
145 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) 144 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
146 {
147 brelse(epos.bh); 145 brelse(epos.bh);
148 return -EIO; 146 return -EIO;
149 } 147 }
150 148
151 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) 149 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
152 {
153 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 150 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
154 if (i+offset > (elen >> dir->i_sb->s_blocksize_bits)) 151 if (i + offset > (elen >> dir->i_sb->s_blocksize_bits))
155 i = (elen >> dir->i_sb->s_blocksize_bits)-offset; 152 i = (elen >> dir->i_sb->s_blocksize_bits) -
156 for (num=0; i>0; i--) 153 offset;
157 { 154 for (num = 0; i > 0; i--) {
158 block = udf_get_lb_pblock(dir->i_sb, eloc, offset+i); 155 block =
156 udf_get_lb_pblock(dir->i_sb, eloc,
157 offset + i);
159 tmp = udf_tgetblk(dir->i_sb, block); 158 tmp = udf_tgetblk(dir->i_sb, block);
160 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 159 if (tmp && !buffer_uptodate(tmp)
160 && !buffer_locked(tmp))
161 bha[num++] = tmp; 161 bha[num++] = tmp;
162 else 162 else
163 brelse(tmp); 163 brelse(tmp);
164 } 164 }
165 if (num) 165 if (num) {
166 {
167 ll_rw_block(READA, num, bha); 166 ll_rw_block(READA, num, bha);
168 for (i=0; i<num; i++) 167 for (i = 0; i < num; i++)
169 brelse(bha[i]); 168 brelse(bha[i]);
170 } 169 }
171 } 170 }
172 } 171 } else {
173 else
174 {
175 brelse(epos.bh); 172 brelse(epos.bh);
176 return -ENOENT; 173 return -ENOENT;
177 } 174 }
178 175
179 while ( nf_pos < size ) 176 while (nf_pos < size) {
180 {
181 filp->f_pos = nf_pos + 1; 177 filp->f_pos = nf_pos + 1;
182 178
183 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset); 179 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc,
180 &elen, &offset);
184 181
185 if (!fi) 182 if (!fi) {
186 {
187 if (fibh.sbh != fibh.ebh) 183 if (fibh.sbh != fibh.ebh)
188 brelse(fibh.ebh); 184 brelse(fibh.ebh);
189 brelse(fibh.sbh); 185 brelse(fibh.sbh);
@@ -196,43 +192,41 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
196 192
197 if (fibh.sbh == fibh.ebh) 193 if (fibh.sbh == fibh.ebh)
198 nameptr = fi->fileIdent + liu; 194 nameptr = fi->fileIdent + liu;
199 else 195 else {
200 {
201 int poffset; /* Unpaded ending offset */ 196 int poffset; /* Unpaded ending offset */
202 197
203 poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi; 198 poffset =
199 fibh.soffset + sizeof(struct fileIdentDesc) + liu +
200 lfi;
204 201
205 if (poffset >= lfi) 202 if (poffset >= lfi)
206 nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); 203 nameptr =
207 else 204 (char *)(fibh.ebh->b_data + poffset - lfi);
208 { 205 else {
209 nameptr = fname; 206 nameptr = fname;
210 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 207 memcpy(nameptr, fi->fileIdent + liu,
211 memcpy(nameptr + lfi - poffset, fibh.ebh->b_data, poffset); 208 lfi - poffset);
209 memcpy(nameptr + lfi - poffset,
210 fibh.ebh->b_data, poffset);
212 } 211 }
213 } 212 }
214 213
215 if ( (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 214 if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
216 { 215 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
217 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE) )
218 continue; 216 continue;
219 } 217 }
220 218
221 if ( (cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0 ) 219 if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
222 { 220 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
223 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE) )
224 continue; 221 continue;
225 } 222 }
226 223
227 if ( cfi.fileCharacteristics & FID_FILE_CHAR_PARENT ) 224 if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) {
228 {
229 iblock = parent_ino(filp->f_path.dentry); 225 iblock = parent_ino(filp->f_path.dentry);
230 flen = 2; 226 flen = 2;
231 memcpy(fname, "..", flen); 227 memcpy(fname, "..", flen);
232 dt_type = DT_DIR; 228 dt_type = DT_DIR;
233 } 229 } else {
234 else
235 {
236 kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation); 230 kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation);
237 231
238 iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0); 232 iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0);
@@ -240,18 +234,18 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
240 dt_type = DT_UNKNOWN; 234 dt_type = DT_UNKNOWN;
241 } 235 }
242 236
243 if (flen) 237 if (flen) {
244 { 238 if (filldir
245 if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0) 239 (dirent, fname, flen, filp->f_pos, iblock,
246 { 240 dt_type) < 0) {
247 if (fibh.sbh != fibh.ebh) 241 if (fibh.sbh != fibh.ebh)
248 brelse(fibh.ebh); 242 brelse(fibh.ebh);
249 brelse(fibh.sbh); 243 brelse(fibh.sbh);
250 brelse(epos.bh); 244 brelse(epos.bh);
251 return 0; 245 return 0;
252 } 246 }
253 } 247 }
254 } /* end while */ 248 } /* end while */
255 249
256 filp->f_pos = nf_pos + 1; 250 filp->f_pos = nf_pos + 1;
257 251
diff --git a/fs/udf/directory.c b/fs/udf/directory.c
index 198caa33027a..8adc77c1d579 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;
@@ -31,31 +31,27 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
31 31
32 *error = 0; 32 *error = 0;
33 33
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;
58 memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder); 54 memcpy((uint8_t *) ad, (*bh)->b_data + loffset, remainder);
59 55
60 brelse(*bh); 56 brelse(*bh);
61 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 57 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
@@ -64,56 +60,56 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
64 if (!((*bh) = udf_tread(dir->i_sb, block))) 60 if (!((*bh) = udf_tread(dir->i_sb, block)))
65 return NULL; 61 return NULL;
66 62
67 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); 63 memcpy((uint8_t *) ad + remainder, (*bh)->b_data,
64 ad_size - remainder);
68 *offset = ad_size - remainder; 65 *offset = ad_size - remainder;
69 } 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,
90 &(fibh->eoffset));
95 91
96 if (!fi) 92 if (!fi)
97 return NULL; 93 return NULL;
98 94
99 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 95 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
100 96
101 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 97 memcpy((uint8_t *) cfi, (uint8_t *) fi,
98 sizeof(struct fileIdentDesc));
102 99
103 return fi; 100 return fi;
104 } 101 }
105 102
106 if (fibh->eoffset == dir->i_sb->s_blocksize) 103 if (fibh->eoffset == dir->i_sb->s_blocksize) {
107 {
108 int lextoffset = epos->offset; 104 int lextoffset = epos->offset;
109 105
110 if (udf_next_aext(dir, epos, eloc, elen, 1) != 106 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
111 (EXT_RECORDED_ALLOCATED >> 30)) 107 (EXT_RECORDED_ALLOCATED >> 30))
112 return NULL; 108 return NULL;
113 109
114 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 110 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
115 111
116 (*offset) ++; 112 (*offset)++;
117 113
118 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 114 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
119 *offset = 0; 115 *offset = 0;
@@ -125,57 +121,57 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
125 return NULL; 121 return NULL;
126 fibh->soffset = fibh->eoffset = 0; 122 fibh->soffset = fibh->eoffset = 0;
127 123
128 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) 124 if (!
125 (*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1)))
129 { 126 {
130 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 127 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
131 if (i+*offset > (*elen >> dir->i_sb->s_blocksize_bits)) 128 if (i + *offset >
132 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; 129 (*elen >> dir->i_sb->s_blocksize_bits))
133 for (num=0; i>0; i--) 130 i = (*elen >> dir->i_sb->s_blocksize_bits) -
134 { 131 *offset;
135 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset+i); 132 for (num = 0; i > 0; i--) {
133 block =
134 udf_get_lb_pblock(dir->i_sb, *eloc,
135 *offset + i);
136 tmp = udf_tgetblk(dir->i_sb, block); 136 tmp = udf_tgetblk(dir->i_sb, block);
137 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 137 if (tmp && !buffer_uptodate(tmp)
138 && !buffer_locked(tmp))
138 bha[num++] = tmp; 139 bha[num++] = tmp;
139 else 140 else
140 brelse(tmp); 141 brelse(tmp);
141 } 142 }
142 if (num) 143 if (num) {
143 {
144 ll_rw_block(READA, num, bha); 144 ll_rw_block(READA, num, bha);
145 for (i=0; i<num; i++) 145 for (i = 0; i < num; i++)
146 brelse(bha[i]); 146 brelse(bha[i]);
147 } 147 }
148 } 148 }
149 } 149 } else if (fibh->sbh != fibh->ebh) {
150 else if (fibh->sbh != fibh->ebh)
151 {
152 brelse(fibh->sbh); 150 brelse(fibh->sbh);
153 fibh->sbh = fibh->ebh; 151 fibh->sbh = fibh->ebh;
154 } 152 }
155 153
156 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize, 154 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
157 &(fibh->eoffset)); 155 &(fibh->eoffset));
158 156
159 if (!fi) 157 if (!fi)
160 return NULL; 158 return NULL;
161 159
162 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 160 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
163 161
164 if (fibh->eoffset <= dir->i_sb->s_blocksize) 162 if (fibh->eoffset <= dir->i_sb->s_blocksize) {
165 { 163 memcpy((uint8_t *) cfi, (uint8_t *) fi,
166 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 164 sizeof(struct fileIdentDesc));
167 } 165 } 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; 166 int lextoffset = epos->offset;
171 167
172 if (udf_next_aext(dir, epos, eloc, elen, 1) != 168 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
173 (EXT_RECORDED_ALLOCATED >> 30)) 169 (EXT_RECORDED_ALLOCATED >> 30))
174 return NULL; 170 return NULL;
175 171
176 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 172 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
177 173
178 (*offset) ++; 174 (*offset)++;
179 175
180 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 176 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
181 *offset = 0; 177 *offset = 0;
@@ -188,62 +184,62 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
188 if (!(fibh->ebh = udf_tread(dir->i_sb, block))) 184 if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
189 return NULL; 185 return NULL;
190 186
191 if (sizeof(struct fileIdentDesc) > - fibh->soffset) 187 if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
192 {
193 int fi_len; 188 int fi_len;
194 189
195 memcpy((uint8_t *)cfi, (uint8_t *)fi, - fibh->soffset); 190 memcpy((uint8_t *) cfi, (uint8_t *) fi, -fibh->soffset);
196 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, 191 memcpy((uint8_t *) cfi - fibh->soffset,
197 sizeof(struct fileIdentDesc) + fibh->soffset); 192 fibh->ebh->b_data,
193 sizeof(struct fileIdentDesc) + fibh->soffset);
198 194
199 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + 195 fi_len =
200 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; 196 (sizeof(struct fileIdentDesc) +
197 cfi->lengthFileIdent +
198 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
201 199
202 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); 200 *nf_pos +=
201 ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
203 fibh->eoffset = fibh->soffset + fi_len; 202 fibh->eoffset = fibh->soffset + fi_len;
204 } 203 } else {
205 else 204 memcpy((uint8_t *) cfi, (uint8_t *) fi,
206 { 205 sizeof(struct fileIdentDesc));
207 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
208 } 206 }
209 } 207 }
210 return fi; 208 return fi;
211} 209}
212 210
213struct fileIdentDesc * 211struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
214udf_get_fileident(void * buffer, int bufsize, int * offset)
215{ 212{
216 struct fileIdentDesc *fi; 213 struct fileIdentDesc *fi;
217 int lengthThisIdent; 214 int lengthThisIdent;
218 uint8_t * ptr; 215 uint8_t *ptr;
219 int padlen; 216 int padlen;
220 217
221 if ( (!buffer) || (!offset) ) { 218 if ((!buffer) || (!offset)) {
222 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, offset); 219 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer,
220 offset);
223 return NULL; 221 return NULL;
224 } 222 }
225 223
226 ptr = buffer; 224 ptr = buffer;
227 225
228 if ( (*offset > 0) && (*offset < bufsize) ) { 226 if ((*offset > 0) && (*offset < bufsize)) {
229 ptr += *offset; 227 ptr += *offset;
230 } 228 }
231 fi=(struct fileIdentDesc *)ptr; 229 fi = (struct fileIdentDesc *)ptr;
232 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) 230 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
233 {
234 udf_debug("0x%x != TAG_IDENT_FID\n", 231 udf_debug("0x%x != TAG_IDENT_FID\n",
235 le16_to_cpu(fi->descTag.tagIdent)); 232 le16_to_cpu(fi->descTag.tagIdent));
236 udf_debug("offset: %u sizeof: %lu bufsize: %u\n", 233 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
237 *offset, (unsigned long)sizeof(struct fileIdentDesc), bufsize); 234 *offset, (unsigned long)sizeof(struct fileIdentDesc),
235 bufsize);
238 return NULL; 236 return NULL;
239 } 237 }
240 if ( (*offset + sizeof(struct fileIdentDesc)) > bufsize ) 238 if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) {
241 {
242 lengthThisIdent = sizeof(struct fileIdentDesc); 239 lengthThisIdent = sizeof(struct fileIdentDesc);
243 } 240 } else
244 else
245 lengthThisIdent = sizeof(struct fileIdentDesc) + 241 lengthThisIdent = sizeof(struct fileIdentDesc) +
246 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); 242 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
247 243
248 /* we need to figure padding, too! */ 244 /* we need to figure padding, too! */
249 padlen = lengthThisIdent % UDF_NAME_PAD; 245 padlen = lengthThisIdent % UDF_NAME_PAD;
@@ -255,56 +251,53 @@ udf_get_fileident(void * buffer, int bufsize, int * offset)
255} 251}
256 252
257#if 0 253#if 0
258static extent_ad * 254static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
259udf_get_fileextent(void * buffer, int bufsize, int * offset)
260{ 255{
261 extent_ad * ext; 256 extent_ad *ext;
262 struct fileEntry *fe; 257 struct fileEntry *fe;
263 uint8_t * ptr; 258 uint8_t *ptr;
264 259
265 if ( (!buffer) || (!offset) ) 260 if ((!buffer) || (!offset)) {
266 {
267 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); 261 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
268 return NULL; 262 return NULL;
269 } 263 }
270 264
271 fe = (struct fileEntry *)buffer; 265 fe = (struct fileEntry *)buffer;
272 266
273 if ( le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE ) 267 if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) {
274 {
275 udf_debug("0x%x != TAG_IDENT_FE\n", 268 udf_debug("0x%x != TAG_IDENT_FE\n",
276 le16_to_cpu(fe->descTag.tagIdent)); 269 le16_to_cpu(fe->descTag.tagIdent));
277 return NULL; 270 return NULL;
278 } 271 }
279 272
280 ptr=(uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); 273 ptr =
274 (uint8_t *) (fe->extendedAttr) +
275 le32_to_cpu(fe->lengthExtendedAttr);
281 276
282 if ( (*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)) ) 277 if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) {
283 {
284 ptr += *offset; 278 ptr += *offset;
285 } 279 }
286 280
287 ext = (extent_ad *)ptr; 281 ext = (extent_ad *) ptr;
288 282
289 *offset = *offset + sizeof(extent_ad); 283 *offset = *offset + sizeof(extent_ad);
290 return ext; 284 return ext;
291} 285}
292#endif 286#endif
293 287
294short_ad * 288short_ad *udf_get_fileshortad(uint8_t * ptr, int maxoffset, int *offset,
295udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc) 289 int inc)
296{ 290{
297 short_ad *sa; 291 short_ad *sa;
298 292
299 if ( (!ptr) || (!offset) ) 293 if ((!ptr) || (!offset)) {
300 {
301 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); 294 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
302 return NULL; 295 return NULL;
303 } 296 }
304 297
305 if ( (*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset) ) 298 if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
306 return NULL; 299 return NULL;
307 else if ((sa = (short_ad *)ptr)->extLength == 0) 300 else if ((sa = (short_ad *) ptr)->extLength == 0)
308 return NULL; 301 return NULL;
309 302
310 if (inc) 303 if (inc)
@@ -312,20 +305,18 @@ udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc)
312 return sa; 305 return sa;
313} 306}
314 307
315long_ad * 308long_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{ 309{
318 long_ad *la; 310 long_ad *la;
319 311
320 if ( (!ptr) || (!offset) ) 312 if ((!ptr) || (!offset)) {
321 {
322 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); 313 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
323 return NULL; 314 return NULL;
324 } 315 }
325 316
326 if ( (*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset) ) 317 if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
327 return NULL; 318 return NULL;
328 else if ((la = (long_ad *)ptr)->extLength == 0) 319 else if ((la = (long_ad *) ptr)->extLength == 0)
329 return NULL; 320 return NULL;
330 321
331 if (inc) 322 if (inc)
diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index f81f2ebbf508..294ce2daa03a 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -38,10 +38,9 @@
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{ 42 uint8_t charSetType;
43 uint8_t charSetType; 43 uint8_t charSetInfo[63];
44 uint8_t charSetInfo[63];
45} __attribute__ ((packed)) charspec; 44} __attribute__ ((packed)) charspec;
46 45
47/* Character Set Type (ECMA 167r3 1/7.2.1.1) */ 46/* Character Set Type (ECMA 167r3 1/7.2.1.1) */
@@ -55,35 +54,33 @@ typedef struct
55#define CHARSPEC_TYPE_CS7 0x07 /* (1/7.2.9) */ 54#define CHARSPEC_TYPE_CS7 0x07 /* (1/7.2.9) */
56#define CHARSPEC_TYPE_CS8 0x08 /* (1/7.2.10) */ 55#define CHARSPEC_TYPE_CS8 0x08 /* (1/7.2.10) */
57 56
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{ 61 __le16 typeAndTimezone;
63 __le16 typeAndTimezone; 62 __le16 year;
64 __le16 year; 63 uint8_t month;
65 uint8_t month; 64 uint8_t day;
66 uint8_t day; 65 uint8_t hour;
67 uint8_t hour; 66 uint8_t minute;
68 uint8_t minute; 67 uint8_t second;
69 uint8_t second; 68 uint8_t centiseconds;
70 uint8_t centiseconds; 69 uint8_t hundredsOfMicroseconds;
71 uint8_t hundredsOfMicroseconds; 70 uint8_t microseconds;
72 uint8_t microseconds;
73} __attribute__ ((packed)) timestamp; 71} __attribute__ ((packed)) timestamp;
74 72
75typedef struct 73typedef struct {
76{ 74 uint16_t typeAndTimezone;
77 uint16_t typeAndTimezone; 75 int16_t year;
78 int16_t year; 76 uint8_t month;
79 uint8_t month; 77 uint8_t day;
80 uint8_t day; 78 uint8_t hour;
81 uint8_t hour; 79 uint8_t minute;
82 uint8_t minute; 80 uint8_t second;
83 uint8_t second; 81 uint8_t centiseconds;
84 uint8_t centiseconds; 82 uint8_t hundredsOfMicroseconds;
85 uint8_t hundredsOfMicroseconds; 83 uint8_t microseconds;
86 uint8_t microseconds;
87} __attribute__ ((packed)) kernel_timestamp; 84} __attribute__ ((packed)) kernel_timestamp;
88 85
89/* Type and Time Zone (ECMA 167r3 1/7.3.1) */ 86/* Type and Time Zone (ECMA 167r3 1/7.3.1) */
@@ -94,11 +91,10 @@ 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{ 95 uint8_t flags;
99 uint8_t flags; 96 uint8_t ident[23];
100 uint8_t ident[23]; 97 uint8_t identSuffix[8];
101 uint8_t identSuffix[8];
102} __attribute__ ((packed)) regid; 98} __attribute__ ((packed)) regid;
103 99
104/* Flags (ECMA 167r3 1/7.4.1) */ 100/* Flags (ECMA 167r3 1/7.4.1) */
@@ -107,12 +103,11 @@ 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{ 107 uint8_t structType;
112 uint8_t structType; 108 uint8_t stdIdent[VSD_STD_ID_LEN];
113 uint8_t stdIdent[VSD_STD_ID_LEN]; 109 uint8_t structVersion;
114 uint8_t structVersion; 110 uint8_t structData[2041];
115 uint8_t structData[2041];
116} __attribute__ ((packed)); 111} __attribute__ ((packed));
117 112
118/* Standard Identifier (EMCA 167r2 2/9.1.2) */ 113/* Standard Identifier (EMCA 167r2 2/9.1.2) */
@@ -127,69 +122,63 @@ 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{ 126 uint8_t structType;
132 uint8_t structType; 127 uint8_t stdIdent[VSD_STD_ID_LEN];
133 uint8_t stdIdent[VSD_STD_ID_LEN]; 128 uint8_t structVersion;
134 uint8_t structVersion; 129 uint8_t structData[2041];
135 uint8_t structData[2041];
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{ 134 uint8_t structType;
141 uint8_t structType; 135 uint8_t stdIdent[VSD_STD_ID_LEN];
142 uint8_t stdIdent[VSD_STD_ID_LEN]; 136 uint8_t structVersion;
143 uint8_t structVersion; 137 uint8_t structData[2041];
144 uint8_t structData[2041];
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{ 142 uint8_t structType;
150 uint8_t structType; 143 uint8_t stdIdent[VSD_STD_ID_LEN];
151 uint8_t stdIdent[VSD_STD_ID_LEN]; 144 uint8_t structVersion;
152 uint8_t structVersion; 145 uint8_t reserved1;
153 uint8_t reserved1; 146 regid archType;
154 regid archType; 147 regid bootIdent;
155 regid bootIdent; 148 __le32 bootExtLocation;
156 __le32 bootExtLocation; 149 __le32 bootExtLength;
157 __le32 bootExtLength; 150 __le64 loadAddress;
158 __le64 loadAddress; 151 __le64 startAddress;
159 __le64 startAddress; 152 timestamp descCreationDateAndTime;
160 timestamp descCreationDateAndTime; 153 __le16 flags;
161 __le16 flags; 154 uint8_t reserved2[32];
162 uint8_t reserved2[32]; 155 uint8_t bootUse[1906];
163 uint8_t bootUse[1906];
164} __attribute__ ((packed)); 156} __attribute__ ((packed));
165 157
166/* Flags (ECMA 167r3 2/9.4.12) */ 158/* Flags (ECMA 167r3 2/9.4.12) */
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{ 163 __le32 extLength;
172 __le32 extLength; 164 __le32 extLocation;
173 __le32 extLocation;
174} __attribute__ ((packed)) extent_ad; 165} __attribute__ ((packed)) extent_ad;
175 166
176typedef struct 167typedef struct {
177{ 168 uint32_t extLength;
178 uint32_t extLength; 169 uint32_t extLocation;
179 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{ 174 __le16 tagIdent;
185 __le16 tagIdent; 175 __le16 descVersion;
186 __le16 descVersion; 176 uint8_t tagChecksum;
187 uint8_t tagChecksum; 177 uint8_t reserved;
188 uint8_t reserved; 178 __le16 tagSerialNum;
189 __le16 tagSerialNum; 179 __le16 descCRC;
190 __le16 descCRC; 180 __le16 descCRCLength;
191 __le16 descCRCLength; 181 __le32 tagLocation;
192 __le32 tagLocation;
193} __attribute__ ((packed)) tag; 182} __attribute__ ((packed)) tag;
194 183
195/* Tag Identifier (ECMA 167r3 3/7.2.1) */ 184/* Tag Identifier (ECMA 167r3 3/7.2.1) */
@@ -204,87 +193,81 @@ 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{ 197 uint8_t structType;
209 uint8_t structType; 198 uint8_t stdIdent[VSD_STD_ID_LEN];
210 uint8_t stdIdent[VSD_STD_ID_LEN]; 199 uint8_t structVersion;
211 uint8_t structVersion; 200 uint8_t reserved;
212 uint8_t reserved; 201 uint8_t structData[2040];
213 uint8_t structData[2040]; 202} __attribute__ ((packed));
214} __attribute__ ((packed)); 203
215
216/* Primary Volume Descriptor (ECMA 167r3 3/10.1) */ 204/* Primary Volume Descriptor (ECMA 167r3 3/10.1) */
217struct primaryVolDesc 205struct primaryVolDesc {
218{ 206 tag descTag;
219 tag descTag; 207 __le32 volDescSeqNum;
220 __le32 volDescSeqNum; 208 __le32 primaryVolDescNum;
221 __le32 primaryVolDescNum; 209 dstring volIdent[32];
222 dstring volIdent[32]; 210 __le16 volSeqNum;
223 __le16 volSeqNum; 211 __le16 maxVolSeqNum;
224 __le16 maxVolSeqNum; 212 __le16 interchangeLvl;
225 __le16 interchangeLvl; 213 __le16 maxInterchangeLvl;
226 __le16 maxInterchangeLvl; 214 __le32 charSetList;
227 __le32 charSetList; 215 __le32 maxCharSetList;
228 __le32 maxCharSetList; 216 dstring volSetIdent[128];
229 dstring volSetIdent[128]; 217 charspec descCharSet;
230 charspec descCharSet; 218 charspec explanatoryCharSet;
231 charspec explanatoryCharSet; 219 extent_ad volAbstract;
232 extent_ad volAbstract; 220 extent_ad volCopyright;
233 extent_ad volCopyright; 221 regid appIdent;
234 regid appIdent; 222 timestamp recordingDateAndTime;
235 timestamp recordingDateAndTime; 223 regid impIdent;
236 regid impIdent; 224 uint8_t impUse[64];
237 uint8_t impUse[64]; 225 __le32 predecessorVolDescSeqLocation;
238 __le32 predecessorVolDescSeqLocation; 226 __le16 flags;
239 __le16 flags; 227 uint8_t reserved[22];
240 uint8_t reserved[22];
241} __attribute__ ((packed)); 228} __attribute__ ((packed));
242 229
243/* Flags (ECMA 167r3 3/10.1.21) */ 230/* Flags (ECMA 167r3 3/10.1.21) */
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{ 235 tag descTag;
249 tag descTag; 236 extent_ad mainVolDescSeqExt;
250 extent_ad mainVolDescSeqExt; 237 extent_ad reserveVolDescSeqExt;
251 extent_ad reserveVolDescSeqExt; 238 uint8_t reserved[480];
252 uint8_t reserved[480];
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{ 243 tag descTag;
258 tag descTag; 244 __le32 volDescSeqNum;
259 __le32 volDescSeqNum; 245 extent_ad nextVolDescSeqExt;
260 extent_ad nextVolDescSeqExt; 246 uint8_t reserved[484];
261 uint8_t reserved[484];
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{ 251 tag descTag;
267 tag descTag; 252 __le32 volDescSeqNum;
268 __le32 volDescSeqNum; 253 regid impIdent;
269 regid impIdent; 254 uint8_t impUse[460];
270 uint8_t impUse[460];
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,29 +290,27 @@ 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{ 294 tag descTag;
312 tag descTag; 295 __le32 volDescSeqNum;
313 __le32 volDescSeqNum; 296 charspec descCharSet;
314 charspec descCharSet; 297 dstring logicalVolIdent[128];
315 dstring logicalVolIdent[128]; 298 __le32 logicalBlockSize;
316 __le32 logicalBlockSize; 299 regid domainIdent;
317 regid domainIdent; 300 uint8_t logicalVolContentsUse[16];
318 uint8_t logicalVolContentsUse[16]; 301 __le32 mapTableLength;
319 __le32 mapTableLength; 302 __le32 numPartitionMaps;
320 __le32 numPartitionMaps; 303 regid impIdent;
321 regid impIdent; 304 uint8_t impUse[128];
322 uint8_t impUse[128]; 305 extent_ad integritySeqExt;
323 extent_ad integritySeqExt; 306 uint8_t partitionMaps[0];
324 uint8_t partitionMaps[0];
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{ 311 uint8_t partitionMapType;
330 uint8_t partitionMapType; 312 uint8_t partitionMapLength;
331 uint8_t partitionMapLength; 313 uint8_t partitionMapping[0];
332 uint8_t partitionMapping[0];
333} __attribute__ ((packed)); 314} __attribute__ ((packed));
334 315
335/* Partition Map Type (ECMA 167r3 3/10.7.1.1) */ 316/* Partition Map Type (ECMA 167r3 3/10.7.1.1) */
@@ -338,51 +319,46 @@ 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{ 323 uint8_t partitionMapType;
343 uint8_t partitionMapType; 324 uint8_t partitionMapLength;
344 uint8_t partitionMapLength; 325 __le16 volSeqNum;
345 __le16 volSeqNum; 326 __le16 partitionNum;
346 __le16 partitionNum;
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{ 331 uint8_t partitionMapType;
352 uint8_t partitionMapType; 332 uint8_t partitionMapLength;
353 uint8_t partitionMapLength; 333 uint8_t partitionIdent[62];
354 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{ 338 tag descTag;
360 tag descTag; 339 __le32 volDescSeqNum;
361 __le32 volDescSeqNum; 340 __le32 numAllocDescs;
362 __le32 numAllocDescs; 341 extent_ad allocDescs[0];
363 extent_ad allocDescs[0];
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{ 346 tag descTag;
369 tag descTag; 347 uint8_t reserved[496];
370 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{ 352 tag descTag;
376 tag descTag; 353 timestamp recordingDateAndTime;
377 timestamp recordingDateAndTime; 354 __le32 integrityType;
378 __le32 integrityType; 355 extent_ad nextIntegrityExt;
379 extent_ad nextIntegrityExt; 356 uint8_t logicalVolContentsUse[32];
380 uint8_t logicalVolContentsUse[32]; 357 __le32 numOfPartitions;
381 __le32 numOfPartitions; 358 __le32 lengthOfImpUse;
382 __le32 lengthOfImpUse; 359 __le32 freeSpaceTable[0];
383 __le32 freeSpaceTable[0]; 360 __le32 sizeTable[0];
384 __le32 sizeTable[0]; 361 uint8_t impUse[0];
385 uint8_t impUse[0];
386} __attribute__ ((packed)); 362} __attribute__ ((packed));
387 363
388/* Integrity Type (ECMA 167r3 3/10.10.3) */ 364/* Integrity Type (ECMA 167r3 3/10.10.3) */
@@ -390,56 +366,49 @@ 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{ 370 __le32 logicalBlockNum;
395 __le32 logicalBlockNum; 371 __le16 partitionReferenceNum;
396 __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{ 376 uint32_t logicalBlockNum;
402 uint32_t logicalBlockNum; 377 uint16_t partitionReferenceNum;
403 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{ 382 __le32 extLength;
409 __le32 extLength; 383 __le32 extPosition;
410 __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{ 388 __le32 extLength;
416 __le32 extLength; 389 lb_addr extLocation;
417 lb_addr extLocation; 390 uint8_t impUse[6];
418 uint8_t impUse[6];
419} __attribute__ ((packed)) long_ad; 391} __attribute__ ((packed)) long_ad;
420 392
421typedef struct 393typedef struct {
422{ 394 uint32_t extLength;
423 uint32_t extLength; 395 kernel_lb_addr extLocation;
424 kernel_lb_addr extLocation; 396 uint8_t impUse[6];
425 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{ 401 __le32 extLength;
431 __le32 extLength; 402 __le32 recordedLength;
432 __le32 recordedLength; 403 __le32 informationLength;
433 __le32 informationLength; 404 lb_addr extLocation;
434 lb_addr extLocation;
435} __attribute__ ((packed)) ext_ad; 405} __attribute__ ((packed)) ext_ad;
436 406
437typedef struct 407typedef struct {
438{ 408 uint32_t extLength;
439 uint32_t extLength; 409 uint32_t recordedLength;
440 uint32_t recordedLength; 410 uint32_t informationLength;
441 uint32_t informationLength; 411 kernel_lb_addr extLocation;
442 kernel_lb_addr extLocation;
443} kernel_ext_ad; 412} kernel_ext_ad;
444 413
445/* Descriptor Tag (ECMA 167r3 4/7.2 - See 3/7.2) */ 414/* Descriptor Tag (ECMA 167r3 4/7.2 - See 3/7.2) */
@@ -458,52 +427,49 @@ 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{ 431 tag descTag;
463 tag descTag; 432 timestamp recordingDateAndTime;
464 timestamp recordingDateAndTime; 433 __le16 interchangeLvl;
465 __le16 interchangeLvl; 434 __le16 maxInterchangeLvl;
466 __le16 maxInterchangeLvl; 435 __le32 charSetList;
467 __le32 charSetList; 436 __le32 maxCharSetList;
468 __le32 maxCharSetList; 437 __le32 fileSetNum;
469 __le32 fileSetNum; 438 __le32 fileSetDescNum;
470 __le32 fileSetDescNum; 439 charspec logicalVolIdentCharSet;
471 charspec logicalVolIdentCharSet; 440 dstring logicalVolIdent[128];
472 dstring logicalVolIdent[128]; 441 charspec fileSetCharSet;
473 charspec fileSetCharSet; 442 dstring fileSetIdent[32];
474 dstring fileSetIdent[32]; 443 dstring copyrightFileIdent[32];
475 dstring copyrightFileIdent[32]; 444 dstring abstractFileIdent[32];
476 dstring abstractFileIdent[32]; 445 long_ad rootDirectoryICB;
477 long_ad rootDirectoryICB; 446 regid domainIdent;
478 regid domainIdent; 447 long_ad nextExt;
479 long_ad nextExt; 448 long_ad streamDirectoryICB;
480 long_ad streamDirectoryICB; 449 uint8_t reserved[32];
481 uint8_t reserved[32];
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{ 454 short_ad unallocSpaceTable;
487 short_ad unallocSpaceTable; 455 short_ad unallocSpaceBitmap;
488 short_ad unallocSpaceBitmap; 456 short_ad partitionIntegrityTable;
489 short_ad partitionIntegrityTable; 457 short_ad freedSpaceTable;
490 short_ad freedSpaceTable; 458 short_ad freedSpaceBitmap;
491 short_ad freedSpaceBitmap; 459 uint8_t reserved[88];
492 uint8_t reserved[88];
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{ 464 tag descTag;
498 tag descTag; 465 __le16 fileVersionNum;
499 __le16 fileVersionNum; 466 uint8_t fileCharacteristics;
500 uint8_t fileCharacteristics; 467 uint8_t lengthFileIdent;
501 uint8_t lengthFileIdent; 468 long_ad icb;
502 long_ad icb; 469 __le16 lengthOfImpUse;
503 __le16 lengthOfImpUse; 470 uint8_t impUse[0];
504 uint8_t impUse[0]; 471 uint8_t fileIdent[0];
505 uint8_t fileIdent[0]; 472 uint8_t padding[0];
506 uint8_t padding[0];
507} __attribute__ ((packed)); 473} __attribute__ ((packed));
508 474
509/* File Characteristics (ECMA 167r3 4/14.4.3) */ 475/* File Characteristics (ECMA 167r3 4/14.4.3) */
@@ -514,24 +480,22 @@ 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{ 484 tag descTag;
519 tag descTag; 485 __le32 previousAllocExtLocation;
520 __le32 previousAllocExtLocation; 486 __le32 lengthAllocDescs;
521 __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{ 491 __le32 priorRecordedNumDirectEntries;
527 __le32 priorRecordedNumDirectEntries; 492 __le16 strategyType;
528 __le16 strategyType; 493 __le16 strategyParameter;
529 __le16 strategyParameter; 494 __le16 numEntries;
530 __le16 numEntries; 495 uint8_t reserved;
531 uint8_t reserved; 496 uint8_t fileType;
532 uint8_t fileType; 497 lb_addr parentICBLocation;
533 lb_addr parentICBLocation; 498 __le16 flags;
534 __le16 flags;
535} __attribute__ ((packed)) icbtag; 499} __attribute__ ((packed)) icbtag;
536 500
537/* Strategy Type (ECMA 167r3 4/14.6.2) */ 501/* Strategy Type (ECMA 167r3 4/14.6.2) */
@@ -576,45 +540,42 @@ 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{ 544 tag descTag;
581 tag descTag; 545 icbtag icbTag;
582 icbtag icbTag; 546 long_ad indirectICB;
583 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{ 551 tag descTag;
589 tag descTag; 552 icbtag icbTag;
590 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{ 557 tag descTag;
596 tag descTag; 558 icbtag icbTag;
597 icbtag icbTag; 559 __le32 uid;
598 __le32 uid; 560 __le32 gid;
599 __le32 gid; 561 __le32 permissions;
600 __le32 permissions; 562 __le16 fileLinkCount;
601 __le16 fileLinkCount; 563 uint8_t recordFormat;
602 uint8_t recordFormat; 564 uint8_t recordDisplayAttr;
603 uint8_t recordDisplayAttr; 565 __le32 recordLength;
604 __le32 recordLength; 566 __le64 informationLength;
605 __le64 informationLength; 567 __le64 logicalBlocksRecorded;
606 __le64 logicalBlocksRecorded; 568 timestamp accessTime;
607 timestamp accessTime; 569 timestamp modificationTime;
608 timestamp modificationTime; 570 timestamp attrTime;
609 timestamp attrTime; 571 __le32 checkpoint;
610 __le32 checkpoint; 572 long_ad extendedAttrICB;
611 long_ad extendedAttrICB; 573 regid impIdent;
612 regid impIdent; 574 __le64 uniqueID;
613 __le64 uniqueID; 575 __le32 lengthExtendedAttr;
614 __le32 lengthExtendedAttr; 576 __le32 lengthAllocDescs;
615 __le32 lengthAllocDescs; 577 uint8_t extendedAttr[0];
616 uint8_t extendedAttr[0]; 578 uint8_t allocDescs[0];
617 uint8_t allocDescs[0];
618} __attribute__ ((packed)); 579} __attribute__ ((packed));
619 580
620/* Permissions (ECMA 167r3 4/14.9.5) */ 581/* Permissions (ECMA 167r3 4/14.9.5) */
@@ -655,57 +616,52 @@ 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{ 620 tag descTag;
660 tag descTag; 621 __le32 impAttrLocation;
661 __le32 impAttrLocation; 622 __le32 appAttrLocation;
662 __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{ 627 __le32 attrType;
668 __le32 attrType; 628 uint8_t attrSubtype;
669 uint8_t attrSubtype; 629 uint8_t reserved[3];
670 uint8_t reserved[3]; 630 __le32 attrLength;
671 __le32 attrLength; 631 uint8_t attrData[0];
672 uint8_t attrData[0];
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{ 636 __le32 attrType;
678 __le32 attrType; 637 uint8_t attrSubtype;
679 uint8_t attrSubtype; 638 uint8_t reserved[3];
680 uint8_t reserved[3]; 639 __le32 attrLength;
681 __le32 attrLength; 640 __le32 escapeSeqLength;
682 __le32 escapeSeqLength; 641 uint8_t charSetType;
683 uint8_t charSetType; 642 uint8_t escapeSeq[0];
684 uint8_t escapeSeq[0];
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{ 647 __le32 attrType;
690 __le32 attrType; 648 uint8_t attrSubtype;
691 uint8_t attrSubtype; 649 uint8_t reserved[3];
692 uint8_t reserved[3]; 650 __le32 attrLength;
693 __le32 attrLength; 651 __le16 ownerIdent;
694 __le16 ownerIdent; 652 __le16 groupIdent;
695 __le16 groupIdent; 653 __le16 permission;
696 __le16 permission;
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{ 658 __le32 attrType;
702 __le32 attrType; 659 uint8_t attrSubtype;
703 uint8_t attrSubtype; 660 uint8_t reserved[3];
704 uint8_t reserved[3]; 661 __le32 attrLength;
705 __le32 attrLength; 662 __le32 dataLength;
706 __le32 dataLength; 663 __le32 fileTimeExistence;
707 __le32 fileTimeExistence; 664 uint8_t fileTimes;
708 uint8_t fileTimes;
709} __attribute__ ((packed)); 665} __attribute__ ((packed));
710 666
711/* FileTimeExistence (ECMA 167r3 4/14.10.5.6) */ 667/* FileTimeExistence (ECMA 167r3 4/14.10.5.6) */
@@ -715,52 +671,48 @@ 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{ 675 __le32 attrType;
720 __le32 attrType; 676 uint8_t attrSubtype;
721 uint8_t attrSubtype; 677 uint8_t reserved[3];
722 uint8_t reserved[3]; 678 __le32 attrLength;
723 __le32 attrLength; 679 __le32 dataLength;
724 __le32 dataLength; 680 __le32 infoTimeExistence;
725 __le32 infoTimeExistence; 681 uint8_t infoTimes[0];
726 uint8_t infoTimes[0];
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{ 686 __le32 attrType;
732 __le32 attrType; 687 uint8_t attrSubtype;
733 uint8_t attrSubtype; 688 uint8_t reserved[3];
734 uint8_t reserved[3]; 689 __le32 attrLength;
735 __le32 attrLength; 690 __le32 impUseLength;
736 __le32 impUseLength; 691 __le32 majorDeviceIdent;
737 __le32 majorDeviceIdent; 692 __le32 minorDeviceIdent;
738 __le32 minorDeviceIdent; 693 uint8_t impUse[0];
739 uint8_t impUse[0];
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{ 698 __le32 attrType;
745 __le32 attrType; 699 uint8_t attrSubtype;
746 uint8_t attrSubtype; 700 uint8_t reserved[3];
747 uint8_t reserved[3]; 701 __le32 attrLength;
748 __le32 attrLength; 702 __le32 impUseLength;
749 __le32 impUseLength; 703 regid impIdent;
750 regid impIdent; 704 uint8_t impUse[0];
751 uint8_t impUse[0];
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{ 709 __le32 attrType;
757 __le32 attrType; 710 uint8_t attrSubtype;
758 uint8_t attrSubtype; 711 uint8_t reserved[3];
759 uint8_t reserved[3]; 712 __le32 attrLength;
760 __le32 attrLength; 713 __le32 appUseLength;
761 __le32 appUseLength; 714 regid appIdent;
762 regid appIdent; 715 uint8_t appUse[0];
763 uint8_t appUse[0];
764} __attribute__ ((packed)); 716} __attribute__ ((packed));
765 717
766#define EXTATTR_CHAR_SET 1 718#define EXTATTR_CHAR_SET 1
@@ -771,35 +723,31 @@ 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{ 728 tag descTag;
778 tag descTag; 729 icbtag icbTag;
779 icbtag icbTag; 730 __le32 lengthAllocDescs;
780 __le32 lengthAllocDescs; 731 uint8_t allocDescs[0];
781 uint8_t allocDescs[0];
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{ 736 tag descTag;
787 tag descTag; 737 __le32 numOfBits;
788 __le32 numOfBits; 738 __le32 numOfBytes;
789 __le32 numOfBytes; 739 uint8_t bitmap[0];
790 uint8_t bitmap[0];
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{ 744 tag descTag;
796 tag descTag; 745 icbtag icbTag;
797 icbtag icbTag; 746 timestamp recordingDateAndTime;
798 timestamp recordingDateAndTime; 747 uint8_t integrityType;
799 uint8_t integrityType; 748 uint8_t reserved[175];
800 uint8_t reserved[175]; 749 regid impIdent;
801 regid impIdent; 750 uint8_t impUse[256];
802 uint8_t impUse[256];
803} __attribute__ ((packed)); 751} __attribute__ ((packed));
804 752
805/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */ 753/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */
@@ -815,50 +763,47 @@ 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{ 767 __le64 uniqueID;
820 __le64 uniqueID; 768 uint8_t reserved[24];
821 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{ 773 uint8_t componentType;
827 uint8_t componentType; 774 uint8_t lengthComponentIdent;
828 uint8_t lengthComponentIdent; 775 __le16 componentFileVersionNum;
829 __le16 componentFileVersionNum; 776 dstring componentIdent[0];
830 dstring componentIdent[0];
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{ 781 tag descTag;
836 tag descTag; 782 icbtag icbTag;
837 icbtag icbTag; 783 __le32 uid;
838 __le32 uid; 784 __le32 gid;
839 __le32 gid; 785 __le32 permissions;
840 __le32 permissions; 786 __le16 fileLinkCount;
841 __le16 fileLinkCount; 787 uint8_t recordFormat;
842 uint8_t recordFormat; 788 uint8_t recordDisplayAttr;
843 uint8_t recordDisplayAttr; 789 __le32 recordLength;
844 __le32 recordLength; 790 __le64 informationLength;
845 __le64 informationLength; 791 __le64 objectSize;
846 __le64 objectSize; 792 __le64 logicalBlocksRecorded;
847 __le64 logicalBlocksRecorded; 793 timestamp accessTime;
848 timestamp accessTime; 794 timestamp modificationTime;
849 timestamp modificationTime; 795 timestamp createTime;
850 timestamp createTime; 796 timestamp attrTime;
851 timestamp attrTime; 797 __le32 checkpoint;
852 __le32 checkpoint; 798 __le32 reserved;
853 __le32 reserved; 799 long_ad extendedAttrICB;
854 long_ad extendedAttrICB; 800 long_ad streamDirectoryICB;
855 long_ad streamDirectoryICB; 801 regid impIdent;
856 regid impIdent; 802 __le64 uniqueID;
857 __le64 uniqueID; 803 __le32 lengthExtendedAttr;
858 __le32 lengthExtendedAttr; 804 __le32 lengthAllocDescs;
859 __le32 lengthAllocDescs; 805 uint8_t extendedAttr[0];
860 uint8_t extendedAttr[0]; 806 uint8_t allocDescs[0];
861 uint8_t allocDescs[0]; 807} __attribute__ ((packed));
862} __attribute__ ((packed)); 808
863 809#endif /* _ECMA_167_H */
864#endif /* _ECMA_167_H */
diff --git a/fs/udf/file.c b/fs/udf/file.c
index df070bee8d4f..67bf36bd3e6e 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -30,7 +30,7 @@
30#include <linux/udf_fs.h> 30#include <linux/udf_fs.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/string.h> /* memset */ 33#include <linux/string.h> /* memset */
34#include <linux/capability.h> 34#include <linux/capability.h>
35#include <linux/errno.h> 35#include <linux/errno.h>
36#include <linux/smp_lock.h> 36#include <linux/smp_lock.h>
@@ -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;
@@ -58,7 +58,8 @@ static int udf_adinicb_readpage(struct file *file, struct page * page)
58 return 0; 58 return 0;
59} 59}
60 60
61static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc) 61static int udf_adinicb_writepage(struct page *page,
62 struct writeback_control *wbc)
62{ 63{
63 struct inode *inode = page->mapping->host; 64 struct inode *inode = page->mapping->host;
64 char *kaddr; 65 char *kaddr;
@@ -74,19 +75,21 @@ static int udf_adinicb_writepage(struct page *page, struct writeback_control *wb
74 return 0; 75 return 0;
75} 76}
76 77
77static int udf_adinicb_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to) 78static int udf_adinicb_prepare_write(struct file *file, struct page *page,
79 unsigned offset, unsigned to)
78{ 80{
79 kmap(page); 81 kmap(page);
80 return 0; 82 return 0;
81} 83}
82 84
83static int udf_adinicb_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to) 85static int udf_adinicb_commit_write(struct file *file, struct page *page,
86 unsigned offset, unsigned to)
84{ 87{
85 struct inode *inode = page->mapping->host; 88 struct inode *inode = page->mapping->host;
86 char *kaddr = page_address(page); 89 char *kaddr = page_address(page);
87 90
88 memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 91 memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset,
89 kaddr + offset, to - offset); 92 kaddr + offset, to - offset);
90 mark_inode_dirty(inode); 93 mark_inode_dirty(inode);
91 SetPageUptodate(page); 94 SetPageUptodate(page);
92 kunmap(page); 95 kunmap(page);
@@ -97,15 +100,15 @@ static int udf_adinicb_commit_write(struct file *file, struct page *page, unsign
97} 100}
98 101
99const struct address_space_operations udf_adinicb_aops = { 102const struct address_space_operations udf_adinicb_aops = {
100 .readpage = udf_adinicb_readpage, 103 .readpage = udf_adinicb_readpage,
101 .writepage = udf_adinicb_writepage, 104 .writepage = udf_adinicb_writepage,
102 .sync_page = block_sync_page, 105 .sync_page = block_sync_page,
103 .prepare_write = udf_adinicb_prepare_write, 106 .prepare_write = udf_adinicb_prepare_write,
104 .commit_write = udf_adinicb_commit_write, 107 .commit_write = udf_adinicb_commit_write,
105}; 108};
106 109
107static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 110static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
108 unsigned long nr_segs, loff_t ppos) 111 unsigned long nr_segs, loff_t ppos)
109{ 112{
110 ssize_t retval; 113 ssize_t retval;
111 struct file *file = iocb->ki_filp; 114 struct file *file = iocb->ki_filp;
@@ -113,25 +116,20 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
113 int err, pos; 116 int err, pos;
114 size_t count = iocb->ki_left; 117 size_t count = iocb->ki_left;
115 118
116 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 119 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
117 {
118 if (file->f_flags & O_APPEND) 120 if (file->f_flags & O_APPEND)
119 pos = inode->i_size; 121 pos = inode->i_size;
120 else 122 else
121 pos = ppos; 123 pos = ppos;
122 124
123 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + 125 if (inode->i_sb->s_blocksize <
124 pos + count)) 126 (udf_file_entry_alloc_offset(inode) + pos + count)) {
125 {
126 udf_expand_file_adinicb(inode, pos + count, &err); 127 udf_expand_file_adinicb(inode, pos + count, &err);
127 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 128 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
128 {
129 udf_debug("udf_expand_adinicb: err=%d\n", err); 129 udf_debug("udf_expand_adinicb: err=%d\n", err);
130 return err; 130 return err;
131 } 131 }
132 } 132 } else {
133 else
134 {
135 if (pos + count > inode->i_size) 133 if (pos + count > inode->i_size)
136 UDF_I_LENALLOC(inode) = pos + count; 134 UDF_I_LENALLOC(inode) = pos + count;
137 else 135 else
@@ -181,48 +179,47 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
181 * Written, tested, and released. 179 * Written, tested, and released.
182 */ 180 */
183int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 181int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
184 unsigned long arg) 182 unsigned long arg)
185{ 183{
186 int result = -EINVAL; 184 int result = -EINVAL;
187 185
188 if ( file_permission(filp, MAY_READ) != 0 ) 186 if (file_permission(filp, MAY_READ) != 0) {
189 { 187 udf_debug("no permission to access inode %lu\n", inode->i_ino);
190 udf_debug("no permission to access inode %lu\n",
191 inode->i_ino);
192 return -EPERM; 188 return -EPERM;
193 } 189 }
194 190
195 if ( !arg ) 191 if (!arg) {
196 {
197 udf_debug("invalid argument to udf_ioctl\n"); 192 udf_debug("invalid argument to udf_ioctl\n");
198 return -EINVAL; 193 return -EINVAL;
199 } 194 }
200 195
201 switch (cmd) 196 switch (cmd) {
202 { 197 case UDF_GETVOLIDENT:
203 case UDF_GETVOLIDENT: 198 return copy_to_user((char __user *)arg,
204 return copy_to_user((char __user *)arg, 199 UDF_SB_VOLIDENT(inode->i_sb),
205 UDF_SB_VOLIDENT(inode->i_sb), 32) ? -EFAULT : 0; 200 32) ? -EFAULT : 0;
206 case UDF_RELOCATE_BLOCKS: 201 case UDF_RELOCATE_BLOCKS:
207 { 202 {
208 long old, new; 203 long old, new;
209 204
210 if (!capable(CAP_SYS_ADMIN)) return -EACCES; 205 if (!capable(CAP_SYS_ADMIN))
211 if (get_user(old, (long __user *)arg)) return -EFAULT; 206 return -EACCES;
207 if (get_user(old, (long __user *)arg))
208 return -EFAULT;
212 if ((result = udf_relocate_blocks(inode->i_sb, 209 if ((result = udf_relocate_blocks(inode->i_sb,
213 old, &new)) == 0) 210 old, &new)) == 0)
214 result = put_user(new, (long __user *)arg); 211 result = put_user(new, (long __user *)arg);
215 212
216 return result; 213 return result;
217 } 214 }
218 case UDF_GETEASIZE: 215 case UDF_GETEASIZE:
219 result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg); 216 result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg);
220 break; 217 break;
221 218
222 case UDF_GETEABLOCK: 219 case UDF_GETEABLOCK:
223 result = copy_to_user((char __user *)arg, UDF_I_DATA(inode), 220 result = copy_to_user((char __user *)arg, UDF_I_DATA(inode),
224 UDF_I_LENEATTR(inode)) ? -EFAULT : 0; 221 UDF_I_LENEATTR(inode)) ? -EFAULT : 0;
225 break; 222 break;
226 } 223 }
227 224
228 return result; 225 return result;
@@ -240,10 +237,9 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
240 * HISTORY 237 * HISTORY
241 * 238 *
242 */ 239 */
243static int udf_release_file(struct inode * inode, struct file * filp) 240static int udf_release_file(struct inode *inode, struct file *filp)
244{ 241{
245 if (filp->f_mode & FMODE_WRITE) 242 if (filp->f_mode & FMODE_WRITE) {
246 {
247 lock_kernel(); 243 lock_kernel();
248 udf_discard_prealloc(inode); 244 udf_discard_prealloc(inode);
249 unlock_kernel(); 245 unlock_kernel();
@@ -252,18 +248,18 @@ static int udf_release_file(struct inode * inode, struct file * filp)
252} 248}
253 249
254const struct file_operations udf_file_operations = { 250const struct file_operations udf_file_operations = {
255 .read = do_sync_read, 251 .read = do_sync_read,
256 .aio_read = generic_file_aio_read, 252 .aio_read = generic_file_aio_read,
257 .ioctl = udf_ioctl, 253 .ioctl = udf_ioctl,
258 .open = generic_file_open, 254 .open = generic_file_open,
259 .mmap = generic_file_mmap, 255 .mmap = generic_file_mmap,
260 .write = do_sync_write, 256 .write = do_sync_write,
261 .aio_write = udf_file_aio_write, 257 .aio_write = udf_file_aio_write,
262 .release = udf_release_file, 258 .release = udf_release_file,
263 .fsync = udf_fsync_file, 259 .fsync = udf_fsync_file,
264 .splice_read = generic_file_splice_read, 260 .splice_read = generic_file_splice_read,
265}; 261};
266 262
267const struct inode_operations udf_file_inode_operations = { 263const struct inode_operations udf_file_inode_operations = {
268 .truncate = udf_truncate, 264 .truncate = udf_truncate,
269}; 265};
diff --git a/fs/udf/fsync.c b/fs/udf/fsync.c
index 6ded93e7c44f..7f0901c4f1f1 100644
--- a/fs/udf/fsync.c
+++ b/fs/udf/fsync.c
@@ -29,7 +29,7 @@ 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 return udf_fsync_inode(inode, datasync); 35 return udf_fsync_inode(inode, datasync);
@@ -45,6 +45,6 @@ static int udf_fsync_inode(struct inode *inode, int datasync)
45 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) 45 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
46 return err; 46 return err;
47 47
48 err |= udf_sync_inode (inode); 48 err |= udf_sync_inode(inode);
49 return err ? -EIO : 0; 49 return err ? -EIO : 0;
50} 50}
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index 10f3188738af..2eb503806bce 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);
@@ -46,10 +46,12 @@ void udf_free_inode(struct inode * inode)
46 if (sbi->s_lvidbh) { 46 if (sbi->s_lvidbh) {
47 if (S_ISDIR(inode->i_mode)) 47 if (S_ISDIR(inode->i_mode))
48 UDF_SB_LVIDIU(sb)->numDirs = 48 UDF_SB_LVIDIU(sb)->numDirs =
49 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) - 1); 49 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)
50 - 1);
50 else 51 else
51 UDF_SB_LVIDIU(sb)->numFiles = 52 UDF_SB_LVIDIU(sb)->numFiles =
52 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1); 53 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles)
54 - 1);
53 55
54 mark_buffer_dirty(sbi->s_lvidbh); 56 mark_buffer_dirty(sbi->s_lvidbh);
55 } 57 }
@@ -58,18 +60,17 @@ void udf_free_inode(struct inode * inode)
58 udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1); 60 udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1);
59} 61}
60 62
61struct inode * udf_new_inode (struct inode *dir, int mode, int * err) 63struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
62{ 64{
63 struct super_block *sb = dir->i_sb; 65 struct super_block *sb = dir->i_sb;
64 struct udf_sb_info *sbi = UDF_SB(sb); 66 struct udf_sb_info *sbi = UDF_SB(sb);
65 struct inode * inode; 67 struct inode *inode;
66 int block; 68 int block;
67 uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum; 69 uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum;
68 70
69 inode = new_inode(sb); 71 inode = new_inode(sb);
70 72
71 if (!inode) 73 if (!inode) {
72 {
73 *err = -ENOMEM; 74 *err = -ENOMEM;
74 return NULL; 75 return NULL;
75 } 76 }
@@ -81,26 +82,30 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
81 UDF_I_NEXT_ALLOC_GOAL(inode) = 0; 82 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
82 UDF_I_STRAT4096(inode) = 0; 83 UDF_I_STRAT4096(inode) = 0;
83 84
84 block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, 85 block =
85 start, err); 86 udf_new_block(dir->i_sb, NULL,
86 if (*err) 87 UDF_I_LOCATION(dir).partitionReferenceNum, start,
87 { 88 err);
89 if (*err) {
88 iput(inode); 90 iput(inode);
89 return NULL; 91 return NULL;
90 } 92 }
91 93
92 mutex_lock(&sbi->s_alloc_mutex); 94 mutex_lock(&sbi->s_alloc_mutex);
93 if (UDF_SB_LVIDBH(sb)) 95 if (UDF_SB_LVIDBH(sb)) {
94 {
95 struct logicalVolHeaderDesc *lvhd; 96 struct logicalVolHeaderDesc *lvhd;
96 uint64_t uniqueID; 97 uint64_t uniqueID;
97 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse); 98 lvhd =
99 (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->
100 logicalVolContentsUse);
98 if (S_ISDIR(mode)) 101 if (S_ISDIR(mode))
99 UDF_SB_LVIDIU(sb)->numDirs = 102 UDF_SB_LVIDIU(sb)->numDirs =
100 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) + 1); 103 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)
104 + 1);
101 else 105 else
102 UDF_SB_LVIDIU(sb)->numFiles = 106 UDF_SB_LVIDIU(sb)->numFiles =
103 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1); 107 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles)
108 + 1);
104 UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID); 109 UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID);
105 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 110 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
106 uniqueID += 16; 111 uniqueID += 16;
@@ -109,35 +114,34 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
109 } 114 }
110 inode->i_mode = mode; 115 inode->i_mode = mode;
111 inode->i_uid = current->fsuid; 116 inode->i_uid = current->fsuid;
112 if (dir->i_mode & S_ISGID) 117 if (dir->i_mode & S_ISGID) {
113 {
114 inode->i_gid = dir->i_gid; 118 inode->i_gid = dir->i_gid;
115 if (S_ISDIR(mode)) 119 if (S_ISDIR(mode))
116 mode |= S_ISGID; 120 mode |= S_ISGID;
117 } 121 } else
118 else
119 inode->i_gid = current->fsgid; 122 inode->i_gid = current->fsgid;
120 123
121 UDF_I_LOCATION(inode).logicalBlockNum = block; 124 UDF_I_LOCATION(inode).logicalBlockNum = block;
122 UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; 125 UDF_I_LOCATION(inode).partitionReferenceNum =
126 UDF_I_LOCATION(dir).partitionReferenceNum;
123 inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); 127 inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
124 inode->i_blocks = 0; 128 inode->i_blocks = 0;
125 UDF_I_LENEATTR(inode) = 0; 129 UDF_I_LENEATTR(inode) = 0;
126 UDF_I_LENALLOC(inode) = 0; 130 UDF_I_LENALLOC(inode) = 0;
127 UDF_I_USE(inode) = 0; 131 UDF_I_USE(inode) = 0;
128 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) 132 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
129 {
130 UDF_I_EFE(inode) = 1; 133 UDF_I_EFE(inode) = 1;
131 UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE); 134 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); 135 UDF_I_DATA(inode) =
133 } 136 kzalloc(inode->i_sb->s_blocksize -
134 else 137 sizeof(struct extendedFileEntry), GFP_KERNEL);
135 { 138 } else {
136 UDF_I_EFE(inode) = 0; 139 UDF_I_EFE(inode) = 0;
137 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); 140 UDF_I_DATA(inode) =
141 kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry),
142 GFP_KERNEL);
138 } 143 }
139 if (!UDF_I_DATA(inode)) 144 if (!UDF_I_DATA(inode)) {
140 {
141 iput(inode); 145 iput(inode);
142 *err = -ENOMEM; 146 *err = -ENOMEM;
143 mutex_unlock(&sbi->s_alloc_mutex); 147 mutex_unlock(&sbi->s_alloc_mutex);
@@ -150,13 +154,12 @@ struct inode * udf_new_inode (struct inode *dir, int mode, int * err)
150 else 154 else
151 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG; 155 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
152 inode->i_mtime = inode->i_atime = inode->i_ctime = 156 inode->i_mtime = inode->i_atime = inode->i_ctime =
153 UDF_I_CRTIME(inode) = current_fs_time(inode->i_sb); 157 UDF_I_CRTIME(inode) = current_fs_time(inode->i_sb);
154 insert_inode_hash(inode); 158 insert_inode_hash(inode);
155 mark_inode_dirty(inode); 159 mark_inode_dirty(inode);
156 mutex_unlock(&sbi->s_alloc_mutex); 160 mutex_unlock(&sbi->s_alloc_mutex);
157 161
158 if (DQUOT_ALLOC_INODE(inode)) 162 if (DQUOT_ALLOC_INODE(inode)) {
159 {
160 DQUOT_DROP(inode); 163 DQUOT_DROP(inode);
161 inode->i_flags |= S_NOQUOTA; 164 inode->i_flags |= S_NOQUOTA;
162 inode->i_nlink = 0; 165 inode->i_nlink = 0;
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 5b82e489af78..be6326f449a1 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -51,18 +51,18 @@ static 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 int udf_alloc_i_data(struct inode *inode, size_t size);
53static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, 53static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
54 long *, int *); 54 long *, int *);
55static int8_t udf_insert_aext(struct inode *, struct extent_position, 55static int8_t udf_insert_aext(struct inode *, struct extent_position,
56 kernel_lb_addr, uint32_t); 56 kernel_lb_addr, uint32_t);
57static void udf_split_extents(struct inode *, int *, int, int, 57static void udf_split_extents(struct inode *, int *, int, int,
58 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 58 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
59static void udf_prealloc_extents(struct inode *, int, int, 59static void udf_prealloc_extents(struct inode *, int, int,
60 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 60 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
61static void udf_merge_extents(struct inode *, 61static void udf_merge_extents(struct inode *,
62 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 62 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
63static void udf_update_extents(struct inode *, 63static void udf_update_extents(struct inode *,
64 kernel_long_ad [EXTENT_MERGE_SIZE], int, int, 64 kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
65 struct extent_position *); 65 struct extent_position *);
66static 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);
67 67
68/* 68/*
@@ -81,7 +81,7 @@ static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
81 * 81 *
82 * Called at the last iput() if i_nlink is zero. 82 * Called at the last iput() if i_nlink is zero.
83 */ 83 */
84void udf_delete_inode(struct inode * inode) 84void udf_delete_inode(struct inode *inode)
85{ 85{
86 truncate_inode_pages(&inode->i_data, 0); 86 truncate_inode_pages(&inode->i_data, 0);
87 87
@@ -97,7 +97,7 @@ void udf_delete_inode(struct inode * inode)
97 97
98 unlock_kernel(); 98 unlock_kernel();
99 return; 99 return;
100no_delete: 100 no_delete:
101 clear_inode(inode); 101 clear_inode(inode);
102} 102}
103 103
@@ -132,26 +132,27 @@ static int udf_readpage(struct file *file, struct page *page)
132 return block_read_full_page(page, udf_get_block); 132 return block_read_full_page(page, udf_get_block);
133} 133}
134 134
135static int udf_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to) 135static int udf_prepare_write(struct file *file, struct page *page,
136 unsigned from, unsigned to)
136{ 137{
137 return block_prepare_write(page, from, to, udf_get_block); 138 return block_prepare_write(page, from, to, udf_get_block);
138} 139}
139 140
140static sector_t udf_bmap(struct address_space *mapping, sector_t block) 141static sector_t udf_bmap(struct address_space *mapping, sector_t block)
141{ 142{
142 return generic_block_bmap(mapping,block,udf_get_block); 143 return generic_block_bmap(mapping, block, udf_get_block);
143} 144}
144 145
145const struct address_space_operations udf_aops = { 146const struct address_space_operations udf_aops = {
146 .readpage = udf_readpage, 147 .readpage = udf_readpage,
147 .writepage = udf_writepage, 148 .writepage = udf_writepage,
148 .sync_page = block_sync_page, 149 .sync_page = block_sync_page,
149 .prepare_write = udf_prepare_write, 150 .prepare_write = udf_prepare_write,
150 .commit_write = generic_commit_write, 151 .commit_write = generic_commit_write,
151 .bmap = udf_bmap, 152 .bmap = udf_bmap,
152}; 153};
153 154
154void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err) 155void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
155{ 156{
156 struct page *page; 157 struct page *page;
157 char *kaddr; 158 char *kaddr;
@@ -163,8 +164,7 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
163 /* from now on we have normal address_space methods */ 164 /* from now on we have normal address_space methods */
164 inode->i_data.a_ops = &udf_aops; 165 inode->i_data.a_ops = &udf_aops;
165 166
166 if (!UDF_I_LENALLOC(inode)) 167 if (!UDF_I_LENALLOC(inode)) {
167 {
168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
169 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 169 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
170 else 170 else
@@ -176,19 +176,18 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
176 page = grab_cache_page(inode->i_mapping, 0); 176 page = grab_cache_page(inode->i_mapping, 0);
177 BUG_ON(!PageLocked(page)); 177 BUG_ON(!PageLocked(page));
178 178
179 if (!PageUptodate(page)) 179 if (!PageUptodate(page)) {
180 {
181 kaddr = kmap(page); 180 kaddr = kmap(page);
182 memset(kaddr + UDF_I_LENALLOC(inode), 0x00, 181 memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
183 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode)); 182 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
184 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 183 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
185 UDF_I_LENALLOC(inode)); 184 UDF_I_LENALLOC(inode));
186 flush_dcache_page(page); 185 flush_dcache_page(page);
187 SetPageUptodate(page); 186 SetPageUptodate(page);
188 kunmap(page); 187 kunmap(page);
189 } 188 }
190 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00, 189 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
191 UDF_I_LENALLOC(inode)); 190 UDF_I_LENALLOC(inode));
192 UDF_I_LENALLOC(inode) = 0; 191 UDF_I_LENALLOC(inode) = 0;
193 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 192 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
194 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 193 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
@@ -201,7 +200,8 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
201 mark_inode_dirty(inode); 200 mark_inode_dirty(inode);
202} 201}
203 202
204struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err) 203struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
204 int *err)
205{ 205{
206 int newblock; 206 int newblock;
207 struct buffer_head *dbh = NULL; 207 struct buffer_head *dbh = NULL;
@@ -220,8 +220,7 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
220 else 220 else
221 alloctype = ICBTAG_FLAG_AD_LONG; 221 alloctype = ICBTAG_FLAG_AD_LONG;
222 222
223 if (!inode->i_size) 223 if (!inode->i_size) {
224 {
225 UDF_I_ALLOCTYPE(inode) = alloctype; 224 UDF_I_ALLOCTYPE(inode) = alloctype;
226 mark_inode_dirty(inode); 225 mark_inode_dirty(inode);
227 return NULL; 226 return NULL;
@@ -229,13 +228,14 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
229 228
230 /* alloc block, and copy data to it */ 229 /* alloc block, and copy data to it */
231 *block = udf_new_block(inode->i_sb, inode, 230 *block = udf_new_block(inode->i_sb, inode,
232 UDF_I_LOCATION(inode).partitionReferenceNum, 231 UDF_I_LOCATION(inode).partitionReferenceNum,
233 UDF_I_LOCATION(inode).logicalBlockNum, err); 232 UDF_I_LOCATION(inode).logicalBlockNum, err);
234 233
235 if (!(*block)) 234 if (!(*block))
236 return NULL; 235 return NULL;
237 newblock = udf_get_pblock(inode->i_sb, *block, 236 newblock = udf_get_pblock(inode->i_sb, *block,
238 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 237 UDF_I_LOCATION(inode).partitionReferenceNum,
238 0);
239 if (!newblock) 239 if (!newblock)
240 return NULL; 240 return NULL;
241 dbh = udf_tgetblk(inode->i_sb, newblock); 241 dbh = udf_tgetblk(inode->i_sb, newblock);
@@ -247,16 +247,17 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
247 unlock_buffer(dbh); 247 unlock_buffer(dbh);
248 mark_buffer_dirty_inode(dbh, inode); 248 mark_buffer_dirty_inode(dbh, inode);
249 249
250 sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; 250 sfibh.soffset = sfibh.eoffset =
251 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
251 sfibh.sbh = sfibh.ebh = NULL; 252 sfibh.sbh = sfibh.ebh = NULL;
252 dfibh.soffset = dfibh.eoffset = 0; 253 dfibh.soffset = dfibh.eoffset = 0;
253 dfibh.sbh = dfibh.ebh = dbh; 254 dfibh.sbh = dfibh.ebh = dbh;
254 while ( (f_pos < size) ) 255 while ((f_pos < size)) {
255 {
256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
257 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); 257 sfi =
258 if (!sfi) 258 udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL,
259 { 259 NULL, NULL);
260 if (!sfi) {
260 brelse(dbh); 261 brelse(dbh);
261 return NULL; 262 return NULL;
262 } 263 }
@@ -266,8 +267,8 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
266 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); 267 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
267 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); 268 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
268 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, 269 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
269 sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) 270 sfi->fileIdent +
270 { 271 le16_to_cpu(sfi->lengthOfImpUse))) {
271 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 272 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
272 brelse(dbh); 273 brelse(dbh);
273 return NULL; 274 return NULL;
@@ -275,10 +276,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
275 } 276 }
276 mark_buffer_dirty_inode(dbh, inode); 277 mark_buffer_dirty_inode(dbh, inode);
277 278
278 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); 279 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0,
280 UDF_I_LENALLOC(inode));
279 UDF_I_LENALLOC(inode) = 0; 281 UDF_I_LENALLOC(inode) = 0;
280 eloc.logicalBlockNum = *block; 282 eloc.logicalBlockNum = *block;
281 eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 283 eloc.partitionReferenceNum =
284 UDF_I_LOCATION(inode).partitionReferenceNum;
282 elen = inode->i_size; 285 elen = inode->i_size;
283 UDF_I_LENEXTENTS(inode) = elen; 286 UDF_I_LENEXTENTS(inode) = elen;
284 epos.bh = NULL; 287 epos.bh = NULL;
@@ -292,14 +295,14 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
292 return dbh; 295 return dbh;
293} 296}
294 297
295static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) 298static int udf_get_block(struct inode *inode, sector_t block,
299 struct buffer_head *bh_result, int create)
296{ 300{
297 int err, new; 301 int err, new;
298 struct buffer_head *bh; 302 struct buffer_head *bh;
299 unsigned long phys; 303 unsigned long phys;
300 304
301 if (!create) 305 if (!create) {
302 {
303 phys = udf_block_map(inode, block); 306 phys = udf_block_map(inode, block);
304 if (phys) 307 if (phys)
305 map_bh(bh_result, inode->i_sb, phys); 308 map_bh(bh_result, inode->i_sb, phys);
@@ -315,10 +318,9 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
315 if (block < 0) 318 if (block < 0)
316 goto abort_negative; 319 goto abort_negative;
317 320
318 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) 321 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
319 { 322 UDF_I_NEXT_ALLOC_BLOCK(inode)++;
320 UDF_I_NEXT_ALLOC_BLOCK(inode) ++; 323 UDF_I_NEXT_ALLOC_GOAL(inode)++;
321 UDF_I_NEXT_ALLOC_GOAL(inode) ++;
322 } 324 }
323 325
324 err = 0; 326 err = 0;
@@ -332,29 +334,27 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
332 if (new) 334 if (new)
333 set_buffer_new(bh_result); 335 set_buffer_new(bh_result);
334 map_bh(bh_result, inode->i_sb, phys); 336 map_bh(bh_result, inode->i_sb, phys);
335abort: 337 abort:
336 unlock_kernel(); 338 unlock_kernel();
337 return err; 339 return err;
338 340
339abort_negative: 341 abort_negative:
340 udf_warning(inode->i_sb, "udf_get_block", "block < 0"); 342 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
341 goto abort; 343 goto abort;
342} 344}
343 345
344static struct buffer_head * 346static struct buffer_head *udf_getblk(struct inode *inode, long block,
345udf_getblk(struct inode *inode, long block, int create, int *err) 347 int create, int *err)
346{ 348{
347 struct buffer_head dummy; 349 struct buffer_head dummy;
348 350
349 dummy.b_state = 0; 351 dummy.b_state = 0;
350 dummy.b_blocknr = -1000; 352 dummy.b_blocknr = -1000;
351 *err = udf_get_block(inode, block, &dummy, create); 353 *err = udf_get_block(inode, block, &dummy, create);
352 if (!*err && buffer_mapped(&dummy)) 354 if (!*err && buffer_mapped(&dummy)) {
353 {
354 struct buffer_head *bh; 355 struct buffer_head *bh;
355 bh = sb_getblk(inode->i_sb, dummy.b_blocknr); 356 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
356 if (buffer_new(&dummy)) 357 if (buffer_new(&dummy)) {
357 {
358 lock_buffer(bh); 358 lock_buffer(bh);
359 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); 359 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
360 set_buffer_uptodate(bh); 360 set_buffer_uptodate(bh);
@@ -368,12 +368,12 @@ udf_getblk(struct inode *inode, long block, int create, int *err)
368 368
369/* Extend the file by 'blocks' blocks, return the number of extents added */ 369/* Extend the file by 'blocks' blocks, return the number of extents added */
370int udf_extend_file(struct inode *inode, struct extent_position *last_pos, 370int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
371 kernel_long_ad *last_ext, sector_t blocks) 371 kernel_long_ad * last_ext, sector_t blocks)
372{ 372{
373 sector_t add; 373 sector_t add;
374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
375 struct super_block *sb = inode->i_sb; 375 struct super_block *sb = inode->i_sb;
376 kernel_lb_addr prealloc_loc = {0, 0}; 376 kernel_lb_addr prealloc_loc = { 0, 0 };
377 int prealloc_len = 0; 377 int prealloc_len = 0;
378 378
379 /* The previous extent is fake and we should not extend by anything 379 /* The previous extent is fake and we should not extend by anything
@@ -383,28 +383,32 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
383 /* Round the last extent up to a multiple of block size */ 383 /* Round the last extent up to a multiple of block size */
384 if (last_ext->extLength & (sb->s_blocksize - 1)) { 384 if (last_ext->extLength & (sb->s_blocksize - 1)) {
385 last_ext->extLength = 385 last_ext->extLength =
386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | 386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + 387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); 388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
389 UDF_I_LENEXTENTS(inode) = 389 UDF_I_LENEXTENTS(inode) =
390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & 390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
391 ~(sb->s_blocksize - 1); 391 ~(sb->s_blocksize - 1);
392 } 392 }
393 /* Last extent are just preallocated blocks? */ 393 /* Last extent are just preallocated blocks? */
394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { 394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
395 EXT_NOT_RECORDED_ALLOCATED) {
395 /* Save the extent so that we can reattach it to the end */ 396 /* Save the extent so that we can reattach it to the end */
396 prealloc_loc = last_ext->extLocation; 397 prealloc_loc = last_ext->extLocation;
397 prealloc_len = last_ext->extLength; 398 prealloc_len = last_ext->extLength;
398 /* Mark the extent as a hole */ 399 /* Mark the extent as a hole */
399 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 400 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
400 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 401 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
401 last_ext->extLocation.logicalBlockNum = 0; 402 last_ext->extLocation.logicalBlockNum = 0;
402 last_ext->extLocation.partitionReferenceNum = 0; 403 last_ext->extLocation.partitionReferenceNum = 0;
403 } 404 }
404 /* Can we merge with the previous extent? */ 405 /* Can we merge with the previous extent? */
405 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { 406 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
406 add = ((1<<30) - sb->s_blocksize - (last_ext->extLength & 407 EXT_NOT_RECORDED_NOT_ALLOCATED) {
407 UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; 408 add =
409 ((1 << 30) - sb->s_blocksize -
410 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> sb->
411 s_blocksize_bits;
408 if (add > blocks) 412 if (add > blocks)
409 add = blocks; 413 add = blocks;
410 blocks -= add; 414 blocks -= add;
@@ -413,40 +417,42 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
413 417
414 if (fake) { 418 if (fake) {
415 udf_add_aext(inode, last_pos, last_ext->extLocation, 419 udf_add_aext(inode, last_pos, last_ext->extLocation,
416 last_ext->extLength, 1); 420 last_ext->extLength, 1);
417 count++; 421 count++;
418 } 422 } else
419 else 423 udf_write_aext(inode, last_pos, last_ext->extLocation,
420 udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); 424 last_ext->extLength, 1);
421 /* Managed to do everything necessary? */ 425 /* Managed to do everything necessary? */
422 if (!blocks) 426 if (!blocks)
423 goto out; 427 goto out;
424 428
425 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ 429 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
426 last_ext->extLocation.logicalBlockNum = 0; 430 last_ext->extLocation.logicalBlockNum = 0;
427 last_ext->extLocation.partitionReferenceNum = 0; 431 last_ext->extLocation.partitionReferenceNum = 0;
428 add = (1 << (30-sb->s_blocksize_bits)) - 1; 432 add = (1 << (30 - sb->s_blocksize_bits)) - 1;
429 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); 433 last_ext->extLength =
434 EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
430 /* Create enough extents to cover the whole hole */ 435 /* Create enough extents to cover the whole hole */
431 while (blocks > add) { 436 while (blocks > add) {
432 blocks -= add; 437 blocks -= add;
433 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 438 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
434 last_ext->extLength, 1) == -1) 439 last_ext->extLength, 1) == -1)
435 return -1; 440 return -1;
436 count++; 441 count++;
437 } 442 }
438 if (blocks) { 443 if (blocks) {
439 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 444 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
440 (blocks << sb->s_blocksize_bits); 445 (blocks << sb->s_blocksize_bits);
441 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 446 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
442 last_ext->extLength, 1) == -1) 447 last_ext->extLength, 1) == -1)
443 return -1; 448 return -1;
444 count++; 449 count++;
445 } 450 }
446out: 451 out:
447 /* Do we have some preallocated blocks saved? */ 452 /* Do we have some preallocated blocks saved? */
448 if (prealloc_len) { 453 if (prealloc_len) {
449 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1) 454 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1)
455 == -1)
450 return -1; 456 return -1;
451 last_ext->extLocation = prealloc_loc; 457 last_ext->extLocation = prealloc_loc;
452 last_ext->extLength = prealloc_len; 458 last_ext->extLength = prealloc_len;
@@ -462,8 +468,8 @@ out:
462 return count; 468 return count;
463} 469}
464 470
465static struct buffer_head * inode_getblk(struct inode * inode, sector_t block, 471static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
466 int *err, long *phys, int *new) 472 int *err, long *phys, int *new)
467{ 473{
468 static sector_t last_block; 474 static sector_t last_block;
469 struct buffer_head *result = NULL; 475 struct buffer_head *result = NULL;
@@ -484,21 +490,18 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
484 prev_epos.block = UDF_I_LOCATION(inode); 490 prev_epos.block = UDF_I_LOCATION(inode);
485 prev_epos.bh = NULL; 491 prev_epos.bh = NULL;
486 cur_epos = next_epos = prev_epos; 492 cur_epos = next_epos = prev_epos;
487 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; 493 b_off = (loff_t) block << inode->i_sb->s_blocksize_bits;
488 494
489 /* find the extent which contains the block we are looking for. 495 /* find the extent which contains the block we are looking for.
490 alternate between laarr[0] and laarr[1] for locations of the 496 alternate between laarr[0] and laarr[1] for locations of the
491 current extent, and the previous extent */ 497 current extent, and the previous extent */
492 do 498 do {
493 { 499 if (prev_epos.bh != cur_epos.bh) {
494 if (prev_epos.bh != cur_epos.bh)
495 {
496 brelse(prev_epos.bh); 500 brelse(prev_epos.bh);
497 get_bh(cur_epos.bh); 501 get_bh(cur_epos.bh);
498 prev_epos.bh = cur_epos.bh; 502 prev_epos.bh = cur_epos.bh;
499 } 503 }
500 if (cur_epos.bh != next_epos.bh) 504 if (cur_epos.bh != next_epos.bh) {
501 {
502 brelse(cur_epos.bh); 505 brelse(cur_epos.bh);
503 get_bh(next_epos.bh); 506 get_bh(next_epos.bh);
504 cur_epos.bh = next_epos.bh; 507 cur_epos.bh = next_epos.bh;
@@ -512,7 +515,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
512 prev_epos.offset = cur_epos.offset; 515 prev_epos.offset = cur_epos.offset;
513 cur_epos.offset = next_epos.offset; 516 cur_epos.offset = next_epos.offset;
514 517
515 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1) 518 if ((etype =
519 udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
516 break; 520 break;
517 521
518 c = !c; 522 c = !c;
@@ -522,10 +526,10 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
522 526
523 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 527 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
524 pgoal = eloc.logicalBlockNum + 528 pgoal = eloc.logicalBlockNum +
525 ((elen + inode->i_sb->s_blocksize - 1) >> 529 ((elen + inode->i_sb->s_blocksize - 1) >>
526 inode->i_sb->s_blocksize_bits); 530 inode->i_sb->s_blocksize_bits);
527 531
528 count ++; 532 count++;
529 } while (lbcount + elen <= b_off); 533 } while (lbcount + elen <= b_off);
530 534
531 b_off -= lbcount; 535 b_off -= lbcount;
@@ -538,15 +542,13 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
538 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0); 542 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
539 543
540 /* if the extent is allocated and recorded, return the block 544 /* if the extent is allocated and recorded, return the block
541 if the extent is not a multiple of the blocksize, round up */ 545 if the extent is not a multiple of the blocksize, round up */
542 546
543 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) 547 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
544 { 548 if (elen & (inode->i_sb->s_blocksize - 1)) {
545 if (elen & (inode->i_sb->s_blocksize - 1))
546 {
547 elen = EXT_RECORDED_ALLOCATED | 549 elen = EXT_RECORDED_ALLOCATED |
548 ((elen + inode->i_sb->s_blocksize - 1) & 550 ((elen + inode->i_sb->s_blocksize - 1) &
549 ~(inode->i_sb->s_blocksize - 1)); 551 ~(inode->i_sb->s_blocksize - 1));
550 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1); 552 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
551 } 553 }
552 brelse(prev_epos.bh); 554 brelse(prev_epos.bh);
@@ -559,18 +561,17 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
559 561
560 last_block = block; 562 last_block = block;
561 /* Are we beyond EOF? */ 563 /* Are we beyond EOF? */
562 if (etype == -1) 564 if (etype == -1) {
563 {
564 int ret; 565 int ret;
565 566
566 if (count) { 567 if (count) {
567 if (c) 568 if (c)
568 laarr[0] = laarr[1]; 569 laarr[0] = laarr[1];
569 startnum = 1; 570 startnum = 1;
570 } 571 } else {
571 else {
572 /* Create a fake extent when there's not one */ 572 /* Create a fake extent when there's not one */
573 memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); 573 memset(&laarr[0].extLocation, 0x00,
574 sizeof(kernel_lb_addr));
574 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 575 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
575 /* Will udf_extend_file() create real extent from a fake one? */ 576 /* Will udf_extend_file() create real extent from a fake one? */
576 startnum = (offset > 0); 577 startnum = (offset > 0);
@@ -590,26 +591,26 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
590 offset = 0; 591 offset = 0;
591 count += ret; 592 count += ret;
592 /* We are not covered by a preallocated extent? */ 593 /* We are not covered by a preallocated extent? */
593 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) { 594 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
595 EXT_NOT_RECORDED_ALLOCATED) {
594 /* Is there any real extent? - otherwise we overwrite 596 /* Is there any real extent? - otherwise we overwrite
595 * the fake one... */ 597 * the fake one... */
596 if (count) 598 if (count)
597 c = !c; 599 c = !c;
598 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 600 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
599 inode->i_sb->s_blocksize; 601 inode->i_sb->s_blocksize;
600 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); 602 memset(&laarr[c].extLocation, 0x00,
601 count ++; 603 sizeof(kernel_lb_addr));
602 endnum ++; 604 count++;
605 endnum++;
603 } 606 }
604 endnum = c+1; 607 endnum = c + 1;
605 lastblock = 1; 608 lastblock = 1;
606 } 609 } else {
607 else {
608 endnum = startnum = ((count > 2) ? 2 : count); 610 endnum = startnum = ((count > 2) ? 2 : count);
609 611
610 /* if the current extent is in position 0, swap it with the previous */ 612 /* if the current extent is in position 0, swap it with the previous */
611 if (!c && count != 1) 613 if (!c && count != 1) {
612 {
613 laarr[2] = laarr[0]; 614 laarr[2] = laarr[0];
614 laarr[0] = laarr[1]; 615 laarr[0] = laarr[1];
615 laarr[1] = laarr[2]; 616 laarr[1] = laarr[2];
@@ -617,37 +618,37 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
617 } 618 }
618 619
619 /* if the current block is located in an extent, read the next extent */ 620 /* if the current block is located in an extent, read the next extent */
620 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) 621 if ((etype =
621 { 622 udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
622 laarr[c+1].extLength = (etype << 30) | elen; 623 laarr[c + 1].extLength = (etype << 30) | elen;
623 laarr[c+1].extLocation = eloc; 624 laarr[c + 1].extLocation = eloc;
624 count ++; 625 count++;
625 startnum ++; 626 startnum++;
626 endnum ++; 627 endnum++;
627 } 628 } else {
628 else {
629 lastblock = 1; 629 lastblock = 1;
630 } 630 }
631 } 631 }
632 632
633 /* if the current extent is not recorded but allocated, get the 633 /* if the current extent is not recorded but allocated, get the
634 block in the extent corresponding to the requested block */ 634 block in the extent corresponding to the requested block */
635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset; 636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
637 else /* otherwise, allocate a new block */ 637 else { /* otherwise, allocate a new block */
638 { 638
639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) 639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
640 goal = UDF_I_NEXT_ALLOC_GOAL(inode); 640 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
641 641
642 if (!goal) 642 if (!goal) {
643 {
644 if (!(goal = pgoal)) 643 if (!(goal = pgoal))
645 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1; 644 goal =
645 UDF_I_LOCATION(inode).logicalBlockNum + 1;
646 } 646 }
647 647
648 if (!(newblocknum = udf_new_block(inode->i_sb, inode, 648 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
649 UDF_I_LOCATION(inode).partitionReferenceNum, goal, err))) 649 UDF_I_LOCATION(inode).
650 { 650 partitionReferenceNum, goal,
651 err))) {
651 brelse(prev_epos.bh); 652 brelse(prev_epos.bh);
652 *err = -ENOSPC; 653 *err = -ENOSPC;
653 return NULL; 654 return NULL;
@@ -656,8 +657,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
656 } 657 }
657 658
658 /* if the extent the requsted block is located in contains multiple blocks, 659 /* if the extent the requsted block is located in contains multiple blocks,
659 split the extent into at most three extents. blocks prior to requested 660 split the extent into at most three extents. blocks prior to requested
660 block, requested block, and blocks after requested block */ 661 block, requested block, and blocks after requested block */
661 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); 662 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
662 663
663#ifdef UDF_PREALLOCATE 664#ifdef UDF_PREALLOCATE
@@ -669,15 +670,15 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
669 udf_merge_extents(inode, laarr, &endnum); 670 udf_merge_extents(inode, laarr, &endnum);
670 671
671 /* write back the new extents, inserting new extents if the new number 672 /* write back the new extents, inserting new extents if the new number
672 of extents is greater than the old number, and deleting extents if 673 of extents is greater than the old number, and deleting extents if
673 the new number of extents is less than the old number */ 674 the new number of extents is less than the old number */
674 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); 675 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
675 676
676 brelse(prev_epos.bh); 677 brelse(prev_epos.bh);
677 678
678 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, 679 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
679 UDF_I_LOCATION(inode).partitionReferenceNum, 0))) 680 UDF_I_LOCATION(inode).
680 { 681 partitionReferenceNum, 0))) {
681 return NULL; 682 return NULL;
682 } 683 }
683 *phys = newblock; 684 *phys = newblock;
@@ -694,283 +695,329 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
694 return result; 695 return result;
695} 696}
696 697
697static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum, 698static void udf_split_extents(struct inode *inode, int *c, int offset,
698 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 699 int newblocknum,
700 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
701 int *endnum)
699{ 702{
700 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || 703 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
701 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 704 (laarr[*c].extLength >> 30) ==
702 { 705 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
703 int curr = *c; 706 int curr = *c;
704 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + 707 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
705 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 708 inode->i_sb->s_blocksize -
709 1) >> inode->i_sb->s_blocksize_bits;
706 int8_t etype = (laarr[curr].extLength >> 30); 710 int8_t etype = (laarr[curr].extLength >> 30);
707 711
708 if (blen == 1) 712 if (blen == 1) ;
709 ; 713 else if (!offset || blen == offset + 1) {
710 else if (!offset || blen == offset + 1) 714 laarr[curr + 2] = laarr[curr + 1];
711 { 715 laarr[curr + 1] = laarr[curr];
712 laarr[curr+2] = laarr[curr+1]; 716 } else {
713 laarr[curr+1] = laarr[curr]; 717 laarr[curr + 3] = laarr[curr + 1];
714 } 718 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
715 else 719 }
716 { 720
717 laarr[curr+3] = laarr[curr+1]; 721 if (offset) {
718 laarr[curr+2] = laarr[curr+1] = laarr[curr]; 722 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
719 } 723 udf_free_blocks(inode->i_sb, inode,
720 724 laarr[curr].extLocation, 0,
721 if (offset) 725 offset);
722 { 726 laarr[curr].extLength =
723 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 727 EXT_NOT_RECORDED_NOT_ALLOCATED | (offset <<
724 { 728 inode->
725 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); 729 i_sb->
726 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 730 s_blocksize_bits);
727 (offset << inode->i_sb->s_blocksize_bits);
728 laarr[curr].extLocation.logicalBlockNum = 0; 731 laarr[curr].extLocation.logicalBlockNum = 0;
729 laarr[curr].extLocation.partitionReferenceNum = 0; 732 laarr[curr].extLocation.partitionReferenceNum =
730 } 733 0;
731 else 734 } else
732 laarr[curr].extLength = (etype << 30) | 735 laarr[curr].extLength = (etype << 30) |
733 (offset << inode->i_sb->s_blocksize_bits); 736 (offset << inode->i_sb->s_blocksize_bits);
734 curr ++; 737 curr++;
735 (*c) ++; 738 (*c)++;
736 (*endnum) ++; 739 (*endnum)++;
737 } 740 }
738 741
739 laarr[curr].extLocation.logicalBlockNum = newblocknum; 742 laarr[curr].extLocation.logicalBlockNum = newblocknum;
740 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 743 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
741 laarr[curr].extLocation.partitionReferenceNum = 744 laarr[curr].extLocation.partitionReferenceNum =
742 UDF_I_LOCATION(inode).partitionReferenceNum; 745 UDF_I_LOCATION(inode).partitionReferenceNum;
743 laarr[curr].extLength = EXT_RECORDED_ALLOCATED | 746 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
744 inode->i_sb->s_blocksize; 747 inode->i_sb->s_blocksize;
745 curr ++; 748 curr++;
746 749
747 if (blen != offset + 1) 750 if (blen != offset + 1) {
748 {
749 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 751 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
750 laarr[curr].extLocation.logicalBlockNum += (offset + 1); 752 laarr[curr].extLocation.logicalBlockNum +=
751 laarr[curr].extLength = (etype << 30) | 753 (offset + 1);
752 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); 754 laarr[curr].extLength =
753 curr ++; 755 (etype << 30) | ((blen - (offset + 1)) << inode->
754 (*endnum) ++; 756 i_sb->s_blocksize_bits);
757 curr++;
758 (*endnum)++;
755 } 759 }
756 } 760 }
757} 761}
758 762
759static void udf_prealloc_extents(struct inode *inode, int c, int lastblock, 763static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
760 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 764 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
765 int *endnum)
761{ 766{
762 int start, length = 0, currlength = 0, i; 767 int start, length = 0, currlength = 0, i;
763 768
764 if (*endnum >= (c+1)) 769 if (*endnum >= (c + 1)) {
765 {
766 if (!lastblock) 770 if (!lastblock)
767 return; 771 return;
768 else 772 else
769 start = c; 773 start = c;
770 } 774 } else {
771 else 775 if ((laarr[c + 1].extLength >> 30) ==
772 { 776 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
773 if ((laarr[c+1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 777 start = c + 1;
774 { 778 length = currlength =
775 start = c+1; 779 (((laarr[c + 1].
776 length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) + 780 extLength & UDF_EXTENT_LENGTH_MASK) +
777 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 781 inode->i_sb->s_blocksize -
778 } 782 1) >> inode->i_sb->s_blocksize_bits);
779 else 783 } else
780 start = c; 784 start = c;
781 } 785 }
782 786
783 for (i=start+1; i<=*endnum; i++) 787 for (i = start + 1; i <= *endnum; i++) {
784 { 788 if (i == *endnum) {
785 if (i == *endnum)
786 {
787 if (lastblock) 789 if (lastblock)
788 length += UDF_DEFAULT_PREALLOC_BLOCKS; 790 length += UDF_DEFAULT_PREALLOC_BLOCKS;
789 } 791 } else if ((laarr[i].extLength >> 30) ==
790 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 792 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
791 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 793 length +=
792 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 794 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
795 inode->i_sb->s_blocksize -
796 1) >> inode->i_sb->s_blocksize_bits);
793 else 797 else
794 break; 798 break;
795 } 799 }
796 800
797 if (length) 801 if (length) {
798 {
799 int next = laarr[start].extLocation.logicalBlockNum + 802 int next = laarr[start].extLocation.logicalBlockNum +
800 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + 803 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
801 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 804 inode->i_sb->s_blocksize -
805 1) >> inode->i_sb->s_blocksize_bits);
802 int numalloc = udf_prealloc_blocks(inode->i_sb, inode, 806 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
803 laarr[start].extLocation.partitionReferenceNum, 807 laarr[start].extLocation.
804 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length : 808 partitionReferenceNum,
805 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength); 809 next,
806 810 (UDF_DEFAULT_PREALLOC_BLOCKS
807 if (numalloc) 811 >
808 { 812 length ? length :
809 if (start == (c+1)) 813 UDF_DEFAULT_PREALLOC_BLOCKS)
814 - currlength);
815
816 if (numalloc) {
817 if (start == (c + 1))
810 laarr[start].extLength += 818 laarr[start].extLength +=
811 (numalloc << inode->i_sb->s_blocksize_bits); 819 (numalloc << inode->i_sb->s_blocksize_bits);
812 else 820 else {
813 { 821 memmove(&laarr[c + 2], &laarr[c + 1],
814 memmove(&laarr[c+2], &laarr[c+1], 822 sizeof(long_ad) * (*endnum - (c + 1)));
815 sizeof(long_ad) * (*endnum - (c+1))); 823 (*endnum)++;
816 (*endnum) ++; 824 laarr[c + 1].extLocation.logicalBlockNum = next;
817 laarr[c+1].extLocation.logicalBlockNum = next; 825 laarr[c + 1].extLocation.partitionReferenceNum =
818 laarr[c+1].extLocation.partitionReferenceNum = 826 laarr[c].extLocation.partitionReferenceNum;
819 laarr[c].extLocation.partitionReferenceNum; 827 laarr[c + 1].extLength =
820 laarr[c+1].extLength = EXT_NOT_RECORDED_ALLOCATED | 828 EXT_NOT_RECORDED_ALLOCATED | (numalloc <<
821 (numalloc << inode->i_sb->s_blocksize_bits); 829 inode->i_sb->
822 start = c+1; 830 s_blocksize_bits);
831 start = c + 1;
823 } 832 }
824 833
825 for (i=start+1; numalloc && i<*endnum; i++) 834 for (i = start + 1; numalloc && i < *endnum; i++) {
826 { 835 int elen =
827 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 836 ((laarr[i].
828 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 837 extLength & UDF_EXTENT_LENGTH_MASK) +
838 inode->i_sb->s_blocksize -
839 1) >> inode->i_sb->s_blocksize_bits;
829 840
830 if (elen > numalloc) 841 if (elen > numalloc) {
831 {
832 laarr[i].extLength -= 842 laarr[i].extLength -=
833 (numalloc << inode->i_sb->s_blocksize_bits); 843 (numalloc << inode->i_sb->
844 s_blocksize_bits);
834 numalloc = 0; 845 numalloc = 0;
835 } 846 } else {
836 else
837 {
838 numalloc -= elen; 847 numalloc -= elen;
839 if (*endnum > (i+1)) 848 if (*endnum > (i + 1))
840 memmove(&laarr[i], &laarr[i+1], 849 memmove(&laarr[i],
841 sizeof(long_ad) * (*endnum - (i+1))); 850 &laarr[i + 1],
842 i --; 851 sizeof(long_ad) *
843 (*endnum) --; 852 (*endnum - (i + 1)));
853 i--;
854 (*endnum)--;
844 } 855 }
845 } 856 }
846 UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits; 857 UDF_I_LENEXTENTS(inode) +=
858 numalloc << inode->i_sb->s_blocksize_bits;
847 } 859 }
848 } 860 }
849} 861}
850 862
851static void udf_merge_extents(struct inode *inode, 863static void udf_merge_extents(struct inode *inode,
852 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 864 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
865 int *endnum)
853{ 866{
854 int i; 867 int i;
855 868
856 for (i=0; i<(*endnum-1); i++) 869 for (i = 0; i < (*endnum - 1); i++) {
857 { 870 if ((laarr[i].extLength >> 30) ==
858 if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30)) 871 (laarr[i + 1].extLength >> 30)) {
859 { 872 if (((laarr[i].extLength >> 30) ==
860 if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || 873 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
861 ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) == 874 ||
862 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 875 ((laarr[i + 1].extLocation.logicalBlockNum -
863 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) 876 laarr[i].extLocation.logicalBlockNum) ==
864 { 877 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
865 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 878 inode->i_sb->s_blocksize -
866 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 879 1) >> inode->i_sb->s_blocksize_bits))) {
867 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 880 if (((laarr[i].
868 { 881 extLength & UDF_EXTENT_LENGTH_MASK) +
869 laarr[i+1].extLength = (laarr[i+1].extLength - 882 (laarr[i + 1].
870 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 883 extLength & UDF_EXTENT_LENGTH_MASK) +
871 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1); 884 inode->i_sb->s_blocksize -
872 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 885 1) & ~UDF_EXTENT_LENGTH_MASK) {
873 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 886 laarr[i + 1].extLength =
874 laarr[i+1].extLocation.logicalBlockNum = 887 (laarr[i + 1].extLength -
875 laarr[i].extLocation.logicalBlockNum + 888 (laarr[i].
876 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >> 889 extLength &
877 inode->i_sb->s_blocksize_bits); 890 UDF_EXTENT_LENGTH_MASK) +
878 } 891 UDF_EXTENT_LENGTH_MASK) & ~(inode->
879 else 892 i_sb->
880 { 893 s_blocksize
881 laarr[i].extLength = laarr[i+1].extLength + 894 - 1);
882 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 895 laarr[i].extLength =
883 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 896 (laarr[i].
884 if (*endnum > (i+2)) 897 extLength & UDF_EXTENT_FLAG_MASK) +
885 memmove(&laarr[i+1], &laarr[i+2], 898 (UDF_EXTENT_LENGTH_MASK + 1) -
886 sizeof(long_ad) * (*endnum - (i+2))); 899 inode->i_sb->s_blocksize;
887 i --; 900 laarr[i +
888 (*endnum) --; 901 1].extLocation.logicalBlockNum =
902 laarr[i].extLocation.
903 logicalBlockNum +
904 ((laarr[i].
905 extLength &
906 UDF_EXTENT_LENGTH_MASK) >> inode->
907 i_sb->s_blocksize_bits);
908 } else {
909 laarr[i].extLength =
910 laarr[i + 1].extLength +
911 (((laarr[i].
912 extLength &
913 UDF_EXTENT_LENGTH_MASK) +
914 inode->i_sb->s_blocksize -
915 1) & ~(inode->i_sb->s_blocksize -
916 1));
917 if (*endnum > (i + 2))
918 memmove(&laarr[i + 1],
919 &laarr[i + 2],
920 sizeof(long_ad) *
921 (*endnum - (i + 2)));
922 i--;
923 (*endnum)--;
889 } 924 }
890 } 925 }
891 } 926 } else
892 else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) && 927 if (((laarr[i].extLength >> 30) ==
893 ((laarr[i+1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) 928 (EXT_NOT_RECORDED_ALLOCATED >> 30))
894 { 929 && ((laarr[i + 1].extLength >> 30) ==
895 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, 930 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
896 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 931 udf_free_blocks(inode->i_sb, inode,
897 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 932 laarr[i].extLocation, 0,
933 ((laarr[i].
934 extLength & UDF_EXTENT_LENGTH_MASK) +
935 inode->i_sb->s_blocksize -
936 1) >> inode->i_sb->s_blocksize_bits);
898 laarr[i].extLocation.logicalBlockNum = 0; 937 laarr[i].extLocation.logicalBlockNum = 0;
899 laarr[i].extLocation.partitionReferenceNum = 0; 938 laarr[i].extLocation.partitionReferenceNum = 0;
900 939
901 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 940 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
902 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 941 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
903 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 942 inode->i_sb->s_blocksize -
904 { 943 1) & ~UDF_EXTENT_LENGTH_MASK) {
905 laarr[i+1].extLength = (laarr[i+1].extLength - 944 laarr[i + 1].extLength =
906 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 945 (laarr[i + 1].extLength -
907 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1); 946 (laarr[i].
908 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 947 extLength & UDF_EXTENT_LENGTH_MASK) +
909 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 948 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->
949 s_blocksize -
950 1);
951 laarr[i].extLength =
952 (laarr[i].
953 extLength & UDF_EXTENT_FLAG_MASK) +
954 (UDF_EXTENT_LENGTH_MASK + 1) -
955 inode->i_sb->s_blocksize;
956 } else {
957 laarr[i].extLength = laarr[i + 1].extLength +
958 (((laarr[i].
959 extLength & UDF_EXTENT_LENGTH_MASK) +
960 inode->i_sb->s_blocksize -
961 1) & ~(inode->i_sb->s_blocksize - 1));
962 if (*endnum > (i + 2))
963 memmove(&laarr[i + 1], &laarr[i + 2],
964 sizeof(long_ad) * (*endnum -
965 (i + 2)));
966 i--;
967 (*endnum)--;
910 } 968 }
911 else 969 } else if ((laarr[i].extLength >> 30) ==
912 { 970 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
913 laarr[i].extLength = laarr[i+1].extLength + 971 udf_free_blocks(inode->i_sb, inode,
914 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 972 laarr[i].extLocation, 0,
915 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 973 ((laarr[i].
916 if (*endnum > (i+2)) 974 extLength & UDF_EXTENT_LENGTH_MASK) +
917 memmove(&laarr[i+1], &laarr[i+2], 975 inode->i_sb->s_blocksize -
918 sizeof(long_ad) * (*endnum - (i+2))); 976 1) >> inode->i_sb->s_blocksize_bits);
919 i --;
920 (*endnum) --;
921 }
922 }
923 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
924 {
925 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
926 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
927 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
928 laarr[i].extLocation.logicalBlockNum = 0; 977 laarr[i].extLocation.logicalBlockNum = 0;
929 laarr[i].extLocation.partitionReferenceNum = 0; 978 laarr[i].extLocation.partitionReferenceNum = 0;
930 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) | 979 laarr[i].extLength =
931 EXT_NOT_RECORDED_NOT_ALLOCATED; 980 (laarr[i].
981 extLength & UDF_EXTENT_LENGTH_MASK) |
982 EXT_NOT_RECORDED_NOT_ALLOCATED;
932 } 983 }
933 } 984 }
934} 985}
935 986
936static void udf_update_extents(struct inode *inode, 987static void udf_update_extents(struct inode *inode,
937 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum, 988 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
938 struct extent_position *epos) 989 int startnum, int endnum,
990 struct extent_position *epos)
939{ 991{
940 int start = 0, i; 992 int start = 0, i;
941 kernel_lb_addr tmploc; 993 kernel_lb_addr tmploc;
942 uint32_t tmplen; 994 uint32_t tmplen;
943 995
944 if (startnum > endnum) 996 if (startnum > endnum) {
945 { 997 for (i = 0; i < (startnum - endnum); i++)
946 for (i=0; i<(startnum-endnum); i++)
947 udf_delete_aext(inode, *epos, laarr[i].extLocation, 998 udf_delete_aext(inode, *epos, laarr[i].extLocation,
948 laarr[i].extLength); 999 laarr[i].extLength);
949 } 1000 } else if (startnum < endnum) {
950 else if (startnum < endnum) 1001 for (i = 0; i < (endnum - startnum); i++) {
951 {
952 for (i=0; i<(endnum-startnum); i++)
953 {
954 udf_insert_aext(inode, *epos, laarr[i].extLocation, 1002 udf_insert_aext(inode, *epos, laarr[i].extLocation,
955 laarr[i].extLength); 1003 laarr[i].extLength);
956 udf_next_aext(inode, epos, &laarr[i].extLocation, 1004 udf_next_aext(inode, epos, &laarr[i].extLocation,
957 &laarr[i].extLength, 1); 1005 &laarr[i].extLength, 1);
958 start ++; 1006 start++;
959 } 1007 }
960 } 1008 }
961 1009
962 for (i=start; i<endnum; i++) 1010 for (i = start; i < endnum; i++) {
963 {
964 udf_next_aext(inode, epos, &tmploc, &tmplen, 0); 1011 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
965 udf_write_aext(inode, epos, laarr[i].extLocation, 1012 udf_write_aext(inode, epos, laarr[i].extLocation,
966 laarr[i].extLength, 1); 1013 laarr[i].extLength, 1);
967 } 1014 }
968} 1015}
969 1016
970struct buffer_head * udf_bread(struct inode * inode, int block, 1017struct buffer_head *udf_bread(struct inode *inode, int block,
971 int create, int * err) 1018 int create, int *err)
972{ 1019{
973 struct buffer_head * bh = NULL; 1020 struct buffer_head *bh = NULL;
974 1021
975 bh = udf_getblk(inode, block, create, err); 1022 bh = udf_getblk(inode, block, create, err);
976 if (!bh) 1023 if (!bh)
@@ -987,56 +1034,51 @@ struct buffer_head * udf_bread(struct inode * inode, int block,
987 return NULL; 1034 return NULL;
988} 1035}
989 1036
990void udf_truncate(struct inode * inode) 1037void udf_truncate(struct inode *inode)
991{ 1038{
992 int offset; 1039 int offset;
993 int err; 1040 int err;
994 1041
995 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1042 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
996 S_ISLNK(inode->i_mode))) 1043 S_ISLNK(inode->i_mode)))
997 return; 1044 return;
998 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) 1045 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
999 return; 1046 return;
1000 1047
1001 lock_kernel(); 1048 lock_kernel();
1002 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1049 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1003 { 1050 if (inode->i_sb->s_blocksize <
1004 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + 1051 (udf_file_entry_alloc_offset(inode) + inode->i_size)) {
1005 inode->i_size))
1006 {
1007 udf_expand_file_adinicb(inode, inode->i_size, &err); 1052 udf_expand_file_adinicb(inode, inode->i_size, &err);
1008 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1053 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1009 {
1010 inode->i_size = UDF_I_LENALLOC(inode); 1054 inode->i_size = UDF_I_LENALLOC(inode);
1011 unlock_kernel(); 1055 unlock_kernel();
1012 return; 1056 return;
1013 } 1057 } else
1014 else
1015 udf_truncate_extents(inode); 1058 udf_truncate_extents(inode);
1016 } 1059 } else {
1017 else
1018 {
1019 offset = inode->i_size & (inode->i_sb->s_blocksize - 1); 1060 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1020 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode)); 1061 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) +
1062 offset, 0x00,
1063 inode->i_sb->s_blocksize - offset -
1064 udf_file_entry_alloc_offset(inode));
1021 UDF_I_LENALLOC(inode) = inode->i_size; 1065 UDF_I_LENALLOC(inode) = inode->i_size;
1022 } 1066 }
1023 } 1067 } else {
1024 else 1068 block_truncate_page(inode->i_mapping, inode->i_size,
1025 { 1069 udf_get_block);
1026 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
1027 udf_truncate_extents(inode); 1070 udf_truncate_extents(inode);
1028 } 1071 }
1029 1072
1030 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb); 1073 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1031 if (IS_SYNC(inode)) 1074 if (IS_SYNC(inode))
1032 udf_sync_inode (inode); 1075 udf_sync_inode(inode);
1033 else 1076 else
1034 mark_inode_dirty(inode); 1077 mark_inode_dirty(inode);
1035 unlock_kernel(); 1078 unlock_kernel();
1036} 1079}
1037 1080
1038static void 1081static void __udf_read_inode(struct inode *inode)
1039__udf_read_inode(struct inode *inode)
1040{ 1082{
1041 struct buffer_head *bh = NULL; 1083 struct buffer_head *bh = NULL;
1042 struct fileEntry *fe; 1084 struct fileEntry *fe;
@@ -1056,19 +1098,18 @@ __udf_read_inode(struct inode *inode)
1056 */ 1098 */
1057 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident); 1099 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1058 1100
1059 if (!bh) 1101 if (!bh) {
1060 {
1061 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", 1102 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1062 inode->i_ino); 1103 inode->i_ino);
1063 make_bad_inode(inode); 1104 make_bad_inode(inode);
1064 return; 1105 return;
1065 } 1106 }
1066 1107
1067 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && 1108 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1068 ident != TAG_IDENT_USE) 1109 ident != TAG_IDENT_USE) {
1069 { 1110 printk(KERN_ERR
1070 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", 1111 "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1071 inode->i_ino, ident); 1112 inode->i_ino, ident);
1072 brelse(bh); 1113 brelse(bh);
1073 make_bad_inode(inode); 1114 make_bad_inode(inode);
1074 return; 1115 return;
@@ -1076,51 +1117,46 @@ __udf_read_inode(struct inode *inode)
1076 1117
1077 fe = (struct fileEntry *)bh->b_data; 1118 fe = (struct fileEntry *)bh->b_data;
1078 1119
1079 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) 1120 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
1080 {
1081 struct buffer_head *ibh = NULL, *nbh = NULL; 1121 struct buffer_head *ibh = NULL, *nbh = NULL;
1082 struct indirectEntry *ie; 1122 struct indirectEntry *ie;
1083 1123
1084 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident); 1124 ibh =
1085 if (ident == TAG_IDENT_IE) 1125 udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
1086 { 1126 &ident);
1087 if (ibh) 1127 if (ident == TAG_IDENT_IE) {
1088 { 1128 if (ibh) {
1089 kernel_lb_addr loc; 1129 kernel_lb_addr loc;
1090 ie = (struct indirectEntry *)ibh->b_data; 1130 ie = (struct indirectEntry *)ibh->b_data;
1091 1131
1092 loc = lelb_to_cpu(ie->indirectICB.extLocation); 1132 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1093 1133
1094 if (ie->indirectICB.extLength && 1134 if (ie->indirectICB.extLength &&
1095 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) 1135 (nbh =
1096 { 1136 udf_read_ptagged(inode->i_sb, loc, 0,
1097 if (ident == TAG_IDENT_FE || 1137 &ident))) {
1098 ident == TAG_IDENT_EFE) 1138 if (ident == TAG_IDENT_FE
1099 { 1139 || ident == TAG_IDENT_EFE) {
1100 memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr)); 1140 memcpy(&UDF_I_LOCATION(inode),
1141 &loc,
1142 sizeof(kernel_lb_addr));
1101 brelse(bh); 1143 brelse(bh);
1102 brelse(ibh); 1144 brelse(ibh);
1103 brelse(nbh); 1145 brelse(nbh);
1104 __udf_read_inode(inode); 1146 __udf_read_inode(inode);
1105 return; 1147 return;
1106 } 1148 } else {
1107 else
1108 {
1109 brelse(nbh); 1149 brelse(nbh);
1110 brelse(ibh); 1150 brelse(ibh);
1111 } 1151 }
1112 } 1152 } else
1113 else
1114 brelse(ibh); 1153 brelse(ibh);
1115 } 1154 }
1116 } 1155 } else
1117 else
1118 brelse(ibh); 1156 brelse(ibh);
1119 } 1157 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1120 else if (le16_to_cpu(fe->icbTag.strategyType) != 4)
1121 {
1122 printk(KERN_ERR "udf: unsupported strategy type: %d\n", 1158 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1123 le16_to_cpu(fe->icbTag.strategyType)); 1159 le16_to_cpu(fe->icbTag.strategyType));
1124 brelse(bh); 1160 brelse(bh);
1125 make_bad_inode(inode); 1161 make_bad_inode(inode);
1126 return; 1162 return;
@@ -1143,62 +1179,70 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1143 1179
1144 if (le16_to_cpu(fe->icbTag.strategyType) == 4) 1180 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
1145 UDF_I_STRAT4096(inode) = 0; 1181 UDF_I_STRAT4096(inode) = 0;
1146 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ 1182 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
1147 UDF_I_STRAT4096(inode) = 1; 1183 UDF_I_STRAT4096(inode) = 1;
1148 1184
1149 UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK; 1185 UDF_I_ALLOCTYPE(inode) =
1186 le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
1150 UDF_I_UNIQUE(inode) = 0; 1187 UDF_I_UNIQUE(inode) = 0;
1151 UDF_I_LENEATTR(inode) = 0; 1188 UDF_I_LENEATTR(inode) = 0;
1152 UDF_I_LENEXTENTS(inode) = 0; 1189 UDF_I_LENEXTENTS(inode) = 0;
1153 UDF_I_LENALLOC(inode) = 0; 1190 UDF_I_LENALLOC(inode) = 0;
1154 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0; 1191 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
1155 UDF_I_NEXT_ALLOC_GOAL(inode) = 0; 1192 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
1156 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) 1193 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1157 {
1158 UDF_I_EFE(inode) = 1; 1194 UDF_I_EFE(inode) = 1;
1159 UDF_I_USE(inode) = 0; 1195 UDF_I_USE(inode) = 0;
1160 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) 1196 if (udf_alloc_i_data
1161 { 1197 (inode,
1198 inode->i_sb->s_blocksize -
1199 sizeof(struct extendedFileEntry))) {
1162 make_bad_inode(inode); 1200 make_bad_inode(inode);
1163 return; 1201 return;
1164 } 1202 }
1165 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); 1203 memcpy(UDF_I_DATA(inode),
1166 } 1204 bh->b_data + sizeof(struct extendedFileEntry),
1167 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) 1205 inode->i_sb->s_blocksize -
1168 { 1206 sizeof(struct extendedFileEntry));
1207 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1169 UDF_I_EFE(inode) = 0; 1208 UDF_I_EFE(inode) = 0;
1170 UDF_I_USE(inode) = 0; 1209 UDF_I_USE(inode) = 0;
1171 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) 1210 if (udf_alloc_i_data
1172 { 1211 (inode,
1212 inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1173 make_bad_inode(inode); 1213 make_bad_inode(inode);
1174 return; 1214 return;
1175 } 1215 }
1176 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1216 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
1177 } 1217 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1178 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1218 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1179 {
1180 UDF_I_EFE(inode) = 0; 1219 UDF_I_EFE(inode) = 0;
1181 UDF_I_USE(inode) = 1; 1220 UDF_I_USE(inode) = 1;
1182 UDF_I_LENALLOC(inode) = 1221 UDF_I_LENALLOC(inode) =
1183 le32_to_cpu( 1222 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->
1184 ((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs); 1223 lengthAllocDescs);
1185 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) 1224 if (udf_alloc_i_data
1186 { 1225 (inode,
1226 inode->i_sb->s_blocksize -
1227 sizeof(struct unallocSpaceEntry))) {
1187 make_bad_inode(inode); 1228 make_bad_inode(inode);
1188 return; 1229 return;
1189 } 1230 }
1190 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1231 memcpy(UDF_I_DATA(inode),
1232 bh->b_data + sizeof(struct unallocSpaceEntry),
1233 inode->i_sb->s_blocksize -
1234 sizeof(struct unallocSpaceEntry));
1191 return; 1235 return;
1192 } 1236 }
1193 1237
1194 inode->i_uid = le32_to_cpu(fe->uid); 1238 inode->i_uid = le32_to_cpu(fe->uid);
1195 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1239 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1196 UDF_FLAG_UID_IGNORE)) 1240 UDF_FLAG_UID_IGNORE))
1197 inode->i_uid = UDF_SB(inode->i_sb)->s_uid; 1241 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1198 1242
1199 inode->i_gid = le32_to_cpu(fe->gid); 1243 inode->i_gid = le32_to_cpu(fe->gid);
1200 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1244 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1201 UDF_FLAG_GID_IGNORE)) 1245 UDF_FLAG_GID_IGNORE))
1202 inode->i_gid = UDF_SB(inode->i_sb)->s_gid; 1246 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1203 1247
1204 inode->i_nlink = le16_to_cpu(fe->fileLinkCount); 1248 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
@@ -1211,41 +1255,31 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1211 inode->i_mode = udf_convert_permissions(fe); 1255 inode->i_mode = udf_convert_permissions(fe);
1212 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask; 1256 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1213 1257
1214 if (UDF_I_EFE(inode) == 0) 1258 if (UDF_I_EFE(inode) == 0) {
1215 {
1216 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << 1259 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1217 (inode->i_sb->s_blocksize_bits - 9); 1260 (inode->i_sb->s_blocksize_bits - 9);
1218 1261
1219 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1262 if (udf_stamp_to_time(&convtime, &convtime_usec,
1220 lets_to_cpu(fe->accessTime)) ) 1263 lets_to_cpu(fe->accessTime))) {
1221 {
1222 inode->i_atime.tv_sec = convtime; 1264 inode->i_atime.tv_sec = convtime;
1223 inode->i_atime.tv_nsec = convtime_usec * 1000; 1265 inode->i_atime.tv_nsec = convtime_usec * 1000;
1224 } 1266 } else {
1225 else
1226 {
1227 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1267 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1228 } 1268 }
1229 1269
1230 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1270 if (udf_stamp_to_time(&convtime, &convtime_usec,
1231 lets_to_cpu(fe->modificationTime)) ) 1271 lets_to_cpu(fe->modificationTime))) {
1232 {
1233 inode->i_mtime.tv_sec = convtime; 1272 inode->i_mtime.tv_sec = convtime;
1234 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1273 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1235 } 1274 } else {
1236 else
1237 {
1238 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1275 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1239 } 1276 }
1240 1277
1241 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1278 if (udf_stamp_to_time(&convtime, &convtime_usec,
1242 lets_to_cpu(fe->attrTime)) ) 1279 lets_to_cpu(fe->attrTime))) {
1243 {
1244 inode->i_ctime.tv_sec = convtime; 1280 inode->i_ctime.tv_sec = convtime;
1245 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1281 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1246 } 1282 } else {
1247 else
1248 {
1249 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1283 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1250 } 1284 }
1251 1285
@@ -1253,65 +1287,51 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1253 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr); 1287 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1254 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs); 1288 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1255 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode); 1289 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
1256 } 1290 } else {
1257 else
1258 {
1259 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << 1291 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1260 (inode->i_sb->s_blocksize_bits - 9); 1292 (inode->i_sb->s_blocksize_bits - 9);
1261 1293
1262 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1294 if (udf_stamp_to_time(&convtime, &convtime_usec,
1263 lets_to_cpu(efe->accessTime)) ) 1295 lets_to_cpu(efe->accessTime))) {
1264 {
1265 inode->i_atime.tv_sec = convtime; 1296 inode->i_atime.tv_sec = convtime;
1266 inode->i_atime.tv_nsec = convtime_usec * 1000; 1297 inode->i_atime.tv_nsec = convtime_usec * 1000;
1267 } 1298 } else {
1268 else
1269 {
1270 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1299 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1271 } 1300 }
1272 1301
1273 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1302 if (udf_stamp_to_time(&convtime, &convtime_usec,
1274 lets_to_cpu(efe->modificationTime)) ) 1303 lets_to_cpu(efe->modificationTime))) {
1275 {
1276 inode->i_mtime.tv_sec = convtime; 1304 inode->i_mtime.tv_sec = convtime;
1277 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1305 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1278 } 1306 } else {
1279 else
1280 {
1281 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1307 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1282 } 1308 }
1283 1309
1284 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1310 if (udf_stamp_to_time(&convtime, &convtime_usec,
1285 lets_to_cpu(efe->createTime)) ) 1311 lets_to_cpu(efe->createTime))) {
1286 {
1287 UDF_I_CRTIME(inode).tv_sec = convtime; 1312 UDF_I_CRTIME(inode).tv_sec = convtime;
1288 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000; 1313 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
1289 } 1314 } else {
1290 else
1291 {
1292 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb); 1315 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
1293 } 1316 }
1294 1317
1295 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1318 if (udf_stamp_to_time(&convtime, &convtime_usec,
1296 lets_to_cpu(efe->attrTime)) ) 1319 lets_to_cpu(efe->attrTime))) {
1297 {
1298 inode->i_ctime.tv_sec = convtime; 1320 inode->i_ctime.tv_sec = convtime;
1299 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1321 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1300 } 1322 } else {
1301 else
1302 {
1303 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1323 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1304 } 1324 }
1305 1325
1306 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); 1326 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1307 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); 1327 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1308 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); 1328 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1309 offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode); 1329 offset =
1330 sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1310 } 1331 }
1311 1332
1312 switch (fe->icbTag.fileType) 1333 switch (fe->icbTag.fileType) {
1313 { 1334 case ICBTAG_FILE_TYPE_DIRECTORY:
1314 case ICBTAG_FILE_TYPE_DIRECTORY:
1315 { 1335 {
1316 inode->i_op = &udf_dir_inode_operations; 1336 inode->i_op = &udf_dir_inode_operations;
1317 inode->i_fop = &udf_dir_operations; 1337 inode->i_fop = &udf_dir_operations;
@@ -1319,9 +1339,9 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1319 inc_nlink(inode); 1339 inc_nlink(inode);
1320 break; 1340 break;
1321 } 1341 }
1322 case ICBTAG_FILE_TYPE_REALTIME: 1342 case ICBTAG_FILE_TYPE_REALTIME:
1323 case ICBTAG_FILE_TYPE_REGULAR: 1343 case ICBTAG_FILE_TYPE_REGULAR:
1324 case ICBTAG_FILE_TYPE_UNDEF: 1344 case ICBTAG_FILE_TYPE_UNDEF:
1325 { 1345 {
1326 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1346 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1327 inode->i_data.a_ops = &udf_adinicb_aops; 1347 inode->i_data.a_ops = &udf_adinicb_aops;
@@ -1332,56 +1352,54 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1332 inode->i_mode |= S_IFREG; 1352 inode->i_mode |= S_IFREG;
1333 break; 1353 break;
1334 } 1354 }
1335 case ICBTAG_FILE_TYPE_BLOCK: 1355 case ICBTAG_FILE_TYPE_BLOCK:
1336 { 1356 {
1337 inode->i_mode |= S_IFBLK; 1357 inode->i_mode |= S_IFBLK;
1338 break; 1358 break;
1339 } 1359 }
1340 case ICBTAG_FILE_TYPE_CHAR: 1360 case ICBTAG_FILE_TYPE_CHAR:
1341 { 1361 {
1342 inode->i_mode |= S_IFCHR; 1362 inode->i_mode |= S_IFCHR;
1343 break; 1363 break;
1344 } 1364 }
1345 case ICBTAG_FILE_TYPE_FIFO: 1365 case ICBTAG_FILE_TYPE_FIFO:
1346 { 1366 {
1347 init_special_inode(inode, inode->i_mode | S_IFIFO, 0); 1367 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1348 break; 1368 break;
1349 } 1369 }
1350 case ICBTAG_FILE_TYPE_SOCKET: 1370 case ICBTAG_FILE_TYPE_SOCKET:
1351 { 1371 {
1352 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0); 1372 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1353 break; 1373 break;
1354 } 1374 }
1355 case ICBTAG_FILE_TYPE_SYMLINK: 1375 case ICBTAG_FILE_TYPE_SYMLINK:
1356 { 1376 {
1357 inode->i_data.a_ops = &udf_symlink_aops; 1377 inode->i_data.a_ops = &udf_symlink_aops;
1358 inode->i_op = &page_symlink_inode_operations; 1378 inode->i_op = &page_symlink_inode_operations;
1359 inode->i_mode = S_IFLNK|S_IRWXUGO; 1379 inode->i_mode = S_IFLNK | S_IRWXUGO;
1360 break; 1380 break;
1361 } 1381 }
1362 default: 1382 default:
1363 { 1383 {
1364 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n", 1384 printk(KERN_ERR
1365 inode->i_ino, fe->icbTag.fileType); 1385 "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1386 inode->i_ino, fe->icbTag.fileType);
1366 make_bad_inode(inode); 1387 make_bad_inode(inode);
1367 return; 1388 return;
1368 } 1389 }
1369 } 1390 }
1370 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1391 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1371 { 1392 struct deviceSpec *dsea = (struct deviceSpec *)
1372 struct deviceSpec *dsea = 1393 udf_get_extendedattr(inode, 12, 1);
1373 (struct deviceSpec *)
1374 udf_get_extendedattr(inode, 12, 1);
1375 1394
1376 if (dsea) 1395 if (dsea) {
1377 { 1396 init_special_inode(inode, inode->i_mode,
1378 init_special_inode(inode, inode->i_mode, MKDEV( 1397 MKDEV(le32_to_cpu
1379 le32_to_cpu(dsea->majorDeviceIdent), 1398 (dsea->majorDeviceIdent),
1380 le32_to_cpu(dsea->minorDeviceIdent))); 1399 le32_to_cpu(dsea->
1400 minorDeviceIdent)));
1381 /* Developer ID ??? */ 1401 /* Developer ID ??? */
1382 } 1402 } else {
1383 else
1384 {
1385 make_bad_inode(inode); 1403 make_bad_inode(inode);
1386 } 1404 }
1387 } 1405 }
@@ -1391,9 +1409,9 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
1391{ 1409{
1392 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); 1410 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1393 1411
1394 if (!UDF_I_DATA(inode)) 1412 if (!UDF_I_DATA(inode)) {
1395 { 1413 printk(KERN_ERR
1396 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n", 1414 "udf:udf_alloc_i_data (ino %ld) no free memory\n",
1397 inode->i_ino); 1415 inode->i_ino);
1398 return -ENOMEM; 1416 return -ENOMEM;
1399 } 1417 }
@@ -1401,8 +1419,7 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
1401 return 0; 1419 return 0;
1402} 1420}
1403 1421
1404static mode_t 1422static mode_t udf_convert_permissions(struct fileEntry *fe)
1405udf_convert_permissions(struct fileEntry *fe)
1406{ 1423{
1407 mode_t mode; 1424 mode_t mode;
1408 uint32_t permissions; 1425 uint32_t permissions;
@@ -1411,12 +1428,12 @@ udf_convert_permissions(struct fileEntry *fe)
1411 permissions = le32_to_cpu(fe->permissions); 1428 permissions = le32_to_cpu(fe->permissions);
1412 flags = le16_to_cpu(fe->icbTag.flags); 1429 flags = le16_to_cpu(fe->icbTag.flags);
1413 1430
1414 mode = (( permissions ) & S_IRWXO) | 1431 mode = ((permissions) & S_IRWXO) |
1415 (( permissions >> 2 ) & S_IRWXG) | 1432 ((permissions >> 2) & S_IRWXG) |
1416 (( permissions >> 4 ) & S_IRWXU) | 1433 ((permissions >> 4) & S_IRWXU) |
1417 (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | 1434 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1418 (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | 1435 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1419 (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); 1436 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1420 1437
1421 return mode; 1438 return mode;
1422} 1439}
@@ -1436,7 +1453,7 @@ udf_convert_permissions(struct fileEntry *fe)
1436 * Written, tested, and released. 1453 * Written, tested, and released.
1437 */ 1454 */
1438 1455
1439int udf_write_inode(struct inode * inode, int sync) 1456int udf_write_inode(struct inode *inode, int sync)
1440{ 1457{
1441 int ret; 1458 int ret;
1442 lock_kernel(); 1459 lock_kernel();
@@ -1445,13 +1462,12 @@ int udf_write_inode(struct inode * inode, int sync)
1445 return ret; 1462 return ret;
1446} 1463}
1447 1464
1448int udf_sync_inode(struct inode * inode) 1465int udf_sync_inode(struct inode *inode)
1449{ 1466{
1450 return udf_update_inode(inode, 1); 1467 return udf_update_inode(inode, 1);
1451} 1468}
1452 1469
1453static int 1470static int udf_update_inode(struct inode *inode, int do_sync)
1454udf_update_inode(struct inode *inode, int do_sync)
1455{ 1471{
1456 struct buffer_head *bh = NULL; 1472 struct buffer_head *bh = NULL;
1457 struct fileEntry *fe; 1473 struct fileEntry *fe;
@@ -1464,10 +1480,10 @@ udf_update_inode(struct inode *inode, int do_sync)
1464 int err = 0; 1480 int err = 0;
1465 1481
1466 bh = udf_tread(inode->i_sb, 1482 bh = udf_tread(inode->i_sb,
1467 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0)); 1483 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode),
1484 0));
1468 1485
1469 if (!bh) 1486 if (!bh) {
1470 {
1471 udf_debug("bread failure\n"); 1487 udf_debug("bread failure\n");
1472 return -EIO; 1488 return -EIO;
1473 } 1489 }
@@ -1477,23 +1493,29 @@ udf_update_inode(struct inode *inode, int do_sync)
1477 fe = (struct fileEntry *)bh->b_data; 1493 fe = (struct fileEntry *)bh->b_data;
1478 efe = (struct extendedFileEntry *)bh->b_data; 1494 efe = (struct extendedFileEntry *)bh->b_data;
1479 1495
1480 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1496 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1481 {
1482 struct unallocSpaceEntry *use = 1497 struct unallocSpaceEntry *use =
1483 (struct unallocSpaceEntry *)bh->b_data; 1498 (struct unallocSpaceEntry *)bh->b_data;
1484 1499
1485 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1500 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1486 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1501 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1487 crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - 1502 UDF_I_DATA(inode),
1488 sizeof(tag); 1503 inode->i_sb->s_blocksize -
1489 use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 1504 sizeof(struct unallocSpaceEntry));
1505 crclen =
1506 sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) -
1507 sizeof(tag);
1508 use->descTag.tagLocation =
1509 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1490 use->descTag.descCRCLength = cpu_to_le16(crclen); 1510 use->descTag.descCRCLength = cpu_to_le16(crclen);
1491 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0)); 1511 use->descTag.descCRC =
1512 cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1492 1513
1493 use->descTag.tagChecksum = 0; 1514 use->descTag.tagChecksum = 0;
1494 for (i=0; i<16; i++) 1515 for (i = 0; i < 16; i++)
1495 if (i != 4) 1516 if (i != 4)
1496 use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; 1517 use->descTag.tagChecksum +=
1518 ((uint8_t *) & (use->descTag))[i];
1497 1519
1498 mark_buffer_dirty(bh); 1520 mark_buffer_dirty(bh);
1499 brelse(bh); 1521 brelse(bh);
@@ -1502,20 +1524,21 @@ udf_update_inode(struct inode *inode, int do_sync)
1502 1524
1503 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) 1525 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1504 fe->uid = cpu_to_le32(-1); 1526 fe->uid = cpu_to_le32(-1);
1505 else fe->uid = cpu_to_le32(inode->i_uid); 1527 else
1528 fe->uid = cpu_to_le32(inode->i_uid);
1506 1529
1507 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) 1530 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1508 fe->gid = cpu_to_le32(-1); 1531 fe->gid = cpu_to_le32(-1);
1509 else fe->gid = cpu_to_le32(inode->i_gid); 1532 else
1533 fe->gid = cpu_to_le32(inode->i_gid);
1510 1534
1511 udfperms = ((inode->i_mode & S_IRWXO) ) | 1535 udfperms = ((inode->i_mode & S_IRWXO)) |
1512 ((inode->i_mode & S_IRWXG) << 2) | 1536 ((inode->i_mode & S_IRWXG) << 2) | ((inode->i_mode & S_IRWXU) << 4);
1513 ((inode->i_mode & S_IRWXU) << 4);
1514 1537
1515 udfperms |= (le32_to_cpu(fe->permissions) & 1538 udfperms |= (le32_to_cpu(fe->permissions) &
1516 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | 1539 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1517 FE_PERM_G_DELETE | FE_PERM_G_CHATTR | 1540 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1518 FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); 1541 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1519 fe->permissions = cpu_to_le32(udfperms); 1542 fe->permissions = cpu_to_le32(udfperms);
1520 1543
1521 if (S_ISDIR(inode->i_mode)) 1544 if (S_ISDIR(inode->i_mode))
@@ -1525,26 +1548,24 @@ udf_update_inode(struct inode *inode, int do_sync)
1525 1548
1526 fe->informationLength = cpu_to_le64(inode->i_size); 1549 fe->informationLength = cpu_to_le64(inode->i_size);
1527 1550
1528 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1551 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1529 {
1530 regid *eid; 1552 regid *eid;
1531 struct deviceSpec *dsea = 1553 struct deviceSpec *dsea = (struct deviceSpec *)
1532 (struct deviceSpec *) 1554 udf_get_extendedattr(inode, 12, 1);
1533 udf_get_extendedattr(inode, 12, 1);
1534 1555
1535 if (!dsea) 1556 if (!dsea) {
1536 {
1537 dsea = (struct deviceSpec *) 1557 dsea = (struct deviceSpec *)
1538 udf_add_extendedattr(inode, 1558 udf_add_extendedattr(inode,
1539 sizeof(struct deviceSpec) + 1559 sizeof(struct deviceSpec) +
1540 sizeof(regid), 12, 0x3); 1560 sizeof(regid), 12, 0x3);
1541 dsea->attrType = cpu_to_le32(12); 1561 dsea->attrType = cpu_to_le32(12);
1542 dsea->attrSubtype = 1; 1562 dsea->attrSubtype = 1;
1543 dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + 1563 dsea->attrLength =
1544 sizeof(regid)); 1564 cpu_to_le32(sizeof(struct deviceSpec) +
1565 sizeof(regid));
1545 dsea->impUseLength = cpu_to_le32(sizeof(regid)); 1566 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1546 } 1567 }
1547 eid = (regid *)dsea->impUse; 1568 eid = (regid *) dsea->impUse;
1548 memset(eid, 0, sizeof(regid)); 1569 memset(eid, 0, sizeof(regid));
1549 strcpy(eid->ident, UDF_ID_DEVELOPER); 1570 strcpy(eid->ident, UDF_ID_DEVELOPER);
1550 eid->identSuffix[0] = UDF_OS_CLASS_UNIX; 1571 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1553,12 +1574,13 @@ udf_update_inode(struct inode *inode, int do_sync)
1553 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode)); 1574 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1554 } 1575 }
1555 1576
1556 if (UDF_I_EFE(inode) == 0) 1577 if (UDF_I_EFE(inode) == 0) {
1557 { 1578 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1558 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1579 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1559 fe->logicalBlocksRecorded = cpu_to_le64( 1580 fe->logicalBlocksRecorded =
1560 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1581 cpu_to_le64((inode->i_blocks +
1561 (inode->i_sb->s_blocksize_bits - 9)); 1582 (1 << (inode->i_sb->s_blocksize_bits - 9)) -
1583 1) >> (inode->i_sb->s_blocksize_bits - 9));
1562 1584
1563 if (udf_time_to_stamp(&cpu_time, inode->i_atime)) 1585 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1564 fe->accessTime = cpu_to_lets(cpu_time); 1586 fe->accessTime = cpu_to_lets(cpu_time);
@@ -1575,31 +1597,34 @@ udf_update_inode(struct inode *inode, int do_sync)
1575 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1597 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1576 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); 1598 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1577 crclen = sizeof(struct fileEntry); 1599 crclen = sizeof(struct fileEntry);
1578 } 1600 } else {
1579 else 1601 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1580 { 1602 UDF_I_DATA(inode),
1581 memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); 1603 inode->i_sb->s_blocksize -
1604 sizeof(struct extendedFileEntry));
1582 efe->objectSize = cpu_to_le64(inode->i_size); 1605 efe->objectSize = cpu_to_le64(inode->i_size);
1583 efe->logicalBlocksRecorded = cpu_to_le64( 1606 efe->logicalBlocksRecorded = cpu_to_le64((inode->i_blocks +
1584 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1607 (1 <<
1585 (inode->i_sb->s_blocksize_bits - 9)); 1608 (inode->i_sb->
1609 s_blocksize_bits -
1610 9)) -
1611 1) >> (inode->i_sb->
1612 s_blocksize_bits
1613 - 9));
1586 1614
1587 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || 1615 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1588 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && 1616 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
1589 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) 1617 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) {
1590 {
1591 UDF_I_CRTIME(inode) = inode->i_atime; 1618 UDF_I_CRTIME(inode) = inode->i_atime;
1592 } 1619 }
1593 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || 1620 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
1594 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && 1621 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
1595 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) 1622 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) {
1596 {
1597 UDF_I_CRTIME(inode) = inode->i_mtime; 1623 UDF_I_CRTIME(inode) = inode->i_mtime;
1598 } 1624 }
1599 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || 1625 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
1600 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && 1626 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
1601 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) 1627 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) {
1602 {
1603 UDF_I_CRTIME(inode) = inode->i_ctime; 1628 UDF_I_CRTIME(inode) = inode->i_ctime;
1604 } 1629 }
1605 1630
@@ -1622,14 +1647,11 @@ udf_update_inode(struct inode *inode, int do_sync)
1622 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE); 1647 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1623 crclen = sizeof(struct extendedFileEntry); 1648 crclen = sizeof(struct extendedFileEntry);
1624 } 1649 }
1625 if (UDF_I_STRAT4096(inode)) 1650 if (UDF_I_STRAT4096(inode)) {
1626 {
1627 fe->icbTag.strategyType = cpu_to_le16(4096); 1651 fe->icbTag.strategyType = cpu_to_le16(4096);
1628 fe->icbTag.strategyParameter = cpu_to_le16(1); 1652 fe->icbTag.strategyParameter = cpu_to_le16(1);
1629 fe->icbTag.numEntries = cpu_to_le16(2); 1653 fe->icbTag.numEntries = cpu_to_le16(2);
1630 } 1654 } else {
1631 else
1632 {
1633 fe->icbTag.strategyType = cpu_to_le16(4); 1655 fe->icbTag.strategyType = cpu_to_le16(4);
1634 fe->icbTag.numEntries = cpu_to_le16(1); 1656 fe->icbTag.numEntries = cpu_to_le16(1);
1635 } 1657 }
@@ -1649,13 +1671,13 @@ udf_update_inode(struct inode *inode, int do_sync)
1649 else if (S_ISSOCK(inode->i_mode)) 1671 else if (S_ISSOCK(inode->i_mode))
1650 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET; 1672 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1651 1673
1652 icbflags = UDF_I_ALLOCTYPE(inode) | 1674 icbflags = UDF_I_ALLOCTYPE(inode) |
1653 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) | 1675 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1654 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) | 1676 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1655 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) | 1677 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1656 (le16_to_cpu(fe->icbTag.flags) & 1678 (le16_to_cpu(fe->icbTag.flags) &
1657 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID | 1679 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1658 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY)); 1680 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1659 1681
1660 fe->icbTag.flags = cpu_to_le16(icbflags); 1682 fe->icbTag.flags = cpu_to_le16(icbflags);
1661 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1683 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
@@ -1663,25 +1685,26 @@ udf_update_inode(struct inode *inode, int do_sync)
1663 else 1685 else
1664 fe->descTag.descVersion = cpu_to_le16(2); 1686 fe->descTag.descVersion = cpu_to_le16(2);
1665 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); 1687 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
1666 fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 1688 fe->descTag.tagLocation =
1689 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1667 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); 1690 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1668 fe->descTag.descCRCLength = cpu_to_le16(crclen); 1691 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1669 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0)); 1692 fe->descTag.descCRC =
1693 cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1670 1694
1671 fe->descTag.tagChecksum = 0; 1695 fe->descTag.tagChecksum = 0;
1672 for (i=0; i<16; i++) 1696 for (i = 0; i < 16; i++)
1673 if (i != 4) 1697 if (i != 4)
1674 fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i]; 1698 fe->descTag.tagChecksum +=
1699 ((uint8_t *) & (fe->descTag))[i];
1675 1700
1676 /* write the data blocks */ 1701 /* write the data blocks */
1677 mark_buffer_dirty(bh); 1702 mark_buffer_dirty(bh);
1678 if (do_sync) 1703 if (do_sync) {
1679 {
1680 sync_dirty_buffer(bh); 1704 sync_dirty_buffer(bh);
1681 if (buffer_req(bh) && !buffer_uptodate(bh)) 1705 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1682 {
1683 printk("IO error syncing udf inode [%s:%08lx]\n", 1706 printk("IO error syncing udf inode [%s:%08lx]\n",
1684 inode->i_sb->s_id, inode->i_ino); 1707 inode->i_sb->s_id, inode->i_ino);
1685 err = -EIO; 1708 err = -EIO;
1686 } 1709 }
1687 } 1710 }
@@ -1689,8 +1712,7 @@ udf_update_inode(struct inode *inode, int do_sync)
1689 return err; 1712 return err;
1690} 1713}
1691 1714
1692struct inode * 1715struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1693udf_iget(struct super_block *sb, kernel_lb_addr ino)
1694{ 1716{
1695 unsigned long block = udf_get_lb_pblock(sb, ino, 0); 1717 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1696 struct inode *inode = iget_locked(sb, block); 1718 struct inode *inode = iget_locked(sb, block);
@@ -1707,22 +1729,23 @@ udf_iget(struct super_block *sb, kernel_lb_addr ino)
1707 if (is_bad_inode(inode)) 1729 if (is_bad_inode(inode))
1708 goto out_iput; 1730 goto out_iput;
1709 1731
1710 if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) { 1732 if (ino.logicalBlockNum >=
1733 UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1711 udf_debug("block=%d, partition=%d out of range\n", 1734 udf_debug("block=%d, partition=%d out of range\n",
1712 ino.logicalBlockNum, ino.partitionReferenceNum); 1735 ino.logicalBlockNum, ino.partitionReferenceNum);
1713 make_bad_inode(inode); 1736 make_bad_inode(inode);
1714 goto out_iput; 1737 goto out_iput;
1715 } 1738 }
1716 1739
1717 return inode; 1740 return inode;
1718 1741
1719 out_iput: 1742 out_iput:
1720 iput(inode); 1743 iput(inode);
1721 return NULL; 1744 return NULL;
1722} 1745}
1723 1746
1724int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, 1747int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1725 kernel_lb_addr eloc, uint32_t elen, int inc) 1748 kernel_lb_addr eloc, uint32_t elen, int inc)
1726{ 1749{
1727 int adsize; 1750 int adsize;
1728 short_ad *sad = NULL; 1751 short_ad *sad = NULL;
@@ -1732,7 +1755,9 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1732 uint8_t *ptr; 1755 uint8_t *ptr;
1733 1756
1734 if (!epos->bh) 1757 if (!epos->bh)
1735 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1758 ptr =
1759 UDF_I_DATA(inode) + epos->offset -
1760 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1736 else 1761 else
1737 ptr = epos->bh->b_data + epos->offset; 1762 ptr = epos->bh->b_data + epos->offset;
1738 1763
@@ -1743,21 +1768,24 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1743 else 1768 else
1744 return -1; 1769 return -1;
1745 1770
1746 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) 1771 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1747 {
1748 char *sptr, *dptr; 1772 char *sptr, *dptr;
1749 struct buffer_head *nbh; 1773 struct buffer_head *nbh;
1750 int err, loffset; 1774 int err, loffset;
1751 kernel_lb_addr obloc = epos->block; 1775 kernel_lb_addr obloc = epos->block;
1752 1776
1753 if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, 1777 if (!
1754 obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) 1778 (epos->block.logicalBlockNum =
1755 { 1779 udf_new_block(inode->i_sb, NULL,
1780 obloc.partitionReferenceNum,
1781 obloc.logicalBlockNum, &err))) {
1756 return -1; 1782 return -1;
1757 } 1783 }
1758 if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, 1784 if (!
1759 epos->block, 0)))) 1785 (nbh =
1760 { 1786 udf_tgetblk(inode->i_sb,
1787 udf_get_lb_pblock(inode->i_sb, epos->block,
1788 0)))) {
1761 return -1; 1789 return -1;
1762 } 1790 }
1763 lock_buffer(nbh); 1791 lock_buffer(nbh);
@@ -1768,144 +1796,142 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1768 1796
1769 aed = (struct allocExtDesc *)(nbh->b_data); 1797 aed = (struct allocExtDesc *)(nbh->b_data);
1770 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 1798 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1771 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); 1799 aed->previousAllocExtLocation =
1772 if (epos->offset + adsize > inode->i_sb->s_blocksize) 1800 cpu_to_le32(obloc.logicalBlockNum);
1773 { 1801 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1774 loffset = epos->offset; 1802 loffset = epos->offset;
1775 aed->lengthAllocDescs = cpu_to_le32(adsize); 1803 aed->lengthAllocDescs = cpu_to_le32(adsize);
1776 sptr = ptr - adsize; 1804 sptr = ptr - adsize;
1777 dptr = nbh->b_data + sizeof(struct allocExtDesc); 1805 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1778 memcpy(dptr, sptr, adsize); 1806 memcpy(dptr, sptr, adsize);
1779 epos->offset = sizeof(struct allocExtDesc) + adsize; 1807 epos->offset = sizeof(struct allocExtDesc) + adsize;
1780 } 1808 } else {
1781 else
1782 {
1783 loffset = epos->offset + adsize; 1809 loffset = epos->offset + adsize;
1784 aed->lengthAllocDescs = cpu_to_le32(0); 1810 aed->lengthAllocDescs = cpu_to_le32(0);
1785 sptr = ptr; 1811 sptr = ptr;
1786 epos->offset = sizeof(struct allocExtDesc); 1812 epos->offset = sizeof(struct allocExtDesc);
1787 1813
1788 if (epos->bh) 1814 if (epos->bh) {
1789 {
1790 aed = (struct allocExtDesc *)epos->bh->b_data; 1815 aed = (struct allocExtDesc *)epos->bh->b_data;
1791 aed->lengthAllocDescs = 1816 aed->lengthAllocDescs =
1792 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1817 cpu_to_le32(le32_to_cpu
1793 } 1818 (aed->lengthAllocDescs) +
1794 else 1819 adsize);
1795 { 1820 } else {
1796 UDF_I_LENALLOC(inode) += adsize; 1821 UDF_I_LENALLOC(inode) += adsize;
1797 mark_inode_dirty(inode); 1822 mark_inode_dirty(inode);
1798 } 1823 }
1799 } 1824 }
1800 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1825 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
1801 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, 1826 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1802 epos->block.logicalBlockNum, sizeof(tag)); 1827 epos->block.logicalBlockNum, sizeof(tag));
1803 else 1828 else
1804 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, 1829 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1805 epos->block.logicalBlockNum, sizeof(tag)); 1830 epos->block.logicalBlockNum, sizeof(tag));
1806 switch (UDF_I_ALLOCTYPE(inode)) 1831 switch (UDF_I_ALLOCTYPE(inode)) {
1807 { 1832 case ICBTAG_FLAG_AD_SHORT:
1808 case ICBTAG_FLAG_AD_SHORT:
1809 { 1833 {
1810 sad = (short_ad *)sptr; 1834 sad = (short_ad *) sptr;
1811 sad->extLength = cpu_to_le32( 1835 sad->extLength =
1812 EXT_NEXT_EXTENT_ALLOCDECS | 1836 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1813 inode->i_sb->s_blocksize); 1837 inode->i_sb->s_blocksize);
1814 sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); 1838 sad->extPosition =
1839 cpu_to_le32(epos->block.logicalBlockNum);
1815 break; 1840 break;
1816 } 1841 }
1817 case ICBTAG_FLAG_AD_LONG: 1842 case ICBTAG_FLAG_AD_LONG:
1818 { 1843 {
1819 lad = (long_ad *)sptr; 1844 lad = (long_ad *) sptr;
1820 lad->extLength = cpu_to_le32( 1845 lad->extLength =
1821 EXT_NEXT_EXTENT_ALLOCDECS | 1846 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1822 inode->i_sb->s_blocksize); 1847 inode->i_sb->s_blocksize);
1823 lad->extLocation = cpu_to_lelb(epos->block); 1848 lad->extLocation = cpu_to_lelb(epos->block);
1824 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1849 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1825 break; 1850 break;
1826 } 1851 }
1827 } 1852 }
1828 if (epos->bh) 1853 if (epos->bh) {
1829 { 1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1830 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1855 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1831 udf_update_tag(epos->bh->b_data, loffset); 1856 udf_update_tag(epos->bh->b_data, loffset);
1832 else 1857 else
1833 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); 1858 udf_update_tag(epos->bh->b_data,
1859 sizeof(struct allocExtDesc));
1834 mark_buffer_dirty_inode(epos->bh, inode); 1860 mark_buffer_dirty_inode(epos->bh, inode);
1835 brelse(epos->bh); 1861 brelse(epos->bh);
1836 } 1862 } else
1837 else
1838 mark_inode_dirty(inode); 1863 mark_inode_dirty(inode);
1839 epos->bh = nbh; 1864 epos->bh = nbh;
1840 } 1865 }
1841 1866
1842 etype = udf_write_aext(inode, epos, eloc, elen, inc); 1867 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1843 1868
1844 if (!epos->bh) 1869 if (!epos->bh) {
1845 {
1846 UDF_I_LENALLOC(inode) += adsize; 1870 UDF_I_LENALLOC(inode) += adsize;
1847 mark_inode_dirty(inode); 1871 mark_inode_dirty(inode);
1848 } 1872 } else {
1849 else
1850 {
1851 aed = (struct allocExtDesc *)epos->bh->b_data; 1873 aed = (struct allocExtDesc *)epos->bh->b_data;
1852 aed->lengthAllocDescs = 1874 aed->lengthAllocDescs =
1853 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1875 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1876 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1855 udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize)); 1877 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1878 udf_update_tag(epos->bh->b_data,
1879 epos->offset + (inc ? 0 : adsize));
1856 else 1880 else
1857 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); 1881 udf_update_tag(epos->bh->b_data,
1882 sizeof(struct allocExtDesc));
1858 mark_buffer_dirty_inode(epos->bh, inode); 1883 mark_buffer_dirty_inode(epos->bh, inode);
1859 } 1884 }
1860 1885
1861 return etype; 1886 return etype;
1862} 1887}
1863 1888
1864int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, 1889int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
1865 kernel_lb_addr eloc, uint32_t elen, int inc) 1890 kernel_lb_addr eloc, uint32_t elen, int inc)
1866{ 1891{
1867 int adsize; 1892 int adsize;
1868 uint8_t *ptr; 1893 uint8_t *ptr;
1869 1894
1870 if (!epos->bh) 1895 if (!epos->bh)
1871 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1896 ptr =
1897 UDF_I_DATA(inode) + epos->offset -
1898 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1872 else 1899 else
1873 ptr = epos->bh->b_data + epos->offset; 1900 ptr = epos->bh->b_data + epos->offset;
1874 1901
1875 switch (UDF_I_ALLOCTYPE(inode)) 1902 switch (UDF_I_ALLOCTYPE(inode)) {
1876 { 1903 case ICBTAG_FLAG_AD_SHORT:
1877 case ICBTAG_FLAG_AD_SHORT:
1878 { 1904 {
1879 short_ad *sad = (short_ad *)ptr; 1905 short_ad *sad = (short_ad *) ptr;
1880 sad->extLength = cpu_to_le32(elen); 1906 sad->extLength = cpu_to_le32(elen);
1881 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum); 1907 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1882 adsize = sizeof(short_ad); 1908 adsize = sizeof(short_ad);
1883 break; 1909 break;
1884 } 1910 }
1885 case ICBTAG_FLAG_AD_LONG: 1911 case ICBTAG_FLAG_AD_LONG:
1886 { 1912 {
1887 long_ad *lad = (long_ad *)ptr; 1913 long_ad *lad = (long_ad *) ptr;
1888 lad->extLength = cpu_to_le32(elen); 1914 lad->extLength = cpu_to_le32(elen);
1889 lad->extLocation = cpu_to_lelb(eloc); 1915 lad->extLocation = cpu_to_lelb(eloc);
1890 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1916 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1891 adsize = sizeof(long_ad); 1917 adsize = sizeof(long_ad);
1892 break; 1918 break;
1893 } 1919 }
1894 default: 1920 default:
1895 return -1; 1921 return -1;
1896 } 1922 }
1897 1923
1898 if (epos->bh) 1924 if (epos->bh) {
1899 { 1925 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1900 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1926 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
1901 { 1927 struct allocExtDesc *aed =
1902 struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; 1928 (struct allocExtDesc *)epos->bh->b_data;
1903 udf_update_tag(epos->bh->b_data, 1929 udf_update_tag(epos->bh->b_data,
1904 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); 1930 le32_to_cpu(aed->lengthAllocDescs) +
1931 sizeof(struct allocExtDesc));
1905 } 1932 }
1906 mark_buffer_dirty_inode(epos->bh, inode); 1933 mark_buffer_dirty_inode(epos->bh, inode);
1907 } 1934 } else
1908 else
1909 mark_inode_dirty(inode); 1935 mark_inode_dirty(inode);
1910 1936
1911 if (inc) 1937 if (inc)
@@ -1913,21 +1939,24 @@ int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
1913 return (elen >> 30); 1939 return (elen >> 30);
1914} 1940}
1915 1941
1916int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, 1942int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
1917 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1943 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1918{ 1944{
1919 int8_t etype; 1945 int8_t etype;
1920 1946
1921 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == 1947 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1922 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) 1948 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1923 {
1924 epos->block = *eloc; 1949 epos->block = *eloc;
1925 epos->offset = sizeof(struct allocExtDesc); 1950 epos->offset = sizeof(struct allocExtDesc);
1926 brelse(epos->bh); 1951 brelse(epos->bh);
1927 if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) 1952 if (!
1928 { 1953 (epos->bh =
1954 udf_tread(inode->i_sb,
1955 udf_get_lb_pblock(inode->i_sb, epos->block,
1956 0)))) {
1929 udf_debug("reading block %d failed!\n", 1957 udf_debug("reading block %d failed!\n",
1930 udf_get_lb_pblock(inode->i_sb, epos->block, 0)); 1958 udf_get_lb_pblock(inode->i_sb, epos->block,
1959 0));
1931 return -1; 1960 return -1;
1932 } 1961 }
1933 } 1962 }
@@ -1935,58 +1964,71 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1935 return etype; 1964 return etype;
1936} 1965}
1937 1966
1938int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, 1967int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
1939 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1968 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1940{ 1969{
1941 int alen; 1970 int alen;
1942 int8_t etype; 1971 int8_t etype;
1943 uint8_t *ptr; 1972 uint8_t *ptr;
1944 1973
1945 if (!epos->bh) 1974 if (!epos->bh) {
1946 {
1947 if (!epos->offset) 1975 if (!epos->offset)
1948 epos->offset = udf_file_entry_alloc_offset(inode); 1976 epos->offset = udf_file_entry_alloc_offset(inode);
1949 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1977 ptr =
1950 alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); 1978 UDF_I_DATA(inode) + epos->offset -
1951 } 1979 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1952 else 1980 alen =
1953 { 1981 udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1982 } else {
1954 if (!epos->offset) 1983 if (!epos->offset)
1955 epos->offset = sizeof(struct allocExtDesc); 1984 epos->offset = sizeof(struct allocExtDesc);
1956 ptr = epos->bh->b_data + epos->offset; 1985 ptr = epos->bh->b_data + epos->offset;
1957 alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); 1986 alen =
1987 sizeof(struct allocExtDesc) +
1988 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1989 lengthAllocDescs);
1958 } 1990 }
1959 1991
1960 switch (UDF_I_ALLOCTYPE(inode)) 1992 switch (UDF_I_ALLOCTYPE(inode)) {
1961 { 1993 case ICBTAG_FLAG_AD_SHORT:
1962 case ICBTAG_FLAG_AD_SHORT:
1963 { 1994 {
1964 short_ad *sad; 1995 short_ad *sad;
1965 1996
1966 if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc))) 1997 if (!
1998 (sad =
1999 udf_get_fileshortad(ptr, alen, &epos->offset,
2000 inc)))
1967 return -1; 2001 return -1;
1968 2002
1969 etype = le32_to_cpu(sad->extLength) >> 30; 2003 etype = le32_to_cpu(sad->extLength) >> 30;
1970 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); 2004 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1971 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 2005 eloc->partitionReferenceNum =
1972 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; 2006 UDF_I_LOCATION(inode).partitionReferenceNum;
2007 *elen =
2008 le32_to_cpu(sad->
2009 extLength) & UDF_EXTENT_LENGTH_MASK;
1973 break; 2010 break;
1974 } 2011 }
1975 case ICBTAG_FLAG_AD_LONG: 2012 case ICBTAG_FLAG_AD_LONG:
1976 { 2013 {
1977 long_ad *lad; 2014 long_ad *lad;
1978 2015
1979 if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc))) 2016 if (!
2017 (lad =
2018 udf_get_filelongad(ptr, alen, &epos->offset, inc)))
1980 return -1; 2019 return -1;
1981 2020
1982 etype = le32_to_cpu(lad->extLength) >> 30; 2021 etype = le32_to_cpu(lad->extLength) >> 30;
1983 *eloc = lelb_to_cpu(lad->extLocation); 2022 *eloc = lelb_to_cpu(lad->extLocation);
1984 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; 2023 *elen =
2024 le32_to_cpu(lad->
2025 extLength) & UDF_EXTENT_LENGTH_MASK;
1985 break; 2026 break;
1986 } 2027 }
1987 default: 2028 default:
1988 { 2029 {
1989 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode)); 2030 udf_debug("alloc_type = %d unsupported\n",
2031 UDF_I_ALLOCTYPE(inode));
1990 return -1; 2032 return -1;
1991 } 2033 }
1992 } 2034 }
@@ -2005,8 +2047,7 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
2005 if (epos.bh) 2047 if (epos.bh)
2006 get_bh(epos.bh); 2048 get_bh(epos.bh);
2007 2049
2008 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) 2050 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
2009 {
2010 udf_write_aext(inode, &epos, neloc, nelen, 1); 2051 udf_write_aext(inode, &epos, neloc, nelen, 1);
2011 2052
2012 neloc = oeloc; 2053 neloc = oeloc;
@@ -2017,16 +2058,15 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
2017 return (nelen >> 30); 2058 return (nelen >> 30);
2018} 2059}
2019 2060
2020int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, 2061int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
2021 kernel_lb_addr eloc, uint32_t elen) 2062 kernel_lb_addr eloc, uint32_t elen)
2022{ 2063{
2023 struct extent_position oepos; 2064 struct extent_position oepos;
2024 int adsize; 2065 int adsize;
2025 int8_t etype; 2066 int8_t etype;
2026 struct allocExtDesc *aed; 2067 struct allocExtDesc *aed;
2027 2068
2028 if (epos.bh) 2069 if (epos.bh) {
2029 {
2030 get_bh(epos.bh); 2070 get_bh(epos.bh);
2031 get_bh(epos.bh); 2071 get_bh(epos.bh);
2032 } 2072 }
@@ -2042,11 +2082,9 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2042 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1) 2082 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2043 return -1; 2083 return -1;
2044 2084
2045 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) 2085 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2046 {
2047 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1); 2086 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2048 if (oepos.bh != epos.bh) 2087 if (oepos.bh != epos.bh) {
2049 {
2050 oepos.block = epos.block; 2088 oepos.block = epos.block;
2051 brelse(oepos.bh); 2089 brelse(oepos.bh);
2052 get_bh(epos.bh); 2090 get_bh(epos.bh);
@@ -2057,45 +2095,44 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2057 memset(&eloc, 0x00, sizeof(kernel_lb_addr)); 2095 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2058 elen = 0; 2096 elen = 0;
2059 2097
2060 if (epos.bh != oepos.bh) 2098 if (epos.bh != oepos.bh) {
2061 {
2062 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1); 2099 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2063 udf_write_aext(inode, &oepos, eloc, elen, 1); 2100 udf_write_aext(inode, &oepos, eloc, elen, 1);
2064 udf_write_aext(inode, &oepos, eloc, elen, 1); 2101 udf_write_aext(inode, &oepos, eloc, elen, 1);
2065 if (!oepos.bh) 2102 if (!oepos.bh) {
2066 {
2067 UDF_I_LENALLOC(inode) -= (adsize * 2); 2103 UDF_I_LENALLOC(inode) -= (adsize * 2);
2068 mark_inode_dirty(inode); 2104 mark_inode_dirty(inode);
2069 } 2105 } else {
2070 else
2071 {
2072 aed = (struct allocExtDesc *)oepos.bh->b_data; 2106 aed = (struct allocExtDesc *)oepos.bh->b_data;
2073 aed->lengthAllocDescs = 2107 aed->lengthAllocDescs =
2074 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize)); 2108 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2075 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 2109 (2 * adsize));
2076 udf_update_tag(oepos.bh->b_data, oepos.offset - (2*adsize)); 2110 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2111 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2112 udf_update_tag(oepos.bh->b_data,
2113 oepos.offset - (2 * adsize));
2077 else 2114 else
2078 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 2115 udf_update_tag(oepos.bh->b_data,
2116 sizeof(struct allocExtDesc));
2079 mark_buffer_dirty_inode(oepos.bh, inode); 2117 mark_buffer_dirty_inode(oepos.bh, inode);
2080 } 2118 }
2081 } 2119 } else {
2082 else
2083 {
2084 udf_write_aext(inode, &oepos, eloc, elen, 1); 2120 udf_write_aext(inode, &oepos, eloc, elen, 1);
2085 if (!oepos.bh) 2121 if (!oepos.bh) {
2086 {
2087 UDF_I_LENALLOC(inode) -= adsize; 2122 UDF_I_LENALLOC(inode) -= adsize;
2088 mark_inode_dirty(inode); 2123 mark_inode_dirty(inode);
2089 } 2124 } else {
2090 else
2091 {
2092 aed = (struct allocExtDesc *)oepos.bh->b_data; 2125 aed = (struct allocExtDesc *)oepos.bh->b_data;
2093 aed->lengthAllocDescs = 2126 aed->lengthAllocDescs =
2094 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); 2127 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2095 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 2128 adsize);
2096 udf_update_tag(oepos.bh->b_data, epos.offset - adsize); 2129 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2130 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2131 udf_update_tag(oepos.bh->b_data,
2132 epos.offset - adsize);
2097 else 2133 else
2098 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 2134 udf_update_tag(oepos.bh->b_data,
2135 sizeof(struct allocExtDesc));
2099 mark_buffer_dirty_inode(oepos.bh, inode); 2136 mark_buffer_dirty_inode(oepos.bh, inode);
2100 } 2137 }
2101 } 2138 }
@@ -2105,14 +2142,15 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2105 return (elen >> 30); 2142 return (elen >> 30);
2106} 2143}
2107 2144
2108int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *pos, 2145int8_t inode_bmap(struct inode * inode, sector_t block,
2109 kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset) 2146 struct extent_position * pos, kernel_lb_addr * eloc,
2147 uint32_t * elen, sector_t * offset)
2110{ 2148{
2111 loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits; 2149 loff_t lbcount = 0, bcount =
2150 (loff_t) block << inode->i_sb->s_blocksize_bits;
2112 int8_t etype; 2151 int8_t etype;
2113 2152
2114 if (block < 0) 2153 if (block < 0) {
2115 {
2116 printk(KERN_ERR "udf: inode_bmap: block < 0\n"); 2154 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2117 return -1; 2155 return -1;
2118 } 2156 }
@@ -2122,11 +2160,10 @@ int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *p
2122 pos->bh = NULL; 2160 pos->bh = NULL;
2123 *elen = 0; 2161 *elen = 0;
2124 2162
2125 do 2163 do {
2126 { 2164 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
2127 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) 2165 *offset =
2128 { 2166 (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2129 *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2130 UDF_I_LENEXTENTS(inode) = lbcount; 2167 UDF_I_LENEXTENTS(inode) = lbcount;
2131 return -1; 2168 return -1;
2132 } 2169 }
@@ -2143,12 +2180,13 @@ long udf_block_map(struct inode *inode, sector_t block)
2143 kernel_lb_addr eloc; 2180 kernel_lb_addr eloc;
2144 uint32_t elen; 2181 uint32_t elen;
2145 sector_t offset; 2182 sector_t offset;
2146 struct extent_position epos = { NULL, 0, { 0, 0}}; 2183 struct extent_position epos = { NULL, 0, {0, 0} };
2147 int ret; 2184 int ret;
2148 2185
2149 lock_kernel(); 2186 lock_kernel();
2150 2187
2151 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 2188 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2189 (EXT_RECORDED_ALLOCATED >> 30))
2152 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); 2190 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2153 else 2191 else
2154 ret = 0; 2192 ret = 0;
diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c
index 084216107667..4826c3616eef 100644
--- a/fs/udf/lowlevel.c
+++ b/fs/udf/lowlevel.c
@@ -26,43 +26,38 @@
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;
64 59
65 if (ioctl_by_bdev(bdev, CDROM_LAST_WRITTEN, (unsigned long) &lblock)) 60 if (ioctl_by_bdev(bdev, CDROM_LAST_WRITTEN, (unsigned long)&lblock))
66 lblock = bdev->bd_inode->i_size >> sb->s_blocksize_bits; 61 lblock = bdev->bd_inode->i_size >> sb->s_blocksize_bits;
67 62
68 if (lblock) 63 if (lblock)
diff --git a/fs/udf/misc.c b/fs/udf/misc.c
index a2b2a98ce78a..a7f57277a96e 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;
@@ -59,78 +56,76 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
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 }
67 63
68 offset = inode->i_sb->s_blocksize - udf_file_entry_alloc_offset(inode) - 64 offset = inode->i_sb->s_blocksize - udf_file_entry_alloc_offset(inode) -
69 UDF_I_LENALLOC(inode); 65 UDF_I_LENALLOC(inode);
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) !=
87 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) 80 TAG_IDENT_EAHD
88 { 81 || le32_to_cpu(eahd->descTag.tagLocation) !=
82 UDF_I_LOCATION(inode).logicalBlockNum) {
89 return NULL; 83 return NULL;
90 } 84 }
91 } 85 } else {
92 else
93 {
94 size -= sizeof(struct extendedAttrHeaderDesc); 86 size -= sizeof(struct extendedAttrHeaderDesc);
95 UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); 87 UDF_I_LENEATTR(inode) +=
88 sizeof(struct extendedAttrHeaderDesc);
96 eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); 89 eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
97 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 90 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
98 eahd->descTag.descVersion = cpu_to_le16(3); 91 eahd->descTag.descVersion = cpu_to_le16(3);
99 else 92 else
100 eahd->descTag.descVersion = cpu_to_le16(2); 93 eahd->descTag.descVersion = cpu_to_le16(2);
101 eahd->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); 94 eahd->descTag.tagSerialNum =
102 eahd->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 95 cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
96 eahd->descTag.tagLocation =
97 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
103 eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); 98 eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF);
104 eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); 99 eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF);
105 } 100 }
106 101
107 offset = UDF_I_LENEATTR(inode); 102 offset = UDF_I_LENEATTR(inode);
108 if (type < 2048) 103 if (type < 2048) {
109 { 104 if (le32_to_cpu(eahd->appAttrLocation) <
110 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) 105 UDF_I_LENEATTR(inode)) {
111 { 106 uint32_t aal =
112 uint32_t aal = le32_to_cpu(eahd->appAttrLocation); 107 le32_to_cpu(eahd->appAttrLocation);
113 memmove(&ea[offset - aal + size], 108 memmove(&ea[offset - aal + size], &ea[aal],
114 &ea[aal], offset - aal); 109 offset - aal);
115 offset -= aal; 110 offset -= aal;
116 eahd->appAttrLocation = cpu_to_le32(aal + size); 111 eahd->appAttrLocation = cpu_to_le32(aal + size);
117 } 112 }
118 if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) 113 if (le32_to_cpu(eahd->impAttrLocation) <
119 { 114 UDF_I_LENEATTR(inode)) {
120 uint32_t ial = le32_to_cpu(eahd->impAttrLocation); 115 uint32_t ial =
121 memmove(&ea[offset - ial + size], 116 le32_to_cpu(eahd->impAttrLocation);
122 &ea[ial], offset - ial); 117 memmove(&ea[offset - ial + size], &ea[ial],
118 offset - ial);
123 offset -= ial; 119 offset -= ial;
124 eahd->impAttrLocation = cpu_to_le32(ial + size); 120 eahd->impAttrLocation = cpu_to_le32(ial + size);
125 } 121 }
126 } 122 } else if (type < 65536) {
127 else if (type < 65536) 123 if (le32_to_cpu(eahd->appAttrLocation) <
128 { 124 UDF_I_LENEATTR(inode)) {
129 if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) 125 uint32_t aal =
130 { 126 le32_to_cpu(eahd->appAttrLocation);
131 uint32_t aal = le32_to_cpu(eahd->appAttrLocation); 127 memmove(&ea[offset - aal + size], &ea[aal],
132 memmove(&ea[offset - aal + size], 128 offset - aal);
133 &ea[aal], offset - aal);
134 offset -= aal; 129 offset -= aal;
135 eahd->appAttrLocation = cpu_to_le32(aal + size); 130 eahd->appAttrLocation = cpu_to_le32(aal + size);
136 } 131 }
@@ -138,22 +133,23 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
138 /* rewrite CRC + checksum of eahd */ 133 /* rewrite CRC + checksum of eahd */
139 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); 134 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
140 eahd->descTag.descCRCLength = cpu_to_le16(crclen); 135 eahd->descTag.descCRCLength = cpu_to_le16(crclen);
141 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + sizeof(tag), crclen, 0)); 136 eahd->descTag.descCRC =
137 cpu_to_le16(udf_crc((char *)eahd + sizeof(tag), crclen, 0));
142 eahd->descTag.tagChecksum = 0; 138 eahd->descTag.tagChecksum = 0;
143 for (i=0; i<16; i++) 139 for (i = 0; i < 16; i++)
144 if (i != 4) 140 if (i != 4)
145 eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; 141 eahd->descTag.tagChecksum +=
142 ((uint8_t *) & (eahd->descTag))[i];
146 UDF_I_LENEATTR(inode) += size; 143 UDF_I_LENEATTR(inode) += size;
147 return (struct genericFormat *)&ea[offset]; 144 return (struct genericFormat *)&ea[offset];
148 } 145 }
149 if (loc & 0x02) 146 if (loc & 0x02) {
150 {
151 } 147 }
152 return NULL; 148 return NULL;
153} 149}
154 150
155struct genericFormat * 151struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
156udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype) 152 uint8_t subtype)
157{ 153{
158 struct genericFormat *gaf; 154 struct genericFormat *gaf;
159 uint8_t *ea = NULL; 155 uint8_t *ea = NULL;
@@ -161,18 +157,17 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
161 157
162 ea = UDF_I_DATA(inode); 158 ea = UDF_I_DATA(inode);
163 159
164 if (UDF_I_LENEATTR(inode)) 160 if (UDF_I_LENEATTR(inode)) {
165 {
166 struct extendedAttrHeaderDesc *eahd; 161 struct extendedAttrHeaderDesc *eahd;
167 eahd = (struct extendedAttrHeaderDesc *)ea; 162 eahd = (struct extendedAttrHeaderDesc *)ea;
168 163
169 /* check checksum/crc */ 164 /* check checksum/crc */
170 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || 165 if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
171 le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) 166 le32_to_cpu(eahd->descTag.tagLocation) !=
172 { 167 UDF_I_LOCATION(inode).logicalBlockNum) {
173 return NULL; 168 return NULL;
174 } 169 }
175 170
176 if (type < 2048) 171 if (type < 2048)
177 offset = sizeof(struct extendedAttrHeaderDesc); 172 offset = sizeof(struct extendedAttrHeaderDesc);
178 else if (type < 65536) 173 else if (type < 65536)
@@ -180,10 +175,10 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
180 else 175 else
181 offset = le32_to_cpu(eahd->appAttrLocation); 176 offset = le32_to_cpu(eahd->appAttrLocation);
182 177
183 while (offset < UDF_I_LENEATTR(inode)) 178 while (offset < UDF_I_LENEATTR(inode)) {
184 {
185 gaf = (struct genericFormat *)&ea[offset]; 179 gaf = (struct genericFormat *)&ea[offset];
186 if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) 180 if (le32_to_cpu(gaf->attrType) == type
181 && gaf->attrSubtype == subtype)
187 return gaf; 182 return gaf;
188 else 183 else
189 offset += le32_to_cpu(gaf->attrLength); 184 offset += le32_to_cpu(gaf->attrLength);
@@ -202,8 +197,8 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
202 * July 1, 1997 - Andrew E. Mileski 197 * July 1, 1997 - Andrew E. Mileski
203 * Written, tested, and released. 198 * Written, tested, and released.
204 */ 199 */
205struct buffer_head * 200struct 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) 201 uint32_t location, uint16_t * ident)
207{ 202{
208 tag *tag_p; 203 tag *tag_p;
209 struct buffer_head *bh = NULL; 204 struct buffer_head *bh = NULL;
@@ -215,29 +210,29 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
215 return NULL; 210 return NULL;
216 211
217 bh = udf_tread(sb, block + UDF_SB_SESSION(sb)); 212 bh = udf_tread(sb, block + UDF_SB_SESSION(sb));
218 if (!bh) 213 if (!bh) {
219 { 214 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); 215 block + UDF_SB_SESSION(sb), location);
221 return NULL; 216 return NULL;
222 } 217 }
223 218
224 tag_p = (tag *)(bh->b_data); 219 tag_p = (tag *) (bh->b_data);
225 220
226 *ident = le16_to_cpu(tag_p->tagIdent); 221 *ident = le16_to_cpu(tag_p->tagIdent);
227 222
228 if ( location != le32_to_cpu(tag_p->tagLocation) ) 223 if (location != le32_to_cpu(tag_p->tagLocation)) {
229 {
230 udf_debug("location mismatch block %u, tag %u != %u\n", 224 udf_debug("location mismatch block %u, tag %u != %u\n",
231 block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location); 225 block + UDF_SB_SESSION(sb),
226 le32_to_cpu(tag_p->tagLocation), location);
232 goto error_out; 227 goto error_out;
233 } 228 }
234 229
235 /* Verify the tag checksum */ 230 /* Verify the tag checksum */
236 checksum = 0U; 231 checksum = 0U;
237 for (i = 0; i < 4; i++) 232 for (i = 0; i < 4; i++)
238 checksum += (uint8_t)(bh->b_data[i]); 233 checksum += (uint8_t) (bh->b_data[i]);
239 for (i = 5; i < 16; i++) 234 for (i = 5; i < 16; i++)
240 checksum += (uint8_t)(bh->b_data[i]); 235 checksum += (uint8_t) (bh->b_data[i]);
241 if (checksum != tag_p->tagChecksum) { 236 if (checksum != tag_p->tagChecksum) {
242 printk(KERN_ERR "udf: tag checksum failed block %d\n", block); 237 printk(KERN_ERR "udf: tag checksum failed block %d\n", block);
243 goto error_out; 238 goto error_out;
@@ -245,38 +240,39 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
245 240
246 /* Verify the tag version */ 241 /* Verify the tag version */
247 if (le16_to_cpu(tag_p->descVersion) != 0x0002U && 242 if (le16_to_cpu(tag_p->descVersion) != 0x0002U &&
248 le16_to_cpu(tag_p->descVersion) != 0x0003U) 243 le16_to_cpu(tag_p->descVersion) != 0x0003U) {
249 {
250 udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n", 244 udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n",
251 le16_to_cpu(tag_p->descVersion), block); 245 le16_to_cpu(tag_p->descVersion), block);
252 goto error_out; 246 goto error_out;
253 } 247 }
254 248
255 /* Verify the descriptor CRC */ 249 /* Verify the descriptor CRC */
256 if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || 250 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), 251 le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
258 le16_to_cpu(tag_p->descCRCLength), 0)) 252 le16_to_cpu(tag_p->
259 { 253 descCRCLength),
254 0)) {
260 return bh; 255 return bh;
261 } 256 }
262 udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", 257 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)); 258 block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC),
259 le16_to_cpu(tag_p->descCRCLength));
264 260
265error_out: 261 error_out:
266 brelse(bh); 262 brelse(bh);
267 return NULL; 263 return NULL;
268} 264}
269 265
270struct buffer_head * 266struct 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) 267 uint32_t offset, uint16_t * ident)
272{ 268{
273 return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), 269 return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
274 loc.logicalBlockNum + offset, ident); 270 loc.logicalBlockNum + offset, ident);
275} 271}
276 272
277void udf_update_tag(char *data, int length) 273void udf_update_tag(char *data, int length)
278{ 274{
279 tag *tptr = (tag *)data; 275 tag *tptr = (tag *) data;
280 int i; 276 int i;
281 277
282 length -= sizeof(tag); 278 length -= sizeof(tag);
@@ -285,15 +281,15 @@ void udf_update_tag(char *data, int length)
285 tptr->descCRCLength = cpu_to_le16(length); 281 tptr->descCRCLength = cpu_to_le16(length);
286 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); 282 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
287 283
288 for (i=0; i<16; i++) 284 for (i = 0; i < 16; i++)
289 if (i != 4) 285 if (i != 4)
290 tptr->tagChecksum += (uint8_t)(data[i]); 286 tptr->tagChecksum += (uint8_t) (data[i]);
291} 287}
292 288
293void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, 289void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
294 uint32_t loc, int length) 290 uint32_t loc, int length)
295{ 291{
296 tag *tptr = (tag *)data; 292 tag *tptr = (tag *) data;
297 tptr->tagIdent = cpu_to_le16(ident); 293 tptr->tagIdent = cpu_to_le16(ident);
298 tptr->descVersion = cpu_to_le16(version); 294 tptr->descVersion = cpu_to_le16(version);
299 tptr->tagSerialNum = cpu_to_le16(snum); 295 tptr->tagSerialNum = cpu_to_le16(snum);
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 51fe307dc0ec..334d363a0903 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -32,7 +32,8 @@
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,8 +41,8 @@ static inline int udf_match(int len1, const char *name1, int len2, const char *n
40} 41}
41 42
42int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, 43int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
43 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, 44 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
44 uint8_t *impuse, uint8_t *fileident) 45 uint8_t * impuse, uint8_t * fileident)
45{ 46{
46 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); 47 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
47 uint16_t crc; 48 uint16_t crc;
@@ -51,7 +52,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
51 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); 52 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
52 uint8_t lfi = cfi->lengthFileIdent; 53 uint8_t lfi = cfi->lengthFileIdent;
53 int padlen = fibh->eoffset - fibh->soffset - liu - lfi - 54 int padlen = fibh->eoffset - fibh->soffset - liu - lfi -
54 sizeof(struct fileIdentDesc); 55 sizeof(struct fileIdentDesc);
55 int adinicb = 0; 56 int adinicb = 0;
56 57
57 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 58 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
@@ -59,83 +60,86 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
59 60
60 offset = fibh->soffset + sizeof(struct fileIdentDesc); 61 offset = fibh->soffset + sizeof(struct fileIdentDesc);
61 62
62 if (impuse) 63 if (impuse) {
63 {
64 if (adinicb || (offset + liu < 0)) 64 if (adinicb || (offset + liu < 0))
65 memcpy((uint8_t *)sfi->impUse, impuse, liu); 65 memcpy((uint8_t *) sfi->impUse, impuse, liu);
66 else if (offset >= 0) 66 else if (offset >= 0)
67 memcpy(fibh->ebh->b_data + offset, impuse, liu); 67 memcpy(fibh->ebh->b_data + offset, impuse, liu);
68 else 68 else {
69 { 69 memcpy((uint8_t *) sfi->impUse, impuse, -offset);
70 memcpy((uint8_t *)sfi->impUse, impuse, -offset); 70 memcpy(fibh->ebh->b_data, impuse - offset,
71 memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); 71 liu + offset);
72 } 72 }
73 } 73 }
74 74
75 offset += liu; 75 offset += liu;
76 76
77 if (fileident) 77 if (fileident) {
78 {
79 if (adinicb || (offset + lfi < 0)) 78 if (adinicb || (offset + lfi < 0))
80 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); 79 memcpy((uint8_t *) sfi->fileIdent + liu, fileident,
80 lfi);
81 else if (offset >= 0) 81 else if (offset >= 0)
82 memcpy(fibh->ebh->b_data + offset, fileident, lfi); 82 memcpy(fibh->ebh->b_data + offset, fileident, lfi);
83 else 83 else {
84 { 84 memcpy((uint8_t *) sfi->fileIdent + liu, fileident,
85 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); 85 -offset);
86 memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); 86 memcpy(fibh->ebh->b_data, fileident - offset,
87 lfi + offset);
87 } 88 }
88 } 89 }
89 90
90 offset += lfi; 91 offset += lfi;
91 92
92 if (adinicb || (offset + padlen < 0)) 93 if (adinicb || (offset + padlen < 0))
93 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); 94 memset((uint8_t *) sfi->padding + liu + lfi, 0x00, padlen);
94 else if (offset >= 0) 95 else if (offset >= 0)
95 memset(fibh->ebh->b_data + offset, 0x00, padlen); 96 memset(fibh->ebh->b_data + offset, 0x00, padlen);
96 else 97 else {
97 { 98 memset((uint8_t *) sfi->padding + liu + lfi, 0x00, -offset);
98 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
99 memset(fibh->ebh->b_data, 0x00, padlen + offset); 99 memset(fibh->ebh->b_data, 0x00, padlen + offset);
100 } 100 }
101 101
102 crc = udf_crc((uint8_t *)cfi + sizeof(tag), sizeof(struct fileIdentDesc) - 102 crc =
103 sizeof(tag), 0); 103 udf_crc((uint8_t *) cfi + sizeof(tag),
104 sizeof(struct fileIdentDesc) - sizeof(tag), 0);
104 105
105 if (fibh->sbh == fibh->ebh) 106 if (fibh->sbh == fibh->ebh)
106 crc = udf_crc((uint8_t *)sfi->impUse, 107 crc = udf_crc((uint8_t *) sfi->impUse,
107 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 108 crclen + sizeof(tag) -
109 sizeof(struct fileIdentDesc), crc);
108 else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) 110 else if (sizeof(struct fileIdentDesc) >= -fibh->soffset)
109 crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, 111 crc =
110 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 112 udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) +
111 else 113 fibh->soffset,
112 { 114 crclen + sizeof(tag) - sizeof(struct fileIdentDesc),
113 crc = udf_crc((uint8_t *)sfi->impUse, 115 crc);
114 -fibh->soffset - sizeof(struct fileIdentDesc), crc); 116 else {
117 crc = udf_crc((uint8_t *) sfi->impUse,
118 -fibh->soffset - sizeof(struct fileIdentDesc),
119 crc);
115 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); 120 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
116 } 121 }
117 122
118 cfi->descTag.descCRC = cpu_to_le16(crc); 123 cfi->descTag.descCRC = cpu_to_le16(crc);
119 cfi->descTag.descCRCLength = cpu_to_le16(crclen); 124 cfi->descTag.descCRCLength = cpu_to_le16(crclen);
120 125
121 for (i=0; i<16; i++) 126 for (i = 0; i < 16; i++)
122 if (i != 4) 127 if (i != 4)
123 checksum += ((uint8_t *)&cfi->descTag)[i]; 128 checksum += ((uint8_t *) & cfi->descTag)[i];
124 129
125 cfi->descTag.tagChecksum = checksum; 130 cfi->descTag.tagChecksum = checksum;
126 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) 131 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset))
127 memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); 132 memcpy((uint8_t *) sfi, (uint8_t *) cfi,
128 else 133 sizeof(struct fileIdentDesc));
129 { 134 else {
130 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); 135 memcpy((uint8_t *) sfi, (uint8_t *) cfi, -fibh->soffset);
131 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, 136 memcpy(fibh->ebh->b_data, (uint8_t *) cfi - fibh->soffset,
132 sizeof(struct fileIdentDesc) + fibh->soffset); 137 sizeof(struct fileIdentDesc) + fibh->soffset);
133 } 138 }
134 139
135 if (adinicb) 140 if (adinicb)
136 mark_inode_dirty(inode); 141 mark_inode_dirty(inode);
137 else 142 else {
138 {
139 if (fibh->sbh != fibh->ebh) 143 if (fibh->sbh != fibh->ebh)
140 mark_buffer_dirty_inode(fibh->ebh, inode); 144 mark_buffer_dirty_inode(fibh->ebh, inode);
141 mark_buffer_dirty_inode(fibh->sbh, inode); 145 mark_buffer_dirty_inode(fibh->sbh, inode);
@@ -143,12 +147,12 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
143 return 0; 147 return 0;
144} 148}
145 149
146static struct fileIdentDesc * 150static struct fileIdentDesc *udf_find_entry(struct inode *dir,
147udf_find_entry(struct inode *dir, struct dentry *dentry, 151 struct dentry *dentry,
148 struct udf_fileident_bh *fibh, 152 struct udf_fileident_bh *fibh,
149 struct fileIdentDesc *cfi) 153 struct fileIdentDesc *cfi)
150{ 154{
151 struct fileIdentDesc *fi=NULL; 155 struct fileIdentDesc *fi = NULL;
152 loff_t f_pos; 156 loff_t f_pos;
153 int block, flen; 157 int block, flen;
154 char fname[UDF_NAME_LEN]; 158 char fname[UDF_NAME_LEN];
@@ -159,46 +163,41 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
159 kernel_lb_addr eloc; 163 kernel_lb_addr eloc;
160 uint32_t elen; 164 uint32_t elen;
161 sector_t offset; 165 sector_t offset;
162 struct extent_position epos = { NULL, 0, { 0, 0}}; 166 struct extent_position epos = { NULL, 0, {0, 0} };
163 167
164 size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 168 size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
165 f_pos = (udf_ext0_offset(dir) >> 2); 169 f_pos = (udf_ext0_offset(dir) >> 2);
166 170
167 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 171 fibh->soffset = fibh->eoffset =
172 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
168 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 173 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
169 fibh->sbh = fibh->ebh = NULL; 174 fibh->sbh = fibh->ebh = NULL;
170 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 175 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
171 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 176 &epos, &eloc, &elen,
172 { 177 &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
173 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 178 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
174 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 179 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
175 {
176 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 180 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
177 epos.offset -= sizeof(short_ad); 181 epos.offset -= sizeof(short_ad);
178 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 182 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
179 epos.offset -= sizeof(long_ad); 183 epos.offset -= sizeof(long_ad);
180 } 184 } else
181 else
182 offset = 0; 185 offset = 0;
183 186
184 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) 187 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
185 {
186 brelse(epos.bh); 188 brelse(epos.bh);
187 return NULL; 189 return NULL;
188 } 190 }
189 } 191 } else {
190 else
191 {
192 brelse(epos.bh); 192 brelse(epos.bh);
193 return NULL; 193 return NULL;
194 } 194 }
195 195
196 while ( (f_pos < size) ) 196 while ((f_pos < size)) {
197 { 197 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); 198 &elen, &offset);
199 199
200 if (!fi) 200 if (!fi) {
201 {
202 if (fibh->sbh != fibh->ebh) 201 if (fibh->sbh != fibh->ebh)
203 brelse(fibh->ebh); 202 brelse(fibh->ebh);
204 brelse(fibh->sbh); 203 brelse(fibh->sbh);
@@ -209,45 +208,45 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
209 liu = le16_to_cpu(cfi->lengthOfImpUse); 208 liu = le16_to_cpu(cfi->lengthOfImpUse);
210 lfi = cfi->lengthFileIdent; 209 lfi = cfi->lengthFileIdent;
211 210
212 if (fibh->sbh == fibh->ebh) 211 if (fibh->sbh == fibh->ebh) {
213 {
214 nameptr = fi->fileIdent + liu; 212 nameptr = fi->fileIdent + liu;
215 } 213 } else {
216 else
217 {
218 int poffset; /* Unpaded ending offset */ 214 int poffset; /* Unpaded ending offset */
219 215
220 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 216 poffset =
217 fibh->soffset + sizeof(struct fileIdentDesc) + liu +
218 lfi;
221 219
222 if (poffset >= lfi) 220 if (poffset >= lfi)
223 nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); 221 nameptr =
224 else 222 (uint8_t *) (fibh->ebh->b_data + poffset -
225 { 223 lfi);
224 else {
226 nameptr = fname; 225 nameptr = fname;
227 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 226 memcpy(nameptr, fi->fileIdent + liu,
228 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 227 lfi - poffset);
228 memcpy(nameptr + lfi - poffset,
229 fibh->ebh->b_data, poffset);
229 } 230 }
230 } 231 }
231 232
232 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 233 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
233 { 234 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
234 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE) )
235 continue; 235 continue;
236 } 236 }
237 237
238 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0 ) 238 if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
239 { 239 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
240 if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE) )
241 continue; 240 continue;
242 } 241 }
243 242
244 if (!lfi) 243 if (!lfi)
245 continue; 244 continue;
246 245
247 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) 246 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) {
248 { 247 if (udf_match
249 if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) 248 (flen, fname, dentry->d_name.len,
250 { 249 dentry->d_name.name)) {
251 brelse(epos.bh); 250 brelse(epos.bh);
252 return fi; 251 return fi;
253 } 252 }
@@ -293,41 +292,37 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
293 * Written, tested, and released. 292 * Written, tested, and released.
294 */ 293 */
295 294
296static struct dentry * 295static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
297udf_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 296 struct nameidata *nd)
298{ 297{
299 struct inode *inode = NULL; 298 struct inode *inode = NULL;
300 struct fileIdentDesc cfi; 299 struct fileIdentDesc cfi;
301 struct udf_fileident_bh fibh; 300 struct udf_fileident_bh fibh;
302 301
303 if (dentry->d_name.len > UDF_NAME_LEN-2) 302 if (dentry->d_name.len > UDF_NAME_LEN - 2)
304 return ERR_PTR(-ENAMETOOLONG); 303 return ERR_PTR(-ENAMETOOLONG);
305 304
306 lock_kernel(); 305 lock_kernel();
307#ifdef UDF_RECOVERY 306#ifdef UDF_RECOVERY
308 /* temporary shorthand for specifying files by inode number */ 307 /* temporary shorthand for specifying files by inode number */
309 if (!strncmp(dentry->d_name.name, ".B=", 3) ) 308 if (!strncmp(dentry->d_name.name, ".B=", 3)) {
310 { 309 kernel_lb_addr lb =
311 kernel_lb_addr lb = { 0, simple_strtoul(dentry->d_name.name+3, NULL, 0) }; 310 { 0, simple_strtoul(dentry->d_name.name + 3, NULL, 0) };
312 inode = udf_iget(dir->i_sb, lb); 311 inode = udf_iget(dir->i_sb, lb);
313 if (!inode) 312 if (!inode) {
314 {
315 unlock_kernel(); 313 unlock_kernel();
316 return ERR_PTR(-EACCES); 314 return ERR_PTR(-EACCES);
317 } 315 }
318 } 316 } else
319 else 317#endif /* UDF_RECOVERY */
320#endif /* UDF_RECOVERY */
321 318
322 if (udf_find_entry(dir, dentry, &fibh, &cfi)) 319 if (udf_find_entry(dir, dentry, &fibh, &cfi)) {
323 {
324 if (fibh.sbh != fibh.ebh) 320 if (fibh.sbh != fibh.ebh)
325 brelse(fibh.ebh); 321 brelse(fibh.ebh);
326 brelse(fibh.sbh); 322 brelse(fibh.sbh);
327 323
328 inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation)); 324 inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation));
329 if ( !inode ) 325 if (!inode) {
330 {
331 unlock_kernel(); 326 unlock_kernel();
332 return ERR_PTR(-EACCES); 327 return ERR_PTR(-EACCES);
333 } 328 }
@@ -337,13 +332,13 @@ udf_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
337 return NULL; 332 return NULL;
338} 333}
339 334
340static struct fileIdentDesc * 335static struct fileIdentDesc *udf_add_entry(struct inode *dir,
341udf_add_entry(struct inode *dir, struct dentry *dentry, 336 struct dentry *dentry,
342 struct udf_fileident_bh *fibh, 337 struct udf_fileident_bh *fibh,
343 struct fileIdentDesc *cfi, int *err) 338 struct fileIdentDesc *cfi, int *err)
344{ 339{
345 struct super_block *sb; 340 struct super_block *sb;
346 struct fileIdentDesc *fi=NULL; 341 struct fileIdentDesc *fi = NULL;
347 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; 342 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN];
348 int namelen; 343 int namelen;
349 loff_t f_pos; 344 loff_t f_pos;
@@ -357,50 +352,47 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
357 kernel_lb_addr eloc; 352 kernel_lb_addr eloc;
358 uint32_t elen; 353 uint32_t elen;
359 sector_t offset; 354 sector_t offset;
360 struct extent_position epos = { NULL, 0, { 0, 0 }}; 355 struct extent_position epos = { NULL, 0, {0, 0} };
361 356
362 sb = dir->i_sb; 357 sb = dir->i_sb;
363 358
364 if (dentry) 359 if (dentry) {
365 { 360 if (!dentry->d_name.len) {
366 if (!dentry->d_name.len)
367 {
368 *err = -EINVAL; 361 *err = -EINVAL;
369 return NULL; 362 return NULL;
370 } 363 }
371 364
372 if ( !(namelen = udf_put_filename(sb, dentry->d_name.name, name, dentry->d_name.len))) 365 if (!
373 { 366 (namelen =
367 udf_put_filename(sb, dentry->d_name.name, name,
368 dentry->d_name.len))) {
374 *err = -ENAMETOOLONG; 369 *err = -ENAMETOOLONG;
375 return NULL; 370 return NULL;
376 } 371 }
377 } 372 } else
378 else
379 namelen = 0; 373 namelen = 0;
380 374
381 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; 375 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
382 376
383 f_pos = (udf_ext0_offset(dir) >> 2); 377 f_pos = (udf_ext0_offset(dir) >> 2);
384 378
385 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 379 fibh->soffset = fibh->eoffset =
380 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
386 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 381 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
387 fibh->sbh = fibh->ebh = NULL; 382 fibh->sbh = fibh->ebh = NULL;
388 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 383 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
389 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 384 &epos, &eloc, &elen,
390 { 385 &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
391 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 386 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
392 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 387 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
393 {
394 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 388 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
395 epos.offset -= sizeof(short_ad); 389 epos.offset -= sizeof(short_ad);
396 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 390 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
397 epos.offset -= sizeof(long_ad); 391 epos.offset -= sizeof(long_ad);
398 } 392 } else
399 else
400 offset = 0; 393 offset = 0;
401 394
402 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) 395 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
403 {
404 brelse(epos.bh); 396 brelse(epos.bh);
405 *err = -EIO; 397 *err = -EIO;
406 return NULL; 398 return NULL;
@@ -408,21 +400,18 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
408 400
409 block = UDF_I_LOCATION(dir).logicalBlockNum; 401 block = UDF_I_LOCATION(dir).logicalBlockNum;
410 402
411 } 403 } else {
412 else
413 {
414 block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0); 404 block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0);
415 fibh->sbh = fibh->ebh = NULL; 405 fibh->sbh = fibh->ebh = NULL;
416 fibh->soffset = fibh->eoffset = sb->s_blocksize; 406 fibh->soffset = fibh->eoffset = sb->s_blocksize;
417 goto add; 407 goto add;
418 } 408 }
419 409
420 while ( (f_pos < size) ) 410 while ((f_pos < size)) {
421 { 411 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); 412 &elen, &offset);
423 413
424 if (!fi) 414 if (!fi) {
425 {
426 if (fibh->sbh != fibh->ebh) 415 if (fibh->sbh != fibh->ebh)
427 brelse(fibh->ebh); 416 brelse(fibh->ebh);
428 brelse(fibh->sbh); 417 brelse(fibh->sbh);
@@ -436,36 +425,38 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
436 425
437 if (fibh->sbh == fibh->ebh) 426 if (fibh->sbh == fibh->ebh)
438 nameptr = fi->fileIdent + liu; 427 nameptr = fi->fileIdent + liu;
439 else 428 else {
440 {
441 int poffset; /* Unpaded ending offset */ 429 int poffset; /* Unpaded ending offset */
442 430
443 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 431 poffset =
432 fibh->soffset + sizeof(struct fileIdentDesc) + liu +
433 lfi;
444 434
445 if (poffset >= lfi) 435 if (poffset >= lfi)
446 nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); 436 nameptr =
447 else 437 (char *)(fibh->ebh->b_data + poffset - lfi);
448 { 438 else {
449 nameptr = fname; 439 nameptr = fname;
450 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 440 memcpy(nameptr, fi->fileIdent + liu,
451 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 441 lfi - poffset);
442 memcpy(nameptr + lfi - poffset,
443 fibh->ebh->b_data, poffset);
452 } 444 }
453 } 445 }
454 446
455 if ( (cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) 447 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
456 { 448 if (((sizeof(struct fileIdentDesc) + liu + lfi +
457 if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) 449 3) & ~3) == nfidlen) {
458 {
459 brelse(epos.bh); 450 brelse(epos.bh);
460 cfi->descTag.tagSerialNum = cpu_to_le16(1); 451 cfi->descTag.tagSerialNum = cpu_to_le16(1);
461 cfi->fileVersionNum = cpu_to_le16(1); 452 cfi->fileVersionNum = cpu_to_le16(1);
462 cfi->fileCharacteristics = 0; 453 cfi->fileCharacteristics = 0;
463 cfi->lengthFileIdent = namelen; 454 cfi->lengthFileIdent = namelen;
464 cfi->lengthOfImpUse = cpu_to_le16(0); 455 cfi->lengthOfImpUse = cpu_to_le16(0);
465 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) 456 if (!udf_write_fi
457 (dir, cfi, fi, fibh, NULL, name))
466 return fi; 458 return fi;
467 else 459 else {
468 {
469 *err = -EIO; 460 *err = -EIO;
470 return NULL; 461 return NULL;
471 } 462 }
@@ -476,8 +467,8 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
476 continue; 467 continue;
477 468
478 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && 469 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) &&
479 udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) 470 udf_match(flen, fname, dentry->d_name.len,
480 { 471 dentry->d_name.name)) {
481 if (fibh->sbh != fibh->ebh) 472 if (fibh->sbh != fibh->ebh)
482 brelse(fibh->ebh); 473 brelse(fibh->ebh);
483 brelse(fibh->sbh); 474 brelse(fibh->sbh);
@@ -487,12 +478,11 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
487 } 478 }
488 } 479 }
489 480
490add: 481 add:
491 f_pos += nfidlen; 482 f_pos += nfidlen;
492 483
493 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && 484 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB &&
494 sb->s_blocksize - fibh->eoffset < nfidlen) 485 sb->s_blocksize - fibh->eoffset < nfidlen) {
495 {
496 brelse(epos.bh); 486 brelse(epos.bh);
497 epos.bh = NULL; 487 epos.bh = NULL;
498 fibh->soffset -= udf_ext0_offset(dir); 488 fibh->soffset -= udf_ext0_offset(dir);
@@ -501,11 +491,14 @@ add:
501 if (fibh->sbh != fibh->ebh) 491 if (fibh->sbh != fibh->ebh)
502 brelse(fibh->ebh); 492 brelse(fibh->ebh);
503 brelse(fibh->sbh); 493 brelse(fibh->sbh);
504 if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) 494 if (!
495 (fibh->sbh = fibh->ebh =
496 udf_expand_dir_adinicb(dir, &block, err)))
505 return NULL; 497 return NULL;
506 epos.block = UDF_I_LOCATION(dir); 498 epos.block = UDF_I_LOCATION(dir);
507 eloc.logicalBlockNum = block; 499 eloc.logicalBlockNum = block;
508 eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; 500 eloc.partitionReferenceNum =
501 UDF_I_LOCATION(dir).partitionReferenceNum;
509 elen = dir->i_sb->s_blocksize; 502 elen = dir->i_sb->s_blocksize;
510 epos.offset = udf_file_entry_alloc_offset(dir); 503 epos.offset = udf_file_entry_alloc_offset(dir);
511 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 504 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
@@ -514,89 +507,84 @@ add:
514 epos.offset += sizeof(long_ad); 507 epos.offset += sizeof(long_ad);
515 } 508 }
516 509
517 if (sb->s_blocksize - fibh->eoffset >= nfidlen) 510 if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
518 {
519 fibh->soffset = fibh->eoffset; 511 fibh->soffset = fibh->eoffset;
520 fibh->eoffset += nfidlen; 512 fibh->eoffset += nfidlen;
521 if (fibh->sbh != fibh->ebh) 513 if (fibh->sbh != fibh->ebh) {
522 {
523 brelse(fibh->sbh); 514 brelse(fibh->sbh);
524 fibh->sbh = fibh->ebh; 515 fibh->sbh = fibh->ebh;
525 } 516 }
526 517
527 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 518 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
528 {
529 block = UDF_I_LOCATION(dir).logicalBlockNum; 519 block = UDF_I_LOCATION(dir).logicalBlockNum;
530 fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - udf_ext0_offset(dir) + UDF_I_LENEATTR(dir)); 520 fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) +
531 } 521 fibh->soffset -
532 else 522 udf_ext0_offset(dir) +
533 { 523 UDF_I_LENEATTR(dir));
524 } else {
534 block = eloc.logicalBlockNum + ((elen - 1) >> 525 block = eloc.logicalBlockNum + ((elen - 1) >>
535 dir->i_sb->s_blocksize_bits); 526 dir->i_sb->
536 fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); 527 s_blocksize_bits);
528 fi = (struct fileIdentDesc *)(fibh->sbh->b_data +
529 fibh->soffset);
537 } 530 }
538 } 531 } else {
539 else
540 {
541 fibh->soffset = fibh->eoffset - sb->s_blocksize; 532 fibh->soffset = fibh->eoffset - sb->s_blocksize;
542 fibh->eoffset += nfidlen - sb->s_blocksize; 533 fibh->eoffset += nfidlen - sb->s_blocksize;
543 if (fibh->sbh != fibh->ebh) 534 if (fibh->sbh != fibh->ebh) {
544 {
545 brelse(fibh->sbh); 535 brelse(fibh->sbh);
546 fibh->sbh = fibh->ebh; 536 fibh->sbh = fibh->ebh;
547 } 537 }
548 538
549 block = eloc.logicalBlockNum + ((elen - 1) >> 539 block = eloc.logicalBlockNum + ((elen - 1) >>
550 dir->i_sb->s_blocksize_bits); 540 dir->i_sb->s_blocksize_bits);
551 541
552 if (!(fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err))) 542 if (!
553 { 543 (fibh->ebh =
544 udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
545 1, err))) {
554 brelse(epos.bh); 546 brelse(epos.bh);
555 brelse(fibh->sbh); 547 brelse(fibh->sbh);
556 return NULL; 548 return NULL;
557 } 549 }
558 550
559 if (!(fibh->soffset)) 551 if (!(fibh->soffset)) {
560 {
561 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == 552 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
562 (EXT_RECORDED_ALLOCATED >> 30)) 553 (EXT_RECORDED_ALLOCATED >> 30)) {
563 {
564 block = eloc.logicalBlockNum + ((elen - 1) >> 554 block = eloc.logicalBlockNum + ((elen - 1) >>
565 dir->i_sb->s_blocksize_bits); 555 dir->i_sb->
566 } 556 s_blocksize_bits);
567 else 557 } else
568 block ++; 558 block++;
569 559
570 brelse(fibh->sbh); 560 brelse(fibh->sbh);
571 fibh->sbh = fibh->ebh; 561 fibh->sbh = fibh->ebh;
572 fi = (struct fileIdentDesc *)(fibh->sbh->b_data); 562 fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
573 } 563 } else {
574 else
575 {
576 fi = (struct fileIdentDesc *) 564 fi = (struct fileIdentDesc *)
577 (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); 565 (fibh->sbh->b_data + sb->s_blocksize +
566 fibh->soffset);
578 } 567 }
579 } 568 }
580 569
581 memset(cfi, 0, sizeof(struct fileIdentDesc)); 570 memset(cfi, 0, sizeof(struct fileIdentDesc));
582 if (UDF_SB_UDFREV(sb) >= 0x0200) 571 if (UDF_SB_UDFREV(sb) >= 0x0200)
583 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); 572 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
573 sizeof(tag));
584 else 574 else
585 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); 575 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
576 sizeof(tag));
586 cfi->fileVersionNum = cpu_to_le16(1); 577 cfi->fileVersionNum = cpu_to_le16(1);
587 cfi->lengthFileIdent = namelen; 578 cfi->lengthFileIdent = namelen;
588 cfi->lengthOfImpUse = cpu_to_le16(0); 579 cfi->lengthOfImpUse = cpu_to_le16(0);
589 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) 580 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
590 {
591 brelse(epos.bh); 581 brelse(epos.bh);
592 dir->i_size += nfidlen; 582 dir->i_size += nfidlen;
593 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 583 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
594 UDF_I_LENALLOC(dir) += nfidlen; 584 UDF_I_LENALLOC(dir) += nfidlen;
595 mark_inode_dirty(dir); 585 mark_inode_dirty(dir);
596 return fi; 586 return fi;
597 } 587 } else {
598 else
599 {
600 brelse(epos.bh); 588 brelse(epos.bh);
601 if (fibh->sbh != fibh->ebh) 589 if (fibh->sbh != fibh->ebh)
602 brelse(fibh->ebh); 590 brelse(fibh->ebh);
@@ -607,7 +595,8 @@ add:
607} 595}
608 596
609static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, 597static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
610 struct udf_fileident_bh *fibh, struct fileIdentDesc *cfi) 598 struct udf_fileident_bh *fibh,
599 struct fileIdentDesc *cfi)
611{ 600{
612 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; 601 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED;
613 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 602 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
@@ -615,7 +604,8 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
615 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); 604 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
616} 605}
617 606
618static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) 607static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
608 struct nameidata *nd)
619{ 609{
620 struct udf_fileident_bh fibh; 610 struct udf_fileident_bh fibh;
621 struct inode *inode; 611 struct inode *inode;
@@ -624,8 +614,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
624 614
625 lock_kernel(); 615 lock_kernel();
626 inode = udf_new_inode(dir, mode, &err); 616 inode = udf_new_inode(dir, mode, &err);
627 if (!inode) 617 if (!inode) {
628 {
629 unlock_kernel(); 618 unlock_kernel();
630 return err; 619 return err;
631 } 620 }
@@ -639,9 +628,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
639 inode->i_mode = mode; 628 inode->i_mode = mode;
640 mark_inode_dirty(inode); 629 mark_inode_dirty(inode);
641 630
642 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 631 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
643 { 632 inode->i_nlink--;
644 inode->i_nlink --;
645 mark_inode_dirty(inode); 633 mark_inode_dirty(inode);
646 iput(inode); 634 iput(inode);
647 unlock_kernel(); 635 unlock_kernel();
@@ -649,11 +637,10 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
649 } 637 }
650 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 638 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
651 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 639 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
652 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 640 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
653 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 641 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
654 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 642 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
655 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 643 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
656 {
657 mark_inode_dirty(dir); 644 mark_inode_dirty(dir);
658 } 645 }
659 if (fibh.sbh != fibh.ebh) 646 if (fibh.sbh != fibh.ebh)
@@ -664,9 +651,10 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, struct
664 return 0; 651 return 0;
665} 652}
666 653
667static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t rdev) 654static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
655 dev_t rdev)
668{ 656{
669 struct inode * inode; 657 struct inode *inode;
670 struct udf_fileident_bh fibh; 658 struct udf_fileident_bh fibh;
671 struct fileIdentDesc cfi, *fi; 659 struct fileIdentDesc cfi, *fi;
672 int err; 660 int err;
@@ -682,9 +670,8 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
682 670
683 inode->i_uid = current->fsuid; 671 inode->i_uid = current->fsuid;
684 init_special_inode(inode, mode, rdev); 672 init_special_inode(inode, mode, rdev);
685 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 673 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
686 { 674 inode->i_nlink--;
687 inode->i_nlink --;
688 mark_inode_dirty(inode); 675 mark_inode_dirty(inode);
689 iput(inode); 676 iput(inode);
690 unlock_kernel(); 677 unlock_kernel();
@@ -692,11 +679,10 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
692 } 679 }
693 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 680 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
694 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 681 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
695 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 682 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
696 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 683 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
697 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 684 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
698 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 685 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
699 {
700 mark_inode_dirty(dir); 686 mark_inode_dirty(dir);
701 } 687 }
702 mark_inode_dirty(inode); 688 mark_inode_dirty(inode);
@@ -706,21 +692,21 @@ static int udf_mknod(struct inode * dir, struct dentry * dentry, int mode, dev_t
706 brelse(fibh.sbh); 692 brelse(fibh.sbh);
707 d_instantiate(dentry, inode); 693 d_instantiate(dentry, inode);
708 err = 0; 694 err = 0;
709out: 695 out:
710 unlock_kernel(); 696 unlock_kernel();
711 return err; 697 return err;
712} 698}
713 699
714static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode) 700static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
715{ 701{
716 struct inode * inode; 702 struct inode *inode;
717 struct udf_fileident_bh fibh; 703 struct udf_fileident_bh fibh;
718 struct fileIdentDesc cfi, *fi; 704 struct fileIdentDesc cfi, *fi;
719 int err; 705 int err;
720 706
721 lock_kernel(); 707 lock_kernel();
722 err = -EMLINK; 708 err = -EMLINK;
723 if (dir->i_nlink >= (256<<sizeof(dir->i_nlink))-1) 709 if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1)
724 goto out; 710 goto out;
725 711
726 err = -EIO; 712 err = -EIO;
@@ -730,8 +716,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
730 716
731 inode->i_op = &udf_dir_inode_operations; 717 inode->i_op = &udf_dir_inode_operations;
732 inode->i_fop = &udf_dir_operations; 718 inode->i_fop = &udf_dir_operations;
733 if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) 719 if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) {
734 {
735 inode->i_nlink--; 720 inode->i_nlink--;
736 mark_inode_dirty(inode); 721 mark_inode_dirty(inode);
737 iput(inode); 722 iput(inode);
@@ -740,9 +725,10 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
740 inode->i_nlink = 2; 725 inode->i_nlink = 2;
741 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 726 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
742 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); 727 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir));
743 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 728 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
744 cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); 729 cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL);
745 cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; 730 cfi.fileCharacteristics =
731 FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
746 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); 732 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
747 brelse(fibh.sbh); 733 brelse(fibh.sbh);
748 inode->i_mode = S_IFDIR | mode; 734 inode->i_mode = S_IFDIR | mode;
@@ -750,8 +736,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
750 inode->i_mode |= S_ISGID; 736 inode->i_mode |= S_ISGID;
751 mark_inode_dirty(inode); 737 mark_inode_dirty(inode);
752 738
753 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 739 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
754 {
755 inode->i_nlink = 0; 740 inode->i_nlink = 0;
756 mark_inode_dirty(inode); 741 mark_inode_dirty(inode);
757 iput(inode); 742 iput(inode);
@@ -759,8 +744,8 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
759 } 744 }
760 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 745 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
761 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 746 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
762 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 747 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
763 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 748 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
764 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; 749 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY;
765 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 750 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
766 inc_nlink(dir); 751 inc_nlink(dir);
@@ -770,7 +755,7 @@ static int udf_mkdir(struct inode * dir, struct dentry * dentry, int mode)
770 brelse(fibh.ebh); 755 brelse(fibh.ebh);
771 brelse(fibh.sbh); 756 brelse(fibh.sbh);
772 err = 0; 757 err = 0;
773out: 758 out:
774 unlock_kernel(); 759 unlock_kernel();
775 return err; 760 return err;
776} 761}
@@ -785,47 +770,41 @@ static int empty_dir(struct inode *dir)
785 kernel_lb_addr eloc; 770 kernel_lb_addr eloc;
786 uint32_t elen; 771 uint32_t elen;
787 sector_t offset; 772 sector_t offset;
788 struct extent_position epos = { NULL, 0, { 0, 0}}; 773 struct extent_position epos = { NULL, 0, {0, 0} };
789 774
790 f_pos = (udf_ext0_offset(dir) >> 2); 775 f_pos = (udf_ext0_offset(dir) >> 2);
791 776
792 fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 777 fibh.soffset = fibh.eoffset =
778 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
793 779
794 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 780 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
795 fibh.sbh = fibh.ebh = NULL; 781 fibh.sbh = fibh.ebh = NULL;
796 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 782 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
797 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 783 &epos, &eloc, &elen,
798 { 784 &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
799 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 785 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
800 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) 786 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
801 {
802 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 787 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
803 epos.offset -= sizeof(short_ad); 788 epos.offset -= sizeof(short_ad);
804 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 789 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
805 epos.offset -= sizeof(long_ad); 790 epos.offset -= sizeof(long_ad);
806 } 791 } else
807 else
808 offset = 0; 792 offset = 0;
809 793
810 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) 794 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
811 {
812 brelse(epos.bh); 795 brelse(epos.bh);
813 return 0; 796 return 0;
814 } 797 }
815 } 798 } else {
816 else
817 {
818 brelse(epos.bh); 799 brelse(epos.bh);
819 return 0; 800 return 0;
820 } 801 }
821 802
803 while ((f_pos < size)) {
804 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
805 &elen, &offset);
822 806
823 while ( (f_pos < size) ) 807 if (!fi) {
824 {
825 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset);
826
827 if (!fi)
828 {
829 if (fibh.sbh != fibh.ebh) 808 if (fibh.sbh != fibh.ebh)
830 brelse(fibh.ebh); 809 brelse(fibh.ebh);
831 brelse(fibh.sbh); 810 brelse(fibh.sbh);
@@ -833,8 +812,8 @@ static int empty_dir(struct inode *dir)
833 return 0; 812 return 0;
834 } 813 }
835 814
836 if (cfi.lengthFileIdent && (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) 815 if (cfi.lengthFileIdent
837 { 816 && (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) {
838 if (fibh.sbh != fibh.ebh) 817 if (fibh.sbh != fibh.ebh)
839 brelse(fibh.ebh); 818 brelse(fibh.ebh);
840 brelse(fibh.sbh); 819 brelse(fibh.sbh);
@@ -849,10 +828,10 @@ static int empty_dir(struct inode *dir)
849 return 1; 828 return 1;
850} 829}
851 830
852static int udf_rmdir(struct inode * dir, struct dentry * dentry) 831static int udf_rmdir(struct inode *dir, struct dentry *dentry)
853{ 832{
854 int retval; 833 int retval;
855 struct inode * inode = dentry->d_inode; 834 struct inode *inode = dentry->d_inode;
856 struct udf_fileident_bh fibh; 835 struct udf_fileident_bh fibh;
857 struct fileIdentDesc *fi, cfi; 836 struct fileIdentDesc *fi, cfi;
858 kernel_lb_addr tloc; 837 kernel_lb_addr tloc;
@@ -875,27 +854,28 @@ static int udf_rmdir(struct inode * dir, struct dentry * dentry)
875 goto end_rmdir; 854 goto end_rmdir;
876 if (inode->i_nlink != 2) 855 if (inode->i_nlink != 2)
877 udf_warning(inode->i_sb, "udf_rmdir", 856 udf_warning(inode->i_sb, "udf_rmdir",
878 "empty directory has nlink != 2 (%d)", 857 "empty directory has nlink != 2 (%d)",
879 inode->i_nlink); 858 inode->i_nlink);
880 clear_nlink(inode); 859 clear_nlink(inode);
881 inode->i_size = 0; 860 inode->i_size = 0;
882 inode_dec_link_count(dir); 861 inode_dec_link_count(dir);
883 inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); 862 inode->i_ctime = dir->i_ctime = dir->i_mtime =
863 current_fs_time(dir->i_sb);
884 mark_inode_dirty(dir); 864 mark_inode_dirty(dir);
885 865
886end_rmdir: 866 end_rmdir:
887 if (fibh.sbh != fibh.ebh) 867 if (fibh.sbh != fibh.ebh)
888 brelse(fibh.ebh); 868 brelse(fibh.ebh);
889 brelse(fibh.sbh); 869 brelse(fibh.sbh);
890out: 870 out:
891 unlock_kernel(); 871 unlock_kernel();
892 return retval; 872 return retval;
893} 873}
894 874
895static int udf_unlink(struct inode * dir, struct dentry * dentry) 875static int udf_unlink(struct inode *dir, struct dentry *dentry)
896{ 876{
897 int retval; 877 int retval;
898 struct inode * inode = dentry->d_inode; 878 struct inode *inode = dentry->d_inode;
899 struct udf_fileident_bh fibh; 879 struct udf_fileident_bh fibh;
900 struct fileIdentDesc *fi; 880 struct fileIdentDesc *fi;
901 struct fileIdentDesc cfi; 881 struct fileIdentDesc cfi;
@@ -912,10 +892,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) 892 if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino)
913 goto end_unlink; 893 goto end_unlink;
914 894
915 if (!inode->i_nlink) 895 if (!inode->i_nlink) {
916 {
917 udf_debug("Deleting nonexistent file (%lu), %d\n", 896 udf_debug("Deleting nonexistent file (%lu), %d\n",
918 inode->i_ino, inode->i_nlink); 897 inode->i_ino, inode->i_nlink);
919 inode->i_nlink = 1; 898 inode->i_nlink = 1;
920 } 899 }
921 retval = udf_delete_entry(dir, fi, &fibh, &cfi); 900 retval = udf_delete_entry(dir, fi, &fibh, &cfi);
@@ -927,22 +906,23 @@ static int udf_unlink(struct inode * dir, struct dentry * dentry)
927 inode->i_ctime = dir->i_ctime; 906 inode->i_ctime = dir->i_ctime;
928 retval = 0; 907 retval = 0;
929 908
930end_unlink: 909 end_unlink:
931 if (fibh.sbh != fibh.ebh) 910 if (fibh.sbh != fibh.ebh)
932 brelse(fibh.ebh); 911 brelse(fibh.ebh);
933 brelse(fibh.sbh); 912 brelse(fibh.sbh);
934out: 913 out:
935 unlock_kernel(); 914 unlock_kernel();
936 return retval; 915 return retval;
937} 916}
938 917
939static int udf_symlink(struct inode * dir, struct dentry * dentry, const char * symname) 918static int udf_symlink(struct inode *dir, struct dentry *dentry,
919 const char *symname)
940{ 920{
941 struct inode * inode; 921 struct inode *inode;
942 struct pathComponent *pc; 922 struct pathComponent *pc;
943 char *compstart; 923 char *compstart;
944 struct udf_fileident_bh fibh; 924 struct udf_fileident_bh fibh;
945 struct extent_position epos = { NULL, 0, {0, 0}}; 925 struct extent_position epos = { NULL, 0, {0, 0} };
946 int eoffset, elen = 0; 926 int eoffset, elen = 0;
947 struct fileIdentDesc *fi; 927 struct fileIdentDesc *fi;
948 struct fileIdentDesc cfi; 928 struct fileIdentDesc cfi;
@@ -960,28 +940,31 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
960 inode->i_data.a_ops = &udf_symlink_aops; 940 inode->i_data.a_ops = &udf_symlink_aops;
961 inode->i_op = &page_symlink_inode_operations; 941 inode->i_op = &page_symlink_inode_operations;
962 942
963 if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) 943 if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) {
964 {
965 kernel_lb_addr eloc; 944 kernel_lb_addr eloc;
966 uint32_t elen; 945 uint32_t elen;
967 946
968 block = udf_new_block(inode->i_sb, inode, 947 block = udf_new_block(inode->i_sb, inode,
969 UDF_I_LOCATION(inode).partitionReferenceNum, 948 UDF_I_LOCATION(inode).
970 UDF_I_LOCATION(inode).logicalBlockNum, &err); 949 partitionReferenceNum,
950 UDF_I_LOCATION(inode).logicalBlockNum,
951 &err);
971 if (!block) 952 if (!block)
972 goto out_no_entry; 953 goto out_no_entry;
973 epos.block = UDF_I_LOCATION(inode); 954 epos.block = UDF_I_LOCATION(inode);
974 epos.offset = udf_file_entry_alloc_offset(inode); 955 epos.offset = udf_file_entry_alloc_offset(inode);
975 epos.bh = NULL; 956 epos.bh = NULL;
976 eloc.logicalBlockNum = block; 957 eloc.logicalBlockNum = block;
977 eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 958 eloc.partitionReferenceNum =
959 UDF_I_LOCATION(inode).partitionReferenceNum;
978 elen = inode->i_sb->s_blocksize; 960 elen = inode->i_sb->s_blocksize;
979 UDF_I_LENEXTENTS(inode) = elen; 961 UDF_I_LENEXTENTS(inode) = elen;
980 udf_add_aext(inode, &epos, eloc, elen, 0); 962 udf_add_aext(inode, &epos, eloc, elen, 0);
981 brelse(epos.bh); 963 brelse(epos.bh);
982 964
983 block = udf_get_pblock(inode->i_sb, block, 965 block = udf_get_pblock(inode->i_sb, block,
984 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 966 UDF_I_LOCATION(inode).
967 partitionReferenceNum, 0);
985 epos.bh = udf_tread(inode->i_sb, block); 968 epos.bh = udf_tread(inode->i_sb, block);
986 lock_buffer(epos.bh); 969 lock_buffer(epos.bh);
987 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); 970 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize);
@@ -989,17 +972,14 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
989 unlock_buffer(epos.bh); 972 unlock_buffer(epos.bh);
990 mark_buffer_dirty_inode(epos.bh, inode); 973 mark_buffer_dirty_inode(epos.bh, inode);
991 ea = epos.bh->b_data + udf_ext0_offset(inode); 974 ea = epos.bh->b_data + udf_ext0_offset(inode);
992 } 975 } else
993 else
994 ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 976 ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
995 977
996 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); 978 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode);
997 pc = (struct pathComponent *)ea; 979 pc = (struct pathComponent *)ea;
998 980
999 if (*symname == '/') 981 if (*symname == '/') {
1000 { 982 do {
1001 do
1002 {
1003 symname++; 983 symname++;
1004 } while (*symname == '/'); 984 } while (*symname == '/');
1005 985
@@ -1012,8 +992,7 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1012 992
1013 err = -ENAMETOOLONG; 993 err = -ENAMETOOLONG;
1014 994
1015 while (*symname) 995 while (*symname) {
1016 {
1017 if (elen + sizeof(struct pathComponent) > eoffset) 996 if (elen + sizeof(struct pathComponent) > eoffset)
1018 goto out_no_entry; 997 goto out_no_entry;
1019 998
@@ -1021,28 +1000,30 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1021 1000
1022 compstart = (char *)symname; 1001 compstart = (char *)symname;
1023 1002
1024 do 1003 do {
1025 {
1026 symname++; 1004 symname++;
1027 } while (*symname && *symname != '/'); 1005 } while (*symname && *symname != '/');
1028 1006
1029 pc->componentType = 5; 1007 pc->componentType = 5;
1030 pc->lengthComponentIdent = 0; 1008 pc->lengthComponentIdent = 0;
1031 pc->componentFileVersionNum = 0; 1009 pc->componentFileVersionNum = 0;
1032 if (compstart[0] == '.') 1010 if (compstart[0] == '.') {
1033 { 1011 if ((symname - compstart) == 1)
1034 if ((symname-compstart) == 1)
1035 pc->componentType = 4; 1012 pc->componentType = 4;
1036 else if ((symname-compstart) == 2 && compstart[1] == '.') 1013 else if ((symname - compstart) == 2
1014 && compstart[1] == '.')
1037 pc->componentType = 3; 1015 pc->componentType = 3;
1038 } 1016 }
1039 1017
1040 if (pc->componentType == 5) 1018 if (pc->componentType == 5) {
1041 { 1019 if (!
1042 if ( !(namelen = udf_put_filename(inode->i_sb, compstart, name, symname-compstart))) 1020 (namelen =
1021 udf_put_filename(inode->i_sb, compstart, name,
1022 symname - compstart)))
1043 goto out_no_entry; 1023 goto out_no_entry;
1044 1024
1045 if (elen + sizeof(struct pathComponent) + namelen > eoffset) 1025 if (elen + sizeof(struct pathComponent) + namelen >
1026 eoffset)
1046 goto out_no_entry; 1027 goto out_no_entry;
1047 else 1028 else
1048 pc->lengthComponentIdent = namelen; 1029 pc->lengthComponentIdent = namelen;
@@ -1052,10 +1033,8 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1052 1033
1053 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; 1034 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
1054 1035
1055 if (*symname) 1036 if (*symname) {
1056 { 1037 do {
1057 do
1058 {
1059 symname++; 1038 symname++;
1060 } while (*symname == '/'); 1039 } while (*symname == '/');
1061 } 1040 }
@@ -1071,22 +1050,22 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1071 goto out_no_entry; 1050 goto out_no_entry;
1072 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1051 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1073 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1052 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
1074 if (UDF_SB_LVIDBH(inode->i_sb)) 1053 if (UDF_SB_LVIDBH(inode->i_sb)) {
1075 {
1076 struct logicalVolHeaderDesc *lvhd; 1054 struct logicalVolHeaderDesc *lvhd;
1077 uint64_t uniqueID; 1055 uint64_t uniqueID;
1078 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1056 lvhd =
1057 (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->
1058 logicalVolContentsUse);
1079 uniqueID = le64_to_cpu(lvhd->uniqueID); 1059 uniqueID = le64_to_cpu(lvhd->uniqueID);
1080 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 1060 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
1081 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); 1061 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
1082 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 1062 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
1083 uniqueID += 16; 1063 uniqueID += 16;
1084 lvhd->uniqueID = cpu_to_le64(uniqueID); 1064 lvhd->uniqueID = cpu_to_le64(uniqueID);
1085 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1065 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
1086 } 1066 }
1087 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1067 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1088 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 1068 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
1089 {
1090 mark_inode_dirty(dir); 1069 mark_inode_dirty(dir);
1091 } 1070 }
1092 if (fibh.sbh != fibh.ebh) 1071 if (fibh.sbh != fibh.ebh)
@@ -1095,18 +1074,18 @@ static int udf_symlink(struct inode * dir, struct dentry * dentry, const char *
1095 d_instantiate(dentry, inode); 1074 d_instantiate(dentry, inode);
1096 err = 0; 1075 err = 0;
1097 1076
1098out: 1077 out:
1099 unlock_kernel(); 1078 unlock_kernel();
1100 return err; 1079 return err;
1101 1080
1102out_no_entry: 1081 out_no_entry:
1103 inode_dec_link_count(inode); 1082 inode_dec_link_count(inode);
1104 iput(inode); 1083 iput(inode);
1105 goto out; 1084 goto out;
1106} 1085}
1107 1086
1108static int udf_link(struct dentry * old_dentry, struct inode * dir, 1087static int udf_link(struct dentry *old_dentry, struct inode *dir,
1109 struct dentry *dentry) 1088 struct dentry *dentry)
1110{ 1089{
1111 struct inode *inode = old_dentry->d_inode; 1090 struct inode *inode = old_dentry->d_inode;
1112 struct udf_fileident_bh fibh; 1091 struct udf_fileident_bh fibh;
@@ -1114,35 +1093,33 @@ static int udf_link(struct dentry * old_dentry, struct inode * dir,
1114 int err; 1093 int err;
1115 1094
1116 lock_kernel(); 1095 lock_kernel();
1117 if (inode->i_nlink >= (256<<sizeof(inode->i_nlink))-1) 1096 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
1118 {
1119 unlock_kernel(); 1097 unlock_kernel();
1120 return -EMLINK; 1098 return -EMLINK;
1121 } 1099 }
1122 1100
1123 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 1101 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
1124 {
1125 unlock_kernel(); 1102 unlock_kernel();
1126 return err; 1103 return err;
1127 } 1104 }
1128 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1105 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1129 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1106 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
1130 if (UDF_SB_LVIDBH(inode->i_sb)) 1107 if (UDF_SB_LVIDBH(inode->i_sb)) {
1131 {
1132 struct logicalVolHeaderDesc *lvhd; 1108 struct logicalVolHeaderDesc *lvhd;
1133 uint64_t uniqueID; 1109 uint64_t uniqueID;
1134 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1110 lvhd =
1111 (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->
1112 logicalVolContentsUse);
1135 uniqueID = le64_to_cpu(lvhd->uniqueID); 1113 uniqueID = le64_to_cpu(lvhd->uniqueID);
1136 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 1114 *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
1137 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); 1115 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
1138 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 1116 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
1139 uniqueID += 16; 1117 uniqueID += 16;
1140 lvhd->uniqueID = cpu_to_le64(uniqueID); 1118 lvhd->uniqueID = cpu_to_le64(uniqueID);
1141 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1119 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
1142 } 1120 }
1143 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1121 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1144 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 1122 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
1145 {
1146 mark_inode_dirty(dir); 1123 mark_inode_dirty(dir);
1147 } 1124 }
1148 if (fibh.sbh != fibh.ebh) 1125 if (fibh.sbh != fibh.ebh)
@@ -1160,80 +1137,80 @@ static int udf_link(struct dentry * old_dentry, struct inode * dir,
1160/* Anybody can rename anything with this: the permission checks are left to the 1137/* Anybody can rename anything with this: the permission checks are left to the
1161 * higher-level routines. 1138 * higher-level routines.
1162 */ 1139 */
1163static int udf_rename (struct inode * old_dir, struct dentry * old_dentry, 1140static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1164 struct inode * new_dir, struct dentry * new_dentry) 1141 struct inode *new_dir, struct dentry *new_dentry)
1165{ 1142{
1166 struct inode * old_inode = old_dentry->d_inode; 1143 struct inode *old_inode = old_dentry->d_inode;
1167 struct inode * new_inode = new_dentry->d_inode; 1144 struct inode *new_inode = new_dentry->d_inode;
1168 struct udf_fileident_bh ofibh, nfibh; 1145 struct udf_fileident_bh ofibh, nfibh;
1169 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; 1146 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi =
1147 NULL, ocfi, ncfi;
1170 struct buffer_head *dir_bh = NULL; 1148 struct buffer_head *dir_bh = NULL;
1171 int retval = -ENOENT; 1149 int retval = -ENOENT;
1172 kernel_lb_addr tloc; 1150 kernel_lb_addr tloc;
1173 1151
1174 lock_kernel(); 1152 lock_kernel();
1175 if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) 1153 if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) {
1176 {
1177 if (ofibh.sbh != ofibh.ebh) 1154 if (ofibh.sbh != ofibh.ebh)
1178 brelse(ofibh.ebh); 1155 brelse(ofibh.ebh);
1179 brelse(ofibh.sbh); 1156 brelse(ofibh.sbh);
1180 } 1157 }
1181 tloc = lelb_to_cpu(ocfi.icb.extLocation); 1158 tloc = lelb_to_cpu(ocfi.icb.extLocation);
1182 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0) 1159 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0)
1183 != old_inode->i_ino) 1160 != old_inode->i_ino)
1184 goto end_rename; 1161 goto end_rename;
1185 1162
1186 nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi); 1163 nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi);
1187 if (nfi) 1164 if (nfi) {
1188 { 1165 if (!new_inode) {
1189 if (!new_inode)
1190 {
1191 if (nfibh.sbh != nfibh.ebh) 1166 if (nfibh.sbh != nfibh.ebh)
1192 brelse(nfibh.ebh); 1167 brelse(nfibh.ebh);
1193 brelse(nfibh.sbh); 1168 brelse(nfibh.sbh);
1194 nfi = NULL; 1169 nfi = NULL;
1195 } 1170 }
1196 } 1171 }
1197 if (S_ISDIR(old_inode->i_mode)) 1172 if (S_ISDIR(old_inode->i_mode)) {
1198 {
1199 uint32_t offset = udf_ext0_offset(old_inode); 1173 uint32_t offset = udf_ext0_offset(old_inode);
1200 1174
1201 if (new_inode) 1175 if (new_inode) {
1202 {
1203 retval = -ENOTEMPTY; 1176 retval = -ENOTEMPTY;
1204 if (!empty_dir(new_inode)) 1177 if (!empty_dir(new_inode))
1205 goto end_rename; 1178 goto end_rename;
1206 } 1179 }
1207 retval = -EIO; 1180 retval = -EIO;
1208 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) 1181 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
1209 {
1210 dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - 1182 dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) -
1211 (UDF_I_EFE(old_inode) ? 1183 (UDF_I_EFE(old_inode) ?
1212 sizeof(struct extendedFileEntry) : 1184 sizeof(struct
1213 sizeof(struct fileEntry)), 1185 extendedFileEntry) :
1214 old_inode->i_sb->s_blocksize, &offset); 1186 sizeof(struct fileEntry)),
1215 } 1187 old_inode->i_sb->s_blocksize,
1216 else 1188 &offset);
1217 { 1189 } else {
1218 dir_bh = udf_bread(old_inode, 0, 0, &retval); 1190 dir_bh = udf_bread(old_inode, 0, 0, &retval);
1219 if (!dir_bh) 1191 if (!dir_bh)
1220 goto end_rename; 1192 goto end_rename;
1221 dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); 1193 dir_fi =
1194 udf_get_fileident(dir_bh->b_data,
1195 old_inode->i_sb->s_blocksize,
1196 &offset);
1222 } 1197 }
1223 if (!dir_fi) 1198 if (!dir_fi)
1224 goto end_rename; 1199 goto end_rename;
1225 tloc = lelb_to_cpu(dir_fi->icb.extLocation); 1200 tloc = lelb_to_cpu(dir_fi->icb.extLocation);
1226 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) 1201 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0)
1227 != old_dir->i_ino) 1202 != old_dir->i_ino)
1228 goto end_rename; 1203 goto end_rename;
1229 1204
1230 retval = -EMLINK; 1205 retval = -EMLINK;
1231 if (!new_inode && new_dir->i_nlink >= (256<<sizeof(new_dir->i_nlink))-1) 1206 if (!new_inode
1207 && new_dir->i_nlink >=
1208 (256 << sizeof(new_dir->i_nlink)) - 1)
1232 goto end_rename; 1209 goto end_rename;
1233 } 1210 }
1234 if (!nfi) 1211 if (!nfi) {
1235 { 1212 nfi =
1236 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); 1213 udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval);
1237 if (!nfi) 1214 if (!nfi)
1238 goto end_rename; 1215 goto end_rename;
1239 } 1216 }
@@ -1257,39 +1234,33 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1257 ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); 1234 ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);
1258 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); 1235 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
1259 1236
1260 if (new_inode) 1237 if (new_inode) {
1261 {
1262 new_inode->i_ctime = current_fs_time(new_inode->i_sb); 1238 new_inode->i_ctime = current_fs_time(new_inode->i_sb);
1263 inode_dec_link_count(new_inode); 1239 inode_dec_link_count(new_inode);
1264 } 1240 }
1265 old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb); 1241 old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb);
1266 mark_inode_dirty(old_dir); 1242 mark_inode_dirty(old_dir);
1267 1243
1268 if (dir_fi) 1244 if (dir_fi) {
1269 {
1270 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); 1245 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir));
1271 udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + 1246 udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) +
1272 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); 1247 le16_to_cpu(dir_fi->
1273 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) 1248 lengthOfImpUse) +
1274 { 1249 3) & ~3);
1250 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
1275 mark_inode_dirty(old_inode); 1251 mark_inode_dirty(old_inode);
1276 } 1252 } else
1277 else
1278 mark_buffer_dirty_inode(dir_bh, old_inode); 1253 mark_buffer_dirty_inode(dir_bh, old_inode);
1279 inode_dec_link_count(old_dir); 1254 inode_dec_link_count(old_dir);
1280 if (new_inode) 1255 if (new_inode) {
1281 {
1282 inode_dec_link_count(new_inode); 1256 inode_dec_link_count(new_inode);
1283 } 1257 } else {
1284 else
1285 {
1286 inc_nlink(new_dir); 1258 inc_nlink(new_dir);
1287 mark_inode_dirty(new_dir); 1259 mark_inode_dirty(new_dir);
1288 } 1260 }
1289 } 1261 }
1290 1262
1291 if (ofi) 1263 if (ofi) {
1292 {
1293 if (ofibh.sbh != ofibh.ebh) 1264 if (ofibh.sbh != ofibh.ebh)
1294 brelse(ofibh.ebh); 1265 brelse(ofibh.ebh);
1295 brelse(ofibh.sbh); 1266 brelse(ofibh.sbh);
@@ -1297,10 +1268,9 @@ static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,
1297 1268
1298 retval = 0; 1269 retval = 0;
1299 1270
1300end_rename: 1271 end_rename:
1301 brelse(dir_bh); 1272 brelse(dir_bh);
1302 if (nfi) 1273 if (nfi) {
1303 {
1304 if (nfibh.sbh != nfibh.ebh) 1274 if (nfibh.sbh != nfibh.ebh)
1305 brelse(nfibh.ebh); 1275 brelse(nfibh.ebh);
1306 brelse(nfibh.sbh); 1276 brelse(nfibh.sbh);
@@ -1310,13 +1280,13 @@ end_rename:
1310} 1280}
1311 1281
1312const struct inode_operations udf_dir_inode_operations = { 1282const struct inode_operations udf_dir_inode_operations = {
1313 .lookup = udf_lookup, 1283 .lookup = udf_lookup,
1314 .create = udf_create, 1284 .create = udf_create,
1315 .link = udf_link, 1285 .link = udf_link,
1316 .unlink = udf_unlink, 1286 .unlink = udf_unlink,
1317 .symlink = udf_symlink, 1287 .symlink = udf_symlink,
1318 .mkdir = udf_mkdir, 1288 .mkdir = udf_mkdir,
1319 .rmdir = udf_rmdir, 1289 .rmdir = udf_rmdir,
1320 .mknod = udf_mknod, 1290 .mknod = udf_mknod,
1321 .rename = udf_rename, 1291 .rename = udf_rename,
1322}; 1292};
diff --git a/fs/udf/osta_udf.h b/fs/udf/osta_udf.h
index e82aae652697..bec5d340d8c5 100644
--- a/fs/udf/osta_udf.h
+++ b/fs/udf/osta_udf.h
@@ -65,153 +65,140 @@
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{ 69 __le16 UDFRevision;
70 __le16 UDFRevision; 70 uint8_t OSClass;
71 uint8_t OSClass; 71 uint8_t OSIdentifier;
72 uint8_t OSIdentifier; 72 uint8_t reserved[4];
73 uint8_t reserved[4];
74} __attribute__ ((packed)); 73} __attribute__ ((packed));
75 74
76struct impIdentSuffix 75struct impIdentSuffix {
77{ 76 uint8_t OSClass;
78 uint8_t OSClass; 77 uint8_t OSIdentifier;
79 uint8_t OSIdentifier; 78 uint8_t reserved[6];
80 uint8_t reserved[6];
81} __attribute__ ((packed)); 79} __attribute__ ((packed));
82 80
83struct appIdentSuffix 81struct appIdentSuffix {
84{ 82 uint8_t impUse[8];
85 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{ 88 regid impIdent;
92 regid impIdent; 89 __le32 numFiles;
93 __le32 numFiles; 90 __le32 numDirs;
94 __le32 numDirs; 91 __le16 minUDFReadRev;
95 __le16 minUDFReadRev; 92 __le16 minUDFWriteRev;
96 __le16 minUDFWriteRev; 93 __le16 maxUDFWriteRev;
97 __le16 maxUDFWriteRev; 94 uint8_t impUse[0];
98 uint8_t impUse[0];
99} __attribute__ ((packed)); 95} __attribute__ ((packed));
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{ 100 charspec LVICharset;
105 charspec LVICharset; 101 dstring logicalVolIdent[128];
106 dstring logicalVolIdent[128]; 102 dstring LVInfo1[36];
107 dstring LVInfo1[36]; 103 dstring LVInfo2[36];
108 dstring LVInfo2[36]; 104 dstring LVInfo3[36];
109 dstring LVInfo3[36]; 105 regid impIdent;
110 regid impIdent; 106 uint8_t impUse[128];
111 uint8_t impUse[128];
112} __attribute__ ((packed)); 107} __attribute__ ((packed));
113 108
114struct udfPartitionMap2 109struct udfPartitionMap2 {
115{ 110 uint8_t partitionMapType;
116 uint8_t partitionMapType; 111 uint8_t partitionMapLength;
117 uint8_t partitionMapLength; 112 uint8_t reserved1[2];
118 uint8_t reserved1[2]; 113 regid partIdent;
119 regid partIdent; 114 __le16 volSeqNum;
120 __le16 volSeqNum; 115 __le16 partitionNum;
121 __le16 partitionNum;
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{ 120 uint8_t partitionMapType;
127 uint8_t partitionMapType; 121 uint8_t partitionMapLength;
128 uint8_t partitionMapLength; 122 uint8_t reserved1[2];
129 uint8_t reserved1[2]; 123 regid partIdent;
130 regid partIdent; 124 __le16 volSeqNum;
131 __le16 volSeqNum; 125 __le16 partitionNum;
132 __le16 partitionNum; 126 uint8_t reserved2[24];
133 uint8_t reserved2[24];
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{ 146 uint8_t partitionMapType;
155 uint8_t partitionMapType; 147 uint8_t partitionMapLength;
156 uint8_t partitionMapLength; 148 uint8_t reserved1[2];
157 uint8_t reserved1[2]; 149 regid partIdent;
158 regid partIdent; 150 __le16 volSeqNum;
159 __le16 volSeqNum; 151 __le16 partitionNum;
160 __le16 partitionNum; 152 __le32 metadataFileLoc;
161 __le32 metadataFileLoc; 153 __le32 metadataMirrorFileLoc;
162 __le32 metadataMirrorFileLoc; 154 __le32 metadataBitmapFileLoc;
163 __le32 metadataBitmapFileLoc; 155 __le32 allocUnitSize;
164 __le32 allocUnitSize; 156 __le16 alignUnitSize;
165 __le16 alignUnitSize; 157 uint8_t flags;
166 uint8_t flags; 158 uint8_t reserved2[5];
167 uint8_t reserved2[5];
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{ 163 __le32 VirtualSector[0];
173 __le32 VirtualSector[0]; 164 regid vatIdent;
174 regid vatIdent; 165 __le32 previousVATICBLoc;
175 __le32 previousVATICBLoc; 166} __attribute__ ((packed));
176} __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{ 172 __le16 lengthHeader;
183 __le16 lengthHeader; 173 __le16 lengthImpUse;
184 __le16 lengthImpUse; 174 dstring logicalVolIdent[128];
185 dstring logicalVolIdent[128]; 175 __le32 previousVATICBLoc;
186 __le32 previousVATICBLoc; 176 __le32 numFiles;
187 __le32 numFiles; 177 __le32 numDirs;
188 __le32 numDirs; 178 __le16 minReadRevision;
189 __le16 minReadRevision; 179 __le16 minWriteRevision;
190 __le16 minWriteRevision; 180 __le16 maxWriteRevision;
191 __le16 maxWriteRevision; 181 __le16 reserved;
192 __le16 reserved; 182 uint8_t impUse[0];
193 uint8_t impUse[0]; 183 __le32 vatEntry[0];
194 __le32 vatEntry[0];
195} __attribute__ ((packed)); 184} __attribute__ ((packed));
196 185
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{ 190 __le32 origLocation;
202 __le32 origLocation; 191 __le32 mappedLocation;
203 __le32 mappedLocation;
204} __attribute__ ((packed)); 192} __attribute__ ((packed));
205 193
206struct sparingTable 194struct sparingTable {
207{ 195 tag descTag;
208 tag descTag; 196 regid sparingIdent;
209 regid sparingIdent; 197 __le16 reallocationTableLen;
210 __le16 reallocationTableLen; 198 __le16 reserved;
211 __le16 reserved; 199 __le32 sequenceNum;
212 __le32 sequenceNum;
213 struct sparingEntry 200 struct sparingEntry
214 mapEntry[0]; 201 mapEntry[0];
215} __attribute__ ((packed)); 202} __attribute__ ((packed));
216 203
217/* Metadata File (and Metadata Mirror File) (UDF 2.50 2.2.13.1) */ 204/* Metadata File (and Metadata Mirror File) (UDF 2.50 2.2.13.1) */
@@ -220,10 +207,9 @@ 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{ 211 __le16 flags;
225 __le16 flags; 212 uint8_t impUse[4];
226 uint8_t impUse[4];
227} __attribute__ ((packed)); 213} __attribute__ ((packed));
228 214
229#define AD_IU_EXT_ERASED 0x0001 215#define AD_IU_EXT_ERASED 0x0001
@@ -233,27 +219,24 @@ 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{ 223 __le16 headerChecksum;
238 __le16 headerChecksum; 224 uint8_t freeEASpace[0];
239 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{ 229 __le16 headerChecksum;
245 __le16 headerChecksum; 230 uint8_t CGMSInfo;
246 uint8_t CGMSInfo; 231 uint8_t dataType;
247 uint8_t dataType; 232 uint8_t protectionSystemInfo[4];
248 uint8_t protectionSystemInfo[4];
249} __attribute__ ((packed)); 233} __attribute__ ((packed));
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{ 238 __le16 headerChecksum;
255 __le16 headerChecksum; 239 uint8_t freeEASpace[0];
256 uint8_t freeEASpace[0];
257} __attribute__ ((packed)); 240} __attribute__ ((packed));
258 241
259/* UDF Defined System Stream (UDF 2.50 3.3.7) */ 242/* UDF Defined System Stream (UDF 2.50 3.3.7) */
@@ -293,4 +276,4 @@ struct freeAppEASpace
293#define UDF_OS_ID_BEOS 0x00U 276#define UDF_OS_ID_BEOS 0x00U
294#define UDF_OS_ID_WINCE 0x00U 277#define UDF_OS_ID_WINCE 0x00U
295 278
296#endif /* _OSTA_UDF_H */ 279#endif /* _OSTA_UDF_H */
diff --git a/fs/udf/partition.c b/fs/udf/partition.c
index 467a26171cd9..a95d830a674d 100644
--- a/fs/udf/partition.c
+++ b/fs/udf/partition.c
@@ -28,106 +28,120 @@
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
35 udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", 36 ("block=%d, partition=%d, offset=%d: invalid partition\n",
36 block, partition, offset); 37 block, partition, offset);
37 return 0xFFFFFFFF; 38 return 0xFFFFFFFF;
38 } 39 }
39 if (UDF_SB_PARTFUNC(sb, partition)) 40 if (UDF_SB_PARTFUNC(sb, partition))
40 return UDF_SB_PARTFUNC(sb, partition)(sb, block, partition, offset); 41 return UDF_SB_PARTFUNC(sb, partition) (sb, block, partition,
42 offset);
41 else 43 else
42 return UDF_SB_PARTROOT(sb, partition) + block + offset; 44 return UDF_SB_PARTROOT(sb, partition) + block + offset;
43} 45}
44 46
45uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 47uint32_t udf_get_pblock_virt15(struct super_block * sb, uint32_t block,
48 uint16_t partition, uint32_t offset)
46{ 49{
47 struct buffer_head *bh = NULL; 50 struct buffer_head *bh = NULL;
48 uint32_t newblock; 51 uint32_t newblock;
49 uint32_t index; 52 uint32_t index;
50 uint32_t loc; 53 uint32_t loc;
51 54
52 index = (sb->s_blocksize - UDF_SB_TYPEVIRT(sb,partition).s_start_offset) / sizeof(uint32_t); 55 index =
56 (sb->s_blocksize -
57 UDF_SB_TYPEVIRT(sb, partition).s_start_offset) / sizeof(uint32_t);
53 58
54 if (block > UDF_SB_TYPEVIRT(sb,partition).s_num_entries) 59 if (block > UDF_SB_TYPEVIRT(sb, partition).s_num_entries) {
55 { 60 udf_debug
56 udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", 61 ("Trying to access block beyond end of VAT (%d max %d)\n",
57 block, UDF_SB_TYPEVIRT(sb,partition).s_num_entries); 62 block, UDF_SB_TYPEVIRT(sb, partition).s_num_entries);
58 return 0xFFFFFFFF; 63 return 0xFFFFFFFF;
59 } 64 }
60 65
61 if (block >= index) 66 if (block >= index) {
62 {
63 block -= index; 67 block -= index;
64 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t))); 68 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t)));
65 index = block % (sb->s_blocksize / sizeof(uint32_t)); 69 index = block % (sb->s_blocksize / sizeof(uint32_t));
66 } 70 } else {
67 else
68 {
69 newblock = 0; 71 newblock = 0;
70 index = UDF_SB_TYPEVIRT(sb,partition).s_start_offset / sizeof(uint32_t) + block; 72 index =
73 UDF_SB_TYPEVIRT(sb,
74 partition).s_start_offset /
75 sizeof(uint32_t) + block;
71 } 76 }
72 77
73 loc = udf_block_map(UDF_SB_VAT(sb), newblock); 78 loc = udf_block_map(UDF_SB_VAT(sb), newblock);
74 79
75 if (!(bh = sb_bread(sb, loc))) 80 if (!(bh = sb_bread(sb, loc))) {
76 {
77 udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", 81 udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n",
78 sb, block, partition, loc, index); 82 sb, block, partition, loc, index);
79 return 0xFFFFFFFF; 83 return 0xFFFFFFFF;
80 } 84 }
81 85
82 loc = le32_to_cpu(((__le32 *)bh->b_data)[index]); 86 loc = le32_to_cpu(((__le32 *) bh->b_data)[index]);
83 87
84 brelse(bh); 88 brelse(bh);
85 89
86 if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) 90 if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) {
87 {
88 udf_debug("recursive call to udf_get_pblock!\n"); 91 udf_debug("recursive call to udf_get_pblock!\n");
89 return 0xFFFFFFFF; 92 return 0xFFFFFFFF;
90 } 93 }
91 94
92 return udf_get_pblock(sb, loc, UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum, offset); 95 return udf_get_pblock(sb, loc,
96 UDF_I_LOCATION(UDF_SB_VAT(sb)).
97 partitionReferenceNum, offset);
93} 98}
94 99
95inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 100inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block,
101 uint16_t partition, uint32_t offset)
96{ 102{
97 return udf_get_pblock_virt15(sb, block, partition, offset); 103 return udf_get_pblock_virt15(sb, block, partition, offset);
98} 104}
99 105
100uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, uint16_t partition, uint32_t offset) 106uint32_t udf_get_pblock_spar15(struct super_block * sb, uint32_t block,
107 uint16_t partition, uint32_t offset)
101{ 108{
102 int i; 109 int i;
103 struct sparingTable *st = NULL; 110 struct sparingTable *st = NULL;
104 uint32_t packet = (block + offset) & ~(UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1); 111 uint32_t packet =
112 (block + offset) & ~(UDF_SB_TYPESPAR(sb, partition).s_packet_len -
113 1);
105 114
106 for (i=0; i<4; i++) 115 for (i = 0; i < 4; i++) {
107 { 116 if (UDF_SB_TYPESPAR(sb, partition).s_spar_map[i] != NULL) {
108 if (UDF_SB_TYPESPAR(sb,partition).s_spar_map[i] != NULL) 117 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,
109 { 118 partition).
110 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,partition).s_spar_map[i]->b_data; 119 s_spar_map[i]->b_data;
111 break; 120 break;
112 } 121 }
113 } 122 }
114 123
115 if (st) 124 if (st) {
116 { 125 for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
117 for (i=0; i<le16_to_cpu(st->reallocationTableLen); i++) 126 if (le32_to_cpu(st->mapEntry[i].origLocation) >=
118 { 127 0xFFFFFFF0)
119 if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0)
120 break; 128 break;
121 else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) 129 else if (le32_to_cpu(st->mapEntry[i].origLocation) ==
122 { 130 packet) {
123 return le32_to_cpu(st->mapEntry[i].mappedLocation) + 131 return le32_to_cpu(st->mapEntry[i].
124 ((block + offset) & (UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1)); 132 mappedLocation) + ((block +
125 } 133 offset) &
126 else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) 134 (UDF_SB_TYPESPAR
135 (sb,
136 partition).
137 s_packet_len
138 - 1));
139 } else if (le32_to_cpu(st->mapEntry[i].origLocation) >
140 packet)
127 break; 141 break;
128 } 142 }
129 } 143 }
130 return UDF_SB_PARTROOT(sb,partition) + block + offset; 144 return UDF_SB_PARTROOT(sb, partition) + block + offset;
131} 145}
132 146
133int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) 147int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
@@ -138,19 +152,21 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
138 uint32_t packet; 152 uint32_t packet;
139 int i, j, k, l; 153 int i, j, k, l;
140 154
141 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 155 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
142 { 156 if (old_block > UDF_SB_PARTROOT(sb, i) &&
143 if (old_block > UDF_SB_PARTROOT(sb,i) && 157 old_block < UDF_SB_PARTROOT(sb, i) + UDF_SB_PARTLEN(sb, i))
144 old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i))
145 { 158 {
146 sdata = &UDF_SB_TYPESPAR(sb,i); 159 sdata = &UDF_SB_TYPESPAR(sb, i);
147 packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1); 160 packet =
148 161 (old_block -
149 for (j=0; j<4; j++) 162 UDF_SB_PARTROOT(sb,
150 { 163 i)) & ~(sdata->s_packet_len - 1);
151 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) 164
152 { 165 for (j = 0; j < 4; j++) {
153 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 166 if (UDF_SB_TYPESPAR(sb, i).s_spar_map[j] !=
167 NULL) {
168 st = (struct sparingTable *)sdata->
169 s_spar_map[j]->b_data;
154 break; 170 break;
155 } 171 }
156 } 172 }
@@ -158,60 +174,123 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
158 if (!st) 174 if (!st)
159 return 1; 175 return 1;
160 176
161 for (k=0; k<le16_to_cpu(st->reallocationTableLen); k++) 177 for (k = 0; k < le16_to_cpu(st->reallocationTableLen);
162 { 178 k++) {
163 if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) 179 if (le32_to_cpu(st->mapEntry[k].origLocation) ==
164 { 180 0xFFFFFFFF) {
165 for (; j<4; j++) 181 for (; j < 4; j++) {
166 { 182 if (sdata->s_spar_map[j]) {
167 if (sdata->s_spar_map[j]) 183 st = (struct
168 { 184 sparingTable *)
169 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 185 sdata->
170 st->mapEntry[k].origLocation = cpu_to_le32(packet); 186 s_spar_map[j]->
171 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); 187 b_data;
172 mark_buffer_dirty(sdata->s_spar_map[j]); 188 st->mapEntry[k].
189 origLocation =
190 cpu_to_le32(packet);
191 udf_update_tag((char *)
192 st,
193 sizeof
194 (struct
195 sparingTable)
196 +
197 le16_to_cpu
198 (st->
199 reallocationTableLen)
200 *
201 sizeof
202 (struct
203 sparingEntry));
204 mark_buffer_dirty
205 (sdata->
206 s_spar_map[j]);
173 } 207 }
174 } 208 }
175 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + 209 *new_block =
176 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); 210 le32_to_cpu(st->mapEntry[k].
211 mappedLocation) +
212 ((old_block -
213 UDF_SB_PARTROOT(sb,
214 i)) & (sdata->
215 s_packet_len
216 - 1));
177 return 0; 217 return 0;
178 } 218 } else
179 else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) 219 if (le32_to_cpu
180 { 220 (st->mapEntry[k].origLocation) ==
181 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + 221 packet) {
182 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); 222 *new_block =
223 le32_to_cpu(st->mapEntry[k].
224 mappedLocation) +
225 ((old_block -
226 UDF_SB_PARTROOT(sb,
227 i)) & (sdata->
228 s_packet_len
229 - 1));
183 return 0; 230 return 0;
184 } 231 } else
185 else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) 232 if (le32_to_cpu
233 (st->mapEntry[k].origLocation) > packet)
186 break; 234 break;
187 } 235 }
188 for (l=k; l<le16_to_cpu(st->reallocationTableLen); l++) 236 for (l = k; l < le16_to_cpu(st->reallocationTableLen);
189 { 237 l++) {
190 if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) 238 if (le32_to_cpu(st->mapEntry[l].origLocation) ==
191 { 239 0xFFFFFFFF) {
192 for (; j<4; j++) 240 for (; j < 4; j++) {
193 { 241 if (sdata->s_spar_map[j]) {
194 if (sdata->s_spar_map[j]) 242 st = (struct
195 { 243 sparingTable *)
196 st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; 244 sdata->
197 mapEntry = st->mapEntry[l]; 245 s_spar_map[j]->
198 mapEntry.origLocation = cpu_to_le32(packet); 246 b_data;
199 memmove(&st->mapEntry[k+1], &st->mapEntry[k], (l-k)*sizeof(struct sparingEntry)); 247 mapEntry =
200 st->mapEntry[k] = mapEntry; 248 st->mapEntry[l];
201 udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); 249 mapEntry.origLocation =
202 mark_buffer_dirty(sdata->s_spar_map[j]); 250 cpu_to_le32(packet);
251 memmove(&st->
252 mapEntry[k + 1],
253 &st->
254 mapEntry[k],
255 (l -
256 k) *
257 sizeof(struct
258 sparingEntry));
259 st->mapEntry[k] =
260 mapEntry;
261 udf_update_tag((char *)
262 st,
263 sizeof
264 (struct
265 sparingTable)
266 +
267 le16_to_cpu
268 (st->
269 reallocationTableLen)
270 *
271 sizeof
272 (struct
273 sparingEntry));
274 mark_buffer_dirty
275 (sdata->
276 s_spar_map[j]);
203 } 277 }
204 } 278 }
205 *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + 279 *new_block =
206 ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); 280 le32_to_cpu(st->mapEntry[k].
281 mappedLocation) +
282 ((old_block -
283 UDF_SB_PARTROOT(sb,
284 i)) & (sdata->
285 s_packet_len
286 - 1));
207 return 0; 287 return 0;
208 } 288 }
209 } 289 }
210 return 1; 290 return 1;
211 } 291 }
212 } 292 }
213 if (i == UDF_SB_NUMPARTS(sb)) 293 if (i == UDF_SB_NUMPARTS(sb)) {
214 {
215 /* outside of partitions */ 294 /* outside of partitions */
216 /* for now, fail =) */ 295 /* for now, fail =) */
217 return 1; 296 return 1;
diff --git a/fs/udf/super.c b/fs/udf/super.c
index d6a504f5d758..911387aa1810 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,25 +97,27 @@ 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}
101 105
102static struct file_system_type udf_fstype = { 106static struct file_system_type udf_fstype = {
103 .owner = THIS_MODULE, 107 .owner = THIS_MODULE,
104 .name = "udf", 108 .name = "udf",
105 .get_sb = udf_get_sb, 109 .get_sb = udf_get_sb,
106 .kill_sb = kill_block_super, 110 .kill_sb = kill_block_super,
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{
114 struct udf_inode_info *ei; 118 struct udf_inode_info *ei;
115 ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL); 119 ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep,
120 GFP_KERNEL);
116 if (!ei) 121 if (!ei)
117 return NULL; 122 return NULL;
118 123
@@ -130,9 +135,9 @@ static void udf_destroy_inode(struct inode *inode)
130 kmem_cache_free(udf_inode_cachep, UDF_I(inode)); 135 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
131} 136}
132 137
133static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags) 138static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
134{ 139{
135 struct udf_inode_info *ei = (struct udf_inode_info *) foo; 140 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
136 141
137 ei->i_ext.i_data = NULL; 142 ei->i_ext.i_data = NULL;
138 inode_init_once(&ei->vfs_inode); 143 inode_init_once(&ei->vfs_inode);
@@ -142,8 +147,8 @@ static int init_inodecache(void)
142{ 147{
143 udf_inode_cachep = kmem_cache_create("udf_inode_cache", 148 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
144 sizeof(struct udf_inode_info), 149 sizeof(struct udf_inode_info),
145 0, (SLAB_RECLAIM_ACCOUNT| 150 0, (SLAB_RECLAIM_ACCOUNT |
146 SLAB_MEM_SPREAD), 151 SLAB_MEM_SPREAD),
147 init_once, NULL); 152 init_once, NULL);
148 if (udf_inode_cachep == NULL) 153 if (udf_inode_cachep == NULL)
149 return -ENOMEM; 154 return -ENOMEM;
@@ -157,19 +162,18 @@ static void destroy_inodecache(void)
157 162
158/* Superblock operations */ 163/* Superblock operations */
159static const struct super_operations udf_sb_ops = { 164static const struct super_operations udf_sb_ops = {
160 .alloc_inode = udf_alloc_inode, 165 .alloc_inode = udf_alloc_inode,
161 .destroy_inode = udf_destroy_inode, 166 .destroy_inode = udf_destroy_inode,
162 .write_inode = udf_write_inode, 167 .write_inode = udf_write_inode,
163 .delete_inode = udf_delete_inode, 168 .delete_inode = udf_delete_inode,
164 .clear_inode = udf_clear_inode, 169 .clear_inode = udf_clear_inode,
165 .put_super = udf_put_super, 170 .put_super = udf_put_super,
166 .write_super = udf_write_super, 171 .write_super = udf_write_super,
167 .statfs = udf_statfs, 172 .statfs = udf_statfs,
168 .remount_fs = udf_remount_fs, 173 .remount_fs = udf_remount_fs,
169}; 174};
170 175
171struct udf_options 176struct udf_options {
172{
173 unsigned char novrs; 177 unsigned char novrs;
174 unsigned int blocksize; 178 unsigned int blocksize;
175 unsigned int session; 179 unsigned int session;
@@ -196,9 +200,9 @@ static int __init init_udf_fs(void)
196 if (err) 200 if (err)
197 goto out; 201 goto out;
198 return 0; 202 return 0;
199out: 203 out:
200 destroy_inodecache(); 204 destroy_inodecache();
201out1: 205 out1:
202 return err; 206 return err;
203} 207}
204 208
@@ -209,7 +213,7 @@ static void __exit exit_udf_fs(void)
209} 213}
210 214
211module_init(init_udf_fs) 215module_init(init_udf_fs)
212module_exit(exit_udf_fs) 216 module_exit(exit_udf_fs)
213 217
214/* 218/*
215 * udf_parse_options 219 * udf_parse_options
@@ -264,7 +268,6 @@ module_exit(exit_udf_fs)
264 * July 1, 1997 - Andrew E. Mileski 268 * July 1, 1997 - Andrew E. Mileski
265 * Written, tested, and released. 269 * Written, tested, and released.
266 */ 270 */
267
268enum { 271enum {
269 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete, 272 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
270 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad, 273 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
@@ -303,8 +306,7 @@ static match_table_t tokens = {
303 {Opt_err, NULL} 306 {Opt_err, NULL}
304}; 307};
305 308
306static int 309static int udf_parse_options(char *options, struct udf_options *uopt)
307udf_parse_options(char *options, struct udf_options *uopt)
308{ 310{
309 char *p; 311 char *p;
310 int option; 312 int option;
@@ -323,126 +325,123 @@ udf_parse_options(char *options, struct udf_options *uopt)
323 if (!options) 325 if (!options)
324 return 1; 326 return 1;
325 327
326 while ((p = strsep(&options, ",")) != NULL) 328 while ((p = strsep(&options, ",")) != NULL) {
327 {
328 substring_t args[MAX_OPT_ARGS]; 329 substring_t args[MAX_OPT_ARGS];
329 int token; 330 int token;
330 if (!*p) 331 if (!*p)
331 continue; 332 continue;
332 333
333 token = match_token(p, tokens, args); 334 token = match_token(p, tokens, args);
334 switch (token) 335 switch (token) {
335 { 336 case Opt_novrs:
336 case Opt_novrs: 337 uopt->novrs = 1;
337 uopt->novrs = 1; 338 case Opt_bs:
338 case Opt_bs: 339 if (match_int(&args[0], &option))
339 if (match_int(&args[0], &option)) 340 return 0;
340 return 0; 341 uopt->blocksize = option;
341 uopt->blocksize = option; 342 break;
342 break; 343 case Opt_unhide:
343 case Opt_unhide: 344 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
344 uopt->flags |= (1 << UDF_FLAG_UNHIDE); 345 break;
345 break; 346 case Opt_undelete:
346 case Opt_undelete: 347 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
347 uopt->flags |= (1 << UDF_FLAG_UNDELETE); 348 break;
348 break; 349 case Opt_noadinicb:
349 case Opt_noadinicb: 350 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
350 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB); 351 break;
351 break; 352 case Opt_adinicb:
352 case Opt_adinicb: 353 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
353 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB); 354 break;
354 break; 355 case Opt_shortad:
355 case Opt_shortad: 356 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
356 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD); 357 break;
357 break; 358 case Opt_longad:
358 case Opt_longad: 359 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
359 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD); 360 break;
360 break; 361 case Opt_gid:
361 case Opt_gid: 362 if (match_int(args, &option))
362 if (match_int(args, &option)) 363 return 0;
363 return 0; 364 uopt->gid = option;
364 uopt->gid = option; 365 break;
365 break; 366 case Opt_uid:
366 case Opt_uid: 367 if (match_int(args, &option))
367 if (match_int(args, &option)) 368 return 0;
368 return 0; 369 uopt->uid = option;
369 uopt->uid = option; 370 break;
370 break; 371 case Opt_umask:
371 case Opt_umask: 372 if (match_octal(args, &option))
372 if (match_octal(args, &option)) 373 return 0;
373 return 0; 374 uopt->umask = option;
374 uopt->umask = option; 375 break;
375 break; 376 case Opt_nostrict:
376 case Opt_nostrict: 377 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
377 uopt->flags &= ~(1 << UDF_FLAG_STRICT); 378 break;
378 break; 379 case Opt_session:
379 case Opt_session: 380 if (match_int(args, &option))
380 if (match_int(args, &option)) 381 return 0;
381 return 0; 382 uopt->session = option;
382 uopt->session = option; 383 break;
383 break; 384 case Opt_lastblock:
384 case Opt_lastblock: 385 if (match_int(args, &option))
385 if (match_int(args, &option)) 386 return 0;
386 return 0; 387 uopt->lastblock = option;
387 uopt->lastblock = option; 388 break;
388 break; 389 case Opt_anchor:
389 case Opt_anchor: 390 if (match_int(args, &option))
390 if (match_int(args, &option)) 391 return 0;
391 return 0; 392 uopt->anchor = option;
392 uopt->anchor = option; 393 break;
393 break; 394 case Opt_volume:
394 case Opt_volume: 395 if (match_int(args, &option))
395 if (match_int(args, &option)) 396 return 0;
396 return 0; 397 uopt->volume = option;
397 uopt->volume = option; 398 break;
398 break; 399 case Opt_partition:
399 case Opt_partition: 400 if (match_int(args, &option))
400 if (match_int(args, &option)) 401 return 0;
401 return 0; 402 uopt->partition = option;
402 uopt->partition = option; 403 break;
403 break; 404 case Opt_fileset:
404 case Opt_fileset: 405 if (match_int(args, &option))
405 if (match_int(args, &option)) 406 return 0;
406 return 0; 407 uopt->fileset = option;
407 uopt->fileset = option; 408 break;
408 break; 409 case Opt_rootdir:
409 case Opt_rootdir: 410 if (match_int(args, &option))
410 if (match_int(args, &option)) 411 return 0;
411 return 0; 412 uopt->rootdir = option;
412 uopt->rootdir = option; 413 break;
413 break; 414 case Opt_utf8:
414 case Opt_utf8: 415 uopt->flags |= (1 << UDF_FLAG_UTF8);
415 uopt->flags |= (1 << UDF_FLAG_UTF8); 416 break;
416 break;
417#ifdef CONFIG_UDF_NLS 417#ifdef CONFIG_UDF_NLS
418 case Opt_iocharset: 418 case Opt_iocharset:
419 uopt->nls_map = load_nls(args[0].from); 419 uopt->nls_map = load_nls(args[0].from);
420 uopt->flags |= (1 << UDF_FLAG_NLS_MAP); 420 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
421 break; 421 break;
422#endif 422#endif
423 case Opt_uignore: 423 case Opt_uignore:
424 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE); 424 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
425 break; 425 break;
426 case Opt_uforget: 426 case Opt_uforget:
427 uopt->flags |= (1 << UDF_FLAG_UID_FORGET); 427 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
428 break; 428 break;
429 case Opt_gignore: 429 case Opt_gignore:
430 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE); 430 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
431 break; 431 break;
432 case Opt_gforget: 432 case Opt_gforget:
433 uopt->flags |= (1 << UDF_FLAG_GID_FORGET); 433 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
434 break; 434 break;
435 default: 435 default:
436 printk(KERN_ERR "udf: bad mount option \"%s\" " 436 printk(KERN_ERR "udf: bad mount option \"%s\" "
437 "or missing value\n", p); 437 "or missing value\n", p);
438 return 0; 438 return 0;
439 } 439 }
440 } 440 }
441 return 1; 441 return 1;
442} 442}
443 443
444void 444void udf_write_super(struct super_block *sb)
445udf_write_super(struct super_block *sb)
446{ 445{
447 lock_kernel(); 446 lock_kernel();
448 if (!(sb->s_flags & MS_RDONLY)) 447 if (!(sb->s_flags & MS_RDONLY))
@@ -451,22 +450,21 @@ udf_write_super(struct super_block *sb)
451 unlock_kernel(); 450 unlock_kernel();
452} 451}
453 452
454static int 453static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
455udf_remount_fs(struct super_block *sb, int *flags, char *options)
456{ 454{
457 struct udf_options uopt; 455 struct udf_options uopt;
458 456
459 uopt.flags = UDF_SB(sb)->s_flags ; 457 uopt.flags = UDF_SB(sb)->s_flags;
460 uopt.uid = UDF_SB(sb)->s_uid ; 458 uopt.uid = UDF_SB(sb)->s_uid;
461 uopt.gid = UDF_SB(sb)->s_gid ; 459 uopt.gid = UDF_SB(sb)->s_gid;
462 uopt.umask = UDF_SB(sb)->s_umask ; 460 uopt.umask = UDF_SB(sb)->s_umask;
463 461
464 if ( !udf_parse_options(options, &uopt) ) 462 if (!udf_parse_options(options, &uopt))
465 return -EINVAL; 463 return -EINVAL;
466 464
467 UDF_SB(sb)->s_flags = uopt.flags; 465 UDF_SB(sb)->s_flags = uopt.flags;
468 UDF_SB(sb)->s_uid = uopt.uid; 466 UDF_SB(sb)->s_uid = uopt.uid;
469 UDF_SB(sb)->s_gid = uopt.gid; 467 UDF_SB(sb)->s_gid = uopt.gid;
470 UDF_SB(sb)->s_umask = uopt.umask; 468 UDF_SB(sb)->s_umask = uopt.umask;
471 469
472 if (UDF_SB_LVIDBH(sb)) { 470 if (UDF_SB_LVIDBH(sb)) {
@@ -512,8 +510,7 @@ udf_remount_fs(struct super_block *sb, int *flags, char *options)
512 * July 1, 1997 - Andrew E. Mileski 510 * July 1, 1997 - Andrew E. Mileski
513 * Written, tested, and released. 511 * Written, tested, and released.
514 */ 512 */
515static int 513static int udf_set_blocksize(struct super_block *sb, int bsize)
516udf_set_blocksize(struct super_block *sb, int bsize)
517{ 514{
518 if (!sb_min_blocksize(sb, bsize)) { 515 if (!sb_min_blocksize(sb, bsize)) {
519 udf_debug("Bad block size (%d)\n", bsize); 516 udf_debug("Bad block size (%d)\n", bsize);
@@ -523,16 +520,15 @@ udf_set_blocksize(struct super_block *sb, int bsize)
523 return sb->s_blocksize; 520 return sb->s_blocksize;
524} 521}
525 522
526static int 523static int udf_vrs(struct super_block *sb, int silent)
527udf_vrs(struct super_block *sb, int silent)
528{ 524{
529 struct volStructDesc *vsd = NULL; 525 struct volStructDesc *vsd = NULL;
530 int sector = 32768; 526 int sector = 32768;
531 int sectorsize; 527 int sectorsize;
532 struct buffer_head *bh = NULL; 528 struct buffer_head *bh = NULL;
533 int iso9660=0; 529 int iso9660 = 0;
534 int nsr02=0; 530 int nsr02 = 0;
535 int nsr03=0; 531 int nsr03 = 0;
536 532
537 /* Block size must be a multiple of 512 */ 533 /* Block size must be a multiple of 512 */
538 if (sb->s_blocksize & 511) 534 if (sb->s_blocksize & 511)
@@ -546,10 +542,9 @@ udf_vrs(struct super_block *sb, int silent)
546 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits); 542 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
547 543
548 udf_debug("Starting at sector %u (%ld byte sectors)\n", 544 udf_debug("Starting at sector %u (%ld byte sectors)\n",
549 (sector >> sb->s_blocksize_bits), sb->s_blocksize); 545 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
550 /* Process the sequence (if applicable) */ 546 /* Process the sequence (if applicable) */
551 for (;!nsr02 && !nsr03; sector += sectorsize) 547 for (; !nsr02 && !nsr03; sector += sectorsize) {
552 {
553 /* Read a block */ 548 /* Read a block */
554 bh = udf_tread(sb, sector >> sb->s_blocksize_bits); 549 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
555 if (!bh) 550 if (!bh)
@@ -557,52 +552,56 @@ udf_vrs(struct super_block *sb, int silent)
557 552
558 /* Look for ISO descriptors */ 553 /* Look for ISO descriptors */
559 vsd = (struct volStructDesc *)(bh->b_data + 554 vsd = (struct volStructDesc *)(bh->b_data +
560 (sector & (sb->s_blocksize - 1))); 555 (sector &
556 (sb->s_blocksize - 1)));
561 557
562 if (vsd->stdIdent[0] == 0) 558 if (vsd->stdIdent[0] == 0) {
563 {
564 brelse(bh); 559 brelse(bh);
565 break; 560 break;
566 } 561 } else
567 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) 562 if (!strncmp
568 { 563 (vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
569 iso9660 = sector; 564 iso9660 = sector;
570 switch (vsd->structType) 565 switch (vsd->structType) {
571 { 566 case 0:
572 case 0: 567 udf_debug("ISO9660 Boot Record found\n");
573 udf_debug("ISO9660 Boot Record found\n"); 568 break;
574 break; 569 case 1:
575 case 1: 570 udf_debug
576 udf_debug("ISO9660 Primary Volume Descriptor found\n"); 571 ("ISO9660 Primary Volume Descriptor found\n");
577 break; 572 break;
578 case 2: 573 case 2:
579 udf_debug("ISO9660 Supplementary Volume Descriptor found\n"); 574 udf_debug
580 break; 575 ("ISO9660 Supplementary Volume Descriptor found\n");
581 case 3: 576 break;
582 udf_debug("ISO9660 Volume Partition Descriptor found\n"); 577 case 3:
583 break; 578 udf_debug
584 case 255: 579 ("ISO9660 Volume Partition Descriptor found\n");
585 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n"); 580 break;
586 break; 581 case 255:
587 default: 582 udf_debug
588 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType); 583 ("ISO9660 Volume Descriptor Set Terminator found\n");
589 break; 584 break;
585 default:
586 udf_debug("ISO9660 VRS (%u) found\n",
587 vsd->structType);
588 break;
590 } 589 }
591 } 590 } else
592 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) 591 if (!strncmp
593 { 592 (vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) {
594 } 593 } else
595 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) 594 if (!strncmp
596 { 595 (vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) {
597 brelse(bh); 596 brelse(bh);
598 break; 597 break;
599 } 598 } else
600 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) 599 if (!strncmp
601 { 600 (vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) {
602 nsr02 = sector; 601 nsr02 = sector;
603 } 602 } else
604 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) 603 if (!strncmp
605 { 604 (vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) {
606 nsr03 = sector; 605 nsr03 = sector;
607 } 606 }
608 brelse(bh); 607 brelse(bh);
@@ -635,8 +634,7 @@ udf_vrs(struct super_block *sb, int silent)
635 * July 1, 1997 - Andrew E. Mileski 634 * July 1, 1997 - Andrew E. Mileski
636 * Written, tested, and released. 635 * Written, tested, and released.
637 */ 636 */
638static void 637static void udf_find_anchor(struct super_block *sb)
639udf_find_anchor(struct super_block *sb)
640{ 638{
641 int lastblock = UDF_SB_LASTBLOCK(sb); 639 int lastblock = UDF_SB_LASTBLOCK(sb);
642 struct buffer_head *bh = NULL; 640 struct buffer_head *bh = NULL;
@@ -644,13 +642,13 @@ udf_find_anchor(struct super_block *sb)
644 uint32_t location; 642 uint32_t location;
645 int i; 643 int i;
646 644
647 if (lastblock) 645 if (lastblock) {
648 {
649 int varlastblock = udf_variable_to_fixed(lastblock); 646 int varlastblock = udf_variable_to_fixed(lastblock);
650 int last[] = { lastblock, lastblock - 2, 647 int last[] = { lastblock, lastblock - 2,
651 lastblock - 150, lastblock - 152, 648 lastblock - 150, lastblock - 152,
652 varlastblock, varlastblock - 2, 649 varlastblock, varlastblock - 2,
653 varlastblock - 150, varlastblock - 152 }; 650 varlastblock - 150, varlastblock - 152
651 };
654 652
655 lastblock = 0; 653 lastblock = 0;
656 654
@@ -663,90 +661,103 @@ udf_find_anchor(struct super_block *sb)
663 * however, if the disc isn't closed, it could be 512 */ 661 * however, if the disc isn't closed, it could be 512 */
664 662
665 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) { 663 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
666 if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) 664 if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) {
667 {
668 ident = location = 0; 665 ident = location = 0;
669 } 666 } else {
670 else 667 ident =
671 { 668 le16_to_cpu(((tag *) bh->b_data)->tagIdent);
672 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 669 location =
673 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 670 le32_to_cpu(((tag *) bh->b_data)->
671 tagLocation);
674 brelse(bh); 672 brelse(bh);
675 } 673 }
676 674
677 if (ident == TAG_IDENT_AVDP) 675 if (ident == TAG_IDENT_AVDP) {
678 { 676 if (location == last[i] - UDF_SB_SESSION(sb)) {
679 if (location == last[i] - UDF_SB_SESSION(sb)) 677 lastblock = UDF_SB_ANCHOR(sb)[0] =
680 { 678 last[i] - UDF_SB_SESSION(sb);
681 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb); 679 UDF_SB_ANCHOR(sb)[1] =
682 UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb); 680 last[i] - 256 - UDF_SB_SESSION(sb);
683 } 681 } else if (location ==
684 else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) 682 udf_variable_to_fixed(last[i]) -
685 { 683 UDF_SB_SESSION(sb)) {
686 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 684 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
687 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb); 685 lastblock = UDF_SB_ANCHOR(sb)[0] =
688 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb); 686 udf_variable_to_fixed(last[i]) -
689 } 687 UDF_SB_SESSION(sb);
690 else 688 UDF_SB_ANCHOR(sb)[1] =
691 udf_debug("Anchor found at block %d, location mismatch %d.\n", 689 lastblock - 256 -
692 last[i], location); 690 UDF_SB_SESSION(sb);
693 } 691 } else
694 else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) 692 udf_debug
695 { 693 ("Anchor found at block %d, location mismatch %d.\n",
694 last[i], location);
695 } else if (ident == TAG_IDENT_FE
696 || ident == TAG_IDENT_EFE) {
696 lastblock = last[i]; 697 lastblock = last[i];
697 UDF_SB_ANCHOR(sb)[3] = 512; 698 UDF_SB_ANCHOR(sb)[3] = 512;
698 } 699 } else {
699 else 700 if (last[i] < 256
700 { 701 || !(bh = sb_bread(sb, last[i] - 256))) {
701 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
702 {
703 ident = location = 0; 702 ident = location = 0;
704 } 703 } else {
705 else 704 ident =
706 { 705 le16_to_cpu(((tag *) bh->b_data)->
707 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 706 tagIdent);
708 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 707 location =
708 le32_to_cpu(((tag *) bh->b_data)->
709 tagLocation);
709 brelse(bh); 710 brelse(bh);
710 } 711 }
711 712
712 if (ident == TAG_IDENT_AVDP && 713 if (ident == TAG_IDENT_AVDP &&
713 location == last[i] - 256 - UDF_SB_SESSION(sb)) 714 location ==
714 { 715 last[i] - 256 - UDF_SB_SESSION(sb)) {
715 lastblock = last[i]; 716 lastblock = last[i];
716 UDF_SB_ANCHOR(sb)[1] = last[i] - 256; 717 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
717 } 718 } else {
718 else 719 if (last[i] < 312 + UDF_SB_SESSION(sb)
719 { 720 || !(bh =
720 if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb)))) 721 sb_bread(sb,
722 last[i] - 312 -
723 UDF_SB_SESSION(sb))))
721 { 724 {
722 ident = location = 0; 725 ident = location = 0;
723 } 726 } else {
724 else 727 ident =
725 { 728 le16_to_cpu(((tag *) bh->
726 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 729 b_data)->
727 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 730 tagIdent);
731 location =
732 le32_to_cpu(((tag *) bh->
733 b_data)->
734 tagLocation);
728 brelse(bh); 735 brelse(bh);
729 } 736 }
730 737
731 if (ident == TAG_IDENT_AVDP && 738 if (ident == TAG_IDENT_AVDP &&
732 location == udf_variable_to_fixed(last[i]) - 256) 739 location ==
733 { 740 udf_variable_to_fixed(last[i]) -
734 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 741 256) {
735 lastblock = udf_variable_to_fixed(last[i]); 742 UDF_SET_FLAG(sb,
736 UDF_SB_ANCHOR(sb)[1] = lastblock - 256; 743 UDF_FLAG_VARCONV);
744 lastblock =
745 udf_variable_to_fixed(last
746 [i]);
747 UDF_SB_ANCHOR(sb)[1] =
748 lastblock - 256;
737 } 749 }
738 } 750 }
739 } 751 }
740 } 752 }
741 } 753 }
742 754
743 if (!lastblock) 755 if (!lastblock) {
744 {
745 /* We havn't found the lastblock. check 312 */ 756 /* We havn't found the lastblock. check 312 */
746 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) 757 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) {
747 { 758 ident = le16_to_cpu(((tag *) bh->b_data)->tagIdent);
748 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); 759 location =
749 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); 760 le32_to_cpu(((tag *) bh->b_data)->tagLocation);
750 brelse(bh); 761 brelse(bh);
751 762
752 if (ident == TAG_IDENT_AVDP && location == 256) 763 if (ident == TAG_IDENT_AVDP && location == 256)
@@ -755,18 +766,19 @@ udf_find_anchor(struct super_block *sb)
755 } 766 }
756 767
757 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { 768 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
758 if (UDF_SB_ANCHOR(sb)[i]) 769 if (UDF_SB_ANCHOR(sb)[i]) {
759 {
760 if (!(bh = udf_read_tagged(sb, 770 if (!(bh = udf_read_tagged(sb,
761 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident))) 771 UDF_SB_ANCHOR(sb)[i],
762 { 772 UDF_SB_ANCHOR(sb)[i],
773 &ident))) {
763 UDF_SB_ANCHOR(sb)[i] = 0; 774 UDF_SB_ANCHOR(sb)[i] = 0;
764 } 775 } else {
765 else
766 {
767 brelse(bh); 776 brelse(bh);
768 if ((ident != TAG_IDENT_AVDP) && (i || 777 if ((ident != TAG_IDENT_AVDP) && (i ||
769 (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) 778 (ident !=
779 TAG_IDENT_FE
780 && ident !=
781 TAG_IDENT_EFE)))
770 { 782 {
771 UDF_SB_ANCHOR(sb)[i] = 0; 783 UDF_SB_ANCHOR(sb)[i] = 0;
772 } 784 }
@@ -777,72 +789,75 @@ udf_find_anchor(struct super_block *sb)
777 UDF_SB_LASTBLOCK(sb) = lastblock; 789 UDF_SB_LASTBLOCK(sb) = lastblock;
778} 790}
779 791
780static int 792static int
781udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root) 793udf_find_fileset(struct super_block *sb, kernel_lb_addr * fileset,
794 kernel_lb_addr * root)
782{ 795{
783 struct buffer_head *bh = NULL; 796 struct buffer_head *bh = NULL;
784 long lastblock; 797 long lastblock;
785 uint16_t ident; 798 uint16_t ident;
786 799
787 if (fileset->logicalBlockNum != 0xFFFFFFFF || 800 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
788 fileset->partitionReferenceNum != 0xFFFF) 801 fileset->partitionReferenceNum != 0xFFFF) {
789 {
790 bh = udf_read_ptagged(sb, *fileset, 0, &ident); 802 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
791 803
792 if (!bh) 804 if (!bh)
793 return 1; 805 return 1;
794 else if (ident != TAG_IDENT_FSD) 806 else if (ident != TAG_IDENT_FSD) {
795 {
796 brelse(bh); 807 brelse(bh);
797 return 1; 808 return 1;
798 } 809 }
799 810
800 } 811 }
801 812
802 if (!bh) /* Search backwards through the partitions */ 813 if (!bh) { /* Search backwards through the partitions */
803 {
804 kernel_lb_addr newfileset; 814 kernel_lb_addr newfileset;
805 815
806 return 1; 816 return 1;
807 817
808 for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1; 818 for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
809 (newfileset.partitionReferenceNum != 0xFFFF && 819 (newfileset.partitionReferenceNum != 0xFFFF &&
810 fileset->logicalBlockNum == 0xFFFFFFFF && 820 fileset->logicalBlockNum == 0xFFFFFFFF &&
811 fileset->partitionReferenceNum == 0xFFFF); 821 fileset->partitionReferenceNum == 0xFFFF);
812 newfileset.partitionReferenceNum--) 822 newfileset.partitionReferenceNum--) {
813 { 823 lastblock =
814 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum); 824 UDF_SB_PARTLEN(sb,
825 newfileset.partitionReferenceNum);
815 newfileset.logicalBlockNum = 0; 826 newfileset.logicalBlockNum = 0;
816 827
817 do 828 do {
818 { 829 bh = udf_read_ptagged(sb, newfileset, 0,
819 bh = udf_read_ptagged(sb, newfileset, 0, &ident); 830 &ident);
820 if (!bh) 831 if (!bh) {
821 { 832 newfileset.logicalBlockNum++;
822 newfileset.logicalBlockNum ++;
823 continue; 833 continue;
824 } 834 }
825 835
826 switch (ident) 836 switch (ident) {
827 { 837 case TAG_IDENT_SBD:
828 case TAG_IDENT_SBD:
829 { 838 {
830 struct spaceBitmapDesc *sp; 839 struct spaceBitmapDesc *sp;
831 sp = (struct spaceBitmapDesc *)bh->b_data; 840 sp = (struct spaceBitmapDesc *)
832 newfileset.logicalBlockNum += 1 + 841 bh->b_data;
833 ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1) 842 newfileset.logicalBlockNum +=
834 >> sb->s_blocksize_bits); 843 1 +
844 ((le32_to_cpu
845 (sp->numOfBytes) +
846 sizeof(struct
847 spaceBitmapDesc) -
848 1)
849 >> sb->s_blocksize_bits);
835 brelse(bh); 850 brelse(bh);
836 break; 851 break;
837 } 852 }
838 case TAG_IDENT_FSD: 853 case TAG_IDENT_FSD:
839 { 854 {
840 *fileset = newfileset; 855 *fileset = newfileset;
841 break; 856 break;
842 } 857 }
843 default: 858 default:
844 { 859 {
845 newfileset.logicalBlockNum ++; 860 newfileset.logicalBlockNum++;
846 brelse(bh); 861 brelse(bh);
847 bh = NULL; 862 bh = NULL;
848 break; 863 break;
@@ -850,16 +865,16 @@ udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr
850 } 865 }
851 } 866 }
852 while (newfileset.logicalBlockNum < lastblock && 867 while (newfileset.logicalBlockNum < lastblock &&
853 fileset->logicalBlockNum == 0xFFFFFFFF && 868 fileset->logicalBlockNum == 0xFFFFFFFF &&
854 fileset->partitionReferenceNum == 0xFFFF); 869 fileset->partitionReferenceNum == 0xFFFF);
855 } 870 }
856 } 871 }
857 872
858 if ((fileset->logicalBlockNum != 0xFFFFFFFF || 873 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
859 fileset->partitionReferenceNum != 0xFFFF) && bh) 874 fileset->partitionReferenceNum != 0xFFFF) && bh) {
860 {
861 udf_debug("Fileset at block=%d, partition=%d\n", 875 udf_debug("Fileset at block=%d, partition=%d\n",
862 fileset->logicalBlockNum, fileset->partitionReferenceNum); 876 fileset->logicalBlockNum,
877 fileset->partitionReferenceNum);
863 878
864 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum; 879 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
865 udf_load_fileset(sb, bh, root); 880 udf_load_fileset(sb, bh, root);
@@ -869,8 +884,7 @@ udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr
869 return 1; 884 return 1;
870} 885}
871 886
872static void 887static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
873udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
874{ 888{
875 struct primaryVolDesc *pvoldesc; 889 struct primaryVolDesc *pvoldesc;
876 time_t recording; 890 time_t recording;
@@ -880,37 +894,35 @@ udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
880 894
881 pvoldesc = (struct primaryVolDesc *)bh->b_data; 895 pvoldesc = (struct primaryVolDesc *)bh->b_data;
882 896
883 if ( udf_stamp_to_time(&recording, &recording_usec, 897 if (udf_stamp_to_time(&recording, &recording_usec,
884 lets_to_cpu(pvoldesc->recordingDateAndTime)) ) 898 lets_to_cpu(pvoldesc->recordingDateAndTime))) {
885 {
886 kernel_timestamp ts; 899 kernel_timestamp ts;
887 ts = lets_to_cpu(pvoldesc->recordingDateAndTime); 900 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
888 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n", 901 udf_debug
889 recording, recording_usec, 902 ("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
890 ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone); 903 recording, recording_usec, ts.year, ts.month, ts.day,
904 ts.hour, ts.minute, ts.typeAndTimezone);
891 UDF_SB_RECORDTIME(sb).tv_sec = recording; 905 UDF_SB_RECORDTIME(sb).tv_sec = recording;
892 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000; 906 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
893 } 907 }
894 908
895 if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) ) 909 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
896 { 910 if (udf_CS0toUTF8(&outstr, &instr)) {
897 if (udf_CS0toUTF8(&outstr, &instr)) 911 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); 912 outstr.u_len > 31 ? 31 : outstr.u_len);
901 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb)); 913 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
902 } 914 }
903 } 915 }
904 916
905 if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) ) 917 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
906 {
907 if (udf_CS0toUTF8(&outstr, &instr)) 918 if (udf_CS0toUTF8(&outstr, &instr))
908 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); 919 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
909 } 920 }
910} 921}
911 922
912static void 923static void
913udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr *root) 924udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
925 kernel_lb_addr * root)
914{ 926{
915 struct fileSetDesc *fset; 927 struct fileSetDesc *fset;
916 928
@@ -920,109 +932,154 @@ udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr
920 932
921 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum); 933 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
922 934
923 udf_debug("Rootdir at block=%d, partition=%d\n", 935 udf_debug("Rootdir at block=%d, partition=%d\n",
924 root->logicalBlockNum, root->partitionReferenceNum); 936 root->logicalBlockNum, root->partitionReferenceNum);
925} 937}
926 938
927static void 939static void udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
928udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
929{ 940{
930 struct partitionDesc *p; 941 struct partitionDesc *p;
931 int i; 942 int i;
932 943
933 p = (struct partitionDesc *)bh->b_data; 944 p = (struct partitionDesc *)bh->b_data;
934 945
935 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 946 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
936 { 947 udf_debug("Searching map: (%d == %d)\n",
937 udf_debug("Searching map: (%d == %d)\n", 948 UDF_SB_PARTMAPS(sb)[i].s_partition_num,
938 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber)); 949 le16_to_cpu(p->partitionNumber));
939 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) 950 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num ==
940 { 951 le16_to_cpu(p->partitionNumber)) {
941 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */ 952 UDF_SB_PARTLEN(sb, i) = le32_to_cpu(p->partitionLength); /* blocks */
942 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation); 953 UDF_SB_PARTROOT(sb, i) =
943 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) 954 le32_to_cpu(p->partitionStartingLocation);
944 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY; 955 if (le32_to_cpu(p->accessType) ==
945 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE) 956 PD_ACCESS_TYPE_READ_ONLY)
946 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE; 957 UDF_SB_PARTFLAGS(sb, i) |=
947 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE) 958 UDF_PART_FLAG_READ_ONLY;
948 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE; 959 if (le32_to_cpu(p->accessType) ==
949 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE) 960 PD_ACCESS_TYPE_WRITE_ONCE)
950 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE; 961 UDF_SB_PARTFLAGS(sb, i) |=
951 962 UDF_PART_FLAG_WRITE_ONCE;
952 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) || 963 if (le32_to_cpu(p->accessType) ==
953 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) 964 PD_ACCESS_TYPE_REWRITABLE)
954 { 965 UDF_SB_PARTFLAGS(sb, i) |=
966 UDF_PART_FLAG_REWRITABLE;
967 if (le32_to_cpu(p->accessType) ==
968 PD_ACCESS_TYPE_OVERWRITABLE)
969 UDF_SB_PARTFLAGS(sb, i) |=
970 UDF_PART_FLAG_OVERWRITABLE;
971
972 if (!strcmp
973 (p->partitionContents.ident,
974 PD_PARTITION_CONTENTS_NSR02)
975 || !strcmp(p->partitionContents.ident,
976 PD_PARTITION_CONTENTS_NSR03)) {
955 struct partitionHeaderDesc *phd; 977 struct partitionHeaderDesc *phd;
956 978
957 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); 979 phd =
958 if (phd->unallocSpaceTable.extLength) 980 (struct partitionHeaderDesc *)(p->
959 { 981 partitionContentsUse);
960 kernel_lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i }; 982 if (phd->unallocSpaceTable.extLength) {
961 983 kernel_lb_addr loc =
962 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table = 984 { le32_to_cpu(phd->
963 udf_iget(sb, loc); 985 unallocSpaceTable.
964 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE; 986 extPosition), i };
965 udf_debug("unallocSpaceTable (part %d) @ %ld\n", 987
966 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino); 988 UDF_SB_PARTMAPS(sb)[i].s_uspace.
989 s_table = udf_iget(sb, loc);
990 UDF_SB_PARTFLAGS(sb, i) |=
991 UDF_PART_FLAG_UNALLOC_TABLE;
992 udf_debug
993 ("unallocSpaceTable (part %d) @ %ld\n",
994 i,
995 UDF_SB_PARTMAPS(sb)[i].s_uspace.
996 s_table->i_ino);
967 } 997 }
968 if (phd->unallocSpaceBitmap.extLength) 998 if (phd->unallocSpaceBitmap.extLength) {
969 {
970 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace); 999 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
971 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) 1000 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.
972 { 1001 s_bitmap != NULL) {
973 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength = 1002 UDF_SB_PARTMAPS(sb)[i].s_uspace.
974 le32_to_cpu(phd->unallocSpaceBitmap.extLength); 1003 s_bitmap->s_extLength =
975 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition = 1004 le32_to_cpu(phd->
976 le32_to_cpu(phd->unallocSpaceBitmap.extPosition); 1005 unallocSpaceBitmap.
977 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP; 1006 extLength);
978 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", 1007 UDF_SB_PARTMAPS(sb)[i].s_uspace.
979 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition); 1008 s_bitmap->s_extPosition =
1009 le32_to_cpu(phd->
1010 unallocSpaceBitmap.
1011 extPosition);
1012 UDF_SB_PARTFLAGS(sb, i) |=
1013 UDF_PART_FLAG_UNALLOC_BITMAP;
1014 udf_debug
1015 ("unallocSpaceBitmap (part %d) @ %d\n",
1016 i,
1017 UDF_SB_PARTMAPS(sb)[i].
1018 s_uspace.s_bitmap->
1019 s_extPosition);
980 } 1020 }
981 } 1021 }
982 if (phd->partitionIntegrityTable.extLength) 1022 if (phd->partitionIntegrityTable.extLength)
983 udf_debug("partitionIntegrityTable (part %d)\n", i); 1023 udf_debug
984 if (phd->freedSpaceTable.extLength) 1024 ("partitionIntegrityTable (part %d)\n",
985 { 1025 i);
986 kernel_lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i }; 1026 if (phd->freedSpaceTable.extLength) {
987 1027 kernel_lb_addr loc =
988 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table = 1028 { le32_to_cpu(phd->freedSpaceTable.
989 udf_iget(sb, loc); 1029 extPosition), i };
990 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE; 1030
991 udf_debug("freedSpaceTable (part %d) @ %ld\n", 1031 UDF_SB_PARTMAPS(sb)[i].s_fspace.
992 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino); 1032 s_table = udf_iget(sb, loc);
1033 UDF_SB_PARTFLAGS(sb, i) |=
1034 UDF_PART_FLAG_FREED_TABLE;
1035 udf_debug
1036 ("freedSpaceTable (part %d) @ %ld\n",
1037 i,
1038 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1039 s_table->i_ino);
993 } 1040 }
994 if (phd->freedSpaceBitmap.extLength) 1041 if (phd->freedSpaceBitmap.extLength) {
995 {
996 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace); 1042 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
997 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) 1043 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.
998 { 1044 s_bitmap != NULL) {
999 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength = 1045 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1000 le32_to_cpu(phd->freedSpaceBitmap.extLength); 1046 s_bitmap->s_extLength =
1001 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition = 1047 le32_to_cpu(phd->
1002 le32_to_cpu(phd->freedSpaceBitmap.extPosition); 1048 freedSpaceBitmap.
1003 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP; 1049 extLength);
1004 udf_debug("freedSpaceBitmap (part %d) @ %d\n", 1050 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1005 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition); 1051 s_bitmap->s_extPosition =
1052 le32_to_cpu(phd->
1053 freedSpaceBitmap.
1054 extPosition);
1055 UDF_SB_PARTFLAGS(sb, i) |=
1056 UDF_PART_FLAG_FREED_BITMAP;
1057 udf_debug
1058 ("freedSpaceBitmap (part %d) @ %d\n",
1059 i,
1060 UDF_SB_PARTMAPS(sb)[i].
1061 s_fspace.s_bitmap->
1062 s_extPosition);
1006 } 1063 }
1007 } 1064 }
1008 } 1065 }
1009 break; 1066 break;
1010 } 1067 }
1011 } 1068 }
1012 if (i == UDF_SB_NUMPARTS(sb)) 1069 if (i == UDF_SB_NUMPARTS(sb)) {
1013 { 1070 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)); 1071 le16_to_cpu(p->partitionNumber));
1015 } 1072 } else {
1016 else 1073 udf_debug
1017 { 1074 ("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1018 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n", 1075 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb, i),
1019 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i), 1076 UDF_SB_PARTROOT(sb, i), UDF_SB_PARTLEN(sb, i));
1020 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
1021 } 1077 }
1022} 1078}
1023 1079
1024static int 1080static int
1025udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_addr *fileset) 1081udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1082 kernel_lb_addr * fileset)
1026{ 1083{
1027 struct logicalVolDesc *lvd; 1084 struct logicalVolDesc *lvd;
1028 int i, j, offset; 1085 int i, j, offset;
@@ -1032,82 +1089,114 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1032 1089
1033 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps)); 1090 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1034 1091
1035 for (i=0,offset=0; 1092 for (i = 0, offset = 0;
1036 i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength); 1093 i < UDF_SB_NUMPARTS(sb)
1037 i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) 1094 && offset < le32_to_cpu(lvd->mapTableLength);
1038 { 1095 i++, offset +=
1039 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; 1096 ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->
1040 if (type == 1) 1097 partitionMapLength) {
1041 { 1098 type =
1042 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); 1099 ((struct genericPartitionMap *)
1043 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15; 1100 &(lvd->partitionMaps[offset]))->partitionMapType;
1044 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum); 1101 if (type == 1) {
1045 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum); 1102 struct genericPartitionMap1 *gpm1 =
1046 UDF_SB_PARTFUNC(sb,i) = NULL; 1103 (struct genericPartitionMap1 *)&(lvd->
1047 } 1104 partitionMaps
1048 else if (type == 2) 1105 [offset]);
1049 { 1106 UDF_SB_PARTTYPE(sb, i) = UDF_TYPE1_MAP15;
1050 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); 1107 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(gpm1->volSeqNum);
1051 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) 1108 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(gpm1->partitionNum);
1052 { 1109 UDF_SB_PARTFUNC(sb, i) = NULL;
1053 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) 1110 } else if (type == 2) {
1054 { 1111 struct udfPartitionMap2 *upm2 =
1055 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15; 1112 (struct udfPartitionMap2 *)&(lvd->
1056 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15; 1113 partitionMaps[offset]);
1057 } 1114 if (!strncmp
1058 else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) 1115 (upm2->partIdent.ident, UDF_ID_VIRTUAL,
1059 { 1116 strlen(UDF_ID_VIRTUAL))) {
1060 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20; 1117 if (le16_to_cpu
1061 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20; 1118 (((__le16 *) upm2->partIdent.
1119 identSuffix)[0]) == 0x0150) {
1120 UDF_SB_PARTTYPE(sb, i) =
1121 UDF_VIRTUAL_MAP15;
1122 UDF_SB_PARTFUNC(sb, i) =
1123 udf_get_pblock_virt15;
1124 } else
1125 if (le16_to_cpu
1126 (((__le16 *) upm2->partIdent.
1127 identSuffix)[0]) == 0x0200) {
1128 UDF_SB_PARTTYPE(sb, i) =
1129 UDF_VIRTUAL_MAP20;
1130 UDF_SB_PARTFUNC(sb, i) =
1131 udf_get_pblock_virt20;
1062 } 1132 }
1063 } 1133 } else
1064 else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) 1134 if (!strncmp
1065 { 1135 (upm2->partIdent.ident, UDF_ID_SPARABLE,
1136 strlen(UDF_ID_SPARABLE))) {
1066 uint32_t loc; 1137 uint32_t loc;
1067 uint16_t ident; 1138 uint16_t ident;
1068 struct sparingTable *st; 1139 struct sparingTable *st;
1069 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]); 1140 struct sparablePartitionMap *spm =
1070 1141 (struct sparablePartitionMap *)&(lvd->
1071 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15; 1142 partitionMaps
1072 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength); 1143 [offset]);
1073 for (j=0; j<spm->numSparingTables; j++) 1144
1074 { 1145 UDF_SB_PARTTYPE(sb, i) = UDF_SPARABLE_MAP15;
1075 loc = le32_to_cpu(spm->locSparingTable[j]); 1146 UDF_SB_TYPESPAR(sb, i).s_packet_len =
1076 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = 1147 le16_to_cpu(spm->packetLength);
1077 udf_read_tagged(sb, loc, loc, &ident); 1148 for (j = 0; j < spm->numSparingTables; j++) {
1078 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) 1149 loc =
1079 { 1150 le32_to_cpu(spm->
1080 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data; 1151 locSparingTable[j]);
1081 if (ident != 0 || 1152 UDF_SB_TYPESPAR(sb, i).s_spar_map[j] =
1082 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) 1153 udf_read_tagged(sb, loc, loc,
1154 &ident);
1155 if (UDF_SB_TYPESPAR(sb, i).
1156 s_spar_map[j] != NULL) {
1157 st = (struct sparingTable *)
1158 UDF_SB_TYPESPAR(sb,
1159 i).
1160 s_spar_map[j]->b_data;
1161 if (ident != 0
1162 || strncmp(st->sparingIdent.
1163 ident,
1164 UDF_ID_SPARING,
1165 strlen
1166 (UDF_ID_SPARING)))
1083 { 1167 {
1084 brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]); 1168 brelse(UDF_SB_TYPESPAR
1085 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL; 1169 (sb,
1170 i).
1171 s_spar_map[j]);
1172 UDF_SB_TYPESPAR(sb,
1173 i).
1174 s_spar_map[j] =
1175 NULL;
1086 } 1176 }
1087 } 1177 }
1088 } 1178 }
1089 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15; 1179 UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_spar15;
1090 } 1180 } else {
1091 else 1181 udf_debug("Unknown ident: %s\n",
1092 { 1182 upm2->partIdent.ident);
1093 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
1094 continue; 1183 continue;
1095 } 1184 }
1096 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum); 1185 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(upm2->volSeqNum);
1097 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum); 1186 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(upm2->partitionNum);
1098 } 1187 }
1099 udf_debug("Partition (%d:%d) type %d on volume %d\n", 1188 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1100 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i)); 1189 i, UDF_SB_PARTNUM(sb, i), type, UDF_SB_PARTVSN(sb,
1190 i));
1101 } 1191 }
1102 1192
1103 if (fileset) 1193 if (fileset) {
1104 { 1194 long_ad *la = (long_ad *) & (lvd->logicalVolContentsUse[0]);
1105 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1106 1195
1107 *fileset = lelb_to_cpu(la->extLocation); 1196 *fileset = lelb_to_cpu(la->extLocation);
1108 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n", 1197 udf_debug
1109 fileset->logicalBlockNum, 1198 ("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1110 fileset->partitionReferenceNum); 1199 fileset->logicalBlockNum, fileset->partitionReferenceNum);
1111 } 1200 }
1112 if (lvd->integritySeqExt.extLength) 1201 if (lvd->integritySeqExt.extLength)
1113 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); 1202 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
@@ -1118,26 +1207,26 @@ udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_a
1118 * udf_load_logicalvolint 1207 * udf_load_logicalvolint
1119 * 1208 *
1120 */ 1209 */
1121static void 1210static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1122udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1123{ 1211{
1124 struct buffer_head *bh = NULL; 1212 struct buffer_head *bh = NULL;
1125 uint16_t ident; 1213 uint16_t ident;
1126 1214
1127 while (loc.extLength > 0 && 1215 while (loc.extLength > 0 &&
1128 (bh = udf_read_tagged(sb, loc.extLocation, 1216 (bh = udf_read_tagged(sb, loc.extLocation,
1129 loc.extLocation, &ident)) && 1217 loc.extLocation, &ident)) &&
1130 ident == TAG_IDENT_LVID) 1218 ident == TAG_IDENT_LVID) {
1131 {
1132 UDF_SB_LVIDBH(sb) = bh; 1219 UDF_SB_LVIDBH(sb) = bh;
1133 1220
1134 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength) 1221 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
1135 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt)); 1222 udf_load_logicalvolint(sb,
1136 1223 leea_to_cpu(UDF_SB_LVID(sb)->
1224 nextIntegrityExt));
1225
1137 if (UDF_SB_LVIDBH(sb) != bh) 1226 if (UDF_SB_LVIDBH(sb) != bh)
1138 brelse(bh); 1227 brelse(bh);
1139 loc.extLength -= sb->s_blocksize; 1228 loc.extLength -= sb->s_blocksize;
1140 loc.extLocation ++; 1229 loc.extLocation++;
1141 } 1230 }
1142 if (UDF_SB_LVIDBH(sb) != bh) 1231 if (UDF_SB_LVIDBH(sb) != bh)
1143 brelse(bh); 1232 brelse(bh);
@@ -1158,15 +1247,16 @@ udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1158 * July 1, 1997 - Andrew E. Mileski 1247 * July 1, 1997 - Andrew E. Mileski
1159 * Written, tested, and released. 1248 * Written, tested, and released.
1160 */ 1249 */
1161static int 1250static int
1162udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_lb_addr *fileset) 1251udf_process_sequence(struct super_block *sb, long block, long lastblock,
1252 kernel_lb_addr * fileset)
1163{ 1253{
1164 struct buffer_head *bh = NULL; 1254 struct buffer_head *bh = NULL;
1165 struct udf_vds_record vds[VDS_POS_LENGTH]; 1255 struct udf_vds_record vds[VDS_POS_LENGTH];
1166 struct generic_desc *gd; 1256 struct generic_desc *gd;
1167 struct volDescPtr *vdp; 1257 struct volDescPtr *vdp;
1168 int done=0; 1258 int done = 0;
1169 int i,j; 1259 int i, j;
1170 uint32_t vdsn; 1260 uint32_t vdsn;
1171 uint16_t ident; 1261 uint16_t ident;
1172 long next_s = 0, next_e = 0; 1262 long next_s = 0, next_e = 0;
@@ -1174,93 +1264,92 @@ udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_
1174 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); 1264 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1175 1265
1176 /* Read the main descriptor sequence */ 1266 /* Read the main descriptor sequence */
1177 for (;(!done && block <= lastblock); block++) 1267 for (; (!done && block <= lastblock); block++) {
1178 {
1179 1268
1180 bh = udf_read_tagged(sb, block, block, &ident); 1269 bh = udf_read_tagged(sb, block, block, &ident);
1181 if (!bh) 1270 if (!bh)
1182 break; 1271 break;
1183 1272
1184 /* Process each descriptor (ISO 13346 3/8.3-8.4) */ 1273 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1185 gd = (struct generic_desc *)bh->b_data; 1274 gd = (struct generic_desc *)bh->b_data;
1186 vdsn = le32_to_cpu(gd->volDescSeqNum); 1275 vdsn = le32_to_cpu(gd->volDescSeqNum);
1187 switch (ident) 1276 switch (ident) {
1188 { 1277 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1189 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ 1278 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
1190 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) 1279 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum =
1191 { 1280 vdsn;
1192 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; 1281 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1193 vds[VDS_POS_PRIMARY_VOL_DESC].block = block; 1282 }
1194 } 1283 break;
1195 break; 1284 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1196 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ 1285 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
1197 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) 1286 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1198 { 1287 vds[VDS_POS_VOL_DESC_PTR].block = block;
1199 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; 1288
1200 vds[VDS_POS_VOL_DESC_PTR].block = block; 1289 vdp = (struct volDescPtr *)bh->b_data;
1201 1290 next_s =
1202 vdp = (struct volDescPtr *)bh->b_data; 1291 le32_to_cpu(vdp->nextVolDescSeqExt.
1203 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); 1292 extLocation);
1204 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); 1293 next_e =
1205 next_e = next_e >> sb->s_blocksize_bits; 1294 le32_to_cpu(vdp->nextVolDescSeqExt.
1206 next_e += next_s; 1295 extLength);
1207 } 1296 next_e = next_e >> sb->s_blocksize_bits;
1208 break; 1297 next_e += next_s;
1209 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ 1298 }
1210 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) 1299 break;
1211 { 1300 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1212 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; 1301 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
1213 vds[VDS_POS_IMP_USE_VOL_DESC].block = block; 1302 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum =
1214 } 1303 vdsn;
1215 break; 1304 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1216 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ 1305 }
1217 if (!vds[VDS_POS_PARTITION_DESC].block) 1306 break;
1218 vds[VDS_POS_PARTITION_DESC].block = block; 1307 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1219 break; 1308 if (!vds[VDS_POS_PARTITION_DESC].block)
1220 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ 1309 vds[VDS_POS_PARTITION_DESC].block = block;
1221 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) 1310 break;
1222 { 1311 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1223 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; 1312 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
1224 vds[VDS_POS_LOGICAL_VOL_DESC].block = block; 1313 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum =
1225 } 1314 vdsn;
1226 break; 1315 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1227 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ 1316 }
1228 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) 1317 break;
1229 { 1318 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1230 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; 1319 if (vdsn >=
1231 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; 1320 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
1232 } 1321 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum =
1233 break; 1322 vdsn;
1234 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ 1323 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1235 vds[VDS_POS_TERMINATING_DESC].block = block; 1324 }
1236 if (next_e) 1325 break;
1237 { 1326 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1238 block = next_s; 1327 vds[VDS_POS_TERMINATING_DESC].block = block;
1239 lastblock = next_e; 1328 if (next_e) {
1240 next_s = next_e = 0; 1329 block = next_s;
1241 } 1330 lastblock = next_e;
1242 else 1331 next_s = next_e = 0;
1243 done = 1; 1332 } else
1244 break; 1333 done = 1;
1334 break;
1245 } 1335 }
1246 brelse(bh); 1336 brelse(bh);
1247 } 1337 }
1248 for (i=0; i<VDS_POS_LENGTH; i++) 1338 for (i = 0; i < VDS_POS_LENGTH; i++) {
1249 { 1339 if (vds[i].block) {
1250 if (vds[i].block) 1340 bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
1251 { 1341 &ident);
1252 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
1253 1342
1254 if (i == VDS_POS_PRIMARY_VOL_DESC) 1343 if (i == VDS_POS_PRIMARY_VOL_DESC)
1255 udf_load_pvoldesc(sb, bh); 1344 udf_load_pvoldesc(sb, bh);
1256 else if (i == VDS_POS_LOGICAL_VOL_DESC) 1345 else if (i == VDS_POS_LOGICAL_VOL_DESC)
1257 udf_load_logicalvol(sb, bh, fileset); 1346 udf_load_logicalvol(sb, bh, fileset);
1258 else if (i == VDS_POS_PARTITION_DESC) 1347 else if (i == VDS_POS_PARTITION_DESC) {
1259 {
1260 struct buffer_head *bh2 = NULL; 1348 struct buffer_head *bh2 = NULL;
1261 udf_load_partdesc(sb, bh); 1349 udf_load_partdesc(sb, bh);
1262 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++) 1350 for (j = vds[i].block + 1;
1263 { 1351 j < vds[VDS_POS_TERMINATING_DESC].block;
1352 j++) {
1264 bh2 = udf_read_tagged(sb, j, j, &ident); 1353 bh2 = udf_read_tagged(sb, j, j, &ident);
1265 gd = (struct generic_desc *)bh2->b_data; 1354 gd = (struct generic_desc *)bh2->b_data;
1266 if (ident == TAG_IDENT_PD) 1355 if (ident == TAG_IDENT_PD)
@@ -1278,31 +1367,27 @@ udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_
1278/* 1367/*
1279 * udf_check_valid() 1368 * udf_check_valid()
1280 */ 1369 */
1281static int 1370static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1282udf_check_valid(struct super_block *sb, int novrs, int silent)
1283{ 1371{
1284 long block; 1372 long block;
1285 1373
1286 if (novrs) 1374 if (novrs) {
1287 {
1288 udf_debug("Validity check skipped because of novrs option\n"); 1375 udf_debug("Validity check skipped because of novrs option\n");
1289 return 0; 1376 return 0;
1290 } 1377 }
1291 /* Check that it is NSR02 compliant */ 1378 /* Check that it is NSR02 compliant */
1292 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ 1379 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1293 else if ((block = udf_vrs(sb, silent)) == -1) 1380 else if ((block = udf_vrs(sb, silent)) == -1) {
1294 { 1381 udf_debug
1295 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n"); 1382 ("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1296 if (!UDF_SB_LASTBLOCK(sb)) 1383 if (!UDF_SB_LASTBLOCK(sb))
1297 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); 1384 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1298 return 0; 1385 return 0;
1299 } 1386 } else
1300 else
1301 return !block; 1387 return !block;
1302} 1388}
1303 1389
1304static int 1390static int udf_load_partition(struct super_block *sb, kernel_lb_addr * fileset)
1305udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1306{ 1391{
1307 struct anchorVolDescPtr *anchor; 1392 struct anchorVolDescPtr *anchor;
1308 uint16_t ident; 1393 uint16_t ident;
@@ -1315,19 +1400,27 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1315 1400
1316 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { 1401 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
1317 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb, 1402 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1318 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident))) 1403 UDF_SB_ANCHOR
1319 { 1404 (sb)[i],
1405 UDF_SB_ANCHOR
1406 (sb)[i],
1407 &ident))) {
1320 anchor = (struct anchorVolDescPtr *)bh->b_data; 1408 anchor = (struct anchorVolDescPtr *)bh->b_data;
1321 1409
1322 /* Locate the main sequence */ 1410 /* Locate the main sequence */
1323 main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation ); 1411 main_s =
1324 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength ); 1412 le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1413 main_e =
1414 le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
1325 main_e = main_e >> sb->s_blocksize_bits; 1415 main_e = main_e >> sb->s_blocksize_bits;
1326 main_e += main_s; 1416 main_e += main_s;
1327 1417
1328 /* Locate the reserve sequence */ 1418 /* Locate the reserve sequence */
1329 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); 1419 reserve_s =
1330 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); 1420 le32_to_cpu(anchor->reserveVolDescSeqExt.
1421 extLocation);
1422 reserve_e =
1423 le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1331 reserve_e = reserve_e >> sb->s_blocksize_bits; 1424 reserve_e = reserve_e >> sb->s_blocksize_bits;
1332 reserve_e += reserve_s; 1425 reserve_e += reserve_s;
1333 1426
@@ -1335,9 +1428,10 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1335 1428
1336 /* Process the main & reserve sequences */ 1429 /* Process the main & reserve sequences */
1337 /* responsible for finding the PartitionDesc(s) */ 1430 /* responsible for finding the PartitionDesc(s) */
1338 if (!(udf_process_sequence(sb, main_s, main_e, fileset) && 1431 if (!
1339 udf_process_sequence(sb, reserve_s, reserve_e, fileset))) 1432 (udf_process_sequence(sb, main_s, main_e, fileset)
1340 { 1433 && udf_process_sequence(sb, reserve_s, reserve_e,
1434 fileset))) {
1341 break; 1435 break;
1342 } 1436 }
1343 } 1437 }
@@ -1349,36 +1443,37 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1349 } else 1443 } else
1350 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]); 1444 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1351 1445
1352 for (i=0; i<UDF_SB_NUMPARTS(sb); i++) 1446 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
1353 { 1447 switch (UDF_SB_PARTTYPE(sb, i)) {
1354 switch (UDF_SB_PARTTYPE(sb, i)) 1448 case UDF_VIRTUAL_MAP15:
1355 { 1449 case UDF_VIRTUAL_MAP20:
1356 case UDF_VIRTUAL_MAP15:
1357 case UDF_VIRTUAL_MAP20:
1358 { 1450 {
1359 kernel_lb_addr uninitialized_var(ino); 1451 kernel_lb_addr uninitialized_var(ino);
1360 1452
1361 if (!UDF_SB_LASTBLOCK(sb)) 1453 if (!UDF_SB_LASTBLOCK(sb)) {
1362 { 1454 UDF_SB_LASTBLOCK(sb) =
1363 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); 1455 udf_get_last_block(sb);
1364 udf_find_anchor(sb); 1456 udf_find_anchor(sb);
1365 } 1457 }
1366 1458
1367 if (!UDF_SB_LASTBLOCK(sb)) 1459 if (!UDF_SB_LASTBLOCK(sb)) {
1368 { 1460 udf_debug
1369 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n"); 1461 ("Unable to determine Lastblock (For Virtual Partition)\n");
1370 return 1; 1462 return 1;
1371 } 1463 }
1372 1464
1373 for (j=0; j<UDF_SB_NUMPARTS(sb); j++) 1465 for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
1374 {
1375 if (j != i && 1466 if (j != i &&
1376 UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) && 1467 UDF_SB_PARTVSN(sb,
1377 UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j)) 1468 i) ==
1378 { 1469 UDF_SB_PARTVSN(sb, j)
1470 && UDF_SB_PARTNUM(sb,
1471 i) ==
1472 UDF_SB_PARTNUM(sb, j)) {
1379 ino.partitionReferenceNum = j; 1473 ino.partitionReferenceNum = j;
1380 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) - 1474 ino.logicalBlockNum =
1381 UDF_SB_PARTROOT(sb,j); 1475 UDF_SB_LASTBLOCK(sb) -
1476 UDF_SB_PARTROOT(sb, j);
1382 break; 1477 break;
1383 } 1478 }
1384 } 1479 }
@@ -1389,13 +1484,13 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1389 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino))) 1484 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1390 return 1; 1485 return 1;
1391 1486
1392 if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15) 1487 if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
1393 { 1488 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
1394 UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb)); 1489 udf_ext0_offset(UDF_SB_VAT(sb));
1395 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2; 1490 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1396 } 1491 (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1397 else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20) 1492 } else if (UDF_SB_PARTTYPE(sb, i) ==
1398 { 1493 UDF_VIRTUAL_MAP20) {
1399 struct buffer_head *bh = NULL; 1494 struct buffer_head *bh = NULL;
1400 uint32_t pos; 1495 uint32_t pos;
1401 1496
@@ -1403,15 +1498,26 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1403 bh = sb_bread(sb, pos); 1498 bh = sb_bread(sb, pos);
1404 if (!bh) 1499 if (!bh)
1405 return 1; 1500 return 1;
1406 UDF_SB_TYPEVIRT(sb,i).s_start_offset = 1501 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) + 1502 le16_to_cpu(((struct
1408 udf_ext0_offset(UDF_SB_VAT(sb)); 1503 virtualAllocationTable20
1409 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 1504 *)bh->b_data +
1410 UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2; 1505 udf_ext0_offset
1506 (UDF_SB_VAT(sb)))->
1507 lengthHeader) +
1508 udf_ext0_offset(UDF_SB_VAT(sb));
1509 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1510 (UDF_SB_VAT(sb)->i_size -
1511 UDF_SB_TYPEVIRT(sb,
1512 i).
1513 s_start_offset) >> 2;
1411 brelse(bh); 1514 brelse(bh);
1412 } 1515 }
1413 UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0); 1516 UDF_SB_PARTROOT(sb, i) =
1414 UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum); 1517 udf_get_pblock(sb, 0, i, 0);
1518 UDF_SB_PARTLEN(sb, i) =
1519 UDF_SB_PARTLEN(sb,
1520 ino.partitionReferenceNum);
1415 } 1521 }
1416 } 1522 }
1417 } 1523 }
@@ -1420,26 +1526,28 @@ udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1420 1526
1421static void udf_open_lvid(struct super_block *sb) 1527static void udf_open_lvid(struct super_block *sb)
1422{ 1528{
1423 if (UDF_SB_LVIDBH(sb)) 1529 if (UDF_SB_LVIDBH(sb)) {
1424 {
1425 int i; 1530 int i;
1426 kernel_timestamp cpu_time; 1531 kernel_timestamp cpu_time;
1427 1532
1428 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1533 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1429 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1534 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1430 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) 1535 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1431 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); 1536 UDF_SB_LVID(sb)->recordingDateAndTime =
1537 cpu_to_lets(cpu_time);
1432 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN; 1538 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1433 1539
1434 UDF_SB_LVID(sb)->descTag.descCRC = 1540 UDF_SB_LVID(sb)->descTag.descCRC =
1435 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), 1541 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1436 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); 1542 le16_to_cpu(UDF_SB_LVID(sb)->descTag.
1543 descCRCLength), 0));
1437 1544
1438 UDF_SB_LVID(sb)->descTag.tagChecksum = 0; 1545 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1439 for (i=0; i<16; i++) 1546 for (i = 0; i < 16; i++)
1440 if (i != 4) 1547 if (i != 4)
1441 UDF_SB_LVID(sb)->descTag.tagChecksum += 1548 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1442 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; 1549 ((uint8_t *) &
1550 (UDF_SB_LVID(sb)->descTag))[i];
1443 1551
1444 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 1552 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1445 } 1553 }
@@ -1448,32 +1556,41 @@ static void udf_open_lvid(struct super_block *sb)
1448static void udf_close_lvid(struct super_block *sb) 1556static void udf_close_lvid(struct super_block *sb)
1449{ 1557{
1450 if (UDF_SB_LVIDBH(sb) && 1558 if (UDF_SB_LVIDBH(sb) &&
1451 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) 1559 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
1452 {
1453 int i; 1560 int i;
1454 kernel_timestamp cpu_time; 1561 kernel_timestamp cpu_time;
1455 1562
1456 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1563 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1457 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1564 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1458 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) 1565 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1459 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); 1566 UDF_SB_LVID(sb)->recordingDateAndTime =
1460 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev)) 1567 cpu_to_lets(cpu_time);
1461 UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); 1568 if (UDF_MAX_WRITE_VERSION >
1462 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev)) 1569 le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1463 UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb)); 1570 UDF_SB_LVIDIU(sb)->maxUDFWriteRev =
1464 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev)) 1571 cpu_to_le16(UDF_MAX_WRITE_VERSION);
1465 UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb)); 1572 if (UDF_SB_UDFREV(sb) >
1466 UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); 1573 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1574 UDF_SB_LVIDIU(sb)->minUDFReadRev =
1575 cpu_to_le16(UDF_SB_UDFREV(sb));
1576 if (UDF_SB_UDFREV(sb) >
1577 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1578 UDF_SB_LVIDIU(sb)->minUDFWriteRev =
1579 cpu_to_le16(UDF_SB_UDFREV(sb));
1580 UDF_SB_LVID(sb)->integrityType =
1581 cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1467 1582
1468 UDF_SB_LVID(sb)->descTag.descCRC = 1583 UDF_SB_LVID(sb)->descTag.descCRC =
1469 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), 1584 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1470 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); 1585 le16_to_cpu(UDF_SB_LVID(sb)->descTag.
1586 descCRCLength), 0));
1471 1587
1472 UDF_SB_LVID(sb)->descTag.tagChecksum = 0; 1588 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1473 for (i=0; i<16; i++) 1589 for (i = 0; i < 16; i++)
1474 if (i != 4) 1590 if (i != 4)
1475 UDF_SB_LVID(sb)->descTag.tagChecksum += 1591 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1476 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; 1592 ((uint8_t *) &
1593 (UDF_SB_LVID(sb)->descTag))[i];
1477 1594
1478 mark_buffer_dirty(UDF_SB_LVIDBH(sb)); 1595 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1479 } 1596 }
@@ -1498,7 +1615,7 @@ static void udf_close_lvid(struct super_block *sb)
1498static int udf_fill_super(struct super_block *sb, void *options, int silent) 1615static int udf_fill_super(struct super_block *sb, void *options, int silent)
1499{ 1616{
1500 int i; 1617 int i;
1501 struct inode *inode=NULL; 1618 struct inode *inode = NULL;
1502 struct udf_options uopt; 1619 struct udf_options uopt;
1503 kernel_lb_addr rootdir, fileset; 1620 kernel_lb_addr rootdir, fileset;
1504 struct udf_sb_info *sbi; 1621 struct udf_sb_info *sbi;
@@ -1520,15 +1637,13 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1520 goto error_out; 1637 goto error_out;
1521 1638
1522 if (uopt.flags & (1 << UDF_FLAG_UTF8) && 1639 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1523 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) 1640 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
1524 {
1525 udf_error(sb, "udf_read_super", 1641 udf_error(sb, "udf_read_super",
1526 "utf8 cannot be combined with iocharset\n"); 1642 "utf8 cannot be combined with iocharset\n");
1527 goto error_out; 1643 goto error_out;
1528 } 1644 }
1529#ifdef CONFIG_UDF_NLS 1645#ifdef CONFIG_UDF_NLS
1530 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) 1646 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
1531 {
1532 uopt.nls_map = load_nls_default(); 1647 uopt.nls_map = load_nls_default();
1533 if (!uopt.nls_map) 1648 if (!uopt.nls_map)
1534 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP); 1649 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
@@ -1552,7 +1667,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1552 if (!udf_set_blocksize(sb, uopt.blocksize)) 1667 if (!udf_set_blocksize(sb, uopt.blocksize))
1553 goto error_out; 1668 goto error_out;
1554 1669
1555 if ( uopt.session == 0xFFFFFFFF ) 1670 if (uopt.session == 0xFFFFFFFF)
1556 UDF_SB_SESSION(sb) = udf_get_last_session(sb); 1671 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1557 else 1672 else
1558 UDF_SB_SESSION(sb) = uopt.session; 1673 UDF_SB_SESSION(sb) = uopt.session;
@@ -1564,10 +1679,9 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1564 UDF_SB_ANCHOR(sb)[2] = uopt.anchor; 1679 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1565 UDF_SB_ANCHOR(sb)[3] = 256; 1680 UDF_SB_ANCHOR(sb)[3] = 256;
1566 1681
1567 if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */ 1682 if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */
1568 {
1569 printk("UDF-fs: No VRS found\n"); 1683 printk("UDF-fs: No VRS found\n");
1570 goto error_out; 1684 goto error_out;
1571 } 1685 }
1572 1686
1573 udf_find_anchor(sb); 1687 udf_find_anchor(sb);
@@ -1579,29 +1693,26 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1579 sb->s_magic = UDF_SUPER_MAGIC; 1693 sb->s_magic = UDF_SUPER_MAGIC;
1580 sb->s_time_gran = 1000; 1694 sb->s_time_gran = 1000;
1581 1695
1582 if (udf_load_partition(sb, &fileset)) 1696 if (udf_load_partition(sb, &fileset)) {
1583 {
1584 printk("UDF-fs: No partition found (1)\n"); 1697 printk("UDF-fs: No partition found (1)\n");
1585 goto error_out; 1698 goto error_out;
1586 } 1699 }
1587 1700
1588 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb)); 1701 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1589 1702
1590 if ( UDF_SB_LVIDBH(sb) ) 1703 if (UDF_SB_LVIDBH(sb)) {
1591 { 1704 uint16_t minUDFReadRev =
1592 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev); 1705 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1593 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); 1706 uint16_t minUDFWriteRev =
1707 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1594 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */ 1708 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1595 1709
1596 if (minUDFReadRev > UDF_MAX_READ_VERSION) 1710 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
1597 {
1598 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n", 1711 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1599 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev), 1712 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1600 UDF_MAX_READ_VERSION); 1713 UDF_MAX_READ_VERSION);
1601 goto error_out; 1714 goto error_out;
1602 } 1715 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
1603 else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1604 {
1605 sb->s_flags |= MS_RDONLY; 1716 sb->s_flags |= MS_RDONLY;
1606 } 1717 }
1607 1718
@@ -1613,31 +1724,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1613 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); 1724 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1614 } 1725 }
1615 1726
1616 if ( !UDF_SB_NUMPARTS(sb) ) 1727 if (!UDF_SB_NUMPARTS(sb)) {
1617 {
1618 printk("UDF-fs: No partition found (2)\n"); 1728 printk("UDF-fs: No partition found (2)\n");
1619 goto error_out; 1729 goto error_out;
1620 } 1730 }
1621 1731
1622 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_READ_ONLY) { 1732 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1623 printk("UDF-fs: Partition marked readonly; forcing readonly mount\n"); 1733 UDF_PART_FLAG_READ_ONLY) {
1734 printk
1735 ("UDF-fs: Partition marked readonly; forcing readonly mount\n");
1624 sb->s_flags |= MS_RDONLY; 1736 sb->s_flags |= MS_RDONLY;
1625 } 1737 }
1626 1738
1627 if ( udf_find_fileset(sb, &fileset, &rootdir) ) 1739 if (udf_find_fileset(sb, &fileset, &rootdir)) {
1628 {
1629 printk("UDF-fs: No fileset found\n"); 1740 printk("UDF-fs: No fileset found\n");
1630 goto error_out; 1741 goto error_out;
1631 } 1742 }
1632 1743
1633 if (!silent) 1744 if (!silent) {
1634 {
1635 kernel_timestamp ts; 1745 kernel_timestamp ts;
1636 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb)); 1746 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", 1747 udf_info
1638 UDFFS_VERSION, UDFFS_DATE, 1748 ("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1639 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute, 1749 UDFFS_VERSION, UDFFS_DATE, UDF_SB_VOLIDENT(sb), ts.year,
1640 ts.typeAndTimezone); 1750 ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
1641 } 1751 }
1642 if (!(sb->s_flags & MS_RDONLY)) 1752 if (!(sb->s_flags & MS_RDONLY))
1643 udf_open_lvid(sb); 1753 udf_open_lvid(sb);
@@ -1645,18 +1755,16 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1645 /* Assign the root inode */ 1755 /* Assign the root inode */
1646 /* assign inodes by physical block number */ 1756 /* assign inodes by physical block number */
1647 /* perhaps it's not extensible enough, but for now ... */ 1757 /* perhaps it's not extensible enough, but for now ... */
1648 inode = udf_iget(sb, rootdir); 1758 inode = udf_iget(sb, rootdir);
1649 if (!inode) 1759 if (!inode) {
1650 {
1651 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n", 1760 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1652 rootdir.logicalBlockNum, rootdir.partitionReferenceNum); 1761 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1653 goto error_out; 1762 goto error_out;
1654 } 1763 }
1655 1764
1656 /* Allocate a dentry for the root inode */ 1765 /* Allocate a dentry for the root inode */
1657 sb->s_root = d_alloc_root(inode); 1766 sb->s_root = d_alloc_root(inode);
1658 if (!sb->s_root) 1767 if (!sb->s_root) {
1659 {
1660 printk("UDF-fs: Couldn't allocate root dentry\n"); 1768 printk("UDF-fs: Couldn't allocate root dentry\n");
1661 iput(inode); 1769 iput(inode);
1662 goto error_out; 1770 goto error_out;
@@ -1664,23 +1772,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1664 sb->s_maxbytes = MAX_LFS_FILESIZE; 1772 sb->s_maxbytes = MAX_LFS_FILESIZE;
1665 return 0; 1773 return 0;
1666 1774
1667error_out: 1775 error_out:
1668 if (UDF_SB_VAT(sb)) 1776 if (UDF_SB_VAT(sb))
1669 iput(UDF_SB_VAT(sb)); 1777 iput(UDF_SB_VAT(sb));
1670 if (UDF_SB_NUMPARTS(sb)) 1778 if (UDF_SB_NUMPARTS(sb)) {
1671 { 1779 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1672 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 1780 UDF_PART_FLAG_UNALLOC_TABLE)
1673 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 1781 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
1674 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 1782 s_table);
1675 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 1783 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1676 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 1784 UDF_PART_FLAG_FREED_TABLE)
1677 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace); 1785 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
1678 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 1786 s_table);
1679 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace); 1787 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1680 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) 1788 UDF_PART_FLAG_UNALLOC_BITMAP)
1681 { 1789 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
1682 for (i=0; i<4; i++) 1790 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1683 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); 1791 UDF_PART_FLAG_FREED_BITMAP)
1792 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
1793 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
1794 UDF_SPARABLE_MAP15) {
1795 for (i = 0; i < 4; i++)
1796 brelse(UDF_SB_TYPESPAR
1797 (sb,
1798 UDF_SB_PARTITION(sb)).s_spar_map[i]);
1684 } 1799 }
1685 } 1800 }
1686#ifdef CONFIG_UDF_NLS 1801#ifdef CONFIG_UDF_NLS
@@ -1697,32 +1812,31 @@ error_out:
1697} 1812}
1698 1813
1699void udf_error(struct super_block *sb, const char *function, 1814void udf_error(struct super_block *sb, const char *function,
1700 const char *fmt, ...) 1815 const char *fmt, ...)
1701{ 1816{
1702 va_list args; 1817 va_list args;
1703 1818
1704 if (!(sb->s_flags & MS_RDONLY)) 1819 if (!(sb->s_flags & MS_RDONLY)) {
1705 {
1706 /* mark sb error */ 1820 /* mark sb error */
1707 sb->s_dirt = 1; 1821 sb->s_dirt = 1;
1708 } 1822 }
1709 va_start(args, fmt); 1823 va_start(args, fmt);
1710 vsnprintf(error_buf, sizeof(error_buf), fmt, args); 1824 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1711 va_end(args); 1825 va_end(args);
1712 printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n", 1826 printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1713 sb->s_id, function, error_buf); 1827 sb->s_id, function, error_buf);
1714} 1828}
1715 1829
1716void udf_warning(struct super_block *sb, const char *function, 1830void udf_warning(struct super_block *sb, const char *function,
1717 const char *fmt, ...) 1831 const char *fmt, ...)
1718{ 1832{
1719 va_list args; 1833 va_list args;
1720 1834
1721 va_start (args, fmt); 1835 va_start(args, fmt);
1722 vsnprintf(error_buf, sizeof(error_buf), fmt, args); 1836 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1723 va_end(args); 1837 va_end(args);
1724 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n", 1838 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1725 sb->s_id, function, error_buf); 1839 sb->s_id, function, error_buf);
1726} 1840}
1727 1841
1728/* 1842/*
@@ -1738,27 +1852,33 @@ void udf_warning(struct super_block *sb, const char *function,
1738 * July 1, 1997 - Andrew E. Mileski 1852 * July 1, 1997 - Andrew E. Mileski
1739 * Written, tested, and released. 1853 * Written, tested, and released.
1740 */ 1854 */
1741static void 1855static void udf_put_super(struct super_block *sb)
1742udf_put_super(struct super_block *sb)
1743{ 1856{
1744 int i; 1857 int i;
1745 1858
1746 if (UDF_SB_VAT(sb)) 1859 if (UDF_SB_VAT(sb))
1747 iput(UDF_SB_VAT(sb)); 1860 iput(UDF_SB_VAT(sb));
1748 if (UDF_SB_NUMPARTS(sb)) 1861 if (UDF_SB_NUMPARTS(sb)) {
1749 { 1862 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1750 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 1863 UDF_PART_FLAG_UNALLOC_TABLE)
1751 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 1864 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
1752 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 1865 s_table);
1753 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 1866 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1754 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 1867 UDF_PART_FLAG_FREED_TABLE)
1755 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace); 1868 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
1756 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 1869 s_table);
1757 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace); 1870 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1758 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) 1871 UDF_PART_FLAG_UNALLOC_BITMAP)
1759 { 1872 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
1760 for (i=0; i<4; i++) 1873 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1761 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); 1874 UDF_PART_FLAG_FREED_BITMAP)
1875 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
1876 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
1877 UDF_SPARABLE_MAP15) {
1878 for (i = 0; i < 4; i++)
1879 brelse(UDF_SB_TYPESPAR
1880 (sb,
1881 UDF_SB_PARTITION(sb)).s_spar_map[i]);
1762 } 1882 }
1763 } 1883 }
1764#ifdef CONFIG_UDF_NLS 1884#ifdef CONFIG_UDF_NLS
@@ -1786,8 +1906,7 @@ udf_put_super(struct super_block *sb)
1786 * July 1, 1997 - Andrew E. Mileski 1906 * July 1, 1997 - Andrew E. Mileski
1787 * Written, tested, and released. 1907 * Written, tested, and released.
1788 */ 1908 */
1789static int 1909static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1790udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1791{ 1910{
1792 struct super_block *sb = dentry->d_sb; 1911 struct super_block *sb = dentry->d_sb;
1793 1912
@@ -1797,11 +1916,12 @@ udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1797 buf->f_bfree = udf_count_free(sb); 1916 buf->f_bfree = udf_count_free(sb);
1798 buf->f_bavail = buf->f_bfree; 1917 buf->f_bavail = buf->f_bfree;
1799 buf->f_files = (UDF_SB_LVIDBH(sb) ? 1918 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1800 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1919 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1801 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree; 1920 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) +
1921 buf->f_bfree;
1802 buf->f_ffree = buf->f_bfree; 1922 buf->f_ffree = buf->f_bfree;
1803 /* __kernel_fsid_t f_fsid */ 1923 /* __kernel_fsid_t f_fsid */
1804 buf->f_namelen = UDF_NAME_LEN-2; 1924 buf->f_namelen = UDF_NAME_LEN - 2;
1805 1925
1806 return 0; 1926 return 0;
1807} 1927}
@@ -1830,13 +1950,10 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1830 loc.partitionReferenceNum = UDF_SB_PARTITION(sb); 1950 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1831 bh = udf_read_ptagged(sb, loc, 0, &ident); 1951 bh = udf_read_ptagged(sb, loc, 0, &ident);
1832 1952
1833 if (!bh) 1953 if (!bh) {
1834 {
1835 printk(KERN_ERR "udf: udf_count_free failed\n"); 1954 printk(KERN_ERR "udf: udf_count_free failed\n");
1836 goto out; 1955 goto out;
1837 } 1956 } else if (ident != TAG_IDENT_SBD) {
1838 else if (ident != TAG_IDENT_SBD)
1839 {
1840 brelse(bh); 1957 brelse(bh);
1841 printk(KERN_ERR "udf: udf_count_free failed\n"); 1958 printk(KERN_ERR "udf: udf_count_free failed\n");
1842 goto out; 1959 goto out;
@@ -1844,43 +1961,39 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1844 1961
1845 bm = (struct spaceBitmapDesc *)bh->b_data; 1962 bm = (struct spaceBitmapDesc *)bh->b_data;
1846 bytes = le32_to_cpu(bm->numOfBytes); 1963 bytes = le32_to_cpu(bm->numOfBytes);
1847 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ 1964 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1848 ptr = (uint8_t *)bh->b_data; 1965 ptr = (uint8_t *) bh->b_data;
1849 1966
1850 while ( bytes > 0 ) 1967 while (bytes > 0) {
1851 { 1968 while ((bytes > 0) && (index < sb->s_blocksize)) {
1852 while ((bytes > 0) && (index < sb->s_blocksize))
1853 {
1854 value = ptr[index]; 1969 value = ptr[index];
1855 accum += udf_bitmap_lookup[ value & 0x0f ]; 1970 accum += udf_bitmap_lookup[value & 0x0f];
1856 accum += udf_bitmap_lookup[ value >> 4 ]; 1971 accum += udf_bitmap_lookup[value >> 4];
1857 index++; 1972 index++;
1858 bytes--; 1973 bytes--;
1859 } 1974 }
1860 if ( bytes ) 1975 if (bytes) {
1861 {
1862 brelse(bh); 1976 brelse(bh);
1863 newblock = udf_get_lb_pblock(sb, loc, ++block); 1977 newblock = udf_get_lb_pblock(sb, loc, ++block);
1864 bh = udf_tread(sb, newblock); 1978 bh = udf_tread(sb, newblock);
1865 if (!bh) 1979 if (!bh) {
1866 {
1867 udf_debug("read failed\n"); 1980 udf_debug("read failed\n");
1868 goto out; 1981 goto out;
1869 } 1982 }
1870 index = 0; 1983 index = 0;
1871 ptr = (uint8_t *)bh->b_data; 1984 ptr = (uint8_t *) bh->b_data;
1872 } 1985 }
1873 } 1986 }
1874 brelse(bh); 1987 brelse(bh);
1875 1988
1876out: 1989 out:
1877 unlock_kernel(); 1990 unlock_kernel();
1878 1991
1879 return accum; 1992 return accum;
1880} 1993}
1881 1994
1882static unsigned int 1995static unsigned int
1883udf_count_free_table(struct super_block *sb, struct inode * table) 1996udf_count_free_table(struct super_block *sb, struct inode *table)
1884{ 1997{
1885 unsigned int accum = 0; 1998 unsigned int accum = 0;
1886 uint32_t elen; 1999 uint32_t elen;
@@ -1902,17 +2015,17 @@ udf_count_free_table(struct super_block *sb, struct inode * table)
1902 2015
1903 return accum; 2016 return accum;
1904} 2017}
1905 2018
1906static unsigned int 2019static unsigned int udf_count_free(struct super_block *sb)
1907udf_count_free(struct super_block *sb)
1908{ 2020{
1909 unsigned int accum = 0; 2021 unsigned int accum = 0;
1910 2022
1911 if (UDF_SB_LVIDBH(sb)) 2023 if (UDF_SB_LVIDBH(sb)) {
1912 { 2024 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) >
1913 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) 2025 UDF_SB_PARTITION(sb)) {
1914 { 2026 accum =
1915 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]); 2027 le32_to_cpu(UDF_SB_LVID(sb)->
2028 freeSpaceTable[UDF_SB_PARTITION(sb)]);
1916 2029
1917 if (accum == 0xFFFFFFFF) 2030 if (accum == 0xFFFFFFFF)
1918 accum = 0; 2031 accum = 0;
@@ -1922,28 +2035,40 @@ udf_count_free(struct super_block *sb)
1922 if (accum) 2035 if (accum)
1923 return accum; 2036 return accum;
1924 2037
1925 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) 2038 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1926 { 2039 UDF_PART_FLAG_UNALLOC_BITMAP) {
1927 accum += udf_count_free_bitmap(sb, 2040 accum +=
1928 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap); 2041 udf_count_free_bitmap(sb,
2042 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2043 (sb)].s_uspace.
2044 s_bitmap);
1929 } 2045 }
1930 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) 2046 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1931 { 2047 UDF_PART_FLAG_FREED_BITMAP) {
1932 accum += udf_count_free_bitmap(sb, 2048 accum +=
1933 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap); 2049 udf_count_free_bitmap(sb,
2050 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2051 (sb)].s_fspace.
2052 s_bitmap);
1934 } 2053 }
1935 if (accum) 2054 if (accum)
1936 return accum; 2055 return accum;
1937 2056
1938 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) 2057 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1939 { 2058 UDF_PART_FLAG_UNALLOC_TABLE) {
1940 accum += udf_count_free_table(sb, 2059 accum +=
1941 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); 2060 udf_count_free_table(sb,
2061 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2062 (sb)].s_uspace.
2063 s_table);
1942 } 2064 }
1943 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) 2065 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1944 { 2066 UDF_PART_FLAG_FREED_TABLE) {
1945 accum += udf_count_free_table(sb, 2067 accum +=
1946 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); 2068 udf_count_free_table(sb,
2069 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2070 (sb)].s_fspace.
2071 s_table);
1947 } 2072 }
1948 2073
1949 return accum; 2074 return accum;
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
index 12613b680cc4..c4b82a920082 100644
--- a/fs/udf/symlink.c
+++ b/fs/udf/symlink.c
@@ -33,41 +33,40 @@
33#include <linux/buffer_head.h> 33#include <linux/buffer_head.h>
34#include "udf_i.h" 34#include "udf_i.h"
35 35
36static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to) 36static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen,
37 char *to)
37{ 38{
38 struct pathComponent *pc; 39 struct pathComponent *pc;
39 int elen = 0; 40 int elen = 0;
40 char *p = to; 41 char *p = to;
41 42
42 while (elen < fromlen) 43 while (elen < fromlen) {
43 {
44 pc = (struct pathComponent *)(from + elen); 44 pc = (struct pathComponent *)(from + elen);
45 switch (pc->componentType) 45 switch (pc->componentType) {
46 { 46 case 1:
47 case 1: 47 if (pc->lengthComponentIdent == 0) {
48 if (pc->lengthComponentIdent == 0) 48 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++ = '/'; 49 *p++ = '/';
66 break; 50 }
51 break;
52 case 3:
53 memcpy(p, "../", 3);
54 p += 3;
55 break;
56 case 4:
57 memcpy(p, "./", 2);
58 p += 2;
59 /* that would be . - just ignore */
60 break;
61 case 5:
62 p += udf_get_filename(sb, pc->componentIdent, p,
63 pc->lengthComponentIdent);
64 *p++ = '/';
65 break;
67 } 66 }
68 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; 67 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
69 } 68 }
70 if (p > to+1) 69 if (p > to + 1)
71 p[-1] = '\0'; 70 p[-1] = '\0';
72 else 71 else
73 p[0] = '\0'; 72 p[0] = '\0';
@@ -84,8 +83,7 @@ static int udf_symlink_filler(struct file *file, struct page *page)
84 lock_kernel(); 83 lock_kernel();
85 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 84 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
86 symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 85 symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
87 else 86 else {
88 {
89 bh = sb_bread(inode->i_sb, udf_block_map(inode, 0)); 87 bh = sb_bread(inode->i_sb, udf_block_map(inode, 0));
90 88
91 if (!bh) 89 if (!bh)
@@ -102,7 +100,7 @@ static int udf_symlink_filler(struct file *file, struct page *page)
102 kunmap(page); 100 kunmap(page);
103 unlock_page(page); 101 unlock_page(page);
104 return 0; 102 return 0;
105out: 103 out:
106 unlock_kernel(); 104 unlock_kernel();
107 SetPageError(page); 105 SetPageError(page);
108 kunmap(page); 106 kunmap(page);
@@ -114,5 +112,5 @@ out:
114 * symlinks can't do much... 112 * symlinks can't do much...
115 */ 113 */
116const struct address_space_operations udf_symlink_aops = { 114const struct address_space_operations udf_symlink_aops = {
117 .readpage = udf_symlink_filler, 115 .readpage = udf_symlink_filler,
118}; 116};
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index 60d277644248..b2002da0a5c0 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -28,35 +28,38 @@
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 = { 0, 0 };
35 int last_block = (elen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 36 int last_block =
36 int first_block = (nelen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 37 (elen + inode->i_sb->s_blocksize -
38 1) >> inode->i_sb->s_blocksize_bits;
39 int first_block =
40 (nelen + inode->i_sb->s_blocksize -
41 1) >> inode->i_sb->s_blocksize_bits;
37 42
38 if (nelen) 43 if (nelen) {
39 { 44 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
40 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 45 udf_free_blocks(inode->i_sb, inode, eloc, 0,
41 { 46 last_block);
42 udf_free_blocks(inode->i_sb, inode, eloc, 0, last_block);
43 etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30); 47 etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30);
44 } 48 } else
45 else
46 neloc = eloc; 49 neloc = eloc;
47 nelen = (etype << 30) | nelen; 50 nelen = (etype << 30) | nelen;
48 } 51 }
49 52
50 if (elen != nelen) 53 if (elen != nelen) {
51 {
52 udf_write_aext(inode, epos, neloc, nelen, 0); 54 udf_write_aext(inode, epos, neloc, nelen, 0);
53 if (last_block - first_block > 0) 55 if (last_block - first_block > 0) {
54 {
55 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) 56 if (etype == (EXT_RECORDED_ALLOCATED >> 30))
56 mark_inode_dirty(inode); 57 mark_inode_dirty(inode);
57 58
58 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 59 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
59 udf_free_blocks(inode->i_sb, inode, eloc, first_block, last_block - first_block); 60 udf_free_blocks(inode->i_sb, inode, eloc,
61 first_block,
62 last_block - first_block);
60 } 63 }
61 } 64 }
62} 65}
@@ -67,7 +70,7 @@ static void extent_trunc(struct inode * inode, struct extent_position *epos,
67 */ 70 */
68void udf_truncate_tail_extent(struct inode *inode) 71void udf_truncate_tail_extent(struct inode *inode)
69{ 72{
70 struct extent_position epos = { NULL, 0, {0, 0}}; 73 struct extent_position epos = { NULL, 0, {0, 0} };
71 kernel_lb_addr eloc; 74 kernel_lb_addr eloc;
72 uint32_t elen, nelen; 75 uint32_t elen, nelen;
73 uint64_t lbcount = 0; 76 uint64_t lbcount = 0;
@@ -89,8 +92,7 @@ void udf_truncate_tail_extent(struct inode *inode)
89 BUG(); 92 BUG();
90 93
91 /* Find the last extent in the file */ 94 /* Find the last extent in the file */
92 while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) 95 while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
93 {
94 etype = netype; 96 etype = netype;
95 lbcount += elen; 97 lbcount += elen;
96 if (lbcount > inode->i_size) { 98 if (lbcount > inode->i_size) {
@@ -123,7 +125,7 @@ void udf_truncate_tail_extent(struct inode *inode)
123 125
124void udf_discard_prealloc(struct inode *inode) 126void udf_discard_prealloc(struct inode *inode)
125{ 127{
126 struct extent_position epos = { NULL, 0, {0, 0}}; 128 struct extent_position epos = { NULL, 0, {0, 0} };
127 kernel_lb_addr eloc; 129 kernel_lb_addr eloc;
128 uint32_t elen; 130 uint32_t elen;
129 uint64_t lbcount = 0; 131 uint64_t lbcount = 0;
@@ -131,7 +133,7 @@ void udf_discard_prealloc(struct inode *inode)
131 int adsize; 133 int adsize;
132 134
133 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || 135 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
134 inode->i_size == UDF_I_LENEXTENTS(inode)) 136 inode->i_size == UDF_I_LENEXTENTS(inode))
135 return; 137 return;
136 138
137 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) 139 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
@@ -153,15 +155,21 @@ void udf_discard_prealloc(struct inode *inode)
153 lbcount -= elen; 155 lbcount -= elen;
154 extent_trunc(inode, &epos, eloc, etype, elen, 0); 156 extent_trunc(inode, &epos, eloc, etype, elen, 0);
155 if (!epos.bh) { 157 if (!epos.bh) {
156 UDF_I_LENALLOC(inode) = epos.offset - udf_file_entry_alloc_offset(inode); 158 UDF_I_LENALLOC(inode) =
159 epos.offset - udf_file_entry_alloc_offset(inode);
157 mark_inode_dirty(inode); 160 mark_inode_dirty(inode);
158 } else { 161 } else {
159 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data); 162 struct allocExtDesc *aed =
160 aed->lengthAllocDescs = cpu_to_le32(epos.offset - sizeof(struct allocExtDesc)); 163 (struct allocExtDesc *)(epos.bh->b_data);
161 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 164 aed->lengthAllocDescs =
165 cpu_to_le32(epos.offset -
166 sizeof(struct allocExtDesc));
167 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
168 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
162 udf_update_tag(epos.bh->b_data, epos.offset); 169 udf_update_tag(epos.bh->b_data, epos.offset);
163 else 170 else
164 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 171 udf_update_tag(epos.bh->b_data,
172 sizeof(struct allocExtDesc));
165 mark_buffer_dirty_inode(epos.bh, inode); 173 mark_buffer_dirty_inode(epos.bh, inode);
166 } 174 }
167 } 175 }
@@ -171,7 +179,7 @@ void udf_discard_prealloc(struct inode *inode)
171 brelse(epos.bh); 179 brelse(epos.bh);
172} 180}
173 181
174void udf_truncate_extents(struct inode * inode) 182void udf_truncate_extents(struct inode *inode)
175{ 183{
176 struct extent_position epos; 184 struct extent_position epos;
177 kernel_lb_addr eloc, neloc = { 0, 0 }; 185 kernel_lb_addr eloc, neloc = { 0, 0 };
@@ -190,9 +198,10 @@ void udf_truncate_extents(struct inode * inode)
190 BUG(); 198 BUG();
191 199
192 etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset); 200 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)); 201 byte_offset =
194 if (etype != -1) 202 (offset << sb->s_blocksize_bits) +
195 { 203 (inode->i_size & (sb->s_blocksize - 1));
204 if (etype != -1) {
196 epos.offset -= adsize; 205 epos.offset -= adsize;
197 extent_trunc(inode, &epos, eloc, etype, elen, byte_offset); 206 extent_trunc(inode, &epos, eloc, etype, elen, byte_offset);
198 epos.offset += adsize; 207 epos.offset += adsize;
@@ -206,86 +215,98 @@ void udf_truncate_extents(struct inode * inode)
206 else 215 else
207 lenalloc -= sizeof(struct allocExtDesc); 216 lenalloc -= sizeof(struct allocExtDesc);
208 217
209 while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) 218 while ((etype =
210 { 219 udf_current_aext(inode, &epos, &eloc, &elen,
211 if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) 220 0)) != -1) {
212 { 221 if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
213 udf_write_aext(inode, &epos, neloc, nelen, 0); 222 udf_write_aext(inode, &epos, neloc, nelen, 0);
214 if (indirect_ext_len) 223 if (indirect_ext_len) {
215 {
216 /* We managed to free all extents in the 224 /* We managed to free all extents in the
217 * indirect extent - free it too */ 225 * indirect extent - free it too */
218 if (!epos.bh) 226 if (!epos.bh)
219 BUG(); 227 BUG();
220 udf_free_blocks(sb, inode, epos.block, 0, indirect_ext_len); 228 udf_free_blocks(sb, inode, epos.block,
221 } 229 0, indirect_ext_len);
222 else 230 } else {
223 { 231 if (!epos.bh) {
224 if (!epos.bh) 232 UDF_I_LENALLOC(inode) =
225 { 233 lenalloc;
226 UDF_I_LENALLOC(inode) = lenalloc;
227 mark_inode_dirty(inode); 234 mark_inode_dirty(inode);
228 } 235 } else {
229 else 236 struct allocExtDesc *aed =
230 { 237 (struct allocExtDesc
231 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data); 238 *)(epos.bh->b_data);
232 aed->lengthAllocDescs = cpu_to_le32(lenalloc); 239 aed->lengthAllocDescs =
233 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(sb) >= 0x0201) 240 cpu_to_le32(lenalloc);
234 udf_update_tag(epos.bh->b_data, lenalloc + 241 if (!UDF_QUERY_FLAG
235 sizeof(struct allocExtDesc)); 242 (sb, UDF_FLAG_STRICT)
243 || UDF_SB_UDFREV(sb) >=
244 0x0201)
245 udf_update_tag(epos.bh->
246 b_data,
247 lenalloc
248 +
249 sizeof
250 (struct
251 allocExtDesc));
236 else 252 else
237 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 253 udf_update_tag(epos.bh->
238 mark_buffer_dirty_inode(epos.bh, inode); 254 b_data,
255 sizeof
256 (struct
257 allocExtDesc));
258 mark_buffer_dirty_inode(epos.bh,
259 inode);
239 } 260 }
240 } 261 }
241 brelse(epos.bh); 262 brelse(epos.bh);
242 epos.offset = sizeof(struct allocExtDesc); 263 epos.offset = sizeof(struct allocExtDesc);
243 epos.block = eloc; 264 epos.block = eloc;
244 epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); 265 epos.bh =
266 udf_tread(sb,
267 udf_get_lb_pblock(sb, eloc, 0));
245 if (elen) 268 if (elen)
246 indirect_ext_len = (elen + 269 indirect_ext_len = (elen +
247 sb->s_blocksize - 1) >> 270 sb->s_blocksize -
248 sb->s_blocksize_bits; 271 1) >> sb->
272 s_blocksize_bits;
249 else 273 else
250 indirect_ext_len = 1; 274 indirect_ext_len = 1;
251 } 275 } else {
252 else 276 extent_trunc(inode, &epos, eloc, etype, elen,
253 { 277 0);
254 extent_trunc(inode, &epos, eloc, etype, elen, 0);
255 epos.offset += adsize; 278 epos.offset += adsize;
256 } 279 }
257 } 280 }
258 281
259 if (indirect_ext_len) 282 if (indirect_ext_len) {
260 {
261 if (!epos.bh) 283 if (!epos.bh)
262 BUG(); 284 BUG();
263 udf_free_blocks(sb, inode, epos.block, 0, indirect_ext_len); 285 udf_free_blocks(sb, inode, epos.block, 0,
264 } 286 indirect_ext_len);
265 else 287 } else {
266 { 288 if (!epos.bh) {
267 if (!epos.bh)
268 {
269 UDF_I_LENALLOC(inode) = lenalloc; 289 UDF_I_LENALLOC(inode) = lenalloc;
270 mark_inode_dirty(inode); 290 mark_inode_dirty(inode);
271 } 291 } else {
272 else 292 struct allocExtDesc *aed =
273 { 293 (struct allocExtDesc *)(epos.bh->b_data);
274 struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data);
275 aed->lengthAllocDescs = cpu_to_le32(lenalloc); 294 aed->lengthAllocDescs = cpu_to_le32(lenalloc);
276 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(sb) >= 0x0201) 295 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT)
277 udf_update_tag(epos.bh->b_data, lenalloc + 296 || UDF_SB_UDFREV(sb) >= 0x0201)
278 sizeof(struct allocExtDesc)); 297 udf_update_tag(epos.bh->b_data,
298 lenalloc +
299 sizeof(struct
300 allocExtDesc));
279 else 301 else
280 udf_update_tag(epos.bh->b_data, sizeof(struct allocExtDesc)); 302 udf_update_tag(epos.bh->b_data,
303 sizeof(struct
304 allocExtDesc));
281 mark_buffer_dirty_inode(epos.bh, inode); 305 mark_buffer_dirty_inode(epos.bh, inode);
282 } 306 }
283 } 307 }
284 } 308 } else if (inode->i_size) {
285 else if (inode->i_size) 309 if (byte_offset) {
286 {
287 if (byte_offset)
288 {
289 kernel_long_ad extent; 310 kernel_long_ad extent;
290 311
291 /* 312 /*
@@ -293,21 +314,33 @@ void udf_truncate_extents(struct inode * inode)
293 * no extent above inode->i_size => truncate is 314 * no extent above inode->i_size => truncate is
294 * extending the file by 'offset' blocks. 315 * extending the file by 'offset' blocks.
295 */ 316 */
296 if ((!epos.bh && epos.offset == udf_file_entry_alloc_offset(inode)) || 317 if ((!epos.bh
297 (epos.bh && epos.offset == sizeof(struct allocExtDesc))) { 318 && epos.offset ==
319 udf_file_entry_alloc_offset(inode)) || (epos.bh
320 && epos.
321 offset ==
322 sizeof
323 (struct
324 allocExtDesc)))
325 {
298 /* File has no extents at all or has empty last 326 /* File has no extents at all or has empty last
299 * indirect extent! Create a fake extent... */ 327 * indirect extent! Create a fake extent... */
300 extent.extLocation.logicalBlockNum = 0; 328 extent.extLocation.logicalBlockNum = 0;
301 extent.extLocation.partitionReferenceNum = 0; 329 extent.extLocation.partitionReferenceNum = 0;
302 extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 330 extent.extLength =
303 } 331 EXT_NOT_RECORDED_NOT_ALLOCATED;
304 else { 332 } else {
305 epos.offset -= adsize; 333 epos.offset -= adsize;
306 etype = udf_next_aext(inode, &epos, 334 etype = udf_next_aext(inode, &epos,
307 &extent.extLocation, &extent.extLength, 0); 335 &extent.extLocation,
336 &extent.extLength, 0);
308 extent.extLength |= etype << 30; 337 extent.extLength |= etype << 30;
309 } 338 }
310 udf_extend_file(inode, &epos, &extent, offset+((inode->i_size & (sb->s_blocksize-1)) != 0)); 339 udf_extend_file(inode, &epos, &extent,
340 offset +
341 ((inode->
342 i_size & (sb->s_blocksize - 1)) !=
343 0));
311 } 344 }
312 } 345 }
313 UDF_I_LENEXTENTS(inode) = inode->i_size; 346 UDF_I_LENEXTENTS(inode) = inode->i_size;
diff --git a/fs/udf/udf_i.h b/fs/udf/udf_i.h
index d7dbe6f3ba0c..bee4308a8113 100644
--- a/fs/udf/udf_i.h
+++ b/fs/udf/udf_i.h
@@ -23,4 +23,4 @@ static inline struct udf_inode_info *UDF_I(struct inode *inode)
23#define UDF_I_LAD(X) ( UDF_I(X)->i_ext.i_lad ) 23#define UDF_I_LAD(X) ( UDF_I(X)->i_ext.i_lad )
24#define UDF_I_DATA(X) ( UDF_I(X)->i_ext.i_data ) 24#define UDF_I_DATA(X) ( UDF_I(X)->i_ext.i_data )
25 25
26#endif /* !defined(_LINUX_UDF_I_H) */ 26#endif /* !defined(_LINUX_UDF_I_H) */
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h
index 3b2e6c8cb151..60f31d8cebee 100644
--- a/fs/udf/udf_sb.h
+++ b/fs/udf/udf_sb.h
@@ -20,8 +20,8 @@
20#define UDF_FLAG_VARCONV 8 20#define UDF_FLAG_VARCONV 8
21#define UDF_FLAG_NLS_MAP 9 21#define UDF_FLAG_NLS_MAP 9
22#define UDF_FLAG_UTF8 10 22#define UDF_FLAG_UTF8 10
23#define UDF_FLAG_UID_FORGET 11 /* save -1 for uid to disk */ 23#define UDF_FLAG_UID_FORGET 11 /* save -1 for uid to disk */
24#define UDF_FLAG_UID_IGNORE 12 /* use sb uid instead of on disk uid */ 24#define UDF_FLAG_UID_IGNORE 12 /* use sb uid instead of on disk uid */
25#define UDF_FLAG_GID_FORGET 13 25#define UDF_FLAG_GID_FORGET 13
26#define UDF_FLAG_GID_IGNORE 14 26#define UDF_FLAG_GID_IGNORE 14
27 27
@@ -139,4 +139,4 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
139#define UDF_SB_FLAGS(X) ( UDF_SB(X)->s_flags ) 139#define UDF_SB_FLAGS(X) ( UDF_SB(X)->s_flags )
140#define UDF_SB_VAT(X) ( UDF_SB(X)->s_vat ) 140#define UDF_SB_VAT(X) ( UDF_SB(X)->s_vat )
141 141
142#endif /* __LINUX_UDF_SB_H */ 142#endif /* __LINUX_UDF_SB_H */
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index f581f2f69c0f..76f2b82a39dc 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{ 66 tag descTag;
69 tag descTag; 67 __le32 volDescSeqNum;
70 __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..450daab35a13 100644
--- a/fs/udf/udfend.h
+++ b/fs/udf/udfend.h
@@ -78,4 +78,4 @@ static inline timestamp cpu_to_lets(kernel_timestamp in)
78 return out; 78 return out;
79} 79}
80 80
81#endif /* __UDF_ENDIAN_H */ 81#endif /* __UDF_ENDIAN_H */
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index 85d8dbe843f1..b9f3198080e9 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -46,37 +46,36 @@
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
82extern struct timezone sys_tz; 81extern struct timezone sys_tz;
@@ -84,27 +83,23 @@ 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;
104 100
105 if ((src.year < EPOCH_YEAR) || 101 if ((src.year < EPOCH_YEAR) ||
106 (src.year >= EPOCH_YEAR+MAX_YEAR_SECONDS)) 102 (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
107 {
108 *dest = -1; 103 *dest = -1;
109 *dest_usec = -1; 104 *dest_usec = -1;
110 return NULL; 105 return NULL;
@@ -112,16 +107,16 @@ udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
112 *dest = year_seconds[src.year - EPOCH_YEAR]; 107 *dest = year_seconds[src.year - EPOCH_YEAR];
113 *dest -= offset * 60; 108 *dest -= offset * 60;
114 109
115 yday = ((__mon_yday[__isleap (src.year)] 110 yday = ((__mon_yday[__isleap(src.year)]
116 [src.month-1]) + (src.day-1)); 111 [src.month - 1]) + (src.day - 1));
117 *dest += ( ( (yday* 24) + src.hour ) * 60 + src.minute ) * 60 + src.second; 112 *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
118 *dest_usec = src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 + src.microseconds; 113 *dest_usec =
114 src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 +
115 src.microseconds;
119 return dest; 116 return dest;
120} 117}
121 118
122 119kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
123kernel_timestamp *
124udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
125{ 120{
126 long int days, rem, y; 121 long int days, rem, y;
127 const unsigned short int *ip; 122 const unsigned short int *ip;
@@ -146,28 +141,28 @@ udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
146#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) 141#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)) 142#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
148 143
149 while (days < 0 || days >= (__isleap(y) ? 366 : 365)) 144 while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
150 {
151 long int yg = y + days / 365 - (days % 365 < 0); 145 long int yg = y + days / 365 - (days % 365 < 0);
152 146
153 /* Adjust DAYS and Y to match the guessed year. */ 147 /* Adjust DAYS and Y to match the guessed year. */
154 days -= ((yg - y) * 365 148 days -= ((yg - y) * 365 + LEAPS_THRU_END_OF(yg - 1)
155 + LEAPS_THRU_END_OF (yg - 1) 149 - LEAPS_THRU_END_OF(y - 1));
156 - 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;
165 dest->day = days + 1; 158 dest->day = days + 1;
166 159
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 =
169 dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - 162 (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100;
170 dest->hundredsOfMicroseconds * 100); 163 dest->microseconds =
164 (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
165 dest->hundredsOfMicroseconds * 100);
171 return dest; 166 return dest;
172} 167}
173 168
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
index 706c92e1dcc9..46835240275c 100644
--- a/fs/udf/unicode.c
+++ b/fs/udf/unicode.c
@@ -29,9 +29,9 @@
29 29
30static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int); 30static 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 memset(dest, 0, sizeof(struct ustr)); 36 memset(dest, 0, sizeof(struct ustr));
37 memcpy(dest->u_name, src, strlen); 37 memcpy(dest->u_name, src, strlen);
@@ -43,33 +43,33 @@ static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
43/* 43/*
44 * udf_build_ustr 44 * udf_build_ustr
45 */ 45 */
46int udf_build_ustr(struct ustr *dest, dstring *ptr, int size) 46int udf_build_ustr(struct ustr *dest, dstring * ptr, int size)
47{ 47{
48 int usesize; 48 int usesize;
49 49
50 if ( (!dest) || (!ptr) || (!size) ) 50 if ((!dest) || (!ptr) || (!size))
51 return -1; 51 return -1;
52 52
53 memset(dest, 0, sizeof(struct ustr)); 53 memset(dest, 0, sizeof(struct ustr));
54 usesize= (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size; 54 usesize = (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size;
55 dest->u_cmpID=ptr[0]; 55 dest->u_cmpID = ptr[0];
56 dest->u_len=ptr[size-1]; 56 dest->u_len = ptr[size - 1];
57 memcpy(dest->u_name, ptr+1, usesize-1); 57 memcpy(dest->u_name, ptr + 1, usesize - 1);
58 return 0; 58 return 0;
59} 59}
60 60
61/* 61/*
62 * udf_build_ustr_exact 62 * udf_build_ustr_exact
63 */ 63 */
64static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) 64static int udf_build_ustr_exact(struct ustr *dest, dstring * ptr, int exactsize)
65{ 65{
66 if ( (!dest) || (!ptr) || (!exactsize) ) 66 if ((!dest) || (!ptr) || (!exactsize))
67 return -1; 67 return -1;
68 68
69 memset(dest, 0, sizeof(struct ustr)); 69 memset(dest, 0, sizeof(struct ustr));
70 dest->u_cmpID=ptr[0]; 70 dest->u_cmpID = ptr[0];
71 dest->u_len=exactsize-1; 71 dest->u_len = exactsize - 1;
72 memcpy(dest->u_name, ptr+1, exactsize-1); 72 memcpy(dest->u_name, ptr + 1, exactsize - 1);
73 return 0; 73 return 0;
74} 74}
75 75
@@ -108,22 +108,20 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
108 cmp_id = ocu_i->u_cmpID; 108 cmp_id = ocu_i->u_cmpID;
109 utf_o->u_len = 0; 109 utf_o->u_len = 0;
110 110
111 if (ocu_len == 0) 111 if (ocu_len == 0) {
112 {
113 memset(utf_o, 0, sizeof(struct ustr)); 112 memset(utf_o, 0, sizeof(struct ustr));
114 utf_o->u_cmpID = 0; 113 utf_o->u_cmpID = 0;
115 utf_o->u_len = 0; 114 utf_o->u_len = 0;
116 return 0; 115 return 0;
117 } 116 }
118 117
119 if ((cmp_id != 8) && (cmp_id != 16)) 118 if ((cmp_id != 8) && (cmp_id != 16)) {
120 { 119 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); 120 cmp_id, ocu_i->u_name);
122 return 0; 121 return 0;
123 } 122 }
124 123
125 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) 124 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
126 {
127 125
128 /* Expand OSTA compressed Unicode to Unicode */ 126 /* Expand OSTA compressed Unicode to Unicode */
129 c = ocu[i++]; 127 c = ocu[i++];
@@ -132,20 +130,22 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
132 130
133 /* Compress Unicode to UTF-8 */ 131 /* Compress Unicode to UTF-8 */
134 if (c < 0x80U) 132 if (c < 0x80U)
135 utf_o->u_name[utf_o->u_len++] = (uint8_t)c; 133 utf_o->u_name[utf_o->u_len++] = (uint8_t) c;
136 else if (c < 0x800U) 134 else if (c < 0x800U) {
137 { 135 utf_o->u_name[utf_o->u_len++] =
138 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); 136 (uint8_t) (0xc0 | (c >> 6));
139 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); 137 utf_o->u_name[utf_o->u_len++] =
140 } 138 (uint8_t) (0x80 | (c & 0x3f));
141 else 139 } else {
142 { 140 utf_o->u_name[utf_o->u_len++] =
143 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); 141 (uint8_t) (0xe0 | (c >> 12));
144 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); 142 utf_o->u_name[utf_o->u_len++] =
145 utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); 143 (uint8_t) (0x80 | ((c >> 6) & 0x3f));
144 utf_o->u_name[utf_o->u_len++] =
145 (uint8_t) (0x80 | (c & 0x3f));
146 } 146 }
147 } 147 }
148 utf_o->u_cmpID=8; 148 utf_o->u_cmpID = 8;
149 149
150 return utf_o->u_len; 150 return utf_o->u_len;
151} 151}
@@ -173,7 +173,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
173 * November 12, 1997 - Andrew E. Mileski 173 * November 12, 1997 - Andrew E. Mileski
174 * Written, tested, and released. 174 * Written, tested, and released.
175 */ 175 */
176static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length) 176static int udf_UTF8toCS0(dstring * ocu, struct ustr *utf, int length)
177{ 177{
178 unsigned c, i, max_val, utf_char; 178 unsigned c, i, max_val, utf_char;
179 int utf_cnt, u_len; 179 int utf_cnt, u_len;
@@ -182,53 +182,38 @@ static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length)
182 ocu[0] = 8; 182 ocu[0] = 8;
183 max_val = 0xffU; 183 max_val = 0xffU;
184 184
185try_again: 185 try_again:
186 u_len = 0U; 186 u_len = 0U;
187 utf_char = 0U; 187 utf_char = 0U;
188 utf_cnt = 0U; 188 utf_cnt = 0U;
189 for (i = 0U; i < utf->u_len; i++) 189 for (i = 0U; i < utf->u_len; i++) {
190 { 190 c = (uint8_t) utf->u_name[i];
191 c = (uint8_t)utf->u_name[i];
192 191
193 /* Complete a multi-byte UTF-8 character */ 192 /* Complete a multi-byte UTF-8 character */
194 if (utf_cnt) 193 if (utf_cnt) {
195 {
196 utf_char = (utf_char << 6) | (c & 0x3fU); 194 utf_char = (utf_char << 6) | (c & 0x3fU);
197 if (--utf_cnt) 195 if (--utf_cnt)
198 continue; 196 continue;
199 } 197 } else {
200 else
201 {
202 /* Check for a multi-byte UTF-8 character */ 198 /* Check for a multi-byte UTF-8 character */
203 if (c & 0x80U) 199 if (c & 0x80U) {
204 {
205 /* Start a multi-byte UTF-8 character */ 200 /* Start a multi-byte UTF-8 character */
206 if ((c & 0xe0U) == 0xc0U) 201 if ((c & 0xe0U) == 0xc0U) {
207 {
208 utf_char = c & 0x1fU; 202 utf_char = c & 0x1fU;
209 utf_cnt = 1; 203 utf_cnt = 1;
210 } 204 } else if ((c & 0xf0U) == 0xe0U) {
211 else if ((c & 0xf0U) == 0xe0U)
212 {
213 utf_char = c & 0x0fU; 205 utf_char = c & 0x0fU;
214 utf_cnt = 2; 206 utf_cnt = 2;
215 } 207 } else if ((c & 0xf8U) == 0xf0U) {
216 else if ((c & 0xf8U) == 0xf0U)
217 {
218 utf_char = c & 0x07U; 208 utf_char = c & 0x07U;
219 utf_cnt = 3; 209 utf_cnt = 3;
220 } 210 } else if ((c & 0xfcU) == 0xf8U) {
221 else if ((c & 0xfcU) == 0xf8U)
222 {
223 utf_char = c & 0x03U; 211 utf_char = c & 0x03U;
224 utf_cnt = 4; 212 utf_cnt = 4;
225 } 213 } else if ((c & 0xfeU) == 0xfcU) {
226 else if ((c & 0xfeU) == 0xfcU)
227 {
228 utf_char = c & 0x01U; 214 utf_char = c & 0x01U;
229 utf_cnt = 5; 215 utf_cnt = 5;
230 } 216 } else
231 else
232 goto error_out; 217 goto error_out;
233 continue; 218 continue;
234 } else 219 } else
@@ -237,37 +222,33 @@ try_again:
237 } 222 }
238 223
239 /* Choose no compression if necessary */ 224 /* Choose no compression if necessary */
240 if (utf_char > max_val) 225 if (utf_char > max_val) {
241 { 226 if (0xffU == max_val) {
242 if ( 0xffU == max_val )
243 {
244 max_val = 0xffffU; 227 max_val = 0xffffU;
245 ocu[0] = (uint8_t)0x10U; 228 ocu[0] = (uint8_t) 0x10U;
246 goto try_again; 229 goto try_again;
247 } 230 }
248 goto error_out; 231 goto error_out;
249 } 232 }
250 233
251 if (max_val == 0xffffU) 234 if (max_val == 0xffffU) {
252 { 235 ocu[++u_len] = (uint8_t) (utf_char >> 8);
253 ocu[++u_len] = (uint8_t)(utf_char >> 8);
254 } 236 }
255 ocu[++u_len] = (uint8_t)(utf_char & 0xffU); 237 ocu[++u_len] = (uint8_t) (utf_char & 0xffU);
256 } 238 }
257 239
258 240 if (utf_cnt) {
259 if (utf_cnt) 241 error_out:
260 {
261error_out:
262 ocu[++u_len] = '?'; 242 ocu[++u_len] = '?';
263 printk(KERN_DEBUG "udf: bad UTF-8 character\n"); 243 printk(KERN_DEBUG "udf: bad UTF-8 character\n");
264 } 244 }
265 245
266 ocu[length - 1] = (uint8_t)u_len + 1; 246 ocu[length - 1] = (uint8_t) u_len + 1;
267 return u_len + 1; 247 return u_len + 1;
268} 248}
269 249
270static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr *ocu_i) 250static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o,
251 struct ustr *ocu_i)
271{ 252{
272 uint8_t *ocu; 253 uint8_t *ocu;
273 uint32_t c; 254 uint32_t c;
@@ -280,36 +261,35 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr *
280 cmp_id = ocu_i->u_cmpID; 261 cmp_id = ocu_i->u_cmpID;
281 utf_o->u_len = 0; 262 utf_o->u_len = 0;
282 263
283 if (ocu_len == 0) 264 if (ocu_len == 0) {
284 {
285 memset(utf_o, 0, sizeof(struct ustr)); 265 memset(utf_o, 0, sizeof(struct ustr));
286 utf_o->u_cmpID = 0; 266 utf_o->u_cmpID = 0;
287 utf_o->u_len = 0; 267 utf_o->u_len = 0;
288 return 0; 268 return 0;
289 } 269 }
290 270
291 if ((cmp_id != 8) && (cmp_id != 16)) 271 if ((cmp_id != 8) && (cmp_id != 16)) {
292 { 272 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); 273 cmp_id, ocu_i->u_name);
294 return 0; 274 return 0;
295 } 275 }
296 276
297 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) 277 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
298 {
299 /* Expand OSTA compressed Unicode to Unicode */ 278 /* Expand OSTA compressed Unicode to Unicode */
300 c = ocu[i++]; 279 c = ocu[i++];
301 if (cmp_id == 16) 280 if (cmp_id == 16)
302 c = (c << 8) | ocu[i++]; 281 c = (c << 8) | ocu[i++];
303 282
304 utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len], 283 utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len],
305 UDF_NAME_LEN - utf_o->u_len); 284 UDF_NAME_LEN - utf_o->u_len);
306 } 285 }
307 utf_o->u_cmpID=8; 286 utf_o->u_cmpID = 8;
308 287
309 return utf_o->u_len; 288 return utf_o->u_len;
310} 289}
311 290
312static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, int length) 291static int udf_NLStoCS0(struct nls_table *nls, dstring * ocu, struct ustr *uni,
292 int length)
313{ 293{
314 unsigned len, i, max_val; 294 unsigned len, i, max_val;
315 uint16_t uni_char; 295 uint16_t uni_char;
@@ -319,93 +299,87 @@ static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, i
319 ocu[0] = 8; 299 ocu[0] = 8;
320 max_val = 0xffU; 300 max_val = 0xffU;
321 301
322try_again: 302 try_again:
323 u_len = 0U; 303 u_len = 0U;
324 for (i = 0U; i < uni->u_len; i++) 304 for (i = 0U; i < uni->u_len; i++) {
325 { 305 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) 306 if (len <= 0)
328 continue; 307 continue;
329 308
330 if (uni_char > max_val) 309 if (uni_char > max_val) {
331 {
332 max_val = 0xffffU; 310 max_val = 0xffffU;
333 ocu[0] = (uint8_t)0x10U; 311 ocu[0] = (uint8_t) 0x10U;
334 goto try_again; 312 goto try_again;
335 } 313 }
336 314
337 if (max_val == 0xffffU) 315 if (max_val == 0xffffU)
338 ocu[++u_len] = (uint8_t)(uni_char >> 8); 316 ocu[++u_len] = (uint8_t) (uni_char >> 8);
339 ocu[++u_len] = (uint8_t)(uni_char & 0xffU); 317 ocu[++u_len] = (uint8_t) (uni_char & 0xffU);
340 i += len - 1; 318 i += len - 1;
341 } 319 }
342 320
343 ocu[length - 1] = (uint8_t)u_len + 1; 321 ocu[length - 1] = (uint8_t) u_len + 1;
344 return u_len + 1; 322 return u_len + 1;
345} 323}
346 324
347int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, int flen) 325int udf_get_filename(struct super_block *sb, uint8_t * sname, uint8_t * dname,
326 int flen)
348{ 327{
349 struct ustr filename, unifilename; 328 struct ustr filename, unifilename;
350 int len; 329 int len;
351 330
352 if (udf_build_ustr_exact(&unifilename, sname, flen)) 331 if (udf_build_ustr_exact(&unifilename, sname, flen)) {
353 {
354 return 0; 332 return 0;
355 } 333 }
356 334
357 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) 335 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
358 { 336 if (!udf_CS0toUTF8(&filename, &unifilename)) {
359 if (!udf_CS0toUTF8(&filename, &unifilename) ) 337 udf_debug("Failed in udf_get_filename: sname = %s\n",
360 { 338 sname);
361 udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
362 return 0; 339 return 0;
363 } 340 }
364 } 341 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
365 else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) 342 if (!udf_CS0toNLS
366 { 343 (UDF_SB(sb)->s_nls_map, &filename, &unifilename)) {
367 if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename) ) 344 udf_debug("Failed in udf_get_filename: sname = %s\n",
368 { 345 sname);
369 udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
370 return 0; 346 return 0;
371 } 347 }
372 } 348 } else
373 else
374 return 0; 349 return 0;
375 350
376 if ((len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, 351 if ((len =
377 unifilename.u_name, unifilename.u_len))) 352 udf_translate_to_linux(dname, filename.u_name, filename.u_len,
378 { 353 unifilename.u_name, unifilename.u_len))) {
379 return len; 354 return len;
380 } 355 }
381 return 0; 356 return 0;
382} 357}
383 358
384int udf_put_filename(struct super_block *sb, const uint8_t *sname, uint8_t *dname, int flen) 359int udf_put_filename(struct super_block *sb, const uint8_t * sname,
360 uint8_t * dname, int flen)
385{ 361{
386 struct ustr unifilename; 362 struct ustr unifilename;
387 int namelen; 363 int namelen;
388 364
389 if ( !(udf_char_to_ustr(&unifilename, sname, flen)) ) 365 if (!(udf_char_to_ustr(&unifilename, sname, flen))) {
390 {
391 return 0; 366 return 0;
392 } 367 }
393 368
394 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) 369 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
395 { 370 if (!
396 if ( !(namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN)) ) 371 (namelen =
397 { 372 udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN))) {
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 if (!
402 { 377 (namelen =
403 if ( !(namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN)) ) 378 udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename,
404 { 379 UDF_NAME_LEN))) {
405 return 0; 380 return 0;
406 } 381 }
407 } 382 } else
408 else
409 return 0; 383 return 0;
410 384
411 return namelen; 385 return namelen;
@@ -416,40 +390,36 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, uint8_t *dnam
416#define CRC_MARK '#' 390#define CRC_MARK '#'
417#define EXT_SIZE 5 391#define EXT_SIZE 5
418 392
419static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, uint8_t *fidName, int fidNameLen) 393static int udf_translate_to_linux(uint8_t * newName, uint8_t * udfName,
394 int udfLen, uint8_t * fidName, int fidNameLen)
420{ 395{
421 int index, newIndex = 0, needsCRC = 0; 396 int index, newIndex = 0, needsCRC = 0;
422 int extIndex = 0, newExtIndex = 0, hasExt = 0; 397 int extIndex = 0, newExtIndex = 0, hasExt = 0;
423 unsigned short valueCRC; 398 unsigned short valueCRC;
424 uint8_t curr; 399 uint8_t curr;
425 const uint8_t hexChar[] = "0123456789ABCDEF"; 400 const uint8_t hexChar[] = "0123456789ABCDEF";
426 401
427 if (udfName[0] == '.' && (udfLen == 1 || 402 if (udfName[0] == '.' && (udfLen == 1 ||
428 (udfLen == 2 && udfName[1] == '.'))) 403 (udfLen == 2 && udfName[1] == '.'))) {
429 {
430 needsCRC = 1; 404 needsCRC = 1;
431 newIndex = udfLen; 405 newIndex = udfLen;
432 memcpy(newName, udfName, udfLen); 406 memcpy(newName, udfName, udfLen);
433 } 407 } else {
434 else 408 for (index = 0; index < udfLen; index++) {
435 {
436 for (index = 0; index < udfLen; index++)
437 {
438 curr = udfName[index]; 409 curr = udfName[index];
439 if (curr == '/' || curr == 0) 410 if (curr == '/' || curr == 0) {
440 {
441 needsCRC = 1; 411 needsCRC = 1;
442 curr = ILLEGAL_CHAR_MARK; 412 curr = ILLEGAL_CHAR_MARK;
443 while (index+1 < udfLen && (udfName[index+1] == '/' || 413 while (index + 1 < udfLen
444 udfName[index+1] == 0)) 414 && (udfName[index + 1] == '/'
415 || udfName[index + 1] == 0))
445 index++; 416 index++;
446 } 417 }
447 if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) 418 if (curr == EXT_MARK
448 { 419 && (udfLen - index - 1) <= EXT_SIZE) {
449 if (udfLen == index + 1) 420 if (udfLen == index + 1)
450 hasExt = 0; 421 hasExt = 0;
451 else 422 else {
452 {
453 hasExt = 1; 423 hasExt = 1;
454 extIndex = index; 424 extIndex = index;
455 newExtIndex = newIndex; 425 newExtIndex = newIndex;
@@ -461,26 +431,29 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
461 needsCRC = 1; 431 needsCRC = 1;
462 } 432 }
463 } 433 }
464 if (needsCRC) 434 if (needsCRC) {
465 {
466 uint8_t ext[EXT_SIZE]; 435 uint8_t ext[EXT_SIZE];
467 int localExtIndex = 0; 436 int localExtIndex = 0;
468 437
469 if (hasExt) 438 if (hasExt) {
470 {
471 int maxFilenameLen; 439 int maxFilenameLen;
472 for(index = 0; index<EXT_SIZE && extIndex + index +1 < udfLen; 440 for (index = 0;
473 index++ ) 441 index < EXT_SIZE && extIndex + index + 1 < udfLen;
474 { 442 index++) {
475 curr = udfName[extIndex + index + 1]; 443 curr = udfName[extIndex + index + 1];
476 444
477 if (curr == '/' || curr == 0) 445 if (curr == '/' || curr == 0) {
478 {
479 needsCRC = 1; 446 needsCRC = 1;
480 curr = ILLEGAL_CHAR_MARK; 447 curr = ILLEGAL_CHAR_MARK;
481 while(extIndex + index + 2 < udfLen && (index + 1 < EXT_SIZE 448 while (extIndex + index + 2 < udfLen
482 && (udfName[extIndex + index + 2] == '/' || 449 && (index + 1 < EXT_SIZE
483 udfName[extIndex + index + 2] == 0))) 450 &&
451 (udfName
452 [extIndex + index + 2] ==
453 '/'
454 || udfName[extIndex +
455 index + 2] ==
456 0)))
484 index++; 457 index++;
485 } 458 }
486 ext[localExtIndex++] = curr; 459 ext[localExtIndex++] = curr;
@@ -490,8 +463,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
490 newIndex = maxFilenameLen; 463 newIndex = maxFilenameLen;
491 else 464 else
492 newIndex = newExtIndex; 465 newIndex = newExtIndex;
493 } 466 } else if (newIndex > 250)
494 else if (newIndex > 250)
495 newIndex = 250; 467 newIndex = 250;
496 newName[newIndex++] = CRC_MARK; 468 newName[newIndex++] = CRC_MARK;
497 valueCRC = udf_crc(fidName, fidNameLen, 0); 469 valueCRC = udf_crc(fidName, fidNameLen, 0);
@@ -500,10 +472,9 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
500 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4]; 472 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4];
501 newName[newIndex++] = hexChar[(valueCRC & 0x000f)]; 473 newName[newIndex++] = hexChar[(valueCRC & 0x000f)];
502 474
503 if (hasExt) 475 if (hasExt) {
504 {
505 newName[newIndex++] = EXT_MARK; 476 newName[newIndex++] = EXT_MARK;
506 for (index = 0;index < localExtIndex ;index++ ) 477 for (index = 0; index < localExtIndex; index++)
507 newName[newIndex++] = ext[index]; 478 newName[newIndex++] = ext[index];
508 } 479 }
509 } 480 }