sh: convert /proc/cpu/aligmnent, /proc/cpu/kernel_alignment to seq_file
[safe/jmp/linux-2.6] / fs / udf / inode.c
index 6b4409f..6d24c2c 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/buffer_head.h>
 #include <linux/writeback.h>
 #include <linux/slab.h>
+#include <linux/crc-itu-t.h>
 
 #include "udf_i.h"
 #include "udf_sb.h"
@@ -52,36 +53,21 @@ static int udf_update_inode(struct inode *, int);
 static void udf_fill_inode(struct inode *, struct buffer_head *);
 static int udf_alloc_i_data(struct inode *inode, size_t size);
 static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
-                                       long *, int *);
+                                       sector_t *, int *);
 static int8_t udf_insert_aext(struct inode *, struct extent_position,
-                             kernel_lb_addr, uint32_t);
+                             struct kernel_lb_addr, uint32_t);
 static void udf_split_extents(struct inode *, int *, int, int,
-                             kernel_long_ad[EXTENT_MERGE_SIZE], int *);
+                             struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
 static void udf_prealloc_extents(struct inode *, int, int,
-                                kernel_long_ad[EXTENT_MERGE_SIZE], int *);
+                                struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
 static void udf_merge_extents(struct inode *,
-                             kernel_long_ad[EXTENT_MERGE_SIZE], int *);
+                             struct kernel_long_ad[EXTENT_MERGE_SIZE], int *);
 static void udf_update_extents(struct inode *,
-                              kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
+                              struct kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
                               struct extent_position *);
 static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
 
-/*
- * udf_delete_inode
- *
- * PURPOSE
- *     Clean-up before the specified inode is destroyed.
- *
- * DESCRIPTION
- *     This routine is called when the kernel destroys an inode structure
- *     ie. when iput() finds i_count == 0.
- *
- * HISTORY
- *     July 1, 1997 - Andrew E. Mileski
- *     Written, tested, and released.
- *
- *  Called at the last iput() if i_nlink is zero.
- */
+
 void udf_delete_inode(struct inode *inode)
 {
        truncate_inode_pages(&inode->i_data, 0);
@@ -104,22 +90,20 @@ no_delete:
 }
 
 /*
- * If we are going to release inode from memory, we discard preallocation and
- * truncate last inode extent to proper length. We could use drop_inode() but
- * it's called under inode_lock and thus we cannot mark inode dirty there.  We
- * use clear_inode() but we have to make sure to write inode as it's not written
- * automatically.
+ * If we are going to release inode from memory, we truncate last inode extent
+ * to proper length. We could use drop_inode() but it's called under inode_lock
+ * and thus we cannot mark inode dirty there.  We use clear_inode() but we have
+ * to make sure to write inode as it's not written automatically.
  */
 void udf_clear_inode(struct inode *inode)
 {
        struct udf_inode_info *iinfo;
        if (!(inode->i_sb->s_flags & MS_RDONLY)) {
                lock_kernel();
-               /* Discard preallocation for directories, symlinks, etc. */
-               udf_discard_prealloc(inode);
                udf_truncate_tail_extent(inode);
                unlock_kernel();
-               write_inode_now(inode, 1);
+               write_inode_now(inode, 0);
+               invalidate_inode_buffers(inode);
        }
        iinfo = UDF_I(inode);
        kfree(iinfo->i_ext.i_data);
@@ -213,14 +197,14 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
 {
        int newblock;
        struct buffer_head *dbh = NULL;
-       kernel_lb_addr eloc;
+       struct kernel_lb_addr eloc;
        uint32_t elen;
        uint8_t alloctype;
        struct extent_position epos;
 
        struct udf_fileident_bh sfibh, dfibh;
-       loff_t f_pos = udf_ext0_offset(inode) >> 2;
-       int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
+       loff_t f_pos = udf_ext0_offset(inode);
+       int size = udf_ext0_offset(inode) + inode->i_size;
        struct fileIdentDesc cfi, *sfi, *dfi;
        struct udf_inode_info *iinfo = UDF_I(inode);
 
@@ -256,11 +240,11 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
        mark_buffer_dirty_inode(dbh, inode);
 
        sfibh.soffset = sfibh.eoffset =
-                       (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
+                       f_pos & (inode->i_sb->s_blocksize - 1);
        sfibh.sbh = sfibh.ebh = NULL;
        dfibh.soffset = dfibh.eoffset = 0;
        dfibh.sbh = dfibh.ebh = dbh;
-       while ((f_pos < size)) {
+       while (f_pos < size) {
                iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
                sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
                                         NULL, NULL, NULL);
@@ -289,12 +273,12 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
        eloc.logicalBlockNum = *block;
        eloc.partitionReferenceNum =
                                iinfo->i_location.partitionReferenceNum;
-       elen = inode->i_size;
+       elen = inode->i_sb->s_blocksize;
        iinfo->i_lenExtents = elen;
        epos.bh = NULL;
        epos.block = iinfo->i_location;
        epos.offset = udf_file_entry_alloc_offset(inode);
-       udf_add_aext(inode, &epos, eloc, elen, 0);
+       udf_add_aext(inode, &epos, &eloc, elen, 0);
        /* UniqueID stuff */
 
        brelse(epos.bh);
@@ -307,7 +291,7 @@ static int udf_get_block(struct inode *inode, sector_t block,
 {
        int err, new;
        struct buffer_head *bh;
-       unsigned long phys;
+       sector_t phys = 0;
        struct udf_inode_info *iinfo;
 
        if (!create) {
@@ -323,9 +307,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
 
        lock_kernel();
 
-       if (block < 0)
-               goto abort_negative;
-
        iinfo = UDF_I(inode);
        if (block == iinfo->i_next_alloc_block + 1) {
                iinfo->i_next_alloc_block++;
@@ -347,10 +328,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
 abort:
        unlock_kernel();
        return err;
-
-abort_negative:
-       udf_warning(inode->i_sb, "udf_get_block", "block < 0");
-       goto abort;
 }
 
 static struct buffer_head *udf_getblk(struct inode *inode, long block,
@@ -379,12 +356,12 @@ static struct buffer_head *udf_getblk(struct inode *inode, long block,
 
 /* Extend the file by 'blocks' blocks, return the number of extents added */
 int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
-                   kernel_long_ad *last_ext, sector_t blocks)
+                   struct kernel_long_ad *last_ext, sector_t blocks)
 {
        sector_t add;
        int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
        struct super_block *sb = inode->i_sb;
-       kernel_lb_addr prealloc_loc = {};
+       struct kernel_lb_addr prealloc_loc = {};
        int prealloc_len = 0;
        struct udf_inode_info *iinfo;
 
@@ -431,11 +408,11 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
        }
 
        if (fake) {
-               udf_add_aext(inode, last_pos, last_ext->extLocation,
+               udf_add_aext(inode, last_pos, &last_ext->extLocation,
                             last_ext->extLength, 1);
                count++;
        } else
-               udf_write_aext(inode, last_pos, last_ext->extLocation,
+               udf_write_aext(inode, last_pos, &last_ext->extLocation,
                                last_ext->extLength, 1);
 
        /* Managed to do everything necessary? */
@@ -452,7 +429,7 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
        /* Create enough extents to cover the whole hole */
        while (blocks > add) {
                blocks -= add;
-               if (udf_add_aext(inode, last_pos, last_ext->extLocation,
+               if (udf_add_aext(inode, last_pos, &last_ext->extLocation,
                                 last_ext->extLength, 1) == -1)
                        return -1;
                count++;
@@ -460,7 +437,7 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
        if (blocks) {
                last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
                        (blocks << sb->s_blocksize_bits);
-               if (udf_add_aext(inode, last_pos, last_ext->extLocation,
+               if (udf_add_aext(inode, last_pos, &last_ext->extLocation,
                                 last_ext->extLength, 1) == -1)
                        return -1;
                count++;
@@ -469,7 +446,7 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
 out:
        /* Do we have some preallocated blocks saved? */
        if (prealloc_len) {
-               if (udf_add_aext(inode, last_pos, prealloc_loc,
+               if (udf_add_aext(inode, last_pos, &prealloc_loc,
                                 prealloc_len, 1) == -1)
                        return -1;
                last_ext->extLocation = prealloc_loc;
@@ -479,9 +456,9 @@ out:
 
        /* last_pos should point to the last written extent... */
        if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
-               last_pos->offset -= sizeof(short_ad);
+               last_pos->offset -= sizeof(struct short_ad);
        else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
-               last_pos->offset -= sizeof(long_ad);
+               last_pos->offset -= sizeof(struct long_ad);
        else
                return -1;
 
@@ -489,15 +466,15 @@ out:
 }
 
 static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
-                                       int *err, long *phys, int *new)
+                                       int *err, sector_t *phys, int *new)
 {
        static sector_t last_block;
        struct buffer_head *result = NULL;
-       kernel_long_ad laarr[EXTENT_MERGE_SIZE];
+       struct kernel_long_ad laarr[EXTENT_MERGE_SIZE];
        struct extent_position prev_epos, cur_epos, next_epos;
        int count = 0, startnum = 0, endnum = 0;
        uint32_t elen = 0, tmpelen;
-       kernel_lb_addr eloc, tmpeloc;
+       struct kernel_lb_addr eloc, tmpeloc;
        int c = 1;
        loff_t lbcount = 0, b_off = 0;
        uint32_t newblocknum, newblock;
@@ -570,12 +547,12 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                        elen = EXT_RECORDED_ALLOCATED |
                                ((elen + inode->i_sb->s_blocksize - 1) &
                                 ~(inode->i_sb->s_blocksize - 1));
-                       etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
+                       etype = udf_write_aext(inode, &cur_epos, &eloc, elen, 1);
                }
                brelse(prev_epos.bh);
                brelse(cur_epos.bh);
                brelse(next_epos.bh);
-               newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
+               newblock = udf_get_lb_pblock(inode->i_sb, &eloc, offset);
                *phys = newblock;
                return NULL;
        }
@@ -592,7 +569,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                } else {
                        /* Create a fake extent when there's not one */
                        memset(&laarr[0].extLocation, 0x00,
-                               sizeof(kernel_lb_addr));
+                               sizeof(struct kernel_lb_addr));
                        laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
                        /* Will udf_extend_file() create real extent from
                           a fake one? */
@@ -622,7 +599,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                        laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
                                inode->i_sb->s_blocksize;
                        memset(&laarr[c].extLocation, 0x00,
-                               sizeof(kernel_lb_addr));
+                               sizeof(struct kernel_lb_addr));
                        count++;
                        endnum++;
                }
@@ -684,8 +661,12 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
        udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
 
 #ifdef UDF_PREALLOCATE
-       /* preallocate blocks */
-       udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
+       /* We preallocate blocks only for regular files. It also makes sense
+        * for directories but there's a problem when to drop the
+        * preallocation. We might use some delayed work for that but I feel
+        * it's overengineering for a filesystem like UDF. */
+       if (S_ISREG(inode->i_mode))
+               udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
 #endif
 
        /* merge any continuous blocks in laarr */
@@ -719,7 +700,7 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
 
 static void udf_split_extents(struct inode *inode, int *c, int offset,
                              int newblocknum,
-                             kernel_long_ad laarr[EXTENT_MERGE_SIZE],
+                             struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
                              int *endnum)
 {
        unsigned long blocksize = inode->i_sb->s_blocksize;
@@ -746,7 +727,7 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
                if (offset) {
                        if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
                                udf_free_blocks(inode->i_sb, inode,
-                                               laarr[curr].extLocation,
+                                               &laarr[curr].extLocation,
                                                0, offset);
                                laarr[curr].extLength =
                                        EXT_NOT_RECORDED_NOT_ALLOCATED |
@@ -783,7 +764,7 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
 }
 
 static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
-                                kernel_long_ad laarr[EXTENT_MERGE_SIZE],
+                                struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
                                 int *endnum)
 {
        int start, length = 0, currlength = 0, i;
@@ -837,7 +818,7 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
                                         inode->i_sb->s_blocksize_bits);
                        else {
                                memmove(&laarr[c + 2], &laarr[c + 1],
-                                       sizeof(long_ad) * (*endnum - (c + 1)));
+                                       sizeof(struct long_ad) * (*endnum - (c + 1)));
                                (*endnum)++;
                                laarr[c + 1].extLocation.logicalBlockNum = next;
                                laarr[c + 1].extLocation.partitionReferenceNum =
@@ -866,7 +847,7 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
                                        if (*endnum > (i + 1))
                                                memmove(&laarr[i],
                                                        &laarr[i + 1],
-                                                       sizeof(long_ad) *
+                                                       sizeof(struct long_ad) *
                                                        (*endnum - (i + 1)));
                                        i--;
                                        (*endnum)--;
@@ -879,7 +860,7 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
 }
 
 static void udf_merge_extents(struct inode *inode,
-                             kernel_long_ad laarr[EXTENT_MERGE_SIZE],
+                             struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
                              int *endnum)
 {
        int i;
@@ -887,8 +868,8 @@ static void udf_merge_extents(struct inode *inode,
        unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
 
        for (i = 0; i < (*endnum - 1); i++) {
-               kernel_long_ad *li /*l[i]*/ = &laarr[i];
-               kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
+               struct kernel_long_ad *li /*l[i]*/ = &laarr[i];
+               struct kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
 
                if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
                        (((li->extLength >> 30) ==
@@ -922,7 +903,7 @@ static void udf_merge_extents(struct inode *inode,
                                         blocksize - 1) & ~(blocksize - 1));
                                if (*endnum > (i + 2))
                                        memmove(&laarr[i + 1], &laarr[i + 2],
-                                               sizeof(long_ad) *
+                                               sizeof(struct long_ad) *
                                                (*endnum - (i + 2)));
                                i--;
                                (*endnum)--;
@@ -931,7 +912,7 @@ static void udf_merge_extents(struct inode *inode,
                                (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
                           ((lip1->extLength >> 30) ==
                                (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
-                       udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
+                       udf_free_blocks(inode->i_sb, inode, &li->extLocation, 0,
                                        ((li->extLength &
                                          UDF_EXTENT_LENGTH_MASK) +
                                         blocksize - 1) >> blocksize_bits);
@@ -957,7 +938,7 @@ static void udf_merge_extents(struct inode *inode,
                                          blocksize - 1) & ~(blocksize - 1));
                                if (*endnum > (i + 2))
                                        memmove(&laarr[i + 1], &laarr[i + 2],
-                                               sizeof(long_ad) *
+                                               sizeof(struct long_ad) *
                                                (*endnum - (i + 2)));
                                i--;
                                (*endnum)--;
@@ -965,7 +946,7 @@ static void udf_merge_extents(struct inode *inode,
                } else if ((li->extLength >> 30) ==
                                        (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
                        udf_free_blocks(inode->i_sb, inode,
-                                       li->extLocation, 0,
+                                       &li->extLocation, 0,
                                        ((li->extLength &
                                                UDF_EXTENT_LENGTH_MASK) +
                                         blocksize - 1) >> blocksize_bits);
@@ -979,12 +960,12 @@ static void udf_merge_extents(struct inode *inode,
 }
 
 static void udf_update_extents(struct inode *inode,
-                              kernel_long_ad laarr[EXTENT_MERGE_SIZE],
+                              struct kernel_long_ad laarr[EXTENT_MERGE_SIZE],
                               int startnum, int endnum,
                               struct extent_position *epos)
 {
        int start = 0, i;
-       kernel_lb_addr tmploc;
+       struct kernel_lb_addr tmploc;
        uint32_t tmplen;
 
        if (startnum > endnum) {
@@ -1003,7 +984,7 @@ static void udf_update_extents(struct inode *inode,
 
        for (i = start; i < endnum; i++) {
                udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
-               udf_write_aext(inode, epos, laarr[i].extLocation,
+               udf_write_aext(inode, epos, &laarr[i].extLocation,
                               laarr[i].extLength, 1);
        }
 }
@@ -1096,7 +1077,7 @@ static void __udf_read_inode(struct inode *inode)
         *      i_nlink = 1
         *      i_op = NULL;
         */
-       bh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 0, &ident);
+       bh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 0, &ident);
        if (!bh) {
                printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
                       inode->i_ino);
@@ -1116,42 +1097,36 @@ static void __udf_read_inode(struct inode *inode)
        fe = (struct fileEntry *)bh->b_data;
 
        if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
-               struct buffer_head *ibh = NULL, *nbh = NULL;
-               struct indirectEntry *ie;
+               struct buffer_head *ibh;
 
-               ibh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 1,
+               ibh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 1,
                                        &ident);
-               if (ident == TAG_IDENT_IE) {
-                       if (ibh) {
-                               kernel_lb_addr loc;
-                               ie = (struct indirectEntry *)ibh->b_data;
-
-                               loc = lelb_to_cpu(ie->indirectICB.extLocation);
-
-                               if (ie->indirectICB.extLength &&
-                                   (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
-                                                           &ident))) {
-                                       if (ident == TAG_IDENT_FE ||
-                                           ident == TAG_IDENT_EFE) {
-                                               memcpy(&iinfo->i_location,
-                                                      &loc,
-                                                      sizeof(kernel_lb_addr));
-                                               brelse(bh);
-                                               brelse(ibh);
-                                               brelse(nbh);
-                                               __udf_read_inode(inode);
-                                               return;
-                                       } else {
-                                               brelse(nbh);
-                                               brelse(ibh);
-                                       }
-                               } else {
+               if (ident == TAG_IDENT_IE && ibh) {
+                       struct buffer_head *nbh = NULL;
+                       struct kernel_lb_addr loc;
+                       struct indirectEntry *ie;
+
+                       ie = (struct indirectEntry *)ibh->b_data;
+                       loc = lelb_to_cpu(ie->indirectICB.extLocation);
+
+                       if (ie->indirectICB.extLength &&
+                               (nbh = udf_read_ptagged(inode->i_sb, &loc, 0,
+                                                       &ident))) {
+                               if (ident == TAG_IDENT_FE ||
+                                       ident == TAG_IDENT_EFE) {
+                                       memcpy(&iinfo->i_location,
+                                               &loc,
+                                               sizeof(struct kernel_lb_addr));
+                                       brelse(bh);
                                        brelse(ibh);
+                                       brelse(nbh);
+                                       __udf_read_inode(inode);
+                                       return;
                                }
+                               brelse(nbh);
                        }
-               } else {
-                       brelse(ibh);
                }
+               brelse(ibh);
        } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
                printk(KERN_ERR "udf: unsupported strategy type: %d\n",
                       le16_to_cpu(fe->icbTag.strategyType));
@@ -1168,8 +1143,6 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
 {
        struct fileEntry *fe;
        struct extendedFileEntry *efe;
-       time_t convtime;
-       long convtime_usec;
        int offset;
        struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
        struct udf_inode_info *iinfo = UDF_I(inode);
@@ -1250,36 +1223,29 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
        inode->i_size = le64_to_cpu(fe->informationLength);
        iinfo->i_lenExtents = inode->i_size;
 
-       inode->i_mode = udf_convert_permissions(fe);
-       inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
+       if (fe->icbTag.fileType != ICBTAG_FILE_TYPE_DIRECTORY &&
+                       sbi->s_fmode != UDF_INVALID_MODE)
+               inode->i_mode = sbi->s_fmode;
+       else if (fe->icbTag.fileType == ICBTAG_FILE_TYPE_DIRECTORY &&
+                       sbi->s_dmode != UDF_INVALID_MODE)
+               inode->i_mode = sbi->s_dmode;
+       else
+               inode->i_mode = udf_convert_permissions(fe);
+       inode->i_mode &= ~sbi->s_umask;
 
        if (iinfo->i_efe == 0) {
                inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
                        (inode->i_sb->s_blocksize_bits - 9);
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(fe->accessTime))) {
-                       inode->i_atime.tv_sec = convtime;
-                       inode->i_atime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
                        inode->i_atime = sbi->s_record_time;
-               }
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(fe->modificationTime))) {
-                       inode->i_mtime.tv_sec = convtime;
-                       inode->i_mtime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_mtime,
+                                           fe->modificationTime))
                        inode->i_mtime = sbi->s_record_time;
-               }
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(fe->attrTime))) {
-                       inode->i_ctime.tv_sec = convtime;
-                       inode->i_ctime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
                        inode->i_ctime = sbi->s_record_time;
-               }
 
                iinfo->i_unique = le64_to_cpu(fe->uniqueID);
                iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
@@ -1289,37 +1255,18 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
                    (inode->i_sb->s_blocksize_bits - 9);
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(efe->accessTime))) {
-                       inode->i_atime.tv_sec = convtime;
-                       inode->i_atime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
                        inode->i_atime = sbi->s_record_time;
-               }
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(efe->modificationTime))) {
-                       inode->i_mtime.tv_sec = convtime;
-                       inode->i_mtime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_mtime,
+                                           efe->modificationTime))
                        inode->i_mtime = sbi->s_record_time;
-               }
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(efe->createTime))) {
-                       iinfo->i_crtime.tv_sec = convtime;
-                       iinfo->i_crtime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
                        iinfo->i_crtime = sbi->s_record_time;
-               }
 
-               if (udf_stamp_to_time(&convtime, &convtime_usec,
-                                     lets_to_cpu(efe->attrTime))) {
-                       inode->i_ctime.tv_sec = convtime;
-                       inode->i_ctime.tv_nsec = convtime_usec * 1000;
-               } else {
+               if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
                        inode->i_ctime = sbi->s_record_time;
-               }
 
                iinfo->i_unique = le64_to_cpu(efe->uniqueID);
                iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
@@ -1338,6 +1285,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
        case ICBTAG_FILE_TYPE_REALTIME:
        case ICBTAG_FILE_TYPE_REGULAR:
        case ICBTAG_FILE_TYPE_UNDEF:
+       case ICBTAG_FILE_TYPE_VAT20:
                if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                        inode->i_data.a_ops = &udf_adinicb_aops;
                else
@@ -1363,6 +1311,15 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                inode->i_op = &page_symlink_inode_operations;
                inode->i_mode = S_IFLNK | S_IRWXUGO;
                break;
+       case ICBTAG_FILE_TYPE_MAIN:
+               udf_debug("METADATA FILE-----\n");
+               break;
+       case ICBTAG_FILE_TYPE_MIRROR:
+               udf_debug("METADATA MIRROR FILE-----\n");
+               break;
+       case ICBTAG_FILE_TYPE_BITMAP:
+               udf_debug("METADATA BITMAP FILE-----\n");
+               break;
        default:
                printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
                                "file type=%d\n", inode->i_ino,
@@ -1416,21 +1373,6 @@ static mode_t udf_convert_permissions(struct fileEntry *fe)
        return mode;
 }
 
-/*
- * udf_write_inode
- *
- * PURPOSE
- *     Write out the specified inode.
- *
- * DESCRIPTION
- *     This routine is called whenever an inode is synced.
- *     Currently this routine is just a placeholder.
- *
- * HISTORY
- *     July 1, 1997 - Andrew E. Mileski
- *     Written, tested, and released.
- */
-
 int udf_write_inode(struct inode *inode, int sync)
 {
        int ret;
@@ -1455,7 +1397,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        uint32_t udfperms;
        uint16_t icbflags;
        uint16_t crclen;
-       kernel_timestamp cpu_time;
        int err = 0;
        struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
        unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@@ -1463,7 +1404,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
 
        bh = udf_tread(inode->i_sb,
                        udf_get_lb_pblock(inode->i_sb,
-                                         iinfo->i_location, 0));
+                                         &iinfo->i_location, 0));
        if (!bh) {
                udf_debug("bread failure\n");
                return -EIO;
@@ -1483,14 +1424,14 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                       iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
                                        sizeof(struct unallocSpaceEntry));
                crclen = sizeof(struct unallocSpaceEntry) +
-                               iinfo->i_lenAlloc - sizeof(tag);
+                               iinfo->i_lenAlloc - sizeof(struct tag);
                use->descTag.tagLocation = cpu_to_le32(
                                                iinfo->i_location.
                                                        logicalBlockNum);
                use->descTag.descCRCLength = cpu_to_le16(crclen);
-               use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
-                                                          sizeof(tag), crclen,
-                                                          0));
+               use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
+                                                          sizeof(struct tag),
+                                                          crclen));
                use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
 
                mark_buffer_dirty(bh);
@@ -1526,23 +1467,23 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        fe->informationLength = cpu_to_le64(inode->i_size);
 
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
-               regid *eid;
+               struct regid *eid;
                struct deviceSpec *dsea =
                        (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
                if (!dsea) {
                        dsea = (struct deviceSpec *)
                                udf_add_extendedattr(inode,
                                                     sizeof(struct deviceSpec) +
-                                                    sizeof(regid), 12, 0x3);
+                                                    sizeof(struct regid), 12, 0x3);
                        dsea->attrType = cpu_to_le32(12);
                        dsea->attrSubtype = 1;
                        dsea->attrLength = cpu_to_le32(
                                                sizeof(struct deviceSpec) +
-                                               sizeof(regid));
-                       dsea->impUseLength = cpu_to_le32(sizeof(regid));
+                                               sizeof(struct regid));
+                       dsea->impUseLength = cpu_to_le32(sizeof(struct regid));
                }
-               eid = (regid *)dsea->impUse;
-               memset(eid, 0, sizeof(regid));
+               eid = (struct regid *)dsea->impUse;
+               memset(eid, 0, sizeof(struct regid));
                strcpy(eid->ident, UDF_ID_DEVELOPER);
                eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
                eid->identSuffix[1] = UDF_OS_ID_LINUX;
@@ -1558,13 +1499,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                        (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
                        (blocksize_bits - 9));
 
-               if (udf_time_to_stamp(&cpu_time, inode->i_atime))
-                       fe->accessTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
-                       fe->modificationTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
-                       fe->attrTime = cpu_to_lets(cpu_time);
-               memset(&(fe->impIdent), 0, sizeof(regid));
+               udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
+               udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
+               udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
+               memset(&(fe->impIdent), 0, sizeof(struct regid));
                strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
                fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
                fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
@@ -1598,16 +1536,12 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                     iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
                        iinfo->i_crtime = inode->i_ctime;
 
-               if (udf_time_to_stamp(&cpu_time, inode->i_atime))
-                       efe->accessTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
-                       efe->modificationTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
-                       efe->createTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
-                       efe->attrTime = cpu_to_lets(cpu_time);
+               udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
+               udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
+               udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
+               udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
 
-               memset(&(efe->impIdent), 0, sizeof(regid));
+               memset(&(efe->impIdent), 0, sizeof(struct regid));
                strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
                efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
                efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
@@ -1658,10 +1592,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        fe->descTag.tagLocation = cpu_to_le32(
                                        iinfo->i_location.logicalBlockNum);
        crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc -
-                                                               sizeof(tag);
+                                                               sizeof(struct tag);
        fe->descTag.descCRCLength = cpu_to_le16(crclen);
-       fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
-                                                 crclen, 0));
+       fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(struct tag),
+                                                 crclen));
        fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
 
        /* write the data blocks */
@@ -1680,7 +1614,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        return err;
 }
 
-struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
+struct inode *udf_iget(struct super_block *sb, struct kernel_lb_addr *ino)
 {
        unsigned long block = udf_get_lb_pblock(sb, ino, 0);
        struct inode *inode = iget_locked(sb, block);
@@ -1689,7 +1623,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
                return NULL;
 
        if (inode->i_state & I_NEW) {
-               memcpy(&UDF_I(inode)->i_location, &ino, sizeof(kernel_lb_addr));
+               memcpy(&UDF_I(inode)->i_location, ino, sizeof(struct kernel_lb_addr));
                __udf_read_inode(inode);
                unlock_new_inode(inode);
        }
@@ -1697,10 +1631,10 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
        if (is_bad_inode(inode))
                goto out_iput;
 
-       if (ino.logicalBlockNum >= UDF_SB(sb)->
-                       s_partmaps[ino.partitionReferenceNum].s_partition_len) {
+       if (ino->logicalBlockNum >= UDF_SB(sb)->
+                       s_partmaps[ino->partitionReferenceNum].s_partition_len) {
                udf_debug("block=%d, partition=%d out of range\n",
-                         ino.logicalBlockNum, ino.partitionReferenceNum);
+                         ino->logicalBlockNum, ino->partitionReferenceNum);
                make_bad_inode(inode);
                goto out_iput;
        }
@@ -1713,11 +1647,11 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
 }
 
 int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
-                   kernel_lb_addr eloc, uint32_t elen, int inc)
+                   struct kernel_lb_addr *eloc, uint32_t elen, int inc)
 {
        int adsize;
-       short_ad *sad = NULL;
-       long_ad *lad = NULL;
+       struct short_ad *sad = NULL;
+       struct long_ad *lad = NULL;
        struct allocExtDesc *aed;
        int8_t etype;
        uint8_t *ptr;
@@ -1731,9 +1665,9 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                ptr = epos->bh->b_data + epos->offset;
 
        if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
-               adsize = sizeof(short_ad);
+               adsize = sizeof(struct short_ad);
        else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
-               adsize = sizeof(long_ad);
+               adsize = sizeof(struct long_ad);
        else
                return -1;
 
@@ -1741,7 +1675,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                char *sptr, *dptr;
                struct buffer_head *nbh;
                int err, loffset;
-               kernel_lb_addr obloc = epos->block;
+               struct kernel_lb_addr obloc = epos->block;
 
                epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
                                                obloc.partitionReferenceNum,
@@ -1749,7 +1683,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                if (!epos->block.logicalBlockNum)
                        return -1;
                nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
-                                                                epos->block,
+                                                                &epos->block,
                                                                 0));
                if (!nbh)
                        return -1;
@@ -1778,9 +1712,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
 
                        if (epos->bh) {
                                aed = (struct allocExtDesc *)epos->bh->b_data;
-                               aed->lengthAllocDescs =
-                                       cpu_to_le32(le32_to_cpu(
-                                       aed->lengthAllocDescs) + adsize);
+                               le32_add_cpu(&aed->lengthAllocDescs, adsize);
                        } else {
                                iinfo->i_lenAlloc += adsize;
                                mark_inode_dirty(inode);
@@ -1788,20 +1720,20 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                }
                if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
                        udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
-                                   epos->block.logicalBlockNum, sizeof(tag));
+                                   epos->block.logicalBlockNum, sizeof(struct tag));
                else
                        udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
-                                   epos->block.logicalBlockNum, sizeof(tag));
+                                   epos->block.logicalBlockNum, sizeof(struct tag));
                switch (iinfo->i_alloc_type) {
                case ICBTAG_FLAG_AD_SHORT:
-                       sad = (short_ad *)sptr;
+                       sad = (struct short_ad *)sptr;
                        sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
                                                     inode->i_sb->s_blocksize);
                        sad->extPosition =
                                cpu_to_le32(epos->block.logicalBlockNum);
                        break;
                case ICBTAG_FLAG_AD_LONG:
-                       lad = (long_ad *)sptr;
+                       lad = (struct long_ad *)sptr;
                        lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
                                                     inode->i_sb->s_blocksize);
                        lad->extLocation = cpu_to_lelb(epos->block);
@@ -1830,9 +1762,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                mark_inode_dirty(inode);
        } else {
                aed = (struct allocExtDesc *)epos->bh->b_data;
-               aed->lengthAllocDescs =
-                       cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
-                                   adsize);
+               le32_add_cpu(&aed->lengthAllocDescs, adsize);
                if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
                                UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
                        udf_update_tag(epos->bh->b_data,
@@ -1847,12 +1777,12 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
 }
 
 int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
-                     kernel_lb_addr eloc, uint32_t elen, int inc)
+                     struct kernel_lb_addr *eloc, uint32_t elen, int inc)
 {
        int adsize;
        uint8_t *ptr;
-       short_ad *sad;
-       long_ad *lad;
+       struct short_ad *sad;
+       struct long_ad *lad;
        struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (!epos->bh)
@@ -1864,17 +1794,17 @@ int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
 
        switch (iinfo->i_alloc_type) {
        case ICBTAG_FLAG_AD_SHORT:
-               sad = (short_ad *)ptr;
+               sad = (struct short_ad *)ptr;
                sad->extLength = cpu_to_le32(elen);
-               sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
-               adsize = sizeof(short_ad);
+               sad->extPosition = cpu_to_le32(eloc->logicalBlockNum);
+               adsize = sizeof(struct short_ad);
                break;
        case ICBTAG_FLAG_AD_LONG:
-               lad = (long_ad *)ptr;
+               lad = (struct long_ad *)ptr;
                lad->extLength = cpu_to_le32(elen);
-               lad->extLocation = cpu_to_lelb(eloc);
+               lad->extLocation = cpu_to_lelb(*eloc);
                memset(lad->impUse, 0x00, sizeof(lad->impUse));
-               adsize = sizeof(long_ad);
+               adsize = sizeof(struct long_ad);
                break;
        default:
                return -1;
@@ -1901,7 +1831,7 @@ int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
 }
 
 int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
-                    kernel_lb_addr *eloc, uint32_t *elen, int inc)
+                    struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
 {
        int8_t etype;
 
@@ -1911,7 +1841,7 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
                epos->block = *eloc;
                epos->offset = sizeof(struct allocExtDesc);
                brelse(epos->bh);
-               block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
+               block = udf_get_lb_pblock(inode->i_sb, &epos->block, 0);
                epos->bh = udf_tread(inode->i_sb, block);
                if (!epos->bh) {
                        udf_debug("reading block %d failed!\n", block);
@@ -1923,13 +1853,13 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
 }
 
 int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
-                       kernel_lb_addr *eloc, uint32_t *elen, int inc)
+                       struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
 {
        int alen;
        int8_t etype;
        uint8_t *ptr;
-       short_ad *sad;
-       long_ad *lad;
+       struct short_ad *sad;
+       struct long_ad *lad;
        struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (!epos->bh) {
@@ -1978,9 +1908,9 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
 }
 
 static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
-                             kernel_lb_addr neloc, uint32_t nelen)
+                             struct kernel_lb_addr neloc, uint32_t nelen)
 {
-       kernel_lb_addr oeloc;
+       struct kernel_lb_addr oeloc;
        uint32_t oelen;
        int8_t etype;
 
@@ -1988,18 +1918,18 @@ static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
                get_bh(epos.bh);
 
        while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
-               udf_write_aext(inode, &epos, neloc, nelen, 1);
+               udf_write_aext(inode, &epos, &neloc, nelen, 1);
                neloc = oeloc;
                nelen = (etype << 30) | oelen;
        }
-       udf_add_aext(inode, &epos, neloc, nelen, 1);
+       udf_add_aext(inode, &epos, &neloc, nelen, 1);
        brelse(epos.bh);
 
        return (nelen >> 30);
 }
 
 int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
-                      kernel_lb_addr eloc, uint32_t elen)
+                      struct kernel_lb_addr eloc, uint32_t elen)
 {
        struct extent_position oepos;
        int adsize;
@@ -2014,9 +1944,9 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
 
        iinfo = UDF_I(inode);
        if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
-               adsize = sizeof(short_ad);
+               adsize = sizeof(struct short_ad);
        else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
-               adsize = sizeof(long_ad);
+               adsize = sizeof(struct long_ad);
        else
                adsize = 0;
 
@@ -2025,7 +1955,7 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
                return -1;
 
        while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
-               udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
+               udf_write_aext(inode, &oepos, &eloc, (etype << 30) | elen, 1);
                if (oepos.bh != epos.bh) {
                        oepos.block = epos.block;
                        brelse(oepos.bh);
@@ -2034,21 +1964,19 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
                        oepos.offset = epos.offset - adsize;
                }
        }
-       memset(&eloc, 0x00, sizeof(kernel_lb_addr));
+       memset(&eloc, 0x00, sizeof(struct kernel_lb_addr));
        elen = 0;
 
        if (epos.bh != oepos.bh) {
-               udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
-               udf_write_aext(inode, &oepos, eloc, elen, 1);
-               udf_write_aext(inode, &oepos, eloc, elen, 1);
+               udf_free_blocks(inode->i_sb, inode, &epos.block, 0, 1);
+               udf_write_aext(inode, &oepos, &eloc, elen, 1);
+               udf_write_aext(inode, &oepos, &eloc, elen, 1);
                if (!oepos.bh) {
                        iinfo->i_lenAlloc -= (adsize * 2);
                        mark_inode_dirty(inode);
                } else {
                        aed = (struct allocExtDesc *)oepos.bh->b_data;
-                       aed->lengthAllocDescs =
-                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
-                                           (2 * adsize));
+                       le32_add_cpu(&aed->lengthAllocDescs, -(2 * adsize));
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
                            UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
                                udf_update_tag(oepos.bh->b_data,
@@ -2059,15 +1987,13 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
                        mark_buffer_dirty_inode(oepos.bh, inode);
                }
        } else {
-               udf_write_aext(inode, &oepos, eloc, elen, 1);
+               udf_write_aext(inode, &oepos, &eloc, elen, 1);
                if (!oepos.bh) {
                        iinfo->i_lenAlloc -= adsize;
                        mark_inode_dirty(inode);
                } else {
                        aed = (struct allocExtDesc *)oepos.bh->b_data;
-                       aed->lengthAllocDescs =
-                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
-                                           adsize);
+                       le32_add_cpu(&aed->lengthAllocDescs, -adsize);
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
                            UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
                                udf_update_tag(oepos.bh->b_data,
@@ -2086,7 +2012,7 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
 }
 
 int8_t inode_bmap(struct inode *inode, sector_t block,
-                 struct extent_position *pos, kernel_lb_addr *eloc,
+                 struct extent_position *pos, struct kernel_lb_addr *eloc,
                  uint32_t *elen, sector_t *offset)
 {
        unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@@ -2095,11 +2021,6 @@ int8_t inode_bmap(struct inode *inode, sector_t block,
        int8_t etype;
        struct udf_inode_info *iinfo;
 
-       if (block < 0) {
-               printk(KERN_ERR "udf: inode_bmap: block < 0\n");
-               return -1;
-       }
-
        iinfo = UDF_I(inode);
        pos->offset = 0;
        pos->block = iinfo->i_location;
@@ -2123,7 +2044,7 @@ int8_t inode_bmap(struct inode *inode, sector_t block,
 
 long udf_block_map(struct inode *inode, sector_t block)
 {
-       kernel_lb_addr eloc;
+       struct kernel_lb_addr eloc;
        uint32_t elen;
        sector_t offset;
        struct extent_position epos = {};
@@ -2133,7 +2054,7 @@ long udf_block_map(struct inode *inode, sector_t block)
 
        if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
                                                (EXT_RECORDED_ALLOCATED >> 30))
-               ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
+               ret = udf_get_lb_pblock(inode->i_sb, &eloc, offset);
        else
                ret = 0;