aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/inode.c')
-rw-r--r--fs/udf/inode.c948
1 files changed, 368 insertions, 580 deletions
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index be6326f449a1..0d2c41666cd2 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -97,7 +97,8 @@ void udf_delete_inode(struct inode *inode)
97 97
98 unlock_kernel(); 98 unlock_kernel();
99 return; 99 return;
100 no_delete: 100
101no_delete:
101 clear_inode(inode); 102 clear_inode(inode);
102} 103}
103 104
@@ -144,12 +145,12 @@ static sector_t udf_bmap(struct address_space *mapping, sector_t block)
144} 145}
145 146
146const struct address_space_operations udf_aops = { 147const struct address_space_operations udf_aops = {
147 .readpage = udf_readpage, 148 .readpage = udf_readpage,
148 .writepage = udf_writepage, 149 .writepage = udf_writepage,
149 .sync_page = block_sync_page, 150 .sync_page = block_sync_page,
150 .prepare_write = udf_prepare_write, 151 .prepare_write = udf_prepare_write,
151 .commit_write = generic_commit_write, 152 .commit_write = generic_commit_write,
152 .bmap = udf_bmap, 153 .bmap = udf_bmap,
153}; 154};
154 155
155void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err) 156void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
@@ -230,12 +231,10 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
230 *block = udf_new_block(inode->i_sb, inode, 231 *block = udf_new_block(inode->i_sb, inode,
231 UDF_I_LOCATION(inode).partitionReferenceNum, 232 UDF_I_LOCATION(inode).partitionReferenceNum,
232 UDF_I_LOCATION(inode).logicalBlockNum, err); 233 UDF_I_LOCATION(inode).logicalBlockNum, err);
233
234 if (!(*block)) 234 if (!(*block))
235 return NULL; 235 return NULL;
236 newblock = udf_get_pblock(inode->i_sb, *block, 236 newblock = udf_get_pblock(inode->i_sb, *block,
237 UDF_I_LOCATION(inode).partitionReferenceNum, 237 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
238 0);
239 if (!newblock) 238 if (!newblock)
240 return NULL; 239 return NULL;
241 dbh = udf_tgetblk(inode->i_sb, newblock); 240 dbh = udf_tgetblk(inode->i_sb, newblock);
@@ -247,16 +246,13 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
247 unlock_buffer(dbh); 246 unlock_buffer(dbh);
248 mark_buffer_dirty_inode(dbh, inode); 247 mark_buffer_dirty_inode(dbh, inode);
249 248
250 sfibh.soffset = sfibh.eoffset = 249 sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
251 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
252 sfibh.sbh = sfibh.ebh = NULL; 250 sfibh.sbh = sfibh.ebh = NULL;
253 dfibh.soffset = dfibh.eoffset = 0; 251 dfibh.soffset = dfibh.eoffset = 0;
254 dfibh.sbh = dfibh.ebh = dbh; 252 dfibh.sbh = dfibh.ebh = dbh;
255 while ((f_pos < size)) { 253 while ((f_pos < size)) {
256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 254 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
257 sfi = 255 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL);
258 udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL,
259 NULL, NULL);
260 if (!sfi) { 256 if (!sfi) {
261 brelse(dbh); 257 brelse(dbh);
262 return NULL; 258 return NULL;
@@ -267,8 +263,7 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
267 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); 263 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
268 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); 264 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
269 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, 265 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
270 sfi->fileIdent + 266 sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) {
271 le16_to_cpu(sfi->lengthOfImpUse))) {
272 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 267 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
273 brelse(dbh); 268 brelse(dbh);
274 return NULL; 269 return NULL;
@@ -276,12 +271,10 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
276 } 271 }
277 mark_buffer_dirty_inode(dbh, inode); 272 mark_buffer_dirty_inode(dbh, inode);
278 273
279 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, 274 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode));
280 UDF_I_LENALLOC(inode));
281 UDF_I_LENALLOC(inode) = 0; 275 UDF_I_LENALLOC(inode) = 0;
282 eloc.logicalBlockNum = *block; 276 eloc.logicalBlockNum = *block;
283 eloc.partitionReferenceNum = 277 eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
284 UDF_I_LOCATION(inode).partitionReferenceNum;
285 elen = inode->i_size; 278 elen = inode->i_size;
286 UDF_I_LENEXTENTS(inode) = elen; 279 UDF_I_LENEXTENTS(inode) = elen;
287 epos.bh = NULL; 280 epos.bh = NULL;
@@ -334,11 +327,12 @@ static int udf_get_block(struct inode *inode, sector_t block,
334 if (new) 327 if (new)
335 set_buffer_new(bh_result); 328 set_buffer_new(bh_result);
336 map_bh(bh_result, inode->i_sb, phys); 329 map_bh(bh_result, inode->i_sb, phys);
337 abort: 330
331abort:
338 unlock_kernel(); 332 unlock_kernel();
339 return err; 333 return err;
340 334
341 abort_negative: 335abort_negative:
342 udf_warning(inode->i_sb, "udf_get_block", "block < 0"); 336 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
343 goto abort; 337 goto abort;
344} 338}
@@ -346,13 +340,13 @@ static int udf_get_block(struct inode *inode, sector_t block,
346static struct buffer_head *udf_getblk(struct inode *inode, long block, 340static struct buffer_head *udf_getblk(struct inode *inode, long block,
347 int create, int *err) 341 int create, int *err)
348{ 342{
343 struct buffer_head *bh;
349 struct buffer_head dummy; 344 struct buffer_head dummy;
350 345
351 dummy.b_state = 0; 346 dummy.b_state = 0;
352 dummy.b_blocknr = -1000; 347 dummy.b_blocknr = -1000;
353 *err = udf_get_block(inode, block, &dummy, create); 348 *err = udf_get_block(inode, block, &dummy, create);
354 if (!*err && buffer_mapped(&dummy)) { 349 if (!*err && buffer_mapped(&dummy)) {
355 struct buffer_head *bh;
356 bh = sb_getblk(inode->i_sb, dummy.b_blocknr); 350 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
357 if (buffer_new(&dummy)) { 351 if (buffer_new(&dummy)) {
358 lock_buffer(bh); 352 lock_buffer(bh);
@@ -363,6 +357,7 @@ static struct buffer_head *udf_getblk(struct inode *inode, long block,
363 } 357 }
364 return bh; 358 return bh;
365 } 359 }
360
366 return NULL; 361 return NULL;
367} 362}
368 363
@@ -373,42 +368,41 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
373 sector_t add; 368 sector_t add;
374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 369 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
375 struct super_block *sb = inode->i_sb; 370 struct super_block *sb = inode->i_sb;
376 kernel_lb_addr prealloc_loc = { 0, 0 }; 371 kernel_lb_addr prealloc_loc = {};
377 int prealloc_len = 0; 372 int prealloc_len = 0;
378 373
379 /* The previous extent is fake and we should not extend by anything 374 /* The previous extent is fake and we should not extend by anything
380 * - there's nothing to do... */ 375 * - there's nothing to do... */
381 if (!blocks && fake) 376 if (!blocks && fake)
382 return 0; 377 return 0;
378
383 /* Round the last extent up to a multiple of block size */ 379 /* Round the last extent up to a multiple of block size */
384 if (last_ext->extLength & (sb->s_blocksize - 1)) { 380 if (last_ext->extLength & (sb->s_blocksize - 1)) {
385 last_ext->extLength = 381 last_ext->extLength =
386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | 382 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + 383 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); 384 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
389 UDF_I_LENEXTENTS(inode) = 385 UDF_I_LENEXTENTS(inode) =
390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & 386 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
391 ~(sb->s_blocksize - 1); 387 ~(sb->s_blocksize - 1);
392 } 388 }
389
393 /* Last extent are just preallocated blocks? */ 390 /* Last extent are just preallocated blocks? */
394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == 391 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) {
395 EXT_NOT_RECORDED_ALLOCATED) {
396 /* Save the extent so that we can reattach it to the end */ 392 /* Save the extent so that we can reattach it to the end */
397 prealloc_loc = last_ext->extLocation; 393 prealloc_loc = last_ext->extLocation;
398 prealloc_len = last_ext->extLength; 394 prealloc_len = last_ext->extLength;
399 /* Mark the extent as a hole */ 395 /* Mark the extent as a hole */
400 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 396 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
401 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 397 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
402 last_ext->extLocation.logicalBlockNum = 0; 398 last_ext->extLocation.logicalBlockNum = 0;
403 last_ext->extLocation.partitionReferenceNum = 0; 399 last_ext->extLocation.partitionReferenceNum = 0;
404 } 400 }
401
405 /* Can we merge with the previous extent? */ 402 /* Can we merge with the previous extent? */
406 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == 403 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) {
407 EXT_NOT_RECORDED_NOT_ALLOCATED) { 404 add = ((1 << 30) - sb->s_blocksize - (last_ext->extLength &
408 add = 405 UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits;
409 ((1 << 30) - sb->s_blocksize -
410 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> sb->
411 s_blocksize_bits;
412 if (add > blocks) 406 if (add > blocks)
413 add = blocks; 407 add = blocks;
414 blocks -= add; 408 blocks -= add;
@@ -419,19 +413,20 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
419 udf_add_aext(inode, last_pos, last_ext->extLocation, 413 udf_add_aext(inode, last_pos, last_ext->extLocation,
420 last_ext->extLength, 1); 414 last_ext->extLength, 1);
421 count++; 415 count++;
422 } else 416 } else {
423 udf_write_aext(inode, last_pos, last_ext->extLocation, 417 udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1);
424 last_ext->extLength, 1); 418 }
419
425 /* Managed to do everything necessary? */ 420 /* Managed to do everything necessary? */
426 if (!blocks) 421 if (!blocks)
427 goto out; 422 goto out;
428 423
429 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ 424 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
430 last_ext->extLocation.logicalBlockNum = 0; 425 last_ext->extLocation.logicalBlockNum = 0;
431 last_ext->extLocation.partitionReferenceNum = 0; 426 last_ext->extLocation.partitionReferenceNum = 0;
432 add = (1 << (30 - sb->s_blocksize_bits)) - 1; 427 add = (1 << (30-sb->s_blocksize_bits)) - 1;
433 last_ext->extLength = 428 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
434 EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); 429
435 /* Create enough extents to cover the whole hole */ 430 /* Create enough extents to cover the whole hole */
436 while (blocks > add) { 431 while (blocks > add) {
437 blocks -= add; 432 blocks -= add;
@@ -442,22 +437,23 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
442 } 437 }
443 if (blocks) { 438 if (blocks) {
444 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 439 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
445 (blocks << sb->s_blocksize_bits); 440 (blocks << sb->s_blocksize_bits);
446 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 441 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
447 last_ext->extLength, 1) == -1) 442 last_ext->extLength, 1) == -1)
448 return -1; 443 return -1;
449 count++; 444 count++;
450 } 445 }
451 out: 446
447out:
452 /* Do we have some preallocated blocks saved? */ 448 /* Do we have some preallocated blocks saved? */
453 if (prealloc_len) { 449 if (prealloc_len) {
454 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) 450 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1)
455 == -1)
456 return -1; 451 return -1;
457 last_ext->extLocation = prealloc_loc; 452 last_ext->extLocation = prealloc_loc;
458 last_ext->extLength = prealloc_len; 453 last_ext->extLength = prealloc_len;
459 count++; 454 count++;
460 } 455 }
456
461 /* last_pos should point to the last written extent... */ 457 /* last_pos should point to the last written extent... */
462 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) 458 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
463 last_pos->offset -= sizeof(short_ad); 459 last_pos->offset -= sizeof(short_ad);
@@ -465,6 +461,7 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
465 last_pos->offset -= sizeof(long_ad); 461 last_pos->offset -= sizeof(long_ad);
466 else 462 else
467 return -1; 463 return -1;
464
468 return count; 465 return count;
469} 466}
470 467
@@ -490,7 +487,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
490 prev_epos.block = UDF_I_LOCATION(inode); 487 prev_epos.block = UDF_I_LOCATION(inode);
491 prev_epos.bh = NULL; 488 prev_epos.bh = NULL;
492 cur_epos = next_epos = prev_epos; 489 cur_epos = next_epos = prev_epos;
493 b_off = (loff_t) block << inode->i_sb->s_blocksize_bits; 490 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
494 491
495 /* find the extent which contains the block we are looking for. 492 /* find the extent which contains the block we are looking for.
496 alternate between laarr[0] and laarr[1] for locations of the 493 alternate between laarr[0] and laarr[1] for locations of the
@@ -515,8 +512,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
515 prev_epos.offset = cur_epos.offset; 512 prev_epos.offset = cur_epos.offset;
516 cur_epos.offset = next_epos.offset; 513 cur_epos.offset = next_epos.offset;
517 514
518 if ((etype = 515 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
519 udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
520 break; 516 break;
521 517
522 c = !c; 518 c = !c;
@@ -526,8 +522,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
526 522
527 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 523 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
528 pgoal = eloc.logicalBlockNum + 524 pgoal = eloc.logicalBlockNum +
529 ((elen + inode->i_sb->s_blocksize - 1) >> 525 ((elen + inode->i_sb->s_blocksize - 1) >>
530 inode->i_sb->s_blocksize_bits); 526 inode->i_sb->s_blocksize_bits);
531 527
532 count++; 528 count++;
533 } while (lbcount + elen <= b_off); 529 } while (lbcount + elen <= b_off);
@@ -547,8 +543,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
547 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) { 543 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
548 if (elen & (inode->i_sb->s_blocksize - 1)) { 544 if (elen & (inode->i_sb->s_blocksize - 1)) {
549 elen = EXT_RECORDED_ALLOCATED | 545 elen = EXT_RECORDED_ALLOCATED |
550 ((elen + inode->i_sb->s_blocksize - 1) & 546 ((elen + inode->i_sb->s_blocksize - 1) &
551 ~(inode->i_sb->s_blocksize - 1)); 547 ~(inode->i_sb->s_blocksize - 1));
552 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1); 548 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
553 } 549 }
554 brelse(prev_epos.bh); 550 brelse(prev_epos.bh);
@@ -570,8 +566,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
570 startnum = 1; 566 startnum = 1;
571 } else { 567 } else {
572 /* Create a fake extent when there's not one */ 568 /* Create a fake extent when there's not one */
573 memset(&laarr[0].extLocation, 0x00, 569 memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr));
574 sizeof(kernel_lb_addr));
575 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 570 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
576 /* Will udf_extend_file() create real extent from a fake one? */ 571 /* Will udf_extend_file() create real extent from a fake one? */
577 startnum = (offset > 0); 572 startnum = (offset > 0);
@@ -591,16 +586,14 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
591 offset = 0; 586 offset = 0;
592 count += ret; 587 count += ret;
593 /* We are not covered by a preallocated extent? */ 588 /* We are not covered by a preallocated extent? */
594 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != 589 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) {
595 EXT_NOT_RECORDED_ALLOCATED) {
596 /* Is there any real extent? - otherwise we overwrite 590 /* Is there any real extent? - otherwise we overwrite
597 * the fake one... */ 591 * the fake one... */
598 if (count) 592 if (count)
599 c = !c; 593 c = !c;
600 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 594 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
601 inode->i_sb->s_blocksize; 595 inode->i_sb->s_blocksize;
602 memset(&laarr[c].extLocation, 0x00, 596 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
603 sizeof(kernel_lb_addr));
604 count++; 597 count++;
605 endnum++; 598 endnum++;
606 } 599 }
@@ -618,8 +611,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
618 } 611 }
619 612
620 /* if the current block is located in an extent, read the next extent */ 613 /* if the current block is located in an extent, read the next extent */
621 if ((etype = 614 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
622 udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
623 laarr[c + 1].extLength = (etype << 30) | elen; 615 laarr[c + 1].extLength = (etype << 30) | elen;
624 laarr[c + 1].extLocation = eloc; 616 laarr[c + 1].extLocation = eloc;
625 count++; 617 count++;
@@ -631,24 +623,21 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
631 } 623 }
632 624
633 /* if the current extent is not recorded but allocated, get the 625 /* if the current extent is not recorded but allocated, get the
634 block in the extent corresponding to the requested block */ 626 * block in the extent corresponding to the requested block */
635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 627 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset; 628 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
637 else { /* otherwise, allocate a new block */ 629 } else { /* otherwise, allocate a new block */
638
639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) 630 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
640 goal = UDF_I_NEXT_ALLOC_GOAL(inode); 631 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
641 632
642 if (!goal) { 633 if (!goal) {
643 if (!(goal = pgoal)) 634 if (!(goal = pgoal))
644 goal = 635 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
645 UDF_I_LOCATION(inode).logicalBlockNum + 1;
646 } 636 }
647 637
648 if (!(newblocknum = udf_new_block(inode->i_sb, inode, 638 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
649 UDF_I_LOCATION(inode). 639 UDF_I_LOCATION(inode).partitionReferenceNum,
650 partitionReferenceNum, goal, 640 goal, err))) {
651 err))) {
652 brelse(prev_epos.bh); 641 brelse(prev_epos.bh);
653 *err = -ENOSPC; 642 *err = -ENOSPC;
654 return NULL; 643 return NULL;
@@ -657,8 +646,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
657 } 646 }
658 647
659 /* if the extent the requsted block is located in contains multiple blocks, 648 /* if the extent the requsted block is located in contains multiple blocks,
660 split the extent into at most three extents. blocks prior to requested 649 * split the extent into at most three extents. blocks prior to requested
661 block, requested block, and blocks after requested block */ 650 * block, requested block, and blocks after requested block */
662 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); 651 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
663 652
664#ifdef UDF_PREALLOCATE 653#ifdef UDF_PREALLOCATE
@@ -670,15 +659,14 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
670 udf_merge_extents(inode, laarr, &endnum); 659 udf_merge_extents(inode, laarr, &endnum);
671 660
672 /* write back the new extents, inserting new extents if the new number 661 /* write back the new extents, inserting new extents if the new number
673 of extents is greater than the old number, and deleting extents if 662 * of extents is greater than the old number, and deleting extents if
674 the new number of extents is less than the old number */ 663 * the new number of extents is less than the old number */
675 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); 664 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
676 665
677 brelse(prev_epos.bh); 666 brelse(prev_epos.bh);
678 667
679 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, 668 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
680 UDF_I_LOCATION(inode). 669 UDF_I_LOCATION(inode).partitionReferenceNum, 0))) {
681 partitionReferenceNum, 0))) {
682 return NULL; 670 return NULL;
683 } 671 }
684 *phys = newblock; 672 *phys = newblock;
@@ -692,6 +680,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
692 udf_sync_inode(inode); 680 udf_sync_inode(inode);
693 else 681 else
694 mark_inode_dirty(inode); 682 mark_inode_dirty(inode);
683
695 return result; 684 return result;
696} 685}
697 686
@@ -701,16 +690,15 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
701 int *endnum) 690 int *endnum)
702{ 691{
703 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || 692 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
704 (laarr[*c].extLength >> 30) == 693 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
705 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
706 int curr = *c; 694 int curr = *c;
707 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + 695 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
708 inode->i_sb->s_blocksize - 696 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
709 1) >> inode->i_sb->s_blocksize_bits;
710 int8_t etype = (laarr[curr].extLength >> 30); 697 int8_t etype = (laarr[curr].extLength >> 30);
711 698
712 if (blen == 1) ; 699 if (blen == 1) {
713 else if (!offset || blen == offset + 1) { 700 ;
701 } else if (!offset || blen == offset + 1) {
714 laarr[curr + 2] = laarr[curr + 1]; 702 laarr[curr + 2] = laarr[curr + 1];
715 laarr[curr + 1] = laarr[curr]; 703 laarr[curr + 1] = laarr[curr];
716 } else { 704 } else {
@@ -720,20 +708,15 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
720 708
721 if (offset) { 709 if (offset) {
722 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { 710 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
723 udf_free_blocks(inode->i_sb, inode, 711 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
724 laarr[curr].extLocation, 0, 712 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
725 offset); 713 (offset << inode->i_sb->s_blocksize_bits);
726 laarr[curr].extLength =
727 EXT_NOT_RECORDED_NOT_ALLOCATED | (offset <<
728 inode->
729 i_sb->
730 s_blocksize_bits);
731 laarr[curr].extLocation.logicalBlockNum = 0; 714 laarr[curr].extLocation.logicalBlockNum = 0;
732 laarr[curr].extLocation.partitionReferenceNum = 715 laarr[curr].extLocation.partitionReferenceNum = 0;
733 0; 716 } else {
734 } else
735 laarr[curr].extLength = (etype << 30) | 717 laarr[curr].extLength = (etype << 30) |
736 (offset << inode->i_sb->s_blocksize_bits); 718 (offset << inode->i_sb->s_blocksize_bits);
719 }
737 curr++; 720 curr++;
738 (*c)++; 721 (*c)++;
739 (*endnum)++; 722 (*endnum)++;
@@ -742,18 +725,16 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
742 laarr[curr].extLocation.logicalBlockNum = newblocknum; 725 laarr[curr].extLocation.logicalBlockNum = newblocknum;
743 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 726 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
744 laarr[curr].extLocation.partitionReferenceNum = 727 laarr[curr].extLocation.partitionReferenceNum =
745 UDF_I_LOCATION(inode).partitionReferenceNum; 728 UDF_I_LOCATION(inode).partitionReferenceNum;
746 laarr[curr].extLength = EXT_RECORDED_ALLOCATED | 729 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
747 inode->i_sb->s_blocksize; 730 inode->i_sb->s_blocksize;
748 curr++; 731 curr++;
749 732
750 if (blen != offset + 1) { 733 if (blen != offset + 1) {
751 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 734 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
752 laarr[curr].extLocation.logicalBlockNum += 735 laarr[curr].extLocation.logicalBlockNum += (offset + 1);
753 (offset + 1); 736 laarr[curr].extLength = (etype << 30) |
754 laarr[curr].extLength = 737 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
755 (etype << 30) | ((blen - (offset + 1)) << inode->
756 i_sb->s_blocksize_bits);
757 curr++; 738 curr++;
758 (*endnum)++; 739 (*endnum)++;
759 } 740 }
@@ -772,90 +753,69 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
772 else 753 else
773 start = c; 754 start = c;
774 } else { 755 } else {
775 if ((laarr[c + 1].extLength >> 30) == 756 if ((laarr[c + 1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
776 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
777 start = c + 1; 757 start = c + 1;
778 length = currlength = 758 length = currlength = (((laarr[c + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
779 (((laarr[c + 1]. 759 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
780 extLength & UDF_EXTENT_LENGTH_MASK) + 760 } else {
781 inode->i_sb->s_blocksize -
782 1) >> inode->i_sb->s_blocksize_bits);
783 } else
784 start = c; 761 start = c;
762 }
785 } 763 }
786 764
787 for (i = start + 1; i <= *endnum; i++) { 765 for (i = start + 1; i <= *endnum; i++) {
788 if (i == *endnum) { 766 if (i == *endnum) {
789 if (lastblock) 767 if (lastblock)
790 length += UDF_DEFAULT_PREALLOC_BLOCKS; 768 length += UDF_DEFAULT_PREALLOC_BLOCKS;
791 } else if ((laarr[i].extLength >> 30) == 769 } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
792 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 770 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
793 length += 771 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
794 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 772 } else {
795 inode->i_sb->s_blocksize -
796 1) >> inode->i_sb->s_blocksize_bits);
797 else
798 break; 773 break;
774 }
799 } 775 }
800 776
801 if (length) { 777 if (length) {
802 int next = laarr[start].extLocation.logicalBlockNum + 778 int next = laarr[start].extLocation.logicalBlockNum +
803 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + 779 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
804 inode->i_sb->s_blocksize - 780 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
805 1) >> inode->i_sb->s_blocksize_bits);
806 int numalloc = udf_prealloc_blocks(inode->i_sb, inode, 781 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
807 laarr[start].extLocation. 782 laarr[start].extLocation.partitionReferenceNum,
808 partitionReferenceNum, 783 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
809 next, 784 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
810 (UDF_DEFAULT_PREALLOC_BLOCKS 785 if (numalloc) {
811 > 786 if (start == (c + 1)) {
812 length ? length :
813 UDF_DEFAULT_PREALLOC_BLOCKS)
814 - currlength);
815
816 if (numalloc) {
817 if (start == (c + 1))
818 laarr[start].extLength += 787 laarr[start].extLength +=
819 (numalloc << inode->i_sb->s_blocksize_bits); 788 (numalloc << inode->i_sb->s_blocksize_bits);
820 else { 789 } else {
821 memmove(&laarr[c + 2], &laarr[c + 1], 790 memmove(&laarr[c + 2], &laarr[c + 1],
822 sizeof(long_ad) * (*endnum - (c + 1))); 791 sizeof(long_ad) * (*endnum - (c + 1)));
823 (*endnum)++; 792 (*endnum)++;
824 laarr[c + 1].extLocation.logicalBlockNum = next; 793 laarr[c + 1].extLocation.logicalBlockNum = next;
825 laarr[c + 1].extLocation.partitionReferenceNum = 794 laarr[c + 1].extLocation.partitionReferenceNum =
826 laarr[c].extLocation.partitionReferenceNum; 795 laarr[c].extLocation.partitionReferenceNum;
827 laarr[c + 1].extLength = 796 laarr[c + 1].extLength = EXT_NOT_RECORDED_ALLOCATED |
828 EXT_NOT_RECORDED_ALLOCATED | (numalloc << 797 (numalloc << inode->i_sb->s_blocksize_bits);
829 inode->i_sb->
830 s_blocksize_bits);
831 start = c + 1; 798 start = c + 1;
832 } 799 }
833 800
834 for (i = start + 1; numalloc && i < *endnum; i++) { 801 for (i = start + 1; numalloc && i < *endnum; i++) {
835 int elen = 802 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
836 ((laarr[i]. 803 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;
840 804
841 if (elen > numalloc) { 805 if (elen > numalloc) {
842 laarr[i].extLength -= 806 laarr[i].extLength -=
843 (numalloc << inode->i_sb-> 807 (numalloc << inode->i_sb->s_blocksize_bits);
844 s_blocksize_bits);
845 numalloc = 0; 808 numalloc = 0;
846 } else { 809 } else {
847 numalloc -= elen; 810 numalloc -= elen;
848 if (*endnum > (i + 1)) 811 if (*endnum > (i + 1))
849 memmove(&laarr[i], 812 memmove(&laarr[i], &laarr[i + 1],
850 &laarr[i + 1], 813 sizeof(long_ad) * (*endnum - (i + 1)));
851 sizeof(long_ad) *
852 (*endnum - (i + 1)));
853 i--; 814 i--;
854 (*endnum)--; 815 (*endnum)--;
855 } 816 }
856 } 817 }
857 UDF_I_LENEXTENTS(inode) += 818 UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits;
858 numalloc << inode->i_sb->s_blocksize_bits;
859 } 819 }
860 } 820 }
861} 821}
@@ -867,119 +827,68 @@ static void udf_merge_extents(struct inode *inode,
867 int i; 827 int i;
868 828
869 for (i = 0; i < (*endnum - 1); i++) { 829 for (i = 0; i < (*endnum - 1); i++) {
870 if ((laarr[i].extLength >> 30) == 830 if ((laarr[i].extLength >> 30) == (laarr[i + 1].extLength >> 30)) {
871 (laarr[i + 1].extLength >> 30)) { 831 if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
872 if (((laarr[i].extLength >> 30) == 832 ((laarr[i + 1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
873 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
874 ||
875 ((laarr[i + 1].extLocation.logicalBlockNum -
876 laarr[i].extLocation.logicalBlockNum) ==
877 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 833 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
878 inode->i_sb->s_blocksize - 834 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) {
879 1) >> inode->i_sb->s_blocksize_bits))) { 835 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
880 if (((laarr[i]. 836 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
881 extLength & UDF_EXTENT_LENGTH_MASK) + 837 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
882 (laarr[i + 1]. 838 laarr[i + 1].extLength = (laarr[i + 1].extLength -
883 extLength & UDF_EXTENT_LENGTH_MASK) + 839 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
884 inode->i_sb->s_blocksize - 840 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
885 1) & ~UDF_EXTENT_LENGTH_MASK) { 841 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
886 laarr[i + 1].extLength = 842 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
887 (laarr[i + 1].extLength - 843 laarr[i + 1].extLocation.logicalBlockNum =
888 (laarr[i]. 844 laarr[i].extLocation.logicalBlockNum +
889 extLength & 845 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >>
890 UDF_EXTENT_LENGTH_MASK) + 846 inode->i_sb->s_blocksize_bits);
891 UDF_EXTENT_LENGTH_MASK) & ~(inode->
892 i_sb->
893 s_blocksize
894 - 1);
895 laarr[i].extLength =
896 (laarr[i].
897 extLength & UDF_EXTENT_FLAG_MASK) +
898 (UDF_EXTENT_LENGTH_MASK + 1) -
899 inode->i_sb->s_blocksize;
900 laarr[i +
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 { 847 } else {
909 laarr[i].extLength = 848 laarr[i].extLength = laarr[i + 1].extLength +
910 laarr[i + 1].extLength + 849 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
911 (((laarr[i]. 850 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
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)) 851 if (*endnum > (i + 2))
918 memmove(&laarr[i + 1], 852 memmove(&laarr[i + 1], &laarr[i + 2],
919 &laarr[i + 2], 853 sizeof(long_ad) * (*endnum - (i + 2)));
920 sizeof(long_ad) *
921 (*endnum - (i + 2)));
922 i--; 854 i--;
923 (*endnum)--; 855 (*endnum)--;
924 } 856 }
925 } 857 }
926 } else 858 } else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
927 if (((laarr[i].extLength >> 30) == 859 ((laarr[i + 1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
928 (EXT_NOT_RECORDED_ALLOCATED >> 30)) 860 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
929 && ((laarr[i + 1].extLength >> 30) == 861 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
930 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) { 862 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
931 udf_free_blocks(inode->i_sb, inode,
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);
937 laarr[i].extLocation.logicalBlockNum = 0; 863 laarr[i].extLocation.logicalBlockNum = 0;
938 laarr[i].extLocation.partitionReferenceNum = 0; 864 laarr[i].extLocation.partitionReferenceNum = 0;
939 865
940 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 866 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
941 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) + 867 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
942 inode->i_sb->s_blocksize - 868 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
943 1) & ~UDF_EXTENT_LENGTH_MASK) { 869 laarr[i + 1].extLength = (laarr[i + 1].extLength -
944 laarr[i + 1].extLength = 870 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
945 (laarr[i + 1].extLength - 871 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
946 (laarr[i]. 872 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
947 extLength & UDF_EXTENT_LENGTH_MASK) + 873 (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 { 874 } else {
957 laarr[i].extLength = laarr[i + 1].extLength + 875 laarr[i].extLength = laarr[i + 1].extLength +
958 (((laarr[i]. 876 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
959 extLength & UDF_EXTENT_LENGTH_MASK) + 877 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
960 inode->i_sb->s_blocksize -
961 1) & ~(inode->i_sb->s_blocksize - 1));
962 if (*endnum > (i + 2)) 878 if (*endnum > (i + 2))
963 memmove(&laarr[i + 1], &laarr[i + 2], 879 memmove(&laarr[i + 1], &laarr[i + 2],
964 sizeof(long_ad) * (*endnum - 880 sizeof(long_ad) * (*endnum - (i + 2)));
965 (i + 2)));
966 i--; 881 i--;
967 (*endnum)--; 882 (*endnum)--;
968 } 883 }
969 } else if ((laarr[i].extLength >> 30) == 884 } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
970 (EXT_NOT_RECORDED_ALLOCATED >> 30)) { 885 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
971 udf_free_blocks(inode->i_sb, inode, 886 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
972 laarr[i].extLocation, 0, 887 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
973 ((laarr[i].
974 extLength & UDF_EXTENT_LENGTH_MASK) +
975 inode->i_sb->s_blocksize -
976 1) >> inode->i_sb->s_blocksize_bits);
977 laarr[i].extLocation.logicalBlockNum = 0; 888 laarr[i].extLocation.logicalBlockNum = 0;
978 laarr[i].extLocation.partitionReferenceNum = 0; 889 laarr[i].extLocation.partitionReferenceNum = 0;
979 laarr[i].extLength = 890 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) |
980 (laarr[i]. 891 EXT_NOT_RECORDED_NOT_ALLOCATED;
981 extLength & UDF_EXTENT_LENGTH_MASK) |
982 EXT_NOT_RECORDED_NOT_ALLOCATED;
983 } 892 }
984 } 893 }
985} 894}
@@ -1025,10 +934,13 @@ struct buffer_head *udf_bread(struct inode *inode, int block,
1025 934
1026 if (buffer_uptodate(bh)) 935 if (buffer_uptodate(bh))
1027 return bh; 936 return bh;
937
1028 ll_rw_block(READ, 1, &bh); 938 ll_rw_block(READ, 1, &bh);
939
1029 wait_on_buffer(bh); 940 wait_on_buffer(bh);
1030 if (buffer_uptodate(bh)) 941 if (buffer_uptodate(bh))
1031 return bh; 942 return bh;
943
1032 brelse(bh); 944 brelse(bh);
1033 *err = -EIO; 945 *err = -EIO;
1034 return NULL; 946 return NULL;
@@ -1047,26 +959,24 @@ void udf_truncate(struct inode *inode)
1047 959
1048 lock_kernel(); 960 lock_kernel();
1049 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { 961 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1050 if (inode->i_sb->s_blocksize < 962 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
1051 (udf_file_entry_alloc_offset(inode) + inode->i_size)) { 963 inode->i_size)) {
1052 udf_expand_file_adinicb(inode, inode->i_size, &err); 964 udf_expand_file_adinicb(inode, inode->i_size, &err);
1053 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { 965 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1054 inode->i_size = UDF_I_LENALLOC(inode); 966 inode->i_size = UDF_I_LENALLOC(inode);
1055 unlock_kernel(); 967 unlock_kernel();
1056 return; 968 return;
1057 } else 969 } else {
1058 udf_truncate_extents(inode); 970 udf_truncate_extents(inode);
971 }
1059 } else { 972 } else {
1060 offset = inode->i_size & (inode->i_sb->s_blocksize - 1); 973 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1061 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + 974 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00,
1062 offset, 0x00, 975 inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode));
1063 inode->i_sb->s_blocksize - offset -
1064 udf_file_entry_alloc_offset(inode));
1065 UDF_I_LENALLOC(inode) = inode->i_size; 976 UDF_I_LENALLOC(inode) = inode->i_size;
1066 } 977 }
1067 } else { 978 } else {
1068 block_truncate_page(inode->i_mapping, inode->i_size, 979 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
1069 udf_get_block);
1070 udf_truncate_extents(inode); 980 udf_truncate_extents(inode);
1071 } 981 }
1072 982
@@ -1097,7 +1007,6 @@ static void __udf_read_inode(struct inode *inode)
1097 * i_op = NULL; 1007 * i_op = NULL;
1098 */ 1008 */
1099 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident); 1009 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1100
1101 if (!bh) { 1010 if (!bh) {
1102 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", 1011 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1103 inode->i_ino); 1012 inode->i_ino);
@@ -1107,8 +1016,7 @@ static void __udf_read_inode(struct inode *inode)
1107 1016
1108 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && 1017 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1109 ident != TAG_IDENT_USE) { 1018 ident != TAG_IDENT_USE) {
1110 printk(KERN_ERR 1019 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1111 "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1112 inode->i_ino, ident); 1020 inode->i_ino, ident);
1113 brelse(bh); 1021 brelse(bh);
1114 make_bad_inode(inode); 1022 make_bad_inode(inode);
@@ -1121,9 +1029,7 @@ static void __udf_read_inode(struct inode *inode)
1121 struct buffer_head *ibh = NULL, *nbh = NULL; 1029 struct buffer_head *ibh = NULL, *nbh = NULL;
1122 struct indirectEntry *ie; 1030 struct indirectEntry *ie;
1123 1031
1124 ibh = 1032 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
1125 udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
1126 &ident);
1127 if (ident == TAG_IDENT_IE) { 1033 if (ident == TAG_IDENT_IE) {
1128 if (ibh) { 1034 if (ibh) {
1129 kernel_lb_addr loc; 1035 kernel_lb_addr loc;
@@ -1132,13 +1038,10 @@ static void __udf_read_inode(struct inode *inode)
1132 loc = lelb_to_cpu(ie->indirectICB.extLocation); 1038 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1133 1039
1134 if (ie->indirectICB.extLength && 1040 if (ie->indirectICB.extLength &&
1135 (nbh = 1041 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) {
1136 udf_read_ptagged(inode->i_sb, loc, 0, 1042 if (ident == TAG_IDENT_FE ||
1137 &ident))) { 1043 ident == TAG_IDENT_EFE) {
1138 if (ident == TAG_IDENT_FE 1044 memcpy(&UDF_I_LOCATION(inode), &loc,
1139 || ident == TAG_IDENT_EFE) {
1140 memcpy(&UDF_I_LOCATION(inode),
1141 &loc,
1142 sizeof(kernel_lb_addr)); 1045 sizeof(kernel_lb_addr));
1143 brelse(bh); 1046 brelse(bh);
1144 brelse(ibh); 1047 brelse(ibh);
@@ -1149,11 +1052,13 @@ static void __udf_read_inode(struct inode *inode)
1149 brelse(nbh); 1052 brelse(nbh);
1150 brelse(ibh); 1053 brelse(ibh);
1151 } 1054 }
1152 } else 1055 } else {
1153 brelse(ibh); 1056 brelse(ibh);
1057 }
1154 } 1058 }
1155 } else 1059 } else {
1156 brelse(ibh); 1060 brelse(ibh);
1061 }
1157 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) { 1062 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1158 printk(KERN_ERR "udf: unsupported strategy type: %d\n", 1063 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1159 le16_to_cpu(fe->icbTag.strategyType)); 1064 le16_to_cpu(fe->icbTag.strategyType));
@@ -1179,11 +1084,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1179 1084
1180 if (le16_to_cpu(fe->icbTag.strategyType) == 4) 1085 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
1181 UDF_I_STRAT4096(inode) = 0; 1086 UDF_I_STRAT4096(inode) = 0;
1182 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ 1087 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
1183 UDF_I_STRAT4096(inode) = 1; 1088 UDF_I_STRAT4096(inode) = 1;
1184 1089
1185 UDF_I_ALLOCTYPE(inode) = 1090 UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
1186 le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
1187 UDF_I_UNIQUE(inode) = 0; 1091 UDF_I_UNIQUE(inode) = 0;
1188 UDF_I_LENEATTR(inode) = 0; 1092 UDF_I_LENEATTR(inode) = 0;
1189 UDF_I_LENEXTENTS(inode) = 0; 1093 UDF_I_LENEXTENTS(inode) = 0;
@@ -1193,23 +1097,16 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1193 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) { 1097 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1194 UDF_I_EFE(inode) = 1; 1098 UDF_I_EFE(inode) = 1;
1195 UDF_I_USE(inode) = 0; 1099 UDF_I_USE(inode) = 0;
1196 if (udf_alloc_i_data 1100 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) {
1197 (inode,
1198 inode->i_sb->s_blocksize -
1199 sizeof(struct extendedFileEntry))) {
1200 make_bad_inode(inode); 1101 make_bad_inode(inode);
1201 return; 1102 return;
1202 } 1103 }
1203 memcpy(UDF_I_DATA(inode), 1104 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry),
1204 bh->b_data + sizeof(struct extendedFileEntry), 1105 inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
1205 inode->i_sb->s_blocksize -
1206 sizeof(struct extendedFileEntry));
1207 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) { 1106 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1208 UDF_I_EFE(inode) = 0; 1107 UDF_I_EFE(inode) = 0;
1209 UDF_I_USE(inode) = 0; 1108 UDF_I_USE(inode) = 0;
1210 if (udf_alloc_i_data 1109 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1211 (inode,
1212 inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1213 make_bad_inode(inode); 1110 make_bad_inode(inode);
1214 return; 1111 return;
1215 } 1112 }
@@ -1219,19 +1116,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1219 UDF_I_EFE(inode) = 0; 1116 UDF_I_EFE(inode) = 0;
1220 UDF_I_USE(inode) = 1; 1117 UDF_I_USE(inode) = 1;
1221 UDF_I_LENALLOC(inode) = 1118 UDF_I_LENALLOC(inode) =
1222 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)-> 1119 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs);
1223 lengthAllocDescs); 1120 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) {
1224 if (udf_alloc_i_data
1225 (inode,
1226 inode->i_sb->s_blocksize -
1227 sizeof(struct unallocSpaceEntry))) {
1228 make_bad_inode(inode); 1121 make_bad_inode(inode);
1229 return; 1122 return;
1230 } 1123 }
1231 memcpy(UDF_I_DATA(inode), 1124 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry),
1232 bh->b_data + sizeof(struct unallocSpaceEntry), 1125 inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
1233 inode->i_sb->s_blocksize -
1234 sizeof(struct unallocSpaceEntry));
1235 return; 1126 return;
1236 } 1127 }
1237 1128
@@ -1257,7 +1148,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1257 1148
1258 if (UDF_I_EFE(inode) == 0) { 1149 if (UDF_I_EFE(inode) == 0) {
1259 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << 1150 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1260 (inode->i_sb->s_blocksize_bits - 9); 1151 (inode->i_sb->s_blocksize_bits - 9);
1261 1152
1262 if (udf_stamp_to_time(&convtime, &convtime_usec, 1153 if (udf_stamp_to_time(&convtime, &convtime_usec,
1263 lets_to_cpu(fe->accessTime))) { 1154 lets_to_cpu(fe->accessTime))) {
@@ -1326,78 +1217,56 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1326 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); 1217 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1327 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); 1218 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1328 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); 1219 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1329 offset = 1220 offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1330 sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1331 } 1221 }
1332 1222
1333 switch (fe->icbTag.fileType) { 1223 switch (fe->icbTag.fileType) {
1334 case ICBTAG_FILE_TYPE_DIRECTORY: 1224 case ICBTAG_FILE_TYPE_DIRECTORY:
1335 { 1225 inode->i_op = &udf_dir_inode_operations;
1336 inode->i_op = &udf_dir_inode_operations; 1226 inode->i_fop = &udf_dir_operations;
1337 inode->i_fop = &udf_dir_operations; 1227 inode->i_mode |= S_IFDIR;
1338 inode->i_mode |= S_IFDIR; 1228 inc_nlink(inode);
1339 inc_nlink(inode); 1229 break;
1340 break;
1341 }
1342 case ICBTAG_FILE_TYPE_REALTIME: 1230 case ICBTAG_FILE_TYPE_REALTIME:
1343 case ICBTAG_FILE_TYPE_REGULAR: 1231 case ICBTAG_FILE_TYPE_REGULAR:
1344 case ICBTAG_FILE_TYPE_UNDEF: 1232 case ICBTAG_FILE_TYPE_UNDEF:
1345 { 1233 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1346 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1234 inode->i_data.a_ops = &udf_adinicb_aops;
1347 inode->i_data.a_ops = &udf_adinicb_aops; 1235 else
1348 else 1236 inode->i_data.a_ops = &udf_aops;
1349 inode->i_data.a_ops = &udf_aops; 1237 inode->i_op = &udf_file_inode_operations;
1350 inode->i_op = &udf_file_inode_operations; 1238 inode->i_fop = &udf_file_operations;
1351 inode->i_fop = &udf_file_operations; 1239 inode->i_mode |= S_IFREG;
1352 inode->i_mode |= S_IFREG; 1240 break;
1353 break;
1354 }
1355 case ICBTAG_FILE_TYPE_BLOCK: 1241 case ICBTAG_FILE_TYPE_BLOCK:
1356 { 1242 inode->i_mode |= S_IFBLK;
1357 inode->i_mode |= S_IFBLK; 1243 break;
1358 break;
1359 }
1360 case ICBTAG_FILE_TYPE_CHAR: 1244 case ICBTAG_FILE_TYPE_CHAR:
1361 { 1245 inode->i_mode |= S_IFCHR;
1362 inode->i_mode |= S_IFCHR; 1246 break;
1363 break;
1364 }
1365 case ICBTAG_FILE_TYPE_FIFO: 1247 case ICBTAG_FILE_TYPE_FIFO:
1366 { 1248 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1367 init_special_inode(inode, inode->i_mode | S_IFIFO, 0); 1249 break;
1368 break;
1369 }
1370 case ICBTAG_FILE_TYPE_SOCKET: 1250 case ICBTAG_FILE_TYPE_SOCKET:
1371 { 1251 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1372 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0); 1252 break;
1373 break;
1374 }
1375 case ICBTAG_FILE_TYPE_SYMLINK: 1253 case ICBTAG_FILE_TYPE_SYMLINK:
1376 { 1254 inode->i_data.a_ops = &udf_symlink_aops;
1377 inode->i_data.a_ops = &udf_symlink_aops; 1255 inode->i_op = &page_symlink_inode_operations;
1378 inode->i_op = &page_symlink_inode_operations; 1256 inode->i_mode = S_IFLNK | S_IRWXUGO;
1379 inode->i_mode = S_IFLNK | S_IRWXUGO; 1257 break;
1380 break;
1381 }
1382 default: 1258 default:
1383 { 1259 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1384 printk(KERN_ERR 1260 inode->i_ino, fe->icbTag.fileType);
1385 "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n", 1261 make_bad_inode(inode);
1386 inode->i_ino, fe->icbTag.fileType); 1262 return;
1387 make_bad_inode(inode);
1388 return;
1389 }
1390 } 1263 }
1391 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { 1264 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1392 struct deviceSpec *dsea = (struct deviceSpec *) 1265 struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1393 udf_get_extendedattr(inode, 12, 1);
1394
1395 if (dsea) { 1266 if (dsea) {
1396 init_special_inode(inode, inode->i_mode, 1267 init_special_inode(inode, inode->i_mode,
1397 MKDEV(le32_to_cpu 1268 MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
1398 (dsea->majorDeviceIdent), 1269 le32_to_cpu(dsea->minorDeviceIdent)));
1399 le32_to_cpu(dsea->
1400 minorDeviceIdent)));
1401 /* Developer ID ??? */ 1270 /* Developer ID ??? */
1402 } else { 1271 } else {
1403 make_bad_inode(inode); 1272 make_bad_inode(inode);
@@ -1410,8 +1279,7 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
1410 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); 1279 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1411 1280
1412 if (!UDF_I_DATA(inode)) { 1281 if (!UDF_I_DATA(inode)) {
1413 printk(KERN_ERR 1282 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",
1415 inode->i_ino); 1283 inode->i_ino);
1416 return -ENOMEM; 1284 return -ENOMEM;
1417 } 1285 }
@@ -1428,12 +1296,12 @@ static mode_t udf_convert_permissions(struct fileEntry *fe)
1428 permissions = le32_to_cpu(fe->permissions); 1296 permissions = le32_to_cpu(fe->permissions);
1429 flags = le16_to_cpu(fe->icbTag.flags); 1297 flags = le16_to_cpu(fe->icbTag.flags);
1430 1298
1431 mode = ((permissions) & S_IRWXO) | 1299 mode = (( permissions ) & S_IRWXO) |
1432 ((permissions >> 2) & S_IRWXG) | 1300 (( permissions >> 2 ) & S_IRWXG) |
1433 ((permissions >> 4) & S_IRWXU) | 1301 (( permissions >> 4 ) & S_IRWXU) |
1434 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | 1302 (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1435 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | 1303 (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1436 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); 1304 (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1437 1305
1438 return mode; 1306 return mode;
1439} 1307}
@@ -1456,9 +1324,11 @@ static mode_t udf_convert_permissions(struct fileEntry *fe)
1456int udf_write_inode(struct inode *inode, int sync) 1324int udf_write_inode(struct inode *inode, int sync)
1457{ 1325{
1458 int ret; 1326 int ret;
1327
1459 lock_kernel(); 1328 lock_kernel();
1460 ret = udf_update_inode(inode, sync); 1329 ret = udf_update_inode(inode, sync);
1461 unlock_kernel(); 1330 unlock_kernel();
1331
1462 return ret; 1332 return ret;
1463} 1333}
1464 1334
@@ -1479,10 +1349,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1479 kernel_timestamp cpu_time; 1349 kernel_timestamp cpu_time;
1480 int err = 0; 1350 int err = 0;
1481 1351
1482 bh = udf_tread(inode->i_sb, 1352 bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0));
1483 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode),
1484 0));
1485
1486 if (!bh) { 1353 if (!bh) {
1487 udf_debug("bread failure\n"); 1354 udf_debug("bread failure\n");
1488 return -EIO; 1355 return -EIO;
@@ -1495,27 +1362,21 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1495 1362
1496 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) { 1363 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1497 struct unallocSpaceEntry *use = 1364 struct unallocSpaceEntry *use =
1498 (struct unallocSpaceEntry *)bh->b_data; 1365 (struct unallocSpaceEntry *)bh->b_data;
1499 1366
1500 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1367 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1501 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), 1368 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode),
1502 UDF_I_DATA(inode), 1369 inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
1503 inode->i_sb->s_blocksize - 1370 crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - sizeof(tag);
1504 sizeof(struct unallocSpaceEntry)); 1371 use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
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);
1510 use->descTag.descCRCLength = cpu_to_le16(crclen); 1372 use->descTag.descCRCLength = cpu_to_le16(crclen);
1511 use->descTag.descCRC = 1373 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1512 cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1513 1374
1514 use->descTag.tagChecksum = 0; 1375 use->descTag.tagChecksum = 0;
1515 for (i = 0; i < 16; i++) 1376 for (i = 0; i < 16; i++) {
1516 if (i != 4) 1377 if (i != 4)
1517 use->descTag.tagChecksum += 1378 use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i];
1518 ((uint8_t *) & (use->descTag))[i]; 1379 }
1519 1380
1520 mark_buffer_dirty(bh); 1381 mark_buffer_dirty(bh);
1521 brelse(bh); 1382 brelse(bh);
@@ -1532,13 +1393,14 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1532 else 1393 else
1533 fe->gid = cpu_to_le32(inode->i_gid); 1394 fe->gid = cpu_to_le32(inode->i_gid);
1534 1395
1535 udfperms = ((inode->i_mode & S_IRWXO)) | 1396 udfperms = ((inode->i_mode & S_IRWXO) ) |
1536 ((inode->i_mode & S_IRWXG) << 2) | ((inode->i_mode & S_IRWXU) << 4); 1397 ((inode->i_mode & S_IRWXG) << 2) |
1398 ((inode->i_mode & S_IRWXU) << 4);
1537 1399
1538 udfperms |= (le32_to_cpu(fe->permissions) & 1400 udfperms |= (le32_to_cpu(fe->permissions) &
1539 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | 1401 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1540 FE_PERM_G_DELETE | FE_PERM_G_CHATTR | 1402 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1541 FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); 1403 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1542 fe->permissions = cpu_to_le32(udfperms); 1404 fe->permissions = cpu_to_le32(udfperms);
1543 1405
1544 if (S_ISDIR(inode->i_mode)) 1406 if (S_ISDIR(inode->i_mode))
@@ -1550,22 +1412,20 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1550 1412
1551 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { 1413 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1552 regid *eid; 1414 regid *eid;
1553 struct deviceSpec *dsea = (struct deviceSpec *) 1415 struct deviceSpec *dsea =
1554 udf_get_extendedattr(inode, 12, 1); 1416 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1555
1556 if (!dsea) { 1417 if (!dsea) {
1557 dsea = (struct deviceSpec *) 1418 dsea = (struct deviceSpec *)
1558 udf_add_extendedattr(inode, 1419 udf_add_extendedattr(inode,
1559 sizeof(struct deviceSpec) + 1420 sizeof(struct deviceSpec) +
1560 sizeof(regid), 12, 0x3); 1421 sizeof(regid), 12, 0x3);
1561 dsea->attrType = cpu_to_le32(12); 1422 dsea->attrType = cpu_to_le32(12);
1562 dsea->attrSubtype = 1; 1423 dsea->attrSubtype = 1;
1563 dsea->attrLength = 1424 dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) +
1564 cpu_to_le32(sizeof(struct deviceSpec) + 1425 sizeof(regid));
1565 sizeof(regid));
1566 dsea->impUseLength = cpu_to_le32(sizeof(regid)); 1426 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1567 } 1427 }
1568 eid = (regid *) dsea->impUse; 1428 eid = (regid *)dsea->impUse;
1569 memset(eid, 0, sizeof(regid)); 1429 memset(eid, 0, sizeof(regid));
1570 strcpy(eid->ident, UDF_ID_DEVELOPER); 1430 strcpy(eid->ident, UDF_ID_DEVELOPER);
1571 eid->identSuffix[0] = UDF_OS_CLASS_UNIX; 1431 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1577,10 +1437,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1577 if (UDF_I_EFE(inode) == 0) { 1437 if (UDF_I_EFE(inode) == 0) {
1578 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), 1438 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1579 inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1439 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1580 fe->logicalBlocksRecorded = 1440 fe->logicalBlocksRecorded = cpu_to_le64(
1581 cpu_to_le64((inode->i_blocks + 1441 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1582 (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1442 (inode->i_sb->s_blocksize_bits - 9));
1583 1) >> (inode->i_sb->s_blocksize_bits - 9));
1584 1443
1585 if (udf_time_to_stamp(&cpu_time, inode->i_atime)) 1444 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1586 fe->accessTime = cpu_to_lets(cpu_time); 1445 fe->accessTime = cpu_to_lets(cpu_time);
@@ -1598,19 +1457,12 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1598 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); 1457 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1599 crclen = sizeof(struct fileEntry); 1458 crclen = sizeof(struct fileEntry);
1600 } else { 1459 } else {
1601 memcpy(bh->b_data + sizeof(struct extendedFileEntry), 1460 memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode),
1602 UDF_I_DATA(inode), 1461 inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
1603 inode->i_sb->s_blocksize -
1604 sizeof(struct extendedFileEntry));
1605 efe->objectSize = cpu_to_le64(inode->i_size); 1462 efe->objectSize = cpu_to_le64(inode->i_size);
1606 efe->logicalBlocksRecorded = cpu_to_le64((inode->i_blocks + 1463 efe->logicalBlocksRecorded = cpu_to_le64(
1607 (1 << 1464 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1608 (inode->i_sb-> 1465 (inode->i_sb->s_blocksize_bits - 9));
1609 s_blocksize_bits -
1610 9)) -
1611 1) >> (inode->i_sb->
1612 s_blocksize_bits
1613 - 9));
1614 1466
1615 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || 1467 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1616 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && 1468 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
@@ -1671,13 +1523,13 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1671 else if (S_ISSOCK(inode->i_mode)) 1523 else if (S_ISSOCK(inode->i_mode))
1672 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET; 1524 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1673 1525
1674 icbflags = UDF_I_ALLOCTYPE(inode) | 1526 icbflags = UDF_I_ALLOCTYPE(inode) |
1675 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) | 1527 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1676 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) | 1528 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1677 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) | 1529 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1678 (le16_to_cpu(fe->icbTag.flags) & 1530 (le16_to_cpu(fe->icbTag.flags) &
1679 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID | 1531 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1680 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY)); 1532 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1681 1533
1682 fe->icbTag.flags = cpu_to_le16(icbflags); 1534 fe->icbTag.flags = cpu_to_le16(icbflags);
1683 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1535 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
@@ -1685,18 +1537,16 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1685 else 1537 else
1686 fe->descTag.descVersion = cpu_to_le16(2); 1538 fe->descTag.descVersion = cpu_to_le16(2);
1687 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); 1539 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
1688 fe->descTag.tagLocation = 1540 fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1689 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1690 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); 1541 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1691 fe->descTag.descCRCLength = cpu_to_le16(crclen); 1542 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1692 fe->descTag.descCRC = 1543 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1693 cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1694 1544
1695 fe->descTag.tagChecksum = 0; 1545 fe->descTag.tagChecksum = 0;
1696 for (i = 0; i < 16; i++) 1546 for (i = 0; i < 16; i++) {
1697 if (i != 4) 1547 if (i != 4)
1698 fe->descTag.tagChecksum += 1548 fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i];
1699 ((uint8_t *) & (fe->descTag))[i]; 1549 }
1700 1550
1701 /* write the data blocks */ 1551 /* write the data blocks */
1702 mark_buffer_dirty(bh); 1552 mark_buffer_dirty(bh);
@@ -1709,6 +1559,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1709 } 1559 }
1710 } 1560 }
1711 brelse(bh); 1561 brelse(bh);
1562
1712 return err; 1563 return err;
1713} 1564}
1714 1565
@@ -1729,8 +1580,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1729 if (is_bad_inode(inode)) 1580 if (is_bad_inode(inode))
1730 goto out_iput; 1581 goto out_iput;
1731 1582
1732 if (ino.logicalBlockNum >= 1583 if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1733 UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1734 udf_debug("block=%d, partition=%d out of range\n", 1584 udf_debug("block=%d, partition=%d out of range\n",
1735 ino.logicalBlockNum, ino.partitionReferenceNum); 1585 ino.logicalBlockNum, ino.partitionReferenceNum);
1736 make_bad_inode(inode); 1586 make_bad_inode(inode);
@@ -1739,7 +1589,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1739 1589
1740 return inode; 1590 return inode;
1741 1591
1742 out_iput: 1592 out_iput:
1743 iput(inode); 1593 iput(inode);
1744 return NULL; 1594 return NULL;
1745} 1595}
@@ -1755,9 +1605,7 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1755 uint8_t *ptr; 1605 uint8_t *ptr;
1756 1606
1757 if (!epos->bh) 1607 if (!epos->bh)
1758 ptr = 1608 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1759 UDF_I_DATA(inode) + epos->offset -
1760 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1761 else 1609 else
1762 ptr = epos->bh->b_data + epos->offset; 1610 ptr = epos->bh->b_data + epos->offset;
1763 1611
@@ -1774,18 +1622,13 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1774 int err, loffset; 1622 int err, loffset;
1775 kernel_lb_addr obloc = epos->block; 1623 kernel_lb_addr obloc = epos->block;
1776 1624
1777 if (! 1625 if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
1778 (epos->block.logicalBlockNum = 1626 obloc.partitionReferenceNum,
1779 udf_new_block(inode->i_sb, NULL, 1627 obloc.logicalBlockNum, &err))) {
1780 obloc.partitionReferenceNum,
1781 obloc.logicalBlockNum, &err))) {
1782 return -1; 1628 return -1;
1783 } 1629 }
1784 if (! 1630 if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1785 (nbh = 1631 epos->block, 0)))) {
1786 udf_tgetblk(inode->i_sb,
1787 udf_get_lb_pblock(inode->i_sb, epos->block,
1788 0)))) {
1789 return -1; 1632 return -1;
1790 } 1633 }
1791 lock_buffer(nbh); 1634 lock_buffer(nbh);
@@ -1796,8 +1639,7 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1796 1639
1797 aed = (struct allocExtDesc *)(nbh->b_data); 1640 aed = (struct allocExtDesc *)(nbh->b_data);
1798 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 1641 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1799 aed->previousAllocExtLocation = 1642 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
1800 cpu_to_le32(obloc.logicalBlockNum);
1801 if (epos->offset + adsize > inode->i_sb->s_blocksize) { 1643 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1802 loffset = epos->offset; 1644 loffset = epos->offset;
1803 aed->lengthAllocDescs = cpu_to_le32(adsize); 1645 aed->lengthAllocDescs = cpu_to_le32(adsize);
@@ -1814,9 +1656,7 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1814 if (epos->bh) { 1656 if (epos->bh) {
1815 aed = (struct allocExtDesc *)epos->bh->b_data; 1657 aed = (struct allocExtDesc *)epos->bh->b_data;
1816 aed->lengthAllocDescs = 1658 aed->lengthAllocDescs =
1817 cpu_to_le32(le32_to_cpu 1659 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1818 (aed->lengthAllocDescs) +
1819 adsize);
1820 } else { 1660 } else {
1821 UDF_I_LENALLOC(inode) += adsize; 1661 UDF_I_LENALLOC(inode) += adsize;
1822 mark_inode_dirty(inode); 1662 mark_inode_dirty(inode);
@@ -1830,37 +1670,30 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1830 epos->block.logicalBlockNum, sizeof(tag)); 1670 epos->block.logicalBlockNum, sizeof(tag));
1831 switch (UDF_I_ALLOCTYPE(inode)) { 1671 switch (UDF_I_ALLOCTYPE(inode)) {
1832 case ICBTAG_FLAG_AD_SHORT: 1672 case ICBTAG_FLAG_AD_SHORT:
1833 { 1673 sad = (short_ad *)sptr;
1834 sad = (short_ad *) sptr; 1674 sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1835 sad->extLength = 1675 inode->i_sb->s_blocksize);
1836 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | 1676 sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum);
1837 inode->i_sb->s_blocksize); 1677 break;
1838 sad->extPosition =
1839 cpu_to_le32(epos->block.logicalBlockNum);
1840 break;
1841 }
1842 case ICBTAG_FLAG_AD_LONG: 1678 case ICBTAG_FLAG_AD_LONG:
1843 { 1679 lad = (long_ad *)sptr;
1844 lad = (long_ad *) sptr; 1680 lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1845 lad->extLength = 1681 inode->i_sb->s_blocksize);
1846 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS | 1682 lad->extLocation = cpu_to_lelb(epos->block);
1847 inode->i_sb->s_blocksize); 1683 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1848 lad->extLocation = cpu_to_lelb(epos->block); 1684 break;
1849 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1850 break;
1851 }
1852 } 1685 }
1853 if (epos->bh) { 1686 if (epos->bh) {
1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) 1687 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1855 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1688 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1856 udf_update_tag(epos->bh->b_data, loffset); 1689 udf_update_tag(epos->bh->b_data, loffset);
1857 else 1690 else
1858 udf_update_tag(epos->bh->b_data, 1691 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
1859 sizeof(struct allocExtDesc));
1860 mark_buffer_dirty_inode(epos->bh, inode); 1692 mark_buffer_dirty_inode(epos->bh, inode);
1861 brelse(epos->bh); 1693 brelse(epos->bh);
1862 } else 1694 } else {
1863 mark_inode_dirty(inode); 1695 mark_inode_dirty(inode);
1696 }
1864 epos->bh = nbh; 1697 epos->bh = nbh;
1865 } 1698 }
1866 1699
@@ -1872,14 +1705,11 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1872 } else { 1705 } else {
1873 aed = (struct allocExtDesc *)epos->bh->b_data; 1706 aed = (struct allocExtDesc *)epos->bh->b_data;
1874 aed->lengthAllocDescs = 1707 aed->lengthAllocDescs =
1875 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1708 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1876 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) 1709 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1877 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1710 udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize));
1878 udf_update_tag(epos->bh->b_data,
1879 epos->offset + (inc ? 0 : adsize));
1880 else 1711 else
1881 udf_update_tag(epos->bh->b_data, 1712 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
1882 sizeof(struct allocExtDesc));
1883 mark_buffer_dirty_inode(epos->bh, inode); 1713 mark_buffer_dirty_inode(epos->bh, inode);
1884 } 1714 }
1885 1715
@@ -1891,51 +1721,47 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
1891{ 1721{
1892 int adsize; 1722 int adsize;
1893 uint8_t *ptr; 1723 uint8_t *ptr;
1724 short_ad *sad;
1725 long_ad *lad;
1894 1726
1895 if (!epos->bh) 1727 if (!epos->bh)
1896 ptr = 1728 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1897 UDF_I_DATA(inode) + epos->offset -
1898 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1899 else 1729 else
1900 ptr = epos->bh->b_data + epos->offset; 1730 ptr = epos->bh->b_data + epos->offset;
1901 1731
1902 switch (UDF_I_ALLOCTYPE(inode)) { 1732 switch (UDF_I_ALLOCTYPE(inode)) {
1903 case ICBTAG_FLAG_AD_SHORT: 1733 case ICBTAG_FLAG_AD_SHORT:
1904 { 1734 sad = (short_ad *)ptr;
1905 short_ad *sad = (short_ad *) ptr; 1735 sad->extLength = cpu_to_le32(elen);
1906 sad->extLength = cpu_to_le32(elen); 1736 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1907 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum); 1737 adsize = sizeof(short_ad);
1908 adsize = sizeof(short_ad); 1738 break;
1909 break;
1910 }
1911 case ICBTAG_FLAG_AD_LONG: 1739 case ICBTAG_FLAG_AD_LONG:
1912 { 1740 lad = (long_ad *)ptr;
1913 long_ad *lad = (long_ad *) ptr; 1741 lad->extLength = cpu_to_le32(elen);
1914 lad->extLength = cpu_to_le32(elen); 1742 lad->extLocation = cpu_to_lelb(eloc);
1915 lad->extLocation = cpu_to_lelb(eloc); 1743 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1916 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1744 adsize = sizeof(long_ad);
1917 adsize = sizeof(long_ad); 1745 break;
1918 break;
1919 }
1920 default: 1746 default:
1921 return -1; 1747 return -1;
1922 } 1748 }
1923 1749
1924 if (epos->bh) { 1750 if (epos->bh) {
1925 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) 1751 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1926 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) { 1752 UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
1927 struct allocExtDesc *aed = 1753 struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data;
1928 (struct allocExtDesc *)epos->bh->b_data;
1929 udf_update_tag(epos->bh->b_data, 1754 udf_update_tag(epos->bh->b_data,
1930 le32_to_cpu(aed->lengthAllocDescs) + 1755 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc));
1931 sizeof(struct allocExtDesc));
1932 } 1756 }
1933 mark_buffer_dirty_inode(epos->bh, inode); 1757 mark_buffer_dirty_inode(epos->bh, inode);
1934 } else 1758 } else {
1935 mark_inode_dirty(inode); 1759 mark_inode_dirty(inode);
1760 }
1936 1761
1937 if (inc) 1762 if (inc)
1938 epos->offset += adsize; 1763 epos->offset += adsize;
1764
1939 return (elen >> 30); 1765 return (elen >> 30);
1940} 1766}
1941 1767
@@ -1949,14 +1775,9 @@ int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
1949 epos->block = *eloc; 1775 epos->block = *eloc;
1950 epos->offset = sizeof(struct allocExtDesc); 1776 epos->offset = sizeof(struct allocExtDesc);
1951 brelse(epos->bh); 1777 brelse(epos->bh);
1952 if (! 1778 if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) {
1953 (epos->bh =
1954 udf_tread(inode->i_sb,
1955 udf_get_lb_pblock(inode->i_sb, epos->block,
1956 0)))) {
1957 udf_debug("reading block %d failed!\n", 1779 udf_debug("reading block %d failed!\n",
1958 udf_get_lb_pblock(inode->i_sb, epos->block, 1780 udf_get_lb_pblock(inode->i_sb, epos->block, 0));
1959 0));
1960 return -1; 1781 return -1;
1961 } 1782 }
1962 } 1783 }
@@ -1970,75 +1791,49 @@ int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
1970 int alen; 1791 int alen;
1971 int8_t etype; 1792 int8_t etype;
1972 uint8_t *ptr; 1793 uint8_t *ptr;
1794 short_ad *sad;
1795 long_ad *lad;
1796
1973 1797
1974 if (!epos->bh) { 1798 if (!epos->bh) {
1975 if (!epos->offset) 1799 if (!epos->offset)
1976 epos->offset = udf_file_entry_alloc_offset(inode); 1800 epos->offset = udf_file_entry_alloc_offset(inode);
1977 ptr = 1801 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1978 UDF_I_DATA(inode) + epos->offset - 1802 alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1979 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1980 alen =
1981 udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1982 } else { 1803 } else {
1983 if (!epos->offset) 1804 if (!epos->offset)
1984 epos->offset = sizeof(struct allocExtDesc); 1805 epos->offset = sizeof(struct allocExtDesc);
1985 ptr = epos->bh->b_data + epos->offset; 1806 ptr = epos->bh->b_data + epos->offset;
1986 alen = 1807 alen = sizeof(struct allocExtDesc) +
1987 sizeof(struct allocExtDesc) + 1808 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs);
1988 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1989 lengthAllocDescs);
1990 } 1809 }
1991 1810
1992 switch (UDF_I_ALLOCTYPE(inode)) { 1811 switch (UDF_I_ALLOCTYPE(inode)) {
1993 case ICBTAG_FLAG_AD_SHORT: 1812 case ICBTAG_FLAG_AD_SHORT:
1994 { 1813 if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc)))
1995 short_ad *sad; 1814 return -1;
1996 1815 etype = le32_to_cpu(sad->extLength) >> 30;
1997 if (! 1816 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1998 (sad = 1817 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1999 udf_get_fileshortad(ptr, alen, &epos->offset, 1818 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
2000 inc))) 1819 break;
2001 return -1;
2002
2003 etype = le32_to_cpu(sad->extLength) >> 30;
2004 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
2005 eloc->partitionReferenceNum =
2006 UDF_I_LOCATION(inode).partitionReferenceNum;
2007 *elen =
2008 le32_to_cpu(sad->
2009 extLength) & UDF_EXTENT_LENGTH_MASK;
2010 break;
2011 }
2012 case ICBTAG_FLAG_AD_LONG: 1820 case ICBTAG_FLAG_AD_LONG:
2013 { 1821 if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc)))
2014 long_ad *lad;
2015
2016 if (!
2017 (lad =
2018 udf_get_filelongad(ptr, alen, &epos->offset, inc)))
2019 return -1;
2020
2021 etype = le32_to_cpu(lad->extLength) >> 30;
2022 *eloc = lelb_to_cpu(lad->extLocation);
2023 *elen =
2024 le32_to_cpu(lad->
2025 extLength) & UDF_EXTENT_LENGTH_MASK;
2026 break;
2027 }
2028 default:
2029 {
2030 udf_debug("alloc_type = %d unsupported\n",
2031 UDF_I_ALLOCTYPE(inode));
2032 return -1; 1822 return -1;
2033 } 1823 etype = le32_to_cpu(lad->extLength) >> 30;
1824 *eloc = lelb_to_cpu(lad->extLocation);
1825 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1826 break;
1827 default:
1828 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
1829 return -1;
2034 } 1830 }
2035 1831
2036 return etype; 1832 return etype;
2037} 1833}
2038 1834
2039static int8_t 1835static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
2040udf_insert_aext(struct inode *inode, struct extent_position epos, 1836 kernel_lb_addr neloc, uint32_t nelen)
2041 kernel_lb_addr neloc, uint32_t nelen)
2042{ 1837{
2043 kernel_lb_addr oeloc; 1838 kernel_lb_addr oeloc;
2044 uint32_t oelen; 1839 uint32_t oelen;
@@ -2049,12 +1844,12 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
2049 1844
2050 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) { 1845 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
2051 udf_write_aext(inode, &epos, neloc, nelen, 1); 1846 udf_write_aext(inode, &epos, neloc, nelen, 1);
2052
2053 neloc = oeloc; 1847 neloc = oeloc;
2054 nelen = (etype << 30) | oelen; 1848 nelen = (etype << 30) | oelen;
2055 } 1849 }
2056 udf_add_aext(inode, &epos, neloc, nelen, 1); 1850 udf_add_aext(inode, &epos, neloc, nelen, 1);
2057 brelse(epos.bh); 1851 brelse(epos.bh);
1852
2058 return (nelen >> 30); 1853 return (nelen >> 30);
2059} 1854}
2060 1855
@@ -2105,15 +1900,12 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
2105 } else { 1900 } else {
2106 aed = (struct allocExtDesc *)oepos.bh->b_data; 1901 aed = (struct allocExtDesc *)oepos.bh->b_data;
2107 aed->lengthAllocDescs = 1902 aed->lengthAllocDescs =
2108 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - 1903 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2 * adsize));
2109 (2 * adsize)); 1904 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2110 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) 1905 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2111 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1906 udf_update_tag(oepos.bh->b_data, oepos.offset - (2 * adsize));
2112 udf_update_tag(oepos.bh->b_data,
2113 oepos.offset - (2 * adsize));
2114 else 1907 else
2115 udf_update_tag(oepos.bh->b_data, 1908 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
2116 sizeof(struct allocExtDesc));
2117 mark_buffer_dirty_inode(oepos.bh, inode); 1909 mark_buffer_dirty_inode(oepos.bh, inode);
2118 } 1910 }
2119 } else { 1911 } else {
@@ -2124,21 +1916,19 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
2124 } else { 1916 } else {
2125 aed = (struct allocExtDesc *)oepos.bh->b_data; 1917 aed = (struct allocExtDesc *)oepos.bh->b_data;
2126 aed->lengthAllocDescs = 1918 aed->lengthAllocDescs =
2127 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - 1919 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize);
2128 adsize); 1920 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2129 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) 1921 UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2130 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1922 udf_update_tag(oepos.bh->b_data, epos.offset - adsize);
2131 udf_update_tag(oepos.bh->b_data,
2132 epos.offset - adsize);
2133 else 1923 else
2134 udf_update_tag(oepos.bh->b_data, 1924 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
2135 sizeof(struct allocExtDesc));
2136 mark_buffer_dirty_inode(oepos.bh, inode); 1925 mark_buffer_dirty_inode(oepos.bh, inode);
2137 } 1926 }
2138 } 1927 }
2139 1928
2140 brelse(epos.bh); 1929 brelse(epos.bh);
2141 brelse(oepos.bh); 1930 brelse(oepos.bh);
1931
2142 return (elen >> 30); 1932 return (elen >> 30);
2143} 1933}
2144 1934
@@ -2162,8 +1952,7 @@ int8_t inode_bmap(struct inode * inode, sector_t block,
2162 1952
2163 do { 1953 do {
2164 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) { 1954 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
2165 *offset = 1955 *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2166 (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2167 UDF_I_LENEXTENTS(inode) = lbcount; 1956 UDF_I_LENEXTENTS(inode) = lbcount;
2168 return -1; 1957 return -1;
2169 } 1958 }
@@ -2180,13 +1969,12 @@ long udf_block_map(struct inode *inode, sector_t block)
2180 kernel_lb_addr eloc; 1969 kernel_lb_addr eloc;
2181 uint32_t elen; 1970 uint32_t elen;
2182 sector_t offset; 1971 sector_t offset;
2183 struct extent_position epos = { NULL, 0, {0, 0} }; 1972 struct extent_position epos = {};
2184 int ret; 1973 int ret;
2185 1974
2186 lock_kernel(); 1975 lock_kernel();
2187 1976
2188 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == 1977 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30))
2189 (EXT_RECORDED_ALLOCATED >> 30))
2190 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); 1978 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2191 else 1979 else
2192 ret = 0; 1980 ret = 0;