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/module.h>
35 #include <linux/pagemap.h>
36 #include <linux/buffer_head.h>
37 #include <linux/writeback.h>
38 #include <linux/slab.h>
39 #include <linux/crc-itu-t.h>
40 #include <linux/mpage.h>
45 MODULE_AUTHOR("Ben Fennema");
46 MODULE_DESCRIPTION("Universal Disk Format Filesystem");
47 MODULE_LICENSE("GPL");
49 #define EXTENT_MERGE_SIZE 5
51 static mode_t udf_convert_permissions(struct fileEntry *);
52 static int udf_update_inode(struct inode *, int);
53 static void udf_fill_inode(struct inode *, struct buffer_head *);
54 static int udf_sync_inode(struct inode *inode);
55 static int udf_alloc_i_data(struct inode *inode, size_t size);
56 static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
58 static int8_t udf_insert_aext(struct inode *, struct extent_position,
59 struct kernel_lb_addr, uint32_t);
60 static void udf_split_extents(struct inode *, int *, int, int,
61 struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
62 static void udf_prealloc_extents(struct inode *, int, int,
63 struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
64 static void udf_merge_extents(struct inode *,
65 struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
66 static void udf_update_extents(struct inode *,
67 struct kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
68 struct extent_position *);
69 static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
72 void udf_evict_inode(struct inode *inode)
74 struct udf_inode_info *iinfo = UDF_I(inode);
77 if (!inode->i_nlink && !is_bad_inode(inode)) {
79 udf_setsize(inode, 0);
80 udf_update_inode(inode, IS_SYNC(inode));
82 truncate_inode_pages(&inode->i_data, 0);
83 invalidate_inode_buffers(inode);
85 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB &&
86 inode->i_size != iinfo->i_lenExtents) {
87 printk(KERN_WARNING "UDF-fs (%s): Inode %lu (mode %o) has "
88 "inode size %llu different from extent length %llu. "
89 "Filesystem need not be standards compliant.\n",
90 inode->i_sb->s_id, inode->i_ino, inode->i_mode,
91 (unsigned long long)inode->i_size,
92 (unsigned long long)iinfo->i_lenExtents);
94 kfree(iinfo->i_ext.i_data);
95 iinfo->i_ext.i_data = NULL;
97 udf_free_inode(inode);
101 static int udf_writepage(struct page *page, struct writeback_control *wbc)
103 return block_write_full_page(page, udf_get_block, wbc);
106 static int udf_readpage(struct file *file, struct page *page)
108 return mpage_readpage(page, udf_get_block);
111 static int udf_readpages(struct file *file, struct address_space *mapping,
112 struct list_head *pages, unsigned nr_pages)
114 return mpage_readpages(mapping, pages, nr_pages, udf_get_block);
117 static int udf_write_begin(struct file *file, struct address_space *mapping,
118 loff_t pos, unsigned len, unsigned flags,
119 struct page **pagep, void **fsdata)
123 ret = block_write_begin(mapping, pos, len, flags, pagep, udf_get_block);
125 struct inode *inode = mapping->host;
126 struct udf_inode_info *iinfo = UDF_I(inode);
127 loff_t isize = inode->i_size;
129 if (pos + len > isize) {
130 truncate_pagecache(inode, pos + len, isize);
131 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
132 down_write(&iinfo->i_data_sem);
133 udf_truncate_extents(inode);
134 up_write(&iinfo->i_data_sem);
142 static sector_t udf_bmap(struct address_space *mapping, sector_t block)
144 return generic_block_bmap(mapping, block, udf_get_block);
147 const struct address_space_operations udf_aops = {
148 .readpage = udf_readpage,
149 .readpages = udf_readpages,
150 .writepage = udf_writepage,
151 .write_begin = udf_write_begin,
152 .write_end = generic_write_end,
156 int udf_expand_file_adinicb(struct inode *inode)
160 struct udf_inode_info *iinfo = UDF_I(inode);
162 struct writeback_control udf_wbc = {
163 .sync_mode = WB_SYNC_NONE,
167 if (!iinfo->i_lenAlloc) {
168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
169 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
171 iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
172 /* from now on we have normal address_space methods */
173 inode->i_data.a_ops = &udf_aops;
174 mark_inode_dirty(inode);
178 page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
182 if (!PageUptodate(page)) {
184 memset(kaddr + iinfo->i_lenAlloc, 0x00,
185 PAGE_CACHE_SIZE - iinfo->i_lenAlloc);
186 memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr,
188 flush_dcache_page(page);
189 SetPageUptodate(page);
192 memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0x00,
194 iinfo->i_lenAlloc = 0;
195 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
196 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
198 iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
199 /* from now on we have normal address_space methods */
200 inode->i_data.a_ops = &udf_aops;
201 err = inode->i_data.a_ops->writepage(page, &udf_wbc);
203 /* Restore everything back so that we don't lose data... */
206 memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr,
210 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
211 inode->i_data.a_ops = &udf_adinicb_aops;
213 page_cache_release(page);
214 mark_inode_dirty(inode);
219 struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
223 struct buffer_head *dbh = NULL;
224 struct kernel_lb_addr eloc;
226 struct extent_position epos;
228 struct udf_fileident_bh sfibh, dfibh;
229 loff_t f_pos = udf_ext0_offset(inode);
230 int size = udf_ext0_offset(inode) + inode->i_size;
231 struct fileIdentDesc cfi, *sfi, *dfi;
232 struct udf_inode_info *iinfo = UDF_I(inode);
234 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
235 alloctype = ICBTAG_FLAG_AD_SHORT;
237 alloctype = ICBTAG_FLAG_AD_LONG;
239 if (!inode->i_size) {
240 iinfo->i_alloc_type = alloctype;
241 mark_inode_dirty(inode);
245 /* alloc block, and copy data to it */
246 *block = udf_new_block(inode->i_sb, inode,
247 iinfo->i_location.partitionReferenceNum,
248 iinfo->i_location.logicalBlockNum, err);
251 newblock = udf_get_pblock(inode->i_sb, *block,
252 iinfo->i_location.partitionReferenceNum,
256 dbh = udf_tgetblk(inode->i_sb, newblock);
260 memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
261 set_buffer_uptodate(dbh);
263 mark_buffer_dirty_inode(dbh, inode);
265 sfibh.soffset = sfibh.eoffset =
266 f_pos & (inode->i_sb->s_blocksize - 1);
267 sfibh.sbh = sfibh.ebh = NULL;
268 dfibh.soffset = dfibh.eoffset = 0;
269 dfibh.sbh = dfibh.ebh = dbh;
270 while (f_pos < size) {
271 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
272 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
278 iinfo->i_alloc_type = alloctype;
279 sfi->descTag.tagLocation = cpu_to_le32(*block);
280 dfibh.soffset = dfibh.eoffset;
281 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
282 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
283 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
285 le16_to_cpu(sfi->lengthOfImpUse))) {
286 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
291 mark_buffer_dirty_inode(dbh, inode);
293 memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0,
295 iinfo->i_lenAlloc = 0;
296 eloc.logicalBlockNum = *block;
297 eloc.partitionReferenceNum =
298 iinfo->i_location.partitionReferenceNum;
299 iinfo->i_lenExtents = inode->i_size;
301 epos.block = iinfo->i_location;
302 epos.offset = udf_file_entry_alloc_offset(inode);
303 udf_add_aext(inode, &epos, &eloc, inode->i_size, 0);
307 mark_inode_dirty(inode);
311 static int udf_get_block(struct inode *inode, sector_t block,
312 struct buffer_head *bh_result, int create)
315 struct buffer_head *bh;
317 struct udf_inode_info *iinfo;
320 phys = udf_block_map(inode, block);
322 map_bh(bh_result, inode->i_sb, phys);
329 iinfo = UDF_I(inode);
331 down_write(&iinfo->i_data_sem);
332 if (block == iinfo->i_next_alloc_block + 1) {
333 iinfo->i_next_alloc_block++;
334 iinfo->i_next_alloc_goal++;
339 bh = inode_getblk(inode, block, &err, &phys, &new);
346 set_buffer_new(bh_result);
347 map_bh(bh_result, inode->i_sb, phys);
350 up_write(&iinfo->i_data_sem);
354 static struct buffer_head *udf_getblk(struct inode *inode, long block,
355 int create, int *err)
357 struct buffer_head *bh;
358 struct buffer_head dummy;
361 dummy.b_blocknr = -1000;
362 *err = udf_get_block(inode, block, &dummy, create);
363 if (!*err && buffer_mapped(&dummy)) {
364 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
365 if (buffer_new(&dummy)) {
367 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
368 set_buffer_uptodate(bh);
370 mark_buffer_dirty_inode(bh, inode);
378 /* Extend the file by 'blocks' blocks, return the number of extents added */
379 static int udf_do_extend_file(struct inode *inode,
380 struct extent_position *last_pos,
381 struct kernel_long_ad *last_ext,
385 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
386 struct super_block *sb = inode->i_sb;
387 struct kernel_lb_addr prealloc_loc = {};
388 int prealloc_len = 0;
389 struct udf_inode_info *iinfo;
392 /* The previous extent is fake and we should not extend by anything
393 * - there's nothing to do... */
397 iinfo = UDF_I(inode);
398 /* Round the last extent up to a multiple of block size */
399 if (last_ext->extLength & (sb->s_blocksize - 1)) {
400 last_ext->extLength =
401 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
402 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
403 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
404 iinfo->i_lenExtents =
405 (iinfo->i_lenExtents + sb->s_blocksize - 1) &
406 ~(sb->s_blocksize - 1);
409 /* Last extent are just preallocated blocks? */
410 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
411 EXT_NOT_RECORDED_ALLOCATED) {
412 /* Save the extent so that we can reattach it to the end */
413 prealloc_loc = last_ext->extLocation;
414 prealloc_len = last_ext->extLength;
415 /* Mark the extent as a hole */
416 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
417 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
418 last_ext->extLocation.logicalBlockNum = 0;
419 last_ext->extLocation.partitionReferenceNum = 0;
422 /* Can we merge with the previous extent? */
423 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
424 EXT_NOT_RECORDED_NOT_ALLOCATED) {
425 add = ((1 << 30) - sb->s_blocksize -
426 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >>
427 sb->s_blocksize_bits;
431 last_ext->extLength += add << sb->s_blocksize_bits;
435 udf_add_aext(inode, last_pos, &last_ext->extLocation,
436 last_ext->extLength, 1);
439 udf_write_aext(inode, last_pos, &last_ext->extLocation,
440 last_ext->extLength, 1);
442 /* Managed to do everything necessary? */
446 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
447 last_ext->extLocation.logicalBlockNum = 0;
448 last_ext->extLocation.partitionReferenceNum = 0;
449 add = (1 << (30-sb->s_blocksize_bits)) - 1;
450 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
451 (add << sb->s_blocksize_bits);
453 /* Create enough extents to cover the whole hole */
454 while (blocks > add) {
456 err = udf_add_aext(inode, last_pos, &last_ext->extLocation,
457 last_ext->extLength, 1);
463 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
464 (blocks << sb->s_blocksize_bits);
465 err = udf_add_aext(inode, last_pos, &last_ext->extLocation,
466 last_ext->extLength, 1);
473 /* Do we have some preallocated blocks saved? */
475 err = udf_add_aext(inode, last_pos, &prealloc_loc,
479 last_ext->extLocation = prealloc_loc;
480 last_ext->extLength = prealloc_len;
484 /* last_pos should point to the last written extent... */
485 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
486 last_pos->offset -= sizeof(struct short_ad);
487 else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
488 last_pos->offset -= sizeof(struct long_ad);
495 static int udf_extend_file(struct inode *inode, loff_t newsize)
498 struct extent_position epos;
499 struct kernel_lb_addr eloc;
502 struct super_block *sb = inode->i_sb;
503 sector_t first_block = newsize >> sb->s_blocksize_bits, offset;
505 struct udf_inode_info *iinfo = UDF_I(inode);
506 struct kernel_long_ad extent;
509 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
510 adsize = sizeof(struct short_ad);
511 else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
512 adsize = sizeof(struct long_ad);
516 etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset);
518 /* File has extent covering the new size (could happen when extending
519 * inside a block)? */
522 if (newsize & (sb->s_blocksize - 1))
524 /* Extended file just to the boundary of the last file block? */
528 /* Truncate is extending the file by 'offset' blocks */
529 if ((!epos.bh && epos.offset == udf_file_entry_alloc_offset(inode)) ||
530 (epos.bh && epos.offset == sizeof(struct allocExtDesc))) {
531 /* File has no extents at all or has empty last
532 * indirect extent! Create a fake extent... */
533 extent.extLocation.logicalBlockNum = 0;
534 extent.extLocation.partitionReferenceNum = 0;
535 extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
537 epos.offset -= adsize;
538 etype = udf_next_aext(inode, &epos, &extent.extLocation,
539 &extent.extLength, 0);
540 extent.extLength |= etype << 30;
542 err = udf_do_extend_file(inode, &epos, &extent, offset);
546 iinfo->i_lenExtents = newsize;
552 static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
553 int *err, sector_t *phys, int *new)
555 static sector_t last_block;
556 struct buffer_head *result = NULL;
557 struct kernel_long_ad laarr[EXTENT_MERGE_SIZE];
558 struct extent_position prev_epos, cur_epos, next_epos;
559 int count = 0, startnum = 0, endnum = 0;
560 uint32_t elen = 0, tmpelen;
561 struct kernel_lb_addr eloc, tmpeloc;
563 loff_t lbcount = 0, b_off = 0;
564 uint32_t newblocknum, newblock;
567 struct udf_inode_info *iinfo = UDF_I(inode);
568 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
571 prev_epos.offset = udf_file_entry_alloc_offset(inode);
572 prev_epos.block = iinfo->i_location;
574 cur_epos = next_epos = prev_epos;
575 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
577 /* find the extent which contains the block we are looking for.
578 alternate between laarr[0] and laarr[1] for locations of the
579 current extent, and the previous extent */
581 if (prev_epos.bh != cur_epos.bh) {
582 brelse(prev_epos.bh);
584 prev_epos.bh = cur_epos.bh;
586 if (cur_epos.bh != next_epos.bh) {
588 get_bh(next_epos.bh);
589 cur_epos.bh = next_epos.bh;
594 prev_epos.block = cur_epos.block;
595 cur_epos.block = next_epos.block;
597 prev_epos.offset = cur_epos.offset;
598 cur_epos.offset = next_epos.offset;
600 etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1);
606 laarr[c].extLength = (etype << 30) | elen;
607 laarr[c].extLocation = eloc;
609 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
610 pgoal = eloc.logicalBlockNum +
611 ((elen + inode->i_sb->s_blocksize - 1) >>
612 inode->i_sb->s_blocksize_bits);
615 } while (lbcount + elen <= b_off);
618 offset = b_off >> inode->i_sb->s_blocksize_bits;
620 * Move prev_epos and cur_epos into indirect extent if we are at
623 udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
624 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
626 /* if the extent is allocated and recorded, return the block
627 if the extent is not a multiple of the blocksize, round up */
629 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
630 if (elen & (inode->i_sb->s_blocksize - 1)) {
631 elen = EXT_RECORDED_ALLOCATED |
632 ((elen + inode->i_sb->s_blocksize - 1) &
633 ~(inode->i_sb->s_blocksize - 1));
634 udf_write_aext(inode, &cur_epos, &eloc, elen, 1);
636 brelse(prev_epos.bh);
638 brelse(next_epos.bh);
639 newblock = udf_get_lb_pblock(inode->i_sb, &eloc, offset);
645 /* Are we beyond EOF? */
654 /* Create a fake extent when there's not one */
655 memset(&laarr[0].extLocation, 0x00,
656 sizeof(struct kernel_lb_addr));
657 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
658 /* Will udf_do_extend_file() create real extent from
660 startnum = (offset > 0);
662 /* Create extents for the hole between EOF and offset */
663 ret = udf_do_extend_file(inode, &prev_epos, laarr, offset);
665 brelse(prev_epos.bh);
667 brelse(next_epos.bh);
674 /* We are not covered by a preallocated extent? */
675 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
676 EXT_NOT_RECORDED_ALLOCATED) {
677 /* Is there any real extent? - otherwise we overwrite
681 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
682 inode->i_sb->s_blocksize;
683 memset(&laarr[c].extLocation, 0x00,
684 sizeof(struct kernel_lb_addr));
691 endnum = startnum = ((count > 2) ? 2 : count);
693 /* if the current extent is in position 0,
694 swap it with the previous */
695 if (!c && count != 1) {
702 /* if the current block is located in an extent,
703 read the next extent */
704 etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0);
706 laarr[c + 1].extLength = (etype << 30) | elen;
707 laarr[c + 1].extLocation = eloc;
715 /* if the current extent is not recorded but allocated, get the
716 * block in the extent corresponding to the requested block */
717 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
718 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
719 else { /* otherwise, allocate a new block */
720 if (iinfo->i_next_alloc_block == block)
721 goal = iinfo->i_next_alloc_goal;
724 if (!(goal = pgoal)) /* XXX: what was intended here? */
725 goal = iinfo->i_location.logicalBlockNum + 1;
728 newblocknum = udf_new_block(inode->i_sb, inode,
729 iinfo->i_location.partitionReferenceNum,
732 brelse(prev_epos.bh);
736 iinfo->i_lenExtents += inode->i_sb->s_blocksize;
739 /* if the extent the requsted block is located in contains multiple
740 * blocks, split the extent into at most three extents. blocks prior
741 * to requested block, requested block, and blocks after requested
743 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
745 #ifdef UDF_PREALLOCATE
746 /* We preallocate blocks only for regular files. It also makes sense
747 * for directories but there's a problem when to drop the
748 * preallocation. We might use some delayed work for that but I feel
749 * it's overengineering for a filesystem like UDF. */
750 if (S_ISREG(inode->i_mode))
751 udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
754 /* merge any continuous blocks in laarr */
755 udf_merge_extents(inode, laarr, &endnum);
757 /* write back the new extents, inserting new extents if the new number
758 * of extents is greater than the old number, and deleting extents if
759 * the new number of extents is less than the old number */
760 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
762 brelse(prev_epos.bh);
764 newblock = udf_get_pblock(inode->i_sb, newblocknum,
765 iinfo->i_location.partitionReferenceNum, 0);
771 iinfo->i_next_alloc_block = block;
772 iinfo->i_next_alloc_goal = newblocknum;
773 inode->i_ctime = current_fs_time(inode->i_sb);
776 udf_sync_inode(inode);
778 mark_inode_dirty(inode);
783 static void udf_split_extents(struct inode *inode, int *c, int offset,
785 struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
788 unsigned long blocksize = inode->i_sb->s_blocksize;
789 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
791 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
792 (laarr[*c].extLength >> 30) ==
793 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
795 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
796 blocksize - 1) >> blocksize_bits;
797 int8_t etype = (laarr[curr].extLength >> 30);
801 else if (!offset || blen == offset + 1) {
802 laarr[curr + 2] = laarr[curr + 1];
803 laarr[curr + 1] = laarr[curr];
805 laarr[curr + 3] = laarr[curr + 1];
806 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
810 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
811 udf_free_blocks(inode->i_sb, inode,
812 &laarr[curr].extLocation,
814 laarr[curr].extLength =
815 EXT_NOT_RECORDED_NOT_ALLOCATED |
816 (offset << blocksize_bits);
817 laarr[curr].extLocation.logicalBlockNum = 0;
818 laarr[curr].extLocation.
819 partitionReferenceNum = 0;
821 laarr[curr].extLength = (etype << 30) |
822 (offset << blocksize_bits);
828 laarr[curr].extLocation.logicalBlockNum = newblocknum;
829 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
830 laarr[curr].extLocation.partitionReferenceNum =
831 UDF_I(inode)->i_location.partitionReferenceNum;
832 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
836 if (blen != offset + 1) {
837 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
838 laarr[curr].extLocation.logicalBlockNum +=
840 laarr[curr].extLength = (etype << 30) |
841 ((blen - (offset + 1)) << blocksize_bits);
848 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
849 struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
852 int start, length = 0, currlength = 0, i;
854 if (*endnum >= (c + 1)) {
860 if ((laarr[c + 1].extLength >> 30) ==
861 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
863 length = currlength =
864 (((laarr[c + 1].extLength &
865 UDF_EXTENT_LENGTH_MASK) +
866 inode->i_sb->s_blocksize - 1) >>
867 inode->i_sb->s_blocksize_bits);
872 for (i = start + 1; i <= *endnum; i++) {
875 length += UDF_DEFAULT_PREALLOC_BLOCKS;
876 } else if ((laarr[i].extLength >> 30) ==
877 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
878 length += (((laarr[i].extLength &
879 UDF_EXTENT_LENGTH_MASK) +
880 inode->i_sb->s_blocksize - 1) >>
881 inode->i_sb->s_blocksize_bits);
887 int next = laarr[start].extLocation.logicalBlockNum +
888 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
889 inode->i_sb->s_blocksize - 1) >>
890 inode->i_sb->s_blocksize_bits);
891 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
892 laarr[start].extLocation.partitionReferenceNum,
893 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
894 length : UDF_DEFAULT_PREALLOC_BLOCKS) -
897 if (start == (c + 1))
898 laarr[start].extLength +=
900 inode->i_sb->s_blocksize_bits);
902 memmove(&laarr[c + 2], &laarr[c + 1],
903 sizeof(struct long_ad) * (*endnum - (c + 1)));
905 laarr[c + 1].extLocation.logicalBlockNum = next;
906 laarr[c + 1].extLocation.partitionReferenceNum =
907 laarr[c].extLocation.
908 partitionReferenceNum;
909 laarr[c + 1].extLength =
910 EXT_NOT_RECORDED_ALLOCATED |
912 inode->i_sb->s_blocksize_bits);
916 for (i = start + 1; numalloc && i < *endnum; i++) {
917 int elen = ((laarr[i].extLength &
918 UDF_EXTENT_LENGTH_MASK) +
919 inode->i_sb->s_blocksize - 1) >>
920 inode->i_sb->s_blocksize_bits;
922 if (elen > numalloc) {
923 laarr[i].extLength -=
925 inode->i_sb->s_blocksize_bits);
929 if (*endnum > (i + 1))
932 sizeof(struct long_ad) *
933 (*endnum - (i + 1)));
938 UDF_I(inode)->i_lenExtents +=
939 numalloc << inode->i_sb->s_blocksize_bits;
944 static void udf_merge_extents(struct inode *inode,
945 struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
949 unsigned long blocksize = inode->i_sb->s_blocksize;
950 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
952 for (i = 0; i < (*endnum - 1); i++) {
953 struct kernel_long_ad *li /*l[i]*/ = &laarr[i];
954 struct kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
956 if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
957 (((li->extLength >> 30) ==
958 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
959 ((lip1->extLocation.logicalBlockNum -
960 li->extLocation.logicalBlockNum) ==
961 (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
962 blocksize - 1) >> blocksize_bits)))) {
964 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
965 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
966 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
967 lip1->extLength = (lip1->extLength -
969 UDF_EXTENT_LENGTH_MASK) +
970 UDF_EXTENT_LENGTH_MASK) &
972 li->extLength = (li->extLength &
973 UDF_EXTENT_FLAG_MASK) +
974 (UDF_EXTENT_LENGTH_MASK + 1) -
976 lip1->extLocation.logicalBlockNum =
977 li->extLocation.logicalBlockNum +
979 UDF_EXTENT_LENGTH_MASK) >>
982 li->extLength = lip1->extLength +
984 UDF_EXTENT_LENGTH_MASK) +
985 blocksize - 1) & ~(blocksize - 1));
986 if (*endnum > (i + 2))
987 memmove(&laarr[i + 1], &laarr[i + 2],
988 sizeof(struct long_ad) *
989 (*endnum - (i + 2)));
993 } else if (((li->extLength >> 30) ==
994 (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
995 ((lip1->extLength >> 30) ==
996 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
997 udf_free_blocks(inode->i_sb, inode, &li->extLocation, 0,
999 UDF_EXTENT_LENGTH_MASK) +
1000 blocksize - 1) >> blocksize_bits);
1001 li->extLocation.logicalBlockNum = 0;
1002 li->extLocation.partitionReferenceNum = 0;
1004 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
1005 (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
1006 blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
1007 lip1->extLength = (lip1->extLength -
1009 UDF_EXTENT_LENGTH_MASK) +
1010 UDF_EXTENT_LENGTH_MASK) &
1012 li->extLength = (li->extLength &
1013 UDF_EXTENT_FLAG_MASK) +
1014 (UDF_EXTENT_LENGTH_MASK + 1) -
1017 li->extLength = lip1->extLength +
1019 UDF_EXTENT_LENGTH_MASK) +
1020 blocksize - 1) & ~(blocksize - 1));
1021 if (*endnum > (i + 2))
1022 memmove(&laarr[i + 1], &laarr[i + 2],
1023 sizeof(struct long_ad) *
1024 (*endnum - (i + 2)));
1028 } else if ((li->extLength >> 30) ==
1029 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
1030 udf_free_blocks(inode->i_sb, inode,
1031 &li->extLocation, 0,
1033 UDF_EXTENT_LENGTH_MASK) +
1034 blocksize - 1) >> blocksize_bits);
1035 li->extLocation.logicalBlockNum = 0;
1036 li->extLocation.partitionReferenceNum = 0;
1037 li->extLength = (li->extLength &
1038 UDF_EXTENT_LENGTH_MASK) |
1039 EXT_NOT_RECORDED_NOT_ALLOCATED;
1044 static void udf_update_extents(struct inode *inode,
1045 struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
1046 int startnum, int endnum,
1047 struct extent_position *epos)
1050 struct kernel_lb_addr tmploc;
1053 if (startnum > endnum) {
1054 for (i = 0; i < (startnum - endnum); i++)
1055 udf_delete_aext(inode, *epos, laarr[i].extLocation,
1056 laarr[i].extLength);
1057 } else if (startnum < endnum) {
1058 for (i = 0; i < (endnum - startnum); i++) {
1059 udf_insert_aext(inode, *epos, laarr[i].extLocation,
1060 laarr[i].extLength);
1061 udf_next_aext(inode, epos, &laarr[i].extLocation,
1062 &laarr[i].extLength, 1);
1067 for (i = start; i < endnum; i++) {
1068 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
1069 udf_write_aext(inode, epos, &laarr[i].extLocation,
1070 laarr[i].extLength, 1);
1074 struct buffer_head *udf_bread(struct inode *inode, int block,
1075 int create, int *err)
1077 struct buffer_head *bh = NULL;
1079 bh = udf_getblk(inode, block, create, err);
1083 if (buffer_uptodate(bh))
1086 ll_rw_block(READ, 1, &bh);
1089 if (buffer_uptodate(bh))
1097 int udf_setsize(struct inode *inode, loff_t newsize)
1100 struct udf_inode_info *iinfo;
1101 int bsize = 1 << inode->i_blkbits;
1103 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1104 S_ISLNK(inode->i_mode)))
1106 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1109 iinfo = UDF_I(inode);
1110 if (newsize > inode->i_size) {
1111 down_write(&iinfo->i_data_sem);
1112 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1114 (udf_file_entry_alloc_offset(inode) + newsize)) {
1115 err = udf_expand_file_adinicb(inode);
1117 up_write(&iinfo->i_data_sem);
1121 iinfo->i_lenAlloc = newsize;
1123 err = udf_extend_file(inode, newsize);
1125 up_write(&iinfo->i_data_sem);
1128 truncate_setsize(inode, newsize);
1129 up_write(&iinfo->i_data_sem);
1131 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1132 down_write(&iinfo->i_data_sem);
1133 memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr + newsize,
1134 0x00, bsize - newsize -
1135 udf_file_entry_alloc_offset(inode));
1136 iinfo->i_lenAlloc = newsize;
1137 truncate_setsize(inode, newsize);
1138 up_write(&iinfo->i_data_sem);
1141 err = block_truncate_page(inode->i_mapping, newsize,
1145 down_write(&iinfo->i_data_sem);
1146 truncate_setsize(inode, newsize);
1147 udf_truncate_extents(inode);
1148 up_write(&iinfo->i_data_sem);
1151 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1153 udf_sync_inode(inode);
1155 mark_inode_dirty(inode);
1159 static void __udf_read_inode(struct inode *inode)
1161 struct buffer_head *bh = NULL;
1162 struct fileEntry *fe;
1164 struct udf_inode_info *iinfo = UDF_I(inode);
1167 * Set defaults, but the inode is still incomplete!
1168 * Note: get_new_inode() sets the following on a new inode:
1171 * i_flags = sb->s_flags
1173 * clean_inode(): zero fills and sets
1178 bh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 0, &ident);
1180 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1182 make_bad_inode(inode);
1186 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1187 ident != TAG_IDENT_USE) {
1188 printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
1189 "failed ident=%d\n", inode->i_ino, ident);
1191 make_bad_inode(inode);
1195 fe = (struct fileEntry *)bh->b_data;
1197 if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
1198 struct buffer_head *ibh;
1200 ibh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 1,
1202 if (ident == TAG_IDENT_IE && ibh) {
1203 struct buffer_head *nbh = NULL;
1204 struct kernel_lb_addr loc;
1205 struct indirectEntry *ie;
1207 ie = (struct indirectEntry *)ibh->b_data;
1208 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1210 if (ie->indirectICB.extLength &&
1211 (nbh = udf_read_ptagged(inode->i_sb, &loc, 0,
1213 if (ident == TAG_IDENT_FE ||
1214 ident == TAG_IDENT_EFE) {
1215 memcpy(&iinfo->i_location,
1217 sizeof(struct kernel_lb_addr));
1221 __udf_read_inode(inode);
1228 } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
1229 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1230 le16_to_cpu(fe->icbTag.strategyType));
1232 make_bad_inode(inode);
1235 udf_fill_inode(inode, bh);
1240 static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1242 struct fileEntry *fe;
1243 struct extendedFileEntry *efe;
1245 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1246 struct udf_inode_info *iinfo = UDF_I(inode);
1248 fe = (struct fileEntry *)bh->b_data;
1249 efe = (struct extendedFileEntry *)bh->b_data;
1251 if (fe->icbTag.strategyType == cpu_to_le16(4))
1252 iinfo->i_strat4096 = 0;
1253 else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
1254 iinfo->i_strat4096 = 1;
1256 iinfo->i_alloc_type = le16_to_cpu(fe->icbTag.flags) &
1257 ICBTAG_FLAG_AD_MASK;
1258 iinfo->i_unique = 0;
1259 iinfo->i_lenEAttr = 0;
1260 iinfo->i_lenExtents = 0;
1261 iinfo->i_lenAlloc = 0;
1262 iinfo->i_next_alloc_block = 0;
1263 iinfo->i_next_alloc_goal = 0;
1264 if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) {
1267 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1268 sizeof(struct extendedFileEntry))) {
1269 make_bad_inode(inode);
1272 memcpy(iinfo->i_ext.i_data,
1273 bh->b_data + sizeof(struct extendedFileEntry),
1274 inode->i_sb->s_blocksize -
1275 sizeof(struct extendedFileEntry));
1276 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) {
1279 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1280 sizeof(struct fileEntry))) {
1281 make_bad_inode(inode);
1284 memcpy(iinfo->i_ext.i_data,
1285 bh->b_data + sizeof(struct fileEntry),
1286 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1287 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
1290 iinfo->i_lenAlloc = le32_to_cpu(
1291 ((struct unallocSpaceEntry *)bh->b_data)->
1293 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
1294 sizeof(struct unallocSpaceEntry))) {
1295 make_bad_inode(inode);
1298 memcpy(iinfo->i_ext.i_data,
1299 bh->b_data + sizeof(struct unallocSpaceEntry),
1300 inode->i_sb->s_blocksize -
1301 sizeof(struct unallocSpaceEntry));
1305 read_lock(&sbi->s_cred_lock);
1306 inode->i_uid = le32_to_cpu(fe->uid);
1307 if (inode->i_uid == -1 ||
1308 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
1309 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
1310 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1312 inode->i_gid = le32_to_cpu(fe->gid);
1313 if (inode->i_gid == -1 ||
1314 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
1315 UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
1316 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1318 if (fe->icbTag.fileType != ICBTAG_FILE_TYPE_DIRECTORY &&
1319 sbi->s_fmode != UDF_INVALID_MODE)
1320 inode->i_mode = sbi->s_fmode;
1321 else if (fe->icbTag.fileType == ICBTAG_FILE_TYPE_DIRECTORY &&
1322 sbi->s_dmode != UDF_INVALID_MODE)
1323 inode->i_mode = sbi->s_dmode;
1325 inode->i_mode = udf_convert_permissions(fe);
1326 inode->i_mode &= ~sbi->s_umask;
1327 read_unlock(&sbi->s_cred_lock);
1329 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1330 if (!inode->i_nlink)
1333 inode->i_size = le64_to_cpu(fe->informationLength);
1334 iinfo->i_lenExtents = inode->i_size;
1336 if (iinfo->i_efe == 0) {
1337 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1338 (inode->i_sb->s_blocksize_bits - 9);
1340 if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
1341 inode->i_atime = sbi->s_record_time;
1343 if (!udf_disk_stamp_to_time(&inode->i_mtime,
1344 fe->modificationTime))
1345 inode->i_mtime = sbi->s_record_time;
1347 if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
1348 inode->i_ctime = sbi->s_record_time;
1350 iinfo->i_unique = le64_to_cpu(fe->uniqueID);
1351 iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
1352 iinfo->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
1353 offset = sizeof(struct fileEntry) + iinfo->i_lenEAttr;
1355 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1356 (inode->i_sb->s_blocksize_bits - 9);
1358 if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
1359 inode->i_atime = sbi->s_record_time;
1361 if (!udf_disk_stamp_to_time(&inode->i_mtime,
1362 efe->modificationTime))
1363 inode->i_mtime = sbi->s_record_time;
1365 if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
1366 iinfo->i_crtime = sbi->s_record_time;
1368 if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
1369 inode->i_ctime = sbi->s_record_time;
1371 iinfo->i_unique = le64_to_cpu(efe->uniqueID);
1372 iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
1373 iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
1374 offset = sizeof(struct extendedFileEntry) +
1378 switch (fe->icbTag.fileType) {
1379 case ICBTAG_FILE_TYPE_DIRECTORY:
1380 inode->i_op = &udf_dir_inode_operations;
1381 inode->i_fop = &udf_dir_operations;
1382 inode->i_mode |= S_IFDIR;
1385 case ICBTAG_FILE_TYPE_REALTIME:
1386 case ICBTAG_FILE_TYPE_REGULAR:
1387 case ICBTAG_FILE_TYPE_UNDEF:
1388 case ICBTAG_FILE_TYPE_VAT20:
1389 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1390 inode->i_data.a_ops = &udf_adinicb_aops;
1392 inode->i_data.a_ops = &udf_aops;
1393 inode->i_op = &udf_file_inode_operations;
1394 inode->i_fop = &udf_file_operations;
1395 inode->i_mode |= S_IFREG;
1397 case ICBTAG_FILE_TYPE_BLOCK:
1398 inode->i_mode |= S_IFBLK;
1400 case ICBTAG_FILE_TYPE_CHAR:
1401 inode->i_mode |= S_IFCHR;
1403 case ICBTAG_FILE_TYPE_FIFO:
1404 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1406 case ICBTAG_FILE_TYPE_SOCKET:
1407 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1409 case ICBTAG_FILE_TYPE_SYMLINK:
1410 inode->i_data.a_ops = &udf_symlink_aops;
1411 inode->i_op = &udf_symlink_inode_operations;
1412 inode->i_mode = S_IFLNK | S_IRWXUGO;
1414 case ICBTAG_FILE_TYPE_MAIN:
1415 udf_debug("METADATA FILE-----\n");
1417 case ICBTAG_FILE_TYPE_MIRROR:
1418 udf_debug("METADATA MIRROR FILE-----\n");
1420 case ICBTAG_FILE_TYPE_BITMAP:
1421 udf_debug("METADATA BITMAP FILE-----\n");
1424 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
1425 "file type=%d\n", inode->i_ino,
1426 fe->icbTag.fileType);
1427 make_bad_inode(inode);
1430 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1431 struct deviceSpec *dsea =
1432 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1434 init_special_inode(inode, inode->i_mode,
1435 MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
1436 le32_to_cpu(dsea->minorDeviceIdent)));
1437 /* Developer ID ??? */
1439 make_bad_inode(inode);
1443 static int udf_alloc_i_data(struct inode *inode, size_t size)
1445 struct udf_inode_info *iinfo = UDF_I(inode);
1446 iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL);
1448 if (!iinfo->i_ext.i_data) {
1449 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
1450 "no free memory\n", inode->i_ino);
1457 static mode_t udf_convert_permissions(struct fileEntry *fe)
1460 uint32_t permissions;
1463 permissions = le32_to_cpu(fe->permissions);
1464 flags = le16_to_cpu(fe->icbTag.flags);
1466 mode = ((permissions) & S_IRWXO) |
1467 ((permissions >> 2) & S_IRWXG) |
1468 ((permissions >> 4) & S_IRWXU) |
1469 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1470 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1471 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1476 int udf_write_inode(struct inode *inode, struct writeback_control *wbc)
1478 return udf_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
1481 static int udf_sync_inode(struct inode *inode)
1483 return udf_update_inode(inode, 1);
1486 static int udf_update_inode(struct inode *inode, int do_sync)
1488 struct buffer_head *bh = NULL;
1489 struct fileEntry *fe;
1490 struct extendedFileEntry *efe;
1495 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1496 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
1497 struct udf_inode_info *iinfo = UDF_I(inode);
1499 bh = udf_tgetblk(inode->i_sb,
1500 udf_get_lb_pblock(inode->i_sb, &iinfo->i_location, 0));
1502 udf_debug("getblk failure\n");
1507 memset(bh->b_data, 0, inode->i_sb->s_blocksize);
1508 fe = (struct fileEntry *)bh->b_data;
1509 efe = (struct extendedFileEntry *)bh->b_data;
1512 struct unallocSpaceEntry *use =
1513 (struct unallocSpaceEntry *)bh->b_data;
1515 use->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
1516 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1517 iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
1518 sizeof(struct unallocSpaceEntry));
1519 use->descTag.tagIdent = cpu_to_le16(TAG_IDENT_USE);
1520 use->descTag.tagLocation =
1521 cpu_to_le32(iinfo->i_location.logicalBlockNum);
1522 crclen = sizeof(struct unallocSpaceEntry) +
1523 iinfo->i_lenAlloc - sizeof(struct tag);
1524 use->descTag.descCRCLength = cpu_to_le16(crclen);
1525 use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
1528 use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
1533 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1534 fe->uid = cpu_to_le32(-1);
1536 fe->uid = cpu_to_le32(inode->i_uid);
1538 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1539 fe->gid = cpu_to_le32(-1);
1541 fe->gid = cpu_to_le32(inode->i_gid);
1543 udfperms = ((inode->i_mode & S_IRWXO)) |
1544 ((inode->i_mode & S_IRWXG) << 2) |
1545 ((inode->i_mode & S_IRWXU) << 4);
1547 udfperms |= (le32_to_cpu(fe->permissions) &
1548 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1549 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1550 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1551 fe->permissions = cpu_to_le32(udfperms);
1553 if (S_ISDIR(inode->i_mode))
1554 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1556 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1558 fe->informationLength = cpu_to_le64(inode->i_size);
1560 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1562 struct deviceSpec *dsea =
1563 (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
1565 dsea = (struct deviceSpec *)
1566 udf_add_extendedattr(inode,
1567 sizeof(struct deviceSpec) +
1568 sizeof(struct regid), 12, 0x3);
1569 dsea->attrType = cpu_to_le32(12);
1570 dsea->attrSubtype = 1;
1571 dsea->attrLength = cpu_to_le32(
1572 sizeof(struct deviceSpec) +
1573 sizeof(struct regid));
1574 dsea->impUseLength = cpu_to_le32(sizeof(struct regid));
1576 eid = (struct regid *)dsea->impUse;
1577 memset(eid, 0, sizeof(struct regid));
1578 strcpy(eid->ident, UDF_ID_DEVELOPER);
1579 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
1580 eid->identSuffix[1] = UDF_OS_ID_LINUX;
1581 dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
1582 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1585 if (iinfo->i_efe == 0) {
1586 memcpy(bh->b_data + sizeof(struct fileEntry),
1587 iinfo->i_ext.i_data,
1588 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1589 fe->logicalBlocksRecorded = cpu_to_le64(
1590 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1591 (blocksize_bits - 9));
1593 udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
1594 udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
1595 udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
1596 memset(&(fe->impIdent), 0, sizeof(struct regid));
1597 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1598 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1599 fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1600 fe->uniqueID = cpu_to_le64(iinfo->i_unique);
1601 fe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr);
1602 fe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
1603 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1604 crclen = sizeof(struct fileEntry);
1606 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1607 iinfo->i_ext.i_data,
1608 inode->i_sb->s_blocksize -
1609 sizeof(struct extendedFileEntry));
1610 efe->objectSize = cpu_to_le64(inode->i_size);
1611 efe->logicalBlocksRecorded = cpu_to_le64(
1612 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1613 (blocksize_bits - 9));
1615 if (iinfo->i_crtime.tv_sec > inode->i_atime.tv_sec ||
1616 (iinfo->i_crtime.tv_sec == inode->i_atime.tv_sec &&
1617 iinfo->i_crtime.tv_nsec > inode->i_atime.tv_nsec))
1618 iinfo->i_crtime = inode->i_atime;
1620 if (iinfo->i_crtime.tv_sec > inode->i_mtime.tv_sec ||
1621 (iinfo->i_crtime.tv_sec == inode->i_mtime.tv_sec &&
1622 iinfo->i_crtime.tv_nsec > inode->i_mtime.tv_nsec))
1623 iinfo->i_crtime = inode->i_mtime;
1625 if (iinfo->i_crtime.tv_sec > inode->i_ctime.tv_sec ||
1626 (iinfo->i_crtime.tv_sec == inode->i_ctime.tv_sec &&
1627 iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
1628 iinfo->i_crtime = inode->i_ctime;
1630 udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
1631 udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
1632 udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
1633 udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
1635 memset(&(efe->impIdent), 0, sizeof(struct regid));
1636 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
1637 efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1638 efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1639 efe->uniqueID = cpu_to_le64(iinfo->i_unique);
1640 efe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr);
1641 efe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
1642 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1643 crclen = sizeof(struct extendedFileEntry);
1645 if (iinfo->i_strat4096) {
1646 fe->icbTag.strategyType = cpu_to_le16(4096);
1647 fe->icbTag.strategyParameter = cpu_to_le16(1);
1648 fe->icbTag.numEntries = cpu_to_le16(2);
1650 fe->icbTag.strategyType = cpu_to_le16(4);
1651 fe->icbTag.numEntries = cpu_to_le16(1);
1654 if (S_ISDIR(inode->i_mode))
1655 fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
1656 else if (S_ISREG(inode->i_mode))
1657 fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
1658 else if (S_ISLNK(inode->i_mode))
1659 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
1660 else if (S_ISBLK(inode->i_mode))
1661 fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
1662 else if (S_ISCHR(inode->i_mode))
1663 fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
1664 else if (S_ISFIFO(inode->i_mode))
1665 fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
1666 else if (S_ISSOCK(inode->i_mode))
1667 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1669 icbflags = iinfo->i_alloc_type |
1670 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1671 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1672 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1673 (le16_to_cpu(fe->icbTag.flags) &
1674 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1675 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1677 fe->icbTag.flags = cpu_to_le16(icbflags);
1678 if (sbi->s_udfrev >= 0x0200)
1679 fe->descTag.descVersion = cpu_to_le16(3);
1681 fe->descTag.descVersion = cpu_to_le16(2);
1682 fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
1683 fe->descTag.tagLocation = cpu_to_le32(
1684 iinfo->i_location.logicalBlockNum);
1685 crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc - sizeof(struct tag);
1686 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1687 fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(struct tag),
1689 fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
1692 set_buffer_uptodate(bh);
1695 /* write the data blocks */
1696 mark_buffer_dirty(bh);
1698 sync_dirty_buffer(bh);
1699 if (buffer_write_io_error(bh)) {
1700 printk(KERN_WARNING "IO error syncing udf inode "
1701 "[%s:%08lx]\n", inode->i_sb->s_id,
1711 struct inode *udf_iget(struct super_block *sb, struct kernel_lb_addr *ino)
1713 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1714 struct inode *inode = iget_locked(sb, block);
1719 if (inode->i_state & I_NEW) {
1720 memcpy(&UDF_I(inode)->i_location, ino, sizeof(struct kernel_lb_addr));
1721 __udf_read_inode(inode);
1722 unlock_new_inode(inode);
1725 if (is_bad_inode(inode))
1728 if (ino->logicalBlockNum >= UDF_SB(sb)->
1729 s_partmaps[ino->partitionReferenceNum].s_partition_len) {
1730 udf_debug("block=%d, partition=%d out of range\n",
1731 ino->logicalBlockNum, ino->partitionReferenceNum);
1732 make_bad_inode(inode);
1743 int udf_add_aext(struct inode *inode, struct extent_position *epos,
1744 struct kernel_lb_addr *eloc, uint32_t elen, int inc)
1747 struct short_ad *sad = NULL;
1748 struct long_ad *lad = NULL;
1749 struct allocExtDesc *aed;
1751 struct udf_inode_info *iinfo = UDF_I(inode);
1754 ptr = iinfo->i_ext.i_data + epos->offset -
1755 udf_file_entry_alloc_offset(inode) +
1758 ptr = epos->bh->b_data + epos->offset;
1760 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
1761 adsize = sizeof(struct short_ad);
1762 else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
1763 adsize = sizeof(struct long_ad);
1767 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1768 unsigned char *sptr, *dptr;
1769 struct buffer_head *nbh;
1771 struct kernel_lb_addr obloc = epos->block;
1773 epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
1774 obloc.partitionReferenceNum,
1775 obloc.logicalBlockNum, &err);
1776 if (!epos->block.logicalBlockNum)
1778 nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1784 memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
1785 set_buffer_uptodate(nbh);
1787 mark_buffer_dirty_inode(nbh, inode);
1789 aed = (struct allocExtDesc *)(nbh->b_data);
1790 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1791 aed->previousAllocExtLocation =
1792 cpu_to_le32(obloc.logicalBlockNum);
1793 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1794 loffset = epos->offset;
1795 aed->lengthAllocDescs = cpu_to_le32(adsize);
1796 sptr = ptr - adsize;
1797 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1798 memcpy(dptr, sptr, adsize);
1799 epos->offset = sizeof(struct allocExtDesc) + adsize;
1801 loffset = epos->offset + adsize;
1802 aed->lengthAllocDescs = cpu_to_le32(0);
1804 epos->offset = sizeof(struct allocExtDesc);
1807 aed = (struct allocExtDesc *)epos->bh->b_data;
1808 le32_add_cpu(&aed->lengthAllocDescs, adsize);
1810 iinfo->i_lenAlloc += adsize;
1811 mark_inode_dirty(inode);
1814 if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
1815 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1816 epos->block.logicalBlockNum, sizeof(struct tag));
1818 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1819 epos->block.logicalBlockNum, sizeof(struct tag));
1820 switch (iinfo->i_alloc_type) {
1821 case ICBTAG_FLAG_AD_SHORT:
1822 sad = (struct short_ad *)sptr;
1823 sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1824 inode->i_sb->s_blocksize);
1826 cpu_to_le32(epos->block.logicalBlockNum);
1828 case ICBTAG_FLAG_AD_LONG:
1829 lad = (struct long_ad *)sptr;
1830 lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1831 inode->i_sb->s_blocksize);
1832 lad->extLocation = cpu_to_lelb(epos->block);
1833 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1837 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1838 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1839 udf_update_tag(epos->bh->b_data, loffset);
1841 udf_update_tag(epos->bh->b_data,
1842 sizeof(struct allocExtDesc));
1843 mark_buffer_dirty_inode(epos->bh, inode);
1846 mark_inode_dirty(inode);
1851 udf_write_aext(inode, epos, eloc, elen, inc);
1854 iinfo->i_lenAlloc += adsize;
1855 mark_inode_dirty(inode);
1857 aed = (struct allocExtDesc *)epos->bh->b_data;
1858 le32_add_cpu(&aed->lengthAllocDescs, adsize);
1859 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1860 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1861 udf_update_tag(epos->bh->b_data,
1862 epos->offset + (inc ? 0 : adsize));
1864 udf_update_tag(epos->bh->b_data,
1865 sizeof(struct allocExtDesc));
1866 mark_buffer_dirty_inode(epos->bh, inode);
1872 void udf_write_aext(struct inode *inode, struct extent_position *epos,
1873 struct kernel_lb_addr *eloc, uint32_t elen, int inc)
1877 struct short_ad *sad;
1878 struct long_ad *lad;
1879 struct udf_inode_info *iinfo = UDF_I(inode);
1882 ptr = iinfo->i_ext.i_data + epos->offset -
1883 udf_file_entry_alloc_offset(inode) +
1886 ptr = epos->bh->b_data + epos->offset;
1888 switch (iinfo->i_alloc_type) {
1889 case ICBTAG_FLAG_AD_SHORT:
1890 sad = (struct short_ad *)ptr;
1891 sad->extLength = cpu_to_le32(elen);
1892 sad->extPosition = cpu_to_le32(eloc->logicalBlockNum);
1893 adsize = sizeof(struct short_ad);
1895 case ICBTAG_FLAG_AD_LONG:
1896 lad = (struct long_ad *)ptr;
1897 lad->extLength = cpu_to_le32(elen);
1898 lad->extLocation = cpu_to_lelb(*eloc);
1899 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1900 adsize = sizeof(struct long_ad);
1907 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1908 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
1909 struct allocExtDesc *aed =
1910 (struct allocExtDesc *)epos->bh->b_data;
1911 udf_update_tag(epos->bh->b_data,
1912 le32_to_cpu(aed->lengthAllocDescs) +
1913 sizeof(struct allocExtDesc));
1915 mark_buffer_dirty_inode(epos->bh, inode);
1917 mark_inode_dirty(inode);
1921 epos->offset += adsize;
1924 int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1925 struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
1929 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1930 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1932 epos->block = *eloc;
1933 epos->offset = sizeof(struct allocExtDesc);
1935 block = udf_get_lb_pblock(inode->i_sb, &epos->block, 0);
1936 epos->bh = udf_tread(inode->i_sb, block);
1938 udf_debug("reading block %d failed!\n", block);
1946 int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
1947 struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
1952 struct short_ad *sad;
1953 struct long_ad *lad;
1954 struct udf_inode_info *iinfo = UDF_I(inode);
1958 epos->offset = udf_file_entry_alloc_offset(inode);
1959 ptr = iinfo->i_ext.i_data + epos->offset -
1960 udf_file_entry_alloc_offset(inode) +
1962 alen = udf_file_entry_alloc_offset(inode) +
1966 epos->offset = sizeof(struct allocExtDesc);
1967 ptr = epos->bh->b_data + epos->offset;
1968 alen = sizeof(struct allocExtDesc) +
1969 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1973 switch (iinfo->i_alloc_type) {
1974 case ICBTAG_FLAG_AD_SHORT:
1975 sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
1978 etype = le32_to_cpu(sad->extLength) >> 30;
1979 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1980 eloc->partitionReferenceNum =
1981 iinfo->i_location.partitionReferenceNum;
1982 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1984 case ICBTAG_FLAG_AD_LONG:
1985 lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
1988 etype = le32_to_cpu(lad->extLength) >> 30;
1989 *eloc = lelb_to_cpu(lad->extLocation);
1990 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1993 udf_debug("alloc_type = %d unsupported\n",
1994 iinfo->i_alloc_type);
2001 static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
2002 struct kernel_lb_addr neloc, uint32_t nelen)
2004 struct kernel_lb_addr oeloc;
2011 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
2012 udf_write_aext(inode, &epos, &neloc, nelen, 1);
2014 nelen = (etype << 30) | oelen;
2016 udf_add_aext(inode, &epos, &neloc, nelen, 1);
2019 return (nelen >> 30);
2022 int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2023 struct kernel_lb_addr eloc, uint32_t elen)
2025 struct extent_position oepos;
2028 struct allocExtDesc *aed;
2029 struct udf_inode_info *iinfo;
2036 iinfo = UDF_I(inode);
2037 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
2038 adsize = sizeof(struct short_ad);
2039 else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
2040 adsize = sizeof(struct long_ad);
2045 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2048 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2049 udf_write_aext(inode, &oepos, &eloc, (etype << 30) | elen, 1);
2050 if (oepos.bh != epos.bh) {
2051 oepos.block = epos.block;
2055 oepos.offset = epos.offset - adsize;
2058 memset(&eloc, 0x00, sizeof(struct kernel_lb_addr));
2061 if (epos.bh != oepos.bh) {
2062 udf_free_blocks(inode->i_sb, inode, &epos.block, 0, 1);
2063 udf_write_aext(inode, &oepos, &eloc, elen, 1);
2064 udf_write_aext(inode, &oepos, &eloc, elen, 1);
2066 iinfo->i_lenAlloc -= (adsize * 2);
2067 mark_inode_dirty(inode);
2069 aed = (struct allocExtDesc *)oepos.bh->b_data;
2070 le32_add_cpu(&aed->lengthAllocDescs, -(2 * adsize));
2071 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2072 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2073 udf_update_tag(oepos.bh->b_data,
2074 oepos.offset - (2 * adsize));
2076 udf_update_tag(oepos.bh->b_data,
2077 sizeof(struct allocExtDesc));
2078 mark_buffer_dirty_inode(oepos.bh, inode);
2081 udf_write_aext(inode, &oepos, &eloc, elen, 1);
2083 iinfo->i_lenAlloc -= adsize;
2084 mark_inode_dirty(inode);
2086 aed = (struct allocExtDesc *)oepos.bh->b_data;
2087 le32_add_cpu(&aed->lengthAllocDescs, -adsize);
2088 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2089 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2090 udf_update_tag(oepos.bh->b_data,
2091 epos.offset - adsize);
2093 udf_update_tag(oepos.bh->b_data,
2094 sizeof(struct allocExtDesc));
2095 mark_buffer_dirty_inode(oepos.bh, inode);
2102 return (elen >> 30);
2105 int8_t inode_bmap(struct inode *inode, sector_t block,
2106 struct extent_position *pos, struct kernel_lb_addr *eloc,
2107 uint32_t *elen, sector_t *offset)
2109 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
2110 loff_t lbcount = 0, bcount =
2111 (loff_t) block << blocksize_bits;
2113 struct udf_inode_info *iinfo;
2115 iinfo = UDF_I(inode);
2117 pos->block = iinfo->i_location;
2122 etype = udf_next_aext(inode, pos, eloc, elen, 1);
2124 *offset = (bcount - lbcount) >> blocksize_bits;
2125 iinfo->i_lenExtents = lbcount;
2129 } while (lbcount <= bcount);
2131 *offset = (bcount + *elen - lbcount) >> blocksize_bits;
2136 long udf_block_map(struct inode *inode, sector_t block)
2138 struct kernel_lb_addr eloc;
2141 struct extent_position epos = {};
2144 down_read(&UDF_I(inode)->i_data_sem);
2146 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2147 (EXT_RECORDED_ALLOCATED >> 30))
2148 ret = udf_get_lb_pblock(inode->i_sb, &eloc, offset);
2152 up_read(&UDF_I(inode)->i_data_sem);
2155 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
2156 return udf_fixed_to_variable(ret);