]> err.no Git - linux-2.6/blobdiff - fs/ext4/dir.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[linux-2.6] / fs / ext4 / dir.c
index d0b54f30b914e5304f367252e5f6a3bd96ac8d38..f612bef983158f4a82c3d2a4b1211a94e713019a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  linux/fs/ext3/dir.c
+ *  linux/fs/ext4/dir.c
  *
  * Copyright (C) 1992, 1993, 1994, 1995
  * Remy Card (card@masi.ibp.fr)
@@ -12,7 +12,7 @@
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *
- *  ext3 directory handling functions
+ *  ext4 directory handling functions
  *
  *  Big-endian to little-endian byte-swapping/bitmaps by
  *        David S. Miller (davem@caip.rutgers.edu), 1995
  */
 
 #include <linux/fs.h>
-#include <linux/jbd.h>
-#include <linux/ext3_fs.h>
+#include <linux/jbd2.h>
+#include <linux/ext4_fs.h>
 #include <linux/buffer_head.h>
-#include <linux/smp_lock.h>
 #include <linux/slab.h>
 #include <linux/rbtree.h>
 
-static unsigned char ext3_filetype_table[] = {
+static unsigned char ext4_filetype_table[] = {
        DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
 };
 
-static int ext3_readdir(struct file *, void *, filldir_t);
-static int ext3_dx_readdir(struct file * filp,
+static int ext4_readdir(struct file *, void *, filldir_t);
+static int ext4_dx_readdir(struct file * filp,
                           void * dirent, filldir_t filldir);
-static int ext3_release_dir (struct inode * inode,
+static int ext4_release_dir (struct inode * inode,
                                struct file * filp);
 
-const struct file_operations ext3_dir_operations = {
+const struct file_operations ext4_dir_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_read_dir,
-       .readdir        = ext3_readdir,         /* we take BKL. needed?*/
-       .ioctl          = ext3_ioctl,           /* BKL held */
+       .readdir        = ext4_readdir,         /* we take BKL. needed?*/
+       .ioctl          = ext4_ioctl,           /* BKL held */
 #ifdef CONFIG_COMPAT
-       .compat_ioctl   = ext3_compat_ioctl,
-#endif
-       .fsync          = ext3_sync_file,       /* BKL held */
-#ifdef CONFIG_EXT3_INDEX
-       .release        = ext3_release_dir,
+       .compat_ioctl   = ext4_compat_ioctl,
 #endif
+       .fsync          = ext4_sync_file,       /* BKL held */
+       .release        = ext4_release_dir,
 };
 
 
 static unsigned char get_dtype(struct super_block *sb, int filetype)
 {
-       if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE) ||
-           (filetype >= EXT3_FT_MAX))
+       if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
+           (filetype >= EXT4_FT_MAX))
                return DT_UNKNOWN;
 
-       return (ext3_filetype_table[filetype]);
+       return (ext4_filetype_table[filetype]);
 }
 
 
-int ext3_check_dir_entry (const char * function, struct inode * dir,
-                         struct ext3_dir_entry_2 * de,
+int ext4_check_dir_entry (const char * function, struct inode * dir,
+                         struct ext4_dir_entry_2 * de,
                          struct buffer_head * bh,
                          unsigned long offset)
 {
        const char * error_msg = NULL;
        const int rlen = le16_to_cpu(de->rec_len);
 
-       if (rlen < EXT3_DIR_REC_LEN(1))
+       if (rlen < EXT4_DIR_REC_LEN(1))
                error_msg = "rec_len is smaller than minimal";
        else if (rlen % 4 != 0)
                error_msg = "rec_len % 4 != 0";
-       else if (rlen < EXT3_DIR_REC_LEN(de->name_len))
+       else if (rlen < EXT4_DIR_REC_LEN(de->name_len))
                error_msg = "rec_len is too small for name_len";
        else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
                error_msg = "directory entry across blocks";
        else if (le32_to_cpu(de->inode) >
-                       le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
+                       le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))
                error_msg = "inode out of bounds";
 
        if (error_msg != NULL)
-               ext3_error (dir->i_sb, function,
+               ext4_error (dir->i_sb, function,
                        "bad entry in directory #%lu: %s - "
                        "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
                        dir->i_ino, error_msg, offset,
@@ -94,26 +91,25 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
        return error_msg == NULL ? 1 : 0;
 }
 
-static int ext3_readdir(struct file * filp,
+static int ext4_readdir(struct file * filp,
                         void * dirent, filldir_t filldir)
 {
        int error = 0;
        unsigned long offset;
        int i, stored;
-       struct ext3_dir_entry_2 *de;
+       struct ext4_dir_entry_2 *de;
        struct super_block *sb;
        int err;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        int ret = 0;
 
        sb = inode->i_sb;
 
-#ifdef CONFIG_EXT3_INDEX
-       if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb,
-                                   EXT3_FEATURE_COMPAT_DIR_INDEX) &&
-           ((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) ||
+       if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
+                                   EXT4_FEATURE_COMPAT_DIR_INDEX) &&
+           ((EXT4_I(inode)->i_flags & EXT4_INDEX_FL) ||
             ((inode->i_size >> sb->s_blocksize_bits) == 1))) {
-               err = ext3_dx_readdir(filp, dirent, filldir);
+               err = ext4_dx_readdir(filp, dirent, filldir);
                if (err != ERR_BAD_DX_DIR) {
                        ret = err;
                        goto out;
@@ -122,28 +118,28 @@ static int ext3_readdir(struct file * filp,
                 * We don't set the inode dirty flag since it's not
                 * critical that it get flushed back to the disk.
                 */
-               EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL;
+               EXT4_I(filp->f_path.dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL;
        }
-#endif
        stored = 0;
        offset = filp->f_pos & (sb->s_blocksize - 1);
 
        while (!error && !stored && filp->f_pos < inode->i_size) {
-               unsigned long blk = filp->f_pos >> EXT3_BLOCK_SIZE_BITS(sb);
+               unsigned long blk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
                struct buffer_head map_bh;
                struct buffer_head *bh = NULL;
 
                map_bh.b_state = 0;
-               err = ext3_get_blocks_handle(NULL, inode, blk, 1,
-                                               &map_bh, 0, 0);
+               err = ext4_get_blocks_wrap(NULL, inode, blk, 1, &map_bh, 0, 0);
                if (err > 0) {
-                       page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
-                               &filp->f_ra,
-                               filp,
-                               map_bh.b_blocknr >>
-                                       (PAGE_CACHE_SHIFT - inode->i_blkbits),
-                               1);
-                       bh = ext3_bread(NULL, inode, blk, 0, &err);
+                       pgoff_t index = map_bh.b_blocknr >>
+                                       (PAGE_CACHE_SHIFT - inode->i_blkbits);
+                       if (!ra_has_index(&filp->f_ra, index))
+                               page_cache_sync_readahead(
+                                       sb->s_bdev->bd_inode->i_mapping,
+                                       &filp->f_ra, filp,
+                                       index, 1);
+                       filp->f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
+                       bh = ext4_bread(NULL, inode, blk, 0, &err);
                }
 
                /*
@@ -151,9 +147,12 @@ static int ext3_readdir(struct file * filp,
                 * of recovering data when there's a bad sector
                 */
                if (!bh) {
-                       ext3_error (sb, "ext3_readdir",
+                       ext4_error (sb, "ext4_readdir",
                                "directory #%lu contains a hole at offset %lu",
                                inode->i_ino, (unsigned long)filp->f_pos);
+                       /* corrupt size?  Maybe no more blocks to read */
+                       if (filp->f_pos > inode->i_blocks << 9)
+                               break;
                        filp->f_pos += sb->s_blocksize - offset;
                        continue;
                }
@@ -165,7 +164,7 @@ revalidate:
                 * to make sure. */
                if (filp->f_version != inode->i_version) {
                        for (i = 0; i < sb->s_blocksize && i < offset; ) {
-                               de = (struct ext3_dir_entry_2 *)
+                               de = (struct ext4_dir_entry_2 *)
                                        (bh->b_data + i);
                                /* It's too expensive to do a full
                                 * dirent test each time round this
@@ -174,7 +173,7 @@ revalidate:
                                 * failure will be detected in the
                                 * dirent test below. */
                                if (le16_to_cpu(de->rec_len) <
-                                               EXT3_DIR_REC_LEN(1))
+                                               EXT4_DIR_REC_LEN(1))
                                        break;
                                i += le16_to_cpu(de->rec_len);
                        }
@@ -186,11 +185,12 @@ revalidate:
 
                while (!error && filp->f_pos < inode->i_size
                       && offset < sb->s_blocksize) {
-                       de = (struct ext3_dir_entry_2 *) (bh->b_data + offset);
-                       if (!ext3_check_dir_entry ("ext3_readdir", inode, de,
+                       de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
+                       if (!ext4_check_dir_entry ("ext4_readdir", inode, de,
                                                   bh, offset)) {
-                               /* On error, skip the f_pos to the
-                                   next block. */
+                               /*
+                                * On error, skip the f_pos to the next block
+                                */
                                filp->f_pos = (filp->f_pos |
                                                (sb->s_blocksize - 1)) + 1;
                                brelse (bh);
@@ -206,7 +206,7 @@ revalidate:
                                 * not the directory has been modified
                                 * during the copy operation.
                                 */
-                               unsigned long version = filp->f_version;
+                               u64 version = filp->f_version;
 
                                error = filldir(dirent, de->name,
                                                de->name_len,
@@ -228,7 +228,6 @@ out:
        return ret;
 }
 
-#ifdef CONFIG_EXT3_INDEX
 /*
  * These functions convert from the major/minor hash to an f_pos
  * value.
@@ -323,7 +322,7 @@ static struct dir_private_info *create_dir_info(loff_t pos)
        return p;
 }
 
-void ext3_htree_free_dir_info(struct dir_private_info *p)
+void ext4_htree_free_dir_info(struct dir_private_info *p)
 {
        free_rb_tree_fname(&p->root);
        kfree(p);
@@ -332,9 +331,9 @@ void ext3_htree_free_dir_info(struct dir_private_info *p)
 /*
  * Given a directory entry, enter it into the fname rb tree.
  */
-int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
+int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
                             __u32 minor_hash,
-                            struct ext3_dir_entry_2 *dirent)
+                            struct ext4_dir_entry_2 *dirent)
 {
        struct rb_node **p, *parent = NULL;
        struct fname * fname, *new_fn;
@@ -390,7 +389,7 @@ int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 
 
 /*
- * This is a helper function for ext3_dx_readdir.  It calls filldir
+ * This is a helper function for ext4_dx_readdir.  It calls filldir
  * for all entres on the fname linked list.  (Normally there is only
  * one entry on the linked list, unless there are 62 bit hash collisions.)
  */
@@ -399,7 +398,7 @@ static int call_filldir(struct file * filp, void * dirent,
 {
        struct dir_private_info *info = filp->private_data;
        loff_t  curr_pos;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct super_block * sb;
        int error;
 
@@ -425,11 +424,11 @@ static int call_filldir(struct file * filp, void * dirent,
        return 0;
 }
 
-static int ext3_dx_readdir(struct file * filp,
+static int ext4_dx_readdir(struct file * filp,
                         void * dirent, filldir_t filldir)
 {
        struct dir_private_info *info = filp->private_data;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct fname *fname;
        int     ret;
 
@@ -440,7 +439,7 @@ static int ext3_dx_readdir(struct file * filp,
                filp->private_data = info;
        }
 
-       if (filp->f_pos == EXT3_HTREE_EOF)
+       if (filp->f_pos == EXT4_HTREE_EOF)
                return 0;       /* EOF */
 
        /* Some one has messed with f_pos; reset the world */
@@ -474,13 +473,13 @@ static int ext3_dx_readdir(struct file * filp,
                        info->curr_node = NULL;
                        free_rb_tree_fname(&info->root);
                        filp->f_version = inode->i_version;
-                       ret = ext3_htree_fill_tree(filp, info->curr_hash,
+                       ret = ext4_htree_fill_tree(filp, info->curr_hash,
                                                   info->curr_minor_hash,
                                                   &info->next_hash);
                        if (ret < 0)
                                return ret;
                        if (ret == 0) {
-                               filp->f_pos = EXT3_HTREE_EOF;
+                               filp->f_pos = EXT4_HTREE_EOF;
                                break;
                        }
                        info->curr_node = rb_first(&info->root);
@@ -495,7 +494,7 @@ static int ext3_dx_readdir(struct file * filp,
                info->curr_node = rb_next(info->curr_node);
                if (!info->curr_node) {
                        if (info->next_hash == ~0) {
-                               filp->f_pos = EXT3_HTREE_EOF;
+                               filp->f_pos = EXT4_HTREE_EOF;
                                break;
                        }
                        info->curr_hash = info->next_hash;
@@ -507,12 +506,10 @@ finished:
        return 0;
 }
 
-static int ext3_release_dir (struct inode * inode, struct file * filp)
+static int ext4_release_dir (struct inode * inode, struct file * filp)
 {
-       if (filp->private_data)
-               ext3_htree_free_dir_info(filp->private_data);
+       if (filp->private_data)
+               ext4_htree_free_dir_info(filp->private_data);
 
        return 0;
 }
-
-#endif