5 * Inode handling routines for the OSTA-UDF(tm) filesystem.
8 * This file is distributed under the terms of the GNU General Public
9 * License (GPL). Copies of the GPL can be obtained from:
10 * ftp://prep.ai.mit.edu/pub/gnu/GPL
11 * Each contributing author retains all rights to their own work.
13 * (C) 1998 Dave Boynton
14 * (C) 1998-2004 Ben Fennema
15 * (C) 1999-2000 Stelias Computing Inc
19 * 10/04/98 dgb Added rudimentary directory functions
20 * 10/07/98 Fully working udf_block_map! It works!
21 * 11/25/98 bmap altered to better support extents
22 * 12/06/98 blf partition support in udf_iget, udf_block_map
24 * 12/12/98 rewrote udf_block_map to handle next extents and descs across
25 * block boundaries (which is not actually allowed)
26 * 12/20/98 added support for strategy 4096
27 * 03/07/99 rewrote udf_block_map (again)
28 * New funcs, inode_bmap, udf_next_aext
29 * 04/19/99 Support for writing device EA's for major/minor #
34 #include <linux/smp_lock.h>
35 #include <linux/module.h>
36 #include <linux/pagemap.h>
37 #include <linux/buffer_head.h>
38 #include <linux/writeback.h>
39 #include <linux/slab.h>
44 MODULE_AUTHOR("Ben Fennema");
45 MODULE_DESCRIPTION("Universal Disk Format Filesystem");
46 MODULE_LICENSE("GPL");
48 #define EXTENT_MERGE_SIZE 5
50 static mode_t udf_convert_permissions(struct fileEntry *);
51 static int udf_update_inode(struct inode *, int);
52 static void udf_fill_inode(struct inode *, struct buffer_head *);
53 static int udf_alloc_i_data(struct inode *inode, size_t size);
54 static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
56 static int8_t udf_insert_aext(struct inode *, struct extent_position,
57 kernel_lb_addr, uint32_t);
58 static void udf_split_extents(struct inode *, int *, int, int,
59 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
60 static void udf_prealloc_extents(struct inode *, int, int,
61 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
62 static void udf_merge_extents(struct inode *,
63 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
64 static void udf_update_extents(struct inode *,
65 kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
66 struct extent_position *);
67 static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
73 * Clean-up before the specified inode is destroyed.
76 * This routine is called when the kernel destroys an inode structure
77 * ie. when iput() finds i_count == 0.
80 * July 1, 1997 - Andrew E. Mileski
81 * Written, tested, and released.
83 * Called at the last iput() if i_nlink is zero.
85 void udf_delete_inode(struct inode *inode)
87 truncate_inode_pages(&inode->i_data, 0);
89 if (is_bad_inode(inode))
96 udf_update_inode(inode, IS_SYNC(inode));
97 udf_free_inode(inode);
107 * If we are going to release inode from memory, we discard preallocation and
108 * truncate last inode extent to proper length. We could use drop_inode() but
109 * it's called under inode_lock and thus we cannot mark inode dirty there. We
110 * use clear_inode() but we have to make sure to write inode as it's not written
113 void udf_clear_inode(struct inode *inode)
115 if (!(inode->i_sb->s_flags & MS_RDONLY)) {
117 /* Discard preallocation for directories, symlinks, etc. */
118 udf_discard_prealloc(inode);
119 udf_truncate_tail_extent(inode);
121 write_inode_now(inode, 1);
123 kfree(UDF_I(inode)->i_ext.i_data);
124 UDF_I(inode)->i_ext.i_data = NULL;
127 static int udf_writepage(struct page *page, struct writeback_control *wbc)
129 return block_write_full_page(page, udf_get_block, wbc);
132 static int udf_readpage(struct file *file, struct page *page)
134 return block_read_full_page(page, udf_get_block);
137 static int udf_write_begin(struct file *file, struct address_space *mapping,
138 loff_t pos, unsigned len, unsigned flags,
139 struct page **pagep, void **fsdata)
142 return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
146 static sector_t udf_bmap(struct address_space *mapping, sector_t block)
148 return generic_block_bmap(mapping, block, udf_get_block);
151 const struct address_space_operations udf_aops = {
152 .readpage = udf_readpage,
153 .writepage = udf_writepage,
154 .sync_page = block_sync_page,
155 .write_begin = udf_write_begin,
156 .write_end = generic_write_end,
160 void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
164 struct writeback_control udf_wbc = {
165 .sync_mode = WB_SYNC_NONE,
169 /* from now on we have normal address_space methods */
170 inode->i_data.a_ops = &udf_aops;
172 if (!UDF_I(inode)->i_lenAlloc) {
173 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
174 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
176 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_LONG;
177 mark_inode_dirty(inode);
181 page = grab_cache_page(inode->i_mapping, 0);
182 BUG_ON(!PageLocked(page));
184 if (!PageUptodate(page)) {
186 memset(kaddr + UDF_I(inode)->i_lenAlloc, 0x00,
187 PAGE_CACHE_SIZE - UDF_I(inode)->i_lenAlloc);
188 memcpy(kaddr, UDF_I(inode)->i_ext.i_data +
189 UDF_I(inode)->i_lenEAttr, UDF_I(inode)->i_lenAlloc);
190 flush_dcache_page(page);
191 SetPageUptodate(page);
194 memset(UDF_I(inode)->i_ext.i_data + UDF_I(inode)->i_lenEAttr, 0x00,
195 UDF_I(inode)->i_lenAlloc);
196 UDF_I(inode)->i_lenAlloc = 0;
197 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
198 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
200 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_LONG;
202 inode->i_data.a_ops->writepage(page, &udf_wbc);
203 page_cache_release(page);
205 mark_inode_dirty(inode);
208 struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
212 struct buffer_head *dbh = NULL;
216 struct extent_position epos;
218 struct udf_fileident_bh sfibh, dfibh;
219 loff_t f_pos = udf_ext0_offset(inode) >> 2;
220 int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
221 struct fileIdentDesc cfi, *sfi, *dfi;
223 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
224 alloctype = ICBTAG_FLAG_AD_SHORT;
226 alloctype = ICBTAG_FLAG_AD_LONG;
228 if (!inode->i_size) {
229 UDF_I(inode)->i_alloc_type = alloctype;
230 mark_inode_dirty(inode);
234 /* alloc block, and copy data to it */
235 *block = udf_new_block(inode->i_sb, inode,
236 UDF_I(inode)->i_location.partitionReferenceNum,
237 UDF_I(inode)->i_location.logicalBlockNum, err);
240 newblock = udf_get_pblock(inode->i_sb, *block,
241 UDF_I(inode)->i_location.partitionReferenceNum,
245 dbh = udf_tgetblk(inode->i_sb, newblock);
249 memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
250 set_buffer_uptodate(dbh);
252 mark_buffer_dirty_inode(dbh, inode);
254 sfibh.soffset = sfibh.eoffset =
255 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
256 sfibh.sbh = sfibh.ebh = NULL;
257 dfibh.soffset = dfibh.eoffset = 0;
258 dfibh.sbh = dfibh.ebh = dbh;
259 while ((f_pos < size)) {
260 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
261 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
267 UDF_I(inode)->i_alloc_type = alloctype;
268 sfi->descTag.tagLocation = cpu_to_le32(*block);
269 dfibh.soffset = dfibh.eoffset;
270 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
271 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
272 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
274 le16_to_cpu(sfi->lengthOfImpUse))) {
275 UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
280 mark_buffer_dirty_inode(dbh, inode);
282 memset(UDF_I(inode)->i_ext.i_data + UDF_I(inode)->i_lenEAttr, 0,
283 UDF_I(inode)->i_lenAlloc);
284 UDF_I(inode)->i_lenAlloc = 0;
285 eloc.logicalBlockNum = *block;
286 eloc.partitionReferenceNum =
287 UDF_I(inode)->i_location.partitionReferenceNum;
288 elen = inode->i_size;
289 UDF_I(inode)->i_lenExtents = elen;
291 epos.block = UDF_I(inode)->i_location;
292 epos.offset = udf_file_entry_alloc_offset(inode);
293 udf_add_aext(inode, &epos, eloc, elen, 0);
297 mark_inode_dirty(inode);
301 static int udf_get_block(struct inode *inode, sector_t block,
302 struct buffer_head *bh_result, int create)
305 struct buffer_head *bh;
309 phys = udf_block_map(inode, block);
311 map_bh(bh_result, inode->i_sb, phys);
324 if (block == UDF_I(inode)->i_next_alloc_block + 1) {
325 UDF_I(inode)->i_next_alloc_block++;
326 UDF_I(inode)->i_next_alloc_goal++;
331 bh = inode_getblk(inode, block, &err, &phys, &new);
338 set_buffer_new(bh_result);
339 map_bh(bh_result, inode->i_sb, phys);
346 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
350 static struct buffer_head *udf_getblk(struct inode *inode, long block,
351 int create, int *err)
353 struct buffer_head *bh;
354 struct buffer_head dummy;
357 dummy.b_blocknr = -1000;
358 *err = udf_get_block(inode, block, &dummy, create);
359 if (!*err && buffer_mapped(&dummy)) {
360 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
361 if (buffer_new(&dummy)) {
363 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
364 set_buffer_uptodate(bh);
366 mark_buffer_dirty_inode(bh, inode);
374 /* Extend the file by 'blocks' blocks, return the number of extents added */
375 int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
376 kernel_long_ad *last_ext, sector_t blocks)
379 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
380 struct super_block *sb = inode->i_sb;
381 kernel_lb_addr prealloc_loc = {};
382 int prealloc_len = 0;
384 /* The previous extent is fake and we should not extend by anything
385 * - there's nothing to do... */
389 /* Round the last extent up to a multiple of block size */
390 if (last_ext->extLength & (sb->s_blocksize - 1)) {
391 last_ext->extLength =
392 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
393 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
394 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
395 UDF_I(inode)->i_lenExtents =
396 (UDF_I(inode)->i_lenExtents + sb->s_blocksize - 1) &
397 ~(sb->s_blocksize - 1);
400 /* Last extent are just preallocated blocks? */
401 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
402 EXT_NOT_RECORDED_ALLOCATED) {
403 /* Save the extent so that we can reattach it to the end */
404 prealloc_loc = last_ext->extLocation;
405 prealloc_len = last_ext->extLength;
406 /* Mark the extent as a hole */
407 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
408 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
409 last_ext->extLocation.logicalBlockNum = 0;
410 last_ext->extLocation.partitionReferenceNum = 0;
413 /* Can we merge with the previous extent? */
414 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
415 EXT_NOT_RECORDED_NOT_ALLOCATED) {
416 add = ((1 << 30) - sb->s_blocksize -
417 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >>
418 sb->s_blocksize_bits;
422 last_ext->extLength += add << sb->s_blocksize_bits;
426 udf_add_aext(inode, last_pos, last_ext->extLocation,
427 last_ext->extLength, 1);
430 udf_write_aext(inode, last_pos, last_ext->extLocation,
431 last_ext->extLength, 1);
433 /* Managed to do everything necessary? */
437 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
438 last_ext->extLocation.logicalBlockNum = 0;
439 last_ext->extLocation.partitionReferenceNum = 0;
440 add = (1 << (30-sb->s_blocksize_bits)) - 1;
441 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
442 (add << sb->s_blocksize_bits);
444 /* Create enough extents to cover the whole hole */
445 while (blocks > add) {
447 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
448 last_ext->extLength, 1) == -1)
453 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
454 (blocks << sb->s_blocksize_bits);
455 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
456 last_ext->extLength, 1) == -1)
462 /* Do we have some preallocated blocks saved? */
464 if (udf_add_aext(inode, last_pos, prealloc_loc,
465 prealloc_len, 1) == -1)
467 last_ext->extLocation = prealloc_loc;
468 last_ext->extLength = prealloc_len;
472 /* last_pos should point to the last written extent... */
473 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
474 last_pos->offset -= sizeof(short_ad);
475 else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
476 last_pos->offset -= sizeof(long_ad);
483 static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
484 int *err, long *phys, int *new)
486 static sector_t last_block;
487 struct buffer_head *result = NULL;
488 kernel_long_ad laarr[EXTENT_MERGE_SIZE];
489 struct extent_position prev_epos, cur_epos, next_epos;
490 int count = 0, startnum = 0, endnum = 0;
491 uint32_t elen = 0, tmpelen;
492 kernel_lb_addr eloc, tmpeloc;
494 loff_t lbcount = 0, b_off = 0;
495 uint32_t newblocknum, newblock;
498 int goal = 0, pgoal = UDF_I(inode)->i_location.logicalBlockNum;
501 prev_epos.offset = udf_file_entry_alloc_offset(inode);
502 prev_epos.block = UDF_I(inode)->i_location;
504 cur_epos = next_epos = prev_epos;
505 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
507 /* find the extent which contains the block we are looking for.
508 alternate between laarr[0] and laarr[1] for locations of the
509 current extent, and the previous extent */
511 if (prev_epos.bh != cur_epos.bh) {
512 brelse(prev_epos.bh);
514 prev_epos.bh = cur_epos.bh;
516 if (cur_epos.bh != next_epos.bh) {
518 get_bh(next_epos.bh);
519 cur_epos.bh = next_epos.bh;
524 prev_epos.block = cur_epos.block;
525 cur_epos.block = next_epos.block;
527 prev_epos.offset = cur_epos.offset;
528 cur_epos.offset = next_epos.offset;
530 etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1);
536 laarr[c].extLength = (etype << 30) | elen;
537 laarr[c].extLocation = eloc;
539 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
540 pgoal = eloc.logicalBlockNum +
541 ((elen + inode->i_sb->s_blocksize - 1) >>
542 inode->i_sb->s_blocksize_bits);
545 } while (lbcount + elen <= b_off);
548 offset = b_off >> inode->i_sb->s_blocksize_bits;
550 * Move prev_epos and cur_epos into indirect extent if we are at
553 udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
554 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
556 /* if the extent is allocated and recorded, return the block
557 if the extent is not a multiple of the blocksize, round up */
559 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
560 if (elen & (inode->i_sb->s_blocksize - 1)) {
561 elen = EXT_RECORDED_ALLOCATED |
562 ((elen + inode->i_sb->s_blocksize - 1) &
563 ~(inode->i_sb->s_blocksize - 1));
564 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
566 brelse(prev_epos.bh);
568 brelse(next_epos.bh);
569 newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
575 /* Are we beyond EOF? */
584 /* Create a fake extent when there's not one */
585 memset(&laarr[0].extLocation, 0x00,
586 sizeof(kernel_lb_addr));
587 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
588 /* Will udf_extend_file() create real extent from
590 startnum = (offset > 0);
592 /* Create extents for the hole between EOF and offset */
593 ret = udf_extend_file(inode, &prev_epos, laarr, offset);
595 brelse(prev_epos.bh);
597 brelse(next_epos.bh);
598 /* We don't really know the error here so we just make
606 /* We are not covered by a preallocated extent? */
607 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
608 EXT_NOT_RECORDED_ALLOCATED) {
609 /* Is there any real extent? - otherwise we overwrite
613 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
614 inode->i_sb->s_blocksize;
615 memset(&laarr[c].extLocation, 0x00,
616 sizeof(kernel_lb_addr));
623 endnum = startnum = ((count > 2) ? 2 : count);
625 /* if the current extent is in position 0,
626 swap it with the previous */
627 if (!c && count != 1) {
634 /* if the current block is located in an extent,
635 read the next extent */
636 etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0);
638 laarr[c + 1].extLength = (etype << 30) | elen;
639 laarr[c + 1].extLocation = eloc;
647 /* if the current extent is not recorded but allocated, get the
648 * block in the extent corresponding to the requested block */
649 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
650 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
651 else { /* otherwise, allocate a new block */
652 if (UDF_I(inode)->i_next_alloc_block == block)
653 goal = UDF_I(inode)->i_next_alloc_goal;
656 if (!(goal = pgoal)) /* XXX: what was intended here? */
657 goal = UDF_I(inode)->
658 i_location.logicalBlockNum + 1;
661 newblocknum = udf_new_block(inode->i_sb, inode,
662 UDF_I(inode)->i_location.partitionReferenceNum,
665 brelse(prev_epos.bh);
669 UDF_I(inode)->i_lenExtents += inode->i_sb->s_blocksize;
672 /* if the extent the requsted block is located in contains multiple
673 * blocks, split the extent into at most three extents. blocks prior
674 * to requested block, requested block, and blocks after requested
676 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
678 #ifdef UDF_PREALLOCATE
679 /* preallocate blocks */
680 udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
683 /* merge any continuous blocks in laarr */
684 udf_merge_extents(inode, laarr, &endnum);
686 /* write back the new extents, inserting new extents if the new number
687 * of extents is greater than the old number, and deleting extents if
688 * the new number of extents is less than the old number */
689 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
691 brelse(prev_epos.bh);
693 newblock = udf_get_pblock(inode->i_sb, newblocknum,
694 UDF_I(inode)->i_location.partitionReferenceNum, 0);
700 UDF_I(inode)->i_next_alloc_block = block;
701 UDF_I(inode)->i_next_alloc_goal = newblocknum;
702 inode->i_ctime = current_fs_time(inode->i_sb);
705 udf_sync_inode(inode);
707 mark_inode_dirty(inode);
712 static void udf_split_extents(struct inode *inode, int *c, int offset,
714 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
717 unsigned long blocksize = inode->i_sb->s_blocksize;
718 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
720 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
721 (laarr[*c].extLength >> 30) ==
722 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
724 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
725 blocksize - 1) >> blocksize_bits;
726 int8_t etype = (laarr[curr].extLength >> 30);
730 else if (!offset || blen == offset + 1) {
731 laarr[curr + 2] = laarr[curr + 1];
732 laarr[curr + 1] = laarr[curr];
734 laarr[curr + 3] = laarr[curr + 1];
735 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
739 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
740 udf_free_blocks(inode->i_sb, inode,
741 laarr[curr].extLocation,
743 laarr[curr].extLength =
744 EXT_NOT_RECORDED_NOT_ALLOCATED |
745 (offset << blocksize_bits);
746 laarr[curr].extLocation.logicalBlockNum = 0;
747 laarr[curr].extLocation.
748 partitionReferenceNum = 0;
750 laarr[curr].extLength = (etype << 30) |
751 (offset << blocksize_bits);
757 laarr[curr].extLocation.logicalBlockNum = newblocknum;
758 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
759 laarr[curr].extLocation.partitionReferenceNum =
760 UDF_I(inode)->i_location.partitionReferenceNum;
761 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
765 if (blen != offset + 1) {
766 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
767 laarr[curr].extLocation.logicalBlockNum +=
769 laarr[curr].extLength = (etype << 30) |
770 ((blen - (offset + 1)) << blocksize_bits);
777 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
778 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
781 int start, length = 0, currlength = 0, i;
783 if (*endnum >= (c + 1)) {
789 if ((laarr[c + 1].extLength >> 30) ==
790 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
792 length = currlength =
793 (((laarr[c + 1].extLength &
794 UDF_EXTENT_LENGTH_MASK) +
795 inode->i_sb->s_blocksize - 1) >>
796 inode->i_sb->s_blocksize_bits);
801 for (i = start + 1; i <= *endnum; i++) {
804 length += UDF_DEFAULT_PREALLOC_BLOCKS;
805 } else if ((laarr[i].extLength >> 30) ==
806 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
807 length += (((laarr[i].extLength &
808 UDF_EXTENT_LENGTH_MASK) +
809 inode->i_sb->s_blocksize - 1) >>
810 inode->i_sb->s_blocksize_bits);
816 int next = laarr[start].extLocation.logicalBlockNum +
817 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
818 inode->i_sb->s_blocksize - 1) >>
819 inode->i_sb->s_blocksize_bits);
820 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
821 laarr[start].extLocation.partitionReferenceNum,
822 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
823 length : UDF_DEFAULT_PREALLOC_BLOCKS) -
826 if (start == (c + 1))
827 laarr[start].extLength +=
829 inode->i_sb->s_blocksize_bits);
831 memmove(&laarr[c + 2], &laarr[c + 1],
832 sizeof(long_ad) * (*endnum - (c + 1)));
834 laarr[c + 1].extLocation.logicalBlockNum = next;
835 laarr[c + 1].extLocation.partitionReferenceNum =
836 laarr[c].extLocation.
837 partitionReferenceNum;
838 laarr[c + 1].extLength =
839 EXT_NOT_RECORDED_ALLOCATED |
841 inode->i_sb->s_blocksize_bits);
845 for (i = start + 1; numalloc && i < *endnum; i++) {
846 int elen = ((laarr[i].extLength &
847 UDF_EXTENT_LENGTH_MASK) +
848 inode->i_sb->s_blocksize - 1) >>
849 inode->i_sb->s_blocksize_bits;
851 if (elen > numalloc) {
852 laarr[i].extLength -=
854 inode->i_sb->s_blocksize_bits);
858 if (*endnum > (i + 1))
862 (*endnum - (i + 1)));
867 UDF_I(inode)->i_lenExtents +=
868 numalloc << inode->i_sb->s_blocksize_bits;
873 static void udf_merge_extents(struct inode *inode,
874 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
878 unsigned long blocksize = inode->i_sb->s_blocksize;
879 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
881 for (i = 0; i < (*endnum - 1); i++) {
882 kernel_long_ad *li /*l[i]*/ = &laarr[i];
883 kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
885 if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
886 (((li->extLength >> 30) ==
887 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
888 ((lip1->extLocation.logicalBlockNum -
889 li->extLocation.logicalBlockNum) ==
890 (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
891 blocksize - 1) >> blocksize_bits)))) {
893 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
894 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
895 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
896 lip1->extLength = (lip1->extLength -
898 UDF_EXTENT_LENGTH_MASK) +
899 UDF_EXTENT_LENGTH_MASK) &
901 li->extLength = (li->extLength &
902 UDF_EXTENT_FLAG_MASK) +
903 (UDF_EXTENT_LENGTH_MASK + 1) -
905 lip1->extLocation.logicalBlockNum =
906 li->extLocation.logicalBlockNum +
908 UDF_EXTENT_LENGTH_MASK) >>
911 li->extLength = lip1->extLength +
913 UDF_EXTENT_LENGTH_MASK) +
914 blocksize - 1) & ~(blocksize - 1));
915 if (*endnum > (i + 2))
916 memmove(&laarr[i + 1], &laarr[i + 2],
918 (*endnum - (i + 2)));
922 } else if (((li->extLength >> 30) ==
923 (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
924 ((lip1->extLength >> 30) ==
925 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
926 udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
928 UDF_EXTENT_LENGTH_MASK) +
929 blocksize - 1) >> blocksize_bits);
930 li->extLocation.logicalBlockNum = 0;
931 li->extLocation.partitionReferenceNum = 0;
933 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
934 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
935 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
936 lip1->extLength = (lip1->extLength -
938 UDF_EXTENT_LENGTH_MASK) +
939 UDF_EXTENT_LENGTH_MASK) &
941 li->extLength = (li->extLength &
942 UDF_EXTENT_FLAG_MASK) +
943 (UDF_EXTENT_LENGTH_MASK + 1) -
946 li->extLength = lip1->extLength +
948 UDF_EXTENT_LENGTH_MASK) +
949 blocksize - 1) & ~(blocksize - 1));
950 if (*endnum > (i + 2))
951 memmove(&laarr[i + 1], &laarr[i + 2],
953 (*endnum - (i + 2)));
957 } else if ((li->extLength >> 30) ==
958 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
959 udf_free_blocks(inode->i_sb, inode,
962 UDF_EXTENT_LENGTH_MASK) +
963 blocksize - 1) >> blocksize_bits);
964 li->extLocation.logicalBlockNum = 0;
965 li->extLocation.partitionReferenceNum = 0;
966 li->extLength = (li->extLength &
967 UDF_EXTENT_LENGTH_MASK) |
968 EXT_NOT_RECORDED_NOT_ALLOCATED;
973 static void udf_update_extents(struct inode *inode,
974 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
975 int startnum, int endnum,
976 struct extent_position *epos)
979 kernel_lb_addr tmploc;
982 if (startnum > endnum) {
983 for (i = 0; i < (startnum - endnum); i++)
984 udf_delete_aext(inode, *epos, laarr[i].extLocation,
986 } else if (startnum < endnum) {
987 for (i = 0; i < (endnum - startnum); i++) {
988 udf_insert_aext(inode, *epos, laarr[i].extLocation,
990 udf_next_aext(inode, epos, &laarr[i].extLocation,
991 &laarr[i].extLength, 1);
996 for (i = start; i < endnum; i++) {
997 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
998 udf_write_aext(inode, epos, laarr[i].extLocation,
999 laarr[i].extLength, 1);
1003 struct buffer_head *udf_bread(struct inode *inode, int block,
1004 int create, int *err)
1006 struct buffer_head *bh = NULL;
1008 bh = udf_getblk(inode, block, create, err);
1012 if (buffer_uptodate(bh))
1015 ll_rw_block(READ, 1, &bh);
1018 if (buffer_uptodate(bh))
1026 void udf_truncate(struct inode *inode)
1031 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1032 S_ISLNK(inode->i_mode)))
1034 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1038 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1039 if (inode->i_sb->s_blocksize <
1040 (udf_file_entry_alloc_offset(inode) +
1042 udf_expand_file_adinicb(inode, inode->i_size, &err);
1043 if (UDF_I(inode)->i_alloc_type ==
1044 ICBTAG_FLAG_AD_IN_ICB) {
1045 inode->i_size = UDF_I(inode)->i_lenAlloc;
1049 udf_truncate_extents(inode);
1051 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1052 memset(UDF_I(inode)->i_ext.i_data +
1053 UDF_I(inode)->i_lenEAttr + offset,
1054 0x00, inode->i_sb->s_blocksize -
1055 offset - udf_file_entry_alloc_offset(inode));
1056 UDF_I(inode)->i_lenAlloc = inode->i_size;
1059 block_truncate_page(inode->i_mapping, inode->i_size,
1061 udf_truncate_extents(inode);
1064 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1066 udf_sync_inode(inode);
1068 mark_inode_dirty(inode);
1072 static void __udf_read_inode(struct inode *inode)
1074 struct buffer_head *bh = NULL;
1075 struct fileEntry *fe;
1079 * Set defaults, but the inode is still incomplete!
1080 * Note: get_new_inode() sets the following on a new inode:
1083 * i_flags = sb->s_flags
1085 * clean_inode(): zero fills and sets
1090 bh = udf_read_ptagged(inode->i_sb, UDF_I(inode)->i_location, 0, &ident);
1092 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1094 make_bad_inode(inode);
1098 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1099 ident != TAG_IDENT_USE) {
1100 printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
1101 "failed ident=%d\n", inode->i_ino, ident);
1103 make_bad_inode(inode);
1107 fe = (struct fileEntry *)bh->b_data;
1109 if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
1110 struct buffer_head *ibh = NULL, *nbh = NULL;
1111 struct indirectEntry *ie;
1113 ibh = udf_read_ptagged(inode->i_sb, UDF_I(inode)->i_location, 1,
1115 if (ident == TAG_IDENT_IE) {
1118 ie = (struct indirectEntry *)ibh->b_data;
1120 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1122 if (ie->indirectICB.extLength &&
1123 (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
1125 if (ident == TAG_IDENT_FE ||
1126 ident == TAG_IDENT_EFE) {
1127 memcpy(&UDF_I(inode)->i_location,
1129 sizeof(kernel_lb_addr));
1133 __udf_read_inode(inode);
1146 } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
1147 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1148 le16_to_cpu(fe->icbTag.strategyType));
1150 make_bad_inode(inode);
1153 udf_fill_inode(inode, bh);
1158 static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1160 struct fileEntry *fe;
1161 struct extendedFileEntry *efe;
1165 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1167 fe = (struct fileEntry *)bh->b_data;
1168 efe = (struct extendedFileEntry *)bh->b_data;
1170 if (fe->icbTag.strategyType == cpu_to_le16(4))
1171 UDF_I(inode)->i_strat4096 = 0;
1172 else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
1173 UDF_I(inode)->i_strat4096 = 1;
1175 UDF_I(inode)->i_alloc_type = le16_to_cpu(fe->icbTag.flags) &
1176 ICBTAG_FLAG_AD_MASK;
1177 UDF_I(inode)->i_unique = 0;
1178 UDF_I(inode)->i_lenEAttr = 0;
1179 UDF_I(inode)->i_lenExtents = 0;
1180 UDF_I(inode)->i_lenAlloc = 0;
1181 UDF_I(inode)->i_next_alloc_block = 0;
1182 UDF_I(inode)->i_next_alloc_goal = 0;
1183 if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) {
1184 UDF_I(inode)->i_efe = 1;
1185 UDF_I(inode)->i_use = 0;
1186 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1187 sizeof(struct extendedFileEntry))) {
1188 make_bad_inode(inode);
1191 memcpy(UDF_I(inode)->i_ext.i_data,
1192 bh->b_data + sizeof(struct extendedFileEntry),
1193 inode->i_sb->s_blocksize -
1194 sizeof(struct extendedFileEntry));
1195 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) {
1196 UDF_I(inode)->i_efe = 0;
1197 UDF_I(inode)->i_use = 0;
1198 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1199 sizeof(struct fileEntry))) {
1200 make_bad_inode(inode);
1203 memcpy(UDF_I(inode)->i_ext.i_data,
1204 bh->b_data + sizeof(struct fileEntry),
1205 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1206 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
1207 UDF_I(inode)->i_efe = 0;
1208 UDF_I(inode)->i_use = 1;
1209 UDF_I(inode)->i_lenAlloc = le32_to_cpu(
1210 ((struct unallocSpaceEntry *)bh->b_data)->
1212 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1213 sizeof(struct unallocSpaceEntry))) {
1214 make_bad_inode(inode);
1217 memcpy(UDF_I(inode)->i_ext.i_data,
1218 bh->b_data + sizeof(struct unallocSpaceEntry),
1219 inode->i_sb->s_blocksize -
1220 sizeof(struct unallocSpaceEntry));
1224 inode->i_uid = le32_to_cpu(fe->uid);
1225 if (inode->i_uid == -1 ||
1226 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
1227 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
1228 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1230 inode->i_gid = le32_to_cpu(fe->gid);
1231 if (inode->i_gid == -1 ||
1232 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
1233 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
1234 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1236 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1237 if (!inode->i_nlink)
1240 inode->i_size = le64_to_cpu(fe->informationLength);
1241 UDF_I(inode)->i_lenExtents = inode->i_size;
1243 inode->i_mode = udf_convert_permissions(fe);
1244 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1246 if (UDF_I(inode)->i_efe == 0) {
1247 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1248 (inode->i_sb->s_blocksize_bits - 9);
1250 if (udf_stamp_to_time(&convtime, &convtime_usec,
1251 lets_to_cpu(fe->accessTime))) {
1252 inode->i_atime.tv_sec = convtime;
1253 inode->i_atime.tv_nsec = convtime_usec * 1000;
1255 inode->i_atime = sbi->s_record_time;
1258 if (udf_stamp_to_time(&convtime, &convtime_usec,
1259 lets_to_cpu(fe->modificationTime))) {
1260 inode->i_mtime.tv_sec = convtime;
1261 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1263 inode->i_mtime = sbi->s_record_time;
1266 if (udf_stamp_to_time(&convtime, &convtime_usec,
1267 lets_to_cpu(fe->attrTime))) {
1268 inode->i_ctime.tv_sec = convtime;
1269 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1271 inode->i_ctime = sbi->s_record_time;
1274 UDF_I(inode)->i_unique = le64_to_cpu(fe->uniqueID);
1275 UDF_I(inode)->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
1276 UDF_I(inode)->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
1277 offset = sizeof(struct fileEntry) + UDF_I(inode)->i_lenEAttr;
1279 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1280 (inode->i_sb->s_blocksize_bits - 9);
1282 if (udf_stamp_to_time(&convtime, &convtime_usec,
1283 lets_to_cpu(efe->accessTime))) {
1284 inode->i_atime.tv_sec = convtime;
1285 inode->i_atime.tv_nsec = convtime_usec * 1000;
1287 inode->i_atime = sbi->s_record_time;
1290 if (udf_stamp_to_time(&convtime, &convtime_usec,
1291 lets_to_cpu(efe->modificationTime))) {
1292 inode->i_mtime.tv_sec = convtime;
1293 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1295 inode->i_mtime = sbi->s_record_time;
1298 if (udf_stamp_to_time(&convtime, &convtime_usec,
1299 lets_to_cpu(efe->createTime))) {
1300 UDF_I(inode)->i_crtime.tv_sec = convtime;
1301 UDF_I(inode)->i_crtime.tv_nsec = convtime_usec * 1000;
1303 UDF_I(inode)->i_crtime = sbi->s_record_time;
1306 if (udf_stamp_to_time(&convtime, &convtime_usec,
1307 lets_to_cpu(efe->attrTime))) {
1308 inode->i_ctime.tv_sec = convtime;
1309 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1311 inode->i_ctime = sbi->s_record_time;
1314 UDF_I(inode)->i_unique = le64_to_cpu(efe->uniqueID);
1315 UDF_I(inode)->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
1316 UDF_I(inode)->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
1317 offset = sizeof(struct extendedFileEntry) +
1318 UDF_I(inode)->i_lenEAttr;
1321 switch (fe->icbTag.fileType) {
1322 case ICBTAG_FILE_TYPE_DIRECTORY:
1323 inode->i_op = &udf_dir_inode_operations;
1324 inode->i_fop = &udf_dir_operations;
1325 inode->i_mode |= S_IFDIR;
1328 case ICBTAG_FILE_TYPE_REALTIME:
1329 case ICBTAG_FILE_TYPE_REGULAR:
1330 case ICBTAG_FILE_TYPE_UNDEF:
1331 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1332 inode->i_data.a_ops = &udf_adinicb_aops;
1334 inode->i_data.a_ops = &udf_aops;
1335 inode->i_op = &udf_file_inode_operations;
1336 inode->i_fop = &udf_file_operations;
1337 inode->i_mode |= S_IFREG;
1339 case ICBTAG_FILE_TYPE_BLOCK:
1340 inode->i_mode |= S_IFBLK;
1342 case ICBTAG_FILE_TYPE_CHAR:
1343 inode->i_mode |= S_IFCHR;
1345 case ICBTAG_FILE_TYPE_FIFO:
1346 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1348 case ICBTAG_FILE_TYPE_SOCKET:
1349 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1351 case ICBTAG_FILE_TYPE_SYMLINK:
1352 inode->i_data.a_ops = &udf_symlink_aops;
1353 inode->i_op = &page_symlink_inode_operations;
1354 inode->i_mode = S_IFLNK | S_IRWXUGO;
1357 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
1358 "file type=%d\n", inode->i_ino,
1359 fe->icbTag.fileType);
1360 make_bad_inode(inode);
1363 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1364 struct deviceSpec *dsea =
1365 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1367 init_special_inode(inode, inode->i_mode,
1368 MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
1369 le32_to_cpu(dsea->minorDeviceIdent)));
1370 /* Developer ID ??? */
1372 make_bad_inode(inode);
1376 static int udf_alloc_i_data(struct inode *inode, size_t size)
1378 UDF_I(inode)->i_ext.i_data = kmalloc(size, GFP_KERNEL);
1380 if (!UDF_I(inode)->i_ext.i_data) {
1381 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
1382 "no free memory\n", inode->i_ino);
1389 static mode_t udf_convert_permissions(struct fileEntry *fe)
1392 uint32_t permissions;
1395 permissions = le32_to_cpu(fe->permissions);
1396 flags = le16_to_cpu(fe->icbTag.flags);
1398 mode = ((permissions) & S_IRWXO) |
1399 ((permissions >> 2) & S_IRWXG) |
1400 ((permissions >> 4) & S_IRWXU) |
1401 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1402 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1403 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1412 * Write out the specified inode.
1415 * This routine is called whenever an inode is synced.
1416 * Currently this routine is just a placeholder.
1419 * July 1, 1997 - Andrew E. Mileski
1420 * Written, tested, and released.
1423 int udf_write_inode(struct inode *inode, int sync)
1428 ret = udf_update_inode(inode, sync);
1434 int udf_sync_inode(struct inode *inode)
1436 return udf_update_inode(inode, 1);
1439 static int udf_update_inode(struct inode *inode, int do_sync)
1441 struct buffer_head *bh = NULL;
1442 struct fileEntry *fe;
1443 struct extendedFileEntry *efe;
1447 kernel_timestamp cpu_time;
1449 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1450 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
1452 bh = udf_tread(inode->i_sb,
1453 udf_get_lb_pblock(inode->i_sb,
1454 UDF_I(inode)->i_location, 0));
1456 udf_debug("bread failure\n");
1460 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
1462 fe = (struct fileEntry *)bh->b_data;
1463 efe = (struct extendedFileEntry *)bh->b_data;
1465 if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
1466 struct unallocSpaceEntry *use =
1467 (struct unallocSpaceEntry *)bh->b_data;
1469 use->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
1470 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1471 UDF_I(inode)->i_ext.i_data, inode->i_sb->s_blocksize -
1472 sizeof(struct unallocSpaceEntry));
1473 crclen = sizeof(struct unallocSpaceEntry) +
1474 UDF_I(inode)->i_lenAlloc - sizeof(tag);
1475 use->descTag.tagLocation = cpu_to_le32(
1476 UDF_I(inode)->i_location.
1478 use->descTag.descCRCLength = cpu_to_le16(crclen);
1479 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
1480 sizeof(tag), crclen,
1482 use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
1484 mark_buffer_dirty(bh);
1489 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1490 fe->uid = cpu_to_le32(-1);
1492 fe->uid = cpu_to_le32(inode->i_uid);
1494 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1495 fe->gid = cpu_to_le32(-1);
1497 fe->gid = cpu_to_le32(inode->i_gid);
1499 udfperms = ((inode->i_mode & S_IRWXO)) |
1500 ((inode->i_mode & S_IRWXG) << 2) |
1501 ((inode->i_mode & S_IRWXU) << 4);
1503 udfperms |= (le32_to_cpu(fe->permissions) &
1504 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1505 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1506 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1507 fe->permissions = cpu_to_le32(udfperms);
1509 if (S_ISDIR(inode->i_mode))
1510 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1512 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1514 fe->informationLength = cpu_to_le64(inode->i_size);
1516 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1518 struct deviceSpec *dsea =
1519 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1521 dsea = (struct deviceSpec *)
1522 udf_add_extendedattr(inode,
1523 sizeof(struct deviceSpec) +
1524 sizeof(regid), 12, 0x3);
1525 dsea->attrType = cpu_to_le32(12);
1526 dsea->attrSubtype = 1;
1527 dsea->attrLength = cpu_to_le32(
1528 sizeof(struct deviceSpec) +
1530 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1532 eid = (regid *)dsea->impUse;
1533 memset(eid, 0, sizeof(regid));
1534 strcpy(eid->ident, UDF_ID_DEVELOPER);
1535 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
1536 eid->identSuffix[1] = UDF_OS_ID_LINUX;
1537 dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
1538 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1541 if (UDF_I(inode)->i_efe == 0) {
1542 memcpy(bh->b_data + sizeof(struct fileEntry),
1543 UDF_I(inode)->i_ext.i_data,
1544 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1545 fe->logicalBlocksRecorded = cpu_to_le64(
1546 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1547 (blocksize_bits - 9));
1549 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1550 fe->accessTime = cpu_to_lets(cpu_time);
1551 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1552 fe->modificationTime = cpu_to_lets(cpu_time);
1553 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1554 fe->attrTime = cpu_to_lets(cpu_time);
1555 memset(&(fe->impIdent), 0, sizeof(regid));
1556 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1557 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1558 fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1559 fe->uniqueID = cpu_to_le64(UDF_I(inode)->i_unique);
1560 fe->lengthExtendedAttr = cpu_to_le32(UDF_I(inode)->i_lenEAttr);
1561 fe->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
1562 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1563 crclen = sizeof(struct fileEntry);
1565 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1566 UDF_I(inode)->i_ext.i_data,
1567 inode->i_sb->s_blocksize -
1568 sizeof(struct extendedFileEntry));
1569 efe->objectSize = cpu_to_le64(inode->i_size);
1570 efe->logicalBlocksRecorded = cpu_to_le64(
1571 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1572 (blocksize_bits - 9));
1574 if (UDF_I(inode)->i_crtime.tv_sec > inode->i_atime.tv_sec ||
1575 (UDF_I(inode)->i_crtime.tv_sec == inode->i_atime.tv_sec &&
1576 UDF_I(inode)->i_crtime.tv_nsec > inode->i_atime.tv_nsec))
1577 UDF_I(inode)->i_crtime = inode->i_atime;
1579 if (UDF_I(inode)->i_crtime.tv_sec > inode->i_mtime.tv_sec ||
1580 (UDF_I(inode)->i_crtime.tv_sec == inode->i_mtime.tv_sec &&
1581 UDF_I(inode)->i_crtime.tv_nsec > inode->i_mtime.tv_nsec))
1582 UDF_I(inode)->i_crtime = inode->i_mtime;
1584 if (UDF_I(inode)->i_crtime.tv_sec > inode->i_ctime.tv_sec ||
1585 (UDF_I(inode)->i_crtime.tv_sec == inode->i_ctime.tv_sec &&
1586 UDF_I(inode)->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
1587 UDF_I(inode)->i_crtime = inode->i_ctime;
1589 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1590 efe->accessTime = cpu_to_lets(cpu_time);
1591 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1592 efe->modificationTime = cpu_to_lets(cpu_time);
1593 if (udf_time_to_stamp(&cpu_time, UDF_I(inode)->i_crtime))
1594 efe->createTime = cpu_to_lets(cpu_time);
1595 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1596 efe->attrTime = cpu_to_lets(cpu_time);
1598 memset(&(efe->impIdent), 0, sizeof(regid));
1599 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
1600 efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1601 efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1602 efe->uniqueID = cpu_to_le64(UDF_I(inode)->i_unique);
1603 efe->lengthExtendedAttr = cpu_to_le32(UDF_I(inode)->i_lenEAttr);
1604 efe->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
1605 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1606 crclen = sizeof(struct extendedFileEntry);
1608 if (UDF_I(inode)->i_strat4096) {
1609 fe->icbTag.strategyType = cpu_to_le16(4096);
1610 fe->icbTag.strategyParameter = cpu_to_le16(1);
1611 fe->icbTag.numEntries = cpu_to_le16(2);
1613 fe->icbTag.strategyType = cpu_to_le16(4);
1614 fe->icbTag.numEntries = cpu_to_le16(1);
1617 if (S_ISDIR(inode->i_mode))
1618 fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
1619 else if (S_ISREG(inode->i_mode))
1620 fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
1621 else if (S_ISLNK(inode->i_mode))
1622 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
1623 else if (S_ISBLK(inode->i_mode))
1624 fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
1625 else if (S_ISCHR(inode->i_mode))
1626 fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
1627 else if (S_ISFIFO(inode->i_mode))
1628 fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
1629 else if (S_ISSOCK(inode->i_mode))
1630 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1632 icbflags = UDF_I(inode)->i_alloc_type |
1633 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1634 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1635 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1636 (le16_to_cpu(fe->icbTag.flags) &
1637 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1638 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1640 fe->icbTag.flags = cpu_to_le16(icbflags);
1641 if (sbi->s_udfrev >= 0x0200)
1642 fe->descTag.descVersion = cpu_to_le16(3);
1644 fe->descTag.descVersion = cpu_to_le16(2);
1645 fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
1646 fe->descTag.tagLocation = cpu_to_le32(
1647 UDF_I(inode)->i_location.logicalBlockNum);
1648 crclen += UDF_I(inode)->i_lenEAttr + UDF_I(inode)->i_lenAlloc -
1650 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1651 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
1653 fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
1655 /* write the data blocks */
1656 mark_buffer_dirty(bh);
1658 sync_dirty_buffer(bh);
1659 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1660 printk(KERN_WARNING "IO error syncing udf inode "
1661 "[%s:%08lx]\n", inode->i_sb->s_id,
1671 struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1673 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1674 struct inode *inode = iget_locked(sb, block);
1679 if (inode->i_state & I_NEW) {
1680 memcpy(&UDF_I(inode)->i_location, &ino, sizeof(kernel_lb_addr));
1681 __udf_read_inode(inode);
1682 unlock_new_inode(inode);
1685 if (is_bad_inode(inode))
1688 if (ino.logicalBlockNum >= UDF_SB(sb)->
1689 s_partmaps[ino.partitionReferenceNum].s_partition_len) {
1690 udf_debug("block=%d, partition=%d out of range\n",
1691 ino.logicalBlockNum, ino.partitionReferenceNum);
1692 make_bad_inode(inode);
1703 int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1704 kernel_lb_addr eloc, uint32_t elen, int inc)
1707 short_ad *sad = NULL;
1708 long_ad *lad = NULL;
1709 struct allocExtDesc *aed;
1714 ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
1715 udf_file_entry_alloc_offset(inode) +
1716 UDF_I(inode)->i_lenEAttr;
1718 ptr = epos->bh->b_data + epos->offset;
1720 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
1721 adsize = sizeof(short_ad);
1722 else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
1723 adsize = sizeof(long_ad);
1727 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1729 struct buffer_head *nbh;
1731 kernel_lb_addr obloc = epos->block;
1733 epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
1734 obloc.partitionReferenceNum,
1735 obloc.logicalBlockNum, &err);
1736 if (!epos->block.logicalBlockNum)
1738 nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1744 memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
1745 set_buffer_uptodate(nbh);
1747 mark_buffer_dirty_inode(nbh, inode);
1749 aed = (struct allocExtDesc *)(nbh->b_data);
1750 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1751 aed->previousAllocExtLocation =
1752 cpu_to_le32(obloc.logicalBlockNum);
1753 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1754 loffset = epos->offset;
1755 aed->lengthAllocDescs = cpu_to_le32(adsize);
1756 sptr = ptr - adsize;
1757 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1758 memcpy(dptr, sptr, adsize);
1759 epos->offset = sizeof(struct allocExtDesc) + adsize;
1761 loffset = epos->offset + adsize;
1762 aed->lengthAllocDescs = cpu_to_le32(0);
1764 epos->offset = sizeof(struct allocExtDesc);
1767 aed = (struct allocExtDesc *)epos->bh->b_data;
1768 aed->lengthAllocDescs =
1769 cpu_to_le32(le32_to_cpu(
1770 aed->lengthAllocDescs) + adsize);
1772 UDF_I(inode)->i_lenAlloc += adsize;
1773 mark_inode_dirty(inode);
1776 if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
1777 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1778 epos->block.logicalBlockNum, sizeof(tag));
1780 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1781 epos->block.logicalBlockNum, sizeof(tag));
1782 switch (UDF_I(inode)->i_alloc_type) {
1783 case ICBTAG_FLAG_AD_SHORT:
1784 sad = (short_ad *)sptr;
1785 sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1786 inode->i_sb->s_blocksize);
1788 cpu_to_le32(epos->block.logicalBlockNum);
1790 case ICBTAG_FLAG_AD_LONG:
1791 lad = (long_ad *)sptr;
1792 lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1793 inode->i_sb->s_blocksize);
1794 lad->extLocation = cpu_to_lelb(epos->block);
1795 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1799 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1800 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1801 udf_update_tag(epos->bh->b_data, loffset);
1803 udf_update_tag(epos->bh->b_data,
1804 sizeof(struct allocExtDesc));
1805 mark_buffer_dirty_inode(epos->bh, inode);
1808 mark_inode_dirty(inode);
1813 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1816 UDF_I(inode)->i_lenAlloc += adsize;
1817 mark_inode_dirty(inode);
1819 aed = (struct allocExtDesc *)epos->bh->b_data;
1820 aed->lengthAllocDescs =
1821 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
1823 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1824 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1825 udf_update_tag(epos->bh->b_data,
1826 epos->offset + (inc ? 0 : adsize));
1828 udf_update_tag(epos->bh->b_data,
1829 sizeof(struct allocExtDesc));
1830 mark_buffer_dirty_inode(epos->bh, inode);
1836 int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
1837 kernel_lb_addr eloc, uint32_t elen, int inc)
1845 ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
1846 udf_file_entry_alloc_offset(inode) +
1847 UDF_I(inode)->i_lenEAttr;
1849 ptr = epos->bh->b_data + epos->offset;
1851 switch (UDF_I(inode)->i_alloc_type) {
1852 case ICBTAG_FLAG_AD_SHORT:
1853 sad = (short_ad *)ptr;
1854 sad->extLength = cpu_to_le32(elen);
1855 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1856 adsize = sizeof(short_ad);
1858 case ICBTAG_FLAG_AD_LONG:
1859 lad = (long_ad *)ptr;
1860 lad->extLength = cpu_to_le32(elen);
1861 lad->extLocation = cpu_to_lelb(eloc);
1862 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1863 adsize = sizeof(long_ad);
1870 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1871 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
1872 struct allocExtDesc *aed =
1873 (struct allocExtDesc *)epos->bh->b_data;
1874 udf_update_tag(epos->bh->b_data,
1875 le32_to_cpu(aed->lengthAllocDescs) +
1876 sizeof(struct allocExtDesc));
1878 mark_buffer_dirty_inode(epos->bh, inode);
1880 mark_inode_dirty(inode);
1884 epos->offset += adsize;
1886 return (elen >> 30);
1889 int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1890 kernel_lb_addr *eloc, uint32_t *elen, int inc)
1894 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1895 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1897 epos->block = *eloc;
1898 epos->offset = sizeof(struct allocExtDesc);
1900 block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
1901 epos->bh = udf_tread(inode->i_sb, block);
1903 udf_debug("reading block %d failed!\n", block);
1911 int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
1912 kernel_lb_addr *eloc, uint32_t *elen, int inc)
1922 epos->offset = udf_file_entry_alloc_offset(inode);
1923 ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
1924 udf_file_entry_alloc_offset(inode) +
1925 UDF_I(inode)->i_lenEAttr;
1926 alen = udf_file_entry_alloc_offset(inode) +
1927 UDF_I(inode)->i_lenAlloc;
1930 epos->offset = sizeof(struct allocExtDesc);
1931 ptr = epos->bh->b_data + epos->offset;
1932 alen = sizeof(struct allocExtDesc) +
1933 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1937 switch (UDF_I(inode)->i_alloc_type) {
1938 case ICBTAG_FLAG_AD_SHORT:
1939 sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
1942 etype = le32_to_cpu(sad->extLength) >> 30;
1943 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1944 eloc->partitionReferenceNum =
1945 UDF_I(inode)->i_location.partitionReferenceNum;
1946 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1948 case ICBTAG_FLAG_AD_LONG:
1949 lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
1952 etype = le32_to_cpu(lad->extLength) >> 30;
1953 *eloc = lelb_to_cpu(lad->extLocation);
1954 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1957 udf_debug("alloc_type = %d unsupported\n",
1958 UDF_I(inode)->i_alloc_type);
1965 static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
1966 kernel_lb_addr neloc, uint32_t nelen)
1968 kernel_lb_addr oeloc;
1975 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
1976 udf_write_aext(inode, &epos, neloc, nelen, 1);
1978 nelen = (etype << 30) | oelen;
1980 udf_add_aext(inode, &epos, neloc, nelen, 1);
1983 return (nelen >> 30);
1986 int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
1987 kernel_lb_addr eloc, uint32_t elen)
1989 struct extent_position oepos;
1992 struct allocExtDesc *aed;
1999 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
2000 adsize = sizeof(short_ad);
2001 else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
2002 adsize = sizeof(long_ad);
2007 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2010 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2011 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2012 if (oepos.bh != epos.bh) {
2013 oepos.block = epos.block;
2017 oepos.offset = epos.offset - adsize;
2020 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2023 if (epos.bh != oepos.bh) {
2024 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2025 udf_write_aext(inode, &oepos, eloc, elen, 1);
2026 udf_write_aext(inode, &oepos, eloc, elen, 1);
2028 UDF_I(inode)->i_lenAlloc -= (adsize * 2);
2029 mark_inode_dirty(inode);
2031 aed = (struct allocExtDesc *)oepos.bh->b_data;
2032 aed->lengthAllocDescs =
2033 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2035 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2036 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2037 udf_update_tag(oepos.bh->b_data,
2038 oepos.offset - (2 * adsize));
2040 udf_update_tag(oepos.bh->b_data,
2041 sizeof(struct allocExtDesc));
2042 mark_buffer_dirty_inode(oepos.bh, inode);
2045 udf_write_aext(inode, &oepos, eloc, elen, 1);
2047 UDF_I(inode)->i_lenAlloc -= adsize;
2048 mark_inode_dirty(inode);
2050 aed = (struct allocExtDesc *)oepos.bh->b_data;
2051 aed->lengthAllocDescs =
2052 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2054 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2055 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2056 udf_update_tag(oepos.bh->b_data,
2057 epos.offset - adsize);
2059 udf_update_tag(oepos.bh->b_data,
2060 sizeof(struct allocExtDesc));
2061 mark_buffer_dirty_inode(oepos.bh, inode);
2068 return (elen >> 30);
2071 int8_t inode_bmap(struct inode *inode, sector_t block,
2072 struct extent_position *pos, kernel_lb_addr *eloc,
2073 uint32_t *elen, sector_t *offset)
2075 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
2076 loff_t lbcount = 0, bcount =
2077 (loff_t) block << blocksize_bits;
2081 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2086 pos->block = UDF_I(inode)->i_location;
2091 etype = udf_next_aext(inode, pos, eloc, elen, 1);
2093 *offset = (bcount - lbcount) >> blocksize_bits;
2094 UDF_I(inode)->i_lenExtents = lbcount;
2098 } while (lbcount <= bcount);
2100 *offset = (bcount + *elen - lbcount) >> blocksize_bits;
2105 long udf_block_map(struct inode *inode, sector_t block)
2107 kernel_lb_addr eloc;
2110 struct extent_position epos = {};
2115 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2116 (EXT_RECORDED_ALLOCATED >> 30))
2117 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2124 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
2125 return udf_fixed_to_variable(ret);