udf: reduce stack usage of udf_get_filename
[safe/jmp/linux-2.6] / fs / udf / truncate.c
index 5c1bf92..225527c 100644 (file)
 #include "udfdecl.h"
 #include <linux/fs.h>
 #include <linux/mm.h>
-#include <linux/udf_fs.h>
 #include <linux/buffer_head.h>
 
 #include "udf_i.h"
 #include "udf_sb.h"
 
 static void extent_trunc(struct inode *inode, struct extent_position *epos,
-                        kernel_lb_addr eloc, int8_t etype, uint32_t elen,
+                        struct kernel_lb_addr *eloc, int8_t etype, uint32_t elen,
                         uint32_t nelen)
 {
-       kernel_lb_addr neloc = {};
+       struct kernel_lb_addr neloc = {};
        int last_block = (elen + inode->i_sb->s_blocksize - 1) >>
                inode->i_sb->s_blocksize_bits;
        int first_block = (nelen + inode->i_sb->s_blocksize - 1) >>
@@ -44,12 +43,12 @@ static void extent_trunc(struct inode *inode, struct extent_position *epos,
                                        last_block);
                        etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30);
                } else
-                       neloc = eloc;
+                       neloc = *eloc;
                nelen = (etype << 30) | nelen;
        }
 
        if (elen != nelen) {
-               udf_write_aext(inode, epos, neloc, nelen, 0);
+               udf_write_aext(inode, epos, &neloc, nelen, 0);
                if (last_block - first_block > 0) {
                        if (etype == (EXT_RECORDED_ALLOCATED >> 30))
                                mark_inode_dirty(inode);
@@ -69,23 +68,24 @@ static void extent_trunc(struct inode *inode, struct extent_position *epos,
 void udf_truncate_tail_extent(struct inode *inode)
 {
        struct extent_position epos = {};
-       kernel_lb_addr eloc;
+       struct kernel_lb_addr eloc;
        uint32_t elen, nelen;
        uint64_t lbcount = 0;
        int8_t etype = -1, netype;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
-           inode->i_size == UDF_I_LENEXTENTS(inode))
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ||
+           inode->i_size == iinfo->i_lenExtents)
                return;
        /* Are we going to delete the file anyway? */
        if (inode->i_nlink == 0)
                return;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
-               adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
-               adsize = sizeof(long_ad);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
+               adsize = sizeof(struct short_ad);
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
+               adsize = sizeof(struct long_ad);
        else
                BUG();
 
@@ -106,7 +106,7 @@ void udf_truncate_tail_extent(struct inode *inode)
                                       (unsigned)elen);
                        nelen = elen - (lbcount - inode->i_size);
                        epos.offset -= adsize;
-                       extent_trunc(inode, &epos, eloc, etype, elen, nelen);
+                       extent_trunc(inode, &epos, &eloc, etype, elen, nelen);
                        epos.offset += adsize;
                        if (udf_next_aext(inode, &epos, &eloc, &elen, 1) != -1)
                                printk(KERN_ERR "udf_truncate_tail_extent(): "
@@ -117,31 +117,32 @@ void udf_truncate_tail_extent(struct inode *inode)
        }
        /* This inode entry is in-memory only and thus we don't have to mark
         * the inode dirty */
-       UDF_I_LENEXTENTS(inode) = inode->i_size;
+       iinfo->i_lenExtents = inode->i_size;
        brelse(epos.bh);
 }
 
 void udf_discard_prealloc(struct inode *inode)
 {
        struct extent_position epos = { NULL, 0, {0, 0} };
-       kernel_lb_addr eloc;
+       struct kernel_lb_addr eloc;
        uint32_t elen;
        uint64_t lbcount = 0;
        int8_t etype = -1, netype;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
-           inode->i_size == UDF_I_LENEXTENTS(inode))
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ||
+           inode->i_size == iinfo->i_lenExtents)
                return;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
-               adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
-               adsize = sizeof(long_ad);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
+               adsize = sizeof(struct short_ad);
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
+               adsize = sizeof(struct long_ad);
        else
                adsize = 0;
 
-       epos.block = UDF_I_LOCATION(inode);
+       epos.block = iinfo->i_location;
 
        /* Find the last extent in the file */
        while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
@@ -151,9 +152,9 @@ void udf_discard_prealloc(struct inode *inode)
        if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
                epos.offset -= adsize;
                lbcount -= elen;
-               extent_trunc(inode, &epos, eloc, etype, elen, 0);
+               extent_trunc(inode, &epos, &eloc, etype, elen, 0);
                if (!epos.bh) {
-                       UDF_I_LENALLOC(inode) =
+                       iinfo->i_lenAlloc =
                                epos.offset -
                                udf_file_entry_alloc_offset(inode);
                        mark_inode_dirty(inode);
@@ -174,26 +175,44 @@ void udf_discard_prealloc(struct inode *inode)
        }
        /* This inode entry is in-memory only and thus we don't have to mark
         * the inode dirty */
-       UDF_I_LENEXTENTS(inode) = lbcount;
+       iinfo->i_lenExtents = lbcount;
        brelse(epos.bh);
 }
 
+static void udf_update_alloc_ext_desc(struct inode *inode,
+                                     struct extent_position *epos,
+                                     u32 lenalloc)
+{
+       struct super_block *sb = inode->i_sb;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+
+       struct allocExtDesc *aed = (struct allocExtDesc *) (epos->bh->b_data);
+       int len = sizeof(struct allocExtDesc);
+
+       aed->lengthAllocDescs = cpu_to_le32(lenalloc);
+       if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || sbi->s_udfrev >= 0x0201)
+               len += lenalloc;
+
+       udf_update_tag(epos->bh->b_data, len);
+       mark_buffer_dirty_inode(epos->bh, inode);
+}
+
 void udf_truncate_extents(struct inode *inode)
 {
        struct extent_position epos;
-       kernel_lb_addr eloc, neloc = {};
+       struct kernel_lb_addr eloc, neloc = {};
        uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc;
        int8_t etype;
        struct super_block *sb = inode->i_sb;
-       struct udf_sb_info *sbi = UDF_SB(sb);
        sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset;
        loff_t byte_offset;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
-               adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
-               adsize = sizeof(long_ad);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
+               adsize = sizeof(struct short_ad);
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
+               adsize = sizeof(struct long_ad);
        else
                BUG();
 
@@ -202,7 +221,7 @@ void udf_truncate_extents(struct inode *inode)
                (inode->i_size & (sb->s_blocksize - 1));
        if (etype != -1) {
                epos.offset -= adsize;
-               extent_trunc(inode, &epos, eloc, etype, elen, byte_offset);
+               extent_trunc(inode, &epos, &eloc, etype, elen, byte_offset);
                epos.offset += adsize;
                if (byte_offset)
                        lenalloc = epos.offset;
@@ -217,44 +236,24 @@ void udf_truncate_extents(struct inode *inode)
                while ((etype = udf_current_aext(inode, &epos, &eloc,
                                                 &elen, 0)) != -1) {
                        if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
-                               udf_write_aext(inode, &epos, neloc, nelen, 0);
+                               udf_write_aext(inode, &epos, &neloc, nelen, 0);
                                if (indirect_ext_len) {
                                        /* We managed to free all extents in the
                                         * indirect extent - free it too */
-                                       if (!epos.bh)
-                                               BUG();
-                                       udf_free_blocks(sb, inode, epos.block,
+                                       BUG_ON(!epos.bh);
+                                       udf_free_blocks(sb, inode, &epos.block,
                                                        0, indirect_ext_len);
-                               } else {
-                                       if (!epos.bh) {
-                                               UDF_I_LENALLOC(inode) =
-                                                               lenalloc;
-                                               mark_inode_dirty(inode);
-                                       } else {
-                                               struct allocExtDesc *aed =
-                                                       (struct allocExtDesc *)
-                                                       (epos.bh->b_data);
-                                               int len =
-                                                   sizeof(struct allocExtDesc);
-
-                                               aed->lengthAllocDescs =
-                                                   cpu_to_le32(lenalloc);
-                                               if (!UDF_QUERY_FLAG(sb,
-                                                       UDF_FLAG_STRICT) ||
-                                                   sbi->s_udfrev >= 0x0201)
-                                                       len += lenalloc;
-
-                                               udf_update_tag(epos.bh->b_data,
-                                                               len);
-                                               mark_buffer_dirty_inode(
-                                                               epos.bh, inode);
-                                       }
-                               }
+                               } else if (!epos.bh) {
+                                       iinfo->i_lenAlloc = lenalloc;
+                                       mark_inode_dirty(inode);
+                               } else
+                                       udf_update_alloc_ext_desc(inode,
+                                                       &epos, lenalloc);
                                brelse(epos.bh);
                                epos.offset = sizeof(struct allocExtDesc);
                                epos.block = eloc;
                                epos.bh = udf_tread(sb,
-                                               udf_get_lb_pblock(sb, eloc, 0));
+                                               udf_get_lb_pblock(sb, &eloc, 0));
                                if (elen)
                                        indirect_ext_len =
                                                (elen + sb->s_blocksize - 1) >>
@@ -262,39 +261,24 @@ void udf_truncate_extents(struct inode *inode)
                                else
                                        indirect_ext_len = 1;
                        } else {
-                               extent_trunc(inode, &epos, eloc, etype,
+                               extent_trunc(inode, &epos, &eloc, etype,
                                             elen, 0);
                                epos.offset += adsize;
                        }
                }
 
                if (indirect_ext_len) {
-                       if (!epos.bh)
-                               BUG();
-                       udf_free_blocks(sb, inode, epos.block, 0,
+                       BUG_ON(!epos.bh);
+                       udf_free_blocks(sb, inode, &epos.block, 0,
                                        indirect_ext_len);
-               } else {
-                       if (!epos.bh) {
-                               UDF_I_LENALLOC(inode) = lenalloc;
-                               mark_inode_dirty(inode);
-                       } else {
-                               struct allocExtDesc *aed =
-                                   (struct allocExtDesc *)(epos.bh->b_data);
-                               aed->lengthAllocDescs = cpu_to_le32(lenalloc);
-                               if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
-                                   sbi->s_udfrev >= 0x0201)
-                                       udf_update_tag(epos.bh->b_data,
-                                               lenalloc +
-                                               sizeof(struct allocExtDesc));
-                               else
-                                       udf_update_tag(epos.bh->b_data,
-                                               sizeof(struct allocExtDesc));
-                               mark_buffer_dirty_inode(epos.bh, inode);
-                       }
-               }
+               } else if (!epos.bh) {
+                       iinfo->i_lenAlloc = lenalloc;
+                       mark_inode_dirty(inode);
+               } else
+                       udf_update_alloc_ext_desc(inode, &epos, lenalloc);
        } else if (inode->i_size) {
                if (byte_offset) {
-                       kernel_long_ad extent;
+                       struct kernel_long_ad extent;
 
                        /*
                         *  OK, there is not extent covering inode->i_size and
@@ -325,7 +309,7 @@ void udf_truncate_extents(struct inode *inode)
                                                (sb->s_blocksize - 1)) != 0));
                }
        }
-       UDF_I_LENEXTENTS(inode) = inode->i_size;
+       iinfo->i_lenExtents = inode->i_size;
 
        brelse(epos.bh);
 }