Import 2.3.26pre2
[davej-history.git] / fs / udf / inode.c
blob71083a7bdd993b35a87d09231f258bba3bb62bf1
1 /*
2 * inode.c
4 * PURPOSE
5 * Inode handling routines for the OSTA-UDF(tm) filesystem.
7 * CONTACTS
8 * E-mail regarding any portion of the Linux UDF file system should be
9 * directed to the development team mailing list (run by majordomo):
10 * linux_udf@hootie.lvld.hp.com
12 * COPYRIGHT
13 * This file is distributed under the terms of the GNU General Public
14 * License (GPL). Copies of the GPL can be obtained from:
15 * ftp://prep.ai.mit.edu/pub/gnu/GPL
16 * Each contributing author retains all rights to their own work.
18 * (C) 1998 Dave Boynton
19 * (C) 1998-1999 Ben Fennema
20 * (C) 1999 Stelias Computing Inc
22 * HISTORY
24 * 10/04/98 dgb Added rudimentary directory functions
25 * 10/07/98 Fully working udf_block_map! It works!
26 * 11/25/98 bmap altered to better support extents
27 * 12/06/98 blf partition support in udf_iget, udf_block_map and udf_read_inode
28 * 12/12/98 rewrote udf_block_map to handle next extents and descs across
29 * block boundaries (which is not actually allowed)
30 * 12/20/98 added support for strategy 4096
31 * 03/07/99 rewrote udf_block_map (again)
32 * New funcs, inode_bmap, udf_next_aext
33 * 04/19/99 Support for writing device EA's for major/minor #
37 #include "udfdecl.h"
38 #include <linux/locks.h>
39 #include <linux/mm.h>
40 #include <linux/smp_lock.h>
42 #include "udf_i.h"
43 #include "udf_sb.h"
45 #define EXTENT_MERGE_SIZE 5
47 static mode_t udf_convert_permissions(struct FileEntry *);
48 static int udf_update_inode(struct inode *, int);
49 static void udf_fill_inode(struct inode *, struct buffer_head *);
50 static struct buffer_head *inode_getblk(struct inode *, long, int *, long *, int *);
51 static void udf_split_extents(struct inode *, int *, int, int,
52 long_ad [EXTENT_MERGE_SIZE], int *);
53 static void udf_prealloc_extents(struct inode *, int, int,
54 long_ad [EXTENT_MERGE_SIZE], int *);
55 static void udf_merge_extents(struct inode *,
56 long_ad [EXTENT_MERGE_SIZE], int *);
57 static void udf_update_extents(struct inode *,
58 long_ad [EXTENT_MERGE_SIZE], int, int,
59 lb_addr, Uint32, struct buffer_head **);
61 static DECLARE_MUTEX(read_semaphore);
64 * udf_put_inode
66 * PURPOSE
68 * DESCRIPTION
69 * This routine is called whenever the kernel no longer needs the inode.
71 * HISTORY
72 * July 1, 1997 - Andrew E. Mileski
73 * Written, tested, and released.
75 * Called at each iput()
77 void udf_put_inode(struct inode * inode)
79 udf_discard_prealloc(inode);
83 * udf_delete_inode
85 * PURPOSE
86 * Clean-up before the specified inode is destroyed.
88 * DESCRIPTION
89 * This routine is called when the kernel destroys an inode structure
90 * ie. when iput() finds i_count == 0.
92 * HISTORY
93 * July 1, 1997 - Andrew E. Mileski
94 * Written, tested, and released.
96 * Called at the last iput() if i_nlink is zero.
98 void udf_delete_inode(struct inode * inode)
100 inode->i_size = 0;
101 if (inode->i_blocks)
102 udf_truncate(inode);
103 udf_free_inode(inode);
106 void udf_discard_prealloc(struct inode * inode)
108 #ifdef UDF_PREALLOCATE
109 lb_addr bloc, eloc;
110 Uint32 extoffset, elen, nelen, offset, adsize = 0;
111 struct buffer_head *bh = NULL;
113 if ((inode->i_size > 0) &&
114 (inode_bmap(inode, (inode->i_size-1) >> inode->i_sb->s_blocksize_bits,
115 &bloc, &extoffset, &eloc, &elen, &offset, &bh) ==
116 EXTENT_RECORDED_ALLOCATED))
118 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
119 adsize = sizeof(short_ad);
120 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
121 adsize = sizeof(long_ad);
122 else
124 udf_release_data(bh);
125 return;
128 nelen = (EXTENT_RECORDED_ALLOCATED << 30) |
129 ((((elen - 1) & ~(inode->i_sb->s_blocksize - 1)) |
130 ((inode->i_size - 1) & (inode->i_sb->s_blocksize - 1))) + 1);
132 if (nelen != ((EXTENT_RECORDED_ALLOCATED << 30) | elen))
134 extoffset -= adsize;
135 udf_write_aext(inode, bloc, &extoffset, eloc, nelen, &bh, 1);
138 if (udf_next_aext(inode, &bloc, &extoffset, &eloc, &elen, &bh, 0) ==
139 EXTENT_NOT_RECORDED_ALLOCATED)
141 udf_free_blocks(inode, eloc, 0, elen >> inode->i_sb->s_blocksize_bits);
142 memset(&eloc, 0x00, sizeof(lb_addr));
143 udf_write_aext(inode, bloc, &extoffset, eloc, 0, &bh, 1);
144 UDF_I_LENALLOC(inode) -= adsize;
145 udf_write_inode(inode);
147 udf_release_data(bh);
149 else if (bh)
150 udf_release_data(bh);
151 #endif
154 static int udf_alloc_block(struct inode *inode, Uint16 partition,
155 Uint32 goal, int *err)
157 int result = 0;
158 wait_on_super(inode->i_sb);
160 result = udf_new_block(inode, partition, goal, err);
162 return result;
165 struct buffer_head * udf_expand_adinicb(struct inode *inode, int *block, int isdir, int *err)
167 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
169 long_ad newad;
170 int newblock;
171 struct buffer_head *sbh = NULL, *dbh = NULL;
173 if (!UDF_I_LENALLOC(inode))
175 UDF_I_EXT0OFFS(inode) = 0;
176 UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_LONG;
177 mark_inode_dirty(inode);
178 if (inode->i_op == &udf_file_inode_operations_adinicb)
179 inode->i_op = &udf_file_inode_operations;
180 return NULL;
183 /* alloc block, and copy data to it */
184 *block = udf_alloc_block(inode,
185 UDF_I_LOCATION(inode).partitionReferenceNum,
186 UDF_I_LOCATION(inode).logicalBlockNum, err);
188 if (!(*block))
189 return NULL;
190 newblock = udf_get_pblock(inode->i_sb, *block,
191 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
192 if (!newblock)
193 return NULL;
194 sbh = udf_tread(inode->i_sb, inode->i_ino, inode->i_sb->s_blocksize);
195 if (!sbh)
196 return NULL;
197 dbh = udf_tread(inode->i_sb, newblock, inode->i_sb->s_blocksize);
198 if (!dbh)
199 return NULL;
201 if (isdir)
203 struct udf_fileident_bh sfibh, dfibh;
204 int f_pos = UDF_I_EXT0OFFS(inode) >> 2;
205 int size = (UDF_I_EXT0OFFS(inode) + inode->i_size) >> 2;
206 struct FileIdentDesc cfi, *sfi, *dfi;
208 sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
209 sfibh.sbh = sfibh.ebh = sbh;
210 dfibh.soffset = dfibh.eoffset = 0;
211 dfibh.sbh = dfibh.ebh = dbh;
212 while ( (f_pos < size) )
214 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL);
215 if (!sfi)
217 udf_release_data(sbh);
218 udf_release_data(dbh);
219 return NULL;
221 sfi->descTag.tagLocation = *block;
222 dfibh.soffset = dfibh.eoffset;
223 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
224 dfi = (struct FileIdentDesc *)(dbh->b_data + dfibh.soffset);
225 if (udf_write_fi(sfi, dfi, &dfibh, sfi->impUse,
226 sfi->fileIdent + sfi->lengthOfImpUse))
228 udf_release_data(sbh);
229 udf_release_data(dbh);
230 return NULL;
234 else
236 memcpy(dbh->b_data, sbh->b_data + udf_file_entry_alloc_offset(inode),
237 UDF_I_LENALLOC(inode));
239 mark_buffer_dirty(dbh, 1);
241 memset(sbh->b_data + udf_file_entry_alloc_offset(inode),
242 0, UDF_I_LENALLOC(inode));
244 memset(&newad, 0x00, sizeof(long_ad));
245 newad.extLength = UDF_I_EXT0LEN(inode) = inode->i_size;
246 newad.extLocation.logicalBlockNum = *block;
247 newad.extLocation.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
248 UDF_I_EXT0LOC(inode) = newad.extLocation;
249 /* UniqueID stuff */
251 memcpy(sbh->b_data + udf_file_entry_alloc_offset(inode),
252 &newad, sizeof(newad));
254 UDF_I_LENALLOC(inode) = sizeof(newad);
255 UDF_I_EXT0OFFS(inode) = 0;
256 UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_LONG;
257 inode->i_blocks += inode->i_sb->s_blocksize / 512;
258 udf_release_data(sbh);
259 mark_inode_dirty(inode);
260 inode->i_version ++;
261 if (inode->i_op == &udf_file_inode_operations_adinicb)
262 inode->i_op = &udf_file_inode_operations;
263 return dbh;
265 else
266 return NULL;
269 struct buffer_head * udf_getblk(struct inode * inode, long block,
270 int create, int * err)
272 struct buffer_head dummy;
273 int error;
275 dummy.b_state = 0;
276 dummy.b_blocknr = -1000;
277 error = udf_get_block(inode, block, &dummy, create);
278 *err = error;
279 if (!error & buffer_mapped(&dummy))
281 struct buffer_head *bh;
282 bh = getblk(dummy.b_dev, dummy.b_blocknr, inode->i_sb->s_blocksize);
283 if (buffer_new(&dummy))
285 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
286 mark_buffer_uptodate(bh, 1);
287 mark_buffer_dirty(bh, 1);
289 return bh;
291 return NULL;
294 int udf_get_block(struct inode *inode, long block, struct buffer_head *bh_result, int create)
296 int err, new;
297 struct buffer_head *bh;
298 unsigned long phys;
300 if (!create)
302 phys = udf_block_map(inode, block);
303 if (phys)
305 bh_result->b_dev = inode->i_dev;
306 bh_result->b_blocknr = phys;
307 bh_result->b_state |= (1UL << BH_Mapped);
309 return 0;
312 err = -EIO;
314 lock_kernel();
316 if (block < 0)
317 goto abort_negative;
319 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1)
321 UDF_I_NEXT_ALLOC_BLOCK(inode) ++;
322 UDF_I_NEXT_ALLOC_GOAL(inode) ++;
325 err = 0;
327 bh = inode_getblk(inode, block, &err, &phys, &new);
328 if (bh)
329 BUG();
330 if (err)
331 goto abort;
332 if (!phys)
333 BUG();
335 bh_result->b_dev = inode->i_dev;
336 bh_result->b_blocknr = phys;
337 bh_result->b_state |= (1UL << BH_Mapped);
338 if (new)
339 bh_result->b_state |= (1UL << BH_New);
340 abort:
341 unlock_kernel();
342 return err;
344 abort_negative:
345 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
346 goto abort;
349 static struct buffer_head * inode_getblk(struct inode * inode, long block,
350 int *err, long *phys, int *new)
352 struct buffer_head *pbh = NULL, *cbh = NULL, *result = NULL;
353 long_ad laarr[EXTENT_MERGE_SIZE];
354 Uint32 pextoffset = 0, cextoffset = 0, nextoffset = 0;
355 int count = 0, startnum = 0, endnum = 0;
356 Uint32 elen = 0;
357 lb_addr eloc, pbloc = UDF_I_LOCATION(inode), cbloc = UDF_I_LOCATION(inode);
358 int c = 1;
359 int lbcount = 0, b_off = 0, offset = 0;
360 Uint32 newblocknum, newblock;
361 char etype;
362 int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
363 char lastblock = 0;
365 pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode);
366 b_off = block << inode->i_sb->s_blocksize_bits;
367 pbloc = cbloc = UDF_I_LOCATION(inode);
369 /* find the extent which contains the block we are looking for.
370 alternate between laarr[0] and laarr[1] for locations of the
371 current extent, and the previous extent */
374 if (pbh != cbh)
376 udf_release_data(pbh);
377 pbh = cbh;
378 atomic_inc(&cbh->b_count);
379 pbloc = cbloc;
382 lbcount += elen;
384 pextoffset = cextoffset;
385 cextoffset = nextoffset;
387 if ((etype = udf_next_aext(inode, &cbloc, &nextoffset, &eloc, &elen, &cbh, 1)) == -1)
388 break;
390 c = !c;
392 laarr[c].extLength = (etype << 30) | elen;
393 laarr[c].extLocation = eloc;
395 if (etype != EXTENT_NOT_RECORDED_NOT_ALLOCATED)
396 pgoal = eloc.logicalBlockNum +
397 ((elen + inode->i_sb->s_blocksize - 1) >>
398 inode->i_sb->s_blocksize);
400 count ++;
401 } while (lbcount + elen <= b_off);
403 b_off -= lbcount;
404 offset = b_off >> inode->i_sb->s_blocksize_bits;
406 /* if the extent is allocated and recorded, return the block
407 if the extent is not a multiple of the blocksize, round up */
409 if (etype == EXTENT_RECORDED_ALLOCATED)
411 if (elen & (inode->i_sb->s_blocksize - 1))
413 elen = (EXTENT_RECORDED_ALLOCATED << 30) |
414 ((elen + inode->i_sb->s_blocksize - 1) &
415 ~(inode->i_sb->s_blocksize - 1));
416 etype = udf_write_aext(inode, cbloc, &cextoffset, eloc, elen, &cbh, 1);
418 udf_release_data(pbh);
419 udf_release_data(cbh);
420 newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
421 *phys = newblock;
422 return NULL;
425 if (etype == -1)
427 endnum = startnum = ((count > 1) ? 1 : count);
428 c = !c;
429 laarr[c].extLength = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) |
430 ((offset + 1) << inode->i_sb->s_blocksize_bits);
431 memset(&laarr[c].extLocation, 0x00, sizeof(lb_addr));
432 count ++;
433 endnum ++;
434 lastblock = 1;
436 else
437 endnum = startnum = ((count > 2) ? 2 : count);
439 /* if the current extent is in position 0, swap it with the previous */
440 if (!c && count != 1)
442 laarr[2] = laarr[0];
443 laarr[0] = laarr[1];
444 laarr[1] = laarr[2];
445 c = 1;
448 /* if the current block is located in a extent, read the next extent */
449 if (etype != -1)
451 if ((etype = udf_next_aext(inode, &cbloc, &nextoffset, &eloc, &elen, &cbh, 0)) != -1)
453 laarr[c+1].extLength = (etype << 30) | elen;
454 laarr[c+1].extLocation = eloc;
455 count ++;
456 startnum ++;
457 endnum ++;
459 else
460 lastblock = 1;
462 udf_release_data(cbh);
464 *err = -EFBIG;
466 /* Check file limits.. */
468 unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
469 if (limit < RLIM_INFINITY)
471 limit >>= inode->i_sb->s_blocksize_bits;
472 if (block >= limit)
474 send_sig(SIGXFSZ, current, 0);
475 *err = -EFBIG;
476 return NULL;
481 /* if the current extent is not recorded but allocated, get the
482 block in the extent corresponding to the requested block */
483 if ((laarr[c].extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED)
484 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
485 else /* otherwise, allocate a new block */
487 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
488 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
490 if (!goal)
492 if (!(goal = pgoal))
493 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
496 if (!(newblocknum = udf_alloc_block(inode,
497 UDF_I_LOCATION(inode).partitionReferenceNum, goal, err)))
499 udf_release_data(pbh);
500 *err = -ENOSPC;
501 return NULL;
505 /* if the extent the requsted block is located in contains multiple blocks,
506 split the extent into at most three extents. blocks prior to requested
507 block, requested block, and blocks after requested block */
508 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
510 #ifdef UDF_PREALLOCATE
511 /* preallocate blocks */
512 udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
513 #endif
515 /* merge any continuous blocks in laarr */
516 udf_merge_extents(inode, laarr, &endnum);
518 /* write back the new extents, inserting new extents if the new number
519 of extents is greater than the old number, and deleting extents if
520 the new number of extents is less than the old number */
521 udf_update_extents(inode, laarr, startnum, endnum, pbloc, pextoffset, &pbh);
523 udf_release_data(pbh);
525 if (pextoffset == udf_file_entry_alloc_offset(inode))
527 UDF_I_EXT0LEN(inode) = laarr[0].extLength;
528 UDF_I_EXT0LOC(inode) = laarr[0].extLocation;
531 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
532 UDF_I_LOCATION(inode).partitionReferenceNum, 0)))
534 return NULL;
536 *phys = newblock;
537 *err = 0;
538 *new = 1;
539 UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
540 UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
541 inode->i_ctime = CURRENT_TIME;
542 UDF_I_UCTIME(inode) = CURRENT_UTIME;
543 inode->i_blocks += inode->i_sb->s_blocksize / 512;
544 #if 0
545 if (IS_SYNC(inode) || UDF_I_OSYNC(inode))
546 udf_sync_inode(inode);
547 else
548 #endif
549 mark_inode_dirty(inode);
550 return result;
553 static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum,
554 long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
556 if ((laarr[*c].extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED ||
557 (laarr[*c].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED)
559 int curr = *c;
560 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
561 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
562 int type = laarr[curr].extLength & ~UDF_EXTENT_LENGTH_MASK;
564 if (blen == 1)
566 else if (!offset || blen == offset + 1)
568 laarr[curr+2] = laarr[curr+1];
569 laarr[curr+1] = laarr[curr];
571 else
573 laarr[curr+3] = laarr[curr+1];
574 laarr[curr+2] = laarr[curr+1] = laarr[curr];
577 if (offset)
579 laarr[curr].extLength = type |
580 (offset << inode->i_sb->s_blocksize_bits);
581 curr ++;
582 (*c) ++;
583 (*endnum) ++;
586 laarr[curr].extLocation.logicalBlockNum = newblocknum;
587 if ((type >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED)
588 laarr[curr].extLocation.partitionReferenceNum =
589 UDF_I_LOCATION(inode).partitionReferenceNum;
590 laarr[curr].extLength = (EXTENT_RECORDED_ALLOCATED << 30) |
591 inode->i_sb->s_blocksize;
592 curr ++;
594 if (blen != offset + 1)
596 if ((type >> 30) == EXTENT_NOT_RECORDED_ALLOCATED)
597 laarr[curr].extLocation.logicalBlockNum += (offset + 1);
598 laarr[curr].extLength = type |
599 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
600 curr ++;
601 (*endnum) ++;
606 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
607 long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
609 int start, length = 0, currlength = 0, i;
611 if (*endnum == (c+1) && !lastblock)
612 return;
614 if ((laarr[c+1].extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED)
616 start = c+1;
617 length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) +
618 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
620 else
621 start = c;
623 for (i=start+1; i<=*endnum; i++)
625 if (i == *endnum)
627 if (lastblock)
628 length += UDF_DEFAULT_PREALLOC_BLOCKS;
630 else if ((laarr[i].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED)
631 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
632 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
633 else
634 break;
637 if (length)
639 int next = laarr[start].extLocation.logicalBlockNum +
640 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
641 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
642 int numalloc = udf_alloc_blocks(inode,
643 laarr[start].extLocation.partitionReferenceNum,
644 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
645 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
647 if (numalloc)
649 if (start == (c+1))
650 laarr[start].extLength +=
651 (numalloc << inode->i_sb->s_blocksize_bits);
652 else
654 memmove(&laarr[c+2], &laarr[c+1],
655 sizeof(long_ad) * (*endnum - (c+1)));
656 (*endnum) ++;
657 laarr[c+1].extLocation.logicalBlockNum = next;
658 laarr[c+1].extLocation.partitionReferenceNum =
659 laarr[c].extLocation.partitionReferenceNum;
660 laarr[c+1].extLength = (EXTENT_NOT_RECORDED_ALLOCATED << 30) |
661 (numalloc << inode->i_sb->s_blocksize_bits);
662 start = c+1;
665 for (i=start+1; numalloc && i<*endnum; i++)
667 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
668 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
670 if (elen > numalloc)
672 laarr[c+1].extLength -=
673 (numalloc << inode->i_sb->s_blocksize_bits);
674 numalloc = 0;
676 else
678 numalloc -= elen;
679 if (*endnum > (i+1))
680 memmove(&laarr[i], &laarr[i+1],
681 sizeof(long_ad) * (*endnum - (i+1)));
682 i --;
683 (*endnum) --;
690 static void udf_merge_extents(struct inode *inode,
691 long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
693 int i;
695 for (i=0; i<(*endnum-1); i++)
697 if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30))
699 if (((laarr[i].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED) ||
700 ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
701 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
702 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits)))
704 laarr[i].extLength = laarr[i+1].extLength +
705 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
706 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1));
707 if (*endnum > (i+2))
708 memmove(&laarr[i+1], &laarr[i+2],
709 sizeof(long_ad) * (*endnum - (i+2)));
710 i --;
711 (*endnum) --;
717 static void udf_update_extents(struct inode *inode,
718 long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum,
719 lb_addr pbloc, Uint32 pextoffset, struct buffer_head **pbh)
721 int start = 0, i;
722 lb_addr tmploc;
723 Uint32 tmplen;
725 if (startnum > endnum)
727 for (i=0; i<(startnum-endnum); i++)
729 udf_delete_aext(inode, pbloc, pextoffset, laarr[i].extLocation,
730 laarr[i].extLength, *pbh);
733 else if (startnum < endnum)
735 for (i=0; i<(endnum-startnum); i++)
737 udf_insert_aext(inode, pbloc, pextoffset, laarr[i].extLocation,
738 laarr[i].extLength, *pbh);
739 udf_next_aext(inode, &pbloc, &pextoffset, &laarr[i].extLocation,
740 &laarr[i].extLength, pbh, 1);
741 start ++;
745 for (i=start; i<endnum; i++)
747 udf_next_aext(inode, &pbloc, &pextoffset, &tmploc, &tmplen, pbh, 0);
748 udf_write_aext(inode, pbloc, &pextoffset, laarr[i].extLocation,
749 laarr[i].extLength, pbh, 1);
753 struct buffer_head * udf_bread(struct inode * inode, int block,
754 int create, int * err)
756 struct buffer_head * bh = NULL;
757 int prev_blocks;
759 prev_blocks = inode->i_blocks;
761 bh = udf_getblk(inode, block, create, err);
762 if (!bh)
763 return NULL;
765 #if 0
766 if (create &&
767 S_ISDIR(inode->i_mode) &&
768 inode->i_blocks > prev_blocks)
770 int i;
771 struct buffer_head *tmp_bh = NULL;
773 for (i=1;
774 i < UDF_DEFAULT_PREALLOC_DIR_BLOCKS;
775 i++)
777 tmp_bh = udf_getblk(inode, block+i, create, err);
778 if (!tmp_bh)
780 udf_release_data(bh);
781 return 0;
783 udf_release_data(tmp_bh);
786 #endif
788 if (buffer_uptodate(bh))
789 return bh;
790 ll_rw_block(READ, 1, &bh);
791 wait_on_buffer(bh);
792 if (buffer_uptodate(bh))
793 return bh;
794 brelse(bh);
795 *err = -EIO;
796 return NULL;
800 * udf_read_inode
802 * PURPOSE
803 * Read an inode.
805 * DESCRIPTION
806 * This routine is called by iget() [which is called by udf_iget()]
807 * (clean_inode() will have been called first)
808 * when an inode is first read into memory.
810 * HISTORY
811 * July 1, 1997 - Andrew E. Mileski
812 * Written, tested, and released.
814 * 12/19/98 dgb Updated to fix size problems.
816 void
817 udf_read_inode(struct inode *inode)
819 struct buffer_head *bh = NULL;
820 struct FileEntry *fe;
821 Uint16 ident;
824 * Set defaults, but the inode is still incomplete!
825 * Note: get_new_inode() sets the following on a new inode:
826 * i_sb = sb
827 * i_dev = sb->s_dev;
828 * i_no = ino
829 * i_flags = sb->s_flags
830 * i_state = 0
831 * clean_inode(): zero fills and sets
832 * i_count = 1
833 * i_nlink = 1
834 * i_op = NULL;
837 inode->i_blksize = inode->i_sb->s_blocksize;
838 inode->i_version = 1;
840 UDF_I_EXT0LEN(inode)=0;
841 UDF_I_EXT0LOC(inode).logicalBlockNum = 0xFFFFFFFF;
842 UDF_I_EXT0LOC(inode).partitionReferenceNum = 0xFFFF;
843 UDF_I_EXT0OFFS(inode)=0;
844 UDF_I_ALLOCTYPE(inode)=0;
846 memcpy(&UDF_I_LOCATION(inode), &UDF_SB_LOCATION(inode->i_sb), sizeof(lb_addr));
848 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
850 if (!bh)
852 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
853 inode->i_ino);
854 make_bad_inode(inode);
855 return;
858 if (ident != TID_FILE_ENTRY && ident != TID_EXTENDED_FILE_ENTRY)
860 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
861 inode->i_ino, ident);
862 udf_release_data(bh);
863 make_bad_inode(inode);
864 return;
867 fe = (struct FileEntry *)bh->b_data;
869 if (le16_to_cpu(fe->icbTag.strategyType) == 4096)
871 struct buffer_head *ibh = NULL, *nbh = NULL;
872 struct IndirectEntry *ie;
874 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
875 if (ident == TID_INDIRECT_ENTRY)
877 if (ibh)
879 lb_addr loc;
880 ie = (struct IndirectEntry *)ibh->b_data;
882 loc = lelb_to_cpu(ie->indirectICB.extLocation);
884 if (ie->indirectICB.extLength &&
885 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident)))
887 if (ident == TID_FILE_ENTRY ||
888 ident == TID_EXTENDED_FILE_ENTRY)
890 memcpy(&UDF_SB_LOCATION(inode->i_sb), &loc, sizeof(lb_addr));
891 udf_release_data(bh);
892 udf_release_data(ibh);
893 udf_release_data(nbh);
894 udf_read_inode(inode);
895 return;
897 else
899 udf_release_data(nbh);
900 udf_release_data(ibh);
903 else
904 udf_release_data(ibh);
907 else
908 udf_release_data(ibh);
910 else if (le16_to_cpu(fe->icbTag.strategyType) != 4)
912 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
913 le16_to_cpu(fe->icbTag.strategyType));
914 udf_release_data(bh);
915 make_bad_inode(inode);
916 return;
918 udf_fill_inode(inode, bh);
919 udf_release_data(bh);
922 static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
924 struct FileEntry *fe;
925 struct ExtendedFileEntry *efe;
926 time_t convtime;
927 long convtime_usec;
928 int offset, alen;
930 fe = (struct FileEntry *)bh->b_data;
931 efe = (struct ExtendedFileEntry *)bh->b_data;
933 if (fe->descTag.tagIdent == TID_EXTENDED_FILE_ENTRY)
934 UDF_I_EXTENDED_FE(inode) = 1;
935 else /* fe->descTag.tagIdent == TID_FILE_ENTRY */
936 UDF_I_EXTENDED_FE(inode) = 0;
938 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
939 UDF_I_STRAT4096(inode) = 0;
940 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
941 UDF_I_STRAT4096(inode) = 1;
943 inode->i_uid = udf_convert_uid(le32_to_cpu(fe->uid));
944 if ( !inode->i_uid ) inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
946 inode->i_gid = udf_convert_gid(le32_to_cpu(fe->gid));
947 if ( !inode->i_gid ) inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
949 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
950 if (!inode->i_nlink)
951 inode->i_nlink = 1;
953 inode->i_size = le64_to_cpu(fe->informationLength);
954 #if BITS_PER_LONG < 64
955 if (le64_to_cpu(fe->informationLength) & 0xFFFFFFFF00000000ULL)
956 inode->i_size = (Uint32)-1;
957 #endif
959 inode->i_mode = udf_convert_permissions(fe);
960 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
962 #ifdef UDF_PREALLOCATE
963 #if 0
964 UDF_I_PREALLOC_BLOCK(inode) = 0;
965 UDF_I_PREALLOC_COUNT(inode) = 0;
966 #endif
967 #endif
968 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
969 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
971 UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICB_FLAG_ALLOC_MASK;
973 if (UDF_I_EXTENDED_FE(inode) == 0)
975 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
976 (inode->i_sb->s_blocksize_bits - 9);
978 if ( udf_stamp_to_time(&convtime, &convtime_usec,
979 lets_to_cpu(fe->modificationTime)) )
981 inode->i_mtime = convtime;
982 UDF_I_UMTIME(inode) = convtime_usec;
983 inode->i_ctime = convtime;
984 UDF_I_UCTIME(inode) = convtime_usec;
986 else
988 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
989 UDF_I_UMTIME(inode) = 0;
990 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
991 UDF_I_UCTIME(inode) = 0;
994 if ( udf_stamp_to_time(&convtime, &convtime_usec,
995 lets_to_cpu(fe->accessTime)) )
997 inode->i_atime = convtime;
998 UDF_I_UATIME(inode) = convtime_usec;
1000 else
1002 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1003 UDF_I_UATIME(inode) = convtime_usec;
1006 UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
1007 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1008 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1009 offset = sizeof(struct FileEntry) + UDF_I_LENEATTR(inode);
1010 alen = offset + UDF_I_LENALLOC(inode);
1012 else
1014 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1015 (inode->i_sb->s_blocksize_bits - 9);
1017 if ( udf_stamp_to_time(&convtime, &convtime_usec,
1018 lets_to_cpu(efe->modificationTime)) )
1020 inode->i_mtime = convtime;
1021 UDF_I_UMTIME(inode) = convtime_usec;
1023 else
1025 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1026 UDF_I_UMTIME(inode) = 0;
1029 if ( udf_stamp_to_time(&convtime, &convtime_usec,
1030 lets_to_cpu(efe->accessTime)) )
1032 inode->i_atime = convtime;
1033 UDF_I_UATIME(inode) = convtime_usec;
1035 else
1037 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1038 UDF_I_UATIME(inode) = 0;
1041 if ( udf_stamp_to_time(&convtime, &convtime_usec,
1042 lets_to_cpu(efe->createTime)) )
1044 inode->i_ctime = convtime;
1045 UDF_I_UCTIME(inode) = convtime_usec;
1047 else
1049 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1050 UDF_I_UCTIME(inode) = 0;
1053 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1054 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1055 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1056 offset = sizeof(struct ExtendedFileEntry) + UDF_I_LENEATTR(inode);
1057 alen = offset + UDF_I_LENALLOC(inode);
1060 switch (UDF_I_ALLOCTYPE(inode))
1062 case ICB_FLAG_AD_SHORT:
1064 short_ad * sa;
1066 sa = udf_get_fileshortad(fe, alen, &offset, 1);
1067 if (sa)
1069 UDF_I_EXT0LEN(inode) = le32_to_cpu(sa->extLength);
1070 UDF_I_EXT0LOC(inode).logicalBlockNum = le32_to_cpu(sa->extPosition);
1071 UDF_I_EXT0LOC(inode).partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1073 break;
1075 case ICB_FLAG_AD_LONG:
1077 long_ad * la;
1079 la = udf_get_filelongad(fe, alen, &offset, 1);
1080 if (la)
1082 UDF_I_EXT0LEN(inode) = le32_to_cpu(la->extLength);
1083 UDF_I_EXT0LOC(inode).logicalBlockNum = le32_to_cpu(la->extLocation.logicalBlockNum);
1084 UDF_I_EXT0LOC(inode).partitionReferenceNum = le16_to_cpu(la->extLocation.partitionReferenceNum);
1086 break;
1088 case ICB_FLAG_AD_EXTENDED:
1090 extent_ad * ext;
1092 ext = udf_get_fileextent(fe, alen, &offset);
1093 if ( (ext) && (ext->extLength) )
1095 UDF_I_EXT0LEN(inode) = le32_to_cpu(ext->extLength);
1096 #if 0
1097 UDF_I_EXT0LOC(inode) = ext->extLocation;
1098 #endif
1100 break;
1102 case ICB_FLAG_AD_IN_ICB: /* short directories */
1104 UDF_I_EXT0LEN(inode) = le32_to_cpu(fe->lengthAllocDescs);
1105 UDF_I_EXT0LOC(inode) = UDF_I_LOCATION(inode);
1106 UDF_I_EXT0OFFS(inode) = sizeof(struct FileEntry) +
1107 le32_to_cpu(fe->lengthExtendedAttr);
1108 break;
1110 } /* end switch ad_type */
1112 switch (fe->icbTag.fileType)
1114 case FILE_TYPE_DIRECTORY:
1116 inode->i_op = &udf_dir_inode_operations;
1117 inode->i_mode |= S_IFDIR;
1118 inode->i_nlink ++;
1119 break;
1121 case FILE_TYPE_REGULAR:
1122 case FILE_TYPE_NONE:
1124 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
1125 inode->i_op = &udf_file_inode_operations_adinicb;
1126 else
1127 inode->i_op = &udf_file_inode_operations;
1128 inode->i_mode |= S_IFREG;
1129 break;
1131 case FILE_TYPE_BLOCK:
1133 inode->i_op = &blkdev_inode_operations;
1134 inode->i_mode |= S_IFBLK;
1135 break;
1137 case FILE_TYPE_CHAR:
1139 inode->i_op = &chrdev_inode_operations;
1140 inode->i_mode |= S_IFCHR;
1141 break;
1143 case FILE_TYPE_FIFO:
1145 init_fifo(inode);
1147 case FILE_TYPE_SYMLINK:
1149 /* untested! */
1150 inode->i_op = &udf_symlink_inode_operations;
1151 inode->i_mode = S_IFLNK|S_IRWXUGO;
1152 break;
1154 default:
1156 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1157 inode->i_ino, fe->icbTag.fileType);
1158 make_bad_inode(inode);
1159 return;
1162 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1164 struct buffer_head *tbh = NULL;
1165 struct DeviceSpecificationExtendedAttr *dsea =
1166 (struct DeviceSpecificationExtendedAttr *)
1167 udf_get_extendedattr(inode, 12, 1, &tbh);
1169 if (dsea)
1171 inode->i_rdev = to_kdev_t(
1172 (le32_to_cpu(dsea->majorDeviceIdent)) << 8) |
1173 (le32_to_cpu(dsea->minorDeviceIdent) & 0xFF);
1174 /* Developer ID ??? */
1175 udf_release_data(tbh);
1177 else
1179 make_bad_inode(inode);
1184 static mode_t
1185 udf_convert_permissions(struct FileEntry *fe)
1187 mode_t mode;
1188 Uint32 permissions;
1189 Uint32 flags;
1191 permissions = le32_to_cpu(fe->permissions);
1192 flags = le16_to_cpu(fe->icbTag.flags);
1194 mode = (( permissions ) & S_IRWXO) |
1195 (( permissions >> 2 ) & S_IRWXG) |
1196 (( permissions >> 4 ) & S_IRWXU) |
1197 (( flags & ICB_FLAG_SETUID) ? S_ISUID : 0) |
1198 (( flags & ICB_FLAG_SETGID) ? S_ISGID : 0) |
1199 (( flags & ICB_FLAG_STICKY) ? S_ISVTX : 0);
1201 return mode;
1205 * udf_write_inode
1207 * PURPOSE
1208 * Write out the specified inode.
1210 * DESCRIPTION
1211 * This routine is called whenever an inode is synced.
1212 * Currently this routine is just a placeholder.
1214 * HISTORY
1215 * July 1, 1997 - Andrew E. Mileski
1216 * Written, tested, and released.
1219 void udf_write_inode(struct inode * inode)
1221 udf_update_inode(inode, 0);
1224 int udf_sync_inode(struct inode * inode)
1226 return udf_update_inode(inode, 1);
1229 static int
1230 udf_update_inode(struct inode *inode, int do_sync)
1232 struct buffer_head *bh = NULL;
1233 struct FileEntry *fe;
1234 struct ExtendedFileEntry *efe;
1235 Uint32 udfperms;
1236 Uint16 icbflags;
1237 Uint16 crclen;
1238 int i;
1239 timestamp cpu_time;
1240 int err = 0;
1242 bh = udf_tread(inode->i_sb,
1243 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0),
1244 inode->i_sb->s_blocksize);
1245 if (!bh)
1247 udf_debug("bread failure\n");
1248 return -EIO;
1250 fe = (struct FileEntry *)bh->b_data;
1251 efe = (struct ExtendedFileEntry *)bh->b_data;
1253 if (inode->i_uid != UDF_SB(inode->i_sb)->s_uid)
1254 fe->uid = cpu_to_le32(inode->i_uid);
1256 if (inode->i_gid != UDF_SB(inode->i_sb)->s_gid)
1257 fe->gid = cpu_to_le32(inode->i_gid);
1259 udfperms = ((inode->i_mode & S_IRWXO) ) |
1260 ((inode->i_mode & S_IRWXG) << 2) |
1261 ((inode->i_mode & S_IRWXU) << 4);
1263 udfperms |= (le32_to_cpu(fe->permissions) &
1264 (PERM_O_DELETE | PERM_O_CHATTR |
1265 PERM_G_DELETE | PERM_G_CHATTR |
1266 PERM_U_DELETE | PERM_U_CHATTR));
1267 fe->permissions = cpu_to_le32(udfperms);
1269 if (S_ISDIR(inode->i_mode))
1270 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1271 else
1272 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1275 fe->informationLength = cpu_to_le64(inode->i_size);
1277 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1279 EntityID *eid;
1280 struct buffer_head *tbh = NULL;
1281 struct DeviceSpecificationExtendedAttr *dsea =
1282 (struct DeviceSpecificationExtendedAttr *)
1283 udf_get_extendedattr(inode, 12, 1, &tbh);
1285 if (!dsea)
1287 dsea = (struct DeviceSpecificationExtendedAttr *)
1288 udf_add_extendedattr(inode,
1289 sizeof(struct DeviceSpecificationExtendedAttr) +
1290 sizeof(EntityID), 12, 0x3, &tbh);
1291 dsea->attrType = 12;
1292 dsea->attrSubtype = 1;
1293 dsea->attrLength = sizeof(struct DeviceSpecificationExtendedAttr) +
1294 sizeof(EntityID);
1295 dsea->impUseLength = sizeof(EntityID);
1297 eid = (EntityID *)dsea->impUse;
1298 memset(eid, 0, sizeof(EntityID));
1299 strcpy(eid->ident, UDF_ID_DEVELOPER);
1300 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
1301 eid->identSuffix[1] = UDF_OS_ID_LINUX;
1302 dsea->majorDeviceIdent = kdev_t_to_nr(inode->i_rdev) >> 8;
1303 dsea->minorDeviceIdent = kdev_t_to_nr(inode->i_rdev) & 0xFF;
1304 mark_buffer_dirty(tbh, 1);
1305 udf_release_data(tbh);
1308 if (UDF_I_EXTENDED_FE(inode) == 0)
1310 fe->logicalBlocksRecorded = cpu_to_le64(
1311 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1312 (inode->i_sb->s_blocksize_bits - 9));
1314 if (udf_time_to_stamp(&cpu_time, inode->i_atime, UDF_I_UATIME(inode)))
1315 fe->accessTime = cpu_to_lets(cpu_time);
1316 if (udf_time_to_stamp(&cpu_time, inode->i_mtime, UDF_I_UMTIME(inode)))
1317 fe->modificationTime = cpu_to_lets(cpu_time);
1318 memset(&(fe->impIdent), 0, sizeof(EntityID));
1319 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1320 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1321 fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1322 fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1323 fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1324 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1325 fe->descTag.tagIdent = le16_to_cpu(TID_FILE_ENTRY);
1326 crclen = sizeof(struct FileEntry);
1328 else
1330 efe->logicalBlocksRecorded = cpu_to_le64(
1331 (inode->i_blocks + (2 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
1332 (inode->i_sb->s_blocksize_bits - 9));
1334 if (udf_time_to_stamp(&cpu_time, inode->i_atime, UDF_I_UATIME(inode)))
1335 efe->accessTime = cpu_to_lets(cpu_time);
1336 if (udf_time_to_stamp(&cpu_time, inode->i_mtime, UDF_I_UMTIME(inode)))
1337 efe->modificationTime = cpu_to_lets(cpu_time);
1338 if (udf_time_to_stamp(&cpu_time, inode->i_ctime, UDF_I_UCTIME(inode)))
1339 efe->createTime = cpu_to_lets(cpu_time);
1340 memset(&(efe->impIdent), 0, sizeof(EntityID));
1341 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
1342 efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1343 efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1344 efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
1345 efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
1346 efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1347 efe->descTag.tagIdent = le16_to_cpu(TID_EXTENDED_FILE_ENTRY);
1348 crclen = sizeof(struct ExtendedFileEntry);
1350 fe->icbTag.strategyType = UDF_I_STRAT4096(inode) ? cpu_to_le16(4096) :
1351 cpu_to_le16(4);
1353 if (S_ISDIR(inode->i_mode))
1354 fe->icbTag.fileType = FILE_TYPE_DIRECTORY;
1355 else if (S_ISREG(inode->i_mode))
1356 fe->icbTag.fileType = FILE_TYPE_REGULAR;
1357 else if (S_ISLNK(inode->i_mode))
1358 fe->icbTag.fileType = FILE_TYPE_SYMLINK;
1359 else if (S_ISBLK(inode->i_mode))
1360 fe->icbTag.fileType = FILE_TYPE_BLOCK;
1361 else if (S_ISCHR(inode->i_mode))
1362 fe->icbTag.fileType = FILE_TYPE_CHAR;
1363 else if (S_ISFIFO(inode->i_mode))
1364 fe->icbTag.fileType = FILE_TYPE_FIFO;
1366 icbflags = UDF_I_ALLOCTYPE(inode) |
1367 ((inode->i_mode & S_ISUID) ? ICB_FLAG_SETUID : 0) |
1368 ((inode->i_mode & S_ISGID) ? ICB_FLAG_SETGID : 0) |
1369 ((inode->i_mode & S_ISVTX) ? ICB_FLAG_STICKY : 0) |
1370 (le16_to_cpu(fe->icbTag.flags) &
1371 ~(ICB_FLAG_ALLOC_MASK | ICB_FLAG_SETUID |
1372 ICB_FLAG_SETGID | ICB_FLAG_STICKY));
1374 fe->icbTag.flags = cpu_to_le16(icbflags);
1375 fe->descTag.descVersion = cpu_to_le16(2);
1376 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
1377 fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1378 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1379 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1380 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1382 fe->descTag.tagChecksum = 0;
1383 for (i=0; i<16; i++)
1384 if (i != 4)
1385 fe->descTag.tagChecksum += ((Uint8 *)&(fe->descTag))[i];
1387 /* write the data blocks */
1388 mark_buffer_dirty(bh, 1);
1389 if (do_sync)
1391 ll_rw_block(WRITE, 1, &bh);
1392 wait_on_buffer(bh);
1393 if (buffer_req(bh) && !buffer_uptodate(bh))
1395 printk("IO error syncing udf inode [%s:%08lx]\n",
1396 bdevname(inode->i_dev), inode->i_ino);
1397 err = -EIO;
1400 udf_release_data(bh);
1401 return err;
1405 * udf_iget
1407 * PURPOSE
1408 * Get an inode.
1410 * DESCRIPTION
1411 * This routine replaces iget() and read_inode().
1413 * HISTORY
1414 * October 3, 1997 - Andrew E. Mileski
1415 * Written, tested, and released.
1417 * 12/19/98 dgb Added semaphore and changed to be a wrapper of iget
1419 struct inode *
1420 udf_iget(struct super_block *sb, lb_addr ino)
1422 struct inode *inode;
1423 unsigned long block;
1425 block = udf_get_lb_pblock(sb, ino, 0);
1427 down(&read_semaphore); /* serialize access to UDF_SB_LOCATION() */
1428 /* This is really icky.. should fix -- blf */
1430 /* put the location where udf_read_inode can find it */
1431 memcpy(&UDF_SB_LOCATION(sb), &ino, sizeof(lb_addr));
1433 /* Get the inode */
1435 inode = iget(sb, block);
1436 /* calls udf_read_inode() ! */
1438 up(&read_semaphore);
1440 if (!inode)
1442 printk(KERN_ERR "udf: iget() failed\n");
1443 return NULL;
1445 else if (is_bad_inode(inode))
1447 iput(inode);
1448 return NULL;
1451 if ( ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum) )
1453 udf_debug("block=%d, partition=%d out of range\n",
1454 ino.logicalBlockNum, ino.partitionReferenceNum);
1455 return NULL;
1458 return inode;
1461 int udf_add_aext(struct inode *inode, lb_addr *bloc, int *extoffset,
1462 lb_addr eloc, Uint32 elen, struct buffer_head **bh, int inc)
1464 int adsize;
1465 short_ad *sad = NULL;
1466 long_ad *lad = NULL;
1467 struct AllocExtDesc *aed;
1468 int ret;
1470 if (!(*bh))
1472 if (!(*bh = udf_tread(inode->i_sb,
1473 udf_get_lb_pblock(inode->i_sb, *bloc, 0),
1474 inode->i_sb->s_blocksize)))
1476 udf_debug("reading block %d failed!\n",
1477 udf_get_lb_pblock(inode->i_sb, *bloc, 0));
1478 return -1;
1482 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1483 adsize = sizeof(short_ad);
1484 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1485 adsize = sizeof(long_ad);
1486 else
1487 return -1;
1489 if (*extoffset + (2 * adsize) > inode->i_sb->s_blocksize)
1491 char *sptr, *dptr;
1492 struct buffer_head *nbh;
1493 int err, loffset;
1494 Uint32 lblock = bloc->logicalBlockNum;
1495 Uint16 lpart = bloc->partitionReferenceNum;
1497 if (!(bloc->logicalBlockNum = udf_new_block(inode,
1498 lpart, lblock, &err)))
1500 return -1;
1502 if (!(nbh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
1503 *bloc, 0), inode->i_sb->s_blocksize)))
1505 return -1;
1507 aed = (struct AllocExtDesc *)(nbh->b_data);
1508 aed->previousAllocExtLocation = cpu_to_le32(lblock);
1509 if (*extoffset + adsize > inode->i_sb->s_blocksize)
1511 loffset = *extoffset;
1512 aed->lengthAllocDescs = cpu_to_le32(adsize);
1513 sptr = (*bh)->b_data + *extoffset - adsize;
1514 dptr = nbh->b_data + sizeof(struct AllocExtDesc);
1515 memcpy(dptr, sptr, adsize);
1516 *extoffset = sizeof(struct AllocExtDesc) + adsize;
1518 else
1520 loffset = *extoffset + adsize;
1521 aed->lengthAllocDescs = cpu_to_le32(0);
1522 sptr = (*bh)->b_data + *extoffset;
1523 *extoffset = sizeof(struct AllocExtDesc);
1525 if (UDF_I_LOCATION(inode).logicalBlockNum == lblock)
1526 UDF_I_LENALLOC(inode) += adsize;
1527 else
1529 aed = (struct AllocExtDesc *)(*bh)->b_data;
1530 aed->lengthAllocDescs =
1531 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1534 udf_new_tag(nbh->b_data, TID_ALLOC_EXTENT_DESC, 2, 1,
1535 bloc->logicalBlockNum, sizeof(tag));
1536 switch (UDF_I_ALLOCTYPE(inode))
1538 case ICB_FLAG_AD_SHORT:
1540 sad = (short_ad *)sptr;
1541 sad->extLength = EXTENT_NEXT_EXTENT_ALLOCDECS << 30 |
1542 inode->i_sb->s_blocksize;
1543 sad->extPosition = cpu_to_le32(bloc->logicalBlockNum);
1544 break;
1546 case ICB_FLAG_AD_LONG:
1548 lad = (long_ad *)sptr;
1549 lad->extLength = EXTENT_NEXT_EXTENT_ALLOCDECS << 30 |
1550 inode->i_sb->s_blocksize;
1551 lad->extLocation = cpu_to_lelb(*bloc);
1552 break;
1555 udf_update_tag((*bh)->b_data, loffset);
1556 mark_buffer_dirty(*bh, 1);
1557 udf_release_data(*bh);
1558 *bh = nbh;
1561 ret = udf_write_aext(inode, *bloc, extoffset, eloc, elen, bh, inc);
1563 if (!memcmp(&UDF_I_LOCATION(inode), bloc, sizeof(lb_addr)))
1565 UDF_I_LENALLOC(inode) += adsize;
1566 mark_inode_dirty(inode);
1568 else
1570 aed = (struct AllocExtDesc *)(*bh)->b_data;
1571 aed->lengthAllocDescs =
1572 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1573 udf_update_tag((*bh)->b_data, *extoffset + (inc ? 0 : adsize));
1574 mark_buffer_dirty(*bh, 1);
1577 return ret;
1580 int udf_write_aext(struct inode *inode, lb_addr bloc, int *extoffset,
1581 lb_addr eloc, Uint32 elen, struct buffer_head **bh, int inc)
1583 int adsize;
1584 short_ad *sad = NULL;
1585 long_ad *lad = NULL;
1587 if (!(*bh))
1589 if (!(*bh = udf_tread(inode->i_sb,
1590 udf_get_lb_pblock(inode->i_sb, bloc, 0),
1591 inode->i_sb->s_blocksize)))
1593 udf_debug("reading block %d failed!\n",
1594 udf_get_lb_pblock(inode->i_sb, bloc, 0));
1595 return -1;
1599 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1600 adsize = sizeof(short_ad);
1601 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1602 adsize = sizeof(long_ad);
1603 else
1604 return -1;
1606 switch (UDF_I_ALLOCTYPE(inode))
1608 case ICB_FLAG_AD_SHORT:
1610 sad = (short_ad *)((*bh)->b_data + *extoffset);
1611 sad->extLength = cpu_to_le32(elen);
1612 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1613 break;
1615 case ICB_FLAG_AD_LONG:
1617 lad = (long_ad *)((*bh)->b_data + *extoffset);
1618 lad->extLength = cpu_to_le32(elen);
1619 lad->extLocation = cpu_to_lelb(eloc);
1620 break;
1624 if (memcmp(&UDF_I_LOCATION(inode), &bloc, sizeof(lb_addr)))
1626 struct AllocExtDesc *aed = (struct AllocExtDesc *)(*bh)->b_data;
1627 udf_update_tag((*bh)->b_data,
1628 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct AllocExtDesc));
1631 mark_buffer_dirty(*bh, 1);
1633 if (inc)
1634 *extoffset += adsize;
1635 return (elen >> 30);
1638 int udf_next_aext(struct inode *inode, lb_addr *bloc, int *extoffset,
1639 lb_addr *eloc, Uint32 *elen, struct buffer_head **bh, int inc)
1641 int pos, alen;
1642 Uint8 etype;
1644 if (!(*bh))
1646 if (!(*bh = udf_tread(inode->i_sb,
1647 udf_get_lb_pblock(inode->i_sb, *bloc, 0),
1648 inode->i_sb->s_blocksize)))
1650 udf_debug("reading block %d failed!\n",
1651 udf_get_lb_pblock(inode->i_sb, *bloc, 0));
1652 return -1;
1656 if (!memcmp(&UDF_I_LOCATION(inode), bloc, sizeof(lb_addr)))
1658 pos = udf_file_entry_alloc_offset(inode);
1659 alen = UDF_I_LENALLOC(inode) + pos;
1661 else
1663 struct AllocExtDesc *aed = (struct AllocExtDesc *)(*bh)->b_data;
1665 pos = sizeof(struct AllocExtDesc);
1666 alen = le32_to_cpu(aed->lengthAllocDescs) + pos;
1669 if (!(*extoffset))
1670 *extoffset = pos;
1672 switch (UDF_I_ALLOCTYPE(inode))
1674 case ICB_FLAG_AD_SHORT:
1676 short_ad *sad;
1678 if (!(sad = udf_get_fileshortad((*bh)->b_data, alen, extoffset, inc)))
1679 return -1;
1681 if ((etype = le32_to_cpu(sad->extLength) >> 30) == EXTENT_NEXT_EXTENT_ALLOCDECS)
1683 bloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1684 *extoffset = 0;
1685 udf_release_data(*bh);
1686 *bh = NULL;
1687 return udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, inc);
1689 else
1691 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1692 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1693 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1695 break;
1697 case ICB_FLAG_AD_LONG:
1699 long_ad *lad;
1701 if (!(lad = udf_get_filelongad((*bh)->b_data, alen, extoffset, inc)))
1702 return -1;
1704 if ((etype = le32_to_cpu(lad->extLength) >> 30) == EXTENT_NEXT_EXTENT_ALLOCDECS)
1706 *bloc = lelb_to_cpu(lad->extLocation);
1707 *extoffset = 0;
1708 udf_release_data(*bh);
1709 *bh = NULL;
1710 return udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, inc);
1712 else
1714 *eloc = lelb_to_cpu(lad->extLocation);
1715 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1717 break;
1719 default:
1721 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
1722 return -1;
1725 if (*elen)
1726 return etype;
1728 udf_debug("Empty Extent!\n");
1729 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1730 *extoffset -= sizeof(short_ad);
1731 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1732 *extoffset -= sizeof(long_ad);
1733 return -1;
1736 int udf_current_aext(struct inode *inode, lb_addr *bloc, int *extoffset,
1737 lb_addr *eloc, Uint32 *elen, struct buffer_head **bh, int inc)
1739 int pos, alen;
1740 Uint8 etype;
1742 if (!(*bh))
1744 if (!(*bh = udf_tread(inode->i_sb,
1745 udf_get_lb_pblock(inode->i_sb, *bloc, 0),
1746 inode->i_sb->s_blocksize)))
1748 udf_debug("reading block %d failed!\n",
1749 udf_get_lb_pblock(inode->i_sb, *bloc, 0));
1750 return -1;
1754 if (!memcmp(&UDF_I_LOCATION(inode), bloc, sizeof(lb_addr)))
1756 if (!(UDF_I_EXTENDED_FE(inode)))
1757 pos = sizeof(struct FileEntry) + UDF_I_LENEATTR(inode);
1758 else
1759 pos = sizeof(struct ExtendedFileEntry) + UDF_I_LENEATTR(inode);
1760 alen = UDF_I_LENALLOC(inode) + pos;
1762 else
1764 struct AllocExtDesc *aed = (struct AllocExtDesc *)(*bh)->b_data;
1766 pos = sizeof(struct AllocExtDesc);
1767 alen = le32_to_cpu(aed->lengthAllocDescs) + pos;
1770 if (!(*extoffset))
1771 *extoffset = pos;
1773 switch (UDF_I_ALLOCTYPE(inode))
1775 case ICB_FLAG_AD_SHORT:
1777 short_ad *sad;
1779 if (!(sad = udf_get_fileshortad((*bh)->b_data, alen, extoffset, inc)))
1780 return -1;
1782 etype = le32_to_cpu(sad->extLength) >> 30;
1783 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1784 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
1785 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
1786 break;
1788 case ICB_FLAG_AD_LONG:
1790 long_ad *lad;
1792 if (!(lad = udf_get_filelongad((*bh)->b_data, alen, extoffset, inc)))
1793 return -1;
1795 etype = le32_to_cpu(lad->extLength) >> 30;
1796 *eloc = lelb_to_cpu(lad->extLocation);
1797 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
1798 break;
1800 default:
1802 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
1803 return -1;
1806 if (*elen)
1807 return etype;
1809 udf_debug("Empty Extent!\n");
1810 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1811 *extoffset -= sizeof(short_ad);
1812 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1813 *extoffset -= sizeof(long_ad);
1814 return -1;
1817 int udf_insert_aext(struct inode *inode, lb_addr bloc, int extoffset,
1818 lb_addr neloc, Uint32 nelen, struct buffer_head *bh)
1820 lb_addr oeloc;
1821 Uint32 oelen;
1822 int type;
1824 if (!bh)
1826 if (!(bh = udf_tread(inode->i_sb,
1827 udf_get_lb_pblock(inode->i_sb, bloc, 0),
1828 inode->i_sb->s_blocksize)))
1830 udf_debug("reading block %d failed!\n",
1831 udf_get_lb_pblock(inode->i_sb, bloc, 0));
1832 return -1;
1835 else
1836 atomic_inc(&bh->b_count);
1838 while ((type = udf_next_aext(inode, &bloc, &extoffset, &oeloc, &oelen, &bh, 0)) != -1)
1840 udf_write_aext(inode, bloc, &extoffset, neloc, nelen, &bh, 1);
1842 neloc = oeloc;
1843 nelen = (type << 30) | oelen;
1845 udf_add_aext(inode, &bloc, &extoffset, neloc, nelen, &bh, 1);
1846 udf_release_data(bh);
1847 return (nelen >> 30);
1850 int udf_delete_aext(struct inode *inode, lb_addr nbloc, int nextoffset,
1851 lb_addr eloc, Uint32 elen, struct buffer_head *nbh)
1853 struct buffer_head *obh;
1854 lb_addr obloc;
1855 int oextoffset, adsize;
1856 char type;
1857 struct AllocExtDesc *aed;
1859 if (!(nbh))
1861 if (!(nbh = udf_tread(inode->i_sb,
1862 udf_get_lb_pblock(inode->i_sb, nbloc, 0),
1863 inode->i_sb->s_blocksize)))
1865 udf_debug("reading block %d failed!\n",
1866 udf_get_lb_pblock(inode->i_sb, nbloc, 0));
1867 return -1;
1870 else
1871 atomic_inc(&nbh->b_count);
1872 atomic_inc(&nbh->b_count);
1874 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1875 adsize = sizeof(short_ad);
1876 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1877 adsize = sizeof(long_ad);
1878 else
1879 adsize = 0;
1881 obh = nbh;
1882 obloc = nbloc;
1883 oextoffset = nextoffset;
1885 if (udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1) == -1)
1886 return -1;
1888 while ((type = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1)
1890 udf_write_aext(inode, obloc, &oextoffset, eloc, (type << 30) | elen, &obh, 1);
1891 if (memcmp(&nbloc, &obloc, sizeof(lb_addr)))
1893 obloc = nbloc;
1894 udf_release_data(obh);
1895 atomic_inc(&nbh->b_count);
1896 obh = nbh;
1897 oextoffset = nextoffset - adsize;
1900 memset(&eloc, 0x00, sizeof(lb_addr));
1901 elen = 0;
1903 if (memcmp(&nbloc, &obloc, sizeof(lb_addr)))
1905 udf_free_blocks(inode, nbloc, 0, 1);
1906 udf_write_aext(inode, obloc, &oextoffset, eloc, elen, &obh, 1);
1907 udf_write_aext(inode, obloc, &oextoffset, eloc, elen, &obh, 1);
1908 if (!memcmp(&UDF_I_LOCATION(inode), &obloc, sizeof(lb_addr)))
1910 UDF_I_LENALLOC(inode) -= (adsize * 2);
1911 mark_inode_dirty(inode);
1913 else
1915 aed = (struct AllocExtDesc *)(obh)->b_data;
1916 aed->lengthAllocDescs =
1917 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize));
1918 udf_update_tag((obh)->b_data, oextoffset - (2*adsize));
1919 mark_buffer_dirty(obh, 1);
1922 else
1924 udf_write_aext(inode, obloc, &oextoffset, eloc, elen, &obh, 1);
1925 if (!memcmp(&UDF_I_LOCATION(inode), &obloc, sizeof(lb_addr)))
1927 UDF_I_LENALLOC(inode) -= adsize;
1928 mark_inode_dirty(inode);
1930 else
1932 aed = (struct AllocExtDesc *)(obh)->b_data;
1933 aed->lengthAllocDescs =
1934 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize);
1935 udf_update_tag((obh)->b_data, oextoffset - adsize);
1936 mark_buffer_dirty(obh, 1);
1940 udf_release_data(nbh);
1941 udf_release_data(obh);
1942 return (elen >> 30);
1945 int inode_bmap(struct inode *inode, int block, lb_addr *bloc, Uint32 *extoffset,
1946 lb_addr *eloc, Uint32 *elen, Uint32 *offset, struct buffer_head **bh)
1948 int etype, lbcount = 0, b_off;
1950 if (block < 0)
1952 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
1953 return -1;
1955 if (!inode)
1957 printk(KERN_ERR "udf: inode_bmap: NULL inode\n");
1958 return -1;
1961 b_off = block << inode->i_sb->s_blocksize_bits;
1962 *bloc = UDF_I_LOCATION(inode);
1963 *eloc = UDF_I_EXT0LOC(inode);
1964 *elen = UDF_I_EXT0LEN(inode) & UDF_EXTENT_LENGTH_MASK;
1965 *extoffset = udf_file_entry_alloc_offset(inode);
1966 if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_SHORT)
1967 *extoffset += sizeof(short_ad);
1968 else if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_LONG)
1969 *extoffset += sizeof(long_ad);
1970 etype = UDF_I_EXT0LEN(inode) >> 30;
1972 while (lbcount + *elen <= b_off)
1974 lbcount += *elen;
1975 if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1)
1977 *offset = (b_off - lbcount) >> inode->i_sb->s_blocksize_bits;
1978 return -1;
1981 *offset = (b_off - lbcount) >> inode->i_sb->s_blocksize_bits;
1983 return etype;
1986 long udf_locked_block_map(struct inode *inode, long block)
1988 lb_addr eloc, bloc;
1989 Uint32 offset, extoffset, elen;
1990 struct buffer_head *bh = NULL;
1991 int ret;
1993 if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == EXTENT_RECORDED_ALLOCATED)
1994 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
1995 else
1996 ret = 0;
1998 if (bh)
1999 udf_release_data(bh);
2001 if (UDF_SB(inode->i_sb)->s_flags & UDF_FLAG_VARCONV)
2002 return udf_fixed_to_variable(ret);
2003 else
2004 return ret;
2007 long udf_block_map(struct inode *inode, long block)
2009 int ret;
2011 lock_kernel();
2012 ret = udf_locked_block_map(inode, block);
2013 unlock_kernel();
2014 return ret;