]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - fs/ntfs/dir.c
net: wireless: sd8797: change wlan interface to wlan0
[linux-2.6.git] / fs / ntfs / dir.c
index 795c3d1930f5f38a265bc530a2e1dd8733341915..99e36107ff604c2164fa7f154b91629f9bf826e3 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * dir.c - NTFS kernel directory operations. Part of the Linux-NTFS project.
  *
- * Copyright (c) 2001-2005 Anton Altaparmakov
+ * Copyright (c) 2001-2007 Anton Altaparmakov
  * Copyright (c) 2002 Richard Russon
  *
  * This program/include file is free software; you can redistribute it and/or
@@ -20,8 +20,8 @@
  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
+#include <linux/slab.h>
 
 #include "dir.h"
 #include "aops.h"
@@ -33,8 +33,8 @@
 /**
  * The little endian Unicode string $I30 as a global constant.
  */
-ntfschar I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
-               const_cpu_to_le16('3'), const_cpu_to_le16('0'), 0 };
+ntfschar I30[5] = { cpu_to_le16('$'), cpu_to_le16('I'),
+               cpu_to_le16('3'),       cpu_to_le16('0'), 0 };
 
 /**
  * ntfs_lookup_inode_by_name - find an inode in a directory given its name
@@ -69,7 +69,7 @@ ntfschar I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
  * work but we don't care for how quickly one can access them. This also fixes
  * the dcache aliasing issues.
  *
- * Locking:  - Caller must hold i_sem on the directory.
+ * Locking:  - Caller must hold i_mutex on the directory.
  *          - Each page cache page in the index allocation mapping must be
  *            locked whilst being accessed otherwise we may find a corrupt
  *            page due to it being under ->writepage at the moment which
@@ -1085,11 +1085,11 @@ static inline int ntfs_filldir(ntfs_volume *vol, loff_t fpos,
  * While this will return the names in random order this doesn't matter for
  * ->readdir but OTOH results in a faster ->readdir.
  *
- * VFS calls ->readdir without BKL but with i_sem held. This protects the VFS
+ * VFS calls ->readdir without BKL but with i_mutex held. This protects the VFS
  * parts (e.g. ->f_pos and ->i_size, and it also protects against directory
  * modifications).
  *
- * Locking:  - Caller must hold i_sem on the directory.
+ * Locking:  - Caller must hold i_mutex on the directory.
  *          - Each page cache page in the index allocation mapping must be
  *            locked whilst being accessed otherwise we may find a corrupt
  *            page due to it being under ->writepage at the moment which
@@ -1101,7 +1101,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
 {
        s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
        loff_t fpos, i_size;
-       struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode;
+       struct inode *bmp_vi, *vdir = filp->f_path.dentry->d_inode;
        struct super_block *sb = vdir->i_sb;
        ntfs_inode *ndir = NTFS_I(vdir);
        ntfs_volume *vol = NTFS_SB(sb);
@@ -1136,9 +1136,9 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        if (fpos == 1) {
                ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, "
                                "inode 0x%lx, DT_DIR.",
-                               parent_ino(filp->f_dentry));
+                               (unsigned long)parent_ino(filp->f_path.dentry));
                rc = filldir(dirent, "..", 2, fpos,
-                               parent_ino(filp->f_dentry), DT_DIR);
+                               parent_ino(filp->f_path.dentry), DT_DIR);
                if (rc)
                        goto done;
                fpos++;
@@ -1149,8 +1149,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
         * Allocate a buffer to store the current name being processed
         * converted to format determined by current NLS.
         */
-       name = (u8*)kmalloc(NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1,
-                       GFP_NOFS);
+       name = kmalloc(NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1, GFP_NOFS);
        if (unlikely(!name)) {
                err = -ENOMEM;
                goto err_out;
@@ -1191,7 +1190,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
         * map the mft record without deadlocking.
         */
        rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-       ir = (INDEX_ROOT*)kmalloc(rc, GFP_NOFS);
+       ir = kmalloc(rc, GFP_NOFS);
        if (unlikely(!ir)) {
                err = -ENOMEM;
                goto err_out;
@@ -1250,16 +1249,12 @@ skip_index_root:
        /* Get the offset into the index allocation attribute. */
        ia_pos = (s64)fpos - vol->mft_record_size;
        ia_mapping = vdir->i_mapping;
-       bmp_vi = ndir->itype.index.bmp_ino;
-       if (unlikely(!bmp_vi)) {
-               ntfs_debug("Inode 0x%lx, regetting index bitmap.", vdir->i_ino);
-               bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4);
-               if (IS_ERR(bmp_vi)) {
-                       ntfs_error(sb, "Failed to get bitmap attribute.");
-                       err = PTR_ERR(bmp_vi);
-                       goto err_out;
-               }
-               ndir->itype.index.bmp_ino = bmp_vi;
+       ntfs_debug("Inode 0x%lx, getting index bitmap.", vdir->i_ino);
+       bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4);
+       if (IS_ERR(bmp_vi)) {
+               ntfs_error(sb, "Failed to get bitmap attribute.");
+               err = PTR_ERR(bmp_vi);
+               goto err_out;
        }
        bmp_mapping = bmp_vi->i_mapping;
        /* Get the starting bitmap bit position and sanity check it. */
@@ -1267,7 +1262,7 @@ skip_index_root:
        if (unlikely(bmp_pos >> 3 >= i_size_read(bmp_vi))) {
                ntfs_error(sb, "Current index allocation position exceeds "
                                "index bitmap size.");
-               goto err_out;
+               goto iput_err_out;
        }
        /* Get the starting bit position in the current bitmap page. */
        cur_bmp_pos = bmp_pos & ((PAGE_CACHE_SIZE * 8) - 1);
@@ -1283,7 +1278,7 @@ get_next_bmp_page:
                ntfs_error(sb, "Reading index bitmap failed.");
                err = PTR_ERR(bmp_page);
                bmp_page = NULL;
-               goto err_out;
+               goto iput_err_out;
        }
        bmp = (u8*)page_address(bmp_page);
        /* Find next index block in use. */
@@ -1430,6 +1425,7 @@ find_next_index_buffer:
                        /* @ia_page is already unlocked in this case. */
                        ntfs_unmap_page(ia_page);
                        ntfs_unmap_page(bmp_page);
+                       iput(bmp_vi);
                        goto abort;
                }
        }
@@ -1440,6 +1436,7 @@ unm_EOD:
                ntfs_unmap_page(ia_page);
        }
        ntfs_unmap_page(bmp_page);
+       iput(bmp_vi);
 EOD:
        /* We are finished, set fpos to EOD. */
        fpos = i_size + vol->mft_record_size;
@@ -1456,8 +1453,11 @@ done:
        filp->f_pos = fpos;
        return 0;
 err_out:
-       if (bmp_page)
+       if (bmp_page) {
                ntfs_unmap_page(bmp_page);
+iput_err_out:
+               iput(bmp_vi);
+       }
        if (ia_page) {
                unlock_page(ia_page);
                ntfs_unmap_page(ia_page);
@@ -1520,25 +1520,39 @@ static int ntfs_dir_open(struct inode *vi, struct file *filp)
  * Note: In the past @filp could be NULL so we ignore it as we don't need it
  * anyway.
  *
- * Locking: Caller must hold i_sem on the inode.
+ * Locking: Caller must hold i_mutex on the inode.
  *
  * TODO: We should probably also write all attribute/index inodes associated
  * with this inode but since we have no simple way of getting to them we ignore
  * this problem for now.  We do write the $BITMAP attribute if it is present
  * which is the important one for a directory so things are not too bad.
  */
-static int ntfs_dir_fsync(struct file *filp, struct dentry *dentry,
-               int datasync)
+static int ntfs_dir_fsync(struct file *filp, loff_t start, loff_t end,
+                         int datasync)
 {
-       struct inode *vi = dentry->d_inode;
-       ntfs_inode *ni = NTFS_I(vi);
+       struct inode *bmp_vi, *vi = filp->f_mapping->host;
        int err, ret;
+       ntfs_attr na;
 
        ntfs_debug("Entering for inode 0x%lx.", vi->i_ino);
+
+       err = filemap_write_and_wait_range(vi->i_mapping, start, end);
+       if (err)
+               return err;
+       mutex_lock(&vi->i_mutex);
+
        BUG_ON(!S_ISDIR(vi->i_mode));
-       if (NInoIndexAllocPresent(ni) && ni->itype.index.bmp_ino)
-               write_inode_now(ni->itype.index.bmp_ino, !datasync);
-       ret = ntfs_write_inode(vi, 1);
+       /* If the bitmap attribute inode is in memory sync it, too. */
+       na.mft_no = vi->i_ino;
+       na.type = AT_BITMAP;
+       na.name = I30;
+       na.name_len = 4;
+       bmp_vi = ilookup5(vi->i_sb, vi->i_ino, (test_t)ntfs_test_inode, &na);
+       if (bmp_vi) {
+               write_inode_now(bmp_vi, !datasync);
+               iput(bmp_vi);
+       }
+       ret = __ntfs_write_inode(vi, 1);
        write_inode_now(vi, !datasync);
        err = sync_blockdev(vi->i_sb->s_bdev);
        if (unlikely(err && !ret))
@@ -1548,12 +1562,13 @@ static int ntfs_dir_fsync(struct file *filp, struct dentry *dentry,
        else
                ntfs_warning(vi->i_sb, "Failed to f%ssync inode 0x%lx.  Error "
                                "%u.", datasync ? "data" : "", vi->i_ino, -ret);
+       mutex_unlock(&vi->i_mutex);
        return ret;
 }
 
 #endif /* NTFS_RW */
 
-struct file_operations ntfs_dir_ops = {
+const struct file_operations ntfs_dir_ops = {
        .llseek         = generic_file_llseek,  /* Seek inside directory. */
        .read           = generic_read_dir,     /* Return -EISDIR. */
        .readdir        = ntfs_readdir,         /* Read directory contents. */