push BKL down into ->put_super
[safe/jmp/linux-2.6] / fs / hfsplus / dir.c
index 82c2237..5f40236 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <linux/errno.h>
 #include <linux/fs.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/random.h>
 
@@ -37,6 +36,8 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
        u16 type;
 
        sb = dir->i_sb;
+
+       dentry->d_op = &hfsplus_dentry_operations;
        dentry->d_fsdata = NULL;
        hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
        hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, &dentry->d_name);
@@ -66,21 +67,28 @@ again:
                }
                cnid = be32_to_cpu(entry.file.id);
                if (entry.file.user_info.fdType == cpu_to_be32(HFSP_HARDLINK_TYPE) &&
-                   entry.file.user_info.fdCreator == cpu_to_be32(HFSP_HFSPLUS_CREATOR)) {
+                   entry.file.user_info.fdCreator == cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
+                   (entry.file.create_date == HFSPLUS_I(HFSPLUS_SB(sb).hidden_dir).create_date ||
+                    entry.file.create_date == HFSPLUS_I(sb->s_root->d_inode).create_date) &&
+                   HFSPLUS_SB(sb).hidden_dir) {
                        struct qstr str;
                        char name[32];
 
                        if (dentry->d_fsdata) {
-                               err = -ENOENT;
-                               inode = NULL;
-                               goto out;
+                               /*
+                                * We found a link pointing to another link,
+                                * so ignore it and treat it as regular file.
+                                */
+                               cnid = (unsigned long)dentry->d_fsdata;
+                               linkid = 0;
+                       } else {
+                               dentry->d_fsdata = (void *)(unsigned long)cnid;
+                               linkid = be32_to_cpu(entry.file.permissions.dev);
+                               str.len = sprintf(name, "iNode%d", linkid);
+                               str.name = name;
+                               hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_SB(sb).hidden_dir->i_ino, &str);
+                               goto again;
                        }
-                       dentry->d_fsdata = (void *)(unsigned long)cnid;
-                       linkid = be32_to_cpu(entry.file.permissions.dev);
-                       str.len = sprintf(name, "iNode%d", linkid);
-                       str.name = name;
-                       hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_SB(sb).hidden_dir->i_ino, &str);
-                       goto again;
                } else if (!dentry->d_fsdata)
                        dentry->d_fsdata = (void *)(unsigned long)cnid;
        } else {
@@ -89,9 +97,9 @@ again:
                goto fail;
        }
        hfs_find_exit(&fd);
-       inode = iget(dir->i_sb, cnid);
-       if (!inode)
-               return ERR_PTR(-EACCES);
+       inode = hfsplus_iget(dir->i_sb, cnid);
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
        if (S_ISREG(inode->i_mode))
                HFSPLUS_I(inode).dev = linkid;
 out:
@@ -104,7 +112,7 @@ fail:
 
 static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct super_block *sb = inode->i_sb;
        int len, err;
        char strbuf[HFSPLUS_MAX_STRLEN + 1];
@@ -291,7 +299,7 @@ static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir,
        if (res)
                return res;
 
-       inode->i_nlink++;
+       inc_nlink(inode);
        hfsplus_instantiate(dst_dentry, inode, cnid);
        atomic_inc(&inode->i_count);
        inode->i_ctime = CURRENT_TIME_SEC;
@@ -330,16 +338,25 @@ static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
        if (res)
                return res;
 
-       inode->i_nlink--;
-       hfsplus_delete_inode(inode);
-       if (inode->i_ino != cnid && !inode->i_nlink) {
-               if (!atomic_read(&HFSPLUS_I(inode).opencnt)) {
-                       res = hfsplus_delete_cat(inode->i_ino, HFSPLUS_SB(sb).hidden_dir, NULL);
-                       if (!res)
-                               hfsplus_delete_inode(inode);
+       if (inode->i_nlink > 0)
+               drop_nlink(inode);
+       if (inode->i_ino == cnid)
+               clear_nlink(inode);
+       if (!inode->i_nlink) {
+               if (inode->i_ino != cnid) {
+                       HFSPLUS_SB(sb).file_count--;
+                       if (!atomic_read(&HFSPLUS_I(inode).opencnt)) {
+                               res = hfsplus_delete_cat(inode->i_ino,
+                                                        HFSPLUS_SB(sb).hidden_dir,
+                                                        NULL);
+                               if (!res)
+                                       hfsplus_delete_inode(inode);
+                       } else
+                               inode->i_flags |= S_DEAD;
                } else
-                       inode->i_flags |= S_DEAD;
-       }
+                       hfsplus_delete_inode(inode);
+       } else
+               HFSPLUS_SB(sb).file_count--;
        inode->i_ctime = CURRENT_TIME_SEC;
        mark_inode_dirty(inode);
 
@@ -378,7 +395,7 @@ static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)
        res = hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
        if (res)
                return res;
-       inode->i_nlink = 0;
+       clear_nlink(inode);
        inode->i_ctime = CURRENT_TIME_SEC;
        hfsplus_delete_inode(inode);
        mark_inode_dirty(inode);
@@ -462,7 +479,7 @@ static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry,
        return res;
 }
 
-struct inode_operations hfsplus_dir_inode_operations = {
+const struct inode_operations hfsplus_dir_inode_operations = {
        .lookup         = hfsplus_lookup,
        .create         = hfsplus_create,
        .link           = hfsplus_link,
@@ -474,7 +491,7 @@ struct inode_operations hfsplus_dir_inode_operations = {
        .rename         = hfsplus_rename,
 };
 
-struct file_operations hfsplus_dir_operations = {
+const struct file_operations hfsplus_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = hfsplus_readdir,
        .ioctl          = hfsplus_ioctl,