diff options
Diffstat (limited to 'fs/udf/inode.c')
-rw-r--r-- | fs/udf/inode.c | 581 |
1 files changed, 350 insertions, 231 deletions
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index ae21a0e59e95..c8461551e108 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
@@ -49,10 +49,10 @@ MODULE_LICENSE("GPL"); | |||
49 | static mode_t udf_convert_permissions(struct fileEntry *); | 49 | static mode_t udf_convert_permissions(struct fileEntry *); |
50 | static int udf_update_inode(struct inode *, int); | 50 | static int udf_update_inode(struct inode *, int); |
51 | static void udf_fill_inode(struct inode *, struct buffer_head *); | 51 | static void udf_fill_inode(struct inode *, struct buffer_head *); |
52 | static struct buffer_head *inode_getblk(struct inode *, long, int *, | 52 | static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, |
53 | long *, int *); | 53 | long *, int *); |
54 | static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int, | 54 | static int8_t udf_insert_aext(struct inode *, struct extent_position, |
55 | kernel_lb_addr, uint32_t, struct buffer_head *); | 55 | kernel_lb_addr, uint32_t); |
56 | static void udf_split_extents(struct inode *, int *, int, int, | 56 | static void udf_split_extents(struct inode *, int *, int, int, |
57 | kernel_long_ad [EXTENT_MERGE_SIZE], int *); | 57 | kernel_long_ad [EXTENT_MERGE_SIZE], int *); |
58 | static void udf_prealloc_extents(struct inode *, int, int, | 58 | static void udf_prealloc_extents(struct inode *, int, int, |
@@ -61,7 +61,7 @@ static void udf_merge_extents(struct inode *, | |||
61 | kernel_long_ad [EXTENT_MERGE_SIZE], int *); | 61 | kernel_long_ad [EXTENT_MERGE_SIZE], int *); |
62 | static void udf_update_extents(struct inode *, | 62 | static void udf_update_extents(struct inode *, |
63 | kernel_long_ad [EXTENT_MERGE_SIZE], int, int, | 63 | kernel_long_ad [EXTENT_MERGE_SIZE], int, int, |
64 | kernel_lb_addr, uint32_t, struct buffer_head **); | 64 | struct extent_position *); |
65 | static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); | 65 | static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); |
66 | 66 | ||
67 | /* | 67 | /* |
@@ -194,10 +194,11 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err) | |||
194 | struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err) | 194 | struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err) |
195 | { | 195 | { |
196 | int newblock; | 196 | int newblock; |
197 | struct buffer_head *sbh = NULL, *dbh = NULL; | 197 | struct buffer_head *dbh = NULL; |
198 | kernel_lb_addr bloc, eloc; | 198 | kernel_lb_addr eloc; |
199 | uint32_t elen, extoffset; | 199 | uint32_t elen; |
200 | uint8_t alloctype; | 200 | uint8_t alloctype; |
201 | struct extent_position epos; | ||
201 | 202 | ||
202 | struct udf_fileident_bh sfibh, dfibh; | 203 | struct udf_fileident_bh sfibh, dfibh; |
203 | loff_t f_pos = udf_ext0_offset(inode) >> 2; | 204 | loff_t f_pos = udf_ext0_offset(inode) >> 2; |
@@ -237,16 +238,16 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int | |||
237 | mark_buffer_dirty_inode(dbh, inode); | 238 | mark_buffer_dirty_inode(dbh, inode); |
238 | 239 | ||
239 | sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; | 240 | sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; |
240 | sbh = sfibh.sbh = sfibh.ebh = NULL; | 241 | sfibh.sbh = sfibh.ebh = NULL; |
241 | dfibh.soffset = dfibh.eoffset = 0; | 242 | dfibh.soffset = dfibh.eoffset = 0; |
242 | dfibh.sbh = dfibh.ebh = dbh; | 243 | dfibh.sbh = dfibh.ebh = dbh; |
243 | while ( (f_pos < size) ) | 244 | while ( (f_pos < size) ) |
244 | { | 245 | { |
245 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 246 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; |
246 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL, NULL, NULL); | 247 | sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); |
247 | if (!sfi) | 248 | if (!sfi) |
248 | { | 249 | { |
249 | udf_release_data(dbh); | 250 | brelse(dbh); |
250 | return NULL; | 251 | return NULL; |
251 | } | 252 | } |
252 | UDF_I_ALLOCTYPE(inode) = alloctype; | 253 | UDF_I_ALLOCTYPE(inode) = alloctype; |
@@ -258,7 +259,7 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int | |||
258 | sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) | 259 | sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) |
259 | { | 260 | { |
260 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; | 261 | UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; |
261 | udf_release_data(dbh); | 262 | brelse(dbh); |
262 | return NULL; | 263 | return NULL; |
263 | } | 264 | } |
264 | } | 265 | } |
@@ -266,16 +267,17 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int | |||
266 | 267 | ||
267 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); | 268 | memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); |
268 | UDF_I_LENALLOC(inode) = 0; | 269 | UDF_I_LENALLOC(inode) = 0; |
269 | bloc = UDF_I_LOCATION(inode); | ||
270 | eloc.logicalBlockNum = *block; | 270 | eloc.logicalBlockNum = *block; |
271 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; | 271 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; |
272 | elen = inode->i_size; | 272 | elen = inode->i_size; |
273 | UDF_I_LENEXTENTS(inode) = elen; | 273 | UDF_I_LENEXTENTS(inode) = elen; |
274 | extoffset = udf_file_entry_alloc_offset(inode); | 274 | epos.bh = NULL; |
275 | udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &sbh, 0); | 275 | epos.block = UDF_I_LOCATION(inode); |
276 | epos.offset = udf_file_entry_alloc_offset(inode); | ||
277 | udf_add_aext(inode, &epos, eloc, elen, 0); | ||
276 | /* UniqueID stuff */ | 278 | /* UniqueID stuff */ |
277 | 279 | ||
278 | udf_release_data(sbh); | 280 | brelse(epos.bh); |
279 | mark_inode_dirty(inode); | 281 | mark_inode_dirty(inode); |
280 | return dbh; | 282 | return dbh; |
281 | } | 283 | } |
@@ -354,53 +356,153 @@ udf_getblk(struct inode *inode, long block, int create, int *err) | |||
354 | return NULL; | 356 | return NULL; |
355 | } | 357 | } |
356 | 358 | ||
357 | static struct buffer_head * inode_getblk(struct inode * inode, long block, | 359 | /* Extend the file by 'blocks' blocks, return the number of extents added */ |
360 | int udf_extend_file(struct inode *inode, struct extent_position *last_pos, | ||
361 | kernel_long_ad *last_ext, sector_t blocks) | ||
362 | { | ||
363 | sector_t add; | ||
364 | int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | ||
365 | struct super_block *sb = inode->i_sb; | ||
366 | kernel_lb_addr prealloc_loc = {0, 0}; | ||
367 | int prealloc_len = 0; | ||
368 | |||
369 | /* The previous extent is fake and we should not extend by anything | ||
370 | * - there's nothing to do... */ | ||
371 | if (!blocks && fake) | ||
372 | return 0; | ||
373 | /* Round the last extent up to a multiple of block size */ | ||
374 | if (last_ext->extLength & (sb->s_blocksize - 1)) { | ||
375 | last_ext->extLength = | ||
376 | (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | | ||
377 | (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + | ||
378 | sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); | ||
379 | UDF_I_LENEXTENTS(inode) = | ||
380 | (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & | ||
381 | ~(sb->s_blocksize - 1); | ||
382 | } | ||
383 | /* Last extent are just preallocated blocks? */ | ||
384 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { | ||
385 | /* Save the extent so that we can reattach it to the end */ | ||
386 | prealloc_loc = last_ext->extLocation; | ||
387 | prealloc_len = last_ext->extLength; | ||
388 | /* Mark the extent as a hole */ | ||
389 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | ||
390 | (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); | ||
391 | last_ext->extLocation.logicalBlockNum = 0; | ||
392 | last_ext->extLocation.partitionReferenceNum = 0; | ||
393 | } | ||
394 | /* Can we merge with the previous extent? */ | ||
395 | if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { | ||
396 | add = ((1<<30) - sb->s_blocksize - (last_ext->extLength & | ||
397 | UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; | ||
398 | if (add > blocks) | ||
399 | add = blocks; | ||
400 | blocks -= add; | ||
401 | last_ext->extLength += add << sb->s_blocksize_bits; | ||
402 | } | ||
403 | |||
404 | if (fake) { | ||
405 | udf_add_aext(inode, last_pos, last_ext->extLocation, | ||
406 | last_ext->extLength, 1); | ||
407 | count++; | ||
408 | } | ||
409 | else | ||
410 | udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); | ||
411 | /* Managed to do everything necessary? */ | ||
412 | if (!blocks) | ||
413 | goto out; | ||
414 | |||
415 | /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ | ||
416 | last_ext->extLocation.logicalBlockNum = 0; | ||
417 | last_ext->extLocation.partitionReferenceNum = 0; | ||
418 | add = (1 << (30-sb->s_blocksize_bits)) - 1; | ||
419 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); | ||
420 | /* Create enough extents to cover the whole hole */ | ||
421 | while (blocks > add) { | ||
422 | blocks -= add; | ||
423 | if (udf_add_aext(inode, last_pos, last_ext->extLocation, | ||
424 | last_ext->extLength, 1) == -1) | ||
425 | return -1; | ||
426 | count++; | ||
427 | } | ||
428 | if (blocks) { | ||
429 | last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | ||
430 | (blocks << sb->s_blocksize_bits); | ||
431 | if (udf_add_aext(inode, last_pos, last_ext->extLocation, | ||
432 | last_ext->extLength, 1) == -1) | ||
433 | return -1; | ||
434 | count++; | ||
435 | } | ||
436 | out: | ||
437 | /* Do we have some preallocated blocks saved? */ | ||
438 | if (prealloc_len) { | ||
439 | if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1) | ||
440 | return -1; | ||
441 | last_ext->extLocation = prealloc_loc; | ||
442 | last_ext->extLength = prealloc_len; | ||
443 | count++; | ||
444 | } | ||
445 | /* last_pos should point to the last written extent... */ | ||
446 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | ||
447 | last_pos->offset -= sizeof(short_ad); | ||
448 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) | ||
449 | last_pos->offset -= sizeof(long_ad); | ||
450 | else | ||
451 | return -1; | ||
452 | return count; | ||
453 | } | ||
454 | |||
455 | static struct buffer_head * inode_getblk(struct inode * inode, sector_t block, | ||
358 | int *err, long *phys, int *new) | 456 | int *err, long *phys, int *new) |
359 | { | 457 | { |
360 | struct buffer_head *pbh = NULL, *cbh = NULL, *nbh = NULL, *result = NULL; | 458 | static sector_t last_block; |
459 | struct buffer_head *result = NULL; | ||
361 | kernel_long_ad laarr[EXTENT_MERGE_SIZE]; | 460 | kernel_long_ad laarr[EXTENT_MERGE_SIZE]; |
362 | uint32_t pextoffset = 0, cextoffset = 0, nextoffset = 0; | 461 | struct extent_position prev_epos, cur_epos, next_epos; |
363 | int count = 0, startnum = 0, endnum = 0; | 462 | int count = 0, startnum = 0, endnum = 0; |
364 | uint32_t elen = 0; | 463 | uint32_t elen = 0; |
365 | kernel_lb_addr eloc, pbloc, cbloc, nbloc; | 464 | kernel_lb_addr eloc; |
366 | int c = 1; | 465 | int c = 1; |
367 | uint64_t lbcount = 0, b_off = 0; | 466 | loff_t lbcount = 0, b_off = 0; |
368 | uint32_t newblocknum, newblock, offset = 0; | 467 | uint32_t newblocknum, newblock; |
468 | sector_t offset = 0; | ||
369 | int8_t etype; | 469 | int8_t etype; |
370 | int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum; | 470 | int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum; |
371 | char lastblock = 0; | 471 | int lastblock = 0; |
372 | 472 | ||
373 | pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode); | 473 | prev_epos.offset = udf_file_entry_alloc_offset(inode); |
374 | b_off = (uint64_t)block << inode->i_sb->s_blocksize_bits; | 474 | prev_epos.block = UDF_I_LOCATION(inode); |
375 | pbloc = cbloc = nbloc = UDF_I_LOCATION(inode); | 475 | prev_epos.bh = NULL; |
476 | cur_epos = next_epos = prev_epos; | ||
477 | b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; | ||
376 | 478 | ||
377 | /* find the extent which contains the block we are looking for. | 479 | /* find the extent which contains the block we are looking for. |
378 | alternate between laarr[0] and laarr[1] for locations of the | 480 | alternate between laarr[0] and laarr[1] for locations of the |
379 | current extent, and the previous extent */ | 481 | current extent, and the previous extent */ |
380 | do | 482 | do |
381 | { | 483 | { |
382 | if (pbh != cbh) | 484 | if (prev_epos.bh != cur_epos.bh) |
383 | { | 485 | { |
384 | udf_release_data(pbh); | 486 | brelse(prev_epos.bh); |
385 | atomic_inc(&cbh->b_count); | 487 | get_bh(cur_epos.bh); |
386 | pbh = cbh; | 488 | prev_epos.bh = cur_epos.bh; |
387 | } | 489 | } |
388 | if (cbh != nbh) | 490 | if (cur_epos.bh != next_epos.bh) |
389 | { | 491 | { |
390 | udf_release_data(cbh); | 492 | brelse(cur_epos.bh); |
391 | atomic_inc(&nbh->b_count); | 493 | get_bh(next_epos.bh); |
392 | cbh = nbh; | 494 | cur_epos.bh = next_epos.bh; |
393 | } | 495 | } |
394 | 496 | ||
395 | lbcount += elen; | 497 | lbcount += elen; |
396 | 498 | ||
397 | pbloc = cbloc; | 499 | prev_epos.block = cur_epos.block; |
398 | cbloc = nbloc; | 500 | cur_epos.block = next_epos.block; |
399 | 501 | ||
400 | pextoffset = cextoffset; | 502 | prev_epos.offset = cur_epos.offset; |
401 | cextoffset = nextoffset; | 503 | cur_epos.offset = next_epos.offset; |
402 | 504 | ||
403 | if ((etype = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) == -1) | 505 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1) |
404 | break; | 506 | break; |
405 | 507 | ||
406 | c = !c; | 508 | c = !c; |
@@ -418,6 +520,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, | |||
418 | 520 | ||
419 | b_off -= lbcount; | 521 | b_off -= lbcount; |
420 | offset = b_off >> inode->i_sb->s_blocksize_bits; | 522 | offset = b_off >> inode->i_sb->s_blocksize_bits; |
523 | /* Move into indirect extent if we are at a pointer to it */ | ||
524 | udf_next_aext(inode, &prev_epos, &eloc, &elen, 0); | ||
421 | 525 | ||
422 | /* if the extent is allocated and recorded, return the block | 526 | /* if the extent is allocated and recorded, return the block |
423 | if the extent is not a multiple of the blocksize, round up */ | 527 | if the extent is not a multiple of the blocksize, round up */ |
@@ -429,54 +533,77 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, | |||
429 | elen = EXT_RECORDED_ALLOCATED | | 533 | elen = EXT_RECORDED_ALLOCATED | |
430 | ((elen + inode->i_sb->s_blocksize - 1) & | 534 | ((elen + inode->i_sb->s_blocksize - 1) & |
431 | ~(inode->i_sb->s_blocksize - 1)); | 535 | ~(inode->i_sb->s_blocksize - 1)); |
432 | etype = udf_write_aext(inode, nbloc, &cextoffset, eloc, elen, nbh, 1); | 536 | etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1); |
433 | } | 537 | } |
434 | udf_release_data(pbh); | 538 | brelse(prev_epos.bh); |
435 | udf_release_data(cbh); | 539 | brelse(cur_epos.bh); |
436 | udf_release_data(nbh); | 540 | brelse(next_epos.bh); |
437 | newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset); | 541 | newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset); |
438 | *phys = newblock; | 542 | *phys = newblock; |
439 | return NULL; | 543 | return NULL; |
440 | } | 544 | } |
441 | 545 | ||
546 | last_block = block; | ||
547 | /* Are we beyond EOF? */ | ||
442 | if (etype == -1) | 548 | if (etype == -1) |
443 | { | 549 | { |
444 | endnum = startnum = ((count > 1) ? 1 : count); | 550 | int ret; |
445 | if (laarr[c].extLength & (inode->i_sb->s_blocksize - 1)) | 551 | |
446 | { | 552 | if (count) { |
447 | laarr[c].extLength = | 553 | if (c) |
448 | (laarr[c].extLength & UDF_EXTENT_FLAG_MASK) | | 554 | laarr[0] = laarr[1]; |
449 | (((laarr[c].extLength & UDF_EXTENT_LENGTH_MASK) + | 555 | startnum = 1; |
450 | inode->i_sb->s_blocksize - 1) & | 556 | } |
451 | ~(inode->i_sb->s_blocksize - 1)); | 557 | else { |
452 | UDF_I_LENEXTENTS(inode) = | 558 | /* Create a fake extent when there's not one */ |
453 | (UDF_I_LENEXTENTS(inode) + inode->i_sb->s_blocksize - 1) & | 559 | memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); |
454 | ~(inode->i_sb->s_blocksize - 1); | 560 | laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; |
561 | /* Will udf_extend_file() create real extent from a fake one? */ | ||
562 | startnum = (offset > 0); | ||
563 | } | ||
564 | /* Create extents for the hole between EOF and offset */ | ||
565 | ret = udf_extend_file(inode, &prev_epos, laarr, offset); | ||
566 | if (ret == -1) { | ||
567 | brelse(prev_epos.bh); | ||
568 | brelse(cur_epos.bh); | ||
569 | brelse(next_epos.bh); | ||
570 | /* We don't really know the error here so we just make | ||
571 | * something up */ | ||
572 | *err = -ENOSPC; | ||
573 | return NULL; | ||
455 | } | 574 | } |
456 | c = !c; | 575 | c = 0; |
457 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | 576 | offset = 0; |
458 | ((offset + 1) << inode->i_sb->s_blocksize_bits); | 577 | count += ret; |
459 | memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); | 578 | /* We are not covered by a preallocated extent? */ |
460 | count ++; | 579 | if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) { |
461 | endnum ++; | 580 | /* Is there any real extent? - otherwise we overwrite |
581 | * the fake one... */ | ||
582 | if (count) | ||
583 | c = !c; | ||
584 | laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | | ||
585 | inode->i_sb->s_blocksize; | ||
586 | memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); | ||
587 | count ++; | ||
588 | endnum ++; | ||
589 | } | ||
590 | endnum = c+1; | ||
462 | lastblock = 1; | 591 | lastblock = 1; |
463 | } | 592 | } |
464 | else | 593 | else { |
465 | endnum = startnum = ((count > 2) ? 2 : count); | 594 | endnum = startnum = ((count > 2) ? 2 : count); |
466 | 595 | ||
467 | /* if the current extent is in position 0, swap it with the previous */ | 596 | /* if the current extent is in position 0, swap it with the previous */ |
468 | if (!c && count != 1) | 597 | if (!c && count != 1) |
469 | { | 598 | { |
470 | laarr[2] = laarr[0]; | 599 | laarr[2] = laarr[0]; |
471 | laarr[0] = laarr[1]; | 600 | laarr[0] = laarr[1]; |
472 | laarr[1] = laarr[2]; | 601 | laarr[1] = laarr[2]; |
473 | c = 1; | 602 | c = 1; |
474 | } | 603 | } |
475 | 604 | ||
476 | /* if the current block is located in a extent, read the next extent */ | 605 | /* if the current block is located in an extent, read the next extent */ |
477 | if (etype != -1) | 606 | if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) |
478 | { | ||
479 | if ((etype = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 0)) != -1) | ||
480 | { | 607 | { |
481 | laarr[c+1].extLength = (etype << 30) | elen; | 608 | laarr[c+1].extLength = (etype << 30) | elen; |
482 | laarr[c+1].extLocation = eloc; | 609 | laarr[c+1].extLocation = eloc; |
@@ -484,11 +611,10 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, | |||
484 | startnum ++; | 611 | startnum ++; |
485 | endnum ++; | 612 | endnum ++; |
486 | } | 613 | } |
487 | else | 614 | else { |
488 | lastblock = 1; | 615 | lastblock = 1; |
616 | } | ||
489 | } | 617 | } |
490 | udf_release_data(cbh); | ||
491 | udf_release_data(nbh); | ||
492 | 618 | ||
493 | /* if the current extent is not recorded but allocated, get the | 619 | /* if the current extent is not recorded but allocated, get the |
494 | block in the extent corresponding to the requested block */ | 620 | block in the extent corresponding to the requested block */ |
@@ -508,7 +634,7 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, | |||
508 | if (!(newblocknum = udf_new_block(inode->i_sb, inode, | 634 | if (!(newblocknum = udf_new_block(inode->i_sb, inode, |
509 | UDF_I_LOCATION(inode).partitionReferenceNum, goal, err))) | 635 | UDF_I_LOCATION(inode).partitionReferenceNum, goal, err))) |
510 | { | 636 | { |
511 | udf_release_data(pbh); | 637 | brelse(prev_epos.bh); |
512 | *err = -ENOSPC; | 638 | *err = -ENOSPC; |
513 | return NULL; | 639 | return NULL; |
514 | } | 640 | } |
@@ -529,11 +655,11 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, | |||
529 | udf_merge_extents(inode, laarr, &endnum); | 655 | udf_merge_extents(inode, laarr, &endnum); |
530 | 656 | ||
531 | /* write back the new extents, inserting new extents if the new number | 657 | /* write back the new extents, inserting new extents if the new number |
532 | of extents is greater than the old number, and deleting extents if | 658 | of extents is greater than the old number, and deleting extents if |
533 | the new number of extents is less than the old number */ | 659 | the new number of extents is less than the old number */ |
534 | udf_update_extents(inode, laarr, startnum, endnum, pbloc, pextoffset, &pbh); | 660 | udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); |
535 | 661 | ||
536 | udf_release_data(pbh); | 662 | brelse(prev_epos.bh); |
537 | 663 | ||
538 | if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, | 664 | if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, |
539 | UDF_I_LOCATION(inode).partitionReferenceNum, 0))) | 665 | UDF_I_LOCATION(inode).partitionReferenceNum, 0))) |
@@ -795,7 +921,7 @@ static void udf_merge_extents(struct inode *inode, | |||
795 | 921 | ||
796 | static void udf_update_extents(struct inode *inode, | 922 | static void udf_update_extents(struct inode *inode, |
797 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum, | 923 | kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum, |
798 | kernel_lb_addr pbloc, uint32_t pextoffset, struct buffer_head **pbh) | 924 | struct extent_position *epos) |
799 | { | 925 | { |
800 | int start = 0, i; | 926 | int start = 0, i; |
801 | kernel_lb_addr tmploc; | 927 | kernel_lb_addr tmploc; |
@@ -804,28 +930,26 @@ static void udf_update_extents(struct inode *inode, | |||
804 | if (startnum > endnum) | 930 | if (startnum > endnum) |
805 | { | 931 | { |
806 | for (i=0; i<(startnum-endnum); i++) | 932 | for (i=0; i<(startnum-endnum); i++) |
807 | { | 933 | udf_delete_aext(inode, *epos, laarr[i].extLocation, |
808 | udf_delete_aext(inode, pbloc, pextoffset, laarr[i].extLocation, | 934 | laarr[i].extLength); |
809 | laarr[i].extLength, *pbh); | ||
810 | } | ||
811 | } | 935 | } |
812 | else if (startnum < endnum) | 936 | else if (startnum < endnum) |
813 | { | 937 | { |
814 | for (i=0; i<(endnum-startnum); i++) | 938 | for (i=0; i<(endnum-startnum); i++) |
815 | { | 939 | { |
816 | udf_insert_aext(inode, pbloc, pextoffset, laarr[i].extLocation, | 940 | udf_insert_aext(inode, *epos, laarr[i].extLocation, |
817 | laarr[i].extLength, *pbh); | 941 | laarr[i].extLength); |
818 | udf_next_aext(inode, &pbloc, &pextoffset, &laarr[i].extLocation, | 942 | udf_next_aext(inode, epos, &laarr[i].extLocation, |
819 | &laarr[i].extLength, pbh, 1); | 943 | &laarr[i].extLength, 1); |
820 | start ++; | 944 | start ++; |
821 | } | 945 | } |
822 | } | 946 | } |
823 | 947 | ||
824 | for (i=start; i<endnum; i++) | 948 | for (i=start; i<endnum; i++) |
825 | { | 949 | { |
826 | udf_next_aext(inode, &pbloc, &pextoffset, &tmploc, &tmplen, pbh, 0); | 950 | udf_next_aext(inode, epos, &tmploc, &tmplen, 0); |
827 | udf_write_aext(inode, pbloc, &pextoffset, laarr[i].extLocation, | 951 | udf_write_aext(inode, epos, laarr[i].extLocation, |
828 | laarr[i].extLength, *pbh, 1); | 952 | laarr[i].extLength, 1); |
829 | } | 953 | } |
830 | } | 954 | } |
831 | 955 | ||
@@ -931,7 +1055,7 @@ __udf_read_inode(struct inode *inode) | |||
931 | { | 1055 | { |
932 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", | 1056 | printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", |
933 | inode->i_ino, ident); | 1057 | inode->i_ino, ident); |
934 | udf_release_data(bh); | 1058 | brelse(bh); |
935 | make_bad_inode(inode); | 1059 | make_bad_inode(inode); |
936 | return; | 1060 | return; |
937 | } | 1061 | } |
@@ -960,35 +1084,36 @@ __udf_read_inode(struct inode *inode) | |||
960 | ident == TAG_IDENT_EFE) | 1084 | ident == TAG_IDENT_EFE) |
961 | { | 1085 | { |
962 | memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr)); | 1086 | memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr)); |
963 | udf_release_data(bh); | 1087 | brelse(bh); |
964 | udf_release_data(ibh); | 1088 | brelse(ibh); |
965 | udf_release_data(nbh); | 1089 | brelse(nbh); |
966 | __udf_read_inode(inode); | 1090 | __udf_read_inode(inode); |
967 | return; | 1091 | return; |
968 | } | 1092 | } |
969 | else | 1093 | else |
970 | { | 1094 | { |
971 | udf_release_data(nbh); | 1095 | brelse(nbh); |
972 | udf_release_data(ibh); | 1096 | brelse(ibh); |
973 | } | 1097 | } |
974 | } | 1098 | } |
975 | else | 1099 | else |
976 | udf_release_data(ibh); | 1100 | brelse(ibh); |
977 | } | 1101 | } |
978 | } | 1102 | } |
979 | else | 1103 | else |
980 | udf_release_data(ibh); | 1104 | brelse(ibh); |
981 | } | 1105 | } |
982 | else if (le16_to_cpu(fe->icbTag.strategyType) != 4) | 1106 | else if (le16_to_cpu(fe->icbTag.strategyType) != 4) |
983 | { | 1107 | { |
984 | printk(KERN_ERR "udf: unsupported strategy type: %d\n", | 1108 | printk(KERN_ERR "udf: unsupported strategy type: %d\n", |
985 | le16_to_cpu(fe->icbTag.strategyType)); | 1109 | le16_to_cpu(fe->icbTag.strategyType)); |
986 | udf_release_data(bh); | 1110 | brelse(bh); |
987 | make_bad_inode(inode); | 1111 | make_bad_inode(inode); |
988 | return; | 1112 | return; |
989 | } | 1113 | } |
990 | udf_fill_inode(inode, bh); | 1114 | udf_fill_inode(inode, bh); |
991 | udf_release_data(bh); | 1115 | |
1116 | brelse(bh); | ||
992 | } | 1117 | } |
993 | 1118 | ||
994 | static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | 1119 | static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) |
@@ -1331,7 +1456,7 @@ udf_update_inode(struct inode *inode, int do_sync) | |||
1331 | use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; | 1456 | use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; |
1332 | 1457 | ||
1333 | mark_buffer_dirty(bh); | 1458 | mark_buffer_dirty(bh); |
1334 | udf_release_data(bh); | 1459 | brelse(bh); |
1335 | return err; | 1460 | return err; |
1336 | } | 1461 | } |
1337 | 1462 | ||
@@ -1520,7 +1645,7 @@ udf_update_inode(struct inode *inode, int do_sync) | |||
1520 | err = -EIO; | 1645 | err = -EIO; |
1521 | } | 1646 | } |
1522 | } | 1647 | } |
1523 | udf_release_data(bh); | 1648 | brelse(bh); |
1524 | return err; | 1649 | return err; |
1525 | } | 1650 | } |
1526 | 1651 | ||
@@ -1556,8 +1681,8 @@ udf_iget(struct super_block *sb, kernel_lb_addr ino) | |||
1556 | return NULL; | 1681 | return NULL; |
1557 | } | 1682 | } |
1558 | 1683 | ||
1559 | int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | 1684 | int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, |
1560 | kernel_lb_addr eloc, uint32_t elen, struct buffer_head **bh, int inc) | 1685 | kernel_lb_addr eloc, uint32_t elen, int inc) |
1561 | { | 1686 | { |
1562 | int adsize; | 1687 | int adsize; |
1563 | short_ad *sad = NULL; | 1688 | short_ad *sad = NULL; |
@@ -1566,10 +1691,10 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1566 | int8_t etype; | 1691 | int8_t etype; |
1567 | uint8_t *ptr; | 1692 | uint8_t *ptr; |
1568 | 1693 | ||
1569 | if (!*bh) | 1694 | if (!epos->bh) |
1570 | ptr = UDF_I_DATA(inode) + *extoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1695 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); |
1571 | else | 1696 | else |
1572 | ptr = (*bh)->b_data + *extoffset; | 1697 | ptr = epos->bh->b_data + epos->offset; |
1573 | 1698 | ||
1574 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 1699 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) |
1575 | adsize = sizeof(short_ad); | 1700 | adsize = sizeof(short_ad); |
@@ -1578,20 +1703,20 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1578 | else | 1703 | else |
1579 | return -1; | 1704 | return -1; |
1580 | 1705 | ||
1581 | if (*extoffset + (2 * adsize) > inode->i_sb->s_blocksize) | 1706 | if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) |
1582 | { | 1707 | { |
1583 | char *sptr, *dptr; | 1708 | char *sptr, *dptr; |
1584 | struct buffer_head *nbh; | 1709 | struct buffer_head *nbh; |
1585 | int err, loffset; | 1710 | int err, loffset; |
1586 | kernel_lb_addr obloc = *bloc; | 1711 | kernel_lb_addr obloc = epos->block; |
1587 | 1712 | ||
1588 | if (!(bloc->logicalBlockNum = udf_new_block(inode->i_sb, NULL, | 1713 | if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, |
1589 | obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) | 1714 | obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) |
1590 | { | 1715 | { |
1591 | return -1; | 1716 | return -1; |
1592 | } | 1717 | } |
1593 | if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, | 1718 | if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, |
1594 | *bloc, 0)))) | 1719 | epos->block, 0)))) |
1595 | { | 1720 | { |
1596 | return -1; | 1721 | return -1; |
1597 | } | 1722 | } |
@@ -1604,25 +1729,25 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1604 | aed = (struct allocExtDesc *)(nbh->b_data); | 1729 | aed = (struct allocExtDesc *)(nbh->b_data); |
1605 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) | 1730 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
1606 | aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); | 1731 | aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); |
1607 | if (*extoffset + adsize > inode->i_sb->s_blocksize) | 1732 | if (epos->offset + adsize > inode->i_sb->s_blocksize) |
1608 | { | 1733 | { |
1609 | loffset = *extoffset; | 1734 | loffset = epos->offset; |
1610 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 1735 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
1611 | sptr = ptr - adsize; | 1736 | sptr = ptr - adsize; |
1612 | dptr = nbh->b_data + sizeof(struct allocExtDesc); | 1737 | dptr = nbh->b_data + sizeof(struct allocExtDesc); |
1613 | memcpy(dptr, sptr, adsize); | 1738 | memcpy(dptr, sptr, adsize); |
1614 | *extoffset = sizeof(struct allocExtDesc) + adsize; | 1739 | epos->offset = sizeof(struct allocExtDesc) + adsize; |
1615 | } | 1740 | } |
1616 | else | 1741 | else |
1617 | { | 1742 | { |
1618 | loffset = *extoffset + adsize; | 1743 | loffset = epos->offset + adsize; |
1619 | aed->lengthAllocDescs = cpu_to_le32(0); | 1744 | aed->lengthAllocDescs = cpu_to_le32(0); |
1620 | sptr = ptr; | 1745 | sptr = ptr; |
1621 | *extoffset = sizeof(struct allocExtDesc); | 1746 | epos->offset = sizeof(struct allocExtDesc); |
1622 | 1747 | ||
1623 | if (*bh) | 1748 | if (epos->bh) |
1624 | { | 1749 | { |
1625 | aed = (struct allocExtDesc *)(*bh)->b_data; | 1750 | aed = (struct allocExtDesc *)epos->bh->b_data; |
1626 | aed->lengthAllocDescs = | 1751 | aed->lengthAllocDescs = |
1627 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1752 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); |
1628 | } | 1753 | } |
@@ -1634,10 +1759,10 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1634 | } | 1759 | } |
1635 | if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) | 1760 | if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) |
1636 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, | 1761 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, |
1637 | bloc->logicalBlockNum, sizeof(tag)); | 1762 | epos->block.logicalBlockNum, sizeof(tag)); |
1638 | else | 1763 | else |
1639 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, | 1764 | udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, |
1640 | bloc->logicalBlockNum, sizeof(tag)); | 1765 | epos->block.logicalBlockNum, sizeof(tag)); |
1641 | switch (UDF_I_ALLOCTYPE(inode)) | 1766 | switch (UDF_I_ALLOCTYPE(inode)) |
1642 | { | 1767 | { |
1643 | case ICBTAG_FLAG_AD_SHORT: | 1768 | case ICBTAG_FLAG_AD_SHORT: |
@@ -1646,7 +1771,7 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1646 | sad->extLength = cpu_to_le32( | 1771 | sad->extLength = cpu_to_le32( |
1647 | EXT_NEXT_EXTENT_ALLOCDECS | | 1772 | EXT_NEXT_EXTENT_ALLOCDECS | |
1648 | inode->i_sb->s_blocksize); | 1773 | inode->i_sb->s_blocksize); |
1649 | sad->extPosition = cpu_to_le32(bloc->logicalBlockNum); | 1774 | sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); |
1650 | break; | 1775 | break; |
1651 | } | 1776 | } |
1652 | case ICBTAG_FLAG_AD_LONG: | 1777 | case ICBTAG_FLAG_AD_LONG: |
@@ -1655,60 +1780,57 @@ int8_t udf_add_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1655 | lad->extLength = cpu_to_le32( | 1780 | lad->extLength = cpu_to_le32( |
1656 | EXT_NEXT_EXTENT_ALLOCDECS | | 1781 | EXT_NEXT_EXTENT_ALLOCDECS | |
1657 | inode->i_sb->s_blocksize); | 1782 | inode->i_sb->s_blocksize); |
1658 | lad->extLocation = cpu_to_lelb(*bloc); | 1783 | lad->extLocation = cpu_to_lelb(epos->block); |
1659 | memset(lad->impUse, 0x00, sizeof(lad->impUse)); | 1784 | memset(lad->impUse, 0x00, sizeof(lad->impUse)); |
1660 | break; | 1785 | break; |
1661 | } | 1786 | } |
1662 | } | 1787 | } |
1663 | if (*bh) | 1788 | if (epos->bh) |
1664 | { | 1789 | { |
1665 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 1790 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
1666 | udf_update_tag((*bh)->b_data, loffset); | 1791 | udf_update_tag(epos->bh->b_data, loffset); |
1667 | else | 1792 | else |
1668 | udf_update_tag((*bh)->b_data, sizeof(struct allocExtDesc)); | 1793 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); |
1669 | mark_buffer_dirty_inode(*bh, inode); | 1794 | mark_buffer_dirty_inode(epos->bh, inode); |
1670 | udf_release_data(*bh); | 1795 | brelse(epos->bh); |
1671 | } | 1796 | } |
1672 | else | 1797 | else |
1673 | mark_inode_dirty(inode); | 1798 | mark_inode_dirty(inode); |
1674 | *bh = nbh; | 1799 | epos->bh = nbh; |
1675 | } | 1800 | } |
1676 | 1801 | ||
1677 | etype = udf_write_aext(inode, *bloc, extoffset, eloc, elen, *bh, inc); | 1802 | etype = udf_write_aext(inode, epos, eloc, elen, inc); |
1678 | 1803 | ||
1679 | if (!*bh) | 1804 | if (!epos->bh) |
1680 | { | 1805 | { |
1681 | UDF_I_LENALLOC(inode) += adsize; | 1806 | UDF_I_LENALLOC(inode) += adsize; |
1682 | mark_inode_dirty(inode); | 1807 | mark_inode_dirty(inode); |
1683 | } | 1808 | } |
1684 | else | 1809 | else |
1685 | { | 1810 | { |
1686 | aed = (struct allocExtDesc *)(*bh)->b_data; | 1811 | aed = (struct allocExtDesc *)epos->bh->b_data; |
1687 | aed->lengthAllocDescs = | 1812 | aed->lengthAllocDescs = |
1688 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 1813 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); |
1689 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 1814 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
1690 | udf_update_tag((*bh)->b_data, *extoffset + (inc ? 0 : adsize)); | 1815 | udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize)); |
1691 | else | 1816 | else |
1692 | udf_update_tag((*bh)->b_data, sizeof(struct allocExtDesc)); | 1817 | udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); |
1693 | mark_buffer_dirty_inode(*bh, inode); | 1818 | mark_buffer_dirty_inode(epos->bh, inode); |
1694 | } | 1819 | } |
1695 | 1820 | ||
1696 | return etype; | 1821 | return etype; |
1697 | } | 1822 | } |
1698 | 1823 | ||
1699 | int8_t udf_write_aext(struct inode *inode, kernel_lb_addr bloc, int *extoffset, | 1824 | int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, |
1700 | kernel_lb_addr eloc, uint32_t elen, struct buffer_head *bh, int inc) | 1825 | kernel_lb_addr eloc, uint32_t elen, int inc) |
1701 | { | 1826 | { |
1702 | int adsize; | 1827 | int adsize; |
1703 | uint8_t *ptr; | 1828 | uint8_t *ptr; |
1704 | 1829 | ||
1705 | if (!bh) | 1830 | if (!epos->bh) |
1706 | ptr = UDF_I_DATA(inode) + *extoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1831 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); |
1707 | else | 1832 | else |
1708 | { | 1833 | ptr = epos->bh->b_data + epos->offset; |
1709 | ptr = bh->b_data + *extoffset; | ||
1710 | atomic_inc(&bh->b_count); | ||
1711 | } | ||
1712 | 1834 | ||
1713 | switch (UDF_I_ALLOCTYPE(inode)) | 1835 | switch (UDF_I_ALLOCTYPE(inode)) |
1714 | { | 1836 | { |
@@ -1733,40 +1855,39 @@ int8_t udf_write_aext(struct inode *inode, kernel_lb_addr bloc, int *extoffset, | |||
1733 | return -1; | 1855 | return -1; |
1734 | } | 1856 | } |
1735 | 1857 | ||
1736 | if (bh) | 1858 | if (epos->bh) |
1737 | { | 1859 | { |
1738 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 1860 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
1739 | { | 1861 | { |
1740 | struct allocExtDesc *aed = (struct allocExtDesc *)(bh)->b_data; | 1862 | struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; |
1741 | udf_update_tag((bh)->b_data, | 1863 | udf_update_tag(epos->bh->b_data, |
1742 | le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); | 1864 | le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); |
1743 | } | 1865 | } |
1744 | mark_buffer_dirty_inode(bh, inode); | 1866 | mark_buffer_dirty_inode(epos->bh, inode); |
1745 | udf_release_data(bh); | ||
1746 | } | 1867 | } |
1747 | else | 1868 | else |
1748 | mark_inode_dirty(inode); | 1869 | mark_inode_dirty(inode); |
1749 | 1870 | ||
1750 | if (inc) | 1871 | if (inc) |
1751 | *extoffset += adsize; | 1872 | epos->offset += adsize; |
1752 | return (elen >> 30); | 1873 | return (elen >> 30); |
1753 | } | 1874 | } |
1754 | 1875 | ||
1755 | int8_t udf_next_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | 1876 | int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, |
1756 | kernel_lb_addr *eloc, uint32_t *elen, struct buffer_head **bh, int inc) | 1877 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
1757 | { | 1878 | { |
1758 | int8_t etype; | 1879 | int8_t etype; |
1759 | 1880 | ||
1760 | while ((etype = udf_current_aext(inode, bloc, extoffset, eloc, elen, bh, inc)) == | 1881 | while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == |
1761 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) | 1882 | (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) |
1762 | { | 1883 | { |
1763 | *bloc = *eloc; | 1884 | epos->block = *eloc; |
1764 | *extoffset = sizeof(struct allocExtDesc); | 1885 | epos->offset = sizeof(struct allocExtDesc); |
1765 | udf_release_data(*bh); | 1886 | brelse(epos->bh); |
1766 | if (!(*bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, *bloc, 0)))) | 1887 | if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) |
1767 | { | 1888 | { |
1768 | udf_debug("reading block %d failed!\n", | 1889 | udf_debug("reading block %d failed!\n", |
1769 | udf_get_lb_pblock(inode->i_sb, *bloc, 0)); | 1890 | udf_get_lb_pblock(inode->i_sb, epos->block, 0)); |
1770 | return -1; | 1891 | return -1; |
1771 | } | 1892 | } |
1772 | } | 1893 | } |
@@ -1774,26 +1895,26 @@ int8_t udf_next_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | |||
1774 | return etype; | 1895 | return etype; |
1775 | } | 1896 | } |
1776 | 1897 | ||
1777 | int8_t udf_current_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffset, | 1898 | int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, |
1778 | kernel_lb_addr *eloc, uint32_t *elen, struct buffer_head **bh, int inc) | 1899 | kernel_lb_addr *eloc, uint32_t *elen, int inc) |
1779 | { | 1900 | { |
1780 | int alen; | 1901 | int alen; |
1781 | int8_t etype; | 1902 | int8_t etype; |
1782 | uint8_t *ptr; | 1903 | uint8_t *ptr; |
1783 | 1904 | ||
1784 | if (!*bh) | 1905 | if (!epos->bh) |
1785 | { | 1906 | { |
1786 | if (!(*extoffset)) | 1907 | if (!epos->offset) |
1787 | *extoffset = udf_file_entry_alloc_offset(inode); | 1908 | epos->offset = udf_file_entry_alloc_offset(inode); |
1788 | ptr = UDF_I_DATA(inode) + *extoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); | 1909 | ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); |
1789 | alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); | 1910 | alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); |
1790 | } | 1911 | } |
1791 | else | 1912 | else |
1792 | { | 1913 | { |
1793 | if (!(*extoffset)) | 1914 | if (!epos->offset) |
1794 | *extoffset = sizeof(struct allocExtDesc); | 1915 | epos->offset = sizeof(struct allocExtDesc); |
1795 | ptr = (*bh)->b_data + *extoffset; | 1916 | ptr = epos->bh->b_data + epos->offset; |
1796 | alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)(*bh)->b_data)->lengthAllocDescs); | 1917 | alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); |
1797 | } | 1918 | } |
1798 | 1919 | ||
1799 | switch (UDF_I_ALLOCTYPE(inode)) | 1920 | switch (UDF_I_ALLOCTYPE(inode)) |
@@ -1802,7 +1923,7 @@ int8_t udf_current_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffse | |||
1802 | { | 1923 | { |
1803 | short_ad *sad; | 1924 | short_ad *sad; |
1804 | 1925 | ||
1805 | if (!(sad = udf_get_fileshortad(ptr, alen, extoffset, inc))) | 1926 | if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc))) |
1806 | return -1; | 1927 | return -1; |
1807 | 1928 | ||
1808 | etype = le32_to_cpu(sad->extLength) >> 30; | 1929 | etype = le32_to_cpu(sad->extLength) >> 30; |
@@ -1815,7 +1936,7 @@ int8_t udf_current_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffse | |||
1815 | { | 1936 | { |
1816 | long_ad *lad; | 1937 | long_ad *lad; |
1817 | 1938 | ||
1818 | if (!(lad = udf_get_filelongad(ptr, alen, extoffset, inc))) | 1939 | if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc))) |
1819 | return -1; | 1940 | return -1; |
1820 | 1941 | ||
1821 | etype = le32_to_cpu(lad->extLength) >> 30; | 1942 | etype = le32_to_cpu(lad->extLength) >> 30; |
@@ -1834,41 +1955,40 @@ int8_t udf_current_aext(struct inode *inode, kernel_lb_addr *bloc, int *extoffse | |||
1834 | } | 1955 | } |
1835 | 1956 | ||
1836 | static int8_t | 1957 | static int8_t |
1837 | udf_insert_aext(struct inode *inode, kernel_lb_addr bloc, int extoffset, | 1958 | udf_insert_aext(struct inode *inode, struct extent_position epos, |
1838 | kernel_lb_addr neloc, uint32_t nelen, struct buffer_head *bh) | 1959 | kernel_lb_addr neloc, uint32_t nelen) |
1839 | { | 1960 | { |
1840 | kernel_lb_addr oeloc; | 1961 | kernel_lb_addr oeloc; |
1841 | uint32_t oelen; | 1962 | uint32_t oelen; |
1842 | int8_t etype; | 1963 | int8_t etype; |
1843 | 1964 | ||
1844 | if (bh) | 1965 | if (epos.bh) |
1845 | atomic_inc(&bh->b_count); | 1966 | get_bh(epos.bh); |
1846 | 1967 | ||
1847 | while ((etype = udf_next_aext(inode, &bloc, &extoffset, &oeloc, &oelen, &bh, 0)) != -1) | 1968 | while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) |
1848 | { | 1969 | { |
1849 | udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1); | 1970 | udf_write_aext(inode, &epos, neloc, nelen, 1); |
1850 | 1971 | ||
1851 | neloc = oeloc; | 1972 | neloc = oeloc; |
1852 | nelen = (etype << 30) | oelen; | 1973 | nelen = (etype << 30) | oelen; |
1853 | } | 1974 | } |
1854 | udf_add_aext(inode, &bloc, &extoffset, neloc, nelen, &bh, 1); | 1975 | udf_add_aext(inode, &epos, neloc, nelen, 1); |
1855 | udf_release_data(bh); | 1976 | brelse(epos.bh); |
1856 | return (nelen >> 30); | 1977 | return (nelen >> 30); |
1857 | } | 1978 | } |
1858 | 1979 | ||
1859 | int8_t udf_delete_aext(struct inode *inode, kernel_lb_addr nbloc, int nextoffset, | 1980 | int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, |
1860 | kernel_lb_addr eloc, uint32_t elen, struct buffer_head *nbh) | 1981 | kernel_lb_addr eloc, uint32_t elen) |
1861 | { | 1982 | { |
1862 | struct buffer_head *obh; | 1983 | struct extent_position oepos; |
1863 | kernel_lb_addr obloc; | 1984 | int adsize; |
1864 | int oextoffset, adsize; | ||
1865 | int8_t etype; | 1985 | int8_t etype; |
1866 | struct allocExtDesc *aed; | 1986 | struct allocExtDesc *aed; |
1867 | 1987 | ||
1868 | if (nbh) | 1988 | if (epos.bh) |
1869 | { | 1989 | { |
1870 | atomic_inc(&nbh->b_count); | 1990 | get_bh(epos.bh); |
1871 | atomic_inc(&nbh->b_count); | 1991 | get_bh(epos.bh); |
1872 | } | 1992 | } |
1873 | 1993 | ||
1874 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) | 1994 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) |
@@ -1878,80 +1998,77 @@ int8_t udf_delete_aext(struct inode *inode, kernel_lb_addr nbloc, int nextoffset | |||
1878 | else | 1998 | else |
1879 | adsize = 0; | 1999 | adsize = 0; |
1880 | 2000 | ||
1881 | obh = nbh; | 2001 | oepos = epos; |
1882 | obloc = nbloc; | 2002 | if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1) |
1883 | oextoffset = nextoffset; | ||
1884 | |||
1885 | if (udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1) == -1) | ||
1886 | return -1; | 2003 | return -1; |
1887 | 2004 | ||
1888 | while ((etype = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1) | 2005 | while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) |
1889 | { | 2006 | { |
1890 | udf_write_aext(inode, obloc, &oextoffset, eloc, (etype << 30) | elen, obh, 1); | 2007 | udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1); |
1891 | if (obh != nbh) | 2008 | if (oepos.bh != epos.bh) |
1892 | { | 2009 | { |
1893 | obloc = nbloc; | 2010 | oepos.block = epos.block; |
1894 | udf_release_data(obh); | 2011 | brelse(oepos.bh); |
1895 | atomic_inc(&nbh->b_count); | 2012 | get_bh(epos.bh); |
1896 | obh = nbh; | 2013 | oepos.bh = epos.bh; |
1897 | oextoffset = nextoffset - adsize; | 2014 | oepos.offset = epos.offset - adsize; |
1898 | } | 2015 | } |
1899 | } | 2016 | } |
1900 | memset(&eloc, 0x00, sizeof(kernel_lb_addr)); | 2017 | memset(&eloc, 0x00, sizeof(kernel_lb_addr)); |
1901 | elen = 0; | 2018 | elen = 0; |
1902 | 2019 | ||
1903 | if (nbh != obh) | 2020 | if (epos.bh != oepos.bh) |
1904 | { | 2021 | { |
1905 | udf_free_blocks(inode->i_sb, inode, nbloc, 0, 1); | 2022 | udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1); |
1906 | udf_write_aext(inode, obloc, &oextoffset, eloc, elen, obh, 1); | 2023 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
1907 | udf_write_aext(inode, obloc, &oextoffset, eloc, elen, obh, 1); | 2024 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
1908 | if (!obh) | 2025 | if (!oepos.bh) |
1909 | { | 2026 | { |
1910 | UDF_I_LENALLOC(inode) -= (adsize * 2); | 2027 | UDF_I_LENALLOC(inode) -= (adsize * 2); |
1911 | mark_inode_dirty(inode); | 2028 | mark_inode_dirty(inode); |
1912 | } | 2029 | } |
1913 | else | 2030 | else |
1914 | { | 2031 | { |
1915 | aed = (struct allocExtDesc *)(obh)->b_data; | 2032 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
1916 | aed->lengthAllocDescs = | 2033 | aed->lengthAllocDescs = |
1917 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize)); | 2034 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize)); |
1918 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 2035 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
1919 | udf_update_tag((obh)->b_data, oextoffset - (2*adsize)); | 2036 | udf_update_tag(oepos.bh->b_data, oepos.offset - (2*adsize)); |
1920 | else | 2037 | else |
1921 | udf_update_tag((obh)->b_data, sizeof(struct allocExtDesc)); | 2038 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); |
1922 | mark_buffer_dirty_inode(obh, inode); | 2039 | mark_buffer_dirty_inode(oepos.bh, inode); |
1923 | } | 2040 | } |
1924 | } | 2041 | } |
1925 | else | 2042 | else |
1926 | { | 2043 | { |
1927 | udf_write_aext(inode, obloc, &oextoffset, eloc, elen, obh, 1); | 2044 | udf_write_aext(inode, &oepos, eloc, elen, 1); |
1928 | if (!obh) | 2045 | if (!oepos.bh) |
1929 | { | 2046 | { |
1930 | UDF_I_LENALLOC(inode) -= adsize; | 2047 | UDF_I_LENALLOC(inode) -= adsize; |
1931 | mark_inode_dirty(inode); | 2048 | mark_inode_dirty(inode); |
1932 | } | 2049 | } |
1933 | else | 2050 | else |
1934 | { | 2051 | { |
1935 | aed = (struct allocExtDesc *)(obh)->b_data; | 2052 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
1936 | aed->lengthAllocDescs = | 2053 | aed->lengthAllocDescs = |
1937 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); | 2054 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); |
1938 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) | 2055 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
1939 | udf_update_tag((obh)->b_data, oextoffset - adsize); | 2056 | udf_update_tag(oepos.bh->b_data, epos.offset - adsize); |
1940 | else | 2057 | else |
1941 | udf_update_tag((obh)->b_data, sizeof(struct allocExtDesc)); | 2058 | udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); |
1942 | mark_buffer_dirty_inode(obh, inode); | 2059 | mark_buffer_dirty_inode(oepos.bh, inode); |
1943 | } | 2060 | } |
1944 | } | 2061 | } |
1945 | 2062 | ||
1946 | udf_release_data(nbh); | 2063 | brelse(epos.bh); |
1947 | udf_release_data(obh); | 2064 | brelse(oepos.bh); |
1948 | return (elen >> 30); | 2065 | return (elen >> 30); |
1949 | } | 2066 | } |
1950 | 2067 | ||
1951 | int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t *extoffset, | 2068 | int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *pos, |
1952 | kernel_lb_addr *eloc, uint32_t *elen, uint32_t *offset, struct buffer_head **bh) | 2069 | kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset) |
1953 | { | 2070 | { |
1954 | uint64_t lbcount = 0, bcount = (uint64_t)block << inode->i_sb->s_blocksize_bits; | 2071 | loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits; |
1955 | int8_t etype; | 2072 | int8_t etype; |
1956 | 2073 | ||
1957 | if (block < 0) | 2074 | if (block < 0) |
@@ -1960,42 +2077,44 @@ int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t | |||
1960 | return -1; | 2077 | return -1; |
1961 | } | 2078 | } |
1962 | 2079 | ||
1963 | *extoffset = 0; | 2080 | pos->offset = 0; |
2081 | pos->block = UDF_I_LOCATION(inode); | ||
2082 | pos->bh = NULL; | ||
1964 | *elen = 0; | 2083 | *elen = 0; |
1965 | *bloc = UDF_I_LOCATION(inode); | ||
1966 | 2084 | ||
1967 | do | 2085 | do |
1968 | { | 2086 | { |
1969 | if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1) | 2087 | if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) |
1970 | { | 2088 | { |
1971 | *offset = bcount - lbcount; | 2089 | *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits; |
1972 | UDF_I_LENEXTENTS(inode) = lbcount; | 2090 | UDF_I_LENEXTENTS(inode) = lbcount; |
1973 | return -1; | 2091 | return -1; |
1974 | } | 2092 | } |
1975 | lbcount += *elen; | 2093 | lbcount += *elen; |
1976 | } while (lbcount <= bcount); | 2094 | } while (lbcount <= bcount); |
1977 | 2095 | ||
1978 | *offset = bcount + *elen - lbcount; | 2096 | *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits; |
1979 | 2097 | ||
1980 | return etype; | 2098 | return etype; |
1981 | } | 2099 | } |
1982 | 2100 | ||
1983 | long udf_block_map(struct inode *inode, long block) | 2101 | long udf_block_map(struct inode *inode, sector_t block) |
1984 | { | 2102 | { |
1985 | kernel_lb_addr eloc, bloc; | 2103 | kernel_lb_addr eloc; |
1986 | uint32_t offset, extoffset, elen; | 2104 | uint32_t elen; |
1987 | struct buffer_head *bh = NULL; | 2105 | sector_t offset; |
2106 | struct extent_position epos = { NULL, 0, { 0, 0}}; | ||
1988 | int ret; | 2107 | int ret; |
1989 | 2108 | ||
1990 | lock_kernel(); | 2109 | lock_kernel(); |
1991 | 2110 | ||
1992 | if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) | 2111 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) |
1993 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset >> inode->i_sb->s_blocksize_bits); | 2112 | ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); |
1994 | else | 2113 | else |
1995 | ret = 0; | 2114 | ret = 0; |
1996 | 2115 | ||
1997 | unlock_kernel(); | 2116 | unlock_kernel(); |
1998 | udf_release_data(bh); | 2117 | brelse(epos.bh); |
1999 | 2118 | ||
2000 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV)) | 2119 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV)) |
2001 | return udf_fixed_to_variable(ret); | 2120 | return udf_fixed_to_variable(ret); |