btrfs: use common file type conversion
[sfrench/cifs-2.6.git] / fs / btrfs / inode.c
index 82fdda8ff5ab82b5298c4b72859e697d8bd1a3d5..1d81a7a78a3ffca454c7cf8d6c728cfb1c96e163 100644 (file)
@@ -73,17 +73,6 @@ struct kmem_cache *btrfs_trans_handle_cachep;
 struct kmem_cache *btrfs_path_cachep;
 struct kmem_cache *btrfs_free_space_cachep;
 
-#define S_SHIFT 12
-static const unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
-       [S_IFREG >> S_SHIFT]    = BTRFS_FT_REG_FILE,
-       [S_IFDIR >> S_SHIFT]    = BTRFS_FT_DIR,
-       [S_IFCHR >> S_SHIFT]    = BTRFS_FT_CHRDEV,
-       [S_IFBLK >> S_SHIFT]    = BTRFS_FT_BLKDEV,
-       [S_IFIFO >> S_SHIFT]    = BTRFS_FT_FIFO,
-       [S_IFSOCK >> S_SHIFT]   = BTRFS_FT_SOCK,
-       [S_IFLNK >> S_SHIFT]    = BTRFS_FT_SYMLINK,
-};
-
 static int btrfs_setsize(struct inode *inode, struct iattr *attr);
 static int btrfs_truncate(struct inode *inode, bool skip_writeback);
 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
@@ -1451,7 +1440,7 @@ next_slot:
                        extent_end = ALIGN(extent_end,
                                           fs_info->sectorsize);
                } else {
-                       BUG_ON(1);
+                       BUG();
                }
 out_check:
                if (extent_end <= start) {
@@ -5797,10 +5786,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
        return d_splice_alias(inode, dentry);
 }
 
-unsigned char btrfs_filetype_table[] = {
-       DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
-};
-
 /*
  * All this infrastructure exists because dir_emit can fault, and we are holding
  * the tree lock when doing readdir.  For now just allocate a buffer and copy
@@ -5939,7 +5924,7 @@ again:
                name_ptr = (char *)(entry + 1);
                read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
                                   name_len);
-               put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)],
+               put_unaligned(fs_ftype_to_dtype(btrfs_dir_type(leaf, di)),
                                &entry->type);
                btrfs_dir_item_key_to_cpu(leaf, di, &location);
                put_unaligned(location.objectid, &entry->ino);
@@ -6344,7 +6329,20 @@ fail:
 
 static inline u8 btrfs_inode_type(struct inode *inode)
 {
-       return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
+       /*
+        * Compile-time asserts that generic FT_* types still match
+        * BTRFS_FT_* types
+        */
+       BUILD_BUG_ON(BTRFS_FT_UNKNOWN != FT_UNKNOWN);
+       BUILD_BUG_ON(BTRFS_FT_REG_FILE != FT_REG_FILE);
+       BUILD_BUG_ON(BTRFS_FT_DIR != FT_DIR);
+       BUILD_BUG_ON(BTRFS_FT_CHRDEV != FT_CHRDEV);
+       BUILD_BUG_ON(BTRFS_FT_BLKDEV != FT_BLKDEV);
+       BUILD_BUG_ON(BTRFS_FT_FIFO != FT_FIFO);
+       BUILD_BUG_ON(BTRFS_FT_SOCK != FT_SOCK);
+       BUILD_BUG_ON(BTRFS_FT_SYMLINK != FT_SYMLINK);
+
+       return fs_umode_to_ftype(inode->i_mode);
 }
 
 /*
@@ -9182,10 +9180,11 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
 
        inode = &ei->vfs_inode;
        extent_map_tree_init(&ei->extent_tree);
-       extent_io_tree_init(&ei->io_tree, inode);
-       extent_io_tree_init(&ei->io_failure_tree, inode);
-       ei->io_tree.track_uptodate = 1;
-       ei->io_failure_tree.track_uptodate = 1;
+       extent_io_tree_init(fs_info, &ei->io_tree, IO_TREE_INODE_IO, inode);
+       extent_io_tree_init(fs_info, &ei->io_failure_tree,
+                           IO_TREE_INODE_IO_FAILURE, inode);
+       ei->io_tree.track_uptodate = true;
+       ei->io_failure_tree.track_uptodate = true;
        atomic_set(&ei->sync_writers, 0);
        mutex_init(&ei->log_mutex);
        mutex_init(&ei->delalloc_mutex);
@@ -10193,7 +10192,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
 
        inode->i_op = &btrfs_symlink_inode_operations;
        inode_nohighmem(inode);
-       inode->i_mapping->a_ops = &btrfs_aops;
        inode_set_bytes(inode, name_len);
        btrfs_i_size_write(BTRFS_I(inode), name_len);
        err = btrfs_update_inode(trans, root, inode);