5 * Inode handling routines for the OSTA-UDF(tm) filesystem.
8 * This file is distributed under the terms of the GNU General Public
9 * License (GPL). Copies of the GPL can be obtained from:
10 * ftp://prep.ai.mit.edu/pub/gnu/GPL
11 * Each contributing author retains all rights to their own work.
13 * (C) 1998 Dave Boynton
14 * (C) 1998-2004 Ben Fennema
15 * (C) 1999-2000 Stelias Computing Inc
19 * 10/04/98 dgb Added rudimentary directory functions
20 * 10/07/98 Fully working udf_block_map! It works!
21 * 11/25/98 bmap altered to better support extents
22 * 12/06/98 blf partition support in udf_iget, udf_block_map
24 * 12/12/98 rewrote udf_block_map to handle next extents and descs across
25 * block boundaries (which is not actually allowed)
26 * 12/20/98 added support for strategy 4096
27 * 03/07/99 rewrote udf_block_map (again)
28 * New funcs, inode_bmap, udf_next_aext
29 * 04/19/99 Support for writing device EA's for major/minor #
34 #include <linux/smp_lock.h>
35 #include <linux/module.h>
36 #include <linux/pagemap.h>
37 #include <linux/buffer_head.h>
38 #include <linux/writeback.h>
39 #include <linux/quotaops.h>
40 #include <linux/slab.h>
41 #include <linux/crc-itu-t.h>
46 MODULE_AUTHOR("Ben Fennema");
47 MODULE_DESCRIPTION("Universal Disk Format Filesystem");
48 MODULE_LICENSE("GPL");
50 #define EXTENT_MERGE_SIZE 5
52 static mode_t
udf_convert_permissions(struct fileEntry
*);
53 static int udf_update_inode(struct inode
*, int);
54 static void udf_fill_inode(struct inode
*, struct buffer_head
*);
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_delete_inode(struct inode
*inode
)
74 if (!is_bad_inode(inode
))
75 dquot_initialize(inode
);
77 truncate_inode_pages(&inode
->i_data
, 0);
79 if (is_bad_inode(inode
))
86 udf_update_inode(inode
, IS_SYNC(inode
));
87 udf_free_inode(inode
);
97 * If we are going to release inode from memory, we truncate last inode extent
98 * to proper length. We could use drop_inode() but it's called under inode_lock
99 * and thus we cannot mark inode dirty there. We use clear_inode() but we have
100 * to make sure to write inode as it's not written automatically.
102 void udf_clear_inode(struct inode
*inode
)
104 struct udf_inode_info
*iinfo
= UDF_I(inode
);
106 if (iinfo
->i_alloc_type
!= ICBTAG_FLAG_AD_IN_ICB
&&
107 inode
->i_size
!= iinfo
->i_lenExtents
) {
108 printk(KERN_WARNING
"UDF-fs (%s): Inode %lu (mode %o) has "
109 "inode size %llu different from extent length %llu. "
110 "Filesystem need not be standards compliant.\n",
111 inode
->i_sb
->s_id
, inode
->i_ino
, inode
->i_mode
,
112 (unsigned long long)inode
->i_size
,
113 (unsigned long long)iinfo
->i_lenExtents
);
117 kfree(iinfo
->i_ext
.i_data
);
118 iinfo
->i_ext
.i_data
= NULL
;
121 static int udf_writepage(struct page
*page
, struct writeback_control
*wbc
)
123 return block_write_full_page(page
, udf_get_block
, wbc
);
126 static int udf_readpage(struct file
*file
, struct page
*page
)
128 return block_read_full_page(page
, udf_get_block
);
131 static int udf_write_begin(struct file
*file
, struct address_space
*mapping
,
132 loff_t pos
, unsigned len
, unsigned flags
,
133 struct page
**pagep
, void **fsdata
)
136 return block_write_begin(file
, mapping
, pos
, len
, flags
, pagep
, fsdata
,
140 static sector_t
udf_bmap(struct address_space
*mapping
, sector_t block
)
142 return generic_block_bmap(mapping
, block
, udf_get_block
);
145 const struct address_space_operations udf_aops
= {
146 .readpage
= udf_readpage
,
147 .writepage
= udf_writepage
,
148 .sync_page
= block_sync_page
,
149 .write_begin
= udf_write_begin
,
150 .write_end
= generic_write_end
,
154 void udf_expand_file_adinicb(struct inode
*inode
, int newsize
, int *err
)
158 struct udf_inode_info
*iinfo
= UDF_I(inode
);
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 (!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 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
+ iinfo
->i_lenAlloc
, 0x00,
182 PAGE_CACHE_SIZE
- iinfo
->i_lenAlloc
);
183 memcpy(kaddr
, iinfo
->i_ext
.i_data
+ iinfo
->i_lenEAttr
,
185 flush_dcache_page(page
);
186 SetPageUptodate(page
);
189 memset(iinfo
->i_ext
.i_data
+ iinfo
->i_lenEAttr
, 0x00,
191 iinfo
->i_lenAlloc
= 0;
192 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
193 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
195 iinfo
->i_alloc_type
= 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
;
208 struct kernel_lb_addr eloc
;
210 struct extent_position epos
;
212 struct udf_fileident_bh sfibh
, dfibh
;
213 loff_t f_pos
= udf_ext0_offset(inode
);
214 int size
= udf_ext0_offset(inode
) + inode
->i_size
;
215 struct fileIdentDesc cfi
, *sfi
, *dfi
;
216 struct udf_inode_info
*iinfo
= UDF_I(inode
);
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 iinfo
->i_alloc_type
= alloctype
;
225 mark_inode_dirty(inode
);
229 /* alloc block, and copy data to it */
230 *block
= udf_new_block(inode
->i_sb
, inode
,
231 iinfo
->i_location
.partitionReferenceNum
,
232 iinfo
->i_location
.logicalBlockNum
, err
);
235 newblock
= udf_get_pblock(inode
->i_sb
, *block
,
236 iinfo
->i_location
.partitionReferenceNum
,
240 dbh
= udf_tgetblk(inode
->i_sb
, newblock
);
244 memset(dbh
->b_data
, 0x00, inode
->i_sb
->s_blocksize
);
245 set_buffer_uptodate(dbh
);
247 mark_buffer_dirty_inode(dbh
, inode
);
249 sfibh
.soffset
= sfibh
.eoffset
=
250 f_pos
& (inode
->i_sb
->s_blocksize
- 1);
251 sfibh
.sbh
= sfibh
.ebh
= NULL
;
252 dfibh
.soffset
= dfibh
.eoffset
= 0;
253 dfibh
.sbh
= dfibh
.ebh
= dbh
;
254 while (f_pos
< size
) {
255 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
256 sfi
= udf_fileident_read(inode
, &f_pos
, &sfibh
, &cfi
, NULL
,
262 iinfo
->i_alloc_type
= alloctype
;
263 sfi
->descTag
.tagLocation
= cpu_to_le32(*block
);
264 dfibh
.soffset
= dfibh
.eoffset
;
265 dfibh
.eoffset
+= (sfibh
.eoffset
- sfibh
.soffset
);
266 dfi
= (struct fileIdentDesc
*)(dbh
->b_data
+ dfibh
.soffset
);
267 if (udf_write_fi(inode
, sfi
, dfi
, &dfibh
, sfi
->impUse
,
269 le16_to_cpu(sfi
->lengthOfImpUse
))) {
270 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
275 mark_buffer_dirty_inode(dbh
, inode
);
277 memset(iinfo
->i_ext
.i_data
+ iinfo
->i_lenEAttr
, 0,
279 iinfo
->i_lenAlloc
= 0;
280 eloc
.logicalBlockNum
= *block
;
281 eloc
.partitionReferenceNum
=
282 iinfo
->i_location
.partitionReferenceNum
;
283 iinfo
->i_lenExtents
= inode
->i_size
;
285 epos
.block
= iinfo
->i_location
;
286 epos
.offset
= udf_file_entry_alloc_offset(inode
);
287 udf_add_aext(inode
, &epos
, &eloc
, inode
->i_size
, 0);
291 mark_inode_dirty(inode
);
295 static int udf_get_block(struct inode
*inode
, sector_t block
,
296 struct buffer_head
*bh_result
, int create
)
299 struct buffer_head
*bh
;
301 struct udf_inode_info
*iinfo
;
304 phys
= udf_block_map(inode
, block
);
306 map_bh(bh_result
, inode
->i_sb
, phys
);
316 iinfo
= UDF_I(inode
);
317 if (block
== iinfo
->i_next_alloc_block
+ 1) {
318 iinfo
->i_next_alloc_block
++;
319 iinfo
->i_next_alloc_goal
++;
324 bh
= inode_getblk(inode
, block
, &err
, &phys
, &new);
331 set_buffer_new(bh_result
);
332 map_bh(bh_result
, inode
->i_sb
, phys
);
339 static struct buffer_head
*udf_getblk(struct inode
*inode
, long block
,
340 int create
, int *err
)
342 struct buffer_head
*bh
;
343 struct buffer_head dummy
;
346 dummy
.b_blocknr
= -1000;
347 *err
= udf_get_block(inode
, block
, &dummy
, create
);
348 if (!*err
&& buffer_mapped(&dummy
)) {
349 bh
= sb_getblk(inode
->i_sb
, dummy
.b_blocknr
);
350 if (buffer_new(&dummy
)) {
352 memset(bh
->b_data
, 0x00, inode
->i_sb
->s_blocksize
);
353 set_buffer_uptodate(bh
);
355 mark_buffer_dirty_inode(bh
, inode
);
363 /* Extend the file by 'blocks' blocks, return the number of extents added */
364 int udf_extend_file(struct inode
*inode
, struct extent_position
*last_pos
,
365 struct kernel_long_ad
*last_ext
, sector_t blocks
)
368 int count
= 0, fake
= !(last_ext
->extLength
& UDF_EXTENT_LENGTH_MASK
);
369 struct super_block
*sb
= inode
->i_sb
;
370 struct kernel_lb_addr prealloc_loc
= {};
371 int prealloc_len
= 0;
372 struct udf_inode_info
*iinfo
;
374 /* The previous extent is fake and we should not extend by anything
375 * - there's nothing to do... */
379 iinfo
= UDF_I(inode
);
380 /* Round the last extent up to a multiple of block size */
381 if (last_ext
->extLength
& (sb
->s_blocksize
- 1)) {
382 last_ext
->extLength
=
383 (last_ext
->extLength
& UDF_EXTENT_FLAG_MASK
) |
384 (((last_ext
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
385 sb
->s_blocksize
- 1) & ~(sb
->s_blocksize
- 1));
386 iinfo
->i_lenExtents
=
387 (iinfo
->i_lenExtents
+ sb
->s_blocksize
- 1) &
388 ~(sb
->s_blocksize
- 1);
391 /* Last extent are just preallocated blocks? */
392 if ((last_ext
->extLength
& UDF_EXTENT_FLAG_MASK
) ==
393 EXT_NOT_RECORDED_ALLOCATED
) {
394 /* Save the extent so that we can reattach it to the end */
395 prealloc_loc
= last_ext
->extLocation
;
396 prealloc_len
= last_ext
->extLength
;
397 /* Mark the extent as a hole */
398 last_ext
->extLength
= EXT_NOT_RECORDED_NOT_ALLOCATED
|
399 (last_ext
->extLength
& UDF_EXTENT_LENGTH_MASK
);
400 last_ext
->extLocation
.logicalBlockNum
= 0;
401 last_ext
->extLocation
.partitionReferenceNum
= 0;
404 /* Can we merge with the previous extent? */
405 if ((last_ext
->extLength
& UDF_EXTENT_FLAG_MASK
) ==
406 EXT_NOT_RECORDED_NOT_ALLOCATED
) {
407 add
= ((1 << 30) - sb
->s_blocksize
-
408 (last_ext
->extLength
& UDF_EXTENT_LENGTH_MASK
)) >>
409 sb
->s_blocksize_bits
;
413 last_ext
->extLength
+= add
<< sb
->s_blocksize_bits
;
417 udf_add_aext(inode
, last_pos
, &last_ext
->extLocation
,
418 last_ext
->extLength
, 1);
421 udf_write_aext(inode
, last_pos
, &last_ext
->extLocation
,
422 last_ext
->extLength
, 1);
424 /* Managed to do everything necessary? */
428 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
429 last_ext
->extLocation
.logicalBlockNum
= 0;
430 last_ext
->extLocation
.partitionReferenceNum
= 0;
431 add
= (1 << (30-sb
->s_blocksize_bits
)) - 1;
432 last_ext
->extLength
= EXT_NOT_RECORDED_NOT_ALLOCATED
|
433 (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)
453 /* Do we have some preallocated blocks saved? */
455 if (udf_add_aext(inode
, last_pos
, &prealloc_loc
,
456 prealloc_len
, 1) == -1)
458 last_ext
->extLocation
= prealloc_loc
;
459 last_ext
->extLength
= prealloc_len
;
463 /* last_pos should point to the last written extent... */
464 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
465 last_pos
->offset
-= sizeof(struct short_ad
);
466 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
467 last_pos
->offset
-= sizeof(struct long_ad
);
474 static struct buffer_head
*inode_getblk(struct inode
*inode
, sector_t block
,
475 int *err
, sector_t
*phys
, int *new)
477 static sector_t last_block
;
478 struct buffer_head
*result
= NULL
;
479 struct kernel_long_ad laarr
[EXTENT_MERGE_SIZE
];
480 struct extent_position prev_epos
, cur_epos
, next_epos
;
481 int count
= 0, startnum
= 0, endnum
= 0;
482 uint32_t elen
= 0, tmpelen
;
483 struct kernel_lb_addr eloc
, tmpeloc
;
485 loff_t lbcount
= 0, b_off
= 0;
486 uint32_t newblocknum
, newblock
;
489 struct udf_inode_info
*iinfo
= UDF_I(inode
);
490 int goal
= 0, pgoal
= iinfo
->i_location
.logicalBlockNum
;
493 prev_epos
.offset
= udf_file_entry_alloc_offset(inode
);
494 prev_epos
.block
= iinfo
->i_location
;
496 cur_epos
= next_epos
= prev_epos
;
497 b_off
= (loff_t
)block
<< inode
->i_sb
->s_blocksize_bits
;
499 /* find the extent which contains the block we are looking for.
500 alternate between laarr[0] and laarr[1] for locations of the
501 current extent, and the previous extent */
503 if (prev_epos
.bh
!= cur_epos
.bh
) {
504 brelse(prev_epos
.bh
);
506 prev_epos
.bh
= cur_epos
.bh
;
508 if (cur_epos
.bh
!= next_epos
.bh
) {
510 get_bh(next_epos
.bh
);
511 cur_epos
.bh
= next_epos
.bh
;
516 prev_epos
.block
= cur_epos
.block
;
517 cur_epos
.block
= next_epos
.block
;
519 prev_epos
.offset
= cur_epos
.offset
;
520 cur_epos
.offset
= next_epos
.offset
;
522 etype
= udf_next_aext(inode
, &next_epos
, &eloc
, &elen
, 1);
528 laarr
[c
].extLength
= (etype
<< 30) | elen
;
529 laarr
[c
].extLocation
= eloc
;
531 if (etype
!= (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30))
532 pgoal
= eloc
.logicalBlockNum
+
533 ((elen
+ inode
->i_sb
->s_blocksize
- 1) >>
534 inode
->i_sb
->s_blocksize_bits
);
537 } while (lbcount
+ elen
<= b_off
);
540 offset
= b_off
>> inode
->i_sb
->s_blocksize_bits
;
542 * Move prev_epos and cur_epos into indirect extent if we are at
545 udf_next_aext(inode
, &prev_epos
, &tmpeloc
, &tmpelen
, 0);
546 udf_next_aext(inode
, &cur_epos
, &tmpeloc
, &tmpelen
, 0);
548 /* if the extent is allocated and recorded, return the block
549 if the extent is not a multiple of the blocksize, round up */
551 if (etype
== (EXT_RECORDED_ALLOCATED
>> 30)) {
552 if (elen
& (inode
->i_sb
->s_blocksize
- 1)) {
553 elen
= EXT_RECORDED_ALLOCATED
|
554 ((elen
+ inode
->i_sb
->s_blocksize
- 1) &
555 ~(inode
->i_sb
->s_blocksize
- 1));
556 etype
= udf_write_aext(inode
, &cur_epos
, &eloc
, elen
, 1);
558 brelse(prev_epos
.bh
);
560 brelse(next_epos
.bh
);
561 newblock
= udf_get_lb_pblock(inode
->i_sb
, &eloc
, offset
);
567 /* Are we beyond EOF? */
576 /* Create a fake extent when there's not one */
577 memset(&laarr
[0].extLocation
, 0x00,
578 sizeof(struct kernel_lb_addr
));
579 laarr
[0].extLength
= EXT_NOT_RECORDED_NOT_ALLOCATED
;
580 /* Will udf_extend_file() create real extent from
582 startnum
= (offset
> 0);
584 /* Create extents for the hole between EOF and offset */
585 ret
= udf_extend_file(inode
, &prev_epos
, laarr
, offset
);
587 brelse(prev_epos
.bh
);
589 brelse(next_epos
.bh
);
590 /* We don't really know the error here so we just make
598 /* We are not covered by a preallocated extent? */
599 if ((laarr
[0].extLength
& UDF_EXTENT_FLAG_MASK
) !=
600 EXT_NOT_RECORDED_ALLOCATED
) {
601 /* Is there any real extent? - otherwise we overwrite
605 laarr
[c
].extLength
= EXT_NOT_RECORDED_NOT_ALLOCATED
|
606 inode
->i_sb
->s_blocksize
;
607 memset(&laarr
[c
].extLocation
, 0x00,
608 sizeof(struct kernel_lb_addr
));
615 endnum
= startnum
= ((count
> 2) ? 2 : count
);
617 /* if the current extent is in position 0,
618 swap it with the previous */
619 if (!c
&& count
!= 1) {
626 /* if the current block is located in an extent,
627 read the next extent */
628 etype
= udf_next_aext(inode
, &next_epos
, &eloc
, &elen
, 0);
630 laarr
[c
+ 1].extLength
= (etype
<< 30) | elen
;
631 laarr
[c
+ 1].extLocation
= eloc
;
639 /* if the current extent is not recorded but allocated, get the
640 * block in the extent corresponding to the requested block */
641 if ((laarr
[c
].extLength
>> 30) == (EXT_NOT_RECORDED_ALLOCATED
>> 30))
642 newblocknum
= laarr
[c
].extLocation
.logicalBlockNum
+ offset
;
643 else { /* otherwise, allocate a new block */
644 if (iinfo
->i_next_alloc_block
== block
)
645 goal
= iinfo
->i_next_alloc_goal
;
648 if (!(goal
= pgoal
)) /* XXX: what was intended here? */
649 goal
= iinfo
->i_location
.logicalBlockNum
+ 1;
652 newblocknum
= udf_new_block(inode
->i_sb
, inode
,
653 iinfo
->i_location
.partitionReferenceNum
,
656 brelse(prev_epos
.bh
);
660 iinfo
->i_lenExtents
+= inode
->i_sb
->s_blocksize
;
663 /* if the extent the requsted block is located in contains multiple
664 * blocks, split the extent into at most three extents. blocks prior
665 * to requested block, requested block, and blocks after requested
667 udf_split_extents(inode
, &c
, offset
, newblocknum
, laarr
, &endnum
);
669 #ifdef UDF_PREALLOCATE
670 /* We preallocate blocks only for regular files. It also makes sense
671 * for directories but there's a problem when to drop the
672 * preallocation. We might use some delayed work for that but I feel
673 * it's overengineering for a filesystem like UDF. */
674 if (S_ISREG(inode
->i_mode
))
675 udf_prealloc_extents(inode
, c
, lastblock
, laarr
, &endnum
);
678 /* merge any continuous blocks in laarr */
679 udf_merge_extents(inode
, laarr
, &endnum
);
681 /* write back the new extents, inserting new extents if the new number
682 * of extents is greater than the old number, and deleting extents if
683 * the new number of extents is less than the old number */
684 udf_update_extents(inode
, laarr
, startnum
, endnum
, &prev_epos
);
686 brelse(prev_epos
.bh
);
688 newblock
= udf_get_pblock(inode
->i_sb
, newblocknum
,
689 iinfo
->i_location
.partitionReferenceNum
, 0);
695 iinfo
->i_next_alloc_block
= block
;
696 iinfo
->i_next_alloc_goal
= newblocknum
;
697 inode
->i_ctime
= current_fs_time(inode
->i_sb
);
700 udf_sync_inode(inode
);
702 mark_inode_dirty(inode
);
707 static void udf_split_extents(struct inode
*inode
, int *c
, int offset
,
709 struct kernel_long_ad laarr
[EXTENT_MERGE_SIZE
],
712 unsigned long blocksize
= inode
->i_sb
->s_blocksize
;
713 unsigned char blocksize_bits
= inode
->i_sb
->s_blocksize_bits
;
715 if ((laarr
[*c
].extLength
>> 30) == (EXT_NOT_RECORDED_ALLOCATED
>> 30) ||
716 (laarr
[*c
].extLength
>> 30) ==
717 (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30)) {
719 int blen
= ((laarr
[curr
].extLength
& UDF_EXTENT_LENGTH_MASK
) +
720 blocksize
- 1) >> blocksize_bits
;
721 int8_t etype
= (laarr
[curr
].extLength
>> 30);
725 else if (!offset
|| blen
== offset
+ 1) {
726 laarr
[curr
+ 2] = laarr
[curr
+ 1];
727 laarr
[curr
+ 1] = laarr
[curr
];
729 laarr
[curr
+ 3] = laarr
[curr
+ 1];
730 laarr
[curr
+ 2] = laarr
[curr
+ 1] = laarr
[curr
];
734 if (etype
== (EXT_NOT_RECORDED_ALLOCATED
>> 30)) {
735 udf_free_blocks(inode
->i_sb
, inode
,
736 &laarr
[curr
].extLocation
,
738 laarr
[curr
].extLength
=
739 EXT_NOT_RECORDED_NOT_ALLOCATED
|
740 (offset
<< blocksize_bits
);
741 laarr
[curr
].extLocation
.logicalBlockNum
= 0;
742 laarr
[curr
].extLocation
.
743 partitionReferenceNum
= 0;
745 laarr
[curr
].extLength
= (etype
<< 30) |
746 (offset
<< blocksize_bits
);
752 laarr
[curr
].extLocation
.logicalBlockNum
= newblocknum
;
753 if (etype
== (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30))
754 laarr
[curr
].extLocation
.partitionReferenceNum
=
755 UDF_I(inode
)->i_location
.partitionReferenceNum
;
756 laarr
[curr
].extLength
= EXT_RECORDED_ALLOCATED
|
760 if (blen
!= offset
+ 1) {
761 if (etype
== (EXT_NOT_RECORDED_ALLOCATED
>> 30))
762 laarr
[curr
].extLocation
.logicalBlockNum
+=
764 laarr
[curr
].extLength
= (etype
<< 30) |
765 ((blen
- (offset
+ 1)) << blocksize_bits
);
772 static void udf_prealloc_extents(struct inode
*inode
, int c
, int lastblock
,
773 struct kernel_long_ad laarr
[EXTENT_MERGE_SIZE
],
776 int start
, length
= 0, currlength
= 0, i
;
778 if (*endnum
>= (c
+ 1)) {
784 if ((laarr
[c
+ 1].extLength
>> 30) ==
785 (EXT_NOT_RECORDED_ALLOCATED
>> 30)) {
787 length
= currlength
=
788 (((laarr
[c
+ 1].extLength
&
789 UDF_EXTENT_LENGTH_MASK
) +
790 inode
->i_sb
->s_blocksize
- 1) >>
791 inode
->i_sb
->s_blocksize_bits
);
796 for (i
= start
+ 1; i
<= *endnum
; i
++) {
799 length
+= UDF_DEFAULT_PREALLOC_BLOCKS
;
800 } else if ((laarr
[i
].extLength
>> 30) ==
801 (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30)) {
802 length
+= (((laarr
[i
].extLength
&
803 UDF_EXTENT_LENGTH_MASK
) +
804 inode
->i_sb
->s_blocksize
- 1) >>
805 inode
->i_sb
->s_blocksize_bits
);
811 int next
= laarr
[start
].extLocation
.logicalBlockNum
+
812 (((laarr
[start
].extLength
& UDF_EXTENT_LENGTH_MASK
) +
813 inode
->i_sb
->s_blocksize
- 1) >>
814 inode
->i_sb
->s_blocksize_bits
);
815 int numalloc
= udf_prealloc_blocks(inode
->i_sb
, inode
,
816 laarr
[start
].extLocation
.partitionReferenceNum
,
817 next
, (UDF_DEFAULT_PREALLOC_BLOCKS
> length
?
818 length
: UDF_DEFAULT_PREALLOC_BLOCKS
) -
821 if (start
== (c
+ 1))
822 laarr
[start
].extLength
+=
824 inode
->i_sb
->s_blocksize_bits
);
826 memmove(&laarr
[c
+ 2], &laarr
[c
+ 1],
827 sizeof(struct long_ad
) * (*endnum
- (c
+ 1)));
829 laarr
[c
+ 1].extLocation
.logicalBlockNum
= next
;
830 laarr
[c
+ 1].extLocation
.partitionReferenceNum
=
831 laarr
[c
].extLocation
.
832 partitionReferenceNum
;
833 laarr
[c
+ 1].extLength
=
834 EXT_NOT_RECORDED_ALLOCATED
|
836 inode
->i_sb
->s_blocksize_bits
);
840 for (i
= start
+ 1; numalloc
&& i
< *endnum
; i
++) {
841 int elen
= ((laarr
[i
].extLength
&
842 UDF_EXTENT_LENGTH_MASK
) +
843 inode
->i_sb
->s_blocksize
- 1) >>
844 inode
->i_sb
->s_blocksize_bits
;
846 if (elen
> numalloc
) {
847 laarr
[i
].extLength
-=
849 inode
->i_sb
->s_blocksize_bits
);
853 if (*endnum
> (i
+ 1))
856 sizeof(struct long_ad
) *
857 (*endnum
- (i
+ 1)));
862 UDF_I(inode
)->i_lenExtents
+=
863 numalloc
<< inode
->i_sb
->s_blocksize_bits
;
868 static void udf_merge_extents(struct inode
*inode
,
869 struct kernel_long_ad laarr
[EXTENT_MERGE_SIZE
],
873 unsigned long blocksize
= inode
->i_sb
->s_blocksize
;
874 unsigned char blocksize_bits
= inode
->i_sb
->s_blocksize_bits
;
876 for (i
= 0; i
< (*endnum
- 1); i
++) {
877 struct kernel_long_ad
*li
/*l[i]*/ = &laarr
[i
];
878 struct kernel_long_ad
*lip1
/*l[i plus 1]*/ = &laarr
[i
+ 1];
880 if (((li
->extLength
>> 30) == (lip1
->extLength
>> 30)) &&
881 (((li
->extLength
>> 30) ==
882 (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30)) ||
883 ((lip1
->extLocation
.logicalBlockNum
-
884 li
->extLocation
.logicalBlockNum
) ==
885 (((li
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
886 blocksize
- 1) >> blocksize_bits
)))) {
888 if (((li
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
889 (lip1
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
890 blocksize
- 1) & ~UDF_EXTENT_LENGTH_MASK
) {
891 lip1
->extLength
= (lip1
->extLength
-
893 UDF_EXTENT_LENGTH_MASK
) +
894 UDF_EXTENT_LENGTH_MASK
) &
896 li
->extLength
= (li
->extLength
&
897 UDF_EXTENT_FLAG_MASK
) +
898 (UDF_EXTENT_LENGTH_MASK
+ 1) -
900 lip1
->extLocation
.logicalBlockNum
=
901 li
->extLocation
.logicalBlockNum
+
903 UDF_EXTENT_LENGTH_MASK
) >>
906 li
->extLength
= lip1
->extLength
+
908 UDF_EXTENT_LENGTH_MASK
) +
909 blocksize
- 1) & ~(blocksize
- 1));
910 if (*endnum
> (i
+ 2))
911 memmove(&laarr
[i
+ 1], &laarr
[i
+ 2],
912 sizeof(struct long_ad
) *
913 (*endnum
- (i
+ 2)));
917 } else if (((li
->extLength
>> 30) ==
918 (EXT_NOT_RECORDED_ALLOCATED
>> 30)) &&
919 ((lip1
->extLength
>> 30) ==
920 (EXT_NOT_RECORDED_NOT_ALLOCATED
>> 30))) {
921 udf_free_blocks(inode
->i_sb
, inode
, &li
->extLocation
, 0,
923 UDF_EXTENT_LENGTH_MASK
) +
924 blocksize
- 1) >> blocksize_bits
);
925 li
->extLocation
.logicalBlockNum
= 0;
926 li
->extLocation
.partitionReferenceNum
= 0;
928 if (((li
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
929 (lip1
->extLength
& UDF_EXTENT_LENGTH_MASK
) +
930 blocksize
- 1) & ~UDF_EXTENT_LENGTH_MASK
) {
931 lip1
->extLength
= (lip1
->extLength
-
933 UDF_EXTENT_LENGTH_MASK
) +
934 UDF_EXTENT_LENGTH_MASK
) &
936 li
->extLength
= (li
->extLength
&
937 UDF_EXTENT_FLAG_MASK
) +
938 (UDF_EXTENT_LENGTH_MASK
+ 1) -
941 li
->extLength
= lip1
->extLength
+
943 UDF_EXTENT_LENGTH_MASK
) +
944 blocksize
- 1) & ~(blocksize
- 1));
945 if (*endnum
> (i
+ 2))
946 memmove(&laarr
[i
+ 1], &laarr
[i
+ 2],
947 sizeof(struct long_ad
) *
948 (*endnum
- (i
+ 2)));
952 } else if ((li
->extLength
>> 30) ==
953 (EXT_NOT_RECORDED_ALLOCATED
>> 30)) {
954 udf_free_blocks(inode
->i_sb
, inode
,
957 UDF_EXTENT_LENGTH_MASK
) +
958 blocksize
- 1) >> blocksize_bits
);
959 li
->extLocation
.logicalBlockNum
= 0;
960 li
->extLocation
.partitionReferenceNum
= 0;
961 li
->extLength
= (li
->extLength
&
962 UDF_EXTENT_LENGTH_MASK
) |
963 EXT_NOT_RECORDED_NOT_ALLOCATED
;
968 static void udf_update_extents(struct inode
*inode
,
969 struct kernel_long_ad laarr
[EXTENT_MERGE_SIZE
],
970 int startnum
, int endnum
,
971 struct extent_position
*epos
)
974 struct kernel_lb_addr tmploc
;
977 if (startnum
> endnum
) {
978 for (i
= 0; i
< (startnum
- endnum
); i
++)
979 udf_delete_aext(inode
, *epos
, laarr
[i
].extLocation
,
981 } else if (startnum
< endnum
) {
982 for (i
= 0; i
< (endnum
- startnum
); i
++) {
983 udf_insert_aext(inode
, *epos
, laarr
[i
].extLocation
,
985 udf_next_aext(inode
, epos
, &laarr
[i
].extLocation
,
986 &laarr
[i
].extLength
, 1);
991 for (i
= start
; i
< endnum
; i
++) {
992 udf_next_aext(inode
, epos
, &tmploc
, &tmplen
, 0);
993 udf_write_aext(inode
, epos
, &laarr
[i
].extLocation
,
994 laarr
[i
].extLength
, 1);
998 struct buffer_head
*udf_bread(struct inode
*inode
, int block
,
999 int create
, int *err
)
1001 struct buffer_head
*bh
= NULL
;
1003 bh
= udf_getblk(inode
, block
, create
, err
);
1007 if (buffer_uptodate(bh
))
1010 ll_rw_block(READ
, 1, &bh
);
1013 if (buffer_uptodate(bh
))
1021 void udf_truncate(struct inode
*inode
)
1025 struct udf_inode_info
*iinfo
;
1027 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
) ||
1028 S_ISLNK(inode
->i_mode
)))
1030 if (IS_APPEND(inode
) || IS_IMMUTABLE(inode
))
1034 iinfo
= UDF_I(inode
);
1035 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_IN_ICB
) {
1036 if (inode
->i_sb
->s_blocksize
<
1037 (udf_file_entry_alloc_offset(inode
) +
1039 udf_expand_file_adinicb(inode
, inode
->i_size
, &err
);
1040 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_IN_ICB
) {
1041 inode
->i_size
= iinfo
->i_lenAlloc
;
1045 udf_truncate_extents(inode
);
1047 offset
= inode
->i_size
& (inode
->i_sb
->s_blocksize
- 1);
1048 memset(iinfo
->i_ext
.i_data
+ iinfo
->i_lenEAttr
+ offset
,
1049 0x00, inode
->i_sb
->s_blocksize
-
1050 offset
- udf_file_entry_alloc_offset(inode
));
1051 iinfo
->i_lenAlloc
= inode
->i_size
;
1054 block_truncate_page(inode
->i_mapping
, inode
->i_size
,
1056 udf_truncate_extents(inode
);
1059 inode
->i_mtime
= inode
->i_ctime
= current_fs_time(inode
->i_sb
);
1061 udf_sync_inode(inode
);
1063 mark_inode_dirty(inode
);
1067 static void __udf_read_inode(struct inode
*inode
)
1069 struct buffer_head
*bh
= NULL
;
1070 struct fileEntry
*fe
;
1072 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1075 * Set defaults, but the inode is still incomplete!
1076 * Note: get_new_inode() sets the following on a new inode:
1079 * i_flags = sb->s_flags
1081 * clean_inode(): zero fills and sets
1086 bh
= udf_read_ptagged(inode
->i_sb
, &iinfo
->i_location
, 0, &ident
);
1088 printk(KERN_ERR
"udf: udf_read_inode(ino %ld) failed !bh\n",
1090 make_bad_inode(inode
);
1094 if (ident
!= TAG_IDENT_FE
&& ident
!= TAG_IDENT_EFE
&&
1095 ident
!= TAG_IDENT_USE
) {
1096 printk(KERN_ERR
"udf: udf_read_inode(ino %ld) "
1097 "failed ident=%d\n", inode
->i_ino
, ident
);
1099 make_bad_inode(inode
);
1103 fe
= (struct fileEntry
*)bh
->b_data
;
1105 if (fe
->icbTag
.strategyType
== cpu_to_le16(4096)) {
1106 struct buffer_head
*ibh
;
1108 ibh
= udf_read_ptagged(inode
->i_sb
, &iinfo
->i_location
, 1,
1110 if (ident
== TAG_IDENT_IE
&& ibh
) {
1111 struct buffer_head
*nbh
= NULL
;
1112 struct kernel_lb_addr loc
;
1113 struct indirectEntry
*ie
;
1115 ie
= (struct indirectEntry
*)ibh
->b_data
;
1116 loc
= lelb_to_cpu(ie
->indirectICB
.extLocation
);
1118 if (ie
->indirectICB
.extLength
&&
1119 (nbh
= udf_read_ptagged(inode
->i_sb
, &loc
, 0,
1121 if (ident
== TAG_IDENT_FE
||
1122 ident
== TAG_IDENT_EFE
) {
1123 memcpy(&iinfo
->i_location
,
1125 sizeof(struct kernel_lb_addr
));
1129 __udf_read_inode(inode
);
1136 } else if (fe
->icbTag
.strategyType
!= cpu_to_le16(4)) {
1137 printk(KERN_ERR
"udf: unsupported strategy type: %d\n",
1138 le16_to_cpu(fe
->icbTag
.strategyType
));
1140 make_bad_inode(inode
);
1143 udf_fill_inode(inode
, bh
);
1148 static void udf_fill_inode(struct inode
*inode
, struct buffer_head
*bh
)
1150 struct fileEntry
*fe
;
1151 struct extendedFileEntry
*efe
;
1153 struct udf_sb_info
*sbi
= UDF_SB(inode
->i_sb
);
1154 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1156 fe
= (struct fileEntry
*)bh
->b_data
;
1157 efe
= (struct extendedFileEntry
*)bh
->b_data
;
1159 if (fe
->icbTag
.strategyType
== cpu_to_le16(4))
1160 iinfo
->i_strat4096
= 0;
1161 else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
1162 iinfo
->i_strat4096
= 1;
1164 iinfo
->i_alloc_type
= le16_to_cpu(fe
->icbTag
.flags
) &
1165 ICBTAG_FLAG_AD_MASK
;
1166 iinfo
->i_unique
= 0;
1167 iinfo
->i_lenEAttr
= 0;
1168 iinfo
->i_lenExtents
= 0;
1169 iinfo
->i_lenAlloc
= 0;
1170 iinfo
->i_next_alloc_block
= 0;
1171 iinfo
->i_next_alloc_goal
= 0;
1172 if (fe
->descTag
.tagIdent
== cpu_to_le16(TAG_IDENT_EFE
)) {
1175 if (udf_alloc_i_data(inode
, inode
->i_sb
->s_blocksize
-
1176 sizeof(struct extendedFileEntry
))) {
1177 make_bad_inode(inode
);
1180 memcpy(iinfo
->i_ext
.i_data
,
1181 bh
->b_data
+ sizeof(struct extendedFileEntry
),
1182 inode
->i_sb
->s_blocksize
-
1183 sizeof(struct extendedFileEntry
));
1184 } else if (fe
->descTag
.tagIdent
== cpu_to_le16(TAG_IDENT_FE
)) {
1187 if (udf_alloc_i_data(inode
, inode
->i_sb
->s_blocksize
-
1188 sizeof(struct fileEntry
))) {
1189 make_bad_inode(inode
);
1192 memcpy(iinfo
->i_ext
.i_data
,
1193 bh
->b_data
+ sizeof(struct fileEntry
),
1194 inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
));
1195 } else if (fe
->descTag
.tagIdent
== cpu_to_le16(TAG_IDENT_USE
)) {
1198 iinfo
->i_lenAlloc
= le32_to_cpu(
1199 ((struct unallocSpaceEntry
*)bh
->b_data
)->
1201 if (udf_alloc_i_data(inode
, inode
->i_sb
->s_blocksize
-
1202 sizeof(struct unallocSpaceEntry
))) {
1203 make_bad_inode(inode
);
1206 memcpy(iinfo
->i_ext
.i_data
,
1207 bh
->b_data
+ sizeof(struct unallocSpaceEntry
),
1208 inode
->i_sb
->s_blocksize
-
1209 sizeof(struct unallocSpaceEntry
));
1213 inode
->i_uid
= le32_to_cpu(fe
->uid
);
1214 if (inode
->i_uid
== -1 ||
1215 UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_UID_IGNORE
) ||
1216 UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_UID_SET
))
1217 inode
->i_uid
= UDF_SB(inode
->i_sb
)->s_uid
;
1219 inode
->i_gid
= le32_to_cpu(fe
->gid
);
1220 if (inode
->i_gid
== -1 ||
1221 UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_GID_IGNORE
) ||
1222 UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_GID_SET
))
1223 inode
->i_gid
= UDF_SB(inode
->i_sb
)->s_gid
;
1225 inode
->i_nlink
= le16_to_cpu(fe
->fileLinkCount
);
1226 if (!inode
->i_nlink
)
1229 inode
->i_size
= le64_to_cpu(fe
->informationLength
);
1230 iinfo
->i_lenExtents
= inode
->i_size
;
1232 if (fe
->icbTag
.fileType
!= ICBTAG_FILE_TYPE_DIRECTORY
&&
1233 sbi
->s_fmode
!= UDF_INVALID_MODE
)
1234 inode
->i_mode
= sbi
->s_fmode
;
1235 else if (fe
->icbTag
.fileType
== ICBTAG_FILE_TYPE_DIRECTORY
&&
1236 sbi
->s_dmode
!= UDF_INVALID_MODE
)
1237 inode
->i_mode
= sbi
->s_dmode
;
1239 inode
->i_mode
= udf_convert_permissions(fe
);
1240 inode
->i_mode
&= ~sbi
->s_umask
;
1242 if (iinfo
->i_efe
== 0) {
1243 inode
->i_blocks
= le64_to_cpu(fe
->logicalBlocksRecorded
) <<
1244 (inode
->i_sb
->s_blocksize_bits
- 9);
1246 if (!udf_disk_stamp_to_time(&inode
->i_atime
, fe
->accessTime
))
1247 inode
->i_atime
= sbi
->s_record_time
;
1249 if (!udf_disk_stamp_to_time(&inode
->i_mtime
,
1250 fe
->modificationTime
))
1251 inode
->i_mtime
= sbi
->s_record_time
;
1253 if (!udf_disk_stamp_to_time(&inode
->i_ctime
, fe
->attrTime
))
1254 inode
->i_ctime
= sbi
->s_record_time
;
1256 iinfo
->i_unique
= le64_to_cpu(fe
->uniqueID
);
1257 iinfo
->i_lenEAttr
= le32_to_cpu(fe
->lengthExtendedAttr
);
1258 iinfo
->i_lenAlloc
= le32_to_cpu(fe
->lengthAllocDescs
);
1259 offset
= sizeof(struct fileEntry
) + iinfo
->i_lenEAttr
;
1261 inode
->i_blocks
= le64_to_cpu(efe
->logicalBlocksRecorded
) <<
1262 (inode
->i_sb
->s_blocksize_bits
- 9);
1264 if (!udf_disk_stamp_to_time(&inode
->i_atime
, efe
->accessTime
))
1265 inode
->i_atime
= sbi
->s_record_time
;
1267 if (!udf_disk_stamp_to_time(&inode
->i_mtime
,
1268 efe
->modificationTime
))
1269 inode
->i_mtime
= sbi
->s_record_time
;
1271 if (!udf_disk_stamp_to_time(&iinfo
->i_crtime
, efe
->createTime
))
1272 iinfo
->i_crtime
= sbi
->s_record_time
;
1274 if (!udf_disk_stamp_to_time(&inode
->i_ctime
, efe
->attrTime
))
1275 inode
->i_ctime
= sbi
->s_record_time
;
1277 iinfo
->i_unique
= le64_to_cpu(efe
->uniqueID
);
1278 iinfo
->i_lenEAttr
= le32_to_cpu(efe
->lengthExtendedAttr
);
1279 iinfo
->i_lenAlloc
= le32_to_cpu(efe
->lengthAllocDescs
);
1280 offset
= sizeof(struct extendedFileEntry
) +
1284 switch (fe
->icbTag
.fileType
) {
1285 case ICBTAG_FILE_TYPE_DIRECTORY
:
1286 inode
->i_op
= &udf_dir_inode_operations
;
1287 inode
->i_fop
= &udf_dir_operations
;
1288 inode
->i_mode
|= S_IFDIR
;
1291 case ICBTAG_FILE_TYPE_REALTIME
:
1292 case ICBTAG_FILE_TYPE_REGULAR
:
1293 case ICBTAG_FILE_TYPE_UNDEF
:
1294 case ICBTAG_FILE_TYPE_VAT20
:
1295 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_IN_ICB
)
1296 inode
->i_data
.a_ops
= &udf_adinicb_aops
;
1298 inode
->i_data
.a_ops
= &udf_aops
;
1299 inode
->i_op
= &udf_file_inode_operations
;
1300 inode
->i_fop
= &udf_file_operations
;
1301 inode
->i_mode
|= S_IFREG
;
1303 case ICBTAG_FILE_TYPE_BLOCK
:
1304 inode
->i_mode
|= S_IFBLK
;
1306 case ICBTAG_FILE_TYPE_CHAR
:
1307 inode
->i_mode
|= S_IFCHR
;
1309 case ICBTAG_FILE_TYPE_FIFO
:
1310 init_special_inode(inode
, inode
->i_mode
| S_IFIFO
, 0);
1312 case ICBTAG_FILE_TYPE_SOCKET
:
1313 init_special_inode(inode
, inode
->i_mode
| S_IFSOCK
, 0);
1315 case ICBTAG_FILE_TYPE_SYMLINK
:
1316 inode
->i_data
.a_ops
= &udf_symlink_aops
;
1317 inode
->i_op
= &udf_symlink_inode_operations
;
1318 inode
->i_mode
= S_IFLNK
| S_IRWXUGO
;
1320 case ICBTAG_FILE_TYPE_MAIN
:
1321 udf_debug("METADATA FILE-----\n");
1323 case ICBTAG_FILE_TYPE_MIRROR
:
1324 udf_debug("METADATA MIRROR FILE-----\n");
1326 case ICBTAG_FILE_TYPE_BITMAP
:
1327 udf_debug("METADATA BITMAP FILE-----\n");
1330 printk(KERN_ERR
"udf: udf_fill_inode(ino %ld) failed unknown "
1331 "file type=%d\n", inode
->i_ino
,
1332 fe
->icbTag
.fileType
);
1333 make_bad_inode(inode
);
1336 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
)) {
1337 struct deviceSpec
*dsea
=
1338 (struct deviceSpec
*)udf_get_extendedattr(inode
, 12, 1);
1340 init_special_inode(inode
, inode
->i_mode
,
1341 MKDEV(le32_to_cpu(dsea
->majorDeviceIdent
),
1342 le32_to_cpu(dsea
->minorDeviceIdent
)));
1343 /* Developer ID ??? */
1345 make_bad_inode(inode
);
1349 static int udf_alloc_i_data(struct inode
*inode
, size_t size
)
1351 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1352 iinfo
->i_ext
.i_data
= kmalloc(size
, GFP_KERNEL
);
1354 if (!iinfo
->i_ext
.i_data
) {
1355 printk(KERN_ERR
"udf:udf_alloc_i_data (ino %ld) "
1356 "no free memory\n", inode
->i_ino
);
1363 static mode_t
udf_convert_permissions(struct fileEntry
*fe
)
1366 uint32_t permissions
;
1369 permissions
= le32_to_cpu(fe
->permissions
);
1370 flags
= le16_to_cpu(fe
->icbTag
.flags
);
1372 mode
= ((permissions
) & S_IRWXO
) |
1373 ((permissions
>> 2) & S_IRWXG
) |
1374 ((permissions
>> 4) & S_IRWXU
) |
1375 ((flags
& ICBTAG_FLAG_SETUID
) ? S_ISUID
: 0) |
1376 ((flags
& ICBTAG_FLAG_SETGID
) ? S_ISGID
: 0) |
1377 ((flags
& ICBTAG_FLAG_STICKY
) ? S_ISVTX
: 0);
1382 int udf_write_inode(struct inode
*inode
, struct writeback_control
*wbc
)
1387 ret
= udf_update_inode(inode
, wbc
->sync_mode
== WB_SYNC_ALL
);
1393 int udf_sync_inode(struct inode
*inode
)
1395 return udf_update_inode(inode
, 1);
1398 static int udf_update_inode(struct inode
*inode
, int do_sync
)
1400 struct buffer_head
*bh
= NULL
;
1401 struct fileEntry
*fe
;
1402 struct extendedFileEntry
*efe
;
1407 struct udf_sb_info
*sbi
= UDF_SB(inode
->i_sb
);
1408 unsigned char blocksize_bits
= inode
->i_sb
->s_blocksize_bits
;
1409 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1411 bh
= udf_tgetblk(inode
->i_sb
,
1412 udf_get_lb_pblock(inode
->i_sb
, &iinfo
->i_location
, 0));
1414 udf_debug("getblk failure\n");
1419 memset(bh
->b_data
, 0, inode
->i_sb
->s_blocksize
);
1420 fe
= (struct fileEntry
*)bh
->b_data
;
1421 efe
= (struct extendedFileEntry
*)bh
->b_data
;
1424 struct unallocSpaceEntry
*use
=
1425 (struct unallocSpaceEntry
*)bh
->b_data
;
1427 use
->lengthAllocDescs
= cpu_to_le32(iinfo
->i_lenAlloc
);
1428 memcpy(bh
->b_data
+ sizeof(struct unallocSpaceEntry
),
1429 iinfo
->i_ext
.i_data
, inode
->i_sb
->s_blocksize
-
1430 sizeof(struct unallocSpaceEntry
));
1431 use
->descTag
.tagIdent
= cpu_to_le16(TAG_IDENT_USE
);
1432 use
->descTag
.tagLocation
=
1433 cpu_to_le32(iinfo
->i_location
.logicalBlockNum
);
1434 crclen
= sizeof(struct unallocSpaceEntry
) +
1435 iinfo
->i_lenAlloc
- sizeof(struct tag
);
1436 use
->descTag
.descCRCLength
= cpu_to_le16(crclen
);
1437 use
->descTag
.descCRC
= cpu_to_le16(crc_itu_t(0, (char *)use
+
1440 use
->descTag
.tagChecksum
= udf_tag_checksum(&use
->descTag
);
1445 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_UID_FORGET
))
1446 fe
->uid
= cpu_to_le32(-1);
1448 fe
->uid
= cpu_to_le32(inode
->i_uid
);
1450 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_GID_FORGET
))
1451 fe
->gid
= cpu_to_le32(-1);
1453 fe
->gid
= cpu_to_le32(inode
->i_gid
);
1455 udfperms
= ((inode
->i_mode
& S_IRWXO
)) |
1456 ((inode
->i_mode
& S_IRWXG
) << 2) |
1457 ((inode
->i_mode
& S_IRWXU
) << 4);
1459 udfperms
|= (le32_to_cpu(fe
->permissions
) &
1460 (FE_PERM_O_DELETE
| FE_PERM_O_CHATTR
|
1461 FE_PERM_G_DELETE
| FE_PERM_G_CHATTR
|
1462 FE_PERM_U_DELETE
| FE_PERM_U_CHATTR
));
1463 fe
->permissions
= cpu_to_le32(udfperms
);
1465 if (S_ISDIR(inode
->i_mode
))
1466 fe
->fileLinkCount
= cpu_to_le16(inode
->i_nlink
- 1);
1468 fe
->fileLinkCount
= cpu_to_le16(inode
->i_nlink
);
1470 fe
->informationLength
= cpu_to_le64(inode
->i_size
);
1472 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
)) {
1474 struct deviceSpec
*dsea
=
1475 (struct deviceSpec
*)udf_get_extendedattr(inode
, 12, 1);
1477 dsea
= (struct deviceSpec
*)
1478 udf_add_extendedattr(inode
,
1479 sizeof(struct deviceSpec
) +
1480 sizeof(struct regid
), 12, 0x3);
1481 dsea
->attrType
= cpu_to_le32(12);
1482 dsea
->attrSubtype
= 1;
1483 dsea
->attrLength
= cpu_to_le32(
1484 sizeof(struct deviceSpec
) +
1485 sizeof(struct regid
));
1486 dsea
->impUseLength
= cpu_to_le32(sizeof(struct regid
));
1488 eid
= (struct regid
*)dsea
->impUse
;
1489 memset(eid
, 0, sizeof(struct regid
));
1490 strcpy(eid
->ident
, UDF_ID_DEVELOPER
);
1491 eid
->identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1492 eid
->identSuffix
[1] = UDF_OS_ID_LINUX
;
1493 dsea
->majorDeviceIdent
= cpu_to_le32(imajor(inode
));
1494 dsea
->minorDeviceIdent
= cpu_to_le32(iminor(inode
));
1497 if (iinfo
->i_efe
== 0) {
1498 memcpy(bh
->b_data
+ sizeof(struct fileEntry
),
1499 iinfo
->i_ext
.i_data
,
1500 inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
));
1501 fe
->logicalBlocksRecorded
= cpu_to_le64(
1502 (inode
->i_blocks
+ (1 << (blocksize_bits
- 9)) - 1) >>
1503 (blocksize_bits
- 9));
1505 udf_time_to_disk_stamp(&fe
->accessTime
, inode
->i_atime
);
1506 udf_time_to_disk_stamp(&fe
->modificationTime
, inode
->i_mtime
);
1507 udf_time_to_disk_stamp(&fe
->attrTime
, inode
->i_ctime
);
1508 memset(&(fe
->impIdent
), 0, sizeof(struct regid
));
1509 strcpy(fe
->impIdent
.ident
, UDF_ID_DEVELOPER
);
1510 fe
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1511 fe
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1512 fe
->uniqueID
= cpu_to_le64(iinfo
->i_unique
);
1513 fe
->lengthExtendedAttr
= cpu_to_le32(iinfo
->i_lenEAttr
);
1514 fe
->lengthAllocDescs
= cpu_to_le32(iinfo
->i_lenAlloc
);
1515 fe
->descTag
.tagIdent
= cpu_to_le16(TAG_IDENT_FE
);
1516 crclen
= sizeof(struct fileEntry
);
1518 memcpy(bh
->b_data
+ sizeof(struct extendedFileEntry
),
1519 iinfo
->i_ext
.i_data
,
1520 inode
->i_sb
->s_blocksize
-
1521 sizeof(struct extendedFileEntry
));
1522 efe
->objectSize
= cpu_to_le64(inode
->i_size
);
1523 efe
->logicalBlocksRecorded
= cpu_to_le64(
1524 (inode
->i_blocks
+ (1 << (blocksize_bits
- 9)) - 1) >>
1525 (blocksize_bits
- 9));
1527 if (iinfo
->i_crtime
.tv_sec
> inode
->i_atime
.tv_sec
||
1528 (iinfo
->i_crtime
.tv_sec
== inode
->i_atime
.tv_sec
&&
1529 iinfo
->i_crtime
.tv_nsec
> inode
->i_atime
.tv_nsec
))
1530 iinfo
->i_crtime
= inode
->i_atime
;
1532 if (iinfo
->i_crtime
.tv_sec
> inode
->i_mtime
.tv_sec
||
1533 (iinfo
->i_crtime
.tv_sec
== inode
->i_mtime
.tv_sec
&&
1534 iinfo
->i_crtime
.tv_nsec
> inode
->i_mtime
.tv_nsec
))
1535 iinfo
->i_crtime
= inode
->i_mtime
;
1537 if (iinfo
->i_crtime
.tv_sec
> inode
->i_ctime
.tv_sec
||
1538 (iinfo
->i_crtime
.tv_sec
== inode
->i_ctime
.tv_sec
&&
1539 iinfo
->i_crtime
.tv_nsec
> inode
->i_ctime
.tv_nsec
))
1540 iinfo
->i_crtime
= inode
->i_ctime
;
1542 udf_time_to_disk_stamp(&efe
->accessTime
, inode
->i_atime
);
1543 udf_time_to_disk_stamp(&efe
->modificationTime
, inode
->i_mtime
);
1544 udf_time_to_disk_stamp(&efe
->createTime
, iinfo
->i_crtime
);
1545 udf_time_to_disk_stamp(&efe
->attrTime
, inode
->i_ctime
);
1547 memset(&(efe
->impIdent
), 0, sizeof(struct regid
));
1548 strcpy(efe
->impIdent
.ident
, UDF_ID_DEVELOPER
);
1549 efe
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1550 efe
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1551 efe
->uniqueID
= cpu_to_le64(iinfo
->i_unique
);
1552 efe
->lengthExtendedAttr
= cpu_to_le32(iinfo
->i_lenEAttr
);
1553 efe
->lengthAllocDescs
= cpu_to_le32(iinfo
->i_lenAlloc
);
1554 efe
->descTag
.tagIdent
= cpu_to_le16(TAG_IDENT_EFE
);
1555 crclen
= sizeof(struct extendedFileEntry
);
1557 if (iinfo
->i_strat4096
) {
1558 fe
->icbTag
.strategyType
= cpu_to_le16(4096);
1559 fe
->icbTag
.strategyParameter
= cpu_to_le16(1);
1560 fe
->icbTag
.numEntries
= cpu_to_le16(2);
1562 fe
->icbTag
.strategyType
= cpu_to_le16(4);
1563 fe
->icbTag
.numEntries
= cpu_to_le16(1);
1566 if (S_ISDIR(inode
->i_mode
))
1567 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_DIRECTORY
;
1568 else if (S_ISREG(inode
->i_mode
))
1569 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_REGULAR
;
1570 else if (S_ISLNK(inode
->i_mode
))
1571 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_SYMLINK
;
1572 else if (S_ISBLK(inode
->i_mode
))
1573 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_BLOCK
;
1574 else if (S_ISCHR(inode
->i_mode
))
1575 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_CHAR
;
1576 else if (S_ISFIFO(inode
->i_mode
))
1577 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_FIFO
;
1578 else if (S_ISSOCK(inode
->i_mode
))
1579 fe
->icbTag
.fileType
= ICBTAG_FILE_TYPE_SOCKET
;
1581 icbflags
= iinfo
->i_alloc_type
|
1582 ((inode
->i_mode
& S_ISUID
) ? ICBTAG_FLAG_SETUID
: 0) |
1583 ((inode
->i_mode
& S_ISGID
) ? ICBTAG_FLAG_SETGID
: 0) |
1584 ((inode
->i_mode
& S_ISVTX
) ? ICBTAG_FLAG_STICKY
: 0) |
1585 (le16_to_cpu(fe
->icbTag
.flags
) &
1586 ~(ICBTAG_FLAG_AD_MASK
| ICBTAG_FLAG_SETUID
|
1587 ICBTAG_FLAG_SETGID
| ICBTAG_FLAG_STICKY
));
1589 fe
->icbTag
.flags
= cpu_to_le16(icbflags
);
1590 if (sbi
->s_udfrev
>= 0x0200)
1591 fe
->descTag
.descVersion
= cpu_to_le16(3);
1593 fe
->descTag
.descVersion
= cpu_to_le16(2);
1594 fe
->descTag
.tagSerialNum
= cpu_to_le16(sbi
->s_serial_number
);
1595 fe
->descTag
.tagLocation
= cpu_to_le32(
1596 iinfo
->i_location
.logicalBlockNum
);
1597 crclen
+= iinfo
->i_lenEAttr
+ iinfo
->i_lenAlloc
- sizeof(struct tag
);
1598 fe
->descTag
.descCRCLength
= cpu_to_le16(crclen
);
1599 fe
->descTag
.descCRC
= cpu_to_le16(crc_itu_t(0, (char *)fe
+ sizeof(struct tag
),
1601 fe
->descTag
.tagChecksum
= udf_tag_checksum(&fe
->descTag
);
1604 set_buffer_uptodate(bh
);
1607 /* write the data blocks */
1608 mark_buffer_dirty(bh
);
1610 sync_dirty_buffer(bh
);
1611 if (buffer_write_io_error(bh
)) {
1612 printk(KERN_WARNING
"IO error syncing udf inode "
1613 "[%s:%08lx]\n", inode
->i_sb
->s_id
,
1623 struct inode
*udf_iget(struct super_block
*sb
, struct kernel_lb_addr
*ino
)
1625 unsigned long block
= udf_get_lb_pblock(sb
, ino
, 0);
1626 struct inode
*inode
= iget_locked(sb
, block
);
1631 if (inode
->i_state
& I_NEW
) {
1632 memcpy(&UDF_I(inode
)->i_location
, ino
, sizeof(struct kernel_lb_addr
));
1633 __udf_read_inode(inode
);
1634 unlock_new_inode(inode
);
1637 if (is_bad_inode(inode
))
1640 if (ino
->logicalBlockNum
>= UDF_SB(sb
)->
1641 s_partmaps
[ino
->partitionReferenceNum
].s_partition_len
) {
1642 udf_debug("block=%d, partition=%d out of range\n",
1643 ino
->logicalBlockNum
, ino
->partitionReferenceNum
);
1644 make_bad_inode(inode
);
1655 int8_t udf_add_aext(struct inode
*inode
, struct extent_position
*epos
,
1656 struct kernel_lb_addr
*eloc
, uint32_t elen
, int inc
)
1659 struct short_ad
*sad
= NULL
;
1660 struct long_ad
*lad
= NULL
;
1661 struct allocExtDesc
*aed
;
1664 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1667 ptr
= iinfo
->i_ext
.i_data
+ epos
->offset
-
1668 udf_file_entry_alloc_offset(inode
) +
1671 ptr
= epos
->bh
->b_data
+ epos
->offset
;
1673 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
1674 adsize
= sizeof(struct short_ad
);
1675 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
1676 adsize
= sizeof(struct long_ad
);
1680 if (epos
->offset
+ (2 * adsize
) > inode
->i_sb
->s_blocksize
) {
1681 unsigned char *sptr
, *dptr
;
1682 struct buffer_head
*nbh
;
1684 struct kernel_lb_addr obloc
= epos
->block
;
1686 epos
->block
.logicalBlockNum
= udf_new_block(inode
->i_sb
, NULL
,
1687 obloc
.partitionReferenceNum
,
1688 obloc
.logicalBlockNum
, &err
);
1689 if (!epos
->block
.logicalBlockNum
)
1691 nbh
= udf_tgetblk(inode
->i_sb
, udf_get_lb_pblock(inode
->i_sb
,
1697 memset(nbh
->b_data
, 0x00, inode
->i_sb
->s_blocksize
);
1698 set_buffer_uptodate(nbh
);
1700 mark_buffer_dirty_inode(nbh
, inode
);
1702 aed
= (struct allocExtDesc
*)(nbh
->b_data
);
1703 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
))
1704 aed
->previousAllocExtLocation
=
1705 cpu_to_le32(obloc
.logicalBlockNum
);
1706 if (epos
->offset
+ adsize
> inode
->i_sb
->s_blocksize
) {
1707 loffset
= epos
->offset
;
1708 aed
->lengthAllocDescs
= cpu_to_le32(adsize
);
1709 sptr
= ptr
- adsize
;
1710 dptr
= nbh
->b_data
+ sizeof(struct allocExtDesc
);
1711 memcpy(dptr
, sptr
, adsize
);
1712 epos
->offset
= sizeof(struct allocExtDesc
) + adsize
;
1714 loffset
= epos
->offset
+ adsize
;
1715 aed
->lengthAllocDescs
= cpu_to_le32(0);
1717 epos
->offset
= sizeof(struct allocExtDesc
);
1720 aed
= (struct allocExtDesc
*)epos
->bh
->b_data
;
1721 le32_add_cpu(&aed
->lengthAllocDescs
, adsize
);
1723 iinfo
->i_lenAlloc
+= adsize
;
1724 mark_inode_dirty(inode
);
1727 if (UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0200)
1728 udf_new_tag(nbh
->b_data
, TAG_IDENT_AED
, 3, 1,
1729 epos
->block
.logicalBlockNum
, sizeof(struct tag
));
1731 udf_new_tag(nbh
->b_data
, TAG_IDENT_AED
, 2, 1,
1732 epos
->block
.logicalBlockNum
, sizeof(struct tag
));
1733 switch (iinfo
->i_alloc_type
) {
1734 case ICBTAG_FLAG_AD_SHORT
:
1735 sad
= (struct short_ad
*)sptr
;
1736 sad
->extLength
= cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS
|
1737 inode
->i_sb
->s_blocksize
);
1739 cpu_to_le32(epos
->block
.logicalBlockNum
);
1741 case ICBTAG_FLAG_AD_LONG
:
1742 lad
= (struct long_ad
*)sptr
;
1743 lad
->extLength
= cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS
|
1744 inode
->i_sb
->s_blocksize
);
1745 lad
->extLocation
= cpu_to_lelb(epos
->block
);
1746 memset(lad
->impUse
, 0x00, sizeof(lad
->impUse
));
1750 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
) ||
1751 UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0201)
1752 udf_update_tag(epos
->bh
->b_data
, loffset
);
1754 udf_update_tag(epos
->bh
->b_data
,
1755 sizeof(struct allocExtDesc
));
1756 mark_buffer_dirty_inode(epos
->bh
, inode
);
1759 mark_inode_dirty(inode
);
1764 etype
= udf_write_aext(inode
, epos
, eloc
, elen
, inc
);
1767 iinfo
->i_lenAlloc
+= adsize
;
1768 mark_inode_dirty(inode
);
1770 aed
= (struct allocExtDesc
*)epos
->bh
->b_data
;
1771 le32_add_cpu(&aed
->lengthAllocDescs
, adsize
);
1772 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
) ||
1773 UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0201)
1774 udf_update_tag(epos
->bh
->b_data
,
1775 epos
->offset
+ (inc
? 0 : adsize
));
1777 udf_update_tag(epos
->bh
->b_data
,
1778 sizeof(struct allocExtDesc
));
1779 mark_buffer_dirty_inode(epos
->bh
, inode
);
1785 int8_t udf_write_aext(struct inode
*inode
, struct extent_position
*epos
,
1786 struct kernel_lb_addr
*eloc
, uint32_t elen
, int inc
)
1790 struct short_ad
*sad
;
1791 struct long_ad
*lad
;
1792 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1795 ptr
= iinfo
->i_ext
.i_data
+ epos
->offset
-
1796 udf_file_entry_alloc_offset(inode
) +
1799 ptr
= epos
->bh
->b_data
+ epos
->offset
;
1801 switch (iinfo
->i_alloc_type
) {
1802 case ICBTAG_FLAG_AD_SHORT
:
1803 sad
= (struct short_ad
*)ptr
;
1804 sad
->extLength
= cpu_to_le32(elen
);
1805 sad
->extPosition
= cpu_to_le32(eloc
->logicalBlockNum
);
1806 adsize
= sizeof(struct short_ad
);
1808 case ICBTAG_FLAG_AD_LONG
:
1809 lad
= (struct long_ad
*)ptr
;
1810 lad
->extLength
= cpu_to_le32(elen
);
1811 lad
->extLocation
= cpu_to_lelb(*eloc
);
1812 memset(lad
->impUse
, 0x00, sizeof(lad
->impUse
));
1813 adsize
= sizeof(struct long_ad
);
1820 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
) ||
1821 UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0201) {
1822 struct allocExtDesc
*aed
=
1823 (struct allocExtDesc
*)epos
->bh
->b_data
;
1824 udf_update_tag(epos
->bh
->b_data
,
1825 le32_to_cpu(aed
->lengthAllocDescs
) +
1826 sizeof(struct allocExtDesc
));
1828 mark_buffer_dirty_inode(epos
->bh
, inode
);
1830 mark_inode_dirty(inode
);
1834 epos
->offset
+= adsize
;
1836 return (elen
>> 30);
1839 int8_t udf_next_aext(struct inode
*inode
, struct extent_position
*epos
,
1840 struct kernel_lb_addr
*eloc
, uint32_t *elen
, int inc
)
1844 while ((etype
= udf_current_aext(inode
, epos
, eloc
, elen
, inc
)) ==
1845 (EXT_NEXT_EXTENT_ALLOCDECS
>> 30)) {
1847 epos
->block
= *eloc
;
1848 epos
->offset
= sizeof(struct allocExtDesc
);
1850 block
= udf_get_lb_pblock(inode
->i_sb
, &epos
->block
, 0);
1851 epos
->bh
= udf_tread(inode
->i_sb
, block
);
1853 udf_debug("reading block %d failed!\n", block
);
1861 int8_t udf_current_aext(struct inode
*inode
, struct extent_position
*epos
,
1862 struct kernel_lb_addr
*eloc
, uint32_t *elen
, int inc
)
1867 struct short_ad
*sad
;
1868 struct long_ad
*lad
;
1869 struct udf_inode_info
*iinfo
= UDF_I(inode
);
1873 epos
->offset
= udf_file_entry_alloc_offset(inode
);
1874 ptr
= iinfo
->i_ext
.i_data
+ epos
->offset
-
1875 udf_file_entry_alloc_offset(inode
) +
1877 alen
= udf_file_entry_alloc_offset(inode
) +
1881 epos
->offset
= sizeof(struct allocExtDesc
);
1882 ptr
= epos
->bh
->b_data
+ epos
->offset
;
1883 alen
= sizeof(struct allocExtDesc
) +
1884 le32_to_cpu(((struct allocExtDesc
*)epos
->bh
->b_data
)->
1888 switch (iinfo
->i_alloc_type
) {
1889 case ICBTAG_FLAG_AD_SHORT
:
1890 sad
= udf_get_fileshortad(ptr
, alen
, &epos
->offset
, inc
);
1893 etype
= le32_to_cpu(sad
->extLength
) >> 30;
1894 eloc
->logicalBlockNum
= le32_to_cpu(sad
->extPosition
);
1895 eloc
->partitionReferenceNum
=
1896 iinfo
->i_location
.partitionReferenceNum
;
1897 *elen
= le32_to_cpu(sad
->extLength
) & UDF_EXTENT_LENGTH_MASK
;
1899 case ICBTAG_FLAG_AD_LONG
:
1900 lad
= udf_get_filelongad(ptr
, alen
, &epos
->offset
, inc
);
1903 etype
= le32_to_cpu(lad
->extLength
) >> 30;
1904 *eloc
= lelb_to_cpu(lad
->extLocation
);
1905 *elen
= le32_to_cpu(lad
->extLength
) & UDF_EXTENT_LENGTH_MASK
;
1908 udf_debug("alloc_type = %d unsupported\n",
1909 iinfo
->i_alloc_type
);
1916 static int8_t udf_insert_aext(struct inode
*inode
, struct extent_position epos
,
1917 struct kernel_lb_addr neloc
, uint32_t nelen
)
1919 struct kernel_lb_addr oeloc
;
1926 while ((etype
= udf_next_aext(inode
, &epos
, &oeloc
, &oelen
, 0)) != -1) {
1927 udf_write_aext(inode
, &epos
, &neloc
, nelen
, 1);
1929 nelen
= (etype
<< 30) | oelen
;
1931 udf_add_aext(inode
, &epos
, &neloc
, nelen
, 1);
1934 return (nelen
>> 30);
1937 int8_t udf_delete_aext(struct inode
*inode
, struct extent_position epos
,
1938 struct kernel_lb_addr eloc
, uint32_t elen
)
1940 struct extent_position oepos
;
1943 struct allocExtDesc
*aed
;
1944 struct udf_inode_info
*iinfo
;
1951 iinfo
= UDF_I(inode
);
1952 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
1953 adsize
= sizeof(struct short_ad
);
1954 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
1955 adsize
= sizeof(struct long_ad
);
1960 if (udf_next_aext(inode
, &epos
, &eloc
, &elen
, 1) == -1)
1963 while ((etype
= udf_next_aext(inode
, &epos
, &eloc
, &elen
, 1)) != -1) {
1964 udf_write_aext(inode
, &oepos
, &eloc
, (etype
<< 30) | elen
, 1);
1965 if (oepos
.bh
!= epos
.bh
) {
1966 oepos
.block
= epos
.block
;
1970 oepos
.offset
= epos
.offset
- adsize
;
1973 memset(&eloc
, 0x00, sizeof(struct kernel_lb_addr
));
1976 if (epos
.bh
!= oepos
.bh
) {
1977 udf_free_blocks(inode
->i_sb
, inode
, &epos
.block
, 0, 1);
1978 udf_write_aext(inode
, &oepos
, &eloc
, elen
, 1);
1979 udf_write_aext(inode
, &oepos
, &eloc
, elen
, 1);
1981 iinfo
->i_lenAlloc
-= (adsize
* 2);
1982 mark_inode_dirty(inode
);
1984 aed
= (struct allocExtDesc
*)oepos
.bh
->b_data
;
1985 le32_add_cpu(&aed
->lengthAllocDescs
, -(2 * adsize
));
1986 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
) ||
1987 UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0201)
1988 udf_update_tag(oepos
.bh
->b_data
,
1989 oepos
.offset
- (2 * adsize
));
1991 udf_update_tag(oepos
.bh
->b_data
,
1992 sizeof(struct allocExtDesc
));
1993 mark_buffer_dirty_inode(oepos
.bh
, inode
);
1996 udf_write_aext(inode
, &oepos
, &eloc
, elen
, 1);
1998 iinfo
->i_lenAlloc
-= adsize
;
1999 mark_inode_dirty(inode
);
2001 aed
= (struct allocExtDesc
*)oepos
.bh
->b_data
;
2002 le32_add_cpu(&aed
->lengthAllocDescs
, -adsize
);
2003 if (!UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_STRICT
) ||
2004 UDF_SB(inode
->i_sb
)->s_udfrev
>= 0x0201)
2005 udf_update_tag(oepos
.bh
->b_data
,
2006 epos
.offset
- adsize
);
2008 udf_update_tag(oepos
.bh
->b_data
,
2009 sizeof(struct allocExtDesc
));
2010 mark_buffer_dirty_inode(oepos
.bh
, inode
);
2017 return (elen
>> 30);
2020 int8_t inode_bmap(struct inode
*inode
, sector_t block
,
2021 struct extent_position
*pos
, struct kernel_lb_addr
*eloc
,
2022 uint32_t *elen
, sector_t
*offset
)
2024 unsigned char blocksize_bits
= inode
->i_sb
->s_blocksize_bits
;
2025 loff_t lbcount
= 0, bcount
=
2026 (loff_t
) block
<< blocksize_bits
;
2028 struct udf_inode_info
*iinfo
;
2030 iinfo
= UDF_I(inode
);
2032 pos
->block
= iinfo
->i_location
;
2037 etype
= udf_next_aext(inode
, pos
, eloc
, elen
, 1);
2039 *offset
= (bcount
- lbcount
) >> blocksize_bits
;
2040 iinfo
->i_lenExtents
= lbcount
;
2044 } while (lbcount
<= bcount
);
2046 *offset
= (bcount
+ *elen
- lbcount
) >> blocksize_bits
;
2051 long udf_block_map(struct inode
*inode
, sector_t block
)
2053 struct kernel_lb_addr eloc
;
2056 struct extent_position epos
= {};
2061 if (inode_bmap(inode
, block
, &epos
, &eloc
, &elen
, &offset
) ==
2062 (EXT_RECORDED_ALLOCATED
>> 30))
2063 ret
= udf_get_lb_pblock(inode
->i_sb
, &eloc
, offset
);
2070 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_VARCONV
))
2071 return udf_fixed_to_variable(ret
);