and changed files
[powerpc.git] / fs / jfs / jfs_dtree.c
index 73b5fc7..6d62f32 100644 (file)
@@ -3,16 +3,16 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
@@ -78,7 +78,7 @@
  *
  * case-insensitive search:
  *
- *     fold search key;
+ *     fold search key;
  *
  *     case-insensitive search of B-tree:
  *     for internal entry, router key is already folded;
@@ -93,7 +93,7 @@
  *     else
  *             return no match;
  *
- *     serialization:
+ *     serialization:
  * target directory inode lock is being held on entry/exit
  * of all main directory service routines.
  *
@@ -381,9 +381,12 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
                 * It's time to move the inline table to an external
                 * page and begin to build the xtree
                 */
-               if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage) ||
-                   dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
-                       goto clean_up;  /* No space */
+               if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
+                       goto clean_up;
+               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
+                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
+                       goto clean_up;
+               }
 
                /*
                 * Save the table, we're going to overwrite it with the
@@ -397,13 +400,15 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
                xtInitRoot(tid, ip);
 
                /*
-                * Allocate the first block & add it to the xtree
+                * Add the first block to the xtree
                 */
                if (xtInsert(tid, ip, 0, 0, sbi->nbperpage, &xaddr, 0)) {
                        /* This really shouldn't fail */
                        jfs_warn("add_index: xtInsert failed!");
                        memcpy(&jfs_ip->i_dirtable, temp_table,
                               sizeof (temp_table));
+                       dbFree(ip, xaddr, sbi->nbperpage);
+                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
                        goto clean_up;
                }
                ip->i_size = PSIZE;
@@ -920,7 +925,7 @@ int dtInsert(tid_t tid, struct inode *ip,
  *
  * return: 0 - success;
  *        errno - failure;
- *     leaf page unpinned;
+ *     leaf page unpinned;
  */
 static int dtSplitUp(tid_t tid,
          struct inode *ip, struct dtsplit * split, struct btstack * btstack)
@@ -1000,6 +1005,9 @@ static int dtSplitUp(tid_t tid,
 
                DT_PUTPAGE(smp);
 
+               if (!DO_INDEX(ip))
+                       ip->i_size = xlen << sbi->l2bsize;
+
                goto freeKeyName;
        }
 
@@ -1050,7 +1058,9 @@ static int dtSplitUp(tid_t tid,
                                xaddr = addressPXD(pxd) + xlen;
                                dbFree(ip, xaddr, (s64) n);
                        }
-               }
+               } else if (!DO_INDEX(ip))
+                       ip->i_size = lengthPXD(pxd) << sbi->l2bsize;
+
 
              extendOut:
                DT_PUTPAGE(smp);
@@ -1093,6 +1103,9 @@ static int dtSplitUp(tid_t tid,
                goto splitOut;
        }
 
+       if (!DO_INDEX(ip))
+               ip->i_size += PSIZE;
+
        /*
         * propagate up the router entry for the leaf page just split
         *
@@ -2419,6 +2432,9 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
                break;
        }
 
+       if (!DO_INDEX(ip))
+               ip->i_size -= PSIZE;
+
        return 0;
 }
 
@@ -2993,7 +3009,7 @@ static inline struct jfs_dirent *next_jfs_dirent(struct jfs_dirent *dirent)
  */
 int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
 {
-       struct inode *ip = filp->f_dentry->d_inode;
+       struct inode *ip = filp->f_path.dentry->d_inode;
        struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab;
        int rc = 0;
        loff_t dtpos;   /* legacy OS/2 style position */
@@ -3751,7 +3767,7 @@ static int ciCompare(struct component_name * key, /* search key */
  *          across page boundary
  *
  * return: non-zero on error
- *     
+ *
  */
 static int ciGetLeafPrefixKey(dtpage_t * lp, int li, dtpage_t * rp,
                               int ri, struct component_name * key, int flag)
@@ -3761,16 +3777,16 @@ static int ciGetLeafPrefixKey(dtpage_t * lp, int li, dtpage_t * rp,
        struct component_name lkey;
        struct component_name rkey;
 
-       lkey.name = (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
+       lkey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
                                        GFP_KERNEL);
        if (lkey.name == NULL)
-               return -ENOSPC;
+               return -ENOMEM;
 
-       rkey.name = (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
+       rkey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
                                        GFP_KERNEL);
        if (rkey.name == NULL) {
                kfree(lkey.name);
-               return -ENOSPC;
+               return -ENOMEM;
        }
 
        /* get left and right key */