LTP GCOV extension - code coverage report
Current view: directory - fs/udf - inode.c
Test: 2.6.14_rebootonly_gcov.info
Date: 2006-05-22 Instrumented lines: 1030
Code covered: 0.0 % Executed lines: 0

       1                 : /*
       2                 :  * inode.c
       3                 :  *
       4                 :  * PURPOSE
       5                 :  *  Inode handling routines for the OSTA-UDF(tm) filesystem.
       6                 :  *
       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@hpesjro.fc.hp.com
      11                 :  *
      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.
      17                 :  *
      18                 :  *  (C) 1998 Dave Boynton
      19                 :  *  (C) 1998-2004 Ben Fennema
      20                 :  *  (C) 1999-2000 Stelias Computing Inc
      21                 :  *
      22                 :  * HISTORY
      23                 :  *
      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 #
      34                 :  */
      35                 : 
      36                 : #include "udfdecl.h"
      37                 : #include <linux/mm.h>
      38                 : #include <linux/smp_lock.h>
      39                 : #include <linux/module.h>
      40                 : #include <linux/pagemap.h>
      41                 : #include <linux/buffer_head.h>
      42                 : #include <linux/writeback.h>
      43                 : #include <linux/slab.h>
      44                 : 
      45                 : #include "udf_i.h"
      46                 : #include "udf_sb.h"
      47                 : 
      48                 : MODULE_AUTHOR("Ben Fennema");
      49                 : MODULE_DESCRIPTION("Universal Disk Format Filesystem");
      50                 : MODULE_LICENSE("GPL");
      51                 : 
      52                 : #define EXTENT_MERGE_SIZE 5
      53                 : 
      54                 : static mode_t udf_convert_permissions(struct fileEntry *);
      55                 : static int udf_update_inode(struct inode *, int);
      56                 : static void udf_fill_inode(struct inode *, struct buffer_head *);
      57                 : static struct buffer_head *inode_getblk(struct inode *, long, int *,
      58                 :         long *, int *);
      59                 : static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int,
      60                 :         kernel_lb_addr, uint32_t, struct buffer_head *);
      61                 : static void udf_split_extents(struct inode *, int *, int, int,
      62                 :         kernel_long_ad [EXTENT_MERGE_SIZE], int *);
      63                 : static void udf_prealloc_extents(struct inode *, int, int,
      64                 :          kernel_long_ad [EXTENT_MERGE_SIZE], int *);
      65                 : static void udf_merge_extents(struct inode *,
      66                 :          kernel_long_ad [EXTENT_MERGE_SIZE], int *);
      67                 : static void udf_update_extents(struct inode *,
      68                 :         kernel_long_ad [EXTENT_MERGE_SIZE], int, int,
      69                 :         kernel_lb_addr, uint32_t, struct buffer_head **);
      70                 : static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
      71                 : 
      72                 : /*
      73                 :  * udf_delete_inode
      74                 :  *
      75                 :  * PURPOSE
      76                 :  *      Clean-up before the specified inode is destroyed.
      77                 :  *
      78                 :  * DESCRIPTION
      79                 :  *      This routine is called when the kernel destroys an inode structure
      80                 :  *      ie. when iput() finds i_count == 0.
      81                 :  *
      82                 :  * HISTORY
      83                 :  *      July 1, 1997 - Andrew E. Mileski
      84                 :  *      Written, tested, and released.
      85                 :  *
      86                 :  *  Called at the last iput() if i_nlink is zero.
      87                 :  */
      88                 : void udf_delete_inode(struct inode * inode)
      89               0 : {
      90               0 :         truncate_inode_pages(&inode->i_data, 0);
      91                 : 
      92               0 :         if (is_bad_inode(inode))
      93               0 :                 goto no_delete;
      94                 : 
      95               0 :         inode->i_size = 0;
      96               0 :         udf_truncate(inode);
      97               0 :         lock_kernel();
      98                 : 
      99               0 :         udf_update_inode(inode, IS_SYNC(inode));
     100               0 :         udf_free_inode(inode);
     101                 : 
     102               0 :         unlock_kernel();
     103               0 :         return;
     104                 : no_delete:
     105               0 :         clear_inode(inode);
     106                 : }
     107                 : 
     108                 : void udf_clear_inode(struct inode *inode)
     109               0 : {
     110               0 :         if (!(inode->i_sb->s_flags & MS_RDONLY)) {
     111               0 :                 lock_kernel();
     112               0 :                 udf_discard_prealloc(inode);
     113               0 :                 unlock_kernel();
     114                 :         }
     115                 : 
     116               0 :         kfree(UDF_I_DATA(inode));
     117               0 :         UDF_I_DATA(inode) = NULL;
     118                 : }
     119                 : 
     120                 : static int udf_writepage(struct page *page, struct writeback_control *wbc)
     121               0 : {
     122               0 :         return block_write_full_page(page, udf_get_block, wbc);
     123                 : }
     124                 : 
     125                 : static int udf_readpage(struct file *file, struct page *page)
     126               0 : {
     127               0 :         return block_read_full_page(page, udf_get_block);
     128                 : }
     129                 : 
     130                 : static int udf_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
     131               0 : {
     132               0 :         return block_prepare_write(page, from, to, udf_get_block);
     133                 : }
     134                 : 
     135                 : static sector_t udf_bmap(struct address_space *mapping, sector_t block)
     136               0 : {
     137               0 :         return generic_block_bmap(mapping,block,udf_get_block);
     138                 : }
     139                 : 
     140                 : struct address_space_operations udf_aops = {
     141                 :         .readpage               = udf_readpage,
     142                 :         .writepage              = udf_writepage,
     143                 :         .sync_page              = block_sync_page,
     144                 :         .prepare_write          = udf_prepare_write,
     145                 :         .commit_write           = generic_commit_write,
     146                 :         .bmap                   = udf_bmap,
     147                 : };
     148                 : 
     149                 : void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
     150               0 : {
     151               0 :         struct page *page;
     152               0 :         char *kaddr;
     153               0 :         struct writeback_control udf_wbc = {
     154                 :                 .sync_mode = WB_SYNC_NONE,
     155                 :                 .nr_to_write = 1,
     156               0 :         };
     157                 : 
     158                 :         /* from now on we have normal address_space methods */
     159               0 :         inode->i_data.a_ops = &udf_aops;
     160                 : 
     161               0 :         if (!UDF_I_LENALLOC(inode))
     162                 :         {
     163               0 :                 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
     164               0 :                         UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
     165                 :                 else
     166               0 :                         UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
     167               0 :                 mark_inode_dirty(inode);
     168               0 :                 return;
     169                 :         }
     170                 : 
     171               0 :         page = grab_cache_page(inode->i_mapping, 0);
     172               0 :         BUG_ON(!PageLocked(page));
     173                 : 
     174               0 :         if (!PageUptodate(page))
     175                 :         {
     176               0 :                 kaddr = kmap(page);
     177               0 :                 memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
     178                 :                         PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
     179               0 :                 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
     180                 :                         UDF_I_LENALLOC(inode));
     181                 :                 flush_dcache_page(page);
     182               0 :                 SetPageUptodate(page);
     183               0 :                 kunmap(page);
     184                 :         }
     185               0 :         memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
     186                 :                 UDF_I_LENALLOC(inode));
     187               0 :         UDF_I_LENALLOC(inode) = 0;
     188               0 :         if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
     189               0 :                 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
     190                 :         else
     191               0 :                 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
     192                 : 
     193               0 :         inode->i_data.a_ops->writepage(page, &udf_wbc);
     194               0 :         page_cache_release(page);
     195                 : 
     196               0 :         mark_inode_dirty(inode);
     197                 : }
     198                 : 
     199                 : struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err)
     200               0 : {
     201               0 :         int newblock;
     202               0 :         struct buffer_head *sbh = NULL, *dbh = NULL;
     203               0 :         kernel_lb_addr bloc, eloc;
     204               0 :         uint32_t elen, extoffset;
     205               0 :         uint8_t alloctype;
     206                 : 
     207               0 :         struct udf_fileident_bh sfibh, dfibh;
     208               0 :         loff_t f_pos = udf_ext0_offset(inode) >> 2;
     209               0 :         int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
     210               0 :         struct fileIdentDesc cfi, *sfi, *dfi;
     211                 : 
     212               0 :         if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
     213               0 :                 alloctype = ICBTAG_FLAG_AD_SHORT;
     214                 :         else
     215               0 :                 alloctype = ICBTAG_FLAG_AD_LONG;
     216                 : 
     217               0 :         if (!inode->i_size)
     218                 :         {
     219               0 :                 UDF_I_ALLOCTYPE(inode) = alloctype;
     220               0 :                 mark_inode_dirty(inode);
     221               0 :                 return NULL;
     222                 :         }
     223                 : 
     224                 :         /* alloc block, and copy data to it */
     225               0 :         *block = udf_new_block(inode->i_sb, inode,
     226                 :                 UDF_I_LOCATION(inode).partitionReferenceNum,
     227                 :                 UDF_I_LOCATION(inode).logicalBlockNum, err);
     228                 : 
     229               0 :         if (!(*block))
     230               0 :                 return NULL;
     231               0 :         newblock = udf_get_pblock(inode->i_sb, *block,
     232                 :                 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
     233               0 :         if (!newblock)
     234               0 :                 return NULL;
     235               0 :         dbh = udf_tgetblk(inode->i_sb, newblock);
     236               0 :         if (!dbh)
     237               0 :                 return NULL;
     238               0 :         lock_buffer(dbh);
     239               0 :         memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
     240               0 :         set_buffer_uptodate(dbh);
     241               0 :         unlock_buffer(dbh);
     242               0 :         mark_buffer_dirty_inode(dbh, inode);
     243                 : 
     244               0 :         sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
     245               0 :         sbh = sfibh.sbh = sfibh.ebh = NULL;
     246               0 :         dfibh.soffset = dfibh.eoffset = 0;
     247               0 :         dfibh.sbh = dfibh.ebh = dbh;
     248               0 :         while ( (f_pos < size) )
     249                 :         {
     250               0 :                 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
     251               0 :                 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL, NULL, NULL);
     252               0 :                 if (!sfi)
     253                 :                 {
     254               0 :                         udf_release_data(dbh);
     255               0 :                         return NULL;
     256                 :                 }
     257               0 :                 UDF_I_ALLOCTYPE(inode) = alloctype;
     258               0 :                 sfi->descTag.tagLocation = cpu_to_le32(*block);
     259               0 :                 dfibh.soffset = dfibh.eoffset;
     260               0 :                 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
     261               0 :                 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
     262               0 :                 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
     263                 :                         sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse)))
     264                 :                 {
     265               0 :                         UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
     266               0 :                         udf_release_data(dbh);
     267               0 :                         return NULL;
     268                 :                 }
     269                 :         }
     270               0 :         mark_buffer_dirty_inode(dbh, inode);
     271                 : 
     272               0 :         memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode));
     273               0 :         UDF_I_LENALLOC(inode) = 0;
     274               0 :         bloc = UDF_I_LOCATION(inode);
     275               0 :         eloc.logicalBlockNum = *block;
     276               0 :         eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
     277               0 :         elen = inode->i_size;
     278               0 :         UDF_I_LENEXTENTS(inode) = elen;
     279               0 :         extoffset = udf_file_entry_alloc_offset(inode);
     280               0 :         udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &sbh, 0);
     281                 :         /* UniqueID stuff */
     282                 : 
     283               0 :         udf_release_data(sbh);
     284               0 :         mark_inode_dirty(inode);
     285               0 :         return dbh;
     286                 : }
     287                 : 
     288                 : static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create)
     289               0 : {
     290               0 :         int err, new;
     291               0 :         struct buffer_head *bh;
     292               0 :         unsigned long phys;
     293                 : 
     294               0 :         if (!create)
     295                 :         {
     296               0 :                 phys = udf_block_map(inode, block);
     297               0 :                 if (phys)
     298               0 :                         map_bh(bh_result, inode->i_sb, phys);
     299               0 :                 return 0;
     300                 :         }
     301                 : 
     302               0 :         err = -EIO;
     303               0 :         new = 0;
     304               0 :         bh = NULL;
     305                 : 
     306               0 :         lock_kernel();
     307                 : 
     308               0 :         if (block < 0)
     309                 :                 goto abort_negative;
     310                 : 
     311               0 :         if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1)
     312                 :         {
     313               0 :                 UDF_I_NEXT_ALLOC_BLOCK(inode) ++;
     314               0 :                 UDF_I_NEXT_ALLOC_GOAL(inode) ++;
     315                 :         }
     316                 : 
     317               0 :         err = 0;
     318                 : 
     319               0 :         bh = inode_getblk(inode, block, &err, &phys, &new);
     320               0 :         if (bh)
     321               0 :                 BUG();
     322               0 :         if (err)
     323               0 :                 goto abort;
     324               0 :         if (!phys)
     325               0 :                 BUG();
     326                 : 
     327               0 :         if (new)
     328               0 :                 set_buffer_new(bh_result);
     329               0 :         map_bh(bh_result, inode->i_sb, phys);
     330                 : abort:
     331               0 :         unlock_kernel();
     332               0 :         return err;
     333                 : 
     334                 : abort_negative:
     335               0 :         udf_warning(inode->i_sb, "udf_get_block", "block < 0");
     336               0 :         goto abort;
     337                 : }
     338                 : 
     339                 : static struct buffer_head *
     340                 : udf_getblk(struct inode *inode, long block, int create, int *err)
     341               0 : {
     342               0 :         struct buffer_head dummy;
     343                 : 
     344               0 :         dummy.b_state = 0;
     345               0 :         dummy.b_blocknr = -1000;
     346               0 :         *err = udf_get_block(inode, block, &dummy, create);
     347               0 :         if (!*err && buffer_mapped(&dummy))
     348                 :         {
     349               0 :                 struct buffer_head *bh;
     350               0 :                 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
     351               0 :                 if (buffer_new(&dummy))
     352                 :                 {
     353               0 :                         lock_buffer(bh);
     354               0 :                         memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
     355               0 :                         set_buffer_uptodate(bh);
     356               0 :                         unlock_buffer(bh);
     357               0 :                         mark_buffer_dirty_inode(bh, inode);
     358                 :                 }
     359               0 :                 return bh;
     360                 :         }
     361               0 :         return NULL;
     362                 : }
     363                 : 
     364                 : static struct buffer_head * inode_getblk(struct inode * inode, long block,
     365                 :         int *err, long *phys, int *new)
     366               0 : {
     367               0 :         struct buffer_head *pbh = NULL, *cbh = NULL, *nbh = NULL, *result = NULL;
     368               0 :         kernel_long_ad laarr[EXTENT_MERGE_SIZE];
     369               0 :         uint32_t pextoffset = 0, cextoffset = 0, nextoffset = 0;
     370               0 :         int count = 0, startnum = 0, endnum = 0;
     371               0 :         uint32_t elen = 0;
     372               0 :         kernel_lb_addr eloc, pbloc, cbloc, nbloc;
     373               0 :         int c = 1;
     374               0 :         uint64_t lbcount = 0, b_off = 0;
     375               0 :         uint32_t newblocknum, newblock, offset = 0;
     376               0 :         int8_t etype;
     377               0 :         int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
     378               0 :         char lastblock = 0;
     379                 : 
     380               0 :         pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode);
     381               0 :         b_off = (uint64_t)block << inode->i_sb->s_blocksize_bits;
     382               0 :         pbloc = cbloc = nbloc = UDF_I_LOCATION(inode);
     383                 : 
     384                 :         /* find the extent which contains the block we are looking for.
     385                 :        alternate between laarr[0] and laarr[1] for locations of the
     386                 :        current extent, and the previous extent */
     387               0 :         do
     388                 :         {
     389               0 :                 if (pbh != cbh)
     390                 :                 {
     391               0 :                         udf_release_data(pbh);
     392               0 :                         atomic_inc(&cbh->b_count);
     393               0 :                         pbh = cbh;
     394                 :                 }
     395               0 :                 if (cbh != nbh)
     396                 :                 {
     397               0 :                         udf_release_data(cbh);
     398               0 :                         atomic_inc(&nbh->b_count);
     399               0 :                         cbh = nbh;
     400                 :                 }
     401                 : 
     402               0 :                 lbcount += elen;
     403                 : 
     404               0 :                 pbloc = cbloc;
     405               0 :                 cbloc = nbloc;
     406                 : 
     407               0 :                 pextoffset = cextoffset;
     408               0 :                 cextoffset = nextoffset;
     409                 : 
     410               0 :                 if ((etype = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) == -1)
     411               0 :                         break;
     412                 : 
     413               0 :                 c = !c;
     414                 : 
     415               0 :                 laarr[c].extLength = (etype << 30) | elen;
     416               0 :                 laarr[c].extLocation = eloc;
     417                 : 
     418               0 :                 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
     419               0 :                         pgoal = eloc.logicalBlockNum +
     420                 :                                 ((elen + inode->i_sb->s_blocksize - 1) >>
     421                 :                                 inode->i_sb->s_blocksize_bits);
     422                 : 
     423               0 :                 count ++;
     424               0 :         } while (lbcount + elen <= b_off);
     425                 : 
     426               0 :         b_off -= lbcount;
     427               0 :         offset = b_off >> inode->i_sb->s_blocksize_bits;
     428                 : 
     429                 :         /* if the extent is allocated and recorded, return the block
     430                 :        if the extent is not a multiple of the blocksize, round up */
     431                 : 
     432               0 :         if (etype == (EXT_RECORDED_ALLOCATED >> 30))
     433                 :         {
     434               0 :                 if (elen & (inode->i_sb->s_blocksize - 1))
     435                 :                 {
     436               0 :                         elen = EXT_RECORDED_ALLOCATED |
     437                 :                                 ((elen + inode->i_sb->s_blocksize - 1) &
     438                 :                                 ~(inode->i_sb->s_blocksize - 1));
     439               0 :                         etype = udf_write_aext(inode, nbloc, &cextoffset, eloc, elen, nbh, 1);
     440                 :                 }
     441               0 :                 udf_release_data(pbh);
     442               0 :                 udf_release_data(cbh);
     443               0 :                 udf_release_data(nbh);
     444               0 :                 newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
     445               0 :                 *phys = newblock;
     446               0 :                 return NULL;
     447                 :         }
     448                 : 
     449               0 :         if (etype == -1)
     450                 :         {
     451               0 :                 endnum = startnum = ((count > 1) ? 1 : count);
     452               0 :                 if (laarr[c].extLength & (inode->i_sb->s_blocksize - 1))
     453                 :                 {
     454               0 :                         laarr[c].extLength =
     455                 :                                 (laarr[c].extLength & UDF_EXTENT_FLAG_MASK) |
     456                 :                                 (((laarr[c].extLength & UDF_EXTENT_LENGTH_MASK) +
     457                 :                                         inode->i_sb->s_blocksize - 1) &
     458                 :                                 ~(inode->i_sb->s_blocksize - 1));
     459               0 :                         UDF_I_LENEXTENTS(inode) =
     460                 :                                 (UDF_I_LENEXTENTS(inode) + inode->i_sb->s_blocksize - 1) &
     461                 :                                         ~(inode->i_sb->s_blocksize - 1);
     462                 :                 }
     463               0 :                 c = !c;
     464               0 :                 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
     465                 :                         ((offset + 1) << inode->i_sb->s_blocksize_bits);
     466               0 :                 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
     467               0 :                 count ++;
     468               0 :                 endnum ++;
     469               0 :                 lastblock = 1;
     470                 :         }
     471                 :         else
     472               0 :                 endnum = startnum = ((count > 2) ? 2 : count);
     473                 : 
     474                 :         /* if the current extent is in position 0, swap it with the previous */
     475               0 :         if (!c && count != 1)
     476                 :         {
     477               0 :                 laarr[2] = laarr[0];
     478               0 :                 laarr[0] = laarr[1];
     479               0 :                 laarr[1] = laarr[2];
     480               0 :                 c = 1;
     481                 :         }
     482                 : 
     483                 :         /* if the current block is located in a extent, read the next extent */
     484               0 :         if (etype != -1)
     485                 :         {
     486               0 :                 if ((etype = udf_next_aext(inode, &nbloc, &nextoffset, &eloc, &elen, &nbh, 0)) != -1)
     487                 :                 {
     488               0 :                         laarr[c+1].extLength = (etype << 30) | elen;
     489               0 :                         laarr[c+1].extLocation = eloc;
     490               0 :                         count ++;
     491               0 :                         startnum ++;
     492               0 :                         endnum ++;
     493                 :                 }
     494                 :                 else
     495               0 :                         lastblock = 1;
     496                 :         }
     497               0 :         udf_release_data(cbh);
     498               0 :         udf_release_data(nbh);
     499                 : 
     500                 :         /* if the current extent is not recorded but allocated, get the
     501                 :                 block in the extent corresponding to the requested block */
     502               0 :         if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
     503               0 :                 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
     504                 :         else /* otherwise, allocate a new block */
     505                 :         {
     506               0 :                 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
     507               0 :                         goal = UDF_I_NEXT_ALLOC_GOAL(inode);
     508                 : 
     509               0 :                 if (!goal)
     510                 :                 {
     511               0 :                         if (!(goal = pgoal))
     512               0 :                                 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
     513                 :                 }
     514                 : 
     515               0 :                 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
     516                 :                         UDF_I_LOCATION(inode).partitionReferenceNum, goal, err)))
     517                 :                 {
     518               0 :                         udf_release_data(pbh);
     519               0 :                         *err = -ENOSPC;
     520               0 :                         return NULL;
     521                 :                 }
     522               0 :                 UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
     523                 :         }
     524                 : 
     525                 :         /* if the extent the requsted block is located in contains multiple blocks,
     526                 :        split the extent into at most three extents. blocks prior to requested
     527                 :        block, requested block, and blocks after requested block */
     528               0 :         udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
     529                 : 
     530                 : #ifdef UDF_PREALLOCATE
     531                 :         /* preallocate blocks */
     532               0 :         udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
     533                 : #endif
     534                 : 
     535                 :         /* merge any continuous blocks in laarr */
     536               0 :         udf_merge_extents(inode, laarr, &endnum);
     537                 : 
     538                 :         /* write back the new extents, inserting new extents if the new number
     539                 :        of extents is greater than the old number, and deleting extents if
     540                 :        the new number of extents is less than the old number */
     541               0 :         udf_update_extents(inode, laarr, startnum, endnum, pbloc, pextoffset, &pbh);
     542                 : 
     543               0 :         udf_release_data(pbh);
     544                 : 
     545               0 :         if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
     546                 :                 UDF_I_LOCATION(inode).partitionReferenceNum, 0)))
     547                 :         {
     548               0 :                 return NULL;
     549                 :         }
     550               0 :         *phys = newblock;
     551               0 :         *err = 0;
     552               0 :         *new = 1;
     553               0 :         UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
     554               0 :         UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
     555               0 :         inode->i_ctime = current_fs_time(inode->i_sb);
     556                 : 
     557               0 :         if (IS_SYNC(inode))
     558               0 :                 udf_sync_inode(inode);
     559                 :         else
     560               0 :                 mark_inode_dirty(inode);
     561               0 :         return result;
     562                 : }
     563                 : 
     564                 : static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum,
     565                 :         kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
     566               0 : {
     567               0 :         if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
     568                 :                 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
     569                 :         {
     570               0 :                 int curr = *c;
     571               0 :                 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
     572               0 :                         inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
     573               0 :                 int8_t etype = (laarr[curr].extLength >> 30);
     574                 : 
     575               0 :                 if (blen == 1)
     576                 :                         ;
     577               0 :                 else if (!offset || blen == offset + 1)
     578                 :                 {
     579               0 :                         laarr[curr+2] = laarr[curr+1];
     580               0 :                         laarr[curr+1] = laarr[curr];
     581                 :                 }
     582                 :                 else
     583                 :                 {
     584               0 :                         laarr[curr+3] = laarr[curr+1];
     585               0 :                         laarr[curr+2] = laarr[curr+1] = laarr[curr];
     586                 :                 }
     587                 : 
     588               0 :                 if (offset)
     589                 :                 {
     590               0 :                         if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
     591                 :                         {
     592               0 :                                 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
     593               0 :                                 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
     594                 :                                         (offset << inode->i_sb->s_blocksize_bits);
     595               0 :                                 laarr[curr].extLocation.logicalBlockNum = 0;
     596               0 :                                 laarr[curr].extLocation.partitionReferenceNum = 0;
     597                 :                         }
     598                 :                         else
     599               0 :                                 laarr[curr].extLength = (etype << 30) |
     600                 :                                         (offset << inode->i_sb->s_blocksize_bits);
     601               0 :                         curr ++;
     602               0 :                         (*c) ++;
     603               0 :                         (*endnum) ++;
     604                 :                 }
     605                 :                 
     606               0 :                 laarr[curr].extLocation.logicalBlockNum = newblocknum;
     607               0 :                 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
     608               0 :                         laarr[curr].extLocation.partitionReferenceNum =
     609                 :                                 UDF_I_LOCATION(inode).partitionReferenceNum;
     610               0 :                 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
     611                 :                         inode->i_sb->s_blocksize;
     612               0 :                 curr ++;
     613                 : 
     614               0 :                 if (blen != offset + 1)
     615                 :                 {
     616               0 :                         if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
     617               0 :                                 laarr[curr].extLocation.logicalBlockNum += (offset + 1);
     618               0 :                         laarr[curr].extLength = (etype << 30) |
     619                 :                                 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
     620               0 :                         curr ++;
     621               0 :                         (*endnum) ++;
     622                 :                 }
     623                 :         }
     624                 : }
     625                 : 
     626                 : static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
     627                 :          kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
     628               0 : {
     629               0 :         int start, length = 0, currlength = 0, i;
     630                 : 
     631               0 :         if (*endnum >= (c+1))
     632                 :         {
     633               0 :                 if (!lastblock)
     634               0 :                         return;
     635                 :                 else
     636               0 :                         start = c;
     637                 :         }
     638                 :         else
     639                 :         {
     640               0 :                 if ((laarr[c+1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
     641                 :                 {
     642               0 :                         start = c+1;
     643               0 :                         length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) +
     644                 :                                 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
     645                 :                 }
     646                 :                 else
     647               0 :                         start = c;
     648                 :         }
     649                 : 
     650               0 :         for (i=start+1; i<=*endnum; i++)
     651                 :         {
     652               0 :                 if (i == *endnum)
     653                 :                 {
     654               0 :                         if (lastblock)
     655               0 :                                 length += UDF_DEFAULT_PREALLOC_BLOCKS;
     656                 :                 }
     657               0 :                 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
     658               0 :                         length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     659                 :                                 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
     660                 :                 else
     661               0 :                         break;
     662                 :         }
     663                 : 
     664               0 :         if (length)
     665                 :         {
     666               0 :                 int next = laarr[start].extLocation.logicalBlockNum +
     667                 :                         (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
     668               0 :                         inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
     669               0 :                 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
     670                 :                         laarr[start].extLocation.partitionReferenceNum,
     671                 :                         next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
     672               0 :                                 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
     673                 : 
     674               0 :                 if (numalloc)
     675                 :                 {
     676               0 :                         if (start == (c+1))
     677               0 :                                 laarr[start].extLength +=
     678                 :                                         (numalloc << inode->i_sb->s_blocksize_bits);
     679                 :                         else
     680                 :                         {
     681               0 :                                 memmove(&laarr[c+2], &laarr[c+1],
     682                 :                                         sizeof(long_ad) * (*endnum - (c+1)));
     683               0 :                                 (*endnum) ++;
     684               0 :                                 laarr[c+1].extLocation.logicalBlockNum = next;
     685               0 :                                 laarr[c+1].extLocation.partitionReferenceNum =
     686                 :                                         laarr[c].extLocation.partitionReferenceNum;
     687               0 :                                 laarr[c+1].extLength = EXT_NOT_RECORDED_ALLOCATED |
     688                 :                                         (numalloc << inode->i_sb->s_blocksize_bits);
     689               0 :                                 start = c+1;
     690                 :                         }
     691                 : 
     692               0 :                         for (i=start+1; numalloc && i<*endnum; i++)
     693                 :                         {
     694               0 :                                 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     695               0 :                                         inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
     696                 : 
     697               0 :                                 if (elen > numalloc)
     698                 :                                 {
     699               0 :                                         laarr[i].extLength -=
     700                 :                                                 (numalloc << inode->i_sb->s_blocksize_bits);
     701               0 :                                         numalloc = 0;
     702                 :                                 }
     703                 :                                 else
     704                 :                                 {
     705               0 :                                         numalloc -= elen;
     706               0 :                                         if (*endnum > (i+1))
     707               0 :                                                 memmove(&laarr[i], &laarr[i+1], 
     708                 :                                                         sizeof(long_ad) * (*endnum - (i+1)));
     709               0 :                                         i --;
     710               0 :                                         (*endnum) --;
     711                 :                                 }
     712                 :                         }
     713               0 :                         UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits;
     714                 :                 }
     715                 :         }
     716                 : }
     717                 : 
     718                 : static void udf_merge_extents(struct inode *inode,
     719                 :          kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
     720               0 : {
     721               0 :         int i;
     722                 : 
     723               0 :         for (i=0; i<(*endnum-1); i++)
     724                 :         {
     725               0 :                 if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30))
     726                 :                 {
     727               0 :                         if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
     728                 :                                 ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
     729                 :                                 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     730                 :                                 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits)))
     731                 :                         {
     732               0 :                                 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     733                 :                                         (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) +
     734                 :                                         inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK)
     735                 :                                 {
     736               0 :                                         laarr[i+1].extLength = (laarr[i+1].extLength -
     737                 :                                                 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     738                 :                                                 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
     739               0 :                                         laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
     740                 :                                                 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
     741               0 :                                         laarr[i+1].extLocation.logicalBlockNum =
     742                 :                                                 laarr[i].extLocation.logicalBlockNum +
     743                 :                                                 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >>
     744                 :                                                         inode->i_sb->s_blocksize_bits);
     745                 :                                 }
     746                 :                                 else
     747                 :                                 {
     748               0 :                                         laarr[i].extLength = laarr[i+1].extLength +
     749                 :                                                 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     750                 :                                                 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1));
     751               0 :                                         if (*endnum > (i+2))
     752               0 :                                                 memmove(&laarr[i+1], &laarr[i+2],
     753                 :                                                         sizeof(long_ad) * (*endnum - (i+2)));
     754               0 :                                         i --;
     755               0 :                                         (*endnum) --;
     756                 :                                 }
     757                 :                         }
     758                 :                 }
     759               0 :                 else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
     760                 :                         ((laarr[i+1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)))
     761                 :                 {
     762               0 :                         udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
     763                 :                                 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     764                 :                                 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
     765               0 :                         laarr[i].extLocation.logicalBlockNum = 0;
     766               0 :                         laarr[i].extLocation.partitionReferenceNum = 0;
     767                 : 
     768               0 :                         if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     769                 :                                 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) +
     770                 :                                 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK)
     771                 :                         {
     772               0 :                                 laarr[i+1].extLength = (laarr[i+1].extLength -
     773                 :                                         (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     774                 :                                         UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
     775               0 :                                 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
     776                 :                                         (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
     777                 :                         }
     778                 :                         else
     779                 :                         {
     780               0 :                                 laarr[i].extLength = laarr[i+1].extLength +
     781                 :                                         (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     782                 :                                         inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1));
     783               0 :                                 if (*endnum > (i+2))
     784               0 :                                         memmove(&laarr[i+1], &laarr[i+2],
     785                 :                                                 sizeof(long_ad) * (*endnum - (i+2)));
     786               0 :                                 i --;
     787               0 :                                 (*endnum) --;
     788                 :                         }
     789                 :                 }
     790               0 :                 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
     791                 :                 {
     792               0 :                         udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
     793                 :                                 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
     794                 :                                inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
     795               0 :                         laarr[i].extLocation.logicalBlockNum = 0;
     796               0 :                         laarr[i].extLocation.partitionReferenceNum = 0;
     797               0 :                         laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) |
     798                 :                                 EXT_NOT_RECORDED_NOT_ALLOCATED;
     799                 :                 }
     800                 :         }
     801                 : }
     802                 : 
     803                 : static void udf_update_extents(struct inode *inode,
     804                 :         kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum,
     805                 :         kernel_lb_addr pbloc, uint32_t pextoffset, struct buffer_head **pbh)
     806               0 : {
     807               0 :         int start = 0, i;
     808               0 :         kernel_lb_addr tmploc;
     809               0 :         uint32_t tmplen;
     810                 : 
     811               0 :         if (startnum > endnum)
     812                 :         {
     813               0 :                 for (i=0; i<(startnum-endnum); i++)
     814                 :                 {
     815               0 :                         udf_delete_aext(inode, pbloc, pextoffset, laarr[i].extLocation,
     816                 :                                 laarr[i].extLength, *pbh);
     817                 :                 }
     818                 :         }
     819               0 :         else if (startnum < endnum)
     820                 :         {
     821               0 :                 for (i=0; i<(endnum-startnum); i++)
     822                 :                 {
     823               0 :                         udf_insert_aext(inode, pbloc, pextoffset, laarr[i].extLocation,
     824                 :                                 laarr[i].extLength, *pbh);
     825               0 :                         udf_next_aext(inode, &pbloc, &pextoffset, &laarr[i].extLocation,
     826                 :                                 &laarr[i].extLength, pbh, 1);
     827               0 :                         start ++;
     828                 :                 }
     829                 :         }
     830                 : 
     831               0 :         for (i=start; i<endnum; i++)
     832                 :         {
     833               0 :                 udf_next_aext(inode, &pbloc, &pextoffset, &tmploc, &tmplen, pbh, 0);
     834               0 :                 udf_write_aext(inode, pbloc, &pextoffset, laarr[i].extLocation,
     835                 :                         laarr[i].extLength, *pbh, 1);
     836                 :         }
     837                 : }
     838                 : 
     839                 : struct buffer_head * udf_bread(struct inode * inode, int block,
     840                 :         int create, int * err)
     841               0 : {
     842               0 :         struct buffer_head * bh = NULL;
     843                 : 
     844               0 :         bh = udf_getblk(inode, block, create, err);
     845               0 :         if (!bh)
     846               0 :                 return NULL;
     847                 : 
     848               0 :         if (buffer_uptodate(bh))
     849               0 :                 return bh;
     850               0 :         ll_rw_block(READ, 1, &bh);
     851               0 :         wait_on_buffer(bh);
     852               0 :         if (buffer_uptodate(bh))
     853               0 :                 return bh;
     854               0 :         brelse(bh);
     855               0 :         *err = -EIO;
     856               0 :         return NULL;
     857                 : }
     858                 : 
     859                 : void udf_truncate(struct inode * inode)
     860               0 : {
     861               0 :         int offset;
     862               0 :         int err;
     863                 : 
     864               0 :         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
     865                 :                         S_ISLNK(inode->i_mode)))
     866               0 :                 return;
     867               0 :         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
     868               0 :                 return;
     869                 : 
     870               0 :         lock_kernel();
     871               0 :         if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
     872                 :         {
     873               0 :                 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
     874                 :                         inode->i_size))
     875                 :                 {
     876               0 :                         udf_expand_file_adinicb(inode, inode->i_size, &err);
     877               0 :                         if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
     878                 :                         {
     879               0 :                                 inode->i_size = UDF_I_LENALLOC(inode);
     880               0 :                                 unlock_kernel();
     881               0 :                                 return;
     882                 :                         }
     883                 :                         else
     884               0 :                                 udf_truncate_extents(inode);
     885                 :                 }
     886                 :                 else
     887                 :                 {
     888               0 :                         offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
     889               0 :                         memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode));
     890               0 :                         UDF_I_LENALLOC(inode) = inode->i_size;
     891                 :                 }
     892                 :         }
     893                 :         else
     894                 :         {
     895               0 :                 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
     896               0 :                 udf_truncate_extents(inode);
     897                 :         }       
     898                 : 
     899               0 :         inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
     900               0 :         if (IS_SYNC(inode))
     901               0 :                 udf_sync_inode (inode);
     902                 :         else
     903               0 :                 mark_inode_dirty(inode);
     904               0 :         unlock_kernel();
     905                 : }
     906                 : 
     907                 : static void
     908                 : __udf_read_inode(struct inode *inode)
     909               0 : {
     910               0 :         struct buffer_head *bh = NULL;
     911               0 :         struct fileEntry *fe;
     912               0 :         uint16_t ident;
     913                 : 
     914                 :         /*
     915                 :          * Set defaults, but the inode is still incomplete!
     916                 :          * Note: get_new_inode() sets the following on a new inode:
     917                 :          *      i_sb = sb
     918                 :          *      i_no = ino
     919                 :          *      i_flags = sb->s_flags
     920                 :          *      i_state = 0
     921                 :          * clean_inode(): zero fills and sets
     922                 :          *      i_count = 1
     923                 :          *      i_nlink = 1
     924                 :          *      i_op = NULL;
     925                 :          */
     926               0 :         inode->i_blksize = PAGE_SIZE;
     927                 : 
     928               0 :         bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
     929                 : 
     930               0 :         if (!bh)
     931                 :         {
     932               0 :                 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
     933                 :                         inode->i_ino);
     934               0 :                 make_bad_inode(inode);
     935               0 :                 return;
     936                 :         }
     937                 : 
     938               0 :         if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
     939                 :                 ident != TAG_IDENT_USE)
     940                 :         {
     941               0 :                 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
     942                 :                         inode->i_ino, ident);
     943               0 :                 udf_release_data(bh);
     944               0 :                 make_bad_inode(inode);
     945               0 :                 return;
     946                 :         }
     947                 : 
     948               0 :         fe = (struct fileEntry *)bh->b_data;
     949                 : 
     950               0 :         if (le16_to_cpu(fe->icbTag.strategyType) == 4096)
     951                 :         {
     952               0 :                 struct buffer_head *ibh = NULL, *nbh = NULL;
     953               0 :                 struct indirectEntry *ie;
     954                 : 
     955               0 :                 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
     956               0 :                 if (ident == TAG_IDENT_IE)
     957                 :                 {
     958               0 :                         if (ibh)
     959                 :                         {
     960               0 :                                 kernel_lb_addr loc;
     961               0 :                                 ie = (struct indirectEntry *)ibh->b_data;
     962                 :         
     963               0 :                                 loc = lelb_to_cpu(ie->indirectICB.extLocation);
     964                 :         
     965               0 :                                 if (ie->indirectICB.extLength && 
     966                 :                                         (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident)))
     967                 :                                 {
     968               0 :                                         if (ident == TAG_IDENT_FE ||
     969                 :                                                 ident == TAG_IDENT_EFE)
     970                 :                                         {
     971               0 :                                                 memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr));
     972               0 :                                                 udf_release_data(bh);
     973               0 :                                                 udf_release_data(ibh);
     974               0 :                                                 udf_release_data(nbh);
     975               0 :                                                 __udf_read_inode(inode);
     976               0 :                                                 return;
     977                 :                                         }
     978                 :                                         else
     979                 :                                         {
     980               0 :                                                 udf_release_data(nbh);
     981               0 :                                                 udf_release_data(ibh);
     982                 :                                         }
     983                 :                                 }
     984                 :                                 else
     985               0 :                                         udf_release_data(ibh);
     986                 :                         }
     987                 :                 }
     988                 :                 else
     989               0 :                         udf_release_data(ibh);
     990                 :         }
     991               0 :         else if (le16_to_cpu(fe->icbTag.strategyType) != 4)
     992                 :         {
     993               0 :                 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
     994                 :                         le16_to_cpu(fe->icbTag.strategyType));
     995               0 :                 udf_release_data(bh);
     996               0 :                 make_bad_inode(inode);
     997               0 :                 return;
     998                 :         }
     999               0 :         udf_fill_inode(inode, bh);
    1000               0 :         udf_release_data(bh);
    1001                 : }
    1002                 : 
    1003                 : static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
    1004               0 : {
    1005               0 :         struct fileEntry *fe;
    1006               0 :         struct extendedFileEntry *efe;
    1007               0 :         time_t convtime;
    1008               0 :         long convtime_usec;
    1009               0 :         int offset;
    1010                 : 
    1011               0 :         fe = (struct fileEntry *)bh->b_data;
    1012               0 :         efe = (struct extendedFileEntry *)bh->b_data;
    1013                 : 
    1014               0 :         if (le16_to_cpu(fe->icbTag.strategyType) == 4)
    1015               0 :                 UDF_I_STRAT4096(inode) = 0;
    1016                 :         else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
    1017               0 :                 UDF_I_STRAT4096(inode) = 1;
    1018                 : 
    1019               0 :         UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
    1020               0 :         UDF_I_UNIQUE(inode) = 0;
    1021               0 :         UDF_I_LENEATTR(inode) = 0;
    1022               0 :         UDF_I_LENEXTENTS(inode) = 0;
    1023               0 :         UDF_I_LENALLOC(inode) = 0;
    1024               0 :         UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
    1025               0 :         UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
    1026               0 :         if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE)
    1027                 :         {
    1028               0 :                 UDF_I_EFE(inode) = 1;
    1029               0 :                 UDF_I_USE(inode) = 0;
    1030               0 :                 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
    1031               0 :                 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
    1032                 :         }
    1033               0 :         else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE)
    1034                 :         {
    1035               0 :                 UDF_I_EFE(inode) = 0;
    1036               0 :                 UDF_I_USE(inode) = 0;
    1037               0 :                 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL);
    1038               0 :                 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), inode->i_sb->s_blocksize - sizeof(struct fileEntry));
    1039                 :         }
    1040               0 :         else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE)
    1041                 :         {
    1042               0 :                 UDF_I_EFE(inode) = 0;
    1043               0 :                 UDF_I_USE(inode) = 1;
    1044               0 :                 UDF_I_LENALLOC(inode) =
    1045                 :                         le32_to_cpu(
    1046                 :                                 ((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs);
    1047               0 :                 UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry), GFP_KERNEL);
    1048               0 :                 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
    1049               0 :                 return;
    1050                 :         }
    1051                 : 
    1052               0 :         inode->i_uid = le32_to_cpu(fe->uid);
    1053               0 :         if ( inode->i_uid == -1 ) inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
    1054                 : 
    1055               0 :         inode->i_gid = le32_to_cpu(fe->gid);
    1056               0 :         if ( inode->i_gid == -1 ) inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
    1057                 : 
    1058               0 :         inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
    1059               0 :         if (!inode->i_nlink)
    1060               0 :                 inode->i_nlink = 1;
    1061                 :         
    1062               0 :         inode->i_size = le64_to_cpu(fe->informationLength);
    1063               0 :         UDF_I_LENEXTENTS(inode) = inode->i_size;
    1064                 : 
    1065               0 :         inode->i_mode = udf_convert_permissions(fe);
    1066               0 :         inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
    1067                 : 
    1068               0 :         if (UDF_I_EFE(inode) == 0)
    1069                 :         {
    1070               0 :                 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
    1071                 :                         (inode->i_sb->s_blocksize_bits - 9);
    1072                 : 
    1073               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1074                 :                         lets_to_cpu(fe->accessTime)) )
    1075                 :                 {
    1076               0 :                         inode->i_atime.tv_sec = convtime;
    1077               0 :                         inode->i_atime.tv_nsec = convtime_usec * 1000;
    1078                 :                 }
    1079                 :                 else
    1080                 :                 {
    1081               0 :                         inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
    1082                 :                 }
    1083                 : 
    1084               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1085                 :                         lets_to_cpu(fe->modificationTime)) )
    1086                 :                 {
    1087               0 :                         inode->i_mtime.tv_sec = convtime;
    1088               0 :                         inode->i_mtime.tv_nsec = convtime_usec * 1000;
    1089                 :                 }
    1090                 :                 else
    1091                 :                 {
    1092               0 :                         inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
    1093                 :                 }
    1094                 : 
    1095               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1096                 :                         lets_to_cpu(fe->attrTime)) )
    1097                 :                 {
    1098               0 :                         inode->i_ctime.tv_sec = convtime;
    1099               0 :                         inode->i_ctime.tv_nsec = convtime_usec * 1000;
    1100                 :                 }
    1101                 :                 else
    1102                 :                 {
    1103               0 :                         inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
    1104                 :                 }
    1105                 : 
    1106               0 :                 UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
    1107               0 :                 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
    1108               0 :                 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
    1109               0 :                 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
    1110                 :         }
    1111                 :         else
    1112                 :         {
    1113               0 :                 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << 
    1114                 :                         (inode->i_sb->s_blocksize_bits - 9);
    1115                 : 
    1116               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1117                 :                         lets_to_cpu(efe->accessTime)) )
    1118                 :                 {
    1119               0 :                         inode->i_atime.tv_sec = convtime;
    1120               0 :                         inode->i_atime.tv_nsec = convtime_usec * 1000;
    1121                 :                 }
    1122                 :                 else
    1123                 :                 {
    1124               0 :                         inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
    1125                 :                 }
    1126                 : 
    1127               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1128                 :                         lets_to_cpu(efe->modificationTime)) )
    1129                 :                 {
    1130               0 :                         inode->i_mtime.tv_sec = convtime;
    1131               0 :                         inode->i_mtime.tv_nsec = convtime_usec * 1000;
    1132                 :                 }
    1133                 :                 else
    1134                 :                 {
    1135               0 :                         inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
    1136                 :                 }
    1137                 : 
    1138               0 :                 if ( udf_stamp_to_time(&convtime, &convtime_usec,
    1139                 :                         lets_to_cpu(efe->createTime)) )
    1140                 :                 {
    1141               0 :                         UDF_I_CRTIME(inode).tv_sec = convtime;
    1142               0 :                         UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
    1143                 :                 }
    1144                 :                 else
    1145                 :                 {
    1146               0 :                         UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
    1147                 :                 }
    1148                 : 
    1149               0 :                 if ( udf_stamp_to_time(