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_DATA(inode));
124 UDF_I_DATA(inode) = 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_LENALLOC(inode)) {
173 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
174 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
176 UDF_I_ALLOCTYPE(inode) = 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_LENALLOC(inode), 0x00,
187 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
188 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
189 UDF_I_LENALLOC(inode));
190 flush_dcache_page(page);
191 SetPageUptodate(page);
194 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
195 UDF_I_LENALLOC(inode));
196 UDF_I_LENALLOC(inode) = 0;
197 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
198 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
200 UDF_I_ALLOCTYPE(inode) = 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_ALLOCTYPE(inode) = 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_LOCATION(inode).partitionReferenceNum,
237 UDF_I_LOCATION(inode).logicalBlockNum, err);
240 newblock = udf_get_pblock(inode->i_sb, *block,
241 UDF_I_LOCATION(inode).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_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
261 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
267 UDF_I_ALLOCTYPE(inode) = 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_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
280 mark_buffer_dirty_inode(dbh, inode);
282 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0,
283 UDF_I_LENALLOC(inode));
284 UDF_I_LENALLOC(inode) = 0;
285 eloc.logicalBlockNum = *block;
286 eloc.partitionReferenceNum =
287 UDF_I_LOCATION(inode).partitionReferenceNum;
288 elen = inode->i_size;
289 UDF_I_LENEXTENTS(inode) = elen;
291 epos.block = UDF_I_LOCATION(inode);
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_NEXT_ALLOC_BLOCK(inode) + 1) {
325 UDF_I_NEXT_ALLOC_BLOCK(inode)++;
326 UDF_I_NEXT_ALLOC_GOAL(inode)++;
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_LENEXTENTS(inode) =
396 (UDF_I_LENEXTENTS(inode) + 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_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
474 last_pos->offset -= sizeof(short_ad);
475 else if (UDF_I_ALLOCTYPE(inode) == 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_LOCATION(inode).logicalBlockNum;
501 prev_epos.offset = udf_file_entry_alloc_offset(inode);
502 prev_epos.block = UDF_I_LOCATION(inode);
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_NEXT_ALLOC_BLOCK(inode) == block)
653 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
656 if (!(goal = pgoal)) /* XXX: what was intended here? */
657 goal = UDF_I_LOCATION(inode).logicalBlockNum+1;
660 newblocknum = udf_new_block(inode->i_sb, inode,
661 UDF_I_LOCATION(inode).partitionReferenceNum,
664 brelse(prev_epos.bh);
668 UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
671 /* if the extent the requsted block is located in contains multiple
672 * blocks, split the extent into at most three extents. blocks prior
673 * to requested block, requested block, and blocks after requested
675 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
677 #ifdef UDF_PREALLOCATE
678 /* preallocate blocks */
679 udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
682 /* merge any continuous blocks in laarr */
683 udf_merge_extents(inode, laarr, &endnum);
685 /* write back the new extents, inserting new extents if the new number
686 * of extents is greater than the old number, and deleting extents if
687 * the new number of extents is less than the old number */
688 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
690 brelse(prev_epos.bh);
692 newblock = udf_get_pblock(inode->i_sb, newblocknum,
693 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
699 UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
700 UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
701 inode->i_ctime = current_fs_time(inode->i_sb);
704 udf_sync_inode(inode);
706 mark_inode_dirty(inode);
711 static void udf_split_extents(struct inode *inode, int *c, int offset,
713 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
716 unsigned long blocksize = inode->i_sb->s_blocksize;
717 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
719 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
720 (laarr[*c].extLength >> 30) ==
721 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
723 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
724 blocksize - 1) >> blocksize_bits;
725 int8_t etype = (laarr[curr].extLength >> 30);
729 else if (!offset || blen == offset + 1) {
730 laarr[curr + 2] = laarr[curr + 1];
731 laarr[curr + 1] = laarr[curr];
733 laarr[curr + 3] = laarr[curr + 1];
734 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
738 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
739 udf_free_blocks(inode->i_sb, inode,
740 laarr[curr].extLocation,
742 laarr[curr].extLength =
743 EXT_NOT_RECORDED_NOT_ALLOCATED |
744 (offset << blocksize_bits);
745 laarr[curr].extLocation.logicalBlockNum = 0;
746 laarr[curr].extLocation.
747 partitionReferenceNum = 0;
749 laarr[curr].extLength = (etype << 30) |
750 (offset << blocksize_bits);
756 laarr[curr].extLocation.logicalBlockNum = newblocknum;
757 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
758 laarr[curr].extLocation.partitionReferenceNum =
759 UDF_I_LOCATION(inode).partitionReferenceNum;
760 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
764 if (blen != offset + 1) {
765 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
766 laarr[curr].extLocation.logicalBlockNum +=
768 laarr[curr].extLength = (etype << 30) |
769 ((blen - (offset + 1)) << blocksize_bits);
776 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
777 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
780 int start, length = 0, currlength = 0, i;
782 if (*endnum >= (c + 1)) {
788 if ((laarr[c + 1].extLength >> 30) ==
789 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
791 length = currlength =
792 (((laarr[c + 1].extLength &
793 UDF_EXTENT_LENGTH_MASK) +
794 inode->i_sb->s_blocksize - 1) >>
795 inode->i_sb->s_blocksize_bits);
800 for (i = start + 1; i <= *endnum; i++) {
803 length += UDF_DEFAULT_PREALLOC_BLOCKS;
804 } else if ((laarr[i].extLength >> 30) ==
805 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
806 length += (((laarr[i].extLength &
807 UDF_EXTENT_LENGTH_MASK) +
808 inode->i_sb->s_blocksize - 1) >>
809 inode->i_sb->s_blocksize_bits);
815 int next = laarr[start].extLocation.logicalBlockNum +
816 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
817 inode->i_sb->s_blocksize - 1) >>
818 inode->i_sb->s_blocksize_bits);
819 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
820 laarr[start].extLocation.partitionReferenceNum,
821 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
822 length : UDF_DEFAULT_PREALLOC_BLOCKS) -
825 if (start == (c + 1))
826 laarr[start].extLength +=
828 inode->i_sb->s_blocksize_bits);
830 memmove(&laarr[c + 2], &laarr[c + 1],
831 sizeof(long_ad) * (*endnum - (c + 1)));
833 laarr[c + 1].extLocation.logicalBlockNum = next;
834 laarr[c + 1].extLocation.partitionReferenceNum =
835 laarr[c].extLocation.
836 partitionReferenceNum;
837 laarr[c + 1].extLength =
838 EXT_NOT_RECORDED_ALLOCATED |
840 inode->i_sb->s_blocksize_bits);
844 for (i = start + 1; numalloc && i < *endnum; i++) {
845 int elen = ((laarr[i].extLength &
846 UDF_EXTENT_LENGTH_MASK) +
847 inode->i_sb->s_blocksize - 1) >>
848 inode->i_sb->s_blocksize_bits;
850 if (elen > numalloc) {
851 laarr[i].extLength -=
853 inode->i_sb->s_blocksize_bits);
857 if (*endnum > (i + 1))
861 (*endnum - (i + 1)));
866 UDF_I_LENEXTENTS(inode) +=
867 numalloc << inode->i_sb->s_blocksize_bits;
872 static void udf_merge_extents(struct inode *inode,
873 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
877 unsigned long blocksize = inode->i_sb->s_blocksize;
878 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
880 for (i = 0; i < (*endnum - 1); i++) {
881 kernel_long_ad *li /*l[i]*/ = &laarr[i];
882 kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
884 if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
885 (((li->extLength >> 30) ==
886 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
887 ((lip1->extLocation.logicalBlockNum -
888 li->extLocation.logicalBlockNum) ==
889 (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
890 blocksize - 1) >> blocksize_bits)))) {
892 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
893 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
894 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
895 lip1->extLength = (lip1->extLength -
897 UDF_EXTENT_LENGTH_MASK) +
898 UDF_EXTENT_LENGTH_MASK) &
900 li->extLength = (li->extLength &
901 UDF_EXTENT_FLAG_MASK) +
902 (UDF_EXTENT_LENGTH_MASK + 1) -
904 lip1->extLocation.logicalBlockNum =
905 li->extLocation.logicalBlockNum +
907 UDF_EXTENT_LENGTH_MASK) >>
910 li->extLength = lip1->extLength +
912 UDF_EXTENT_LENGTH_MASK) +
913 blocksize - 1) & ~(blocksize - 1));
914 if (*endnum > (i + 2))
915 memmove(&laarr[i + 1], &laarr[i + 2],
917 (*endnum - (i + 2)));
921 } else if (((li->extLength >> 30) ==
922 (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
923 ((lip1->extLength >> 30) ==
924 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
925 udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
927 UDF_EXTENT_LENGTH_MASK) +
928 blocksize - 1) >> blocksize_bits);
929 li->extLocation.logicalBlockNum = 0;
930 li->extLocation.partitionReferenceNum = 0;
932 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
933 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
934 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
935 lip1->extLength = (lip1->extLength -
937 UDF_EXTENT_LENGTH_MASK) +
938 UDF_EXTENT_LENGTH_MASK) &
940 li->extLength = (li->extLength &
941 UDF_EXTENT_FLAG_MASK) +
942 (UDF_EXTENT_LENGTH_MASK + 1) -
945 li->extLength = lip1->extLength +
947 UDF_EXTENT_LENGTH_MASK) +
948 blocksize - 1) & ~(blocksize - 1));
949 if (*endnum > (i + 2))
950 memmove(&laarr[i + 1], &laarr[i + 2],
952 (*endnum - (i + 2)));
956 } else if ((li->extLength >> 30) ==
957 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
958 udf_free_blocks(inode->i_sb, inode,
961 UDF_EXTENT_LENGTH_MASK) +
962 blocksize - 1) >> blocksize_bits);
963 li->extLocation.logicalBlockNum = 0;
964 li->extLocation.partitionReferenceNum = 0;
965 li->extLength = (li->extLength &
966 UDF_EXTENT_LENGTH_MASK) |
967 EXT_NOT_RECORDED_NOT_ALLOCATED;
972 static void udf_update_extents(struct inode *inode,
973 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
974 int startnum, int endnum,
975 struct extent_position *epos)
978 kernel_lb_addr tmploc;
981 if (startnum > endnum) {
982 for (i = 0; i < (startnum - endnum); i++)
983 udf_delete_aext(inode, *epos, laarr[i].extLocation,
985 } else if (startnum < endnum) {
986 for (i = 0; i < (endnum - startnum); i++) {
987 udf_insert_aext(inode, *epos, laarr[i].extLocation,
989 udf_next_aext(inode, epos, &laarr[i].extLocation,
990 &laarr[i].extLength, 1);
995 for (i = start; i < endnum; i++) {
996 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
997 udf_write_aext(inode, epos, laarr[i].extLocation,
998 laarr[i].extLength, 1);
1002 struct buffer_head *udf_bread(struct inode *inode, int block,
1003 int create, int *err)
1005 struct buffer_head *bh = NULL;
1007 bh = udf_getblk(inode, block, create, err);
1011 if (buffer_uptodate(bh))
1014 ll_rw_block(READ, 1, &bh);
1017 if (buffer_uptodate(bh))
1025 void udf_truncate(struct inode *inode)
1030 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1031 S_ISLNK(inode->i_mode)))
1033 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1037 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1038 if (inode->i_sb->s_blocksize <
1039 (udf_file_entry_alloc_offset(inode) +
1041 udf_expand_file_adinicb(inode, inode->i_size, &err);
1042 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1043 inode->i_size = UDF_I_LENALLOC(inode);
1047 udf_truncate_extents(inode);
1049 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1050 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) +
1051 offset, 0x00, inode->i_sb->s_blocksize -
1052 offset - udf_file_entry_alloc_offset(inode));
1053 UDF_I_LENALLOC(inode) = inode->i_size;
1056 block_truncate_page(inode->i_mapping, inode->i_size,
1058 udf_truncate_extents(inode);
1061 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1063 udf_sync_inode(inode);
1065 mark_inode_dirty(inode);
1069 static void __udf_read_inode(struct inode *inode)
1071 struct buffer_head *bh = NULL;
1072 struct fileEntry *fe;
1076 * Set defaults, but the inode is still incomplete!
1077 * Note: get_new_inode() sets the following on a new inode:
1080 * i_flags = sb->s_flags
1082 * clean_inode(): zero fills and sets
1087 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1089 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1091 make_bad_inode(inode);
1095 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1096 ident != TAG_IDENT_USE) {
1097 printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
1098 "failed ident=%d\n", inode->i_ino, ident);
1100 make_bad_inode(inode);
1104 fe = (struct fileEntry *)bh->b_data;
1106 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
1107 struct buffer_head *ibh = NULL, *nbh = NULL;
1108 struct indirectEntry *ie;
1110 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
1112 if (ident == TAG_IDENT_IE) {
1115 ie = (struct indirectEntry *)ibh->b_data;
1117 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1119 if (ie->indirectICB.extLength &&
1120 (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
1122 if (ident == TAG_IDENT_FE ||
1123 ident == TAG_IDENT_EFE) {
1124 memcpy(&UDF_I_LOCATION(inode),
1126 sizeof(kernel_lb_addr));
1130 __udf_read_inode(inode);
1143 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1144 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1145 le16_to_cpu(fe->icbTag.strategyType));
1147 make_bad_inode(inode);
1150 udf_fill_inode(inode, bh);
1155 static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1157 struct fileEntry *fe;
1158 struct extendedFileEntry *efe;
1162 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1164 fe = (struct fileEntry *)bh->b_data;
1165 efe = (struct extendedFileEntry *)bh->b_data;
1167 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
1168 UDF_I_STRAT4096(inode) = 0;
1169 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
1170 UDF_I_STRAT4096(inode) = 1;
1172 UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) &
1173 ICBTAG_FLAG_AD_MASK;
1174 UDF_I_UNIQUE(inode) = 0;
1175 UDF_I_LENEATTR(inode) = 0;
1176 UDF_I_LENEXTENTS(inode) = 0;
1177 UDF_I_LENALLOC(inode) = 0;
1178 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
1179 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
1180 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1181 UDF_I_EFE(inode) = 1;
1182 UDF_I_USE(inode) = 0;
1183 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1184 sizeof(struct extendedFileEntry))) {
1185 make_bad_inode(inode);
1188 memcpy(UDF_I_DATA(inode),
1189 bh->b_data + sizeof(struct extendedFileEntry),
1190 inode->i_sb->s_blocksize -
1191 sizeof(struct extendedFileEntry));
1192 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1193 UDF_I_EFE(inode) = 0;
1194 UDF_I_USE(inode) = 0;
1195 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1196 sizeof(struct fileEntry))) {
1197 make_bad_inode(inode);
1200 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
1201 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1202 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1203 UDF_I_EFE(inode) = 0;
1204 UDF_I_USE(inode) = 1;
1205 UDF_I_LENALLOC(inode) = le32_to_cpu(
1206 ((struct unallocSpaceEntry *)bh->b_data)->
1208 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1209 sizeof(struct unallocSpaceEntry))) {
1210 make_bad_inode(inode);
1213 memcpy(UDF_I_DATA(inode),
1214 bh->b_data + sizeof(struct unallocSpaceEntry),
1215 inode->i_sb->s_blocksize -
1216 sizeof(struct unallocSpaceEntry));
1220 inode->i_uid = le32_to_cpu(fe->uid);
1221 if (inode->i_uid == -1 ||
1222 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
1223 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
1224 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1226 inode->i_gid = le32_to_cpu(fe->gid);
1227 if (inode->i_gid == -1 ||
1228 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
1229 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
1230 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1232 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1233 if (!inode->i_nlink)
1236 inode->i_size = le64_to_cpu(fe->informationLength);
1237 UDF_I_LENEXTENTS(inode) = inode->i_size;
1239 inode->i_mode = udf_convert_permissions(fe);
1240 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1242 if (UDF_I_EFE(inode) == 0) {
1243 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1244 (inode->i_sb->s_blocksize_bits - 9);
1246 if (udf_stamp_to_time(&convtime, &convtime_usec,
1247 lets_to_cpu(fe->accessTime))) {
1248 inode->i_atime.tv_sec = convtime;
1249 inode->i_atime.tv_nsec = convtime_usec * 1000;
1251 inode->i_atime = sbi->s_record_time;
1254 if (udf_stamp_to_time(&convtime, &convtime_usec,
1255 lets_to_cpu(fe->modificationTime))) {
1256 inode->i_mtime.tv_sec = convtime;
1257 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1259 inode->i_mtime = sbi->s_record_time;
1262 if (udf_stamp_to_time(&convtime, &convtime_usec,
1263 lets_to_cpu(fe->attrTime))) {
1264 inode->i_ctime.tv_sec = convtime;
1265 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1267 inode->i_ctime = sbi->s_record_time;
1270 UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
1271 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1272 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1273 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
1275 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1276 (inode->i_sb->s_blocksize_bits - 9);
1278 if (udf_stamp_to_time(&convtime, &convtime_usec,
1279 lets_to_cpu(efe->accessTime))) {
1280 inode->i_atime.tv_sec = convtime;
1281 inode->i_atime.tv_nsec = convtime_usec * 1000;
1283 inode->i_atime = sbi->s_record_time;
1286 if (udf_stamp_to_time(&convtime, &convtime_usec,
1287 lets_to_cpu(efe->modificationTime))) {
1288 inode->i_mtime.tv_sec = convtime;
1289 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1291 inode->i_mtime = sbi->s_record_time;
1294 if (udf_stamp_to_time(&convtime, &convtime_usec,
1295 lets_to_cpu(efe->createTime))) {
1296 UDF_I_CRTIME(inode).tv_sec = convtime;
1297 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
1299 UDF_I_CRTIME(inode) = sbi->s_record_time;
1302 if (udf_stamp_to_time(&convtime, &convtime_usec,
1303 lets_to_cpu(efe->attrTime))) {
1304 inode->i_ctime.tv_sec = convtime;
1305 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1307 inode->i_ctime = sbi->s_record_time;
1310 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1311 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1312 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1313 offset = sizeof(struct extendedFileEntry) +
1314 UDF_I_LENEATTR(inode);
1317 switch (fe->icbTag.fileType) {
1318 case ICBTAG_FILE_TYPE_DIRECTORY:
1319 inode->i_op = &udf_dir_inode_operations;
1320 inode->i_fop = &udf_dir_operations;
1321 inode->i_mode |= S_IFDIR;
1324 case ICBTAG_FILE_TYPE_REALTIME:
1325 case ICBTAG_FILE_TYPE_REGULAR:
1326 case ICBTAG_FILE_TYPE_UNDEF:
1327 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1328 inode->i_data.a_ops = &udf_adinicb_aops;
1330 inode->i_data.a_ops = &udf_aops;
1331 inode->i_op = &udf_file_inode_operations;
1332 inode->i_fop = &udf_file_operations;
1333 inode->i_mode |= S_IFREG;
1335 case ICBTAG_FILE_TYPE_BLOCK:
1336 inode->i_mode |= S_IFBLK;
1338 case ICBTAG_FILE_TYPE_CHAR:
1339 inode->i_mode |= S_IFCHR;
1341 case ICBTAG_FILE_TYPE_FIFO:
1342 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1344 case ICBTAG_FILE_TYPE_SOCKET:
1345 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1347 case ICBTAG_FILE_TYPE_SYMLINK:
1348 inode->i_data.a_ops = &udf_symlink_aops;
1349 inode->i_op = &page_symlink_inode_operations;
1350 inode->i_mode = S_IFLNK | S_IRWXUGO;
1353 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
1354 "file type=%d\n", inode->i_ino,
1355 fe->icbTag.fileType);
1356 make_bad_inode(inode);
1359 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1360 struct deviceSpec *dsea =
1361 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1363 init_special_inode(inode, inode->i_mode,
1364 MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
1365 le32_to_cpu(dsea->minorDeviceIdent)));
1366 /* Developer ID ??? */
1368 make_bad_inode(inode);
1372 static int udf_alloc_i_data(struct inode *inode, size_t size)
1374 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1376 if (!UDF_I_DATA(inode)) {
1377 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
1378 "no free memory\n", inode->i_ino);
1385 static mode_t udf_convert_permissions(struct fileEntry *fe)
1388 uint32_t permissions;
1391 permissions = le32_to_cpu(fe->permissions);
1392 flags = le16_to_cpu(fe->icbTag.flags);
1394 mode = ((permissions) & S_IRWXO) |
1395 ((permissions >> 2) & S_IRWXG) |
1396 ((permissions >> 4) & S_IRWXU) |
1397 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1398 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1399 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1408 * Write out the specified inode.
1411 * This routine is called whenever an inode is synced.
1412 * Currently this routine is just a placeholder.
1415 * July 1, 1997 - Andrew E. Mileski
1416 * Written, tested, and released.
1419 int udf_write_inode(struct inode *inode, int sync)
1424 ret = udf_update_inode(inode, sync);
1430 int udf_sync_inode(struct inode *inode)
1432 return udf_update_inode(inode, 1);
1435 static int udf_update_inode(struct inode *inode, int do_sync)
1437 struct buffer_head *bh = NULL;
1438 struct fileEntry *fe;
1439 struct extendedFileEntry *efe;
1443 kernel_timestamp cpu_time;
1445 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1446 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
1448 bh = udf_tread(inode->i_sb,
1449 udf_get_lb_pblock(inode->i_sb,
1450 UDF_I_LOCATION(inode), 0));
1452 udf_debug("bread failure\n");
1456 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
1458 fe = (struct fileEntry *)bh->b_data;
1459 efe = (struct extendedFileEntry *)bh->b_data;
1461 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1462 struct unallocSpaceEntry *use =
1463 (struct unallocSpaceEntry *)bh->b_data;
1465 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1466 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1467 UDF_I_DATA(inode), inode->i_sb->s_blocksize -
1468 sizeof(struct unallocSpaceEntry));
1469 crclen = sizeof(struct unallocSpaceEntry) +
1470 UDF_I_LENALLOC(inode) - sizeof(tag);
1471 use->descTag.tagLocation = cpu_to_le32(
1472 UDF_I_LOCATION(inode).
1474 use->descTag.descCRCLength = cpu_to_le16(crclen);
1475 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
1476 sizeof(tag), crclen,
1478 use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
1480 mark_buffer_dirty(bh);
1485 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1486 fe->uid = cpu_to_le32(-1);
1488 fe->uid = cpu_to_le32(inode->i_uid);
1490 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1491 fe->gid = cpu_to_le32(-1);
1493 fe->gid = cpu_to_le32(inode->i_gid);
1495 udfperms = ((inode->i_mode & S_IRWXO)) |
1496 ((inode->i_mode & S_IRWXG) << 2) |
1497 ((inode->i_mode & S_IRWXU) << 4);
1499 udfperms |= (le32_to_cpu(fe->permissions) &
1500 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1501 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1502 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1503 fe->permissions = cpu_to_le32(udfperms);
1505 if (S_ISDIR(inode->i_mode))
1506 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1508 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1510 fe->informationLength = cpu_to_le64(inode->i_size);
1512 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1514 struct deviceSpec *dsea =
1515 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1517 dsea = (struct deviceSpec *)
1518 udf_add_extendedattr(inode,
1519 sizeof(struct deviceSpec) +
1520 sizeof(regid), 12, 0x3);
1521 dsea->attrType = cpu_to_le32(12);
1522 dsea->attrSubtype = 1;
1523 dsea->attrLength = cpu_to_le32(
1524 sizeof(struct deviceSpec) +
1526 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1528 eid = (regid *)dsea->impUse;
1529 memset(eid, 0, sizeof(regid));
1530 strcpy(eid->ident, UDF_ID_DEVELOPER);
1531 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
1532 eid->identSuffix[1] = UDF_OS_ID_LINUX;
1533 dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
1534 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1537 if (UDF_I_EFE(inode) == 0) {
1538 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1539 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1540 fe->logicalBlocksRecorded = cpu_to_le64(
1541 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1542 (blocksize_bits - 9));
1544 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1545 fe->accessTime = cpu_to_lets(cpu_time);
1546 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1547 fe->modificationTime = cpu_to_lets(cpu_time);
1548 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1549 fe->attrTime = cpu_to_lets(cpu_time);
1550 memset(&(fe->impIdent), 0, sizeof(regid));
1551 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1552 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1553 fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1554 fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1555 fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1556 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1557 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1558 crclen = sizeof(struct fileEntry);
1560 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1562 inode->i_sb->s_blocksize -
1563 sizeof(struct extendedFileEntry));
1564 efe->objectSize = cpu_to_le64(inode->i_size);
1565 efe->logicalBlocksRecorded = cpu_to_le64(
1566 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1567 (blocksize_bits - 9));
1569 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1570 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
1571 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec))
1572 UDF_I_CRTIME(inode) = inode->i_atime;
1574 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
1575 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
1576 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec))
1577 UDF_I_CRTIME(inode) = inode->i_mtime;
1579 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
1580 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
1581 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec))
1582 UDF_I_CRTIME(inode) = inode->i_ctime;
1584 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1585 efe->accessTime = cpu_to_lets(cpu_time);
1586 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1587 efe->modificationTime = cpu_to_lets(cpu_time);
1588 if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode)))
1589 efe->createTime = cpu_to_lets(cpu_time);
1590 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1591 efe->attrTime = cpu_to_lets(cpu_time);
1593 memset(&(efe->impIdent), 0, sizeof(regid));
1594 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
1595 efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1596 efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1597 efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1598 efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1599 efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1600 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1601 crclen = sizeof(struct extendedFileEntry);
1603 if (UDF_I_STRAT4096(inode)) {
1604 fe->icbTag.strategyType = cpu_to_le16(4096);
1605 fe->icbTag.strategyParameter = cpu_to_le16(1);
1606 fe->icbTag.numEntries = cpu_to_le16(2);
1608 fe->icbTag.strategyType = cpu_to_le16(4);
1609 fe->icbTag.numEntries = cpu_to_le16(1);
1612 if (S_ISDIR(inode->i_mode))
1613 fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
1614 else if (S_ISREG(inode->i_mode))
1615 fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
1616 else if (S_ISLNK(inode->i_mode))
1617 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
1618 else if (S_ISBLK(inode->i_mode))
1619 fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
1620 else if (S_ISCHR(inode->i_mode))
1621 fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
1622 else if (S_ISFIFO(inode->i_mode))
1623 fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
1624 else if (S_ISSOCK(inode->i_mode))
1625 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1627 icbflags = UDF_I_ALLOCTYPE(inode) |
1628 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1629 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1630 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1631 (le16_to_cpu(fe->icbTag.flags) &
1632 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1633 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1635 fe->icbTag.flags = cpu_to_le16(icbflags);
1636 if (sbi->s_udfrev >= 0x0200)
1637 fe->descTag.descVersion = cpu_to_le16(3);
1639 fe->descTag.descVersion = cpu_to_le16(2);
1640 fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
1641 fe->descTag.tagLocation = cpu_to_le32(
1642 UDF_I_LOCATION(inode).logicalBlockNum);
1643 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1644 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1645 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
1647 fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
1649 /* write the data blocks */
1650 mark_buffer_dirty(bh);
1652 sync_dirty_buffer(bh);
1653 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1654 printk(KERN_WARNING "IO error syncing udf inode "
1655 "[%s:%08lx]\n", inode->i_sb->s_id,
1665 struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1667 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1668 struct inode *inode = iget_locked(sb, block);
1673 if (inode->i_state & I_NEW) {
1674 memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr));
1675 __udf_read_inode(inode);
1676 unlock_new_inode(inode);
1679 if (is_bad_inode(inode))
1682 if (ino.logicalBlockNum >= UDF_SB(sb)->
1683 s_partmaps[ino.partitionReferenceNum].s_partition_len) {
1684 udf_debug("block=%d, partition=%d out of range\n",
1685 ino.logicalBlockNum, ino.partitionReferenceNum);
1686 make_bad_inode(inode);
1697 int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1698 kernel_lb_addr eloc, uint32_t elen, int inc)
1701 short_ad *sad = NULL;
1702 long_ad *lad = NULL;
1703 struct allocExtDesc *aed;
1708 ptr = UDF_I_DATA(inode) + epos->offset -
1709 udf_file_entry_alloc_offset(inode) +
1710 UDF_I_LENEATTR(inode);
1712 ptr = epos->bh->b_data + epos->offset;
1714 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
1715 adsize = sizeof(short_ad);
1716 else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
1717 adsize = sizeof(long_ad);
1721 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1723 struct buffer_head *nbh;
1725 kernel_lb_addr obloc = epos->block;
1727 epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
1728 obloc.partitionReferenceNum,
1729 obloc.logicalBlockNum, &err);
1730 if (!epos->block.logicalBlockNum)
1732 nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1738 memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
1739 set_buffer_uptodate(nbh);
1741 mark_buffer_dirty_inode(nbh, inode);
1743 aed = (struct allocExtDesc *)(nbh->b_data);
1744 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1745 aed->previousAllocExtLocation =
1746 cpu_to_le32(obloc.logicalBlockNum);
1747 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1748 loffset = epos->offset;
1749 aed->lengthAllocDescs = cpu_to_le32(adsize);
1750 sptr = ptr - adsize;
1751 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1752 memcpy(dptr, sptr, adsize);
1753 epos->offset = sizeof(struct allocExtDesc) + adsize;
1755 loffset = epos->offset + adsize;
1756 aed->lengthAllocDescs = cpu_to_le32(0);
1758 epos->offset = sizeof(struct allocExtDesc);
1761 aed = (struct allocExtDesc *)epos->bh->b_data;
1762 aed->lengthAllocDescs =
1763 cpu_to_le32(le32_to_cpu(
1764 aed->lengthAllocDescs) + adsize);
1766 UDF_I_LENALLOC(inode) += adsize;
1767 mark_inode_dirty(inode);
1770 if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
1771 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1772 epos->block.logicalBlockNum, sizeof(tag));
1774 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1775 epos->block.logicalBlockNum, sizeof(tag));
1776 switch (UDF_I_ALLOCTYPE(inode)) {
1777 case ICBTAG_FLAG_AD_SHORT:
1778 sad = (short_ad *)sptr;
1779 sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1780 inode->i_sb->s_blocksize);
1782 cpu_to_le32(epos->block.logicalBlockNum);
1784 case ICBTAG_FLAG_AD_LONG:
1785 lad = (long_ad *)sptr;
1786 lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1787 inode->i_sb->s_blocksize);
1788 lad->extLocation = cpu_to_lelb(epos->block);
1789 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1793 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1794 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1795 udf_update_tag(epos->bh->b_data, loffset);
1797 udf_update_tag(epos->bh->b_data,
1798 sizeof(struct allocExtDesc));
1799 mark_buffer_dirty_inode(epos->bh, inode);
1802 mark_inode_dirty(inode);
1807 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1810 UDF_I_LENALLOC(inode) += adsize;
1811 mark_inode_dirty(inode);
1813 aed = (struct allocExtDesc *)epos->bh->b_data;
1814 aed->lengthAllocDescs =
1815 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
1817 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1818 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1819 udf_update_tag(epos->bh->b_data,
1820 epos->offset + (inc ? 0 : adsize));
1822 udf_update_tag(epos->bh->b_data,
1823 sizeof(struct allocExtDesc));
1824 mark_buffer_dirty_inode(epos->bh, inode);
1830 int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
1831 kernel_lb_addr eloc, uint32_t elen, int inc)
1839 ptr = UDF_I_DATA(inode) + epos->offset -
1840 udf_file_entry_alloc_offset(inode) +
1841 UDF_I_LENEATTR(inode);
1843 ptr = epos->bh->b_data + epos->offset;
1845 switch (UDF_I_ALLOCTYPE(inode)) {
1846 case ICBTAG_FLAG_AD_SHORT:
1847 sad = (short_ad *)ptr;
1848 sad->extLength = cpu_to_le32(elen);
1849 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1850 adsize = sizeof(short_ad);
1852 case ICBTAG_FLAG_AD_LONG:
1853 lad = (long_ad *)ptr;
1854 lad->extLength = cpu_to_le32(elen);
1855 lad->extLocation = cpu_to_lelb(eloc);
1856 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1857 adsize = sizeof(long_ad);
1864 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1865 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
1866 struct allocExtDesc *aed =
1867 (struct allocExtDesc *)epos->bh->b_data;
1868 udf_update_tag(epos->bh->b_data,
1869 le32_to_cpu(aed->lengthAllocDescs) +
1870 sizeof(struct allocExtDesc));
1872 mark_buffer_dirty_inode(epos->bh, inode);
1874 mark_inode_dirty(inode);
1878 epos->offset += adsize;
1880 return (elen >> 30);
1883 int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1884 kernel_lb_addr *eloc, uint32_t *elen, int inc)
1888 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1889 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1891 epos->block = *eloc;
1892 epos->offset = sizeof(struct allocExtDesc);
1894 block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
1895 epos->bh = udf_tread(inode->i_sb, block);
1897 udf_debug("reading block %d failed!\n", block);
1905 int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
1906 kernel_lb_addr *eloc, uint32_t *elen, int inc)
1916 epos->offset = udf_file_entry_alloc_offset(inode);
1917 ptr = UDF_I_DATA(inode) + epos->offset -
1918 udf_file_entry_alloc_offset(inode) +
1919 UDF_I_LENEATTR(inode);
1920 alen = udf_file_entry_alloc_offset(inode) +
1921 UDF_I_LENALLOC(inode);
1924 epos->offset = sizeof(struct allocExtDesc);
1925 ptr = epos->bh->b_data + epos->offset;
1926 alen = sizeof(struct allocExtDesc) +
1927 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1931 switch (UDF_I_ALLOCTYPE(inode)) {
1932 case ICBTAG_FLAG_AD_SHORT:
1933 sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
1936 etype = le32_to_cpu(sad->extLength) >> 30;
1937 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1938 eloc->partitionReferenceNum =
1939 UDF_I_LOCATION(inode).partitionReferenceNum;
1940 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1942 case ICBTAG_FLAG_AD_LONG:
1943 lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
1946 etype = le32_to_cpu(lad->extLength) >> 30;
1947 *eloc = lelb_to_cpu(lad->extLocation);
1948 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1951 udf_debug("alloc_type = %d unsupported\n",
1952 UDF_I_ALLOCTYPE(inode));
1959 static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
1960 kernel_lb_addr neloc, uint32_t nelen)
1962 kernel_lb_addr oeloc;
1969 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
1970 udf_write_aext(inode, &epos, neloc, nelen, 1);
1972 nelen = (etype << 30) | oelen;
1974 udf_add_aext(inode, &epos, neloc, nelen, 1);
1977 return (nelen >> 30);
1980 int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
1981 kernel_lb_addr eloc, uint32_t elen)
1983 struct extent_position oepos;
1986 struct allocExtDesc *aed;
1993 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
1994 adsize = sizeof(short_ad);
1995 else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
1996 adsize = sizeof(long_ad);
2001 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2004 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2005 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2006 if (oepos.bh != epos.bh) {
2007 oepos.block = epos.block;
2011 oepos.offset = epos.offset - adsize;
2014 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2017 if (epos.bh != oepos.bh) {
2018 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2019 udf_write_aext(inode, &oepos, eloc, elen, 1);
2020 udf_write_aext(inode, &oepos, eloc, elen, 1);
2022 UDF_I_LENALLOC(inode) -= (adsize * 2);
2023 mark_inode_dirty(inode);
2025 aed = (struct allocExtDesc *)oepos.bh->b_data;
2026 aed->lengthAllocDescs =
2027 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2029 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2030 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2031 udf_update_tag(oepos.bh->b_data,
2032 oepos.offset - (2 * adsize));
2034 udf_update_tag(oepos.bh->b_data,
2035 sizeof(struct allocExtDesc));
2036 mark_buffer_dirty_inode(oepos.bh, inode);
2039 udf_write_aext(inode, &oepos, eloc, elen, 1);
2041 UDF_I_LENALLOC(inode) -= adsize;
2042 mark_inode_dirty(inode);
2044 aed = (struct allocExtDesc *)oepos.bh->b_data;
2045 aed->lengthAllocDescs =
2046 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2048 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2049 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2050 udf_update_tag(oepos.bh->b_data,
2051 epos.offset - adsize);
2053 udf_update_tag(oepos.bh->b_data,
2054 sizeof(struct allocExtDesc));
2055 mark_buffer_dirty_inode(oepos.bh, inode);
2062 return (elen >> 30);
2065 int8_t inode_bmap(struct inode *inode, sector_t block,
2066 struct extent_position *pos, kernel_lb_addr *eloc,
2067 uint32_t *elen, sector_t *offset)
2069 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
2070 loff_t lbcount = 0, bcount =
2071 (loff_t) block << blocksize_bits;
2075 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2080 pos->block = UDF_I_LOCATION(inode);
2085 etype = udf_next_aext(inode, pos, eloc, elen, 1);
2087 *offset = (bcount - lbcount) >> blocksize_bits;
2088 UDF_I_LENEXTENTS(inode) = lbcount;
2092 } while (lbcount <= bcount);
2094 *offset = (bcount + *elen - lbcount) >> blocksize_bits;
2099 long udf_block_map(struct inode *inode, sector_t block)
2101 kernel_lb_addr eloc;
2104 struct extent_position epos = {};
2109 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2110 (EXT_RECORDED_ALLOCATED >> 30))
2111 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2118 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
2119 return udf_fixed_to_variable(ret);