neigh: simplify seq_file code
[safe/jmp/linux-2.6] / fs / ntfs / namei.c
index 887c5e1..2ca0015 100644 (file)
@@ -174,7 +174,6 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
        // TODO: Consider moving this lot to a separate function! (AIA)
 handle_name:
    {
-       struct dentry *real_dent, *new_dent;
        MFT_RECORD *m;
        ntfs_attr_search_ctx *ctx;
        ntfs_inode *ni = NTFS_I(dent_inode);
@@ -255,93 +254,9 @@ handle_name:
        }
        nls_name.hash = full_name_hash(nls_name.name, nls_name.len);
 
-       /*
-        * Note: No need for dent->d_lock lock as i_mutex is held on the
-        * parent inode.
-        */
-
-       /* Does a dentry matching the nls_name exist already? */
-       real_dent = d_lookup(dent->d_parent, &nls_name);
-       /* If not, create it now. */
-       if (!real_dent) {
-               real_dent = d_alloc(dent->d_parent, &nls_name);
-               kfree(nls_name.name);
-               if (!real_dent) {
-                       err = -ENOMEM;
-                       goto err_out;
-               }
-               new_dent = d_splice_alias(dent_inode, real_dent);
-               if (new_dent)
-                       dput(real_dent);
-               else
-                       new_dent = real_dent;
-               ntfs_debug("Done.  (Created new dentry.)");
-               return new_dent;
-       }
+       dent = d_add_ci(dent, dent_inode, &nls_name);
        kfree(nls_name.name);
-       /* Matching dentry exists, check if it is negative. */
-       if (real_dent->d_inode) {
-               if (unlikely(real_dent->d_inode != dent_inode)) {
-                       /* This can happen because bad inodes are unhashed. */
-                       BUG_ON(!is_bad_inode(dent_inode));
-                       BUG_ON(!is_bad_inode(real_dent->d_inode));
-               }
-               /*
-                * Already have the inode and the dentry attached, decrement
-                * the reference count to balance the ntfs_iget() we did
-                * earlier on.  We found the dentry using d_lookup() so it
-                * cannot be disconnected and thus we do not need to worry
-                * about any NFS/disconnectedness issues here.
-                */
-               iput(dent_inode);
-               ntfs_debug("Done.  (Already had inode and dentry.)");
-               return real_dent;
-       }
-       /*
-        * Negative dentry: instantiate it unless the inode is a directory and
-        * has a 'disconnected' dentry (i.e. IS_ROOT and DCACHE_DISCONNECTED),
-        * in which case d_move() that in place of the found dentry.
-        */
-       if (!S_ISDIR(dent_inode->i_mode)) {
-               /* Not a directory; everything is easy. */
-               d_instantiate(real_dent, dent_inode);
-               ntfs_debug("Done.  (Already had negative file dentry.)");
-               return real_dent;
-       }
-       spin_lock(&dcache_lock);
-       if (list_empty(&dent_inode->i_dentry)) {
-               /*
-                * Directory without a 'disconnected' dentry; we need to do
-                * d_instantiate() by hand because it takes dcache_lock which
-                * we already hold.
-                */
-               list_add(&real_dent->d_alias, &dent_inode->i_dentry);
-               real_dent->d_inode = dent_inode;
-               spin_unlock(&dcache_lock);
-               security_d_instantiate(real_dent, dent_inode);
-               ntfs_debug("Done.  (Already had negative directory dentry.)");
-               return real_dent;
-       }
-       /*
-        * Directory with a 'disconnected' dentry; get a reference to the
-        * 'disconnected' dentry.
-        */
-       new_dent = list_entry(dent_inode->i_dentry.next, struct dentry,
-                       d_alias);
-       dget_locked(new_dent);
-       spin_unlock(&dcache_lock);
-       /* Do security vodoo. */
-       security_d_instantiate(real_dent, dent_inode);
-       /* Move new_dent in place of real_dent. */
-       d_move(new_dent, real_dent);
-       /* Balance the ntfs_iget() we did above. */
-       iput(dent_inode);
-       /* Throw away real_dent. */
-       dput(real_dent);
-       /* Use new_dent as the actual dentry. */
-       ntfs_debug("Done.  (Already had negative, disconnected directory "
-                       "dentry.)");
-       return new_dent;
+       return dent;
 
 eio_err_out:
        ntfs_error(vol->sb, "Illegal file name attribute. Run chkdsk.");
@@ -389,8 +304,6 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
        ntfs_attr_search_ctx *ctx;
        ATTR_RECORD *attr;
        FILE_NAME_ATTR *fn;
-       struct inode *parent_vi;
-       struct dentry *parent_dent;
        unsigned long parent_ino;
        int err;
 
@@ -430,24 +343,8 @@ try_next:
        /* Release the search context and the mft record of the child. */
        ntfs_attr_put_search_ctx(ctx);
        unmap_mft_record(ni);
-       /* Get the inode of the parent directory. */
-       parent_vi = ntfs_iget(vi->i_sb, parent_ino);
-       if (IS_ERR(parent_vi) || unlikely(is_bad_inode(parent_vi))) {
-               if (!IS_ERR(parent_vi))
-                       iput(parent_vi);
-               ntfs_error(vi->i_sb, "Failed to get parent directory inode "
-                               "0x%lx of child inode 0x%lx.", parent_ino,
-                               vi->i_ino);
-               return ERR_PTR(-EACCES);
-       }
-       /* Finally get a dentry for the parent directory and return it. */
-       parent_dent = d_alloc_anon(parent_vi);
-       if (unlikely(!parent_dent)) {
-               iput(parent_vi);
-               return ERR_PTR(-ENOMEM);
-       }
-       ntfs_debug("Done for inode 0x%lx.", vi->i_ino);
-       return parent_dent;
+
+       return d_obtain_alias(ntfs_iget(vi->i_sb, parent_ino));
 }
 
 static struct inode *ntfs_nfs_get_inode(struct super_block *sb,
@@ -499,7 +396,7 @@ static struct dentry *ntfs_fh_to_parent(struct super_block *sb, struct fid *fid,
  * allowing the inode number 0 which is used in NTFS for the system file $MFT
  * and due to using iget() whereas NTFS needs ntfs_iget().
  */
-struct export_operations ntfs_export_ops = {
+const struct export_operations ntfs_export_ops = {
        .get_parent     = ntfs_get_parent,      /* Find the parent of a given
                                                   directory. */
        .fh_to_dentry   = ntfs_fh_to_dentry,