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 and udf_read_inode
23 * 12/12/98 rewrote udf_block_map to handle next extents and descs across
24 * block boundaries (which is not actually allowed)
25 * 12/20/98 added support for strategy 4096
26 * 03/07/99 rewrote udf_block_map (again)
27 * New funcs, inode_bmap, udf_next_aext
28 * 04/19/99 Support for writing device EA's for major/minor #
33 #include <linux/smp_lock.h>
34 #include <linux/module.h>
35 #include <linux/pagemap.h>
36 #include <linux/buffer_head.h>
37 #include <linux/writeback.h>
38 #include <linux/slab.h>
43 MODULE_AUTHOR("Ben Fennema");
44 MODULE_DESCRIPTION("Universal Disk Format Filesystem");
45 MODULE_LICENSE("GPL");
47 #define EXTENT_MERGE_SIZE 5
49 static mode_t udf_convert_permissions(struct fileEntry *);
50 static int udf_update_inode(struct inode *, int);
51 static void udf_fill_inode(struct inode *, struct buffer_head *);
52 static int udf_alloc_i_data(struct inode *inode, size_t size);
53 static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
55 static int8_t udf_insert_aext(struct inode *, struct extent_position,
56 kernel_lb_addr, uint32_t);
57 static void udf_split_extents(struct inode *, int *, int, int,
58 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
59 static void udf_prealloc_extents(struct inode *, int, int,
60 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
61 static void udf_merge_extents(struct inode *,
62 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
63 static void udf_update_extents(struct inode *,
64 kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
65 struct extent_position *);
66 static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
72 * Clean-up before the specified inode is destroyed.
75 * This routine is called when the kernel destroys an inode structure
76 * ie. when iput() finds i_count == 0.
79 * July 1, 1997 - Andrew E. Mileski
80 * Written, tested, and released.
82 * Called at the last iput() if i_nlink is zero.
84 void udf_delete_inode(struct inode *inode)
86 truncate_inode_pages(&inode->i_data, 0);
88 if (is_bad_inode(inode))
95 udf_update_inode(inode, IS_SYNC(inode));
96 udf_free_inode(inode);
105 * If we are going to release inode from memory, we discard preallocation and
106 * truncate last inode extent to proper length. We could use drop_inode() but
107 * it's called under inode_lock and thus we cannot mark inode dirty there. We
108 * use clear_inode() but we have to make sure to write inode as it's not written
111 void udf_clear_inode(struct inode *inode)
113 if (!(inode->i_sb->s_flags & MS_RDONLY)) {
115 /* Discard preallocation for directories, symlinks, etc. */
116 udf_discard_prealloc(inode);
117 udf_truncate_tail_extent(inode);
119 write_inode_now(inode, 1);
121 kfree(UDF_I_DATA(inode));
122 UDF_I_DATA(inode) = NULL;
125 static int udf_writepage(struct page *page, struct writeback_control *wbc)
127 return block_write_full_page(page, udf_get_block, wbc);
130 static int udf_readpage(struct file *file, struct page *page)
132 return block_read_full_page(page, udf_get_block);
135 static int udf_prepare_write(struct file *file, struct page *page,
136 unsigned from, unsigned to)
138 return block_prepare_write(page, from, to, udf_get_block);
141 static sector_t udf_bmap(struct address_space *mapping, sector_t block)
143 return generic_block_bmap(mapping, block, udf_get_block);
146 const struct address_space_operations udf_aops = {
147 .readpage = udf_readpage,
148 .writepage = udf_writepage,
149 .sync_page = block_sync_page,
150 .prepare_write = udf_prepare_write,
151 .commit_write = generic_commit_write,
155 void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
159 struct writeback_control udf_wbc = {
160 .sync_mode = WB_SYNC_NONE,
164 /* from now on we have normal address_space methods */
165 inode->i_data.a_ops = &udf_aops;
167 if (!UDF_I_LENALLOC(inode)) {
168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
169 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
171 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
172 mark_inode_dirty(inode);
176 page = grab_cache_page(inode->i_mapping, 0);
177 BUG_ON(!PageLocked(page));
179 if (!PageUptodate(page)) {
181 memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
182 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
183 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
184 UDF_I_LENALLOC(inode));
185 flush_dcache_page(page);
186 SetPageUptodate(page);
189 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
190 UDF_I_LENALLOC(inode));
191 UDF_I_LENALLOC(inode) = 0;
192 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
193 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
195 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
197 inode->i_data.a_ops->writepage(page, &udf_wbc);
198 page_cache_release(page);
200 mark_inode_dirty(inode);
203 struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
207 struct buffer_head *dbh = NULL;
211 struct extent_position epos;
213 struct udf_fileident_bh sfibh, dfibh;
214 loff_t f_pos = udf_ext0_offset(inode) >> 2;
215 int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
216 struct fileIdentDesc cfi, *sfi, *dfi;
218 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
219 alloctype = ICBTAG_FLAG_AD_SHORT;
221 alloctype = ICBTAG_FLAG_AD_LONG;
223 if (!inode->i_size) {
224 UDF_I_ALLOCTYPE(inode) = alloctype;
225 mark_inode_dirty(inode);
229 /* alloc block, and copy data to it */
230 *block = udf_new_block(inode->i_sb, inode,
231 UDF_I_LOCATION(inode).partitionReferenceNum,
232 UDF_I_LOCATION(inode).logicalBlockNum, err);
236 newblock = udf_get_pblock(inode->i_sb, *block,
237 UDF_I_LOCATION(inode).partitionReferenceNum,
241 dbh = udf_tgetblk(inode->i_sb, newblock);
245 memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
246 set_buffer_uptodate(dbh);
248 mark_buffer_dirty_inode(dbh, inode);
250 sfibh.soffset = sfibh.eoffset =
251 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
252 sfibh.sbh = sfibh.ebh = NULL;
253 dfibh.soffset = dfibh.eoffset = 0;
254 dfibh.sbh = dfibh.ebh = dbh;
255 while ((f_pos < size)) {
256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
258 udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL,
264 UDF_I_ALLOCTYPE(inode) = alloctype;
265 sfi->descTag.tagLocation = cpu_to_le32(*block);
266 dfibh.soffset = dfibh.eoffset;
267 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
268 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
269 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
271 le16_to_cpu(sfi->lengthOfImpUse))) {
272 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
277 mark_buffer_dirty_inode(dbh, inode);
279 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0,
280 UDF_I_LENALLOC(inode));
281 UDF_I_LENALLOC(inode) = 0;
282 eloc.logicalBlockNum = *block;
283 eloc.partitionReferenceNum =
284 UDF_I_LOCATION(inode).partitionReferenceNum;
285 elen = inode->i_size;
286 UDF_I_LENEXTENTS(inode) = elen;
288 epos.block = UDF_I_LOCATION(inode);
289 epos.offset = udf_file_entry_alloc_offset(inode);
290 udf_add_aext(inode, &epos, eloc, elen, 0);
294 mark_inode_dirty(inode);
298 static int udf_get_block(struct inode *inode, sector_t block,
299 struct buffer_head *bh_result, int create)
302 struct buffer_head *bh;
306 phys = udf_block_map(inode, block);
308 map_bh(bh_result, inode->i_sb, phys);
321 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
322 UDF_I_NEXT_ALLOC_BLOCK(inode)++;
323 UDF_I_NEXT_ALLOC_GOAL(inode)++;
328 bh = inode_getblk(inode, block, &err, &phys, &new);
335 set_buffer_new(bh_result);
336 map_bh(bh_result, inode->i_sb, phys);
342 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
346 static struct buffer_head *udf_getblk(struct inode *inode, long block,
347 int create, int *err)
349 struct buffer_head dummy;
352 dummy.b_blocknr = -1000;
353 *err = udf_get_block(inode, block, &dummy, create);
354 if (!*err && buffer_mapped(&dummy)) {
355 struct buffer_head *bh;
356 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
357 if (buffer_new(&dummy)) {
359 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
360 set_buffer_uptodate(bh);
362 mark_buffer_dirty_inode(bh, inode);
369 /* Extend the file by 'blocks' blocks, return the number of extents added */
370 int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
371 kernel_long_ad * last_ext, sector_t blocks)
374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
375 struct super_block *sb = inode->i_sb;
376 kernel_lb_addr prealloc_loc = { 0, 0 };
377 int prealloc_len = 0;
379 /* The previous extent is fake and we should not extend by anything
380 * - there's nothing to do... */
383 /* Round the last extent up to a multiple of block size */
384 if (last_ext->extLength & (sb->s_blocksize - 1)) {
385 last_ext->extLength =
386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
389 UDF_I_LENEXTENTS(inode) =
390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
391 ~(sb->s_blocksize - 1);
393 /* Last extent are just preallocated blocks? */
394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
395 EXT_NOT_RECORDED_ALLOCATED) {
396 /* Save the extent so that we can reattach it to the end */
397 prealloc_loc = last_ext->extLocation;
398 prealloc_len = last_ext->extLength;
399 /* Mark the extent as a hole */
400 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
401 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
402 last_ext->extLocation.logicalBlockNum = 0;
403 last_ext->extLocation.partitionReferenceNum = 0;
405 /* Can we merge with the previous extent? */
406 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
407 EXT_NOT_RECORDED_NOT_ALLOCATED) {
409 ((1 << 30) - sb->s_blocksize -
410 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> sb->
415 last_ext->extLength += add << sb->s_blocksize_bits;
419 udf_add_aext(inode, last_pos, last_ext->extLocation,
420 last_ext->extLength, 1);
423 udf_write_aext(inode, last_pos, last_ext->extLocation,
424 last_ext->extLength, 1);
425 /* Managed to do everything necessary? */
429 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
430 last_ext->extLocation.logicalBlockNum = 0;
431 last_ext->extLocation.partitionReferenceNum = 0;
432 add = (1 << (30 - sb->s_blocksize_bits)) - 1;
433 last_ext->extLength =
434 EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
435 /* Create enough extents to cover the whole hole */
436 while (blocks > add) {
438 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
439 last_ext->extLength, 1) == -1)
444 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
445 (blocks << sb->s_blocksize_bits);
446 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
447 last_ext->extLength, 1) == -1)
452 /* Do we have some preallocated blocks saved? */
454 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1)
457 last_ext->extLocation = prealloc_loc;
458 last_ext->extLength = prealloc_len;
461 /* last_pos should point to the last written extent... */
462 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
463 last_pos->offset -= sizeof(short_ad);
464 else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
465 last_pos->offset -= sizeof(long_ad);
471 static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
472 int *err, long *phys, int *new)
474 static sector_t last_block;
475 struct buffer_head *result = NULL;
476 kernel_long_ad laarr[EXTENT_MERGE_SIZE];
477 struct extent_position prev_epos, cur_epos, next_epos;
478 int count = 0, startnum = 0, endnum = 0;
479 uint32_t elen = 0, tmpelen;
480 kernel_lb_addr eloc, tmpeloc;
482 loff_t lbcount = 0, b_off = 0;
483 uint32_t newblocknum, newblock;
486 int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
489 prev_epos.offset = udf_file_entry_alloc_offset(inode);
490 prev_epos.block = UDF_I_LOCATION(inode);
492 cur_epos = next_epos = prev_epos;
493 b_off = (loff_t) block << inode->i_sb->s_blocksize_bits;
495 /* find the extent which contains the block we are looking for.
496 alternate between laarr[0] and laarr[1] for locations of the
497 current extent, and the previous extent */
499 if (prev_epos.bh != cur_epos.bh) {
500 brelse(prev_epos.bh);
502 prev_epos.bh = cur_epos.bh;
504 if (cur_epos.bh != next_epos.bh) {
506 get_bh(next_epos.bh);
507 cur_epos.bh = next_epos.bh;
512 prev_epos.block = cur_epos.block;
513 cur_epos.block = next_epos.block;
515 prev_epos.offset = cur_epos.offset;
516 cur_epos.offset = next_epos.offset;
519 udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
524 laarr[c].extLength = (etype << 30) | elen;
525 laarr[c].extLocation = eloc;
527 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
528 pgoal = eloc.logicalBlockNum +
529 ((elen + inode->i_sb->s_blocksize - 1) >>
530 inode->i_sb->s_blocksize_bits);
533 } while (lbcount + elen <= b_off);
536 offset = b_off >> inode->i_sb->s_blocksize_bits;
538 * Move prev_epos and cur_epos into indirect extent if we are at
541 udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
542 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
544 /* if the extent is allocated and recorded, return the block
545 if the extent is not a multiple of the blocksize, round up */
547 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
548 if (elen & (inode->i_sb->s_blocksize - 1)) {
549 elen = EXT_RECORDED_ALLOCATED |
550 ((elen + inode->i_sb->s_blocksize - 1) &
551 ~(inode->i_sb->s_blocksize - 1));
552 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
554 brelse(prev_epos.bh);
556 brelse(next_epos.bh);
557 newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
563 /* Are we beyond EOF? */
572 /* Create a fake extent when there's not one */
573 memset(&laarr[0].extLocation, 0x00,
574 sizeof(kernel_lb_addr));
575 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
576 /* Will udf_extend_file() create real extent from a fake one? */
577 startnum = (offset > 0);
579 /* Create extents for the hole between EOF and offset */
580 ret = udf_extend_file(inode, &prev_epos, laarr, offset);
582 brelse(prev_epos.bh);
584 brelse(next_epos.bh);
585 /* We don't really know the error here so we just make
593 /* We are not covered by a preallocated extent? */
594 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
595 EXT_NOT_RECORDED_ALLOCATED) {
596 /* Is there any real extent? - otherwise we overwrite
600 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
601 inode->i_sb->s_blocksize;
602 memset(&laarr[c].extLocation, 0x00,
603 sizeof(kernel_lb_addr));
610 endnum = startnum = ((count > 2) ? 2 : count);
612 /* if the current extent is in position 0, swap it with the previous */
613 if (!c && count != 1) {
620 /* if the current block is located in an extent, read the next extent */
622 udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
623 laarr[c + 1].extLength = (etype << 30) | elen;
624 laarr[c + 1].extLocation = eloc;
633 /* if the current extent is not recorded but allocated, get the
634 block in the extent corresponding to the requested block */
635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
637 else { /* otherwise, allocate a new block */
639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
640 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
645 UDF_I_LOCATION(inode).logicalBlockNum + 1;
648 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
649 UDF_I_LOCATION(inode).
650 partitionReferenceNum, goal,
652 brelse(prev_epos.bh);
656 UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
659 /* if the extent the requsted block is located in contains multiple blocks,
660 split the extent into at most three extents. blocks prior to requested
661 block, requested block, and blocks after requested block */
662 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
664 #ifdef UDF_PREALLOCATE
665 /* preallocate blocks */
666 udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
669 /* merge any continuous blocks in laarr */
670 udf_merge_extents(inode, laarr, &endnum);
672 /* write back the new extents, inserting new extents if the new number
673 of extents is greater than the old number, and deleting extents if
674 the new number of extents is less than the old number */
675 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
677 brelse(prev_epos.bh);
679 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
680 UDF_I_LOCATION(inode).
681 partitionReferenceNum, 0))) {
687 UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
688 UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
689 inode->i_ctime = current_fs_time(inode->i_sb);
692 udf_sync_inode(inode);
694 mark_inode_dirty(inode);
698 static void udf_split_extents(struct inode *inode, int *c, int offset,
700 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
703 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
704 (laarr[*c].extLength >> 30) ==
705 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
707 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
708 inode->i_sb->s_blocksize -
709 1) >> inode->i_sb->s_blocksize_bits;
710 int8_t etype = (laarr[curr].extLength >> 30);
713 else if (!offset || blen == offset + 1) {
714 laarr[curr + 2] = laarr[curr + 1];
715 laarr[curr + 1] = laarr[curr];
717 laarr[curr + 3] = laarr[curr + 1];
718 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
722 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
723 udf_free_blocks(inode->i_sb, inode,
724 laarr[curr].extLocation, 0,
726 laarr[curr].extLength =
727 EXT_NOT_RECORDED_NOT_ALLOCATED | (offset <<
731 laarr[curr].extLocation.logicalBlockNum = 0;
732 laarr[curr].extLocation.partitionReferenceNum =
735 laarr[curr].extLength = (etype << 30) |
736 (offset << inode->i_sb->s_blocksize_bits);
742 laarr[curr].extLocation.logicalBlockNum = newblocknum;
743 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
744 laarr[curr].extLocation.partitionReferenceNum =
745 UDF_I_LOCATION(inode).partitionReferenceNum;
746 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
747 inode->i_sb->s_blocksize;
750 if (blen != offset + 1) {
751 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
752 laarr[curr].extLocation.logicalBlockNum +=
754 laarr[curr].extLength =
755 (etype << 30) | ((blen - (offset + 1)) << inode->
756 i_sb->s_blocksize_bits);
763 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
764 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
767 int start, length = 0, currlength = 0, i;
769 if (*endnum >= (c + 1)) {
775 if ((laarr[c + 1].extLength >> 30) ==
776 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
778 length = currlength =
780 extLength & UDF_EXTENT_LENGTH_MASK) +
781 inode->i_sb->s_blocksize -
782 1) >> inode->i_sb->s_blocksize_bits);
787 for (i = start + 1; i <= *endnum; i++) {
790 length += UDF_DEFAULT_PREALLOC_BLOCKS;
791 } else if ((laarr[i].extLength >> 30) ==
792 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
794 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
795 inode->i_sb->s_blocksize -
796 1) >> inode->i_sb->s_blocksize_bits);
802 int next = laarr[start].extLocation.logicalBlockNum +
803 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
804 inode->i_sb->s_blocksize -
805 1) >> inode->i_sb->s_blocksize_bits);
806 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
807 laarr[start].extLocation.
808 partitionReferenceNum,
810 (UDF_DEFAULT_PREALLOC_BLOCKS
813 UDF_DEFAULT_PREALLOC_BLOCKS)
817 if (start == (c + 1))
818 laarr[start].extLength +=
819 (numalloc << inode->i_sb->s_blocksize_bits);
821 memmove(&laarr[c + 2], &laarr[c + 1],
822 sizeof(long_ad) * (*endnum - (c + 1)));
824 laarr[c + 1].extLocation.logicalBlockNum = next;
825 laarr[c + 1].extLocation.partitionReferenceNum =
826 laarr[c].extLocation.partitionReferenceNum;
827 laarr[c + 1].extLength =
828 EXT_NOT_RECORDED_ALLOCATED | (numalloc <<
834 for (i = start + 1; numalloc && i < *endnum; i++) {
837 extLength & UDF_EXTENT_LENGTH_MASK) +
838 inode->i_sb->s_blocksize -
839 1) >> inode->i_sb->s_blocksize_bits;
841 if (elen > numalloc) {
842 laarr[i].extLength -=
843 (numalloc << inode->i_sb->
848 if (*endnum > (i + 1))
852 (*endnum - (i + 1)));
857 UDF_I_LENEXTENTS(inode) +=
858 numalloc << inode->i_sb->s_blocksize_bits;
863 static void udf_merge_extents(struct inode *inode,
864 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
869 for (i = 0; i < (*endnum - 1); i++) {
870 if ((laarr[i].extLength >> 30) ==
871 (laarr[i + 1].extLength >> 30)) {
872 if (((laarr[i].extLength >> 30) ==
873 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
875 ((laarr[i + 1].extLocation.logicalBlockNum -
876 laarr[i].extLocation.logicalBlockNum) ==
877 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
878 inode->i_sb->s_blocksize -
879 1) >> inode->i_sb->s_blocksize_bits))) {
881 extLength & UDF_EXTENT_LENGTH_MASK) +
883 extLength & UDF_EXTENT_LENGTH_MASK) +
884 inode->i_sb->s_blocksize -
885 1) & ~UDF_EXTENT_LENGTH_MASK) {
886 laarr[i + 1].extLength =
887 (laarr[i + 1].extLength -
890 UDF_EXTENT_LENGTH_MASK) +
891 UDF_EXTENT_LENGTH_MASK) & ~(inode->
897 extLength & UDF_EXTENT_FLAG_MASK) +
898 (UDF_EXTENT_LENGTH_MASK + 1) -
899 inode->i_sb->s_blocksize;
901 1].extLocation.logicalBlockNum =
902 laarr[i].extLocation.
906 UDF_EXTENT_LENGTH_MASK) >> inode->
907 i_sb->s_blocksize_bits);
910 laarr[i + 1].extLength +
913 UDF_EXTENT_LENGTH_MASK) +
914 inode->i_sb->s_blocksize -
915 1) & ~(inode->i_sb->s_blocksize -
917 if (*endnum > (i + 2))
918 memmove(&laarr[i + 1],
921 (*endnum - (i + 2)));
927 if (((laarr[i].extLength >> 30) ==
928 (EXT_NOT_RECORDED_ALLOCATED >> 30))
929 && ((laarr[i + 1].extLength >> 30) ==
930 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
931 udf_free_blocks(inode->i_sb, inode,
932 laarr[i].extLocation, 0,
934 extLength & UDF_EXTENT_LENGTH_MASK) +
935 inode->i_sb->s_blocksize -
936 1) >> inode->i_sb->s_blocksize_bits);
937 laarr[i].extLocation.logicalBlockNum = 0;
938 laarr[i].extLocation.partitionReferenceNum = 0;
940 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
941 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
942 inode->i_sb->s_blocksize -
943 1) & ~UDF_EXTENT_LENGTH_MASK) {
944 laarr[i + 1].extLength =
945 (laarr[i + 1].extLength -
947 extLength & UDF_EXTENT_LENGTH_MASK) +
948 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->
953 extLength & UDF_EXTENT_FLAG_MASK) +
954 (UDF_EXTENT_LENGTH_MASK + 1) -
955 inode->i_sb->s_blocksize;
957 laarr[i].extLength = laarr[i + 1].extLength +
959 extLength & UDF_EXTENT_LENGTH_MASK) +
960 inode->i_sb->s_blocksize -
961 1) & ~(inode->i_sb->s_blocksize - 1));
962 if (*endnum > (i + 2))
963 memmove(&laarr[i + 1], &laarr[i + 2],
964 sizeof(long_ad) * (*endnum -
969 } else if ((laarr[i].extLength >> 30) ==
970 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
971 udf_free_blocks(inode->i_sb, inode,
972 laarr[i].extLocation, 0,
974 extLength & UDF_EXTENT_LENGTH_MASK) +
975 inode->i_sb->s_blocksize -
976 1) >> inode->i_sb->s_blocksize_bits);
977 laarr[i].extLocation.logicalBlockNum = 0;
978 laarr[i].extLocation.partitionReferenceNum = 0;
981 extLength & UDF_EXTENT_LENGTH_MASK) |
982 EXT_NOT_RECORDED_NOT_ALLOCATED;
987 static void udf_update_extents(struct inode *inode,
988 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
989 int startnum, int endnum,
990 struct extent_position *epos)
993 kernel_lb_addr tmploc;
996 if (startnum > endnum) {
997 for (i = 0; i < (startnum - endnum); i++)
998 udf_delete_aext(inode, *epos, laarr[i].extLocation,
1000 } else if (startnum < endnum) {
1001 for (i = 0; i < (endnum - startnum); i++) {
1002 udf_insert_aext(inode, *epos, laarr[i].extLocation,
1003 laarr[i].extLength);
1004 udf_next_aext(inode, epos, &laarr[i].extLocation,
1005 &laarr[i].extLength, 1);
1010 for (i = start; i < endnum; i++) {
1011 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
1012 udf_write_aext(inode, epos, laarr[i].extLocation,
1013 laarr[i].extLength, 1);
1017 struct buffer_head *udf_bread(struct inode *inode, int block,
1018 int create, int *err)
1020 struct buffer_head *bh = NULL;
1022 bh = udf_getblk(inode, block, create, err);
1026 if (buffer_uptodate(bh))
1028 ll_rw_block(READ, 1, &bh);
1030 if (buffer_uptodate(bh))
1037 void udf_truncate(struct inode *inode)
1042 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1043 S_ISLNK(inode->i_mode)))
1045 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1049 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1050 if (inode->i_sb->s_blocksize <
1051 (udf_file_entry_alloc_offset(inode) + inode->i_size)) {
1052 udf_expand_file_adinicb(inode, inode->i_size, &err);
1053 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1054 inode->i_size = UDF_I_LENALLOC(inode);
1058 udf_truncate_extents(inode);
1060 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1061 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) +
1063 inode->i_sb->s_blocksize - offset -
1064 udf_file_entry_alloc_offset(inode));
1065 UDF_I_LENALLOC(inode) = inode->i_size;
1068 block_truncate_page(inode->i_mapping, inode->i_size,
1070 udf_truncate_extents(inode);
1073 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1075 udf_sync_inode(inode);
1077 mark_inode_dirty(inode);
1081 static void __udf_read_inode(struct inode *inode)
1083 struct buffer_head *bh = NULL;
1084 struct fileEntry *fe;
1088 * Set defaults, but the inode is still incomplete!
1089 * Note: get_new_inode() sets the following on a new inode:
1092 * i_flags = sb->s_flags
1094 * clean_inode(): zero fills and sets
1099 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1102 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1104 make_bad_inode(inode);
1108 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1109 ident != TAG_IDENT_USE) {
1111 "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1112 inode->i_ino, ident);
1114 make_bad_inode(inode);
1118 fe = (struct fileEntry *)bh->b_data;
1120 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
1121 struct buffer_head *ibh = NULL, *nbh = NULL;
1122 struct indirectEntry *ie;
1125 udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
1127 if (ident == TAG_IDENT_IE) {
1130 ie = (struct indirectEntry *)ibh->b_data;
1132 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1134 if (ie->indirectICB.extLength &&
1136 udf_read_ptagged(inode->i_sb, loc, 0,
1138 if (ident == TAG_IDENT_FE
1139 || ident == TAG_IDENT_EFE) {
1140 memcpy(&UDF_I_LOCATION(inode),
1142 sizeof(kernel_lb_addr));
1146 __udf_read_inode(inode);
1157 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1158 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1159 le16_to_cpu(fe->icbTag.strategyType));
1161 make_bad_inode(inode);
1164 udf_fill_inode(inode, bh);
1169 static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1171 struct fileEntry *fe;
1172 struct extendedFileEntry *efe;
1177 fe = (struct fileEntry *)bh->b_data;
1178 efe = (struct extendedFileEntry *)bh->b_data;
1180 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
1181 UDF_I_STRAT4096(inode) = 0;
1182 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
1183 UDF_I_STRAT4096(inode) = 1;
1185 UDF_I_ALLOCTYPE(inode) =
1186 le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
1187 UDF_I_UNIQUE(inode) = 0;
1188 UDF_I_LENEATTR(inode) = 0;
1189 UDF_I_LENEXTENTS(inode) = 0;
1190 UDF_I_LENALLOC(inode) = 0;
1191 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
1192 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
1193 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1194 UDF_I_EFE(inode) = 1;
1195 UDF_I_USE(inode) = 0;
1196 if (udf_alloc_i_data
1198 inode->i_sb->s_blocksize -
1199 sizeof(struct extendedFileEntry))) {
1200 make_bad_inode(inode);
1203 memcpy(UDF_I_DATA(inode),
1204 bh->b_data + sizeof(struct extendedFileEntry),
1205 inode->i_sb->s_blocksize -
1206 sizeof(struct extendedFileEntry));
1207 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1208 UDF_I_EFE(inode) = 0;
1209 UDF_I_USE(inode) = 0;
1210 if (udf_alloc_i_data
1212 inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1213 make_bad_inode(inode);
1216 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
1217 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1218 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1219 UDF_I_EFE(inode) = 0;
1220 UDF_I_USE(inode) = 1;
1221 UDF_I_LENALLOC(inode) =
1222 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->
1224 if (udf_alloc_i_data
1226 inode->i_sb->s_blocksize -
1227 sizeof(struct unallocSpaceEntry))) {
1228 make_bad_inode(inode);
1231 memcpy(UDF_I_DATA(inode),
1232 bh->b_data + sizeof(struct unallocSpaceEntry),
1233 inode->i_sb->s_blocksize -
1234 sizeof(struct unallocSpaceEntry));
1238 inode->i_uid = le32_to_cpu(fe->uid);
1239 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1240 UDF_FLAG_UID_IGNORE))
1241 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1243 inode->i_gid = le32_to_cpu(fe->gid);
1244 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1245 UDF_FLAG_GID_IGNORE))
1246 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1248 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1249 if (!inode->i_nlink)
1252 inode->i_size = le64_to_cpu(fe->informationLength);
1253 UDF_I_LENEXTENTS(inode) = inode->i_size;
1255 inode->i_mode = udf_convert_permissions(fe);
1256 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1258 if (UDF_I_EFE(inode) == 0) {
1259 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1260 (inode->i_sb->s_blocksize_bits - 9);
1262 if (udf_stamp_to_time(&convtime, &convtime_usec,
1263 lets_to_cpu(fe->accessTime))) {
1264 inode->i_atime.tv_sec = convtime;
1265 inode->i_atime.tv_nsec = convtime_usec * 1000;
1267 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1270 if (udf_stamp_to_time(&convtime, &convtime_usec,
1271 lets_to_cpu(fe->modificationTime))) {
1272 inode->i_mtime.tv_sec = convtime;
1273 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1275 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1278 if (udf_stamp_to_time(&convtime, &convtime_usec,
1279 lets_to_cpu(fe->attrTime))) {
1280 inode->i_ctime.tv_sec = convtime;
1281 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1283 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1286 UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
1287 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1288 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1289 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
1291 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1292 (inode->i_sb->s_blocksize_bits - 9);
1294 if (udf_stamp_to_time(&convtime, &convtime_usec,
1295 lets_to_cpu(efe->accessTime))) {
1296 inode->i_atime.tv_sec = convtime;
1297 inode->i_atime.tv_nsec = convtime_usec * 1000;
1299 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1302 if (udf_stamp_to_time(&convtime, &convtime_usec,
1303 lets_to_cpu(efe->modificationTime))) {
1304 inode->i_mtime.tv_sec = convtime;
1305 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1307 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1310 if (udf_stamp_to_time(&convtime, &convtime_usec,
1311 lets_to_cpu(efe->createTime))) {
1312 UDF_I_CRTIME(inode).tv_sec = convtime;
1313 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
1315 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
1318 if (udf_stamp_to_time(&convtime, &convtime_usec,
1319 lets_to_cpu(efe->attrTime))) {
1320 inode->i_ctime.tv_sec = convtime;
1321 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1323 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1326 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1327 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1328 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1330 sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1333 switch (fe->icbTag.fileType) {
1334 case ICBTAG_FILE_TYPE_DIRECTORY:
1336 inode->i_op = &udf_dir_inode_operations;
1337 inode->i_fop = &udf_dir_operations;
1338 inode->i_mode |= S_IFDIR;
1342 case ICBTAG_FILE_TYPE_REALTIME:
1343 case ICBTAG_FILE_TYPE_REGULAR:
1344 case ICBTAG_FILE_TYPE_UNDEF:
1346 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1347 inode->i_data.a_ops = &udf_adinicb_aops;
1349 inode->i_data.a_ops = &udf_aops;
1350 inode->i_op = &udf_file_inode_operations;
1351 inode->i_fop = &udf_file_operations;
1352 inode->i_mode |= S_IFREG;
1355 case ICBTAG_FILE_TYPE_BLOCK:
1357 inode->i_mode |= S_IFBLK;
1360 case ICBTAG_FILE_TYPE_CHAR:
1362 inode->i_mode |= S_IFCHR;
1365 case ICBTAG_FILE_TYPE_FIFO:
1367 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1370 case ICBTAG_FILE_TYPE_SOCKET:
1372 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1375 case ICBTAG_FILE_TYPE_SYMLINK:
1377 inode->i_data.a_ops = &udf_symlink_aops;
1378 inode->i_op = &page_symlink_inode_operations;
1379 inode->i_mode = S_IFLNK | S_IRWXUGO;
1385 "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1386 inode->i_ino, fe->icbTag.fileType);
1387 make_bad_inode(inode);
1391 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1392 struct deviceSpec *dsea = (struct deviceSpec *)
1393 udf_get_extendedattr(inode, 12, 1);
1396 init_special_inode(inode, inode->i_mode,
1398 (dsea->majorDeviceIdent),
1400 minorDeviceIdent)));
1401 /* Developer ID ??? */
1403 make_bad_inode(inode);
1408 static int udf_alloc_i_data(struct inode *inode, size_t size)
1410 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1412 if (!UDF_I_DATA(inode)) {
1414 "udf:udf_alloc_i_data (ino %ld) no free memory\n",
1422 static mode_t udf_convert_permissions(struct fileEntry *fe)
1425 uint32_t permissions;
1428 permissions = le32_to_cpu(fe->permissions);
1429 flags = le16_to_cpu(fe->icbTag.flags);
1431 mode = ((permissions) & S_IRWXO) |
1432 ((permissions >> 2) & S_IRWXG) |
1433 ((permissions >> 4) & S_IRWXU) |
1434 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1435 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1436 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1445 * Write out the specified inode.
1448 * This routine is called whenever an inode is synced.
1449 * Currently this routine is just a placeholder.
1452 * July 1, 1997 - Andrew E. Mileski
1453 * Written, tested, and released.
1456 int udf_write_inode(struct inode *inode, int sync)
1460 ret = udf_update_inode(inode, sync);
1465 int udf_sync_inode(struct inode *inode)
1467 return udf_update_inode(inode, 1);
1470 static int udf_update_inode(struct inode *inode, int do_sync)
1472 struct buffer_head *bh = NULL;
1473 struct fileEntry *fe;
1474 struct extendedFileEntry *efe;
1479 kernel_timestamp cpu_time;
1482 bh = udf_tread(inode->i_sb,
1483 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode),
1487 udf_debug("bread failure\n");
1491 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
1493 fe = (struct fileEntry *)bh->b_data;
1494 efe = (struct extendedFileEntry *)bh->b_data;
1496 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1497 struct unallocSpaceEntry *use =
1498 (struct unallocSpaceEntry *)bh->b_data;
1500 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1501 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1503 inode->i_sb->s_blocksize -
1504 sizeof(struct unallocSpaceEntry));
1506 sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) -
1508 use->descTag.tagLocation =
1509 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1510 use->descTag.descCRCLength = cpu_to_le16(crclen);
1511 use->descTag.descCRC =
1512 cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1514 use->descTag.tagChecksum = 0;
1515 for (i = 0; i < 16; i++)
1517 use->descTag.tagChecksum +=
1518 ((uint8_t *) & (use->descTag))[i];
1520 mark_buffer_dirty(bh);
1525 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1526 fe->uid = cpu_to_le32(-1);
1528 fe->uid = cpu_to_le32(inode->i_uid);
1530 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1531 fe->gid = cpu_to_le32(-1);
1533 fe->gid = cpu_to_le32(inode->i_gid);
1535 udfperms = ((inode->i_mode & S_IRWXO)) |
1536 ((inode->i_mode & S_IRWXG) << 2) | ((inode->i_mode & S_IRWXU) << 4);
1538 udfperms |= (le32_to_cpu(fe->permissions) &
1539 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1540 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1541 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1542 fe->permissions = cpu_to_le32(udfperms);
1544 if (S_ISDIR(inode->i_mode))
1545 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1547 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1549 fe->informationLength = cpu_to_le64(inode->i_size);
1551 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1553 struct deviceSpec *dsea = (struct deviceSpec *)
1554 udf_get_extendedattr(inode, 12, 1);
1557 dsea = (struct deviceSpec *)
1558 udf_add_extendedattr(inode,
1559 sizeof(struct deviceSpec) +
1560 sizeof(regid), 12, 0x3);
1561 dsea->attrType = cpu_to_le32(12);
1562 dsea->attrSubtype = 1;
1564 cpu_to_le32(sizeof(struct deviceSpec) +
1566 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1568 eid = (regid *) dsea->impUse;
1569 memset(eid, 0, sizeof(regid));
1570 strcpy(eid->ident, UDF_ID_DEVELOPER);
1571 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
1572 eid->identSuffix[1] = UDF_OS_ID_LINUX;
1573 dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
1574 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1577 if (UDF_I_EFE(inode) == 0) {
1578 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1579 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1580 fe->logicalBlocksRecorded =
1581 cpu_to_le64((inode->i_blocks +
1582 (1 << (inode->i_sb->s_blocksize_bits - 9)) -
1583 1) >> (inode->i_sb->s_blocksize_bits - 9));
1585 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1586 fe->accessTime = cpu_to_lets(cpu_time);
1587 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1588 fe->modificationTime = cpu_to_lets(cpu_time);
1589 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1590 fe->attrTime = cpu_to_lets(cpu_time);
1591 memset(&(fe->impIdent), 0, sizeof(regid));
1592 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1593 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1594 fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1595 fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1596 fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1597 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1598 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1599 crclen = sizeof(struct fileEntry);
1601 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1603 inode->i_sb->s_blocksize -
1604 sizeof(struct extendedFileEntry));
1605 efe->objectSize = cpu_to_le64(inode->i_size);
1606 efe->logicalBlocksRecorded = cpu_to_le64((inode->i_blocks +
1611 1) >> (inode->i_sb->
1615 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1616 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
1617 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) {
1618 UDF_I_CRTIME(inode) = inode->i_atime;
1620 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
1621 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
1622 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) {
1623 UDF_I_CRTIME(inode) = inode->i_mtime;
1625 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
1626 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
1627 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) {
1628 UDF_I_CRTIME(inode) = inode->i_ctime;
1631 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1632 efe->accessTime = cpu_to_lets(cpu_time);
1633 if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1634 efe->modificationTime = cpu_to_lets(cpu_time);
1635 if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode)))
1636 efe->createTime = cpu_to_lets(cpu_time);
1637 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1638 efe->attrTime = cpu_to_lets(cpu_time);
1640 memset(&(efe->impIdent), 0, sizeof(regid));
1641 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
1642 efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1643 efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1644 efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1645 efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1646 efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1647 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1648 crclen = sizeof(struct extendedFileEntry);
1650 if (UDF_I_STRAT4096(inode)) {
1651 fe->icbTag.strategyType = cpu_to_le16(4096);
1652 fe->icbTag.strategyParameter = cpu_to_le16(1);
1653 fe->icbTag.numEntries = cpu_to_le16(2);
1655 fe->icbTag.strategyType = cpu_to_le16(4);
1656 fe->icbTag.numEntries = cpu_to_le16(1);
1659 if (S_ISDIR(inode->i_mode))
1660 fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
1661 else if (S_ISREG(inode->i_mode))
1662 fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
1663 else if (S_ISLNK(inode->i_mode))
1664 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
1665 else if (S_ISBLK(inode->i_mode))
1666 fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
1667 else if (S_ISCHR(inode->i_mode))
1668 fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
1669 else if (S_ISFIFO(inode->i_mode))
1670 fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
1671 else if (S_ISSOCK(inode->i_mode))
1672 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1674 icbflags = UDF_I_ALLOCTYPE(inode) |
1675 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1676 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1677 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1678 (le16_to_cpu(fe->icbTag.flags) &
1679 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1680 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1682 fe->icbTag.flags = cpu_to_le16(icbflags);
1683 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
1684 fe->descTag.descVersion = cpu_to_le16(3);
1686 fe->descTag.descVersion = cpu_to_le16(2);
1687 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
1688 fe->descTag.tagLocation =
1689 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1690 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1691 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1692 fe->descTag.descCRC =
1693 cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1695 fe->descTag.tagChecksum = 0;
1696 for (i = 0; i < 16; i++)
1698 fe->descTag.tagChecksum +=
1699 ((uint8_t *) & (fe->descTag))[i];
1701 /* write the data blocks */
1702 mark_buffer_dirty(bh);
1704 sync_dirty_buffer(bh);
1705 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1706 printk("IO error syncing udf inode [%s:%08lx]\n",
1707 inode->i_sb->s_id, inode->i_ino);
1715 struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1717 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1718 struct inode *inode = iget_locked(sb, block);
1723 if (inode->i_state & I_NEW) {
1724 memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr));
1725 __udf_read_inode(inode);
1726 unlock_new_inode(inode);
1729 if (is_bad_inode(inode))
1732 if (ino.logicalBlockNum >=
1733 UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1734 udf_debug("block=%d, partition=%d out of range\n",
1735 ino.logicalBlockNum, ino.partitionReferenceNum);
1736 make_bad_inode(inode);
1747 int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1748 kernel_lb_addr eloc, uint32_t elen, int inc)
1751 short_ad *sad = NULL;
1752 long_ad *lad = NULL;
1753 struct allocExtDesc *aed;
1759 UDF_I_DATA(inode) + epos->offset -
1760 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1762 ptr = epos->bh->b_data + epos->offset;
1764 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
1765 adsize = sizeof(short_ad);
1766 else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
1767 adsize = sizeof(long_ad);
1771 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1773 struct buffer_head *nbh;
1775 kernel_lb_addr obloc = epos->block;
1778 (epos->block.logicalBlockNum =
1779 udf_new_block(inode->i_sb, NULL,
1780 obloc.partitionReferenceNum,
1781 obloc.logicalBlockNum, &err))) {
1786 udf_tgetblk(inode->i_sb,
1787 udf_get_lb_pblock(inode->i_sb, epos->block,
1792 memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
1793 set_buffer_uptodate(nbh);
1795 mark_buffer_dirty_inode(nbh, inode);
1797 aed = (struct allocExtDesc *)(nbh->b_data);
1798 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1799 aed->previousAllocExtLocation =
1800 cpu_to_le32(obloc.logicalBlockNum);
1801 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1802 loffset = epos->offset;
1803 aed->lengthAllocDescs = cpu_to_le32(adsize);
1804 sptr = ptr - adsize;
1805 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1806 memcpy(dptr, sptr, adsize);
1807 epos->offset = sizeof(struct allocExtDesc) + adsize;
1809 loffset = epos->offset + adsize;
1810 aed->lengthAllocDescs = cpu_to_le32(0);
1812 epos->offset = sizeof(struct allocExtDesc);
1815 aed = (struct allocExtDesc *)epos->bh->b_data;
1816 aed->lengthAllocDescs =
1817 cpu_to_le32(le32_to_cpu
1818 (aed->lengthAllocDescs) +
1821 UDF_I_LENALLOC(inode) += adsize;
1822 mark_inode_dirty(inode);
1825 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
1826 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1827 epos->block.logicalBlockNum, sizeof(tag));
1829 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1830 epos->block.logicalBlockNum, sizeof(tag));
1831 switch (UDF_I_ALLOCTYPE(inode)) {
1832 case ICBTAG_FLAG_AD_SHORT:
1834 sad = (short_ad *) sptr;
1836 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1837 inode->i_sb->s_blocksize);
1839 cpu_to_le32(epos->block.logicalBlockNum);
1842 case ICBTAG_FLAG_AD_LONG:
1844 lad = (long_ad *) sptr;
1846 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1847 inode->i_sb->s_blocksize);
1848 lad->extLocation = cpu_to_lelb(epos->block);
1849 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1855 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1856 udf_update_tag(epos->bh->b_data, loffset);
1858 udf_update_tag(epos->bh->b_data,
1859 sizeof(struct allocExtDesc));
1860 mark_buffer_dirty_inode(epos->bh, inode);
1863 mark_inode_dirty(inode);
1867 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1870 UDF_I_LENALLOC(inode) += adsize;
1871 mark_inode_dirty(inode);
1873 aed = (struct allocExtDesc *)epos->bh->b_data;
1874 aed->lengthAllocDescs =
1875 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1876 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1877 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1878 udf_update_tag(epos->bh->b_data,
1879 epos->offset + (inc ? 0 : adsize));
1881 udf_update_tag(epos->bh->b_data,
1882 sizeof(struct allocExtDesc));
1883 mark_buffer_dirty_inode(epos->bh, inode);
1889 int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
1890 kernel_lb_addr eloc, uint32_t elen, int inc)
1897 UDF_I_DATA(inode) + epos->offset -
1898 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1900 ptr = epos->bh->b_data + epos->offset;
1902 switch (UDF_I_ALLOCTYPE(inode)) {
1903 case ICBTAG_FLAG_AD_SHORT:
1905 short_ad *sad = (short_ad *) ptr;
1906 sad->extLength = cpu_to_le32(elen);
1907 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1908 adsize = sizeof(short_ad);
1911 case ICBTAG_FLAG_AD_LONG:
1913 long_ad *lad = (long_ad *) ptr;
1914 lad->extLength = cpu_to_le32(elen);
1915 lad->extLocation = cpu_to_lelb(eloc);
1916 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1917 adsize = sizeof(long_ad);
1925 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1926 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
1927 struct allocExtDesc *aed =
1928 (struct allocExtDesc *)epos->bh->b_data;
1929 udf_update_tag(epos->bh->b_data,
1930 le32_to_cpu(aed->lengthAllocDescs) +
1931 sizeof(struct allocExtDesc));
1933 mark_buffer_dirty_inode(epos->bh, inode);
1935 mark_inode_dirty(inode);
1938 epos->offset += adsize;
1939 return (elen >> 30);
1942 int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
1943 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1947 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1948 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1949 epos->block = *eloc;
1950 epos->offset = sizeof(struct allocExtDesc);
1954 udf_tread(inode->i_sb,
1955 udf_get_lb_pblock(inode->i_sb, epos->block,
1957 udf_debug("reading block %d failed!\n",
1958 udf_get_lb_pblock(inode->i_sb, epos->block,
1967 int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
1968 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1976 epos->offset = udf_file_entry_alloc_offset(inode);
1978 UDF_I_DATA(inode) + epos->offset -
1979 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1981 udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1984 epos->offset = sizeof(struct allocExtDesc);
1985 ptr = epos->bh->b_data + epos->offset;
1987 sizeof(struct allocExtDesc) +
1988 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1992 switch (UDF_I_ALLOCTYPE(inode)) {
1993 case ICBTAG_FLAG_AD_SHORT:
1999 udf_get_fileshortad(ptr, alen, &epos->offset,
2003 etype = le32_to_cpu(sad->extLength) >> 30;
2004 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
2005 eloc->partitionReferenceNum =
2006 UDF_I_LOCATION(inode).partitionReferenceNum;
2009 extLength) & UDF_EXTENT_LENGTH_MASK;
2012 case ICBTAG_FLAG_AD_LONG:
2018 udf_get_filelongad(ptr, alen, &epos->offset, inc)))
2021 etype = le32_to_cpu(lad->extLength) >> 30;
2022 *eloc = lelb_to_cpu(lad->extLocation);
2025 extLength) & UDF_EXTENT_LENGTH_MASK;
2030 udf_debug("alloc_type = %d unsupported\n",
2031 UDF_I_ALLOCTYPE(inode));
2040 udf_insert_aext(struct inode *inode, struct extent_position epos,
2041 kernel_lb_addr neloc, uint32_t nelen)
2043 kernel_lb_addr oeloc;
2050 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
2051 udf_write_aext(inode, &epos, neloc, nelen, 1);
2054 nelen = (etype << 30) | oelen;
2056 udf_add_aext(inode, &epos, neloc, nelen, 1);
2058 return (nelen >> 30);
2061 int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
2062 kernel_lb_addr eloc, uint32_t elen)
2064 struct extent_position oepos;
2067 struct allocExtDesc *aed;
2074 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
2075 adsize = sizeof(short_ad);
2076 else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
2077 adsize = sizeof(long_ad);
2082 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2085 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2086 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2087 if (oepos.bh != epos.bh) {
2088 oepos.block = epos.block;
2092 oepos.offset = epos.offset - adsize;
2095 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2098 if (epos.bh != oepos.bh) {
2099 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2100 udf_write_aext(inode, &oepos, eloc, elen, 1);
2101 udf_write_aext(inode, &oepos, eloc, elen, 1);
2103 UDF_I_LENALLOC(inode) -= (adsize * 2);
2104 mark_inode_dirty(inode);
2106 aed = (struct allocExtDesc *)oepos.bh->b_data;
2107 aed->lengthAllocDescs =
2108 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2110 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2111 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2112 udf_update_tag(oepos.bh->b_data,
2113 oepos.offset - (2 * adsize));
2115 udf_update_tag(oepos.bh->b_data,
2116 sizeof(struct allocExtDesc));
2117 mark_buffer_dirty_inode(oepos.bh, inode);
2120 udf_write_aext(inode, &oepos, eloc, elen, 1);
2122 UDF_I_LENALLOC(inode) -= adsize;
2123 mark_inode_dirty(inode);
2125 aed = (struct allocExtDesc *)oepos.bh->b_data;
2126 aed->lengthAllocDescs =
2127 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2129 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2130 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2131 udf_update_tag(oepos.bh->b_data,
2132 epos.offset - adsize);
2134 udf_update_tag(oepos.bh->b_data,
2135 sizeof(struct allocExtDesc));
2136 mark_buffer_dirty_inode(oepos.bh, inode);
2142 return (elen >> 30);
2145 int8_t inode_bmap(struct inode * inode, sector_t block,
2146 struct extent_position * pos, kernel_lb_addr * eloc,
2147 uint32_t * elen, sector_t * offset)
2149 loff_t lbcount = 0, bcount =
2150 (loff_t) block << inode->i_sb->s_blocksize_bits;
2154 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2159 pos->block = UDF_I_LOCATION(inode);
2164 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
2166 (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2167 UDF_I_LENEXTENTS(inode) = lbcount;
2171 } while (lbcount <= bcount);
2173 *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
2178 long udf_block_map(struct inode *inode, sector_t block)
2180 kernel_lb_addr eloc;
2183 struct extent_position epos = { NULL, 0, {0, 0} };
2188 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2189 (EXT_RECORDED_ALLOCATED >> 30))
2190 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2197 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
2198 return udf_fixed_to_variable(ret);