aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/filesystems/debugfs.txt2
-rw-r--r--Documentation/filesystems/porting6
-rw-r--r--Documentation/filesystems/qnx6.txt174
-rw-r--r--Documentation/ioctl/ioctl-number.txt1
-rw-r--r--arch/alpha/kernel/binfmt_loader.c3
-rw-r--r--arch/powerpc/platforms/cell/spufs/inode.c14
-rw-r--r--arch/s390/hypfs/inode.c6
-rw-r--r--arch/um/include/asm/mmu.h2
-rw-r--r--arch/um/include/asm/mmu_context.h11
-rw-r--r--arch/um/kernel/skas/mmu.c25
-rw-r--r--arch/x86/ia32/ia32_aout.c4
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c16
-rw-r--r--drivers/misc/ibmasm/module.c11
-rw-r--r--drivers/mmc/card/block.c2
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad_debugfs.c2
-rw-r--r--drivers/oprofile/oprofilefs.c11
-rw-r--r--drivers/usb/core/inode.c23
-rw-r--r--drivers/usb/gadget/f_fs.c8
-rw-r--r--drivers/usb/gadget/inode.c13
-rw-r--r--fs/9p/v9fs.c16
-rw-r--r--fs/9p/vfs_super.c3
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/Makefile1
-rw-r--r--fs/adfs/super.c3
-rw-r--r--fs/affs/super.c7
-rw-r--r--fs/afs/super.c7
-rw-r--r--fs/aio.c65
-rw-r--r--fs/anon_inodes.c109
-rw-r--r--fs/autofs4/init.c6
-rw-r--r--fs/autofs4/inode.c10
-rw-r--r--fs/befs/linuxvfs.c3
-rw-r--r--fs/bfs/inode.c3
-rw-r--r--fs/binfmt_aout.c4
-rw-r--r--fs/binfmt_elf.c5
-rw-r--r--fs/binfmt_elf_fdpic.c6
-rw-r--r--fs/binfmt_em86.c3
-rw-r--r--fs/binfmt_flat.c4
-rw-r--r--fs/binfmt_misc.c7
-rw-r--r--fs/binfmt_script.c3
-rw-r--r--fs/binfmt_som.c4
-rw-r--r--fs/btrfs/super.c8
-rw-r--r--fs/cachefiles/namei.c3
-rw-r--r--fs/ceph/super.c3
-rw-r--r--fs/cifs/cifsfs.c7
-rw-r--r--fs/coda/inode.c6
-rw-r--r--fs/configfs/configfs_internal.h7
-rw-r--r--fs/configfs/dir.c72
-rw-r--r--fs/configfs/inode.c62
-rw-r--r--fs/configfs/mount.c16
-rw-r--r--fs/configfs/symlink.c12
-rw-r--r--fs/cramfs/inode.c6
-rw-r--r--fs/dcache.c24
-rw-r--r--fs/debugfs/file.c2
-rw-r--r--fs/devpts/inode.c3
-rw-r--r--fs/ecryptfs/file.c9
-rw-r--r--fs/ecryptfs/main.c19
-rw-r--r--fs/ecryptfs/super.c1
-rw-r--r--fs/efs/super.c3
-rw-r--r--fs/exec.c8
-rw-r--r--fs/exofs/namei.c13
-rw-r--r--fs/exofs/super.c4
-rw-r--r--fs/ext2/namei.c13
-rw-r--r--fs/ext2/super.c4
-rw-r--r--fs/ext3/super.c3
-rw-r--r--fs/ext4/super.c8
-rw-r--r--fs/fat/inode.c8
-rw-r--r--fs/file_table.c3
-rw-r--r--fs/freevxfs/vxfs_super.c3
-rw-r--r--fs/fs_struct.c29
-rw-r--r--fs/fuse/inode.c9
-rw-r--r--fs/gfs2/ops_fstype.c3
-rw-r--r--fs/hfs/super.c6
-rw-r--r--fs/hfsplus/hfsplus_fs.h5
-rw-r--r--fs/hfsplus/hfsplus_raw.h2
-rw-r--r--fs/hfsplus/inode.c2
-rw-r--r--fs/hfsplus/ioctl.c34
-rw-r--r--fs/hfsplus/super.c17
-rw-r--r--fs/hostfs/hostfs_kern.c4
-rw-r--r--fs/hpfs/super.c6
-rw-r--r--fs/hppfs/hppfs.c9
-rw-r--r--fs/hugetlbfs/inode.c13
-rw-r--r--fs/inode.c28
-rw-r--r--fs/isofs/inode.c3
-rw-r--r--fs/jffs2/fs.c6
-rw-r--r--fs/jfs/namei.c13
-rw-r--r--fs/jfs/super.c12
-rw-r--r--fs/libfs.c8
-rw-r--r--fs/logfs/dir.c3
-rw-r--r--fs/logfs/super.c12
-rw-r--r--fs/minix/inode.c38
-rw-r--r--fs/minix/minix.h1
-rw-r--r--fs/minix/namei.c14
-rw-r--r--fs/namei.c15
-rw-r--r--fs/ncpfs/inode.c6
-rw-r--r--fs/nfs/getroot.c6
-rw-r--r--fs/nfsd/fault_inject.c2
-rw-r--r--fs/nfsd/vfs.c11
-rw-r--r--fs/nilfs2/namei.c11
-rw-r--r--fs/nilfs2/super.c4
-rw-r--r--fs/ntfs/super.c9
-rw-r--r--fs/ocfs2/dlmfs/dlmfs.c14
-rw-r--r--fs/ocfs2/super.c51
-rw-r--r--fs/omfs/inode.c6
-rw-r--r--fs/openpromfs/inode.c3
-rw-r--r--fs/proc/inode.c16
-rw-r--r--fs/pstore/inode.c25
-rw-r--r--fs/qnx4/inode.c88
-rw-r--r--fs/qnx4/namei.c9
-rw-r--r--fs/qnx4/qnx4.h2
-rw-r--r--fs/qnx6/Kconfig26
-rw-r--r--fs/qnx6/Makefile7
-rw-r--r--fs/qnx6/README8
-rw-r--r--fs/qnx6/dir.c291
-rw-r--r--fs/qnx6/inode.c698
-rw-r--r--fs/qnx6/namei.c42
-rw-r--r--fs/qnx6/qnx6.h135
-rw-r--r--fs/qnx6/super_mmi.c150
-rw-r--r--fs/ramfs/inode.c30
-rw-r--r--fs/reiserfs/acl.h (renamed from include/linux/reiserfs_acl.h)0
-rw-r--r--fs/reiserfs/bitmap.c4
-rw-r--r--fs/reiserfs/dir.c2
-rw-r--r--fs/reiserfs/do_balan.c2
-rw-r--r--fs/reiserfs/file.c6
-rw-r--r--fs/reiserfs/fix_node.c2
-rw-r--r--fs/reiserfs/hashes.c2
-rw-r--r--fs/reiserfs/ibalance.c2
-rw-r--r--fs/reiserfs/inode.c6
-rw-r--r--fs/reiserfs/ioctl.c2
-rw-r--r--fs/reiserfs/item_ops.c2
-rw-r--r--fs/reiserfs/journal.c2
-rw-r--r--fs/reiserfs/lbalance.c2
-rw-r--r--fs/reiserfs/lock.c2
-rw-r--r--fs/reiserfs/namei.c6
-rw-r--r--fs/reiserfs/objectid.c3
-rw-r--r--fs/reiserfs/prints.c4
-rw-r--r--fs/reiserfs/procfs.c3
-rw-r--r--fs/reiserfs/reiserfs.h2922
-rw-r--r--fs/reiserfs/resize.c3
-rw-r--r--fs/reiserfs/stree.c2
-rw-r--r--fs/reiserfs/super.c12
-rw-r--r--fs/reiserfs/tail_conversion.c2
-rw-r--r--fs/reiserfs/xattr.c6
-rw-r--r--fs/reiserfs/xattr.h122
-rw-r--r--fs/reiserfs/xattr_acl.c6
-rw-r--r--fs/reiserfs/xattr_security.c4
-rw-r--r--fs/reiserfs/xattr_trusted.c4
-rw-r--r--fs/reiserfs/xattr_user.c4
-rw-r--r--fs/romfs/super.c6
-rw-r--r--fs/squashfs/super.c3
-rw-r--r--fs/stat.c2
-rw-r--r--fs/sysfs/mount.c3
-rw-r--r--fs/sysv/namei.c12
-rw-r--r--fs/sysv/super.c27
-rw-r--r--fs/sysv/sysv.h1
-rw-r--r--fs/ubifs/super.c6
-rw-r--r--fs/udf/namei.c13
-rw-r--r--fs/udf/super.c6
-rw-r--r--fs/ufs/namei.c14
-rw-r--r--fs/ufs/super.c7
-rw-r--r--fs/xfs/xfs_rename.c11
-rw-r--r--fs/xfs/xfs_super.c7
-rw-r--r--fs/xfs/xfs_utils.c2
-rw-r--r--fs/xfs/xfs_vnodeops.c16
-rw-r--r--include/linux/audit.h2
-rw-r--r--include/linux/binfmts.h10
-rw-r--r--include/linux/dcache.h1
-rw-r--r--include/linux/debugfs.h4
-rw-r--r--include/linux/file.h1
-rw-r--r--include/linux/fs.h10
-rw-r--r--include/linux/magic.h1
-rw-r--r--include/linux/qnx6_fs.h134
-rw-r--r--include/linux/reiserfs_fs.h2334
-rw-r--r--include/linux/reiserfs_fs_i.h63
-rw-r--r--include/linux/reiserfs_fs_sb.h554
-rw-r--r--include/linux/reiserfs_xattr.h128
-rw-r--r--include/linux/trace_seq.h4
-rw-r--r--include/net/af_unix.h3
-rw-r--r--ipc/mqueue.c24
-rw-r--r--kernel/audit.c2
-rw-r--r--kernel/cgroup.c8
-rw-r--r--kernel/trace/trace_output.c2
-rw-r--r--mm/shmem.c10
-rw-r--r--net/sunrpc/rpc_pipe.c8
-rw-r--r--net/unix/af_unix.c37
-rw-r--r--net/unix/diag.c2
-rw-r--r--security/lsm_audit.c8
186 files changed, 5360 insertions, 4141 deletions
diff --git a/Documentation/filesystems/debugfs.txt b/Documentation/filesystems/debugfs.txt
index 4e2575873187..7a34f827989c 100644
--- a/Documentation/filesystems/debugfs.txt
+++ b/Documentation/filesystems/debugfs.txt
@@ -136,7 +136,7 @@ file.
136 void __iomem *base; 136 void __iomem *base;
137 }; 137 };
138 138
139 struct dentry *debugfs_create_regset32(const char *name, mode_t mode, 139 struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
140 struct dentry *parent, 140 struct dentry *parent,
141 struct debugfs_regset32 *regset); 141 struct debugfs_regset32 *regset);
142 142
diff --git a/Documentation/filesystems/porting b/Documentation/filesystems/porting
index b4a3d765ff9a..74acd9618819 100644
--- a/Documentation/filesystems/porting
+++ b/Documentation/filesystems/porting
@@ -429,3 +429,9 @@ filemap_write_and_wait_range() so that all dirty pages are synced out properly.
429You must also keep in mind that ->fsync() is not called with i_mutex held 429You must also keep in mind that ->fsync() is not called with i_mutex held
430anymore, so if you require i_mutex locking you must make sure to take it and 430anymore, so if you require i_mutex locking you must make sure to take it and
431release it yourself. 431release it yourself.
432
433--
434[mandatory]
435 d_alloc_root() is gone, along with a lot of bugs caused by code
436misusing it. Replacement: d_make_root(inode). The difference is,
437d_make_root() drops the reference to inode if dentry allocation fails.
diff --git a/Documentation/filesystems/qnx6.txt b/Documentation/filesystems/qnx6.txt
new file mode 100644
index 000000000000..050223ea03c7
--- /dev/null
+++ b/Documentation/filesystems/qnx6.txt
@@ -0,0 +1,174 @@
1The QNX6 Filesystem
2===================
3
4The qnx6fs is used by newer QNX operating system versions. (e.g. Neutrino)
5It got introduced in QNX 6.4.0 and is used default since 6.4.1.
6
7Option
8======
9
10mmi_fs Mount filesystem as used for example by Audi MMI 3G system
11
12Specification
13=============
14
15qnx6fs shares many properties with traditional Unix filesystems. It has the
16concepts of blocks, inodes and directories.
17On QNX it is possible to create little endian and big endian qnx6 filesystems.
18This feature makes it possible to create and use a different endianness fs
19for the target (QNX is used on quite a range of embedded systems) plattform
20running on a different endianess.
21The Linux driver handles endianness transparently. (LE and BE)
22
23Blocks
24------
25
26The space in the device or file is split up into blocks. These are a fixed
27size of 512, 1024, 2048 or 4096, which is decided when the filesystem is
28created.
29Blockpointers are 32bit, so the maximum space that can be adressed is
302^32 * 4096 bytes or 16TB
31
32The superblocks
33---------------
34
35The superblock contains all global information about the filesystem.
36Each qnx6fs got two superblocks, each one having a 64bit serial number.
37That serial number is used to identify the "active" superblock.
38In write mode with reach new snapshot (after each synchronous write), the
39serial of the new master superblock is increased (old superblock serial + 1)
40
41So basically the snapshot functionality is realized by an atomic final
42update of the serial number. Before updating that serial, all modifications
43are done by copying all modified blocks during that specific write request
44(or period) and building up a new (stable) filesystem structure under the
45inactive superblock.
46
47Each superblock holds a set of root inodes for the different filesystem
48parts. (Inode, Bitmap and Longfilenames)
49Each of these root nodes holds information like total size of the stored
50data and the adressing levels in that specific tree.
51If the level value is 0, up to 16 direct blocks can be adressed by each
52node.
53Level 1 adds an additional indirect adressing level where each indirect
54adressing block holds up to blocksize / 4 bytes pointers to data blocks.
55Level 2 adds an additional indirect adressig block level (so, already up
56to 16 * 256 * 256 = 1048576 blocks that can be adressed by such a tree)a
57
58Unused block pointers are always set to ~0 - regardless of root node,
59indirect adressing blocks or inodes.
60Data leaves are always on the lowest level. So no data is stored on upper
61tree levels.
62
63The first Superblock is located at 0x2000. (0x2000 is the bootblock size)
64The Audi MMI 3G first superblock directly starts at byte 0.
65Second superblock position can either be calculated from the superblock
66information (total number of filesystem blocks) or by taking the highest
67device address, zeroing the last 3 bytes and then substracting 0x1000 from
68that address.
69
700x1000 is the size reserved for each superblock - regardless of the
71blocksize of the filesystem.
72
73Inodes
74------
75
76Each object in the filesystem is represented by an inode. (index node)
77The inode structure contains pointers to the filesystem blocks which contain
78the data held in the object and all of the metadata about an object except
79its longname. (filenames longer than 27 characters)
80The metadata about an object includes the permissions, owner, group, flags,
81size, number of blocks used, access time, change time and modification time.
82
83Object mode field is POSIX format. (which makes things easier)
84
85There are also pointers to the first 16 blocks, if the object data can be
86adressed with 16 direct blocks.
87For more than 16 blocks an indirect adressing in form of another tree is
88used. (scheme is the same as the one used for the superblock root nodes)
89
90The filesize is stored 64bit. Inode counting starts with 1. (whilst long
91filename inodes start with 0)
92
93Directories
94-----------
95
96A directory is a filesystem object and has an inode just like a file.
97It is a specially formatted file containing records which associate each
98name with an inode number.
99'.' inode number points to the directory inode
100'..' inode number points to the parent directory inode
101Eeach filename record additionally got a filename length field.
102
103One special case are long filenames or subdirectory names.
104These got set a filename length field of 0xff in the corresponding directory
105record plus the longfile inode number also stored in that record.
106With that longfilename inode number, the longfilename tree can be walked
107starting with the superblock longfilename root node pointers.
108
109Special files
110-------------
111
112Symbolic links are also filesystem objects with inodes. They got a specific
113bit in the inode mode field identifying them as symbolic link.
114The directory entry file inode pointer points to the target file inode.
115
116Hard links got an inode, a directory entry, but a specific mode bit set,
117no block pointers and the directory file record pointing to the target file
118inode.
119
120Character and block special devices do not exist in QNX as those files
121are handled by the QNX kernel/drivers and created in /dev independant of the
122underlaying filesystem.
123
124Long filenames
125--------------
126
127Long filenames are stored in a seperate adressing tree. The staring point
128is the longfilename root node in the active superblock.
129Each data block (tree leaves) holds one long filename. That filename is
130limited to 510 bytes. The first two starting bytes are used as length field
131for the actual filename.
132If that structure shall fit for all allowed blocksizes, it is clear why there
133is a limit of 510 bytes for the actual filename stored.
134
135Bitmap
136------
137
138The qnx6fs filesystem allocation bitmap is stored in a tree under bitmap
139root node in the superblock and each bit in the bitmap represents one
140filesystem block.
141The first block is block 0, which starts 0x1000 after superblock start.
142So for a normal qnx6fs 0x3000 (bootblock + superblock) is the physical
143address at which block 0 is located.
144
145Bits at the end of the last bitmap block are set to 1, if the device is
146smaller than addressing space in the bitmap.
147
148Bitmap system area
149------------------
150
151The bitmap itself is devided into three parts.
152First the system area, that is split into two halfs.
153Then userspace.
154
155The requirement for a static, fixed preallocated system area comes from how
156qnx6fs deals with writes.
157Each superblock got it's own half of the system area. So superblock #1
158always uses blocks from the lower half whilst superblock #2 just writes to
159blocks represented by the upper half bitmap system area bits.
160
161Bitmap blocks, Inode blocks and indirect addressing blocks for those two
162tree structures are treated as system blocks.
163
164The rational behind that is that a write request can work on a new snapshot
165(system area of the inactive - resp. lower serial numbered superblock) while
166at the same time there is still a complete stable filesystem structer in the
167other half of the system area.
168
169When finished with writing (a sync write is completed, the maximum sync leap
170time or a filesystem sync is requested), serial of the previously inactive
171superblock atomically is increased and the fs switches over to that - then
172stable declared - superblock.
173
174For all data outside the system area, blocks are just copied while writing.
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 68fbfb6529eb..3b7488fc3373 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -218,6 +218,7 @@ Code Seq#(hex) Include File Comments
218'h' 00-7F conflict! Charon filesystem 218'h' 00-7F conflict! Charon filesystem
219 <mailto:zapman@interlan.net> 219 <mailto:zapman@interlan.net>
220'h' 00-1F linux/hpet.h conflict! 220'h' 00-1F linux/hpet.h conflict!
221'h' 80-8F fs/hfsplus/ioctl.c
221'i' 00-3F linux/i2o-dev.h conflict! 222'i' 00-3F linux/i2o-dev.h conflict!
222'i' 0B-1F linux/ipmi.h conflict! 223'i' 0B-1F linux/ipmi.h conflict!
223'i' 80-8F linux/i8k.h 224'i' 80-8F linux/i8k.h
diff --git a/arch/alpha/kernel/binfmt_loader.c b/arch/alpha/kernel/binfmt_loader.c
index 3fcfad410130..d1f474d1d44d 100644
--- a/arch/alpha/kernel/binfmt_loader.c
+++ b/arch/alpha/kernel/binfmt_loader.c
@@ -46,6 +46,7 @@ static struct linux_binfmt loader_format = {
46 46
47static int __init init_loader_binfmt(void) 47static int __init init_loader_binfmt(void)
48{ 48{
49 return insert_binfmt(&loader_format); 49 insert_binfmt(&loader_format);
50 return 0;
50} 51}
51arch_initcall(init_loader_binfmt); 52arch_initcall(init_loader_binfmt);
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index d4a094ca96f3..4a3d90e0d426 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -757,9 +757,9 @@ spufs_create_root(struct super_block *sb, void *data)
757 goto out_iput; 757 goto out_iput;
758 758
759 ret = -ENOMEM; 759 ret = -ENOMEM;
760 sb->s_root = d_alloc_root(inode); 760 sb->s_root = d_make_root(inode);
761 if (!sb->s_root) 761 if (!sb->s_root)
762 goto out_iput; 762 goto out;
763 763
764 return 0; 764 return 0;
765out_iput: 765out_iput:
@@ -828,19 +828,19 @@ static int __init spufs_init(void)
828 ret = spu_sched_init(); 828 ret = spu_sched_init();
829 if (ret) 829 if (ret)
830 goto out_cache; 830 goto out_cache;
831 ret = register_filesystem(&spufs_type); 831 ret = register_spu_syscalls(&spufs_calls);
832 if (ret) 832 if (ret)
833 goto out_sched; 833 goto out_sched;
834 ret = register_spu_syscalls(&spufs_calls); 834 ret = register_filesystem(&spufs_type);
835 if (ret) 835 if (ret)
836 goto out_fs; 836 goto out_syscalls;
837 837
838 spufs_init_isolated_loader(); 838 spufs_init_isolated_loader();
839 839
840 return 0; 840 return 0;
841 841
842out_fs: 842out_syscalls:
843 unregister_filesystem(&spufs_type); 843 unregister_spu_syscalls(&spufs_calls);
844out_sched: 844out_sched:
845 spu_sched_exit(); 845 spu_sched_exit();
846out_cache: 846out_cache:
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 8a2a887478cc..6a2cb560e968 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -293,11 +293,9 @@ static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
293 return -ENOMEM; 293 return -ENOMEM;
294 root_inode->i_op = &simple_dir_inode_operations; 294 root_inode->i_op = &simple_dir_inode_operations;
295 root_inode->i_fop = &simple_dir_operations; 295 root_inode->i_fop = &simple_dir_operations;
296 sb->s_root = root_dentry = d_alloc_root(root_inode); 296 sb->s_root = root_dentry = d_make_root(root_inode);
297 if (!root_dentry) { 297 if (!root_dentry)
298 iput(root_inode);
299 return -ENOMEM; 298 return -ENOMEM;
300 }
301 if (MACHINE_IS_VM) 299 if (MACHINE_IS_VM)
302 rc = hypfs_vm_create_files(sb, root_dentry); 300 rc = hypfs_vm_create_files(sb, root_dentry);
303 else 301 else
diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h
index 30509b9f37fd..53e8b498ebba 100644
--- a/arch/um/include/asm/mmu.h
+++ b/arch/um/include/asm/mmu.h
@@ -12,7 +12,7 @@
12typedef struct mm_context { 12typedef struct mm_context {
13 struct mm_id id; 13 struct mm_id id;
14 struct uml_arch_mm_context arch; 14 struct uml_arch_mm_context arch;
15 struct page **stub_pages; 15 struct page *stub_pages[2];
16} mm_context_t; 16} mm_context_t;
17 17
18extern void __switch_mm(struct mm_id * mm_idp); 18extern void __switch_mm(struct mm_id * mm_idp);
diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h
index 591b3d8d7614..aa4a743dc4ab 100644
--- a/arch/um/include/asm/mmu_context.h
+++ b/arch/um/include/asm/mmu_context.h
@@ -9,7 +9,7 @@
9#include <linux/sched.h> 9#include <linux/sched.h>
10#include <asm/mmu.h> 10#include <asm/mmu.h>
11 11
12extern void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm); 12extern void uml_setup_stubs(struct mm_struct *mm);
13extern void arch_exit_mmap(struct mm_struct *mm); 13extern void arch_exit_mmap(struct mm_struct *mm);
14 14
15#define deactivate_mm(tsk,mm) do { } while (0) 15#define deactivate_mm(tsk,mm) do { } while (0)
@@ -23,7 +23,9 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
23 * when the new ->mm is used for the first time. 23 * when the new ->mm is used for the first time.
24 */ 24 */
25 __switch_mm(&new->context.id); 25 __switch_mm(&new->context.id);
26 arch_dup_mmap(old, new); 26 down_write(&new->mmap_sem);
27 uml_setup_stubs(new);
28 up_write(&new->mmap_sem);
27} 29}
28 30
29static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 31static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
@@ -39,6 +41,11 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
39 } 41 }
40} 42}
41 43
44static inline void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
45{
46 uml_setup_stubs(mm);
47}
48
42static inline void enter_lazy_tlb(struct mm_struct *mm, 49static inline void enter_lazy_tlb(struct mm_struct *mm,
43 struct task_struct *tsk) 50 struct task_struct *tsk)
44{ 51{
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 1aee587e9c5d..4947b319f53a 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -92,8 +92,6 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
92 goto out_free; 92 goto out_free;
93 } 93 }
94 94
95 to_mm->stub_pages = NULL;
96
97 return 0; 95 return 0;
98 96
99 out_free: 97 out_free:
@@ -103,7 +101,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
103 return ret; 101 return ret;
104} 102}
105 103
106void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) 104void uml_setup_stubs(struct mm_struct *mm)
107{ 105{
108 struct page **pages; 106 struct page **pages;
109 int err, ret; 107 int err, ret;
@@ -120,29 +118,20 @@ void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
120 if (ret) 118 if (ret)
121 goto out; 119 goto out;
122 120
123 pages = kmalloc(2 * sizeof(struct page *), GFP_KERNEL); 121 mm->context.stub_pages[0] = virt_to_page(&__syscall_stub_start);
124 if (pages == NULL) { 122 mm->context.stub_pages[1] = virt_to_page(mm->context.id.stack);
125 printk(KERN_ERR "arch_dup_mmap failed to allocate 2 page "
126 "pointers\n");
127 goto out;
128 }
129
130 pages[0] = virt_to_page(&__syscall_stub_start);
131 pages[1] = virt_to_page(mm->context.id.stack);
132 mm->context.stub_pages = pages;
133 123
134 /* dup_mmap already holds mmap_sem */ 124 /* dup_mmap already holds mmap_sem */
135 err = install_special_mapping(mm, STUB_START, STUB_END - STUB_START, 125 err = install_special_mapping(mm, STUB_START, STUB_END - STUB_START,
136 VM_READ | VM_MAYREAD | VM_EXEC | 126 VM_READ | VM_MAYREAD | VM_EXEC |
137 VM_MAYEXEC | VM_DONTCOPY, pages); 127 VM_MAYEXEC | VM_DONTCOPY,
128 mm->context.stub_pages);
138 if (err) { 129 if (err) {
139 printk(KERN_ERR "install_special_mapping returned %d\n", err); 130 printk(KERN_ERR "install_special_mapping returned %d\n", err);
140 goto out_free; 131 goto out;
141 } 132 }
142 return; 133 return;
143 134
144out_free:
145 kfree(pages);
146out: 135out:
147 force_sigsegv(SIGSEGV, current); 136 force_sigsegv(SIGSEGV, current);
148} 137}
@@ -151,8 +140,6 @@ void arch_exit_mmap(struct mm_struct *mm)
151{ 140{
152 pte_t *pte; 141 pte_t *pte;
153 142
154 if (mm->context.stub_pages != NULL)
155 kfree(mm->context.stub_pages);
156 pte = virt_to_pte(mm, STUB_CODE); 143 pte = virt_to_pte(mm, STUB_CODE);
157 if (pte != NULL) 144 if (pte != NULL)
158 pte_clear(mm, STUB_CODE, pte); 145 pte_clear(mm, STUB_CODE, pte);
diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index 39e49091f648..4c2e59a420b9 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -323,7 +323,6 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
323 } 323 }
324 324
325 install_exec_creds(bprm); 325 install_exec_creds(bprm);
326 current->flags &= ~PF_FORKNOEXEC;
327 326
328 if (N_MAGIC(ex) == OMAGIC) { 327 if (N_MAGIC(ex) == OMAGIC) {
329 unsigned long text_addr, map_size; 328 unsigned long text_addr, map_size;
@@ -519,7 +518,8 @@ out:
519 518
520static int __init init_aout_binfmt(void) 519static int __init init_aout_binfmt(void)
521{ 520{
522 return register_binfmt(&aout_format); 521 register_binfmt(&aout_format);
522 return 0;
523} 523}
524 524
525static void __exit exit_aout_binfmt(void) 525static void __exit exit_aout_binfmt(void)
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index 35361753b487..1c034b80d408 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -87,7 +87,7 @@
87static LIST_HEAD(service_processors); 87static LIST_HEAD(service_processors);
88 88
89static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode); 89static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode);
90static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root); 90static void ibmasmfs_create_files (struct super_block *sb);
91static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent); 91static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent);
92 92
93 93
@@ -114,7 +114,6 @@ static struct file_system_type ibmasmfs_type = {
114static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent) 114static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent)
115{ 115{
116 struct inode *root; 116 struct inode *root;
117 struct dentry *root_dentry;
118 117
119 sb->s_blocksize = PAGE_CACHE_SIZE; 118 sb->s_blocksize = PAGE_CACHE_SIZE;
120 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 119 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -129,14 +128,11 @@ static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent)
129 root->i_op = &simple_dir_inode_operations; 128 root->i_op = &simple_dir_inode_operations;
130 root->i_fop = ibmasmfs_dir_ops; 129 root->i_fop = ibmasmfs_dir_ops;
131 130
132 root_dentry = d_alloc_root(root); 131 sb->s_root = d_make_root(root);
133 if (!root_dentry) { 132 if (!sb->s_root)
134 iput(root);
135 return -ENOMEM; 133 return -ENOMEM;
136 }
137 sb->s_root = root_dentry;
138 134
139 ibmasmfs_create_files(sb, root_dentry); 135 ibmasmfs_create_files(sb);
140 return 0; 136 return 0;
141} 137}
142 138
@@ -612,7 +608,7 @@ static const struct file_operations remote_settings_fops = {
612}; 608};
613 609
614 610
615static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root) 611static void ibmasmfs_create_files (struct super_block *sb)
616{ 612{
617 struct list_head *entry; 613 struct list_head *entry;
618 struct service_processor *sp; 614 struct service_processor *sp;
@@ -621,7 +617,7 @@ static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root)
621 struct dentry *dir; 617 struct dentry *dir;
622 struct dentry *remote_dir; 618 struct dentry *remote_dir;
623 sp = list_entry(entry, struct service_processor, node); 619 sp = list_entry(entry, struct service_processor, node);
624 dir = ibmasmfs_create_dir(sb, root, sp->dirname); 620 dir = ibmasmfs_create_dir(sb, sb->s_root, sp->dirname);
625 if (!dir) 621 if (!dir)
626 continue; 622 continue;
627 623
diff --git a/drivers/misc/ibmasm/module.c b/drivers/misc/ibmasm/module.c
index 1ccedb71e728..168d8008f460 100644
--- a/drivers/misc/ibmasm/module.c
+++ b/drivers/misc/ibmasm/module.c
@@ -211,18 +211,17 @@ static void __exit ibmasm_exit (void)
211 211
212static int __init ibmasm_init(void) 212static int __init ibmasm_init(void)
213{ 213{
214 int result; 214 int result = pci_register_driver(&ibmasm_driver);
215 if (result)
216 return result;
215 217
216 result = ibmasmfs_register(); 218 result = ibmasmfs_register();
217 if (result) { 219 if (result) {
220 pci_unregister_driver(&ibmasm_driver);
218 err("Failed to register ibmasmfs file system"); 221 err("Failed to register ibmasmfs file system");
219 return result; 222 return result;
220 } 223 }
221 result = pci_register_driver(&ibmasm_driver); 224
222 if (result) {
223 ibmasmfs_unregister();
224 return result;
225 }
226 ibmasm_register_panic_notifier(); 225 ibmasm_register_panic_notifier();
227 info(DRIVER_DESC " version " DRIVER_VERSION " loaded"); 226 info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
228 return 0; 227 return 0;
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index c6a383d0244d..e5a3c7b6dedb 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1685,7 +1685,7 @@ static int mmc_add_disk(struct mmc_blk_data *md)
1685 1685
1686 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) && 1686 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
1687 card->ext_csd.boot_ro_lockable) { 1687 card->ext_csd.boot_ro_lockable) {
1688 mode_t mode; 1688 umode_t mode;
1689 1689
1690 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS) 1690 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
1691 mode = S_IRUGO; 1691 mode = S_IRUGO;
diff --git a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
index c9fdceb135f3..6e8bc9d88c41 100644
--- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
+++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
@@ -516,7 +516,7 @@ static const struct file_operations bnad_debugfs_op_drvinfo = {
516 516
517struct bnad_debugfs_entry { 517struct bnad_debugfs_entry {
518 const char *name; 518 const char *name;
519 mode_t mode; 519 umode_t mode;
520 const struct file_operations *fops; 520 const struct file_operations *fops;
521}; 521};
522 522
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 2f0aa0f700e6..ee8fd037bb53 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -238,7 +238,6 @@ struct dentry *oprofilefs_mkdir(struct super_block *sb,
238static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent) 238static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)
239{ 239{
240 struct inode *root_inode; 240 struct inode *root_inode;
241 struct dentry *root_dentry;
242 241
243 sb->s_blocksize = PAGE_CACHE_SIZE; 242 sb->s_blocksize = PAGE_CACHE_SIZE;
244 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 243 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -251,15 +250,11 @@ static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)
251 return -ENOMEM; 250 return -ENOMEM;
252 root_inode->i_op = &simple_dir_inode_operations; 251 root_inode->i_op = &simple_dir_inode_operations;
253 root_inode->i_fop = &simple_dir_operations; 252 root_inode->i_fop = &simple_dir_operations;
254 root_dentry = d_alloc_root(root_inode); 253 sb->s_root = d_make_root(root_inode);
255 if (!root_dentry) { 254 if (!sb->s_root)
256 iput(root_inode);
257 return -ENOMEM; 255 return -ENOMEM;
258 }
259
260 sb->s_root = root_dentry;
261 256
262 oprofile_create_files(sb, root_dentry); 257 oprofile_create_files(sb, sb->s_root);
263 258
264 // FIXME: verify kill_litter_super removes our dentries 259 // FIXME: verify kill_litter_super removes our dentries
265 return 0; 260 return 0;
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 9e186f3da839..cefa0c8b5b6a 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -50,7 +50,6 @@
50static const struct file_operations default_file_operations; 50static const struct file_operations default_file_operations;
51static struct vfsmount *usbfs_mount; 51static struct vfsmount *usbfs_mount;
52static int usbfs_mount_count; /* = 0 */ 52static int usbfs_mount_count; /* = 0 */
53static int ignore_mount = 0;
54 53
55static struct dentry *devices_usbfs_dentry; 54static struct dentry *devices_usbfs_dentry;
56static int num_buses; /* = 0 */ 55static int num_buses; /* = 0 */
@@ -256,7 +255,7 @@ static int remount(struct super_block *sb, int *flags, char *data)
256 * i.e. it's a simple_pin_fs from create_special_files, 255 * i.e. it's a simple_pin_fs from create_special_files,
257 * then ignore it. 256 * then ignore it.
258 */ 257 */
259 if (ignore_mount) 258 if (*flags & MS_KERNMOUNT)
260 return 0; 259 return 0;
261 260
262 if (parse_options(sb, data)) { 261 if (parse_options(sb, data)) {
@@ -454,7 +453,6 @@ static const struct super_operations usbfs_ops = {
454static int usbfs_fill_super(struct super_block *sb, void *data, int silent) 453static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
455{ 454{
456 struct inode *inode; 455 struct inode *inode;
457 struct dentry *root;
458 456
459 sb->s_blocksize = PAGE_CACHE_SIZE; 457 sb->s_blocksize = PAGE_CACHE_SIZE;
460 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 458 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -462,19 +460,11 @@ static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
462 sb->s_op = &usbfs_ops; 460 sb->s_op = &usbfs_ops;
463 sb->s_time_gran = 1; 461 sb->s_time_gran = 1;
464 inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0); 462 inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0);
465 463 sb->s_root = d_make_root(inode);
466 if (!inode) { 464 if (!sb->s_root) {
467 dbg("%s: could not get inode!",__func__);
468 return -ENOMEM;
469 }
470
471 root = d_alloc_root(inode);
472 if (!root) {
473 dbg("%s: could not get root dentry!",__func__); 465 dbg("%s: could not get root dentry!",__func__);
474 iput(inode);
475 return -ENOMEM; 466 return -ENOMEM;
476 } 467 }
477 sb->s_root = root;
478 return 0; 468 return 0;
479} 469}
480 470
@@ -591,11 +581,6 @@ static int create_special_files (void)
591 struct dentry *parent; 581 struct dentry *parent;
592 int retval; 582 int retval;
593 583
594 /* the simple_pin_fs calls will call remount with no options
595 * without this flag that would overwrite the real mount options (if any)
596 */
597 ignore_mount = 1;
598
599 /* create the devices special file */ 584 /* create the devices special file */
600 retval = simple_pin_fs(&usb_fs_type, &usbfs_mount, &usbfs_mount_count); 585 retval = simple_pin_fs(&usb_fs_type, &usbfs_mount, &usbfs_mount_count);
601 if (retval) { 586 if (retval) {
@@ -603,8 +588,6 @@ static int create_special_files (void)
603 goto exit; 588 goto exit;
604 } 589 }
605 590
606 ignore_mount = 0;
607
608 parent = usbfs_mount->mnt_root; 591 parent = usbfs_mount->mnt_root;
609 devices_usbfs_dentry = fs_create_file ("devices", 592 devices_usbfs_dentry = fs_create_file ("devices",
610 listmode | S_IFREG, parent, 593 listmode | S_IFREG, parent,
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 7f445ec723bc..1cbba70836bc 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1063,13 +1063,9 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1063 &simple_dir_operations, 1063 &simple_dir_operations,
1064 &simple_dir_inode_operations, 1064 &simple_dir_inode_operations,
1065 &data->perms); 1065 &data->perms);
1066 if (unlikely(!inode)) 1066 sb->s_root = d_make_root(inode);
1067 if (unlikely(!sb->s_root))
1067 goto Enomem; 1068 goto Enomem;
1068 sb->s_root = d_alloc_root(inode);
1069 if (unlikely(!sb->s_root)) {
1070 iput(inode);
1071 goto Enomem;
1072 }
1073 1069
1074 /* EP0 file */ 1070 /* EP0 file */
1075 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, 1071 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 4f18a0e46070..8793f32bab11 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1571,20 +1571,18 @@ delegate:
1571 1571
1572static void destroy_ep_files (struct dev_data *dev) 1572static void destroy_ep_files (struct dev_data *dev)
1573{ 1573{
1574 struct list_head *entry, *tmp;
1575
1576 DBG (dev, "%s %d\n", __func__, dev->state); 1574 DBG (dev, "%s %d\n", __func__, dev->state);
1577 1575
1578 /* dev->state must prevent interference */ 1576 /* dev->state must prevent interference */
1579restart: 1577restart:
1580 spin_lock_irq (&dev->lock); 1578 spin_lock_irq (&dev->lock);
1581 list_for_each_safe (entry, tmp, &dev->epfiles) { 1579 while (!list_empty(&dev->epfiles)) {
1582 struct ep_data *ep; 1580 struct ep_data *ep;
1583 struct inode *parent; 1581 struct inode *parent;
1584 struct dentry *dentry; 1582 struct dentry *dentry;
1585 1583
1586 /* break link to FS */ 1584 /* break link to FS */
1587 ep = list_entry (entry, struct ep_data, epfiles); 1585 ep = list_first_entry (&dev->epfiles, struct ep_data, epfiles);
1588 list_del_init (&ep->epfiles); 1586 list_del_init (&ep->epfiles);
1589 dentry = ep->dentry; 1587 dentry = ep->dentry;
1590 ep->dentry = NULL; 1588 ep->dentry = NULL;
@@ -1607,8 +1605,7 @@ restart:
1607 dput (dentry); 1605 dput (dentry);
1608 mutex_unlock (&parent->i_mutex); 1606 mutex_unlock (&parent->i_mutex);
1609 1607
1610 /* fds may still be open */ 1608 spin_lock_irq (&dev->lock);
1611 goto restart;
1612 } 1609 }
1613 spin_unlock_irq (&dev->lock); 1610 spin_unlock_irq (&dev->lock);
1614} 1611}
@@ -2061,10 +2058,8 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
2061 if (!inode) 2058 if (!inode)
2062 goto Enomem; 2059 goto Enomem;
2063 inode->i_op = &simple_dir_inode_operations; 2060 inode->i_op = &simple_dir_inode_operations;
2064 if (!(sb->s_root = d_alloc_root (inode))) { 2061 if (!(sb->s_root = d_make_root (inode)))
2065 iput(inode);
2066 goto Enomem; 2062 goto Enomem;
2067 }
2068 2063
2069 /* the ep0 file is named after the controller we expect; 2064 /* the ep0 file is named after the controller we expect;
2070 * user mode code can use it for sanity checks, like we do. 2065 * user mode code can use it for sanity checks, like we do.
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 1964f98e74be..b85efa773949 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -594,21 +594,21 @@ static int __init init_v9fs(void)
594 int err; 594 int err;
595 pr_info("Installing v9fs 9p2000 file system support\n"); 595 pr_info("Installing v9fs 9p2000 file system support\n");
596 /* TODO: Setup list of registered trasnport modules */ 596 /* TODO: Setup list of registered trasnport modules */
597 err = register_filesystem(&v9fs_fs_type);
598 if (err < 0) {
599 pr_err("Failed to register filesystem\n");
600 return err;
601 }
602 597
603 err = v9fs_cache_register(); 598 err = v9fs_cache_register();
604 if (err < 0) { 599 if (err < 0) {
605 pr_err("Failed to register v9fs for caching\n"); 600 pr_err("Failed to register v9fs for caching\n");
606 goto out_fs_unreg; 601 return err;
607 } 602 }
608 603
609 err = v9fs_sysfs_init(); 604 err = v9fs_sysfs_init();
610 if (err < 0) { 605 if (err < 0) {
611 pr_err("Failed to register with sysfs\n"); 606 pr_err("Failed to register with sysfs\n");
607 goto out_cache;
608 }
609 err = register_filesystem(&v9fs_fs_type);
610 if (err < 0) {
611 pr_err("Failed to register filesystem\n");
612 goto out_sysfs_cleanup; 612 goto out_sysfs_cleanup;
613 } 613 }
614 614
@@ -617,8 +617,8 @@ static int __init init_v9fs(void)
617out_sysfs_cleanup: 617out_sysfs_cleanup:
618 v9fs_sysfs_cleanup(); 618 v9fs_sysfs_cleanup();
619 619
620out_fs_unreg: 620out_cache:
621 unregister_filesystem(&v9fs_fs_type); 621 v9fs_cache_unregister();
622 622
623 return err; 623 return err;
624} 624}
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 7b0cd87b07c2..10b7d3c9dba8 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -155,9 +155,8 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
155 goto release_sb; 155 goto release_sb;
156 } 156 }
157 157
158 root = d_alloc_root(inode); 158 root = d_make_root(inode);
159 if (!root) { 159 if (!root) {
160 iput(inode);
161 retval = -ENOMEM; 160 retval = -ENOMEM;
162 goto release_sb; 161 goto release_sb;
163 } 162 }
diff --git a/fs/Kconfig b/fs/Kconfig
index aa195265362f..f95ae3a027f3 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -214,6 +214,7 @@ source "fs/minix/Kconfig"
214source "fs/omfs/Kconfig" 214source "fs/omfs/Kconfig"
215source "fs/hpfs/Kconfig" 215source "fs/hpfs/Kconfig"
216source "fs/qnx4/Kconfig" 216source "fs/qnx4/Kconfig"
217source "fs/qnx6/Kconfig"
217source "fs/romfs/Kconfig" 218source "fs/romfs/Kconfig"
218source "fs/pstore/Kconfig" 219source "fs/pstore/Kconfig"
219source "fs/sysv/Kconfig" 220source "fs/sysv/Kconfig"
diff --git a/fs/Makefile b/fs/Makefile
index 93804d4d66e1..2fb977934673 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_UBIFS_FS) += ubifs/
102obj-$(CONFIG_AFFS_FS) += affs/ 102obj-$(CONFIG_AFFS_FS) += affs/
103obj-$(CONFIG_ROMFS_FS) += romfs/ 103obj-$(CONFIG_ROMFS_FS) += romfs/
104obj-$(CONFIG_QNX4FS_FS) += qnx4/ 104obj-$(CONFIG_QNX4FS_FS) += qnx4/
105obj-$(CONFIG_QNX6FS_FS) += qnx6/
105obj-$(CONFIG_AUTOFS4_FS) += autofs4/ 106obj-$(CONFIG_AUTOFS4_FS) += autofs4/
106obj-$(CONFIG_ADFS_FS) += adfs/ 107obj-$(CONFIG_ADFS_FS) += adfs/
107obj-$(CONFIG_FUSE_FS) += fuse/ 108obj-$(CONFIG_FUSE_FS) += fuse/
diff --git a/fs/adfs/super.c b/fs/adfs/super.c
index 8e3b36ace305..06fdcc9382c4 100644
--- a/fs/adfs/super.c
+++ b/fs/adfs/super.c
@@ -483,10 +483,9 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
483 483
484 sb->s_d_op = &adfs_dentry_operations; 484 sb->s_d_op = &adfs_dentry_operations;
485 root = adfs_iget(sb, &root_obj); 485 root = adfs_iget(sb, &root_obj);
486 sb->s_root = d_alloc_root(root); 486 sb->s_root = d_make_root(root);
487 if (!sb->s_root) { 487 if (!sb->s_root) {
488 int i; 488 int i;
489 iput(root);
490 for (i = 0; i < asb->s_map_size; i++) 489 for (i = 0; i < asb->s_map_size; i++)
491 brelse(asb->s_map[i].dm_bh); 490 brelse(asb->s_map[i].dm_bh);
492 kfree(asb->s_map); 491 kfree(asb->s_map);
diff --git a/fs/affs/super.c b/fs/affs/super.c
index 8ba73fed7964..0782653a05a2 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -473,7 +473,7 @@ got_root:
473 root_inode = affs_iget(sb, root_block); 473 root_inode = affs_iget(sb, root_block);
474 if (IS_ERR(root_inode)) { 474 if (IS_ERR(root_inode)) {
475 ret = PTR_ERR(root_inode); 475 ret = PTR_ERR(root_inode);
476 goto out_error_noinode; 476 goto out_error;
477 } 477 }
478 478
479 if (AFFS_SB(sb)->s_flags & SF_INTL) 479 if (AFFS_SB(sb)->s_flags & SF_INTL)
@@ -481,7 +481,7 @@ got_root:
481 else 481 else
482 sb->s_d_op = &affs_dentry_operations; 482 sb->s_d_op = &affs_dentry_operations;
483 483
484 sb->s_root = d_alloc_root(root_inode); 484 sb->s_root = d_make_root(root_inode);
485 if (!sb->s_root) { 485 if (!sb->s_root) {
486 printk(KERN_ERR "AFFS: Get root inode failed\n"); 486 printk(KERN_ERR "AFFS: Get root inode failed\n");
487 goto out_error; 487 goto out_error;
@@ -494,9 +494,6 @@ got_root:
494 * Begin the cascaded cleanup ... 494 * Begin the cascaded cleanup ...
495 */ 495 */
496out_error: 496out_error:
497 if (root_inode)
498 iput(root_inode);
499out_error_noinode:
500 kfree(sbi->s_bitmap); 497 kfree(sbi->s_bitmap);
501 affs_brelse(root_bh); 498 affs_brelse(root_bh);
502 kfree(sbi->s_prefix); 499 kfree(sbi->s_prefix);
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 983ec59fc80d..f02b31e7e648 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -301,7 +301,6 @@ static int afs_fill_super(struct super_block *sb,
301{ 301{
302 struct afs_super_info *as = sb->s_fs_info; 302 struct afs_super_info *as = sb->s_fs_info;
303 struct afs_fid fid; 303 struct afs_fid fid;
304 struct dentry *root = NULL;
305 struct inode *inode = NULL; 304 struct inode *inode = NULL;
306 int ret; 305 int ret;
307 306
@@ -327,18 +326,16 @@ static int afs_fill_super(struct super_block *sb,
327 set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags); 326 set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags);
328 327
329 ret = -ENOMEM; 328 ret = -ENOMEM;
330 root = d_alloc_root(inode); 329 sb->s_root = d_make_root(inode);
331 if (!root) 330 if (!sb->s_root)
332 goto error; 331 goto error;
333 332
334 sb->s_d_op = &afs_fs_dentry_operations; 333 sb->s_d_op = &afs_fs_dentry_operations;
335 sb->s_root = root;
336 334
337 _leave(" = 0"); 335 _leave(" = 0");
338 return 0; 336 return 0;
339 337
340error: 338error:
341 iput(inode);
342 _leave(" = %d", ret); 339 _leave(" = %d", ret);
343 return ret; 340 return ret;
344} 341}
diff --git a/fs/aio.c b/fs/aio.c
index 5b600cb8779e..c7acaf3167aa 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -199,16 +199,7 @@ static int aio_setup_ring(struct kioctx *ctx)
199static void ctx_rcu_free(struct rcu_head *head) 199static void ctx_rcu_free(struct rcu_head *head)
200{ 200{
201 struct kioctx *ctx = container_of(head, struct kioctx, rcu_head); 201 struct kioctx *ctx = container_of(head, struct kioctx, rcu_head);
202 unsigned nr_events = ctx->max_reqs;
203
204 kmem_cache_free(kioctx_cachep, ctx); 202 kmem_cache_free(kioctx_cachep, ctx);
205
206 if (nr_events) {
207 spin_lock(&aio_nr_lock);
208 BUG_ON(aio_nr - nr_events > aio_nr);
209 aio_nr -= nr_events;
210 spin_unlock(&aio_nr_lock);
211 }
212} 203}
213 204
214/* __put_ioctx 205/* __put_ioctx
@@ -217,13 +208,19 @@ static void ctx_rcu_free(struct rcu_head *head)
217 */ 208 */
218static void __put_ioctx(struct kioctx *ctx) 209static void __put_ioctx(struct kioctx *ctx)
219{ 210{
211 unsigned nr_events = ctx->max_reqs;
220 BUG_ON(ctx->reqs_active); 212 BUG_ON(ctx->reqs_active);
221 213
222 cancel_delayed_work(&ctx->wq); 214 cancel_delayed_work_sync(&ctx->wq);
223 cancel_work_sync(&ctx->wq.work);
224 aio_free_ring(ctx); 215 aio_free_ring(ctx);
225 mmdrop(ctx->mm); 216 mmdrop(ctx->mm);
226 ctx->mm = NULL; 217 ctx->mm = NULL;
218 if (nr_events) {
219 spin_lock(&aio_nr_lock);
220 BUG_ON(aio_nr - nr_events > aio_nr);
221 aio_nr -= nr_events;
222 spin_unlock(&aio_nr_lock);
223 }
227 pr_debug("__put_ioctx: freeing %p\n", ctx); 224 pr_debug("__put_ioctx: freeing %p\n", ctx);
228 call_rcu(&ctx->rcu_head, ctx_rcu_free); 225 call_rcu(&ctx->rcu_head, ctx_rcu_free);
229} 226}
@@ -247,7 +244,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
247{ 244{
248 struct mm_struct *mm; 245 struct mm_struct *mm;
249 struct kioctx *ctx; 246 struct kioctx *ctx;
250 int did_sync = 0; 247 int err = -ENOMEM;
251 248
252 /* Prevent overflows */ 249 /* Prevent overflows */
253 if ((nr_events > (0x10000000U / sizeof(struct io_event))) || 250 if ((nr_events > (0x10000000U / sizeof(struct io_event))) ||
@@ -256,7 +253,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
256 return ERR_PTR(-EINVAL); 253 return ERR_PTR(-EINVAL);
257 } 254 }
258 255
259 if ((unsigned long)nr_events > aio_max_nr) 256 if (!nr_events || (unsigned long)nr_events > aio_max_nr)
260 return ERR_PTR(-EAGAIN); 257 return ERR_PTR(-EAGAIN);
261 258
262 ctx = kmem_cache_zalloc(kioctx_cachep, GFP_KERNEL); 259 ctx = kmem_cache_zalloc(kioctx_cachep, GFP_KERNEL);
@@ -280,25 +277,14 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
280 goto out_freectx; 277 goto out_freectx;
281 278
282 /* limit the number of system wide aios */ 279 /* limit the number of system wide aios */
283 do { 280 spin_lock(&aio_nr_lock);
284 spin_lock_bh(&aio_nr_lock); 281 if (aio_nr + nr_events > aio_max_nr ||
285 if (aio_nr + nr_events > aio_max_nr || 282 aio_nr + nr_events < aio_nr) {
286 aio_nr + nr_events < aio_nr) 283 spin_unlock(&aio_nr_lock);
287 ctx->max_reqs = 0;
288 else
289 aio_nr += ctx->max_reqs;
290 spin_unlock_bh(&aio_nr_lock);
291 if (ctx->max_reqs || did_sync)
292 break;
293
294 /* wait for rcu callbacks to have completed before giving up */
295 synchronize_rcu();
296 did_sync = 1;
297 ctx->max_reqs = nr_events;
298 } while (1);
299
300 if (ctx->max_reqs == 0)
301 goto out_cleanup; 284 goto out_cleanup;
285 }
286 aio_nr += ctx->max_reqs;
287 spin_unlock(&aio_nr_lock);
302 288
303 /* now link into global list. */ 289 /* now link into global list. */
304 spin_lock(&mm->ioctx_lock); 290 spin_lock(&mm->ioctx_lock);
@@ -310,16 +296,13 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
310 return ctx; 296 return ctx;
311 297
312out_cleanup: 298out_cleanup:
313 __put_ioctx(ctx); 299 err = -EAGAIN;
314 return ERR_PTR(-EAGAIN); 300 aio_free_ring(ctx);
315
316out_freectx: 301out_freectx:
317 mmdrop(mm); 302 mmdrop(mm);
318 kmem_cache_free(kioctx_cachep, ctx); 303 kmem_cache_free(kioctx_cachep, ctx);
319 ctx = ERR_PTR(-ENOMEM); 304 dprintk("aio: error allocating ioctx %d\n", err);
320 305 return ERR_PTR(err);
321 dprintk("aio: error allocating ioctx %p\n", ctx);
322 return ctx;
323} 306}
324 307
325/* aio_cancel_all 308/* aio_cancel_all
@@ -407,10 +390,6 @@ void exit_aio(struct mm_struct *mm)
407 aio_cancel_all(ctx); 390 aio_cancel_all(ctx);
408 391
409 wait_for_all_aios(ctx); 392 wait_for_all_aios(ctx);
410 /*
411 * Ensure we don't leave the ctx on the aio_wq
412 */
413 cancel_work_sync(&ctx->wq.work);
414 393
415 if (1 != atomic_read(&ctx->users)) 394 if (1 != atomic_read(&ctx->users))
416 printk(KERN_DEBUG 395 printk(KERN_DEBUG
@@ -920,7 +899,7 @@ static void aio_kick_handler(struct work_struct *work)
920 unuse_mm(mm); 899 unuse_mm(mm);
921 set_fs(oldfs); 900 set_fs(oldfs);
922 /* 901 /*
923 * we're in a worker thread already, don't use queue_delayed_work, 902 * we're in a worker thread already; no point using non-zero delay
924 */ 903 */
925 if (requeue) 904 if (requeue)
926 queue_delayed_work(aio_wq, &ctx->wq, 0); 905 queue_delayed_work(aio_wq, &ctx->wq, 0);
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index f11e43ed907d..28d39fb84ae3 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -39,19 +39,6 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
39 .d_dname = anon_inodefs_dname, 39 .d_dname = anon_inodefs_dname,
40}; 40};
41 41
42static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
43 int flags, const char *dev_name, void *data)
44{
45 return mount_pseudo(fs_type, "anon_inode:", NULL,
46 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
47}
48
49static struct file_system_type anon_inode_fs_type = {
50 .name = "anon_inodefs",
51 .mount = anon_inodefs_mount,
52 .kill_sb = kill_anon_super,
53};
54
55/* 42/*
56 * nop .set_page_dirty method so that people can use .page_mkwrite on 43 * nop .set_page_dirty method so that people can use .page_mkwrite on
57 * anon inodes. 44 * anon inodes.
@@ -65,6 +52,62 @@ static const struct address_space_operations anon_aops = {
65 .set_page_dirty = anon_set_page_dirty, 52 .set_page_dirty = anon_set_page_dirty,
66}; 53};
67 54
55/*
56 * A single inode exists for all anon_inode files. Contrary to pipes,
57 * anon_inode inodes have no associated per-instance data, so we need
58 * only allocate one of them.
59 */
60static struct inode *anon_inode_mkinode(struct super_block *s)
61{
62 struct inode *inode = new_inode_pseudo(s);
63
64 if (!inode)
65 return ERR_PTR(-ENOMEM);
66
67 inode->i_ino = get_next_ino();
68 inode->i_fop = &anon_inode_fops;
69
70 inode->i_mapping->a_ops = &anon_aops;
71
72 /*
73 * Mark the inode dirty from the very beginning,
74 * that way it will never be moved to the dirty
75 * list because mark_inode_dirty() will think
76 * that it already _is_ on the dirty list.
77 */
78 inode->i_state = I_DIRTY;
79 inode->i_mode = S_IRUSR | S_IWUSR;
80 inode->i_uid = current_fsuid();
81 inode->i_gid = current_fsgid();
82 inode->i_flags |= S_PRIVATE;
83 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
84 return inode;
85}
86
87static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
88 int flags, const char *dev_name, void *data)
89{
90 struct dentry *root;
91 root = mount_pseudo(fs_type, "anon_inode:", NULL,
92 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
93 if (!IS_ERR(root)) {
94 struct super_block *s = root->d_sb;
95 anon_inode_inode = anon_inode_mkinode(s);
96 if (IS_ERR(anon_inode_inode)) {
97 dput(root);
98 deactivate_locked_super(s);
99 root = ERR_CAST(anon_inode_inode);
100 }
101 }
102 return root;
103}
104
105static struct file_system_type anon_inode_fs_type = {
106 .name = "anon_inodefs",
107 .mount = anon_inodefs_mount,
108 .kill_sb = kill_anon_super,
109};
110
68/** 111/**
69 * anon_inode_getfile - creates a new file instance by hooking it up to an 112 * anon_inode_getfile - creates a new file instance by hooking it up to an
70 * anonymous inode, and a dentry that describe the "class" 113 * anonymous inode, and a dentry that describe the "class"
@@ -180,38 +223,6 @@ err_put_unused_fd:
180} 223}
181EXPORT_SYMBOL_GPL(anon_inode_getfd); 224EXPORT_SYMBOL_GPL(anon_inode_getfd);
182 225
183/*
184 * A single inode exists for all anon_inode files. Contrary to pipes,
185 * anon_inode inodes have no associated per-instance data, so we need
186 * only allocate one of them.
187 */
188static struct inode *anon_inode_mkinode(void)
189{
190 struct inode *inode = new_inode_pseudo(anon_inode_mnt->mnt_sb);
191
192 if (!inode)
193 return ERR_PTR(-ENOMEM);
194
195 inode->i_ino = get_next_ino();
196 inode->i_fop = &anon_inode_fops;
197
198 inode->i_mapping->a_ops = &anon_aops;
199
200 /*
201 * Mark the inode dirty from the very beginning,
202 * that way it will never be moved to the dirty
203 * list because mark_inode_dirty() will think
204 * that it already _is_ on the dirty list.
205 */
206 inode->i_state = I_DIRTY;
207 inode->i_mode = S_IRUSR | S_IWUSR;
208 inode->i_uid = current_fsuid();
209 inode->i_gid = current_fsgid();
210 inode->i_flags |= S_PRIVATE;
211 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
212 return inode;
213}
214
215static int __init anon_inode_init(void) 226static int __init anon_inode_init(void)
216{ 227{
217 int error; 228 int error;
@@ -224,16 +235,8 @@ static int __init anon_inode_init(void)
224 error = PTR_ERR(anon_inode_mnt); 235 error = PTR_ERR(anon_inode_mnt);
225 goto err_unregister_filesystem; 236 goto err_unregister_filesystem;
226 } 237 }
227 anon_inode_inode = anon_inode_mkinode();
228 if (IS_ERR(anon_inode_inode)) {
229 error = PTR_ERR(anon_inode_inode);
230 goto err_mntput;
231 }
232
233 return 0; 238 return 0;
234 239
235err_mntput:
236 kern_unmount(anon_inode_mnt);
237err_unregister_filesystem: 240err_unregister_filesystem:
238 unregister_filesystem(&anon_inode_fs_type); 241 unregister_filesystem(&anon_inode_fs_type);
239err_exit: 242err_exit:
diff --git a/fs/autofs4/init.c b/fs/autofs4/init.c
index c038727b4050..cddc74b9cdb2 100644
--- a/fs/autofs4/init.c
+++ b/fs/autofs4/init.c
@@ -31,11 +31,11 @@ static int __init init_autofs4_fs(void)
31{ 31{
32 int err; 32 int err;
33 33
34 autofs_dev_ioctl_init();
35
34 err = register_filesystem(&autofs_fs_type); 36 err = register_filesystem(&autofs_fs_type);
35 if (err) 37 if (err)
36 return err; 38 autofs_dev_ioctl_exit();
37
38 autofs_dev_ioctl_init();
39 39
40 return err; 40 return err;
41} 41}
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 06858d955120..d8dc002e9cc3 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -247,12 +247,9 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
247 if (!ino) 247 if (!ino)
248 goto fail_free; 248 goto fail_free;
249 root_inode = autofs4_get_inode(s, S_IFDIR | 0755); 249 root_inode = autofs4_get_inode(s, S_IFDIR | 0755);
250 if (!root_inode) 250 root = d_make_root(root_inode);
251 goto fail_ino;
252
253 root = d_alloc_root(root_inode);
254 if (!root) 251 if (!root)
255 goto fail_iput; 252 goto fail_ino;
256 pipe = NULL; 253 pipe = NULL;
257 254
258 root->d_fsdata = ino; 255 root->d_fsdata = ino;
@@ -317,9 +314,6 @@ fail_fput:
317fail_dput: 314fail_dput:
318 dput(root); 315 dput(root);
319 goto fail_free; 316 goto fail_free;
320fail_iput:
321 printk("autofs: get root dentry failed\n");
322 iput(root_inode);
323fail_ino: 317fail_ino:
324 kfree(ino); 318 kfree(ino);
325fail_free: 319fail_free:
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 6e6d536767fe..e18da23d42b5 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -852,9 +852,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
852 ret = PTR_ERR(root); 852 ret = PTR_ERR(root);
853 goto unacquire_priv_sbp; 853 goto unacquire_priv_sbp;
854 } 854 }
855 sb->s_root = d_alloc_root(root); 855 sb->s_root = d_make_root(root);
856 if (!sb->s_root) { 856 if (!sb->s_root) {
857 iput(root);
858 befs_error(sb, "get root inode failed"); 857 befs_error(sb, "get root inode failed");
859 goto unacquire_priv_sbp; 858 goto unacquire_priv_sbp;
860 } 859 }
diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
index b0391bc402b1..e23dc7c8b884 100644
--- a/fs/bfs/inode.c
+++ b/fs/bfs/inode.c
@@ -367,9 +367,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
367 ret = PTR_ERR(inode); 367 ret = PTR_ERR(inode);
368 goto out2; 368 goto out2;
369 } 369 }
370 s->s_root = d_alloc_root(inode); 370 s->s_root = d_make_root(inode);
371 if (!s->s_root) { 371 if (!s->s_root) {
372 iput(inode);
373 ret = -ENOMEM; 372 ret = -ENOMEM;
374 goto out2; 373 goto out2;
375 } 374 }
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 1ff94054d35a..4d5e6d26578c 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -267,7 +267,6 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
267 } 267 }
268 268
269 install_exec_creds(bprm); 269 install_exec_creds(bprm);
270 current->flags &= ~PF_FORKNOEXEC;
271 270
272 if (N_MAGIC(ex) == OMAGIC) { 271 if (N_MAGIC(ex) == OMAGIC) {
273 unsigned long text_addr, map_size; 272 unsigned long text_addr, map_size;
@@ -454,7 +453,8 @@ out:
454 453
455static int __init init_aout_binfmt(void) 454static int __init init_aout_binfmt(void)
456{ 455{
457 return register_binfmt(&aout_format); 456 register_binfmt(&aout_format);
457 return 0;
458} 458}
459 459
460static void __exit exit_aout_binfmt(void) 460static void __exit exit_aout_binfmt(void)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 07d096c49920..81878b78c9d4 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -712,7 +712,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
712 goto out_free_dentry; 712 goto out_free_dentry;
713 713
714 /* OK, This is the point of no return */ 714 /* OK, This is the point of no return */
715 current->flags &= ~PF_FORKNOEXEC;
716 current->mm->def_flags = def_flags; 715 current->mm->def_flags = def_flags;
717 716
718 /* Do this immediately, since STACK_TOP as used in setup_arg_pages 717 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
@@ -934,7 +933,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
934#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */ 933#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */
935 934
936 install_exec_creds(bprm); 935 install_exec_creds(bprm);
937 current->flags &= ~PF_FORKNOEXEC;
938 retval = create_elf_tables(bprm, &loc->elf_ex, 936 retval = create_elf_tables(bprm, &loc->elf_ex,
939 load_addr, interp_load_addr); 937 load_addr, interp_load_addr);
940 if (retval < 0) { 938 if (retval < 0) {
@@ -2077,7 +2075,8 @@ out:
2077 2075
2078static int __init init_elf_binfmt(void) 2076static int __init init_elf_binfmt(void)
2079{ 2077{
2080 return register_binfmt(&elf_format); 2078 register_binfmt(&elf_format);
2079 return 0;
2081} 2080}
2082 2081
2083static void __exit exit_elf_binfmt(void) 2082static void __exit exit_elf_binfmt(void)
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 30745f459faf..c64bf5ee2df4 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -91,7 +91,8 @@ static struct linux_binfmt elf_fdpic_format = {
91 91
92static int __init init_elf_fdpic_binfmt(void) 92static int __init init_elf_fdpic_binfmt(void)
93{ 93{
94 return register_binfmt(&elf_fdpic_format); 94 register_binfmt(&elf_fdpic_format);
95 return 0;
95} 96}
96 97
97static void __exit exit_elf_fdpic_binfmt(void) 98static void __exit exit_elf_fdpic_binfmt(void)
@@ -334,8 +335,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
334 current->mm->context.exec_fdpic_loadmap = 0; 335 current->mm->context.exec_fdpic_loadmap = 0;
335 current->mm->context.interp_fdpic_loadmap = 0; 336 current->mm->context.interp_fdpic_loadmap = 0;
336 337
337 current->flags &= ~PF_FORKNOEXEC;
338
339#ifdef CONFIG_MMU 338#ifdef CONFIG_MMU
340 elf_fdpic_arch_lay_out_mm(&exec_params, 339 elf_fdpic_arch_lay_out_mm(&exec_params,
341 &interp_params, 340 &interp_params,
@@ -413,7 +412,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
413#endif 412#endif
414 413
415 install_exec_creds(bprm); 414 install_exec_creds(bprm);
416 current->flags &= ~PF_FORKNOEXEC;
417 if (create_elf_fdpic_tables(bprm, current->mm, 415 if (create_elf_fdpic_tables(bprm, current->mm,
418 &exec_params, &interp_params) < 0) 416 &exec_params, &interp_params) < 0)
419 goto error_kill; 417 goto error_kill;
diff --git a/fs/binfmt_em86.c b/fs/binfmt_em86.c
index b8e8b0acf9bd..2790c7e1912e 100644
--- a/fs/binfmt_em86.c
+++ b/fs/binfmt_em86.c
@@ -100,7 +100,8 @@ static struct linux_binfmt em86_format = {
100 100
101static int __init init_em86_binfmt(void) 101static int __init init_em86_binfmt(void)
102{ 102{
103 return register_binfmt(&em86_format); 103 register_binfmt(&em86_format);
104 return 0;
104} 105}
105 106
106static void __exit exit_em86_binfmt(void) 107static void __exit exit_em86_binfmt(void)
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 1bffbe0ed778..04f61f0bdfde 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -902,7 +902,6 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
902 libinfo.lib_list[j].start_data:UNLOADED_LIB; 902 libinfo.lib_list[j].start_data:UNLOADED_LIB;
903 903
904 install_exec_creds(bprm); 904 install_exec_creds(bprm);
905 current->flags &= ~PF_FORKNOEXEC;
906 905
907 set_binfmt(&flat_format); 906 set_binfmt(&flat_format);
908 907
@@ -950,7 +949,8 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
950 949
951static int __init init_flat_binfmt(void) 950static int __init init_flat_binfmt(void)
952{ 951{
953 return register_binfmt(&flat_format); 952 register_binfmt(&flat_format);
953 return 0;
954} 954}
955 955
956/****************************************************************************/ 956/****************************************************************************/
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index a9198dfd5f85..1ffb60355cae 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -726,11 +726,8 @@ static struct file_system_type bm_fs_type = {
726static int __init init_misc_binfmt(void) 726static int __init init_misc_binfmt(void)
727{ 727{
728 int err = register_filesystem(&bm_fs_type); 728 int err = register_filesystem(&bm_fs_type);
729 if (!err) { 729 if (!err)
730 err = insert_binfmt(&misc_format); 730 insert_binfmt(&misc_format);
731 if (err)
732 unregister_filesystem(&bm_fs_type);
733 }
734 return err; 731 return err;
735} 732}
736 733
diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c
index 396a9884591f..d3b8c1f63155 100644
--- a/fs/binfmt_script.c
+++ b/fs/binfmt_script.c
@@ -105,7 +105,8 @@ static struct linux_binfmt script_format = {
105 105
106static int __init init_script_binfmt(void) 106static int __init init_script_binfmt(void)
107{ 107{
108 return register_binfmt(&script_format); 108 register_binfmt(&script_format);
109 return 0;
109} 110}
110 111
111static void __exit exit_script_binfmt(void) 112static void __exit exit_script_binfmt(void)
diff --git a/fs/binfmt_som.c b/fs/binfmt_som.c
index cc8560f6c9b0..e4fc746629a7 100644
--- a/fs/binfmt_som.c
+++ b/fs/binfmt_som.c
@@ -225,7 +225,6 @@ load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs)
225 goto out_free; 225 goto out_free;
226 226
227 /* OK, This is the point of no return */ 227 /* OK, This is the point of no return */
228 current->flags &= ~PF_FORKNOEXEC;
229 current->personality = PER_HPUX; 228 current->personality = PER_HPUX;
230 setup_new_exec(bprm); 229 setup_new_exec(bprm);
231 230
@@ -289,7 +288,8 @@ static int load_som_library(struct file *f)
289 288
290static int __init init_som_binfmt(void) 289static int __init init_som_binfmt(void)
291{ 290{
292 return register_binfmt(&som_format); 291 register_binfmt(&som_format);
292 return 0;
293} 293}
294 294
295static void __exit exit_som_binfmt(void) 295static void __exit exit_som_binfmt(void)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 3ce97b217cbe..81df3fec6a6d 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -629,7 +629,6 @@ static int btrfs_fill_super(struct super_block *sb,
629 void *data, int silent) 629 void *data, int silent)
630{ 630{
631 struct inode *inode; 631 struct inode *inode;
632 struct dentry *root_dentry;
633 struct btrfs_fs_info *fs_info = btrfs_sb(sb); 632 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
634 struct btrfs_key key; 633 struct btrfs_key key;
635 int err; 634 int err;
@@ -660,15 +659,12 @@ static int btrfs_fill_super(struct super_block *sb,
660 goto fail_close; 659 goto fail_close;
661 } 660 }
662 661
663 root_dentry = d_alloc_root(inode); 662 sb->s_root = d_make_root(inode);
664 if (!root_dentry) { 663 if (!sb->s_root) {
665 iput(inode);
666 err = -ENOMEM; 664 err = -ENOMEM;
667 goto fail_close; 665 goto fail_close;
668 } 666 }
669 667
670 sb->s_root = root_dentry;
671
672 save_mount_options(sb, data); 668 save_mount_options(sb, data);
673 cleancache_init_fs(sb); 669 cleancache_init_fs(sb);
674 sb->s_flags |= MS_ACTIVE; 670 sb->s_flags |= MS_ACTIVE;
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index a0358c2189cb..7f0771d3894e 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -646,7 +646,8 @@ lookup_again:
646 * (this is used to keep track of culling, and atimes are only 646 * (this is used to keep track of culling, and atimes are only
647 * updated by read, write and readdir but not lookup or 647 * updated by read, write and readdir but not lookup or
648 * open) */ 648 * open) */
649 touch_atime(cache->mnt, next); 649 path.dentry = next;
650 touch_atime(&path);
650 } 651 }
651 652
652 /* open a file interface onto a data file */ 653 /* open a file interface onto a data file */
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 00de2c9568cd..256f85221926 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -655,9 +655,8 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
655 dout("open_root_inode success\n"); 655 dout("open_root_inode success\n");
656 if (ceph_ino(inode) == CEPH_INO_ROOT && 656 if (ceph_ino(inode) == CEPH_INO_ROOT &&
657 fsc->sb->s_root == NULL) { 657 fsc->sb->s_root == NULL) {
658 root = d_alloc_root(inode); 658 root = d_make_root(inode);
659 if (!root) { 659 if (!root) {
660 iput(inode);
661 root = ERR_PTR(-ENOMEM); 660 root = ERR_PTR(-ENOMEM);
662 goto out; 661 goto out;
663 } 662 }
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index b1fd382d1952..418fc42fb8b2 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -119,12 +119,10 @@ cifs_read_super(struct super_block *sb)
119 119
120 if (IS_ERR(inode)) { 120 if (IS_ERR(inode)) {
121 rc = PTR_ERR(inode); 121 rc = PTR_ERR(inode);
122 inode = NULL;
123 goto out_no_root; 122 goto out_no_root;
124 } 123 }
125 124
126 sb->s_root = d_alloc_root(inode); 125 sb->s_root = d_make_root(inode);
127
128 if (!sb->s_root) { 126 if (!sb->s_root) {
129 rc = -ENOMEM; 127 rc = -ENOMEM;
130 goto out_no_root; 128 goto out_no_root;
@@ -147,9 +145,6 @@ cifs_read_super(struct super_block *sb)
147 145
148out_no_root: 146out_no_root:
149 cERROR(1, "cifs_read_super: get root inode failed"); 147 cERROR(1, "cifs_read_super: get root inode failed");
150 if (inode)
151 iput(inode);
152
153 return rc; 148 return rc;
154} 149}
155 150
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index 5e2e1b3f068d..05156c17b551 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -208,13 +208,12 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
208 if (IS_ERR(root)) { 208 if (IS_ERR(root)) {
209 error = PTR_ERR(root); 209 error = PTR_ERR(root);
210 printk("Failure of coda_cnode_make for root: error %d\n", error); 210 printk("Failure of coda_cnode_make for root: error %d\n", error);
211 root = NULL;
212 goto error; 211 goto error;
213 } 212 }
214 213
215 printk("coda_read_super: rootinode is %ld dev %s\n", 214 printk("coda_read_super: rootinode is %ld dev %s\n",
216 root->i_ino, root->i_sb->s_id); 215 root->i_ino, root->i_sb->s_id);
217 sb->s_root = d_alloc_root(root); 216 sb->s_root = d_make_root(root);
218 if (!sb->s_root) { 217 if (!sb->s_root) {
219 error = -EINVAL; 218 error = -EINVAL;
220 goto error; 219 goto error;
@@ -222,9 +221,6 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
222 return 0; 221 return 0;
223 222
224error: 223error:
225 if (root)
226 iput(root);
227
228 mutex_lock(&vc->vc_mutex); 224 mutex_lock(&vc->vc_mutex);
229 bdi_destroy(&vc->bdi); 225 bdi_destroy(&vc->bdi);
230 vc->vc_sb = NULL; 226 vc->vc_sb = NULL;
diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h
index ede857d20a04..b5f0a3b91f18 100644
--- a/fs/configfs/configfs_internal.h
+++ b/fs/configfs/configfs_internal.h
@@ -58,12 +58,11 @@ struct configfs_dirent {
58extern struct mutex configfs_symlink_mutex; 58extern struct mutex configfs_symlink_mutex;
59extern spinlock_t configfs_dirent_lock; 59extern spinlock_t configfs_dirent_lock;
60 60
61extern struct vfsmount * configfs_mount;
62extern struct kmem_cache *configfs_dir_cachep; 61extern struct kmem_cache *configfs_dir_cachep;
63 62
64extern int configfs_is_root(struct config_item *item); 63extern int configfs_is_root(struct config_item *item);
65 64
66extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *); 65extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *);
67extern int configfs_create(struct dentry *, umode_t mode, int (*init)(struct inode *)); 66extern int configfs_create(struct dentry *, umode_t mode, int (*init)(struct inode *));
68extern int configfs_inode_init(void); 67extern int configfs_inode_init(void);
69extern void configfs_inode_exit(void); 68extern void configfs_inode_exit(void);
@@ -80,15 +79,15 @@ extern const unsigned char * configfs_get_name(struct configfs_dirent *sd);
80extern void configfs_drop_dentry(struct configfs_dirent *sd, struct dentry *parent); 79extern void configfs_drop_dentry(struct configfs_dirent *sd, struct dentry *parent);
81extern int configfs_setattr(struct dentry *dentry, struct iattr *iattr); 80extern int configfs_setattr(struct dentry *dentry, struct iattr *iattr);
82 81
83extern int configfs_pin_fs(void); 82extern struct dentry *configfs_pin_fs(void);
84extern void configfs_release_fs(void); 83extern void configfs_release_fs(void);
85 84
86extern struct rw_semaphore configfs_rename_sem; 85extern struct rw_semaphore configfs_rename_sem;
87extern struct super_block * configfs_sb;
88extern const struct file_operations configfs_dir_operations; 86extern const struct file_operations configfs_dir_operations;
89extern const struct file_operations configfs_file_operations; 87extern const struct file_operations configfs_file_operations;
90extern const struct file_operations bin_fops; 88extern const struct file_operations bin_fops;
91extern const struct inode_operations configfs_dir_inode_operations; 89extern const struct inode_operations configfs_dir_inode_operations;
90extern const struct inode_operations configfs_root_inode_operations;
92extern const struct inode_operations configfs_symlink_inode_operations; 91extern const struct inode_operations configfs_symlink_inode_operations;
93extern const struct dentry_operations configfs_dentry_ops; 92extern const struct dentry_operations configfs_dentry_ops;
94 93
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 5ddd7ebd9dcd..7e6c52d8a207 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -264,11 +264,13 @@ static int init_symlink(struct inode * inode)
264 return 0; 264 return 0;
265} 265}
266 266
267static int create_dir(struct config_item * k, struct dentry * p, 267static int create_dir(struct config_item *k, struct dentry *d)
268 struct dentry * d)
269{ 268{
270 int error; 269 int error;
271 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; 270 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
271 struct dentry *p = d->d_parent;
272
273 BUG_ON(!k);
272 274
273 error = configfs_dirent_exists(p->d_fsdata, d->d_name.name); 275 error = configfs_dirent_exists(p->d_fsdata, d->d_name.name);
274 if (!error) 276 if (!error)
@@ -304,19 +306,7 @@ static int create_dir(struct config_item * k, struct dentry * p,
304 306
305static int configfs_create_dir(struct config_item * item, struct dentry *dentry) 307static int configfs_create_dir(struct config_item * item, struct dentry *dentry)
306{ 308{
307 struct dentry * parent; 309 int error = create_dir(item, dentry);
308 int error = 0;
309
310 BUG_ON(!item);
311
312 if (item->ci_parent)
313 parent = item->ci_parent->ci_dentry;
314 else if (configfs_mount)
315 parent = configfs_mount->mnt_root;
316 else
317 return -EFAULT;
318
319 error = create_dir(item,parent,dentry);
320 if (!error) 310 if (!error)
321 item->ci_dentry = dentry; 311 item->ci_dentry = dentry;
322 return error; 312 return error;
@@ -1079,23 +1069,24 @@ int configfs_depend_item(struct configfs_subsystem *subsys,
1079 int ret; 1069 int ret;
1080 struct configfs_dirent *p, *root_sd, *subsys_sd = NULL; 1070 struct configfs_dirent *p, *root_sd, *subsys_sd = NULL;
1081 struct config_item *s_item = &subsys->su_group.cg_item; 1071 struct config_item *s_item = &subsys->su_group.cg_item;
1072 struct dentry *root;
1082 1073
1083 /* 1074 /*
1084 * Pin the configfs filesystem. This means we can safely access 1075 * Pin the configfs filesystem. This means we can safely access
1085 * the root of the configfs filesystem. 1076 * the root of the configfs filesystem.
1086 */ 1077 */
1087 ret = configfs_pin_fs(); 1078 root = configfs_pin_fs();
1088 if (ret) 1079 if (IS_ERR(root))
1089 return ret; 1080 return PTR_ERR(root);
1090 1081
1091 /* 1082 /*
1092 * Next, lock the root directory. We're going to check that the 1083 * Next, lock the root directory. We're going to check that the
1093 * subsystem is really registered, and so we need to lock out 1084 * subsystem is really registered, and so we need to lock out
1094 * configfs_[un]register_subsystem(). 1085 * configfs_[un]register_subsystem().
1095 */ 1086 */
1096 mutex_lock(&configfs_sb->s_root->d_inode->i_mutex); 1087 mutex_lock(&root->d_inode->i_mutex);
1097 1088
1098 root_sd = configfs_sb->s_root->d_fsdata; 1089 root_sd = root->d_fsdata;
1099 1090
1100 list_for_each_entry(p, &root_sd->s_children, s_sibling) { 1091 list_for_each_entry(p, &root_sd->s_children, s_sibling) {
1101 if (p->s_type & CONFIGFS_DIR) { 1092 if (p->s_type & CONFIGFS_DIR) {
@@ -1129,7 +1120,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,
1129out_unlock_dirent_lock: 1120out_unlock_dirent_lock:
1130 spin_unlock(&configfs_dirent_lock); 1121 spin_unlock(&configfs_dirent_lock);
1131out_unlock_fs: 1122out_unlock_fs:
1132 mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex); 1123 mutex_unlock(&root->d_inode->i_mutex);
1133 1124
1134 /* 1125 /*
1135 * If we succeeded, the fs is pinned via other methods. If not, 1126 * If we succeeded, the fs is pinned via other methods. If not,
@@ -1183,11 +1174,6 @@ static int configfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
1183 struct module *subsys_owner = NULL, *new_item_owner = NULL; 1174 struct module *subsys_owner = NULL, *new_item_owner = NULL;
1184 char *name; 1175 char *name;
1185 1176
1186 if (dentry->d_parent == configfs_sb->s_root) {
1187 ret = -EPERM;
1188 goto out;
1189 }
1190
1191 sd = dentry->d_parent->d_fsdata; 1177 sd = dentry->d_parent->d_fsdata;
1192 1178
1193 /* 1179 /*
@@ -1359,9 +1345,6 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
1359 struct module *subsys_owner = NULL, *dead_item_owner = NULL; 1345 struct module *subsys_owner = NULL, *dead_item_owner = NULL;
1360 int ret; 1346 int ret;
1361 1347
1362 if (dentry->d_parent == configfs_sb->s_root)
1363 return -EPERM;
1364
1365 sd = dentry->d_fsdata; 1348 sd = dentry->d_fsdata;
1366 if (sd->s_type & CONFIGFS_USET_DEFAULT) 1349 if (sd->s_type & CONFIGFS_USET_DEFAULT)
1367 return -EPERM; 1350 return -EPERM;
@@ -1459,6 +1442,11 @@ const struct inode_operations configfs_dir_inode_operations = {
1459 .setattr = configfs_setattr, 1442 .setattr = configfs_setattr,
1460}; 1443};
1461 1444
1445const struct inode_operations configfs_root_inode_operations = {
1446 .lookup = configfs_lookup,
1447 .setattr = configfs_setattr,
1448};
1449
1462#if 0 1450#if 0
1463int configfs_rename_dir(struct config_item * item, const char *new_name) 1451int configfs_rename_dir(struct config_item * item, const char *new_name)
1464{ 1452{
@@ -1546,6 +1534,7 @@ static inline unsigned char dt_type(struct configfs_dirent *sd)
1546static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir) 1534static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1547{ 1535{
1548 struct dentry *dentry = filp->f_path.dentry; 1536 struct dentry *dentry = filp->f_path.dentry;
1537 struct super_block *sb = dentry->d_sb;
1549 struct configfs_dirent * parent_sd = dentry->d_fsdata; 1538 struct configfs_dirent * parent_sd = dentry->d_fsdata;
1550 struct configfs_dirent *cursor = filp->private_data; 1539 struct configfs_dirent *cursor = filp->private_data;
1551 struct list_head *p, *q = &cursor->s_sibling; 1540 struct list_head *p, *q = &cursor->s_sibling;
@@ -1608,7 +1597,7 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
1608 ino = inode->i_ino; 1597 ino = inode->i_ino;
1609 spin_unlock(&configfs_dirent_lock); 1598 spin_unlock(&configfs_dirent_lock);
1610 if (!inode) 1599 if (!inode)
1611 ino = iunique(configfs_sb, 2); 1600 ino = iunique(sb, 2);
1612 1601
1613 if (filldir(dirent, name, len, filp->f_pos, ino, 1602 if (filldir(dirent, name, len, filp->f_pos, ino,
1614 dt_type(next)) < 0) 1603 dt_type(next)) < 0)
@@ -1680,27 +1669,27 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1680 struct config_group *group = &subsys->su_group; 1669 struct config_group *group = &subsys->su_group;
1681 struct qstr name; 1670 struct qstr name;
1682 struct dentry *dentry; 1671 struct dentry *dentry;
1672 struct dentry *root;
1683 struct configfs_dirent *sd; 1673 struct configfs_dirent *sd;
1684 1674
1685 err = configfs_pin_fs(); 1675 root = configfs_pin_fs();
1686 if (err) 1676 if (IS_ERR(root))
1687 return err; 1677 return PTR_ERR(root);
1688 1678
1689 if (!group->cg_item.ci_name) 1679 if (!group->cg_item.ci_name)
1690 group->cg_item.ci_name = group->cg_item.ci_namebuf; 1680 group->cg_item.ci_name = group->cg_item.ci_namebuf;
1691 1681
1692 sd = configfs_sb->s_root->d_fsdata; 1682 sd = root->d_fsdata;
1693 link_group(to_config_group(sd->s_element), group); 1683 link_group(to_config_group(sd->s_element), group);
1694 1684
1695 mutex_lock_nested(&configfs_sb->s_root->d_inode->i_mutex, 1685 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT);
1696 I_MUTEX_PARENT);
1697 1686
1698 name.name = group->cg_item.ci_name; 1687 name.name = group->cg_item.ci_name;
1699 name.len = strlen(name.name); 1688 name.len = strlen(name.name);
1700 name.hash = full_name_hash(name.name, name.len); 1689 name.hash = full_name_hash(name.name, name.len);
1701 1690
1702 err = -ENOMEM; 1691 err = -ENOMEM;
1703 dentry = d_alloc(configfs_sb->s_root, &name); 1692 dentry = d_alloc(root, &name);
1704 if (dentry) { 1693 if (dentry) {
1705 d_add(dentry, NULL); 1694 d_add(dentry, NULL);
1706 1695
@@ -1717,7 +1706,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1717 } 1706 }
1718 } 1707 }
1719 1708
1720 mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex); 1709 mutex_unlock(&root->d_inode->i_mutex);
1721 1710
1722 if (err) { 1711 if (err) {
1723 unlink_group(group); 1712 unlink_group(group);
@@ -1731,13 +1720,14 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
1731{ 1720{
1732 struct config_group *group = &subsys->su_group; 1721 struct config_group *group = &subsys->su_group;
1733 struct dentry *dentry = group->cg_item.ci_dentry; 1722 struct dentry *dentry = group->cg_item.ci_dentry;
1723 struct dentry *root = dentry->d_sb->s_root;
1734 1724
1735 if (dentry->d_parent != configfs_sb->s_root) { 1725 if (dentry->d_parent != root) {
1736 printk(KERN_ERR "configfs: Tried to unregister non-subsystem!\n"); 1726 printk(KERN_ERR "configfs: Tried to unregister non-subsystem!\n");
1737 return; 1727 return;
1738 } 1728 }
1739 1729
1740 mutex_lock_nested(&configfs_sb->s_root->d_inode->i_mutex, 1730 mutex_lock_nested(&root->d_inode->i_mutex,
1741 I_MUTEX_PARENT); 1731 I_MUTEX_PARENT);
1742 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); 1732 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
1743 mutex_lock(&configfs_symlink_mutex); 1733 mutex_lock(&configfs_symlink_mutex);
@@ -1754,7 +1744,7 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
1754 1744
1755 d_delete(dentry); 1745 d_delete(dentry);
1756 1746
1757 mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex); 1747 mutex_unlock(&root->d_inode->i_mutex);
1758 1748
1759 dput(dentry); 1749 dput(dentry);
1760 1750
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 3ee36d418863..0074362d9f7f 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -44,8 +44,6 @@
44static struct lock_class_key default_group_class[MAX_LOCK_DEPTH]; 44static struct lock_class_key default_group_class[MAX_LOCK_DEPTH];
45#endif 45#endif
46 46
47extern struct super_block * configfs_sb;
48
49static const struct address_space_operations configfs_aops = { 47static const struct address_space_operations configfs_aops = {
50 .readpage = simple_readpage, 48 .readpage = simple_readpage,
51 .write_begin = simple_write_begin, 49 .write_begin = simple_write_begin,
@@ -132,9 +130,10 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
132 inode->i_ctime = iattr->ia_ctime; 130 inode->i_ctime = iattr->ia_ctime;
133} 131}
134 132
135struct inode *configfs_new_inode(umode_t mode, struct configfs_dirent * sd) 133struct inode *configfs_new_inode(umode_t mode, struct configfs_dirent *sd,
134 struct super_block *s)
136{ 135{
137 struct inode * inode = new_inode(configfs_sb); 136 struct inode * inode = new_inode(s);
138 if (inode) { 137 if (inode) {
139 inode->i_ino = get_next_ino(); 138 inode->i_ino = get_next_ino();
140 inode->i_mapping->a_ops = &configfs_aops; 139 inode->i_mapping->a_ops = &configfs_aops;
@@ -188,36 +187,35 @@ static void configfs_set_inode_lock_class(struct configfs_dirent *sd,
188int configfs_create(struct dentry * dentry, umode_t mode, int (*init)(struct inode *)) 187int configfs_create(struct dentry * dentry, umode_t mode, int (*init)(struct inode *))
189{ 188{
190 int error = 0; 189 int error = 0;
191 struct inode * inode = NULL; 190 struct inode *inode = NULL;
192 if (dentry) { 191 struct configfs_dirent *sd;
193 if (!dentry->d_inode) { 192 struct inode *p_inode;
194 struct configfs_dirent *sd = dentry->d_fsdata; 193
195 if ((inode = configfs_new_inode(mode, sd))) { 194 if (!dentry)
196 if (dentry->d_parent && dentry->d_parent->d_inode) { 195 return -ENOENT;
197 struct inode *p_inode = dentry->d_parent->d_inode; 196
198 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME; 197 if (dentry->d_inode)
199 } 198 return -EEXIST;
200 configfs_set_inode_lock_class(sd, inode);
201 goto Proceed;
202 }
203 else
204 error = -ENOMEM;
205 } else
206 error = -EEXIST;
207 } else
208 error = -ENOENT;
209 goto Done;
210 199
211 Proceed: 200 sd = dentry->d_fsdata;
212 if (init) 201 inode = configfs_new_inode(mode, sd, dentry->d_sb);
202 if (!inode)
203 return -ENOMEM;
204
205 p_inode = dentry->d_parent->d_inode;
206 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
207 configfs_set_inode_lock_class(sd, inode);
208
209 if (init) {
213 error = init(inode); 210 error = init(inode);
214 if (!error) { 211 if (error) {
215 d_instantiate(dentry, inode); 212 iput(inode);
216 if (S_ISDIR(mode) || S_ISLNK(mode)) 213 return error;
217 dget(dentry); /* pin link and directory dentries in core */ 214 }
218 } else 215 }
219 iput(inode); 216 d_instantiate(dentry, inode);
220 Done: 217 if (S_ISDIR(mode) || S_ISLNK(mode))
218 dget(dentry); /* pin link and directory dentries in core */
221 return error; 219 return error;
222} 220}
223 221
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 276e15cafd58..aee0a7ebbd8e 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -37,8 +37,7 @@
37/* Random magic number */ 37/* Random magic number */
38#define CONFIGFS_MAGIC 0x62656570 38#define CONFIGFS_MAGIC 0x62656570
39 39
40struct vfsmount * configfs_mount = NULL; 40static struct vfsmount *configfs_mount = NULL;
41struct super_block * configfs_sb = NULL;
42struct kmem_cache *configfs_dir_cachep; 41struct kmem_cache *configfs_dir_cachep;
43static int configfs_mnt_count = 0; 42static int configfs_mnt_count = 0;
44 43
@@ -77,12 +76,11 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent)
77 sb->s_magic = CONFIGFS_MAGIC; 76 sb->s_magic = CONFIGFS_MAGIC;
78 sb->s_op = &configfs_ops; 77 sb->s_op = &configfs_ops;
79 sb->s_time_gran = 1; 78 sb->s_time_gran = 1;
80 configfs_sb = sb;
81 79
82 inode = configfs_new_inode(S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO, 80 inode = configfs_new_inode(S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
83 &configfs_root); 81 &configfs_root, sb);
84 if (inode) { 82 if (inode) {
85 inode->i_op = &configfs_dir_inode_operations; 83 inode->i_op = &configfs_root_inode_operations;
86 inode->i_fop = &configfs_dir_operations; 84 inode->i_fop = &configfs_dir_operations;
87 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 85 /* directory inodes start off with i_nlink == 2 (for "." entry) */
88 inc_nlink(inode); 86 inc_nlink(inode);
@@ -91,10 +89,9 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent)
91 return -ENOMEM; 89 return -ENOMEM;
92 } 90 }
93 91
94 root = d_alloc_root(inode); 92 root = d_make_root(inode);
95 if (!root) { 93 if (!root) {
96 pr_debug("%s: could not get root dentry!\n",__func__); 94 pr_debug("%s: could not get root dentry!\n",__func__);
97 iput(inode);
98 return -ENOMEM; 95 return -ENOMEM;
99 } 96 }
100 config_group_init(&configfs_root_group); 97 config_group_init(&configfs_root_group);
@@ -118,10 +115,11 @@ static struct file_system_type configfs_fs_type = {
118 .kill_sb = kill_litter_super, 115 .kill_sb = kill_litter_super,
119}; 116};
120 117
121int configfs_pin_fs(void) 118struct dentry *configfs_pin_fs(void)
122{ 119{
123 return simple_pin_fs(&configfs_fs_type, &configfs_mount, 120 int err = simple_pin_fs(&configfs_fs_type, &configfs_mount,
124 &configfs_mnt_count); 121 &configfs_mnt_count);
122 return err ? ERR_PTR(err) : configfs_mount->mnt_root;
125} 123}
126 124
127void configfs_release_fs(void) 125void configfs_release_fs(void)
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index 0f3eb41d9201..cc9f2546ea4a 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -110,13 +110,13 @@ out:
110 110
111 111
112static int get_target(const char *symname, struct path *path, 112static int get_target(const char *symname, struct path *path,
113 struct config_item **target) 113 struct config_item **target, struct super_block *sb)
114{ 114{
115 int ret; 115 int ret;
116 116
117 ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path); 117 ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path);
118 if (!ret) { 118 if (!ret) {
119 if (path->dentry->d_sb == configfs_sb) { 119 if (path->dentry->d_sb == sb) {
120 *target = configfs_get_config_item(path->dentry); 120 *target = configfs_get_config_item(path->dentry);
121 if (!*target) { 121 if (!*target) {
122 ret = -ENOENT; 122 ret = -ENOENT;
@@ -141,10 +141,6 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
141 struct config_item *target_item = NULL; 141 struct config_item *target_item = NULL;
142 struct config_item_type *type; 142 struct config_item_type *type;
143 143
144 ret = -EPERM; /* What lack-of-symlink returns */
145 if (dentry->d_parent == configfs_sb->s_root)
146 goto out;
147
148 sd = dentry->d_parent->d_fsdata; 144 sd = dentry->d_parent->d_fsdata;
149 /* 145 /*
150 * Fake invisibility if dir belongs to a group/default groups hierarchy 146 * Fake invisibility if dir belongs to a group/default groups hierarchy
@@ -162,7 +158,7 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
162 !type->ct_item_ops->allow_link) 158 !type->ct_item_ops->allow_link)
163 goto out_put; 159 goto out_put;
164 160
165 ret = get_target(symname, &path, &target_item); 161 ret = get_target(symname, &path, &target_item, dentry->d_sb);
166 if (ret) 162 if (ret)
167 goto out_put; 163 goto out_put;
168 164
@@ -198,8 +194,6 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
198 if (!(sd->s_type & CONFIGFS_ITEM_LINK)) 194 if (!(sd->s_type & CONFIGFS_ITEM_LINK))
199 goto out; 195 goto out;
200 196
201 BUG_ON(dentry->d_parent == configfs_sb->s_root);
202
203 sl = sd->s_element; 197 sl = sd->s_element;
204 198
205 parent_item = configfs_get_config_item(dentry->d_parent); 199 parent_item = configfs_get_config_item(dentry->d_parent);
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 04d51f9333d7..d013c46402ed 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -318,11 +318,9 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent)
318 root = get_cramfs_inode(sb, &super.root, 0); 318 root = get_cramfs_inode(sb, &super.root, 0);
319 if (IS_ERR(root)) 319 if (IS_ERR(root))
320 goto out; 320 goto out;
321 sb->s_root = d_alloc_root(root); 321 sb->s_root = d_make_root(root);
322 if (!sb->s_root) { 322 if (!sb->s_root)
323 iput(root);
324 goto out; 323 goto out;
325 }
326 return 0; 324 return 0;
327out: 325out:
328 kfree(sbi); 326 kfree(sbi);
diff --git a/fs/dcache.c b/fs/dcache.c
index 11828de68dce..e441941c834d 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1466,30 +1466,6 @@ struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode)
1466 1466
1467EXPORT_SYMBOL(d_instantiate_unique); 1467EXPORT_SYMBOL(d_instantiate_unique);
1468 1468
1469/**
1470 * d_alloc_root - allocate root dentry
1471 * @root_inode: inode to allocate the root for
1472 *
1473 * Allocate a root ("/") dentry for the inode given. The inode is
1474 * instantiated and returned. %NULL is returned if there is insufficient
1475 * memory or the inode passed is %NULL.
1476 */
1477
1478struct dentry * d_alloc_root(struct inode * root_inode)
1479{
1480 struct dentry *res = NULL;
1481
1482 if (root_inode) {
1483 static const struct qstr name = { .name = "/", .len = 1 };
1484
1485 res = __d_alloc(root_inode->i_sb, &name);
1486 if (res)
1487 d_instantiate(res, root_inode);
1488 }
1489 return res;
1490}
1491EXPORT_SYMBOL(d_alloc_root);
1492
1493struct dentry *d_make_root(struct inode *root_inode) 1469struct dentry *d_make_root(struct inode *root_inode)
1494{ 1470{
1495 struct dentry *res = NULL; 1471 struct dentry *res = NULL;
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index ef023eef0464..21e93605161c 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -611,7 +611,7 @@ static const struct file_operations fops_regset32 = {
611 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling 611 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
612 * code. 612 * code.
613 */ 613 */
614struct dentry *debugfs_create_regset32(const char *name, mode_t mode, 614struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
615 struct dentry *parent, 615 struct dentry *parent,
616 struct debugfs_regset32 *regset) 616 struct debugfs_regset32 *regset)
617{ 617{
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 1c6f908e38ca..10f5e0b484db 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -374,12 +374,11 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
374 inode->i_fop = &simple_dir_operations; 374 inode->i_fop = &simple_dir_operations;
375 set_nlink(inode, 2); 375 set_nlink(inode, 2);
376 376
377 s->s_root = d_alloc_root(inode); 377 s->s_root = d_make_root(inode);
378 if (s->s_root) 378 if (s->s_root)
379 return 0; 379 return 0;
380 380
381 printk(KERN_ERR "devpts: get root dentry failed\n"); 381 printk(KERN_ERR "devpts: get root dentry failed\n");
382 iput(inode);
383 382
384fail: 383fail:
385 return -ENOMEM; 384 return -ENOMEM;
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index d3f95f941c47..2b17f2f9b121 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -48,8 +48,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
48 unsigned long nr_segs, loff_t pos) 48 unsigned long nr_segs, loff_t pos)
49{ 49{
50 ssize_t rc; 50 ssize_t rc;
51 struct dentry *lower_dentry; 51 struct path lower;
52 struct vfsmount *lower_vfsmount;
53 struct file *file = iocb->ki_filp; 52 struct file *file = iocb->ki_filp;
54 53
55 rc = generic_file_aio_read(iocb, iov, nr_segs, pos); 54 rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
@@ -60,9 +59,9 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
60 if (-EIOCBQUEUED == rc) 59 if (-EIOCBQUEUED == rc)
61 rc = wait_on_sync_kiocb(iocb); 60 rc = wait_on_sync_kiocb(iocb);
62 if (rc >= 0) { 61 if (rc >= 0) {
63 lower_dentry = ecryptfs_dentry_to_lower(file->f_path.dentry); 62 lower.dentry = ecryptfs_dentry_to_lower(file->f_path.dentry);
64 lower_vfsmount = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry); 63 lower.mnt = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry);
65 touch_atime(lower_vfsmount, lower_dentry); 64 touch_atime(&lower);
66 } 65 }
67 return rc; 66 return rc;
68} 67}
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index b4a6befb1216..68954937a071 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -550,9 +550,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
550 if (IS_ERR(inode)) 550 if (IS_ERR(inode))
551 goto out_free; 551 goto out_free;
552 552
553 s->s_root = d_alloc_root(inode); 553 s->s_root = d_make_root(inode);
554 if (!s->s_root) { 554 if (!s->s_root) {
555 iput(inode);
556 rc = -ENOMEM; 555 rc = -ENOMEM;
557 goto out_free; 556 goto out_free;
558 } 557 }
@@ -795,15 +794,10 @@ static int __init ecryptfs_init(void)
795 "Failed to allocate one or more kmem_cache objects\n"); 794 "Failed to allocate one or more kmem_cache objects\n");
796 goto out; 795 goto out;
797 } 796 }
798 rc = register_filesystem(&ecryptfs_fs_type);
799 if (rc) {
800 printk(KERN_ERR "Failed to register filesystem\n");
801 goto out_free_kmem_caches;
802 }
803 rc = do_sysfs_registration(); 797 rc = do_sysfs_registration();
804 if (rc) { 798 if (rc) {
805 printk(KERN_ERR "sysfs registration failed\n"); 799 printk(KERN_ERR "sysfs registration failed\n");
806 goto out_unregister_filesystem; 800 goto out_free_kmem_caches;
807 } 801 }
808 rc = ecryptfs_init_kthread(); 802 rc = ecryptfs_init_kthread();
809 if (rc) { 803 if (rc) {
@@ -824,19 +818,24 @@ static int __init ecryptfs_init(void)
824 "rc = [%d]\n", rc); 818 "rc = [%d]\n", rc);
825 goto out_release_messaging; 819 goto out_release_messaging;
826 } 820 }
821 rc = register_filesystem(&ecryptfs_fs_type);
822 if (rc) {
823 printk(KERN_ERR "Failed to register filesystem\n");
824 goto out_destroy_crypto;
825 }
827 if (ecryptfs_verbosity > 0) 826 if (ecryptfs_verbosity > 0)
828 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values " 827 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
829 "will be written to the syslog!\n", ecryptfs_verbosity); 828 "will be written to the syslog!\n", ecryptfs_verbosity);
830 829
831 goto out; 830 goto out;
831out_destroy_crypto:
832 ecryptfs_destroy_crypto();
832out_release_messaging: 833out_release_messaging:
833 ecryptfs_release_messaging(); 834 ecryptfs_release_messaging();
834out_destroy_kthread: 835out_destroy_kthread:
835 ecryptfs_destroy_kthread(); 836 ecryptfs_destroy_kthread();
836out_do_sysfs_unregistration: 837out_do_sysfs_unregistration:
837 do_sysfs_unregistration(); 838 do_sysfs_unregistration();
838out_unregister_filesystem:
839 unregister_filesystem(&ecryptfs_fs_type);
840out_free_kmem_caches: 839out_free_kmem_caches:
841 ecryptfs_free_kmem_caches(); 840 ecryptfs_free_kmem_caches();
842out: 841out:
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c
index cf152823bbf4..2dd946b636d2 100644
--- a/fs/ecryptfs/super.c
+++ b/fs/ecryptfs/super.c
@@ -184,7 +184,6 @@ static int ecryptfs_show_options(struct seq_file *m, struct dentry *root)
184const struct super_operations ecryptfs_sops = { 184const struct super_operations ecryptfs_sops = {
185 .alloc_inode = ecryptfs_alloc_inode, 185 .alloc_inode = ecryptfs_alloc_inode,
186 .destroy_inode = ecryptfs_destroy_inode, 186 .destroy_inode = ecryptfs_destroy_inode,
187 .drop_inode = generic_drop_inode,
188 .statfs = ecryptfs_statfs, 187 .statfs = ecryptfs_statfs,
189 .remount_fs = NULL, 188 .remount_fs = NULL,
190 .evict_inode = ecryptfs_evict_inode, 189 .evict_inode = ecryptfs_evict_inode,
diff --git a/fs/efs/super.c b/fs/efs/super.c
index 981106429a9f..e755ec746c69 100644
--- a/fs/efs/super.c
+++ b/fs/efs/super.c
@@ -317,10 +317,9 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
317 goto out_no_fs; 317 goto out_no_fs;
318 } 318 }
319 319
320 s->s_root = d_alloc_root(root); 320 s->s_root = d_make_root(root);
321 if (!(s->s_root)) { 321 if (!(s->s_root)) {
322 printk(KERN_ERR "EFS: get root dentry failed\n"); 322 printk(KERN_ERR "EFS: get root dentry failed\n");
323 iput(root);
324 ret = -ENOMEM; 323 ret = -ENOMEM;
325 goto out_no_fs; 324 goto out_no_fs;
326 } 325 }
diff --git a/fs/exec.c b/fs/exec.c
index 3908544f5d18..0b931471d4f4 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -81,15 +81,13 @@ static atomic_t call_count = ATOMIC_INIT(1);
81static LIST_HEAD(formats); 81static LIST_HEAD(formats);
82static DEFINE_RWLOCK(binfmt_lock); 82static DEFINE_RWLOCK(binfmt_lock);
83 83
84int __register_binfmt(struct linux_binfmt * fmt, int insert) 84void __register_binfmt(struct linux_binfmt * fmt, int insert)
85{ 85{
86 if (!fmt) 86 BUG_ON(!fmt);
87 return -EINVAL;
88 write_lock(&binfmt_lock); 87 write_lock(&binfmt_lock);
89 insert ? list_add(&fmt->lh, &formats) : 88 insert ? list_add(&fmt->lh, &formats) :
90 list_add_tail(&fmt->lh, &formats); 89 list_add_tail(&fmt->lh, &formats);
91 write_unlock(&binfmt_lock); 90 write_unlock(&binfmt_lock);
92 return 0;
93} 91}
94 92
95EXPORT_SYMBOL(__register_binfmt); 93EXPORT_SYMBOL(__register_binfmt);
@@ -1115,7 +1113,7 @@ int flush_old_exec(struct linux_binprm * bprm)
1115 bprm->mm = NULL; /* We're using it now */ 1113 bprm->mm = NULL; /* We're using it now */
1116 1114
1117 set_fs(USER_DS); 1115 set_fs(USER_DS);
1118 current->flags &= ~(PF_RANDOMIZE | PF_KTHREAD); 1116 current->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD);
1119 flush_thread(); 1117 flush_thread();
1120 current->personality &= ~bprm->per_clear; 1118 current->personality &= ~bprm->per_clear;
1121 1119
diff --git a/fs/exofs/namei.c b/fs/exofs/namei.c
index 9dbf0c301030..fc7161d6bf6b 100644
--- a/fs/exofs/namei.c
+++ b/fs/exofs/namei.c
@@ -143,9 +143,6 @@ static int exofs_link(struct dentry *old_dentry, struct inode *dir,
143{ 143{
144 struct inode *inode = old_dentry->d_inode; 144 struct inode *inode = old_dentry->d_inode;
145 145
146 if (inode->i_nlink >= EXOFS_LINK_MAX)
147 return -EMLINK;
148
149 inode->i_ctime = CURRENT_TIME; 146 inode->i_ctime = CURRENT_TIME;
150 inode_inc_link_count(inode); 147 inode_inc_link_count(inode);
151 ihold(inode); 148 ihold(inode);
@@ -156,10 +153,7 @@ static int exofs_link(struct dentry *old_dentry, struct inode *dir,
156static int exofs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 153static int exofs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
157{ 154{
158 struct inode *inode; 155 struct inode *inode;
159 int err = -EMLINK; 156 int err;
160
161 if (dir->i_nlink >= EXOFS_LINK_MAX)
162 goto out;
163 157
164 inode_inc_link_count(dir); 158 inode_inc_link_count(dir);
165 159
@@ -275,11 +269,6 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
275 if (err) 269 if (err)
276 goto out_dir; 270 goto out_dir;
277 } else { 271 } else {
278 if (dir_de) {
279 err = -EMLINK;
280 if (new_dir->i_nlink >= EXOFS_LINK_MAX)
281 goto out_dir;
282 }
283 err = exofs_add_link(new_dentry, old_inode); 272 err = exofs_add_link(new_dentry, old_inode);
284 if (err) 273 if (err)
285 goto out_dir; 274 goto out_dir;
diff --git a/fs/exofs/super.c b/fs/exofs/super.c
index d22cd168c6ee..7f2b590a36b7 100644
--- a/fs/exofs/super.c
+++ b/fs/exofs/super.c
@@ -754,6 +754,7 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
754 sb->s_blocksize = EXOFS_BLKSIZE; 754 sb->s_blocksize = EXOFS_BLKSIZE;
755 sb->s_blocksize_bits = EXOFS_BLKSHIFT; 755 sb->s_blocksize_bits = EXOFS_BLKSHIFT;
756 sb->s_maxbytes = MAX_LFS_FILESIZE; 756 sb->s_maxbytes = MAX_LFS_FILESIZE;
757 sb->s_max_links = EXOFS_LINK_MAX;
757 atomic_set(&sbi->s_curr_pending, 0); 758 atomic_set(&sbi->s_curr_pending, 0);
758 sb->s_bdev = NULL; 759 sb->s_bdev = NULL;
759 sb->s_dev = 0; 760 sb->s_dev = 0;
@@ -818,9 +819,8 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
818 ret = PTR_ERR(root); 819 ret = PTR_ERR(root);
819 goto free_sbi; 820 goto free_sbi;
820 } 821 }
821 sb->s_root = d_alloc_root(root); 822 sb->s_root = d_make_root(root);
822 if (!sb->s_root) { 823 if (!sb->s_root) {
823 iput(root);
824 EXOFS_ERR("ERROR: get root inode failed\n"); 824 EXOFS_ERR("ERROR: get root inode failed\n");
825 ret = -ENOMEM; 825 ret = -ENOMEM;
826 goto free_sbi; 826 goto free_sbi;
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 080419814bae..dffb86536285 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -195,9 +195,6 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,
195 struct inode *inode = old_dentry->d_inode; 195 struct inode *inode = old_dentry->d_inode;
196 int err; 196 int err;
197 197
198 if (inode->i_nlink >= EXT2_LINK_MAX)
199 return -EMLINK;
200
201 dquot_initialize(dir); 198 dquot_initialize(dir);
202 199
203 inode->i_ctime = CURRENT_TIME_SEC; 200 inode->i_ctime = CURRENT_TIME_SEC;
@@ -217,10 +214,7 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,
217static int ext2_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode) 214static int ext2_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
218{ 215{
219 struct inode * inode; 216 struct inode * inode;
220 int err = -EMLINK; 217 int err;
221
222 if (dir->i_nlink >= EXT2_LINK_MAX)
223 goto out;
224 218
225 dquot_initialize(dir); 219 dquot_initialize(dir);
226 220
@@ -346,11 +340,6 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
346 drop_nlink(new_inode); 340 drop_nlink(new_inode);
347 inode_dec_link_count(new_inode); 341 inode_dec_link_count(new_inode);
348 } else { 342 } else {
349 if (dir_de) {
350 err = -EMLINK;
351 if (new_dir->i_nlink >= EXT2_LINK_MAX)
352 goto out_dir;
353 }
354 err = ext2_add_link(new_dentry, old_inode); 343 err = ext2_add_link(new_dentry, old_inode);
355 if (err) 344 if (err)
356 goto out_dir; 345 goto out_dir;
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 0090595beb28..e1025c7a437a 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -919,6 +919,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
919 } 919 }
920 920
921 sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits); 921 sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
922 sb->s_max_links = EXT2_LINK_MAX;
922 923
923 if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) { 924 if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
924 sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; 925 sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
@@ -1087,9 +1088,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
1087 goto failed_mount3; 1088 goto failed_mount3;
1088 } 1089 }
1089 1090
1090 sb->s_root = d_alloc_root(root); 1091 sb->s_root = d_make_root(root);
1091 if (!sb->s_root) { 1092 if (!sb->s_root) {
1092 iput(root);
1093 ext2_msg(sb, KERN_ERR, "error: get root inode failed"); 1093 ext2_msg(sb, KERN_ERR, "error: get root inode failed");
1094 ret = -ENOMEM; 1094 ret = -ENOMEM;
1095 goto failed_mount3; 1095 goto failed_mount3;
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 726c7ef6cdf1..e0b45b93327b 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -2046,10 +2046,9 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
2046 ext3_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck"); 2046 ext3_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
2047 goto failed_mount3; 2047 goto failed_mount3;
2048 } 2048 }
2049 sb->s_root = d_alloc_root(root); 2049 sb->s_root = d_make_root(root);
2050 if (!sb->s_root) { 2050 if (!sb->s_root) {
2051 ext3_msg(sb, KERN_ERR, "error: get root dentry failed"); 2051 ext3_msg(sb, KERN_ERR, "error: get root dentry failed");
2052 iput(root);
2053 ret = -ENOMEM; 2052 ret = -ENOMEM;
2054 goto failed_mount3; 2053 goto failed_mount3;
2055 } 2054 }
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 502c61fd7392..933900909ed0 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3735,9 +3735,8 @@ no_journal:
3735 iput(root); 3735 iput(root);
3736 goto failed_mount4; 3736 goto failed_mount4;
3737 } 3737 }
3738 sb->s_root = d_alloc_root(root); 3738 sb->s_root = d_make_root(root);
3739 if (!sb->s_root) { 3739 if (!sb->s_root) {
3740 iput(root);
3741 ext4_msg(sb, KERN_ERR, "get root dentry failed"); 3740 ext4_msg(sb, KERN_ERR, "get root dentry failed");
3742 ret = -ENOMEM; 3741 ret = -ENOMEM;
3743 goto failed_mount4; 3742 goto failed_mount4;
@@ -5056,6 +5055,9 @@ static int __init ext4_init_fs(void)
5056{ 5055{
5057 int i, err; 5056 int i, err;
5058 5057
5058 ext4_li_info = NULL;
5059 mutex_init(&ext4_li_mtx);
5060
5059 ext4_check_flag_values(); 5061 ext4_check_flag_values();
5060 5062
5061 for (i = 0; i < EXT4_WQ_HASH_SZ; i++) { 5063 for (i = 0; i < EXT4_WQ_HASH_SZ; i++) {
@@ -5094,8 +5096,6 @@ static int __init ext4_init_fs(void)
5094 if (err) 5096 if (err)
5095 goto out; 5097 goto out;
5096 5098
5097 ext4_li_info = NULL;
5098 mutex_init(&ext4_li_mtx);
5099 return 0; 5099 return 0;
5100out: 5100out:
5101 unregister_as_ext2(); 5101 unregister_as_ext2();
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 3ab841054d53..21687e31acc0 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1496,11 +1496,13 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
1496 root_inode->i_ino = MSDOS_ROOT_INO; 1496 root_inode->i_ino = MSDOS_ROOT_INO;
1497 root_inode->i_version = 1; 1497 root_inode->i_version = 1;
1498 error = fat_read_root(root_inode); 1498 error = fat_read_root(root_inode);
1499 if (error < 0) 1499 if (error < 0) {
1500 iput(root_inode);
1500 goto out_fail; 1501 goto out_fail;
1502 }
1501 error = -ENOMEM; 1503 error = -ENOMEM;
1502 insert_inode_hash(root_inode); 1504 insert_inode_hash(root_inode);
1503 sb->s_root = d_alloc_root(root_inode); 1505 sb->s_root = d_make_root(root_inode);
1504 if (!sb->s_root) { 1506 if (!sb->s_root) {
1505 fat_msg(sb, KERN_ERR, "get root inode failed"); 1507 fat_msg(sb, KERN_ERR, "get root inode failed");
1506 goto out_fail; 1508 goto out_fail;
@@ -1516,8 +1518,6 @@ out_invalid:
1516out_fail: 1518out_fail:
1517 if (fat_inode) 1519 if (fat_inode)
1518 iput(fat_inode); 1520 iput(fat_inode);
1519 if (root_inode)
1520 iput(root_inode);
1521 unload_nls(sbi->nls_io); 1521 unload_nls(sbi->nls_io);
1522 unload_nls(sbi->nls_disk); 1522 unload_nls(sbi->nls_disk);
1523 if (sbi->options.iocharset != fat_default_iocharset) 1523 if (sbi->options.iocharset != fat_default_iocharset)
diff --git a/fs/file_table.c b/fs/file_table.c
index 20002e39754d..70f2a0fd6aec 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -204,7 +204,7 @@ EXPORT_SYMBOL(alloc_file);
204 * to write to @file, along with access to write through 204 * to write to @file, along with access to write through
205 * its vfsmount. 205 * its vfsmount.
206 */ 206 */
207void drop_file_write_access(struct file *file) 207static void drop_file_write_access(struct file *file)
208{ 208{
209 struct vfsmount *mnt = file->f_path.mnt; 209 struct vfsmount *mnt = file->f_path.mnt;
210 struct dentry *dentry = file->f_path.dentry; 210 struct dentry *dentry = file->f_path.dentry;
@@ -219,7 +219,6 @@ void drop_file_write_access(struct file *file)
219 mnt_drop_write(mnt); 219 mnt_drop_write(mnt);
220 file_release_write(file); 220 file_release_write(file);
221} 221}
222EXPORT_SYMBOL_GPL(drop_file_write_access);
223 222
224/* the real guts of fput() - releasing the last reference to file 223/* the real guts of fput() - releasing the last reference to file
225 */ 224 */
diff --git a/fs/freevxfs/vxfs_super.c b/fs/freevxfs/vxfs_super.c
index 9d1c99558389..d4fabd26084e 100644
--- a/fs/freevxfs/vxfs_super.c
+++ b/fs/freevxfs/vxfs_super.c
@@ -224,9 +224,8 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
224 ret = PTR_ERR(root); 224 ret = PTR_ERR(root);
225 goto out; 225 goto out;
226 } 226 }
227 sbp->s_root = d_alloc_root(root); 227 sbp->s_root = d_make_root(root);
228 if (!sbp->s_root) { 228 if (!sbp->s_root) {
229 iput(root);
230 printk(KERN_WARNING "vxfs: unable to get root dentry.\n"); 229 printk(KERN_WARNING "vxfs: unable to get root dentry.\n");
231 goto out_free_ilist; 230 goto out_free_ilist;
232 } 231 }
diff --git a/fs/fs_struct.c b/fs/fs_struct.c
index 78b519c13536..6324c4274959 100644
--- a/fs/fs_struct.c
+++ b/fs/fs_struct.c
@@ -26,11 +26,11 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
26{ 26{
27 struct path old_root; 27 struct path old_root;
28 28
29 path_get_longterm(path);
29 spin_lock(&fs->lock); 30 spin_lock(&fs->lock);
30 write_seqcount_begin(&fs->seq); 31 write_seqcount_begin(&fs->seq);
31 old_root = fs->root; 32 old_root = fs->root;
32 fs->root = *path; 33 fs->root = *path;
33 path_get_longterm(path);
34 write_seqcount_end(&fs->seq); 34 write_seqcount_end(&fs->seq);
35 spin_unlock(&fs->lock); 35 spin_unlock(&fs->lock);
36 if (old_root.dentry) 36 if (old_root.dentry)
@@ -45,11 +45,11 @@ void set_fs_pwd(struct fs_struct *fs, struct path *path)
45{ 45{
46 struct path old_pwd; 46 struct path old_pwd;
47 47
48 path_get_longterm(path);
48 spin_lock(&fs->lock); 49 spin_lock(&fs->lock);
49 write_seqcount_begin(&fs->seq); 50 write_seqcount_begin(&fs->seq);
50 old_pwd = fs->pwd; 51 old_pwd = fs->pwd;
51 fs->pwd = *path; 52 fs->pwd = *path;
52 path_get_longterm(path);
53 write_seqcount_end(&fs->seq); 53 write_seqcount_end(&fs->seq);
54 spin_unlock(&fs->lock); 54 spin_unlock(&fs->lock);
55 55
@@ -57,6 +57,14 @@ void set_fs_pwd(struct fs_struct *fs, struct path *path)
57 path_put_longterm(&old_pwd); 57 path_put_longterm(&old_pwd);
58} 58}
59 59
60static inline int replace_path(struct path *p, const struct path *old, const struct path *new)
61{
62 if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
63 return 0;
64 *p = *new;
65 return 1;
66}
67
60void chroot_fs_refs(struct path *old_root, struct path *new_root) 68void chroot_fs_refs(struct path *old_root, struct path *new_root)
61{ 69{
62 struct task_struct *g, *p; 70 struct task_struct *g, *p;
@@ -68,21 +76,16 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
68 task_lock(p); 76 task_lock(p);
69 fs = p->fs; 77 fs = p->fs;
70 if (fs) { 78 if (fs) {
79 int hits = 0;
71 spin_lock(&fs->lock); 80 spin_lock(&fs->lock);
72 write_seqcount_begin(&fs->seq); 81 write_seqcount_begin(&fs->seq);
73 if (fs->root.dentry == old_root->dentry 82 hits += replace_path(&fs->root, old_root, new_root);
74 && fs->root.mnt == old_root->mnt) { 83 hits += replace_path(&fs->pwd, old_root, new_root);
75 path_get_longterm(new_root); 84 write_seqcount_end(&fs->seq);
76 fs->root = *new_root; 85 while (hits--) {
77 count++; 86 count++;
78 }
79 if (fs->pwd.dentry == old_root->dentry
80 && fs->pwd.mnt == old_root->mnt) {
81 path_get_longterm(new_root); 87 path_get_longterm(new_root);
82 fs->pwd = *new_root;
83 count++;
84 } 88 }
85 write_seqcount_end(&fs->seq);
86 spin_unlock(&fs->lock); 89 spin_unlock(&fs->lock);
87 } 90 }
88 task_unlock(p); 91 task_unlock(p);
@@ -107,10 +110,8 @@ void exit_fs(struct task_struct *tsk)
107 int kill; 110 int kill;
108 task_lock(tsk); 111 task_lock(tsk);
109 spin_lock(&fs->lock); 112 spin_lock(&fs->lock);
110 write_seqcount_begin(&fs->seq);
111 tsk->fs = NULL; 113 tsk->fs = NULL;
112 kill = !--fs->users; 114 kill = !--fs->users;
113 write_seqcount_end(&fs->seq);
114 spin_unlock(&fs->lock); 115 spin_unlock(&fs->lock);
115 task_unlock(tsk); 116 task_unlock(tsk);
116 if (kill) 117 if (kill)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 64cf8d07393e..4aec5995867e 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -988,14 +988,9 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
988 988
989 err = -ENOMEM; 989 err = -ENOMEM;
990 root = fuse_get_root_inode(sb, d.rootmode); 990 root = fuse_get_root_inode(sb, d.rootmode);
991 if (!root) 991 root_dentry = d_make_root(root);
992 if (!root_dentry)
992 goto err_put_conn; 993 goto err_put_conn;
993
994 root_dentry = d_alloc_root(root);
995 if (!root_dentry) {
996 iput(root);
997 goto err_put_conn;
998 }
999 /* only now - we want root dentry with NULL ->d_op */ 994 /* only now - we want root dentry with NULL ->d_op */
1000 sb->s_d_op = &fuse_dentry_operations; 995 sb->s_d_op = &fuse_dentry_operations;
1001 996
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 24f609c9ef91..10e848c6d1b5 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -431,10 +431,9 @@ static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr,
431 fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode)); 431 fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode));
432 return PTR_ERR(inode); 432 return PTR_ERR(inode);
433 } 433 }
434 dentry = d_alloc_root(inode); 434 dentry = d_make_root(inode);
435 if (!dentry) { 435 if (!dentry) {
436 fs_err(sdp, "can't alloc %s dentry\n", name); 436 fs_err(sdp, "can't alloc %s dentry\n", name);
437 iput(inode);
438 return -ENOMEM; 437 return -ENOMEM;
439 } 438 }
440 *dptr = dentry; 439 *dptr = dentry;
diff --git a/fs/hfs/super.c b/fs/hfs/super.c
index 8137fb3e6780..7b4c537d6e13 100644
--- a/fs/hfs/super.c
+++ b/fs/hfs/super.c
@@ -430,15 +430,13 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
430 430
431 sb->s_d_op = &hfs_dentry_operations; 431 sb->s_d_op = &hfs_dentry_operations;
432 res = -ENOMEM; 432 res = -ENOMEM;
433 sb->s_root = d_alloc_root(root_inode); 433 sb->s_root = d_make_root(root_inode);
434 if (!sb->s_root) 434 if (!sb->s_root)
435 goto bail_iput; 435 goto bail_no_root;
436 436
437 /* everything's okay */ 437 /* everything's okay */
438 return 0; 438 return 0;
439 439
440bail_iput:
441 iput(root_inode);
442bail_no_root: 440bail_no_root:
443 printk(KERN_ERR "hfs: get root inode failed.\n"); 441 printk(KERN_ERR "hfs: get root inode failed.\n");
444bail: 442bail:
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 21a5b7fc6db4..4e75ac646fea 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -317,6 +317,11 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
317 317
318 318
319/* 319/*
320 * hfs+-specific ioctl for making the filesystem bootable
321 */
322#define HFSPLUS_IOC_BLESS _IO('h', 0x80)
323
324/*
320 * Functions in any *.c used in other files 325 * Functions in any *.c used in other files
321 */ 326 */
322 327
diff --git a/fs/hfsplus/hfsplus_raw.h b/fs/hfsplus/hfsplus_raw.h
index 927cdd6d5bf5..921967e5abb1 100644
--- a/fs/hfsplus/hfsplus_raw.h
+++ b/fs/hfsplus/hfsplus_raw.h
@@ -117,7 +117,7 @@ struct hfsplus_vh {
117 __be32 write_count; 117 __be32 write_count;
118 __be64 encodings_bmp; 118 __be64 encodings_bmp;
119 119
120 u8 finder_info[32]; 120 u32 finder_info[8];
121 121
122 struct hfsplus_fork_raw alloc_file; 122 struct hfsplus_fork_raw alloc_file;
123 struct hfsplus_fork_raw ext_file; 123 struct hfsplus_fork_raw ext_file;
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 6643b242bdd7..82b69ee4dacc 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -193,6 +193,7 @@ static struct dentry *hfsplus_file_lookup(struct inode *dir,
193 mutex_init(&hip->extents_lock); 193 mutex_init(&hip->extents_lock);
194 hip->extent_state = 0; 194 hip->extent_state = 0;
195 hip->flags = 0; 195 hip->flags = 0;
196 hip->userflags = 0;
196 set_bit(HFSPLUS_I_RSRC, &hip->flags); 197 set_bit(HFSPLUS_I_RSRC, &hip->flags);
197 198
198 err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); 199 err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
@@ -400,6 +401,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode)
400 atomic_set(&hip->opencnt, 0); 401 atomic_set(&hip->opencnt, 0);
401 hip->extent_state = 0; 402 hip->extent_state = 0;
402 hip->flags = 0; 403 hip->flags = 0;
404 hip->userflags = 0;
403 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec)); 405 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
404 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec)); 406 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
405 hip->alloc_blocks = 0; 407 hip->alloc_blocks = 0;
diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
index f66c7655b3f7..c640ba57074b 100644
--- a/fs/hfsplus/ioctl.c
+++ b/fs/hfsplus/ioctl.c
@@ -20,6 +20,38 @@
20#include <asm/uaccess.h> 20#include <asm/uaccess.h>
21#include "hfsplus_fs.h" 21#include "hfsplus_fs.h"
22 22
23/*
24 * "Blessing" an HFS+ filesystem writes metadata to the superblock informing
25 * the platform firmware which file to boot from
26 */
27static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
28{
29 struct dentry *dentry = file->f_path.dentry;
30 struct inode *inode = dentry->d_inode;
31 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
32 struct hfsplus_vh *vh = sbi->s_vhdr;
33 struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
34
35 if (!capable(CAP_SYS_ADMIN))
36 return -EPERM;
37
38 mutex_lock(&sbi->vh_mutex);
39
40 /* Directory containing the bootable system */
41 vh->finder_info[0] = bvh->finder_info[0] =
42 cpu_to_be32(parent_ino(dentry));
43
44 /* Bootloader */
45 vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(inode->i_ino);
46
47 /* Per spec, the OS X system folder - same as finder_info[0] here */
48 vh->finder_info[5] = bvh->finder_info[5] =
49 cpu_to_be32(parent_ino(dentry));
50
51 mutex_unlock(&sbi->vh_mutex);
52 return 0;
53}
54
23static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags) 55static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags)
24{ 56{
25 struct inode *inode = file->f_path.dentry->d_inode; 57 struct inode *inode = file->f_path.dentry->d_inode;
@@ -108,6 +140,8 @@ long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
108 return hfsplus_ioctl_getflags(file, argp); 140 return hfsplus_ioctl_getflags(file, argp);
109 case HFSPLUS_IOC_EXT2_SETFLAGS: 141 case HFSPLUS_IOC_EXT2_SETFLAGS:
110 return hfsplus_ioctl_setflags(file, argp); 142 return hfsplus_ioctl_setflags(file, argp);
143 case HFSPLUS_IOC_BLESS:
144 return hfsplus_ioctl_bless(file, argp);
111 default: 145 default:
112 return -ENOTTY; 146 return -ENOTTY;
113 } 147 }
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 427682ca9e48..ceb1c281eefb 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -465,6 +465,13 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
465 goto out_put_alloc_file; 465 goto out_put_alloc_file;
466 } 466 }
467 467
468 sb->s_d_op = &hfsplus_dentry_operations;
469 sb->s_root = d_make_root(root);
470 if (!sb->s_root) {
471 err = -ENOMEM;
472 goto out_put_alloc_file;
473 }
474
468 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1; 475 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
469 str.name = HFSP_HIDDENDIR_NAME; 476 str.name = HFSP_HIDDENDIR_NAME;
470 err = hfs_find_init(sbi->cat_tree, &fd); 477 err = hfs_find_init(sbi->cat_tree, &fd);
@@ -515,13 +522,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
515 } 522 }
516 } 523 }
517 524
518 sb->s_d_op = &hfsplus_dentry_operations;
519 sb->s_root = d_alloc_root(root);
520 if (!sb->s_root) {
521 err = -ENOMEM;
522 goto out_put_hidden_dir;
523 }
524
525 unload_nls(sbi->nls); 525 unload_nls(sbi->nls);
526 sbi->nls = nls; 526 sbi->nls = nls;
527 return 0; 527 return 0;
@@ -529,7 +529,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
529out_put_hidden_dir: 529out_put_hidden_dir:
530 iput(sbi->hidden_dir); 530 iput(sbi->hidden_dir);
531out_put_root: 531out_put_root:
532 iput(root); 532 dput(sb->s_root);
533 sb->s_root = NULL;
533out_put_alloc_file: 534out_put_alloc_file:
534 iput(sbi->alloc_file); 535 iput(sbi->alloc_file);
535out_close_cat_tree: 536out_close_cat_tree:
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index e130bd46d671..588d45885a6f 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -966,9 +966,9 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
966 } 966 }
967 967
968 err = -ENOMEM; 968 err = -ENOMEM;
969 sb->s_root = d_alloc_root(root_inode); 969 sb->s_root = d_make_root(root_inode);
970 if (sb->s_root == NULL) 970 if (sb->s_root == NULL)
971 goto out_put; 971 goto out;
972 972
973 return 0; 973 return 0;
974 974
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index 3690467c944e..54f6eccb79d9 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -625,11 +625,9 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
625 hpfs_init_inode(root); 625 hpfs_init_inode(root);
626 hpfs_read_inode(root); 626 hpfs_read_inode(root);
627 unlock_new_inode(root); 627 unlock_new_inode(root);
628 s->s_root = d_alloc_root(root); 628 s->s_root = d_make_root(root);
629 if (!s->s_root) { 629 if (!s->s_root)
630 iput(root);
631 goto bail0; 630 goto bail0;
632 }
633 631
634 /* 632 /*
635 * find the root directory's . pointer & finish filling in the inode 633 * find the root directory's . pointer & finish filling in the inode
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c
index d92f4ce80925..a80e45a690ac 100644
--- a/fs/hppfs/hppfs.c
+++ b/fs/hppfs/hppfs.c
@@ -726,17 +726,12 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
726 726
727 err = -ENOMEM; 727 err = -ENOMEM;
728 root_inode = get_inode(sb, dget(proc_mnt->mnt_root)); 728 root_inode = get_inode(sb, dget(proc_mnt->mnt_root));
729 if (!root_inode) 729 sb->s_root = d_make_root(root_inode);
730 goto out_mntput;
731
732 sb->s_root = d_alloc_root(root_inode);
733 if (!sb->s_root) 730 if (!sb->s_root)
734 goto out_iput; 731 goto out_mntput;
735 732
736 return 0; 733 return 0;
737 734
738 out_iput:
739 iput(root_inode);
740 out_mntput: 735 out_mntput:
741 mntput(proc_mnt); 736 mntput(proc_mnt);
742 out: 737 out:
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7ac0217..81932fa1861a 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -831,8 +831,6 @@ bad_val:
831static int 831static int
832hugetlbfs_fill_super(struct super_block *sb, void *data, int silent) 832hugetlbfs_fill_super(struct super_block *sb, void *data, int silent)
833{ 833{
834 struct inode * inode;
835 struct dentry * root;
836 int ret; 834 int ret;
837 struct hugetlbfs_config config; 835 struct hugetlbfs_config config;
838 struct hugetlbfs_sb_info *sbinfo; 836 struct hugetlbfs_sb_info *sbinfo;
@@ -865,16 +863,9 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent)
865 sb->s_magic = HUGETLBFS_MAGIC; 863 sb->s_magic = HUGETLBFS_MAGIC;
866 sb->s_op = &hugetlbfs_ops; 864 sb->s_op = &hugetlbfs_ops;
867 sb->s_time_gran = 1; 865 sb->s_time_gran = 1;
868 inode = hugetlbfs_get_root(sb, &config); 866 sb->s_root = d_make_root(hugetlbfs_get_root(sb, &config));
869 if (!inode) 867 if (!sb->s_root)
870 goto out_free;
871
872 root = d_alloc_root(inode);
873 if (!root) {
874 iput(inode);
875 goto out_free; 868 goto out_free;
876 }
877 sb->s_root = root;
878 return 0; 869 return 0;
879out_free: 870out_free:
880 kfree(sbinfo); 871 kfree(sbinfo);
diff --git a/fs/inode.c b/fs/inode.c
index 83ab215baab1..9f4f5fecc096 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2,29 +2,19 @@
2 * (C) 1997 Linus Torvalds 2 * (C) 1997 Linus Torvalds
3 * (C) 1999 Andrea Arcangeli <andrea@suse.de> (dynamic inode allocation) 3 * (C) 1999 Andrea Arcangeli <andrea@suse.de> (dynamic inode allocation)
4 */ 4 */
5#include <linux/export.h>
5#include <linux/fs.h> 6#include <linux/fs.h>
6#include <linux/mm.h> 7#include <linux/mm.h>
7#include <linux/dcache.h>
8#include <linux/init.h>
9#include <linux/slab.h>
10#include <linux/writeback.h>
11#include <linux/module.h>
12#include <linux/backing-dev.h> 8#include <linux/backing-dev.h>
13#include <linux/wait.h>
14#include <linux/rwsem.h>
15#include <linux/hash.h> 9#include <linux/hash.h>
16#include <linux/swap.h> 10#include <linux/swap.h>
17#include <linux/security.h> 11#include <linux/security.h>
18#include <linux/pagemap.h>
19#include <linux/cdev.h> 12#include <linux/cdev.h>
20#include <linux/bootmem.h> 13#include <linux/bootmem.h>
21#include <linux/fsnotify.h> 14#include <linux/fsnotify.h>
22#include <linux/mount.h> 15#include <linux/mount.h>
23#include <linux/async.h>
24#include <linux/posix_acl.h> 16#include <linux/posix_acl.h>
25#include <linux/prefetch.h> 17#include <linux/prefetch.h>
26#include <linux/ima.h>
27#include <linux/cred.h>
28#include <linux/buffer_head.h> /* for inode_has_buffers */ 18#include <linux/buffer_head.h> /* for inode_has_buffers */
29#include <linux/ratelimit.h> 19#include <linux/ratelimit.h>
30#include "internal.h" 20#include "internal.h"
@@ -1369,17 +1359,6 @@ int generic_delete_inode(struct inode *inode)
1369EXPORT_SYMBOL(generic_delete_inode); 1359EXPORT_SYMBOL(generic_delete_inode);
1370 1360
1371/* 1361/*
1372 * Normal UNIX filesystem behaviour: delete the
1373 * inode when the usage count drops to zero, and
1374 * i_nlink is zero.
1375 */
1376int generic_drop_inode(struct inode *inode)
1377{
1378 return !inode->i_nlink || inode_unhashed(inode);
1379}
1380EXPORT_SYMBOL_GPL(generic_drop_inode);
1381
1382/*
1383 * Called when we're dropping the last reference 1362 * Called when we're dropping the last reference
1384 * to an inode. 1363 * to an inode.
1385 * 1364 *
@@ -1510,9 +1489,10 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1510 * This function automatically handles read only file systems and media, 1489 * This function automatically handles read only file systems and media,
1511 * as well as the "noatime" flag and inode specific "noatime" markers. 1490 * as well as the "noatime" flag and inode specific "noatime" markers.
1512 */ 1491 */
1513void touch_atime(struct vfsmount *mnt, struct dentry *dentry) 1492void touch_atime(struct path *path)
1514{ 1493{
1515 struct inode *inode = dentry->d_inode; 1494 struct vfsmount *mnt = path->mnt;
1495 struct inode *inode = path->dentry->d_inode;
1516 struct timespec now; 1496 struct timespec now;
1517 1497
1518 if (inode->i_flags & S_NOATIME) 1498 if (inode->i_flags & S_NOATIME)
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index bd62c76fb5df..29037c365ba4 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -947,9 +947,8 @@ root_found:
947 s->s_d_op = &isofs_dentry_ops[table]; 947 s->s_d_op = &isofs_dentry_ops[table];
948 948
949 /* get the root dentry */ 949 /* get the root dentry */
950 s->s_root = d_alloc_root(inode); 950 s->s_root = d_make_root(inode);
951 if (!(s->s_root)) { 951 if (!(s->s_root)) {
952 iput(inode);
953 error = -ENOMEM; 952 error = -ENOMEM;
954 goto out_no_inode; 953 goto out_no_inode;
955 } 954 }
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 2e0123867cb1..c0d5c9d770da 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -561,9 +561,9 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
561 ret = -ENOMEM; 561 ret = -ENOMEM;
562 562
563 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n")); 563 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n"));
564 sb->s_root = d_alloc_root(root_i); 564 sb->s_root = d_make_root(root_i);
565 if (!sb->s_root) 565 if (!sb->s_root)
566 goto out_root_i; 566 goto out_root;
567 567
568 sb->s_maxbytes = 0xFFFFFFFF; 568 sb->s_maxbytes = 0xFFFFFFFF;
569 sb->s_blocksize = PAGE_CACHE_SIZE; 569 sb->s_blocksize = PAGE_CACHE_SIZE;
@@ -573,8 +573,6 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
573 jffs2_start_garbage_collect_thread(c); 573 jffs2_start_garbage_collect_thread(c);
574 return 0; 574 return 0;
575 575
576 out_root_i:
577 iput(root_i);
578out_root: 576out_root:
579 jffs2_free_ino_caches(c); 577 jffs2_free_ino_caches(c);
580 jffs2_free_raw_node_refs(c); 578 jffs2_free_raw_node_refs(c);
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 5f7c160ea64f..07c91ca6017d 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -220,12 +220,6 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
220 220
221 dquot_initialize(dip); 221 dquot_initialize(dip);
222 222
223 /* link count overflow on parent directory ? */
224 if (dip->i_nlink == JFS_LINK_MAX) {
225 rc = -EMLINK;
226 goto out1;
227 }
228
229 /* 223 /*
230 * search parent directory for entry/freespace 224 * search parent directory for entry/freespace
231 * (dtSearch() returns parent directory page pinned) 225 * (dtSearch() returns parent directory page pinned)
@@ -806,9 +800,6 @@ static int jfs_link(struct dentry *old_dentry,
806 jfs_info("jfs_link: %s %s", old_dentry->d_name.name, 800 jfs_info("jfs_link: %s %s", old_dentry->d_name.name,
807 dentry->d_name.name); 801 dentry->d_name.name);
808 802
809 if (ip->i_nlink == JFS_LINK_MAX)
810 return -EMLINK;
811
812 dquot_initialize(dir); 803 dquot_initialize(dir);
813 804
814 tid = txBegin(ip->i_sb, 0); 805 tid = txBegin(ip->i_sb, 0);
@@ -1138,10 +1129,6 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1138 rc = -ENOTEMPTY; 1129 rc = -ENOTEMPTY;
1139 goto out3; 1130 goto out3;
1140 } 1131 }
1141 } else if ((new_dir != old_dir) &&
1142 (new_dir->i_nlink == JFS_LINK_MAX)) {
1143 rc = -EMLINK;
1144 goto out3;
1145 } 1132 }
1146 } else if (new_ip) { 1133 } else if (new_ip) {
1147 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL); 1134 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL);
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 682bca642f38..4a82950f412f 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -441,6 +441,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
441 return -ENOMEM; 441 return -ENOMEM;
442 442
443 sb->s_fs_info = sbi; 443 sb->s_fs_info = sbi;
444 sb->s_max_links = JFS_LINK_MAX;
444 sbi->sb = sb; 445 sbi->sb = sb;
445 sbi->uid = sbi->gid = sbi->umask = -1; 446 sbi->uid = sbi->gid = sbi->umask = -1;
446 447
@@ -521,7 +522,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
521 ret = PTR_ERR(inode); 522 ret = PTR_ERR(inode);
522 goto out_no_rw; 523 goto out_no_rw;
523 } 524 }
524 sb->s_root = d_alloc_root(inode); 525 sb->s_root = d_make_root(inode);
525 if (!sb->s_root) 526 if (!sb->s_root)
526 goto out_no_root; 527 goto out_no_root;
527 528
@@ -539,7 +540,6 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
539 540
540out_no_root: 541out_no_root:
541 jfs_err("jfs_read_super: get root dentry failed"); 542 jfs_err("jfs_read_super: get root dentry failed");
542 iput(inode);
543 543
544out_no_rw: 544out_no_rw:
545 rc = jfs_umount(sb); 545 rc = jfs_umount(sb);
@@ -860,8 +860,14 @@ static int __init init_jfs_fs(void)
860 jfs_proc_init(); 860 jfs_proc_init();
861#endif 861#endif
862 862
863 return register_filesystem(&jfs_fs_type); 863 rc = register_filesystem(&jfs_fs_type);
864 if (!rc)
865 return 0;
864 866
867#ifdef PROC_FS_JFS
868 jfs_proc_clean();
869#endif
870 kthread_stop(jfsSyncThread);
865kill_committask: 871kill_committask:
866 for (i = 0; i < commit_threads; i++) 872 for (i = 0; i < commit_threads; i++)
867 kthread_stop(jfsCommitThread[i]); 873 kthread_stop(jfsCommitThread[i]);
diff --git a/fs/libfs.c b/fs/libfs.c
index 5b2dbb3ba4fc..722e0d5ba182 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -491,11 +491,9 @@ int simple_fill_super(struct super_block *s, unsigned long magic,
491 inode->i_op = &simple_dir_inode_operations; 491 inode->i_op = &simple_dir_inode_operations;
492 inode->i_fop = &simple_dir_operations; 492 inode->i_fop = &simple_dir_operations;
493 set_nlink(inode, 2); 493 set_nlink(inode, 2);
494 root = d_alloc_root(inode); 494 root = d_make_root(inode);
495 if (!root) { 495 if (!root)
496 iput(inode);
497 return -ENOMEM; 496 return -ENOMEM;
498 }
499 for (i = 0; !files->name || files->name[0]; i++, files++) { 497 for (i = 0; !files->name || files->name[0]; i++, files++) {
500 if (!files->name) 498 if (!files->name)
501 continue; 499 continue;
@@ -536,7 +534,7 @@ int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *c
536 spin_lock(&pin_fs_lock); 534 spin_lock(&pin_fs_lock);
537 if (unlikely(!*mount)) { 535 if (unlikely(!*mount)) {
538 spin_unlock(&pin_fs_lock); 536 spin_unlock(&pin_fs_lock);
539 mnt = vfs_kern_mount(type, 0, type->name, NULL); 537 mnt = vfs_kern_mount(type, MS_KERNMOUNT, type->name, NULL);
540 if (IS_ERR(mnt)) 538 if (IS_ERR(mnt))
541 return PTR_ERR(mnt); 539 return PTR_ERR(mnt);
542 spin_lock(&pin_fs_lock); 540 spin_lock(&pin_fs_lock);
diff --git a/fs/logfs/dir.c b/fs/logfs/dir.c
index 1b6e21dda286..bea5d1b9954b 100644
--- a/fs/logfs/dir.c
+++ b/fs/logfs/dir.c
@@ -558,9 +558,6 @@ static int logfs_link(struct dentry *old_dentry, struct inode *dir,
558{ 558{
559 struct inode *inode = old_dentry->d_inode; 559 struct inode *inode = old_dentry->d_inode;
560 560
561 if (inode->i_nlink >= LOGFS_LINK_MAX)
562 return -EMLINK;
563
564 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 561 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
565 ihold(inode); 562 ihold(inode);
566 inc_nlink(inode); 563 inc_nlink(inode);
diff --git a/fs/logfs/super.c b/fs/logfs/super.c
index c9ee7f5d1caf..97bca623d893 100644
--- a/fs/logfs/super.c
+++ b/fs/logfs/super.c
@@ -315,11 +315,9 @@ static int logfs_get_sb_final(struct super_block *sb)
315 if (IS_ERR(rootdir)) 315 if (IS_ERR(rootdir))
316 goto fail; 316 goto fail;
317 317
318 sb->s_root = d_alloc_root(rootdir); 318 sb->s_root = d_make_root(rootdir);
319 if (!sb->s_root) { 319 if (!sb->s_root)
320 iput(rootdir);
321 goto fail; 320 goto fail;
322 }
323 321
324 /* at that point we know that ->put_super() will be called */ 322 /* at that point we know that ->put_super() will be called */
325 super->s_erase_page = alloc_pages(GFP_KERNEL, 0); 323 super->s_erase_page = alloc_pages(GFP_KERNEL, 0);
@@ -542,6 +540,7 @@ static struct dentry *logfs_get_sb_device(struct logfs_super *super,
542 * the filesystem incompatible with 32bit systems. 540 * the filesystem incompatible with 32bit systems.
543 */ 541 */
544 sb->s_maxbytes = (1ull << 43) - 1; 542 sb->s_maxbytes = (1ull << 43) - 1;
543 sb->s_max_links = LOGFS_LINK_MAX;
545 sb->s_op = &logfs_super_operations; 544 sb->s_op = &logfs_super_operations;
546 sb->s_flags = flags | MS_NOATIME; 545 sb->s_flags = flags | MS_NOATIME;
547 546
@@ -627,7 +626,10 @@ static int __init logfs_init(void)
627 if (ret) 626 if (ret)
628 goto out2; 627 goto out2;
629 628
630 return register_filesystem(&logfs_fs_type); 629 ret = register_filesystem(&logfs_fs_type);
630 if (!ret)
631 return 0;
632 logfs_destroy_inode_cache();
631out2: 633out2:
632 logfs_compr_exit(); 634 logfs_compr_exit();
633out1: 635out1:
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index fa8b612b8ce2..fcb05d2c6b5f 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -190,24 +190,24 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
190 sbi->s_version = MINIX_V1; 190 sbi->s_version = MINIX_V1;
191 sbi->s_dirsize = 16; 191 sbi->s_dirsize = 16;
192 sbi->s_namelen = 14; 192 sbi->s_namelen = 14;
193 sbi->s_link_max = MINIX_LINK_MAX; 193 s->s_max_links = MINIX_LINK_MAX;
194 } else if (s->s_magic == MINIX_SUPER_MAGIC2) { 194 } else if (s->s_magic == MINIX_SUPER_MAGIC2) {
195 sbi->s_version = MINIX_V1; 195 sbi->s_version = MINIX_V1;
196 sbi->s_dirsize = 32; 196 sbi->s_dirsize = 32;
197 sbi->s_namelen = 30; 197 sbi->s_namelen = 30;
198 sbi->s_link_max = MINIX_LINK_MAX; 198 s->s_max_links = MINIX_LINK_MAX;
199 } else if (s->s_magic == MINIX2_SUPER_MAGIC) { 199 } else if (s->s_magic == MINIX2_SUPER_MAGIC) {
200 sbi->s_version = MINIX_V2; 200 sbi->s_version = MINIX_V2;
201 sbi->s_nzones = ms->s_zones; 201 sbi->s_nzones = ms->s_zones;
202 sbi->s_dirsize = 16; 202 sbi->s_dirsize = 16;
203 sbi->s_namelen = 14; 203 sbi->s_namelen = 14;
204 sbi->s_link_max = MINIX2_LINK_MAX; 204 s->s_max_links = MINIX2_LINK_MAX;
205 } else if (s->s_magic == MINIX2_SUPER_MAGIC2) { 205 } else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
206 sbi->s_version = MINIX_V2; 206 sbi->s_version = MINIX_V2;
207 sbi->s_nzones = ms->s_zones; 207 sbi->s_nzones = ms->s_zones;
208 sbi->s_dirsize = 32; 208 sbi->s_dirsize = 32;
209 sbi->s_namelen = 30; 209 sbi->s_namelen = 30;
210 sbi->s_link_max = MINIX2_LINK_MAX; 210 s->s_max_links = MINIX2_LINK_MAX;
211 } else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) { 211 } else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) {
212 m3s = (struct minix3_super_block *) bh->b_data; 212 m3s = (struct minix3_super_block *) bh->b_data;
213 s->s_magic = m3s->s_magic; 213 s->s_magic = m3s->s_magic;
@@ -221,9 +221,9 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
221 sbi->s_dirsize = 64; 221 sbi->s_dirsize = 64;
222 sbi->s_namelen = 60; 222 sbi->s_namelen = 60;
223 sbi->s_version = MINIX_V3; 223 sbi->s_version = MINIX_V3;
224 sbi->s_link_max = MINIX2_LINK_MAX;
225 sbi->s_mount_state = MINIX_VALID_FS; 224 sbi->s_mount_state = MINIX_VALID_FS;
226 sb_set_blocksize(s, m3s->s_blocksize); 225 sb_set_blocksize(s, m3s->s_blocksize);
226 s->s_max_links = MINIX2_LINK_MAX;
227 } else 227 } else
228 goto out_no_fs; 228 goto out_no_fs;
229 229
@@ -254,14 +254,6 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
254 minix_set_bit(0,sbi->s_imap[0]->b_data); 254 minix_set_bit(0,sbi->s_imap[0]->b_data);
255 minix_set_bit(0,sbi->s_zmap[0]->b_data); 255 minix_set_bit(0,sbi->s_zmap[0]->b_data);
256 256
257 /* set up enough so that it can read an inode */
258 s->s_op = &minix_sops;
259 root_inode = minix_iget(s, MINIX_ROOT_INO);
260 if (IS_ERR(root_inode)) {
261 ret = PTR_ERR(root_inode);
262 goto out_no_root;
263 }
264
265 /* Apparently minix can create filesystems that allocate more blocks for 257 /* Apparently minix can create filesystems that allocate more blocks for
266 * the bitmaps than needed. We simply ignore that, but verify it didn't 258 * the bitmaps than needed. We simply ignore that, but verify it didn't
267 * create one with not enough blocks and bail out if so. 259 * create one with not enough blocks and bail out if so.
@@ -270,7 +262,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
270 if (sbi->s_imap_blocks < block) { 262 if (sbi->s_imap_blocks < block) {
271 printk("MINIX-fs: file system does not have enough " 263 printk("MINIX-fs: file system does not have enough "
272 "imap blocks allocated. Refusing to mount\n"); 264 "imap blocks allocated. Refusing to mount\n");
273 goto out_iput; 265 goto out_no_bitmap;
274 } 266 }
275 267
276 block = minix_blocks_needed( 268 block = minix_blocks_needed(
@@ -279,13 +271,21 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
279 if (sbi->s_zmap_blocks < block) { 271 if (sbi->s_zmap_blocks < block) {
280 printk("MINIX-fs: file system does not have enough " 272 printk("MINIX-fs: file system does not have enough "
281 "zmap blocks allocated. Refusing to mount.\n"); 273 "zmap blocks allocated. Refusing to mount.\n");
282 goto out_iput; 274 goto out_no_bitmap;
275 }
276
277 /* set up enough so that it can read an inode */
278 s->s_op = &minix_sops;
279 root_inode = minix_iget(s, MINIX_ROOT_INO);
280 if (IS_ERR(root_inode)) {
281 ret = PTR_ERR(root_inode);
282 goto out_no_root;
283 } 283 }
284 284
285 ret = -ENOMEM; 285 ret = -ENOMEM;
286 s->s_root = d_alloc_root(root_inode); 286 s->s_root = d_make_root(root_inode);
287 if (!s->s_root) 287 if (!s->s_root)
288 goto out_iput; 288 goto out_no_root;
289 289
290 if (!(s->s_flags & MS_RDONLY)) { 290 if (!(s->s_flags & MS_RDONLY)) {
291 if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */ 291 if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
@@ -301,10 +301,6 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
301 301
302 return 0; 302 return 0;
303 303
304out_iput:
305 iput(root_inode);
306 goto out_freemap;
307
308out_no_root: 304out_no_root:
309 if (!silent) 305 if (!silent)
310 printk("MINIX-fs: get root inode failed\n"); 306 printk("MINIX-fs: get root inode failed\n");
diff --git a/fs/minix/minix.h b/fs/minix/minix.h
index c889ef0aa571..1ebd11854622 100644
--- a/fs/minix/minix.h
+++ b/fs/minix/minix.h
@@ -34,7 +34,6 @@ struct minix_sb_info {
34 unsigned long s_max_size; 34 unsigned long s_max_size;
35 int s_dirsize; 35 int s_dirsize;
36 int s_namelen; 36 int s_namelen;
37 int s_link_max;
38 struct buffer_head ** s_imap; 37 struct buffer_head ** s_imap;
39 struct buffer_head ** s_zmap; 38 struct buffer_head ** s_zmap;
40 struct buffer_head * s_sbh; 39 struct buffer_head * s_sbh;
diff --git a/fs/minix/namei.c b/fs/minix/namei.c
index 2f76e38c2065..2d0ee1786305 100644
--- a/fs/minix/namei.c
+++ b/fs/minix/namei.c
@@ -94,9 +94,6 @@ static int minix_link(struct dentry * old_dentry, struct inode * dir,
94{ 94{
95 struct inode *inode = old_dentry->d_inode; 95 struct inode *inode = old_dentry->d_inode;
96 96
97 if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
98 return -EMLINK;
99
100 inode->i_ctime = CURRENT_TIME_SEC; 97 inode->i_ctime = CURRENT_TIME_SEC;
101 inode_inc_link_count(inode); 98 inode_inc_link_count(inode);
102 ihold(inode); 99 ihold(inode);
@@ -106,10 +103,7 @@ static int minix_link(struct dentry * old_dentry, struct inode * dir,
106static int minix_mkdir(struct inode * dir, struct dentry *dentry, umode_t mode) 103static int minix_mkdir(struct inode * dir, struct dentry *dentry, umode_t mode)
107{ 104{
108 struct inode * inode; 105 struct inode * inode;
109 int err = -EMLINK; 106 int err;
110
111 if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
112 goto out;
113 107
114 inode_inc_link_count(dir); 108 inode_inc_link_count(dir);
115 109
@@ -181,7 +175,6 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)
181static int minix_rename(struct inode * old_dir, struct dentry *old_dentry, 175static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
182 struct inode * new_dir, struct dentry *new_dentry) 176 struct inode * new_dir, struct dentry *new_dentry)
183{ 177{
184 struct minix_sb_info * info = minix_sb(old_dir->i_sb);
185 struct inode * old_inode = old_dentry->d_inode; 178 struct inode * old_inode = old_dentry->d_inode;
186 struct inode * new_inode = new_dentry->d_inode; 179 struct inode * new_inode = new_dentry->d_inode;
187 struct page * dir_page = NULL; 180 struct page * dir_page = NULL;
@@ -219,11 +212,6 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
219 drop_nlink(new_inode); 212 drop_nlink(new_inode);
220 inode_dec_link_count(new_inode); 213 inode_dec_link_count(new_inode);
221 } else { 214 } else {
222 if (dir_de) {
223 err = -EMLINK;
224 if (new_dir->i_nlink >= info->s_link_max)
225 goto out_dir;
226 }
227 err = minix_add_link(new_dentry, old_inode); 215 err = minix_add_link(new_dentry, old_inode);
228 if (err) 216 if (err)
229 goto out_dir; 217 goto out_dir;
diff --git a/fs/namei.c b/fs/namei.c
index 20a4fcf001ec..13e6a1f191a9 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -642,7 +642,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
642 cond_resched(); 642 cond_resched();
643 current->total_link_count++; 643 current->total_link_count++;
644 644
645 touch_atime(link->mnt, dentry); 645 touch_atime(link);
646 nd_set_link(nd, NULL); 646 nd_set_link(nd, NULL);
647 647
648 error = security_inode_follow_link(link->dentry, nd); 648 error = security_inode_follow_link(link->dentry, nd);
@@ -2691,6 +2691,7 @@ SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, d
2691int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 2691int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
2692{ 2692{
2693 int error = may_create(dir, dentry); 2693 int error = may_create(dir, dentry);
2694 unsigned max_links = dir->i_sb->s_max_links;
2694 2695
2695 if (error) 2696 if (error)
2696 return error; 2697 return error;
@@ -2703,6 +2704,9 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
2703 if (error) 2704 if (error)
2704 return error; 2705 return error;
2705 2706
2707 if (max_links && dir->i_nlink >= max_links)
2708 return -EMLINK;
2709
2706 error = dir->i_op->mkdir(dir, dentry, mode); 2710 error = dir->i_op->mkdir(dir, dentry, mode);
2707 if (!error) 2711 if (!error)
2708 fsnotify_mkdir(dir, dentry); 2712 fsnotify_mkdir(dir, dentry);
@@ -3033,6 +3037,7 @@ SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newn
3033int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) 3037int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
3034{ 3038{
3035 struct inode *inode = old_dentry->d_inode; 3039 struct inode *inode = old_dentry->d_inode;
3040 unsigned max_links = dir->i_sb->s_max_links;
3036 int error; 3041 int error;
3037 3042
3038 if (!inode) 3043 if (!inode)
@@ -3063,6 +3068,8 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
3063 /* Make sure we don't allow creating hardlink to an unlinked file */ 3068 /* Make sure we don't allow creating hardlink to an unlinked file */
3064 if (inode->i_nlink == 0) 3069 if (inode->i_nlink == 0)
3065 error = -ENOENT; 3070 error = -ENOENT;
3071 else if (max_links && inode->i_nlink >= max_links)
3072 error = -EMLINK;
3066 else 3073 else
3067 error = dir->i_op->link(old_dentry, dir, new_dentry); 3074 error = dir->i_op->link(old_dentry, dir, new_dentry);
3068 mutex_unlock(&inode->i_mutex); 3075 mutex_unlock(&inode->i_mutex);
@@ -3172,6 +3179,7 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
3172{ 3179{
3173 int error = 0; 3180 int error = 0;
3174 struct inode *target = new_dentry->d_inode; 3181 struct inode *target = new_dentry->d_inode;
3182 unsigned max_links = new_dir->i_sb->s_max_links;
3175 3183
3176 /* 3184 /*
3177 * If we are going to change the parent - check write permissions, 3185 * If we are going to change the parent - check write permissions,
@@ -3195,6 +3203,11 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
3195 if (d_mountpoint(old_dentry) || d_mountpoint(new_dentry)) 3203 if (d_mountpoint(old_dentry) || d_mountpoint(new_dentry))
3196 goto out; 3204 goto out;
3197 3205
3206 error = -EMLINK;
3207 if (max_links && !target && new_dir != old_dir &&
3208 new_dir->i_nlink >= max_links)
3209 goto out;
3210
3198 if (target) 3211 if (target)
3199 shrink_dcache_parent(new_dentry); 3212 shrink_dcache_parent(new_dentry);
3200 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); 3213 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index 3d1e34f8a68e..49df0e7f8379 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -716,13 +716,11 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
716 if (!root_inode) 716 if (!root_inode)
717 goto out_disconnect; 717 goto out_disconnect;
718 DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber); 718 DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
719 sb->s_root = d_alloc_root(root_inode); 719 sb->s_root = d_make_root(root_inode);
720 if (!sb->s_root) 720 if (!sb->s_root)
721 goto out_no_root; 721 goto out_disconnect;
722 return 0; 722 return 0;
723 723
724out_no_root:
725 iput(root_inode);
726out_disconnect: 724out_disconnect:
727 ncp_lock_server(server); 725 ncp_lock_server(server);
728 ncp_disconnect(server); 726 ncp_disconnect(server);
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index dcb61548887f..801d6d830787 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -49,11 +49,9 @@ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *i
49{ 49{
50 /* The mntroot acts as the dummy root dentry for this superblock */ 50 /* The mntroot acts as the dummy root dentry for this superblock */
51 if (sb->s_root == NULL) { 51 if (sb->s_root == NULL) {
52 sb->s_root = d_alloc_root(inode); 52 sb->s_root = d_make_root(inode);
53 if (sb->s_root == NULL) { 53 if (sb->s_root == NULL)
54 iput(inode);
55 return -ENOMEM; 54 return -ENOMEM;
56 }
57 ihold(inode); 55 ihold(inode);
58 /* 56 /*
59 * Ensure that this dentry is invisible to d_find_alias(). 57 * Ensure that this dentry is invisible to d_find_alias().
diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
index ce7f0758d84c..9559ce468732 100644
--- a/fs/nfsd/fault_inject.c
+++ b/fs/nfsd/fault_inject.c
@@ -72,7 +72,7 @@ int nfsd_fault_inject_init(void)
72{ 72{
73 unsigned int i; 73 unsigned int i;
74 struct nfsd_fault_inject_op *op; 74 struct nfsd_fault_inject_op *op;
75 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; 75 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
76 76
77 debug_dir = debugfs_create_dir("nfsd", NULL); 77 debug_dir = debugfs_create_dir("nfsd", NULL);
78 if (!debug_dir) 78 if (!debug_dir)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index edf6d3ed8777..e59f71d0cf73 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1541,30 +1541,31 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1541__be32 1541__be32
1542nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp) 1542nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
1543{ 1543{
1544 struct dentry *dentry;
1545 struct inode *inode; 1544 struct inode *inode;
1546 mm_segment_t oldfs; 1545 mm_segment_t oldfs;
1547 __be32 err; 1546 __be32 err;
1548 int host_err; 1547 int host_err;
1548 struct path path;
1549 1549
1550 err = fh_verify(rqstp, fhp, S_IFLNK, NFSD_MAY_NOP); 1550 err = fh_verify(rqstp, fhp, S_IFLNK, NFSD_MAY_NOP);
1551 if (err) 1551 if (err)
1552 goto out; 1552 goto out;
1553 1553
1554 dentry = fhp->fh_dentry; 1554 path.mnt = fhp->fh_export->ex_path.mnt;
1555 inode = dentry->d_inode; 1555 path.dentry = fhp->fh_dentry;
1556 inode = path.dentry->d_inode;
1556 1557
1557 err = nfserr_inval; 1558 err = nfserr_inval;
1558 if (!inode->i_op->readlink) 1559 if (!inode->i_op->readlink)
1559 goto out; 1560 goto out;
1560 1561
1561 touch_atime(fhp->fh_export->ex_path.mnt, dentry); 1562 touch_atime(&path);
1562 /* N.B. Why does this call need a get_fs()?? 1563 /* N.B. Why does this call need a get_fs()??
1563 * Remove the set_fs and watch the fireworks:-) --okir 1564 * Remove the set_fs and watch the fireworks:-) --okir
1564 */ 1565 */
1565 1566
1566 oldfs = get_fs(); set_fs(KERNEL_DS); 1567 oldfs = get_fs(); set_fs(KERNEL_DS);
1567 host_err = inode->i_op->readlink(dentry, buf, *lenp); 1568 host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
1568 set_fs(oldfs); 1569 set_fs(oldfs);
1569 1570
1570 if (host_err < 0) 1571 if (host_err < 0)
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 1cd3f624dffc..fce2bbee66d4 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -193,9 +193,6 @@ static int nilfs_link(struct dentry *old_dentry, struct inode *dir,
193 struct nilfs_transaction_info ti; 193 struct nilfs_transaction_info ti;
194 int err; 194 int err;
195 195
196 if (inode->i_nlink >= NILFS_LINK_MAX)
197 return -EMLINK;
198
199 err = nilfs_transaction_begin(dir->i_sb, &ti, 1); 196 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
200 if (err) 197 if (err)
201 return err; 198 return err;
@@ -219,9 +216,6 @@ static int nilfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
219 struct nilfs_transaction_info ti; 216 struct nilfs_transaction_info ti;
220 int err; 217 int err;
221 218
222 if (dir->i_nlink >= NILFS_LINK_MAX)
223 return -EMLINK;
224
225 err = nilfs_transaction_begin(dir->i_sb, &ti, 1); 219 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
226 if (err) 220 if (err)
227 return err; 221 return err;
@@ -400,11 +394,6 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
400 drop_nlink(new_inode); 394 drop_nlink(new_inode);
401 nilfs_mark_inode_dirty(new_inode); 395 nilfs_mark_inode_dirty(new_inode);
402 } else { 396 } else {
403 if (dir_de) {
404 err = -EMLINK;
405 if (new_dir->i_nlink >= NILFS_LINK_MAX)
406 goto out_dir;
407 }
408 err = nilfs_add_link(new_dentry, old_inode); 397 err = nilfs_add_link(new_dentry, old_inode);
409 if (err) 398 if (err)
410 goto out_dir; 399 goto out_dir;
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 08e3d4f9df18..1099a76cee59 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -917,9 +917,8 @@ static int nilfs_get_root_dentry(struct super_block *sb,
917 if (root->cno == NILFS_CPTREE_CURRENT_CNO) { 917 if (root->cno == NILFS_CPTREE_CURRENT_CNO) {
918 dentry = d_find_alias(inode); 918 dentry = d_find_alias(inode);
919 if (!dentry) { 919 if (!dentry) {
920 dentry = d_alloc_root(inode); 920 dentry = d_make_root(inode);
921 if (!dentry) { 921 if (!dentry) {
922 iput(inode);
923 ret = -ENOMEM; 922 ret = -ENOMEM;
924 goto failed_dentry; 923 goto failed_dentry;
925 } 924 }
@@ -1059,6 +1058,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
1059 sb->s_export_op = &nilfs_export_ops; 1058 sb->s_export_op = &nilfs_export_ops;
1060 sb->s_root = NULL; 1059 sb->s_root = NULL;
1061 sb->s_time_gran = 1; 1060 sb->s_time_gran = 1;
1061 sb->s_max_links = NILFS_LINK_MAX;
1062 1062
1063 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; 1063 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
1064 sb->s_bdi = bdi ? : &default_backing_dev_info; 1064 sb->s_bdi = bdi ? : &default_backing_dev_info;
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 28d4e6ab6634..b341492542ca 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -2908,9 +2908,10 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
2908 ntfs_error(sb, "Failed to load system files."); 2908 ntfs_error(sb, "Failed to load system files.");
2909 goto unl_upcase_iput_tmp_ino_err_out_now; 2909 goto unl_upcase_iput_tmp_ino_err_out_now;
2910 } 2910 }
2911 if ((sb->s_root = d_alloc_root(vol->root_ino))) { 2911
2912 /* We grab a reference, simulating an ntfs_iget(). */ 2912 /* We grab a reference, simulating an ntfs_iget(). */
2913 ihold(vol->root_ino); 2913 ihold(vol->root_ino);
2914 if ((sb->s_root = d_make_root(vol->root_ino))) {
2914 ntfs_debug("Exiting, status successful."); 2915 ntfs_debug("Exiting, status successful.");
2915 /* Release the default upcase if it has no users. */ 2916 /* Release the default upcase if it has no users. */
2916 mutex_lock(&ntfs_lock); 2917 mutex_lock(&ntfs_lock);
@@ -3158,6 +3159,8 @@ static int __init init_ntfs_fs(void)
3158 } 3159 }
3159 printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); 3160 printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n");
3160 3161
3162 /* Unregister the ntfs sysctls. */
3163 ntfs_sysctl(0);
3161sysctl_err_out: 3164sysctl_err_out:
3162 kmem_cache_destroy(ntfs_big_inode_cache); 3165 kmem_cache_destroy(ntfs_big_inode_cache);
3163big_inode_err_out: 3166big_inode_err_out:
diff --git a/fs/ocfs2/dlmfs/dlmfs.c b/fs/ocfs2/dlmfs/dlmfs.c
index abfac0d7ae9c..3b5825ef3193 100644
--- a/fs/ocfs2/dlmfs/dlmfs.c
+++ b/fs/ocfs2/dlmfs/dlmfs.c
@@ -582,24 +582,14 @@ static int dlmfs_fill_super(struct super_block * sb,
582 void * data, 582 void * data,
583 int silent) 583 int silent)
584{ 584{
585 struct inode * inode;
586 struct dentry * root;
587
588 sb->s_maxbytes = MAX_LFS_FILESIZE; 585 sb->s_maxbytes = MAX_LFS_FILESIZE;
589 sb->s_blocksize = PAGE_CACHE_SIZE; 586 sb->s_blocksize = PAGE_CACHE_SIZE;
590 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 587 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
591 sb->s_magic = DLMFS_MAGIC; 588 sb->s_magic = DLMFS_MAGIC;
592 sb->s_op = &dlmfs_ops; 589 sb->s_op = &dlmfs_ops;
593 inode = dlmfs_get_root_inode(sb); 590 sb->s_root = d_make_root(dlmfs_get_root_inode(sb));
594 if (!inode) 591 if (!sb->s_root)
595 return -ENOMEM;
596
597 root = d_alloc_root(inode);
598 if (!root) {
599 iput(inode);
600 return -ENOMEM; 592 return -ENOMEM;
601 }
602 sb->s_root = root;
603 return 0; 593 return 0;
604} 594}
605 595
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 604e12c4e979..68f4541c2db9 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -1154,19 +1154,19 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
1154 } 1154 }
1155 1155
1156 status = ocfs2_mount_volume(sb); 1156 status = ocfs2_mount_volume(sb);
1157 if (osb->root_inode)
1158 inode = igrab(osb->root_inode);
1159
1160 if (status < 0) 1157 if (status < 0)
1161 goto read_super_error; 1158 goto read_super_error;
1162 1159
1160 if (osb->root_inode)
1161 inode = igrab(osb->root_inode);
1162
1163 if (!inode) { 1163 if (!inode) {
1164 status = -EIO; 1164 status = -EIO;
1165 mlog_errno(status); 1165 mlog_errno(status);
1166 goto read_super_error; 1166 goto read_super_error;
1167 } 1167 }
1168 1168
1169 root = d_alloc_root(inode); 1169 root = d_make_root(inode);
1170 if (!root) { 1170 if (!root) {
1171 status = -ENOMEM; 1171 status = -ENOMEM;
1172 mlog_errno(status); 1172 mlog_errno(status);
@@ -1220,9 +1220,6 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
1220read_super_error: 1220read_super_error:
1221 brelse(bh); 1221 brelse(bh);
1222 1222
1223 if (inode)
1224 iput(inode);
1225
1226 if (osb) { 1223 if (osb) {
1227 atomic_set(&osb->vol_state, VOLUME_DISABLED); 1224 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1228 wake_up(&osb->osb_mount_event); 1225 wake_up(&osb->osb_mount_event);
@@ -1627,21 +1624,17 @@ static int __init ocfs2_init(void)
1627 init_waitqueue_head(&ocfs2__ioend_wq[i]); 1624 init_waitqueue_head(&ocfs2__ioend_wq[i]);
1628 1625
1629 status = init_ocfs2_uptodate_cache(); 1626 status = init_ocfs2_uptodate_cache();
1630 if (status < 0) { 1627 if (status < 0)
1631 mlog_errno(status); 1628 goto out1;
1632 goto leave;
1633 }
1634 1629
1635 status = ocfs2_initialize_mem_caches(); 1630 status = ocfs2_initialize_mem_caches();
1636 if (status < 0) { 1631 if (status < 0)
1637 mlog_errno(status); 1632 goto out2;
1638 goto leave;
1639 }
1640 1633
1641 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq"); 1634 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1642 if (!ocfs2_wq) { 1635 if (!ocfs2_wq) {
1643 status = -ENOMEM; 1636 status = -ENOMEM;
1644 goto leave; 1637 goto out3;
1645 } 1638 }
1646 1639
1647 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL); 1640 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
@@ -1653,17 +1646,23 @@ static int __init ocfs2_init(void)
1653 ocfs2_set_locking_protocol(); 1646 ocfs2_set_locking_protocol();
1654 1647
1655 status = register_quota_format(&ocfs2_quota_format); 1648 status = register_quota_format(&ocfs2_quota_format);
1656leave: 1649 if (status < 0)
1657 if (status < 0) { 1650 goto out4;
1658 ocfs2_free_mem_caches(); 1651 status = register_filesystem(&ocfs2_fs_type);
1659 exit_ocfs2_uptodate_cache(); 1652 if (!status)
1660 mlog_errno(status); 1653 return 0;
1661 }
1662 1654
1663 if (status >= 0) { 1655 unregister_quota_format(&ocfs2_quota_format);
1664 return register_filesystem(&ocfs2_fs_type); 1656out4:
1665 } else 1657 destroy_workqueue(ocfs2_wq);
1666 return -1; 1658 debugfs_remove(ocfs2_debugfs_root);
1659out3:
1660 ocfs2_free_mem_caches();
1661out2:
1662 exit_ocfs2_uptodate_cache();
1663out1:
1664 mlog_errno(status);
1665 return status;
1667} 1666}
1668 1667
1669static void __exit ocfs2_exit(void) 1668static void __exit ocfs2_exit(void)
diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c
index 6065bb0ba207..dbc842222589 100644
--- a/fs/omfs/inode.c
+++ b/fs/omfs/inode.c
@@ -539,11 +539,9 @@ static int omfs_fill_super(struct super_block *sb, void *data, int silent)
539 goto out_brelse_bh2; 539 goto out_brelse_bh2;
540 } 540 }
541 541
542 sb->s_root = d_alloc_root(root); 542 sb->s_root = d_make_root(root);
543 if (!sb->s_root) { 543 if (!sb->s_root)
544 iput(root);
545 goto out_brelse_bh2; 544 goto out_brelse_bh2;
546 }
547 printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name); 545 printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name);
548 546
549 ret = 0; 547 ret = 0;
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index a88c03bc749d..bc49c975d501 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -408,13 +408,12 @@ static int openprom_fill_super(struct super_block *s, void *data, int silent)
408 oi->type = op_inode_node; 408 oi->type = op_inode_node;
409 oi->u.node = of_find_node_by_path("/"); 409 oi->u.node = of_find_node_by_path("/");
410 410
411 s->s_root = d_alloc_root(root_inode); 411 s->s_root = d_make_root(root_inode);
412 if (!s->s_root) 412 if (!s->s_root)
413 goto out_no_root_dentry; 413 goto out_no_root_dentry;
414 return 0; 414 return 0;
415 415
416out_no_root_dentry: 416out_no_root_dentry:
417 iput(root_inode);
418 ret = -ENOMEM; 417 ret = -ENOMEM;
419out_no_root: 418out_no_root:
420 printk("openprom_fill_super: get root inode failed\n"); 419 printk("openprom_fill_super: get root inode failed\n");
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 84fd3235a590..8461a7b82fdb 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -486,8 +486,6 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
486 486
487int proc_fill_super(struct super_block *s) 487int proc_fill_super(struct super_block *s)
488{ 488{
489 struct inode * root_inode;
490
491 s->s_flags |= MS_NODIRATIME | MS_NOSUID | MS_NOEXEC; 489 s->s_flags |= MS_NODIRATIME | MS_NOSUID | MS_NOEXEC;
492 s->s_blocksize = 1024; 490 s->s_blocksize = 1024;
493 s->s_blocksize_bits = 10; 491 s->s_blocksize_bits = 10;
@@ -496,19 +494,11 @@ int proc_fill_super(struct super_block *s)
496 s->s_time_gran = 1; 494 s->s_time_gran = 1;
497 495
498 pde_get(&proc_root); 496 pde_get(&proc_root);
499 root_inode = proc_get_inode(s, &proc_root); 497 s->s_root = d_make_root(proc_get_inode(s, &proc_root));
500 if (!root_inode) 498 if (s->s_root)
501 goto out_no_root; 499 return 0;
502 root_inode->i_uid = 0;
503 root_inode->i_gid = 0;
504 s->s_root = d_alloc_root(root_inode);
505 if (!s->s_root)
506 goto out_no_root;
507 return 0;
508 500
509out_no_root:
510 printk("proc_read_super: get root inode failed\n"); 501 printk("proc_read_super: get root inode failed\n");
511 iput(root_inode);
512 pde_put(&proc_root); 502 pde_put(&proc_root);
513 return -ENOMEM; 503 return -ENOMEM;
514} 504}
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index b3b426edb2fd..f37c32b94525 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -278,9 +278,7 @@ fail:
278 278
279int pstore_fill_super(struct super_block *sb, void *data, int silent) 279int pstore_fill_super(struct super_block *sb, void *data, int silent)
280{ 280{
281 struct inode *inode = NULL; 281 struct inode *inode;
282 struct dentry *root;
283 int err;
284 282
285 save_mount_options(sb, data); 283 save_mount_options(sb, data);
286 284
@@ -296,26 +294,17 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent)
296 parse_options(data); 294 parse_options(data);
297 295
298 inode = pstore_get_inode(sb, NULL, S_IFDIR | 0755, 0); 296 inode = pstore_get_inode(sb, NULL, S_IFDIR | 0755, 0);
299 if (!inode) { 297 if (inode) {
300 err = -ENOMEM; 298 /* override ramfs "dir" options so we catch unlink(2) */
301 goto fail; 299 inode->i_op = &pstore_dir_inode_operations;
302 }
303 /* override ramfs "dir" options so we catch unlink(2) */
304 inode->i_op = &pstore_dir_inode_operations;
305
306 root = d_alloc_root(inode);
307 sb->s_root = root;
308 if (!root) {
309 err = -ENOMEM;
310 goto fail;
311 } 300 }
301 sb->s_root = d_make_root(inode);
302 if (!sb->s_root)
303 return -ENOMEM;
312 304
313 pstore_get_records(0); 305 pstore_get_records(0);
314 306
315 return 0; 307 return 0;
316fail:
317 iput(inode);
318 return err;
319} 308}
320 309
321static struct dentry *pstore_mount(struct file_system_type *fs_type, 310static struct dentry *pstore_mount(struct file_system_type *fs_type,
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index 6b009548d2e0..552e994e3aa1 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -52,38 +52,6 @@ static int qnx4_remount(struct super_block *sb, int *flags, char *data)
52 return 0; 52 return 0;
53} 53}
54 54
55static struct buffer_head *qnx4_getblk(struct inode *inode, int nr,
56 int create)
57{
58 struct buffer_head *result = NULL;
59
60 if ( nr >= 0 )
61 nr = qnx4_block_map( inode, nr );
62 if (nr) {
63 result = sb_getblk(inode->i_sb, nr);
64 return result;
65 }
66 return NULL;
67}
68
69struct buffer_head *qnx4_bread(struct inode *inode, int block, int create)
70{
71 struct buffer_head *bh;
72
73 bh = qnx4_getblk(inode, block, create);
74 if (!bh || buffer_uptodate(bh)) {
75 return bh;
76 }
77 ll_rw_block(READ, 1, &bh);
78 wait_on_buffer(bh);
79 if (buffer_uptodate(bh)) {
80 return bh;
81 }
82 brelse(bh);
83
84 return NULL;
85}
86
87static int qnx4_get_block( struct inode *inode, sector_t iblock, struct buffer_head *bh, int create ) 55static int qnx4_get_block( struct inode *inode, sector_t iblock, struct buffer_head *bh, int create )
88{ 56{
89 unsigned long phys; 57 unsigned long phys;
@@ -98,23 +66,31 @@ static int qnx4_get_block( struct inode *inode, sector_t iblock, struct buffer_h
98 return 0; 66 return 0;
99} 67}
100 68
69static inline u32 try_extent(qnx4_xtnt_t *extent, u32 *offset)
70{
71 u32 size = le32_to_cpu(extent->xtnt_size);
72 if (*offset < size)
73 return le32_to_cpu(extent->xtnt_blk) + *offset - 1;
74 *offset -= size;
75 return 0;
76}
77
101unsigned long qnx4_block_map( struct inode *inode, long iblock ) 78unsigned long qnx4_block_map( struct inode *inode, long iblock )
102{ 79{
103 int ix; 80 int ix;
104 long offset, i_xblk; 81 long i_xblk;
105 unsigned long block = 0;
106 struct buffer_head *bh = NULL; 82 struct buffer_head *bh = NULL;
107 struct qnx4_xblk *xblk = NULL; 83 struct qnx4_xblk *xblk = NULL;
108 struct qnx4_inode_entry *qnx4_inode = qnx4_raw_inode(inode); 84 struct qnx4_inode_entry *qnx4_inode = qnx4_raw_inode(inode);
109 u16 nxtnt = le16_to_cpu(qnx4_inode->di_num_xtnts); 85 u16 nxtnt = le16_to_cpu(qnx4_inode->di_num_xtnts);
86 u32 offset = iblock;
87 u32 block = try_extent(&qnx4_inode->di_first_xtnt, &offset);
110 88
111 if ( iblock < le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_size) ) { 89 if (block) {
112 // iblock is in the first extent. This is easy. 90 // iblock is in the first extent. This is easy.
113 block = le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_blk) + iblock - 1;
114 } else { 91 } else {
115 // iblock is beyond first extent. We have to follow the extent chain. 92 // iblock is beyond first extent. We have to follow the extent chain.
116 i_xblk = le32_to_cpu(qnx4_inode->di_xblk); 93 i_xblk = le32_to_cpu(qnx4_inode->di_xblk);
117 offset = iblock - le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_size);
118 ix = 0; 94 ix = 0;
119 while ( --nxtnt > 0 ) { 95 while ( --nxtnt > 0 ) {
120 if ( ix == 0 ) { 96 if ( ix == 0 ) {
@@ -130,12 +106,11 @@ unsigned long qnx4_block_map( struct inode *inode, long iblock )
130 return -EIO; 106 return -EIO;
131 } 107 }
132 } 108 }
133 if ( offset < le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_size) ) { 109 block = try_extent(&xblk->xblk_xtnts[ix], &offset);
110 if (block) {
134 // got it! 111 // got it!
135 block = le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_blk) + offset - 1;
136 break; 112 break;
137 } 113 }
138 offset -= le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_size);
139 if ( ++ix >= xblk->xblk_num_xtnts ) { 114 if ( ++ix >= xblk->xblk_num_xtnts ) {
140 i_xblk = le32_to_cpu(xblk->xblk_next_xblk); 115 i_xblk = le32_to_cpu(xblk->xblk_next_xblk);
141 ix = 0; 116 ix = 0;
@@ -260,15 +235,13 @@ static int qnx4_fill_super(struct super_block *s, void *data, int silent)
260 } 235 }
261 236
262 ret = -ENOMEM; 237 ret = -ENOMEM;
263 s->s_root = d_alloc_root(root); 238 s->s_root = d_make_root(root);
264 if (s->s_root == NULL) 239 if (s->s_root == NULL)
265 goto outi; 240 goto outb;
266 241
267 brelse(bh); 242 brelse(bh);
268 return 0; 243 return 0;
269 244
270 outi:
271 iput(root);
272 outb: 245 outb:
273 kfree(qs->BitMap); 246 kfree(qs->BitMap);
274 out: 247 out:
@@ -288,44 +261,17 @@ static void qnx4_put_super(struct super_block *sb)
288 return; 261 return;
289} 262}
290 263
291static int qnx4_writepage(struct page *page, struct writeback_control *wbc)
292{
293 return block_write_full_page(page,qnx4_get_block, wbc);
294}
295
296static int qnx4_readpage(struct file *file, struct page *page) 264static int qnx4_readpage(struct file *file, struct page *page)
297{ 265{
298 return block_read_full_page(page,qnx4_get_block); 266 return block_read_full_page(page,qnx4_get_block);
299} 267}
300 268
301static int qnx4_write_begin(struct file *file, struct address_space *mapping,
302 loff_t pos, unsigned len, unsigned flags,
303 struct page **pagep, void **fsdata)
304{
305 struct qnx4_inode_info *qnx4_inode = qnx4_i(mapping->host);
306 int ret;
307
308 *pagep = NULL;
309 ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
310 qnx4_get_block,
311 &qnx4_inode->mmu_private);
312 if (unlikely(ret)) {
313 loff_t isize = mapping->host->i_size;
314 if (pos + len > isize)
315 vmtruncate(mapping->host, isize);
316 }
317
318 return ret;
319}
320static sector_t qnx4_bmap(struct address_space *mapping, sector_t block) 269static sector_t qnx4_bmap(struct address_space *mapping, sector_t block)
321{ 270{
322 return generic_block_bmap(mapping,block,qnx4_get_block); 271 return generic_block_bmap(mapping,block,qnx4_get_block);
323} 272}
324static const struct address_space_operations qnx4_aops = { 273static const struct address_space_operations qnx4_aops = {
325 .readpage = qnx4_readpage, 274 .readpage = qnx4_readpage,
326 .writepage = qnx4_writepage,
327 .write_begin = qnx4_write_begin,
328 .write_end = generic_write_end,
329 .bmap = qnx4_bmap 275 .bmap = qnx4_bmap
330}; 276};
331 277
diff --git a/fs/qnx4/namei.c b/fs/qnx4/namei.c
index 275327b5615e..a512c0b30e8e 100644
--- a/fs/qnx4/namei.c
+++ b/fs/qnx4/namei.c
@@ -39,10 +39,6 @@ static int qnx4_match(int len, const char *name,
39 } else { 39 } else {
40 namelen = QNX4_SHORT_NAME_MAX; 40 namelen = QNX4_SHORT_NAME_MAX;
41 } 41 }
42 /* "" means "." ---> so paths like "/usr/lib//libc.a" work */
43 if (!len && (de->di_fname[0] == '.') && (de->di_fname[1] == '\0')) {
44 return 1;
45 }
46 thislen = strlen( de->di_fname ); 42 thislen = strlen( de->di_fname );
47 if ( thislen > namelen ) 43 if ( thislen > namelen )
48 thislen = namelen; 44 thislen = namelen;
@@ -72,7 +68,9 @@ static struct buffer_head *qnx4_find_entry(int len, struct inode *dir,
72 block = offset = blkofs = 0; 68 block = offset = blkofs = 0;
73 while (blkofs * QNX4_BLOCK_SIZE + offset < dir->i_size) { 69 while (blkofs * QNX4_BLOCK_SIZE + offset < dir->i_size) {
74 if (!bh) { 70 if (!bh) {
75 bh = qnx4_bread(dir, blkofs, 0); 71 block = qnx4_block_map(dir, blkofs);
72 if (block)
73 bh = sb_bread(dir->i_sb, block);
76 if (!bh) { 74 if (!bh) {
77 blkofs++; 75 blkofs++;
78 continue; 76 continue;
@@ -80,7 +78,6 @@ static struct buffer_head *qnx4_find_entry(int len, struct inode *dir,
80 } 78 }
81 *res_dir = (struct qnx4_inode_entry *) (bh->b_data + offset); 79 *res_dir = (struct qnx4_inode_entry *) (bh->b_data + offset);
82 if (qnx4_match(len, name, bh, &offset)) { 80 if (qnx4_match(len, name, bh, &offset)) {
83 block = qnx4_block_map( dir, blkofs );
84 *ino = block * QNX4_INODES_PER_BLOCK + 81 *ino = block * QNX4_INODES_PER_BLOCK +
85 (offset / QNX4_DIR_ENTRY_SIZE) - 1; 82 (offset / QNX4_DIR_ENTRY_SIZE) - 1;
86 return bh; 83 return bh;
diff --git a/fs/qnx4/qnx4.h b/fs/qnx4/qnx4.h
index 33a60858203b..244d4620189b 100644
--- a/fs/qnx4/qnx4.h
+++ b/fs/qnx4/qnx4.h
@@ -27,8 +27,6 @@ extern struct dentry *qnx4_lookup(struct inode *dir, struct dentry *dentry, stru
27extern unsigned long qnx4_count_free_blocks(struct super_block *sb); 27extern unsigned long qnx4_count_free_blocks(struct super_block *sb);
28extern unsigned long qnx4_block_map(struct inode *inode, long iblock); 28extern unsigned long qnx4_block_map(struct inode *inode, long iblock);
29 29
30extern struct buffer_head *qnx4_bread(struct inode *, int, int);
31
32extern const struct inode_operations qnx4_dir_inode_operations; 30extern const struct inode_operations qnx4_dir_inode_operations;
33extern const struct file_operations qnx4_dir_operations; 31extern const struct file_operations qnx4_dir_operations;
34extern int qnx4_is_free(struct super_block *sb, long block); 32extern int qnx4_is_free(struct super_block *sb, long block);
diff --git a/fs/qnx6/Kconfig b/fs/qnx6/Kconfig
new file mode 100644
index 000000000000..edbba5c17cc8
--- /dev/null
+++ b/fs/qnx6/Kconfig
@@ -0,0 +1,26 @@
1config QNX6FS_FS
2 tristate "QNX6 file system support (read only)"
3 depends on BLOCK && CRC32
4 help
5 This is the file system used by the real-time operating systems
6 QNX 6 (also called QNX RTP).
7 Further information is available at <http://www.qnx.com/>.
8 Say Y if you intend to mount QNX hard disks or floppies formatted
9 with a mkqnx6fs.
10 However, keep in mind that this currently is a readonly driver!
11
12 To compile this file system support as a module, choose M here: the
13 module will be called qnx6.
14
15 If you don't know whether you need it, then you don't need it:
16 answer N.
17
18config QNX6FS_DEBUG
19 bool "QNX6 debugging information"
20 depends on QNX6FS_FS
21 help
22 Turns on extended debugging output.
23
24 If you are not a developer working on the QNX6FS, you probably don't
25 want this:
26 answer N.
diff --git a/fs/qnx6/Makefile b/fs/qnx6/Makefile
new file mode 100644
index 000000000000..9dd06199afc9
--- /dev/null
+++ b/fs/qnx6/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the linux qnx4-filesystem routines.
3#
4
5obj-$(CONFIG_QNX6FS_FS) += qnx6.o
6
7qnx6-objs := inode.o dir.o namei.o super_mmi.o
diff --git a/fs/qnx6/README b/fs/qnx6/README
new file mode 100644
index 000000000000..116d622026cc
--- /dev/null
+++ b/fs/qnx6/README
@@ -0,0 +1,8 @@
1
2 This is a snapshot of the QNX6 filesystem for Linux.
3 Please send diffs and remarks to <chaosman@ontika.net> .
4
5Credits :
6
7Al Viro <viro@ZenIV.linux.org.uk> (endless patience with me & support ;))
8Kai Bankett <chaosman@ontika.net> (Maintainer)
diff --git a/fs/qnx6/dir.c b/fs/qnx6/dir.c
new file mode 100644
index 000000000000..dc597353db3b
--- /dev/null
+++ b/fs/qnx6/dir.c
@@ -0,0 +1,291 @@
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 * 16-02-2012 pagemap extension by Al Viro
10 *
11 */
12
13#include "qnx6.h"
14
15static unsigned qnx6_lfile_checksum(char *name, unsigned size)
16{
17 unsigned crc = 0;
18 char *end = name + size;
19 while (name < end) {
20 crc = ((crc >> 1) + *(name++)) ^
21 ((crc & 0x00000001) ? 0x80000000 : 0);
22 }
23 return crc;
24}
25
26static struct page *qnx6_get_page(struct inode *dir, unsigned long n)
27{
28 struct address_space *mapping = dir->i_mapping;
29 struct page *page = read_mapping_page(mapping, n, NULL);
30 if (!IS_ERR(page))
31 kmap(page);
32 return page;
33}
34
35static inline unsigned long dir_pages(struct inode *inode)
36{
37 return (inode->i_size+PAGE_CACHE_SIZE-1)>>PAGE_CACHE_SHIFT;
38}
39
40static unsigned last_entry(struct inode *inode, unsigned long page_nr)
41{
42 unsigned long last_byte = inode->i_size;
43 last_byte -= page_nr << PAGE_CACHE_SHIFT;
44 if (last_byte > PAGE_CACHE_SIZE)
45 last_byte = PAGE_CACHE_SIZE;
46 return last_byte / QNX6_DIR_ENTRY_SIZE;
47}
48
49static struct qnx6_long_filename *qnx6_longname(struct super_block *sb,
50 struct qnx6_long_dir_entry *de,
51 struct page **p)
52{
53 struct qnx6_sb_info *sbi = QNX6_SB(sb);
54 u32 s = fs32_to_cpu(sbi, de->de_long_inode); /* in block units */
55 u32 n = s >> (PAGE_CACHE_SHIFT - sb->s_blocksize_bits); /* in pages */
56 /* within page */
57 u32 offs = (s << sb->s_blocksize_bits) & ~PAGE_CACHE_MASK;
58 struct address_space *mapping = sbi->longfile->i_mapping;
59 struct page *page = read_mapping_page(mapping, n, NULL);
60 if (IS_ERR(page))
61 return ERR_CAST(page);
62 kmap(*p = page);
63 return (struct qnx6_long_filename *)(page_address(page) + offs);
64}
65
66static int qnx6_dir_longfilename(struct inode *inode,
67 struct qnx6_long_dir_entry *de,
68 void *dirent, loff_t pos,
69 unsigned de_inode, filldir_t filldir)
70{
71 struct qnx6_long_filename *lf;
72 struct super_block *s = inode->i_sb;
73 struct qnx6_sb_info *sbi = QNX6_SB(s);
74 struct page *page;
75 int lf_size;
76
77 if (de->de_size != 0xff) {
78 /* error - long filename entries always have size 0xff
79 in direntry */
80 printk(KERN_ERR "qnx6: invalid direntry size (%i).\n",
81 de->de_size);
82 return 0;
83 }
84 lf = qnx6_longname(s, de, &page);
85 if (IS_ERR(lf)) {
86 printk(KERN_ERR "qnx6:Error reading longname\n");
87 return 0;
88 }
89
90 lf_size = fs16_to_cpu(sbi, lf->lf_size);
91
92 if (lf_size > QNX6_LONG_NAME_MAX) {
93 QNX6DEBUG((KERN_INFO "file %s\n", lf->lf_fname));
94 printk(KERN_ERR "qnx6:Filename too long (%i)\n", lf_size);
95 qnx6_put_page(page);
96 return 0;
97 }
98
99 /* calc & validate longfilename checksum
100 mmi 3g filesystem does not have that checksum */
101 if (!test_opt(s, MMI_FS) && fs32_to_cpu(sbi, de->de_checksum) !=
102 qnx6_lfile_checksum(lf->lf_fname, lf_size))
103 printk(KERN_INFO "qnx6: long filename checksum error.\n");
104
105 QNX6DEBUG((KERN_INFO "qnx6_readdir:%.*s inode:%u\n",
106 lf_size, lf->lf_fname, de_inode));
107 if (filldir(dirent, lf->lf_fname, lf_size, pos, de_inode,
108 DT_UNKNOWN) < 0) {
109 qnx6_put_page(page);
110 return 0;
111 }
112
113 qnx6_put_page(page);
114 /* success */
115 return 1;
116}
117
118static int qnx6_readdir(struct file *filp, void *dirent, filldir_t filldir)
119{
120 struct inode *inode = filp->f_path.dentry->d_inode;
121 struct super_block *s = inode->i_sb;
122 struct qnx6_sb_info *sbi = QNX6_SB(s);
123 loff_t pos = filp->f_pos & (QNX6_DIR_ENTRY_SIZE - 1);
124 unsigned long npages = dir_pages(inode);
125 unsigned long n = pos >> PAGE_CACHE_SHIFT;
126 unsigned start = (pos & ~PAGE_CACHE_MASK) / QNX6_DIR_ENTRY_SIZE;
127 bool done = false;
128
129 if (filp->f_pos >= inode->i_size)
130 return 0;
131
132 for ( ; !done && n < npages; n++, start = 0) {
133 struct page *page = qnx6_get_page(inode, n);
134 int limit = last_entry(inode, n);
135 struct qnx6_dir_entry *de;
136 int i = start;
137
138 if (IS_ERR(page)) {
139 printk(KERN_ERR "qnx6_readdir: read failed\n");
140 filp->f_pos = (n + 1) << PAGE_CACHE_SHIFT;
141 return PTR_ERR(page);
142 }
143 de = ((struct qnx6_dir_entry *)page_address(page)) + start;
144 for (; i < limit; i++, de++, pos += QNX6_DIR_ENTRY_SIZE) {
145 int size = de->de_size;
146 u32 no_inode = fs32_to_cpu(sbi, de->de_inode);
147
148 if (!no_inode || !size)
149 continue;
150
151 if (size > QNX6_SHORT_NAME_MAX) {
152 /* long filename detected
153 get the filename from long filename
154 structure / block */
155 if (!qnx6_dir_longfilename(inode,
156 (struct qnx6_long_dir_entry *)de,
157 dirent, pos, no_inode,
158 filldir)) {
159 done = true;
160 break;
161 }
162 } else {
163 QNX6DEBUG((KERN_INFO "qnx6_readdir:%.*s"
164 " inode:%u\n", size, de->de_fname,
165 no_inode));
166 if (filldir(dirent, de->de_fname, size,
167 pos, no_inode, DT_UNKNOWN)
168 < 0) {
169 done = true;
170 break;
171 }
172 }
173 }
174 qnx6_put_page(page);
175 }
176 filp->f_pos = pos;
177 return 0;
178}
179
180/*
181 * check if the long filename is correct.
182 */
183static unsigned qnx6_long_match(int len, const char *name,
184 struct qnx6_long_dir_entry *de, struct inode *dir)
185{
186 struct super_block *s = dir->i_sb;
187 struct qnx6_sb_info *sbi = QNX6_SB(s);
188 struct page *page;
189 int thislen;
190 struct qnx6_long_filename *lf = qnx6_longname(s, de, &page);
191
192 if (IS_ERR(lf))
193 return 0;
194
195 thislen = fs16_to_cpu(sbi, lf->lf_size);
196 if (len != thislen) {
197 qnx6_put_page(page);
198 return 0;
199 }
200 if (memcmp(name, lf->lf_fname, len) == 0) {
201 qnx6_put_page(page);
202 return fs32_to_cpu(sbi, de->de_inode);
203 }
204 qnx6_put_page(page);
205 return 0;
206}
207
208/*
209 * check if the filename is correct.
210 */
211static unsigned qnx6_match(struct super_block *s, int len, const char *name,
212 struct qnx6_dir_entry *de)
213{
214 struct qnx6_sb_info *sbi = QNX6_SB(s);
215 if (memcmp(name, de->de_fname, len) == 0)
216 return fs32_to_cpu(sbi, de->de_inode);
217 return 0;
218}
219
220
221unsigned qnx6_find_entry(int len, struct inode *dir, const char *name,
222 struct page **res_page)
223{
224 struct super_block *s = dir->i_sb;
225 struct qnx6_inode_info *ei = QNX6_I(dir);
226 struct page *page = NULL;
227 unsigned long start, n;
228 unsigned long npages = dir_pages(dir);
229 unsigned ino;
230 struct qnx6_dir_entry *de;
231 struct qnx6_long_dir_entry *lde;
232
233 *res_page = NULL;
234
235 if (npages == 0)
236 return 0;
237 start = ei->i_dir_start_lookup;
238 if (start >= npages)
239 start = 0;
240 n = start;
241
242 do {
243 page = qnx6_get_page(dir, n);
244 if (!IS_ERR(page)) {
245 int limit = last_entry(dir, n);
246 int i;
247
248 de = (struct qnx6_dir_entry *)page_address(page);
249 for (i = 0; i < limit; i++, de++) {
250 if (len <= QNX6_SHORT_NAME_MAX) {
251 /* short filename */
252 if (len != de->de_size)
253 continue;
254 ino = qnx6_match(s, len, name, de);
255 if (ino)
256 goto found;
257 } else if (de->de_size == 0xff) {
258 /* deal with long filename */
259 lde = (struct qnx6_long_dir_entry *)de;
260 ino = qnx6_long_match(len,
261 name, lde, dir);
262 if (ino)
263 goto found;
264 } else
265 printk(KERN_ERR "qnx6: undefined "
266 "filename size in inode.\n");
267 }
268 qnx6_put_page(page);
269 }
270
271 if (++n >= npages)
272 n = 0;
273 } while (n != start);
274 return 0;
275
276found:
277 *res_page = page;
278 ei->i_dir_start_lookup = n;
279 return ino;
280}
281
282const struct file_operations qnx6_dir_operations = {
283 .llseek = generic_file_llseek,
284 .read = generic_read_dir,
285 .readdir = qnx6_readdir,
286 .fsync = generic_file_fsync,
287};
288
289const struct inode_operations qnx6_dir_inode_operations = {
290 .lookup = qnx6_lookup,
291};
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
new file mode 100644
index 000000000000..e44012dc5645
--- /dev/null
+++ b/fs/qnx6/inode.c
@@ -0,0 +1,698 @@
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 * 16-02-2012 pagemap extension by Al Viro
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/highuid.h>
17#include <linux/pagemap.h>
18#include <linux/buffer_head.h>
19#include <linux/writeback.h>
20#include <linux/statfs.h>
21#include <linux/parser.h>
22#include <linux/seq_file.h>
23#include <linux/mount.h>
24#include <linux/crc32.h>
25#include <linux/mpage.h>
26#include "qnx6.h"
27
28static const struct super_operations qnx6_sops;
29
30static void qnx6_put_super(struct super_block *sb);
31static struct inode *qnx6_alloc_inode(struct super_block *sb);
32static void qnx6_destroy_inode(struct inode *inode);
33static int qnx6_remount(struct super_block *sb, int *flags, char *data);
34static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf);
35static int qnx6_show_options(struct seq_file *seq, struct dentry *root);
36
37static const struct super_operations qnx6_sops = {
38 .alloc_inode = qnx6_alloc_inode,
39 .destroy_inode = qnx6_destroy_inode,
40 .put_super = qnx6_put_super,
41 .statfs = qnx6_statfs,
42 .remount_fs = qnx6_remount,
43 .show_options = qnx6_show_options,
44};
45
46static int qnx6_show_options(struct seq_file *seq, struct dentry *root)
47{
48 struct super_block *sb = root->d_sb;
49 struct qnx6_sb_info *sbi = QNX6_SB(sb);
50
51 if (sbi->s_mount_opt & QNX6_MOUNT_MMI_FS)
52 seq_puts(seq, ",mmi_fs");
53 return 0;
54}
55
56static int qnx6_remount(struct super_block *sb, int *flags, char *data)
57{
58 *flags |= MS_RDONLY;
59 return 0;
60}
61
62static unsigned qnx6_get_devblock(struct super_block *sb, __fs32 block)
63{
64 struct qnx6_sb_info *sbi = QNX6_SB(sb);
65 return fs32_to_cpu(sbi, block) + sbi->s_blks_off;
66}
67
68static unsigned qnx6_block_map(struct inode *inode, unsigned iblock);
69
70static int qnx6_get_block(struct inode *inode, sector_t iblock,
71 struct buffer_head *bh, int create)
72{
73 unsigned phys;
74
75 QNX6DEBUG((KERN_INFO "qnx6: qnx6_get_block inode=[%ld] iblock=[%ld]\n",
76 inode->i_ino, (unsigned long)iblock));
77
78 phys = qnx6_block_map(inode, iblock);
79 if (phys) {
80 /* logical block is before EOF */
81 map_bh(bh, inode->i_sb, phys);
82 }
83 return 0;
84}
85
86static int qnx6_check_blockptr(__fs32 ptr)
87{
88 if (ptr == ~(__fs32)0) {
89 printk(KERN_ERR "qnx6: hit unused blockpointer.\n");
90 return 0;
91 }
92 return 1;
93}
94
95static int qnx6_readpage(struct file *file, struct page *page)
96{
97 return mpage_readpage(page, qnx6_get_block);
98}
99
100static int qnx6_readpages(struct file *file, struct address_space *mapping,
101 struct list_head *pages, unsigned nr_pages)
102{
103 return mpage_readpages(mapping, pages, nr_pages, qnx6_get_block);
104}
105
106/*
107 * returns the block number for the no-th element in the tree
108 * inodebits requred as there are multiple inodes in one inode block
109 */
110static unsigned qnx6_block_map(struct inode *inode, unsigned no)
111{
112 struct super_block *s = inode->i_sb;
113 struct qnx6_sb_info *sbi = QNX6_SB(s);
114 struct qnx6_inode_info *ei = QNX6_I(inode);
115 unsigned block = 0;
116 struct buffer_head *bh;
117 __fs32 ptr;
118 int levelptr;
119 int ptrbits = sbi->s_ptrbits;
120 int bitdelta;
121 u32 mask = (1 << ptrbits) - 1;
122 int depth = ei->di_filelevels;
123 int i;
124
125 bitdelta = ptrbits * depth;
126 levelptr = no >> bitdelta;
127
128 if (levelptr > QNX6_NO_DIRECT_POINTERS - 1) {
129 printk(KERN_ERR "qnx6:Requested file block number (%u) too big.",
130 no);
131 return 0;
132 }
133
134 block = qnx6_get_devblock(s, ei->di_block_ptr[levelptr]);
135
136 for (i = 0; i < depth; i++) {
137 bh = sb_bread(s, block);
138 if (!bh) {
139 printk(KERN_ERR "qnx6:Error reading block (%u)\n",
140 block);
141 return 0;
142 }
143 bitdelta -= ptrbits;
144 levelptr = (no >> bitdelta) & mask;
145 ptr = ((__fs32 *)bh->b_data)[levelptr];
146
147 if (!qnx6_check_blockptr(ptr))
148 return 0;
149
150 block = qnx6_get_devblock(s, ptr);
151 brelse(bh);
152 }
153 return block;
154}
155
156static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
157{
158 struct super_block *sb = dentry->d_sb;
159 struct qnx6_sb_info *sbi = QNX6_SB(sb);
160 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
161
162 buf->f_type = sb->s_magic;
163 buf->f_bsize = sb->s_blocksize;
164 buf->f_blocks = fs32_to_cpu(sbi, sbi->sb->sb_num_blocks);
165 buf->f_bfree = fs32_to_cpu(sbi, sbi->sb->sb_free_blocks);
166 buf->f_files = fs32_to_cpu(sbi, sbi->sb->sb_num_inodes);
167 buf->f_ffree = fs32_to_cpu(sbi, sbi->sb->sb_free_inodes);
168 buf->f_bavail = buf->f_bfree;
169 buf->f_namelen = QNX6_LONG_NAME_MAX;
170 buf->f_fsid.val[0] = (u32)id;
171 buf->f_fsid.val[1] = (u32)(id >> 32);
172
173 return 0;
174}
175
176/*
177 * Check the root directory of the filesystem to make sure
178 * it really _is_ a qnx6 filesystem, and to check the size
179 * of the directory entry.
180 */
181static const char *qnx6_checkroot(struct super_block *s)
182{
183 static char match_root[2][3] = {".\0\0", "..\0"};
184 int i, error = 0;
185 struct qnx6_dir_entry *dir_entry;
186 struct inode *root = s->s_root->d_inode;
187 struct address_space *mapping = root->i_mapping;
188 struct page *page = read_mapping_page(mapping, 0, NULL);
189 if (IS_ERR(page))
190 return "error reading root directory";
191 kmap(page);
192 dir_entry = page_address(page);
193 for (i = 0; i < 2; i++) {
194 /* maximum 3 bytes - due to match_root limitation */
195 if (strncmp(dir_entry[i].de_fname, match_root[i], 3))
196 error = 1;
197 }
198 qnx6_put_page(page);
199 if (error)
200 return "error reading root directory.";
201 return NULL;
202}
203
204#ifdef CONFIG_QNX6FS_DEBUG
205void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
206{
207 struct qnx6_sb_info *sbi = QNX6_SB(s);
208
209 QNX6DEBUG((KERN_INFO "magic: %08x\n",
210 fs32_to_cpu(sbi, sb->sb_magic)));
211 QNX6DEBUG((KERN_INFO "checksum: %08x\n",
212 fs32_to_cpu(sbi, sb->sb_checksum)));
213 QNX6DEBUG((KERN_INFO "serial: %llx\n",
214 fs64_to_cpu(sbi, sb->sb_serial)));
215 QNX6DEBUG((KERN_INFO "flags: %08x\n",
216 fs32_to_cpu(sbi, sb->sb_flags)));
217 QNX6DEBUG((KERN_INFO "blocksize: %08x\n",
218 fs32_to_cpu(sbi, sb->sb_blocksize)));
219 QNX6DEBUG((KERN_INFO "num_inodes: %08x\n",
220 fs32_to_cpu(sbi, sb->sb_num_inodes)));
221 QNX6DEBUG((KERN_INFO "free_inodes: %08x\n",
222 fs32_to_cpu(sbi, sb->sb_free_inodes)));
223 QNX6DEBUG((KERN_INFO "num_blocks: %08x\n",
224 fs32_to_cpu(sbi, sb->sb_num_blocks)));
225 QNX6DEBUG((KERN_INFO "free_blocks: %08x\n",
226 fs32_to_cpu(sbi, sb->sb_free_blocks)));
227 QNX6DEBUG((KERN_INFO "inode_levels: %02x\n",
228 sb->Inode.levels));
229}
230#endif
231
232enum {
233 Opt_mmifs,
234 Opt_err
235};
236
237static const match_table_t tokens = {
238 {Opt_mmifs, "mmi_fs"},
239 {Opt_err, NULL}
240};
241
242static int qnx6_parse_options(char *options, struct super_block *sb)
243{
244 char *p;
245 struct qnx6_sb_info *sbi = QNX6_SB(sb);
246 substring_t args[MAX_OPT_ARGS];
247
248 if (!options)
249 return 1;
250
251 while ((p = strsep(&options, ",")) != NULL) {
252 int token;
253 if (!*p)
254 continue;
255
256 token = match_token(p, tokens, args);
257 switch (token) {
258 case Opt_mmifs:
259 set_opt(sbi->s_mount_opt, MMI_FS);
260 break;
261 default:
262 return 0;
263 }
264 }
265 return 1;
266}
267
268static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
269 int offset, int silent)
270{
271 struct qnx6_sb_info *sbi = QNX6_SB(s);
272 struct buffer_head *bh;
273 struct qnx6_super_block *sb;
274
275 /* Check the superblock signatures
276 start with the first superblock */
277 bh = sb_bread(s, offset);
278 if (!bh) {
279 printk(KERN_ERR "qnx6: unable to read the first superblock\n");
280 return NULL;
281 }
282 sb = (struct qnx6_super_block *)bh->b_data;
283 if (fs32_to_cpu(sbi, sb->sb_magic) != QNX6_SUPER_MAGIC) {
284 sbi->s_bytesex = BYTESEX_BE;
285 if (fs32_to_cpu(sbi, sb->sb_magic) == QNX6_SUPER_MAGIC) {
286 /* we got a big endian fs */
287 QNX6DEBUG((KERN_INFO "qnx6: fs got different"
288 " endianess.\n"));
289 return bh;
290 } else
291 sbi->s_bytesex = BYTESEX_LE;
292 if (!silent) {
293 if (offset == 0) {
294 printk(KERN_ERR "qnx6: wrong signature (magic)"
295 " in superblock #1.\n");
296 } else {
297 printk(KERN_INFO "qnx6: wrong signature (magic)"
298 " at position (0x%lx) - will try"
299 " alternative position (0x0000).\n",
300 offset * s->s_blocksize);
301 }
302 }
303 brelse(bh);
304 return NULL;
305 }
306 return bh;
307}
308
309static struct inode *qnx6_private_inode(struct super_block *s,
310 struct qnx6_root_node *p);
311
312static int qnx6_fill_super(struct super_block *s, void *data, int silent)
313{
314 struct buffer_head *bh1 = NULL, *bh2 = NULL;
315 struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
316 struct qnx6_sb_info *sbi;
317 struct inode *root;
318 const char *errmsg;
319 struct qnx6_sb_info *qs;
320 int ret = -EINVAL;
321 u64 offset;
322 int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
323
324 qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
325 if (!qs)
326 return -ENOMEM;
327 s->s_fs_info = qs;
328
329 /* Superblock always is 512 Byte long */
330 if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
331 printk(KERN_ERR "qnx6: unable to set blocksize\n");
332 goto outnobh;
333 }
334
335 /* parse the mount-options */
336 if (!qnx6_parse_options((char *) data, s)) {
337 printk(KERN_ERR "qnx6: invalid mount options.\n");
338 goto outnobh;
339 }
340 if (test_opt(s, MMI_FS)) {
341 sb1 = qnx6_mmi_fill_super(s, silent);
342 if (sb1)
343 goto mmi_success;
344 else
345 goto outnobh;
346 }
347 sbi = QNX6_SB(s);
348 sbi->s_bytesex = BYTESEX_LE;
349 /* Check the superblock signatures
350 start with the first superblock */
351 bh1 = qnx6_check_first_superblock(s,
352 bootblock_offset / QNX6_SUPERBLOCK_SIZE, silent);
353 if (!bh1) {
354 /* try again without bootblock offset */
355 bh1 = qnx6_check_first_superblock(s, 0, silent);
356 if (!bh1) {
357 printk(KERN_ERR "qnx6: unable to read the first superblock\n");
358 goto outnobh;
359 }
360 /* seems that no bootblock at partition start */
361 bootblock_offset = 0;
362 }
363 sb1 = (struct qnx6_super_block *)bh1->b_data;
364
365#ifdef CONFIG_QNX6FS_DEBUG
366 qnx6_superblock_debug(sb1, s);
367#endif
368
369 /* checksum check - start at byte 8 and end at byte 512 */
370 if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
371 crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
372 printk(KERN_ERR "qnx6: superblock #1 checksum error\n");
373 goto out;
374 }
375
376 /* set new blocksize */
377 if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
378 printk(KERN_ERR "qnx6: unable to set blocksize\n");
379 goto out;
380 }
381 /* blocksize invalidates bh - pull it back in */
382 brelse(bh1);
383 bh1 = sb_bread(s, bootblock_offset >> s->s_blocksize_bits);
384 if (!bh1)
385 goto outnobh;
386 sb1 = (struct qnx6_super_block *)bh1->b_data;
387
388 /* calculate second superblock blocknumber */
389 offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) +
390 (bootblock_offset >> s->s_blocksize_bits) +
391 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
392
393 /* set bootblock offset */
394 sbi->s_blks_off = (bootblock_offset >> s->s_blocksize_bits) +
395 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
396
397 /* next the second superblock */
398 bh2 = sb_bread(s, offset);
399 if (!bh2) {
400 printk(KERN_ERR "qnx6: unable to read the second superblock\n");
401 goto out;
402 }
403 sb2 = (struct qnx6_super_block *)bh2->b_data;
404 if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
405 if (!silent)
406 printk(KERN_ERR "qnx6: wrong signature (magic)"
407 " in superblock #2.\n");
408 goto out;
409 }
410
411 /* checksum check - start at byte 8 and end at byte 512 */
412 if (fs32_to_cpu(sbi, sb2->sb_checksum) !=
413 crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
414 printk(KERN_ERR "qnx6: superblock #2 checksum error\n");
415 goto out;
416 }
417
418 if (fs64_to_cpu(sbi, sb1->sb_serial) >=
419 fs64_to_cpu(sbi, sb2->sb_serial)) {
420 /* superblock #1 active */
421 sbi->sb_buf = bh1;
422 sbi->sb = (struct qnx6_super_block *)bh1->b_data;
423 brelse(bh2);
424 printk(KERN_INFO "qnx6: superblock #1 active\n");
425 } else {
426 /* superblock #2 active */
427 sbi->sb_buf = bh2;
428 sbi->sb = (struct qnx6_super_block *)bh2->b_data;
429 brelse(bh1);
430 printk(KERN_INFO "qnx6: superblock #2 active\n");
431 }
432mmi_success:
433 /* sanity check - limit maximum indirect pointer levels */
434 if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
435 printk(KERN_ERR "qnx6: too many inode levels (max %i, sb %i)\n",
436 QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
437 goto out;
438 }
439 if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
440 printk(KERN_ERR "qnx6: too many longfilename levels"
441 " (max %i, sb %i)\n",
442 QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
443 goto out;
444 }
445 s->s_op = &qnx6_sops;
446 s->s_magic = QNX6_SUPER_MAGIC;
447 s->s_flags |= MS_RDONLY; /* Yup, read-only yet */
448
449 /* ease the later tree level calculations */
450 sbi = QNX6_SB(s);
451 sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
452 sbi->inodes = qnx6_private_inode(s, &sb1->Inode);
453 if (!sbi->inodes)
454 goto out;
455 sbi->longfile = qnx6_private_inode(s, &sb1->Longfile);
456 if (!sbi->longfile)
457 goto out1;
458
459 /* prefetch root inode */
460 root = qnx6_iget(s, QNX6_ROOT_INO);
461 if (IS_ERR(root)) {
462 printk(KERN_ERR "qnx6: get inode failed\n");
463 ret = PTR_ERR(root);
464 goto out2;
465 }
466
467 ret = -ENOMEM;
468 s->s_root = d_make_root(root);
469 if (!s->s_root)
470 goto out2;
471
472 ret = -EINVAL;
473 errmsg = qnx6_checkroot(s);
474 if (errmsg != NULL) {
475 if (!silent)
476 printk(KERN_ERR "qnx6: %s\n", errmsg);
477 goto out3;
478 }
479 return 0;
480
481out3:
482 dput(s->s_root);
483 s->s_root = NULL;
484out2:
485 iput(sbi->longfile);
486out1:
487 iput(sbi->inodes);
488out:
489 if (bh1)
490 brelse(bh1);
491 if (bh2)
492 brelse(bh2);
493outnobh:
494 kfree(qs);
495 s->s_fs_info = NULL;
496 return ret;
497}
498
499static void qnx6_put_super(struct super_block *sb)
500{
501 struct qnx6_sb_info *qs = QNX6_SB(sb);
502 brelse(qs->sb_buf);
503 iput(qs->longfile);
504 iput(qs->inodes);
505 kfree(qs);
506 sb->s_fs_info = NULL;
507 return;
508}
509
510static sector_t qnx6_bmap(struct address_space *mapping, sector_t block)
511{
512 return generic_block_bmap(mapping, block, qnx6_get_block);
513}
514static const struct address_space_operations qnx6_aops = {
515 .readpage = qnx6_readpage,
516 .readpages = qnx6_readpages,
517 .bmap = qnx6_bmap
518};
519
520static struct inode *qnx6_private_inode(struct super_block *s,
521 struct qnx6_root_node *p)
522{
523 struct inode *inode = new_inode(s);
524 if (inode) {
525 struct qnx6_inode_info *ei = QNX6_I(inode);
526 struct qnx6_sb_info *sbi = QNX6_SB(s);
527 inode->i_size = fs64_to_cpu(sbi, p->size);
528 memcpy(ei->di_block_ptr, p->ptr, sizeof(p->ptr));
529 ei->di_filelevels = p->levels;
530 inode->i_mode = S_IFREG | S_IRUSR; /* probably wrong */
531 inode->i_mapping->a_ops = &qnx6_aops;
532 }
533 return inode;
534}
535
536struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
537{
538 struct qnx6_sb_info *sbi = QNX6_SB(sb);
539 struct qnx6_inode_entry *raw_inode;
540 struct inode *inode;
541 struct qnx6_inode_info *ei;
542 struct address_space *mapping;
543 struct page *page;
544 u32 n, offs;
545
546 inode = iget_locked(sb, ino);
547 if (!inode)
548 return ERR_PTR(-ENOMEM);
549 if (!(inode->i_state & I_NEW))
550 return inode;
551
552 ei = QNX6_I(inode);
553
554 inode->i_mode = 0;
555
556 if (ino == 0) {
557 printk(KERN_ERR "qnx6: bad inode number on dev %s: %u is "
558 "out of range\n",
559 sb->s_id, ino);
560 iget_failed(inode);
561 return ERR_PTR(-EIO);
562 }
563 n = (ino - 1) >> (PAGE_CACHE_SHIFT - QNX6_INODE_SIZE_BITS);
564 offs = (ino - 1) & (~PAGE_CACHE_MASK >> QNX6_INODE_SIZE_BITS);
565 mapping = sbi->inodes->i_mapping;
566 page = read_mapping_page(mapping, n, NULL);
567 if (IS_ERR(page)) {
568 printk(KERN_ERR "qnx6: major problem: unable to read inode from "
569 "dev %s\n", sb->s_id);
570 iget_failed(inode);
571 return ERR_CAST(page);
572 }
573 kmap(page);
574 raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs;
575
576 inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode);
577 inode->i_uid = (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid);
578 inode->i_gid = (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid);
579 inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size);
580 inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_mtime);
581 inode->i_mtime.tv_nsec = 0;
582 inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_atime);
583 inode->i_atime.tv_nsec = 0;
584 inode->i_ctime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_ctime);
585 inode->i_ctime.tv_nsec = 0;
586
587 /* calc blocks based on 512 byte blocksize */
588 inode->i_blocks = (inode->i_size + 511) >> 9;
589
590 memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
591 sizeof(raw_inode->di_block_ptr));
592 ei->di_filelevels = raw_inode->di_filelevels;
593
594 if (S_ISREG(inode->i_mode)) {
595 inode->i_fop = &generic_ro_fops;
596 inode->i_mapping->a_ops = &qnx6_aops;
597 } else if (S_ISDIR(inode->i_mode)) {
598 inode->i_op = &qnx6_dir_inode_operations;
599 inode->i_fop = &qnx6_dir_operations;
600 inode->i_mapping->a_ops = &qnx6_aops;
601 } else if (S_ISLNK(inode->i_mode)) {
602 inode->i_op = &page_symlink_inode_operations;
603 inode->i_mapping->a_ops = &qnx6_aops;
604 } else
605 init_special_inode(inode, inode->i_mode, 0);
606 qnx6_put_page(page);
607 unlock_new_inode(inode);
608 return inode;
609}
610
611static struct kmem_cache *qnx6_inode_cachep;
612
613static struct inode *qnx6_alloc_inode(struct super_block *sb)
614{
615 struct qnx6_inode_info *ei;
616 ei = kmem_cache_alloc(qnx6_inode_cachep, GFP_KERNEL);
617 if (!ei)
618 return NULL;
619 return &ei->vfs_inode;
620}
621
622static void qnx6_i_callback(struct rcu_head *head)
623{
624 struct inode *inode = container_of(head, struct inode, i_rcu);
625 INIT_LIST_HEAD(&inode->i_dentry);
626 kmem_cache_free(qnx6_inode_cachep, QNX6_I(inode));
627}
628
629static void qnx6_destroy_inode(struct inode *inode)
630{
631 call_rcu(&inode->i_rcu, qnx6_i_callback);
632}
633
634static void init_once(void *foo)
635{
636 struct qnx6_inode_info *ei = (struct qnx6_inode_info *) foo;
637
638 inode_init_once(&ei->vfs_inode);
639}
640
641static int init_inodecache(void)
642{
643 qnx6_inode_cachep = kmem_cache_create("qnx6_inode_cache",
644 sizeof(struct qnx6_inode_info),
645 0, (SLAB_RECLAIM_ACCOUNT|
646 SLAB_MEM_SPREAD),
647 init_once);
648 if (!qnx6_inode_cachep)
649 return -ENOMEM;
650 return 0;
651}
652
653static void destroy_inodecache(void)
654{
655 kmem_cache_destroy(qnx6_inode_cachep);
656}
657
658static struct dentry *qnx6_mount(struct file_system_type *fs_type,
659 int flags, const char *dev_name, void *data)
660{
661 return mount_bdev(fs_type, flags, dev_name, data, qnx6_fill_super);
662}
663
664static struct file_system_type qnx6_fs_type = {
665 .owner = THIS_MODULE,
666 .name = "qnx6",
667 .mount = qnx6_mount,
668 .kill_sb = kill_block_super,
669 .fs_flags = FS_REQUIRES_DEV,
670};
671
672static int __init init_qnx6_fs(void)
673{
674 int err;
675
676 err = init_inodecache();
677 if (err)
678 return err;
679
680 err = register_filesystem(&qnx6_fs_type);
681 if (err) {
682 destroy_inodecache();
683 return err;
684 }
685
686 printk(KERN_INFO "QNX6 filesystem 1.0.0 registered.\n");
687 return 0;
688}
689
690static void __exit exit_qnx6_fs(void)
691{
692 unregister_filesystem(&qnx6_fs_type);
693 destroy_inodecache();
694}
695
696module_init(init_qnx6_fs)
697module_exit(exit_qnx6_fs)
698MODULE_LICENSE("GPL");
diff --git a/fs/qnx6/namei.c b/fs/qnx6/namei.c
new file mode 100644
index 000000000000..8a97289e04ad
--- /dev/null
+++ b/fs/qnx6/namei.c
@@ -0,0 +1,42 @@
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 * 16-02-2012 pagemap extension by Al Viro
10 *
11 */
12
13#include "qnx6.h"
14
15struct dentry *qnx6_lookup(struct inode *dir, struct dentry *dentry,
16 struct nameidata *nd)
17{
18 unsigned ino;
19 struct page *page;
20 struct inode *foundinode = NULL;
21 const char *name = dentry->d_name.name;
22 int len = dentry->d_name.len;
23
24 if (len > QNX6_LONG_NAME_MAX)
25 return ERR_PTR(-ENAMETOOLONG);
26
27 ino = qnx6_find_entry(len, dir, name, &page);
28 if (ino) {
29 foundinode = qnx6_iget(dir->i_sb, ino);
30 qnx6_put_page(page);
31 if (IS_ERR(foundinode)) {
32 QNX6DEBUG((KERN_ERR "qnx6: lookup->iget -> "
33 " error %ld\n", PTR_ERR(foundinode)));
34 return ERR_CAST(foundinode);
35 }
36 } else {
37 QNX6DEBUG((KERN_INFO "qnx6_lookup: not found %s\n", name));
38 return NULL;
39 }
40 d_add(dentry, foundinode);
41 return NULL;
42}
diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
new file mode 100644
index 000000000000..6c5e02a0b6a8
--- /dev/null
+++ b/fs/qnx6/qnx6.h
@@ -0,0 +1,135 @@
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 * 16-02-2012 page map extension by Al Viro
10 *
11 */
12
13#include <linux/fs.h>
14#include <linux/pagemap.h>
15
16typedef __u16 __bitwise __fs16;
17typedef __u32 __bitwise __fs32;
18typedef __u64 __bitwise __fs64;
19
20#include <linux/qnx6_fs.h>
21
22#ifdef CONFIG_QNX6FS_DEBUG
23#define QNX6DEBUG(X) printk X
24#else
25#define QNX6DEBUG(X) (void) 0
26#endif
27
28struct qnx6_sb_info {
29 struct buffer_head *sb_buf; /* superblock buffer */
30 struct qnx6_super_block *sb; /* our superblock */
31 int s_blks_off; /* blkoffset fs-startpoint */
32 int s_ptrbits; /* indirect pointer bitfield */
33 unsigned long s_mount_opt; /* all mount options */
34 int s_bytesex; /* holds endianess info */
35 struct inode * inodes;
36 struct inode * longfile;
37};
38
39struct qnx6_inode_info {
40 __fs32 di_block_ptr[QNX6_NO_DIRECT_POINTERS];
41 __u8 di_filelevels;
42 __u32 i_dir_start_lookup;
43 struct inode vfs_inode;
44};
45
46extern struct inode *qnx6_iget(struct super_block *sb, unsigned ino);
47extern struct dentry *qnx6_lookup(struct inode *dir, struct dentry *dentry,
48 struct nameidata *nd);
49
50#ifdef CONFIG_QNX6FS_DEBUG
51extern void qnx6_superblock_debug(struct qnx6_super_block *,
52 struct super_block *);
53#endif
54
55extern const struct inode_operations qnx6_dir_inode_operations;
56extern const struct file_operations qnx6_dir_operations;
57
58static inline struct qnx6_sb_info *QNX6_SB(struct super_block *sb)
59{
60 return sb->s_fs_info;
61}
62
63static inline struct qnx6_inode_info *QNX6_I(struct inode *inode)
64{
65 return container_of(inode, struct qnx6_inode_info, vfs_inode);
66}
67
68#define clear_opt(o, opt) (o &= ~(QNX6_MOUNT_##opt))
69#define set_opt(o, opt) (o |= (QNX6_MOUNT_##opt))
70#define test_opt(sb, opt) (QNX6_SB(sb)->s_mount_opt & \
71 QNX6_MOUNT_##opt)
72enum {
73 BYTESEX_LE,
74 BYTESEX_BE,
75};
76
77static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
78{
79 if (sbi->s_bytesex == BYTESEX_LE)
80 return le64_to_cpu((__force __le64)n);
81 else
82 return be64_to_cpu((__force __be64)n);
83}
84
85static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
86{
87 if (sbi->s_bytesex == BYTESEX_LE)
88 return (__force __fs64)cpu_to_le64(n);
89 else
90 return (__force __fs64)cpu_to_be64(n);
91}
92
93static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
94{
95 if (sbi->s_bytesex == BYTESEX_LE)
96 return le32_to_cpu((__force __le32)n);
97 else
98 return be32_to_cpu((__force __be32)n);
99}
100
101static inline __fs32 cpu_to_fs32(struct qnx6_sb_info *sbi, __u32 n)
102{
103 if (sbi->s_bytesex == BYTESEX_LE)
104 return (__force __fs32)cpu_to_le32(n);
105 else
106 return (__force __fs32)cpu_to_be32(n);
107}
108
109static inline __u16 fs16_to_cpu(struct qnx6_sb_info *sbi, __fs16 n)
110{
111 if (sbi->s_bytesex == BYTESEX_LE)
112 return le16_to_cpu((__force __le16)n);
113 else
114 return be16_to_cpu((__force __be16)n);
115}
116
117static inline __fs16 cpu_to_fs16(struct qnx6_sb_info *sbi, __u16 n)
118{
119 if (sbi->s_bytesex == BYTESEX_LE)
120 return (__force __fs16)cpu_to_le16(n);
121 else
122 return (__force __fs16)cpu_to_be16(n);
123}
124
125extern struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s,
126 int silent);
127
128static inline void qnx6_put_page(struct page *page)
129{
130 kunmap(page);
131 page_cache_release(page);
132}
133
134extern unsigned qnx6_find_entry(int len, struct inode *dir, const char *name,
135 struct page **res_page);
diff --git a/fs/qnx6/super_mmi.c b/fs/qnx6/super_mmi.c
new file mode 100644
index 000000000000..29c32cba62d6
--- /dev/null
+++ b/fs/qnx6/super_mmi.c
@@ -0,0 +1,150 @@
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 *
10 */
11
12#include <linux/buffer_head.h>
13#include <linux/slab.h>
14#include <linux/crc32.h>
15#include "qnx6.h"
16
17static void qnx6_mmi_copy_sb(struct qnx6_super_block *qsb,
18 struct qnx6_mmi_super_block *sb)
19{
20 qsb->sb_magic = sb->sb_magic;
21 qsb->sb_checksum = sb->sb_checksum;
22 qsb->sb_serial = sb->sb_serial;
23 qsb->sb_blocksize = sb->sb_blocksize;
24 qsb->sb_num_inodes = sb->sb_num_inodes;
25 qsb->sb_free_inodes = sb->sb_free_inodes;
26 qsb->sb_num_blocks = sb->sb_num_blocks;
27 qsb->sb_free_blocks = sb->sb_free_blocks;
28
29 /* the rest of the superblock is the same */
30 memcpy(&qsb->Inode, &sb->Inode, sizeof(sb->Inode));
31 memcpy(&qsb->Bitmap, &sb->Bitmap, sizeof(sb->Bitmap));
32 memcpy(&qsb->Longfile, &sb->Longfile, sizeof(sb->Longfile));
33}
34
35struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent)
36{
37 struct buffer_head *bh1, *bh2 = NULL;
38 struct qnx6_mmi_super_block *sb1, *sb2;
39 struct qnx6_super_block *qsb = NULL;
40 struct qnx6_sb_info *sbi;
41 __u64 offset;
42
43 /* Check the superblock signatures
44 start with the first superblock */
45 bh1 = sb_bread(s, 0);
46 if (!bh1) {
47 printk(KERN_ERR "qnx6: Unable to read first mmi superblock\n");
48 return NULL;
49 }
50 sb1 = (struct qnx6_mmi_super_block *)bh1->b_data;
51 sbi = QNX6_SB(s);
52 if (fs32_to_cpu(sbi, sb1->sb_magic) != QNX6_SUPER_MAGIC) {
53 if (!silent) {
54 printk(KERN_ERR "qnx6: wrong signature (magic) in"
55 " superblock #1.\n");
56 goto out;
57 }
58 }
59
60 /* checksum check - start at byte 8 and end at byte 512 */
61 if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
62 crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
63 printk(KERN_ERR "qnx6: superblock #1 checksum error\n");
64 goto out;
65 }
66
67 /* calculate second superblock blocknumber */
68 offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) + QNX6_SUPERBLOCK_AREA /
69 fs32_to_cpu(sbi, sb1->sb_blocksize);
70
71 /* set new blocksize */
72 if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
73 printk(KERN_ERR "qnx6: unable to set blocksize\n");
74 goto out;
75 }
76 /* blocksize invalidates bh - pull it back in */
77 brelse(bh1);
78 bh1 = sb_bread(s, 0);
79 if (!bh1)
80 goto out;
81 sb1 = (struct qnx6_mmi_super_block *)bh1->b_data;
82
83 /* read second superblock */
84 bh2 = sb_bread(s, offset);
85 if (!bh2) {
86 printk(KERN_ERR "qnx6: unable to read the second superblock\n");
87 goto out;
88 }
89 sb2 = (struct qnx6_mmi_super_block *)bh2->b_data;
90 if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
91 if (!silent)
92 printk(KERN_ERR "qnx6: wrong signature (magic) in"
93 " superblock #2.\n");
94 goto out;
95 }
96
97 /* checksum check - start at byte 8 and end at byte 512 */
98 if (fs32_to_cpu(sbi, sb2->sb_checksum)
99 != crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
100 printk(KERN_ERR "qnx6: superblock #1 checksum error\n");
101 goto out;
102 }
103
104 qsb = kmalloc(sizeof(*qsb), GFP_KERNEL);
105 if (!qsb) {
106 printk(KERN_ERR "qnx6: unable to allocate memory.\n");
107 goto out;
108 }
109
110 if (fs64_to_cpu(sbi, sb1->sb_serial) >
111 fs64_to_cpu(sbi, sb2->sb_serial)) {
112 /* superblock #1 active */
113 qnx6_mmi_copy_sb(qsb, sb1);
114#ifdef CONFIG_QNX6FS_DEBUG
115 qnx6_superblock_debug(qsb, s);
116#endif
117 memcpy(bh1->b_data, qsb, sizeof(struct qnx6_super_block));
118
119 sbi->sb_buf = bh1;
120 sbi->sb = (struct qnx6_super_block *)bh1->b_data;
121 brelse(bh2);
122 printk(KERN_INFO "qnx6: superblock #1 active\n");
123 } else {
124 /* superblock #2 active */
125 qnx6_mmi_copy_sb(qsb, sb2);
126#ifdef CONFIG_QNX6FS_DEBUG
127 qnx6_superblock_debug(qsb, s);
128#endif
129 memcpy(bh2->b_data, qsb, sizeof(struct qnx6_super_block));
130
131 sbi->sb_buf = bh2;
132 sbi->sb = (struct qnx6_super_block *)bh2->b_data;
133 brelse(bh1);
134 printk(KERN_INFO "qnx6: superblock #2 active\n");
135 }
136 kfree(qsb);
137
138 /* offset for mmi_fs is just SUPERBLOCK_AREA bytes */
139 sbi->s_blks_off = QNX6_SUPERBLOCK_AREA / s->s_blocksize;
140
141 /* success */
142 return sbi->sb;
143
144out:
145 if (bh1 != NULL)
146 brelse(bh1);
147 if (bh2 != NULL)
148 brelse(bh2);
149 return NULL;
150}
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index aec766abe3af..a1fdabe21dec 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -209,22 +209,19 @@ static int ramfs_parse_options(char *data, struct ramfs_mount_opts *opts)
209int ramfs_fill_super(struct super_block *sb, void *data, int silent) 209int ramfs_fill_super(struct super_block *sb, void *data, int silent)
210{ 210{
211 struct ramfs_fs_info *fsi; 211 struct ramfs_fs_info *fsi;
212 struct inode *inode = NULL; 212 struct inode *inode;
213 struct dentry *root;
214 int err; 213 int err;
215 214
216 save_mount_options(sb, data); 215 save_mount_options(sb, data);
217 216
218 fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL); 217 fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
219 sb->s_fs_info = fsi; 218 sb->s_fs_info = fsi;
220 if (!fsi) { 219 if (!fsi)
221 err = -ENOMEM; 220 return -ENOMEM;
222 goto fail;
223 }
224 221
225 err = ramfs_parse_options(data, &fsi->mount_opts); 222 err = ramfs_parse_options(data, &fsi->mount_opts);
226 if (err) 223 if (err)
227 goto fail; 224 return err;
228 225
229 sb->s_maxbytes = MAX_LFS_FILESIZE; 226 sb->s_maxbytes = MAX_LFS_FILESIZE;
230 sb->s_blocksize = PAGE_CACHE_SIZE; 227 sb->s_blocksize = PAGE_CACHE_SIZE;
@@ -234,24 +231,11 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent)
234 sb->s_time_gran = 1; 231 sb->s_time_gran = 1;
235 232
236 inode = ramfs_get_inode(sb, NULL, S_IFDIR | fsi->mount_opts.mode, 0); 233 inode = ramfs_get_inode(sb, NULL, S_IFDIR | fsi->mount_opts.mode, 0);
237 if (!inode) { 234 sb->s_root = d_make_root(inode);
238 err = -ENOMEM; 235 if (!sb->s_root)
239 goto fail; 236 return -ENOMEM;
240 }
241
242 root = d_alloc_root(inode);
243 sb->s_root = root;
244 if (!root) {
245 err = -ENOMEM;
246 goto fail;
247 }
248 237
249 return 0; 238 return 0;
250fail:
251 kfree(fsi);
252 sb->s_fs_info = NULL;
253 iput(inode);
254 return err;
255} 239}
256 240
257struct dentry *ramfs_mount(struct file_system_type *fs_type, 241struct dentry *ramfs_mount(struct file_system_type *fs_type,
diff --git a/include/linux/reiserfs_acl.h b/fs/reiserfs/acl.h
index f096b80e73d8..f096b80e73d8 100644
--- a/include/linux/reiserfs_acl.h
+++ b/fs/reiserfs/acl.h
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index 70de42f09f1d..4c0c7d163d15 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -4,14 +4,12 @@
4/* Reiserfs block (de)allocator, bitmap-based. */ 4/* Reiserfs block (de)allocator, bitmap-based. */
5 5
6#include <linux/time.h> 6#include <linux/time.h>
7#include <linux/reiserfs_fs.h> 7#include "reiserfs.h"
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/vmalloc.h> 12#include <linux/vmalloc.h>
13#include <linux/reiserfs_fs_sb.h>
14#include <linux/reiserfs_fs_i.h>
15#include <linux/quotaops.h> 13#include <linux/quotaops.h>
16#include <linux/seq_file.h> 14#include <linux/seq_file.h>
17 15
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index 133e9355dc6f..66c53b642a88 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -5,7 +5,7 @@
5#include <linux/string.h> 5#include <linux/string.h>
6#include <linux/errno.h> 6#include <linux/errno.h>
7#include <linux/fs.h> 7#include <linux/fs.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9#include <linux/stat.h> 9#include <linux/stat.h>
10#include <linux/buffer_head.h> 10#include <linux/buffer_head.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 60c080440661..2b7882b508db 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -17,7 +17,7 @@
17 17
18#include <asm/uaccess.h> 18#include <asm/uaccess.h>
19#include <linux/time.h> 19#include <linux/time.h>
20#include <linux/reiserfs_fs.h> 20#include "reiserfs.h"
21#include <linux/buffer_head.h> 21#include <linux/buffer_head.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23 23
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index ace635053a36..8375c922c0d5 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -3,9 +3,9 @@
3 */ 3 */
4 4
5#include <linux/time.h> 5#include <linux/time.h>
6#include <linux/reiserfs_fs.h> 6#include "reiserfs.h"
7#include <linux/reiserfs_acl.h> 7#include "acl.h"
8#include <linux/reiserfs_xattr.h> 8#include "xattr.h"
9#include <asm/uaccess.h> 9#include <asm/uaccess.h>
10#include <linux/pagemap.h> 10#include <linux/pagemap.h>
11#include <linux/swap.h> 11#include <linux/swap.h>
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index 1e4250bc3a6f..430e0658704c 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -37,7 +37,7 @@
37#include <linux/time.h> 37#include <linux/time.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/string.h> 39#include <linux/string.h>
40#include <linux/reiserfs_fs.h> 40#include "reiserfs.h"
41#include <linux/buffer_head.h> 41#include <linux/buffer_head.h>
42 42
43/* To make any changes in the tree we find a node, that contains item 43/* To make any changes in the tree we find a node, that contains item
diff --git a/fs/reiserfs/hashes.c b/fs/reiserfs/hashes.c
index 6471c670743e..91b0cc1242a2 100644
--- a/fs/reiserfs/hashes.c
+++ b/fs/reiserfs/hashes.c
@@ -19,7 +19,7 @@
19// 19//
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/reiserfs_fs.h> 22#include "reiserfs.h"
23#include <asm/types.h> 23#include <asm/types.h>
24 24
25#define DELTA 0x9E3779B9 25#define DELTA 0x9E3779B9
diff --git a/fs/reiserfs/ibalance.c b/fs/reiserfs/ibalance.c
index 2074fd95046b..e1978fd895f5 100644
--- a/fs/reiserfs/ibalance.c
+++ b/fs/reiserfs/ibalance.c
@@ -5,7 +5,7 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/string.h> 6#include <linux/string.h>
7#include <linux/time.h> 7#include <linux/time.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10 10
11/* this is one and only function that is used outside (do_balance.c) */ 11/* this is one and only function that is used outside (do_balance.c) */
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 9e8cd5acd79c..494c315c7417 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -4,9 +4,9 @@
4 4
5#include <linux/time.h> 5#include <linux/time.h>
6#include <linux/fs.h> 6#include <linux/fs.h>
7#include <linux/reiserfs_fs.h> 7#include "reiserfs.h"
8#include <linux/reiserfs_acl.h> 8#include "acl.h"
9#include <linux/reiserfs_xattr.h> 9#include "xattr.h"
10#include <linux/exportfs.h> 10#include <linux/exportfs.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/highmem.h> 12#include <linux/highmem.h>
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 950e3d1b5c9e..0c2185042d5f 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -5,7 +5,7 @@
5#include <linux/capability.h> 5#include <linux/capability.h>
6#include <linux/fs.h> 6#include <linux/fs.h>
7#include <linux/mount.h> 7#include <linux/mount.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9#include <linux/time.h> 9#include <linux/time.h>
10#include <asm/uaccess.h> 10#include <asm/uaccess.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
index 72cb1cc51b87..ee382ef3d300 100644
--- a/fs/reiserfs/item_ops.c
+++ b/fs/reiserfs/item_ops.c
@@ -3,7 +3,7 @@
3 */ 3 */
4 4
5#include <linux/time.h> 5#include <linux/time.h>
6#include <linux/reiserfs_fs.h> 6#include "reiserfs.h"
7 7
8// this contains item handlers for old item types: sd, direct, 8// this contains item handlers for old item types: sd, direct,
9// indirect, directory 9// indirect, directory
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index c3cf54fd4de3..cf9f4de00a95 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -37,7 +37,7 @@
37#include <linux/time.h> 37#include <linux/time.h>
38#include <linux/semaphore.h> 38#include <linux/semaphore.h>
39#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
40#include <linux/reiserfs_fs.h> 40#include "reiserfs.h"
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/errno.h> 42#include <linux/errno.h>
43#include <linux/fcntl.h> 43#include <linux/fcntl.h>
diff --git a/fs/reiserfs/lbalance.c b/fs/reiserfs/lbalance.c
index b43d01556313..79e5a8b4c226 100644
--- a/fs/reiserfs/lbalance.c
+++ b/fs/reiserfs/lbalance.c
@@ -5,7 +5,7 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/string.h> 6#include <linux/string.h>
7#include <linux/time.h> 7#include <linux/time.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10 10
11/* these are used in do_balance.c */ 11/* these are used in do_balance.c */
diff --git a/fs/reiserfs/lock.c b/fs/reiserfs/lock.c
index 7df1ce48203a..d735bc8470e3 100644
--- a/fs/reiserfs/lock.c
+++ b/fs/reiserfs/lock.c
@@ -1,4 +1,4 @@
1#include <linux/reiserfs_fs.h> 1#include "reiserfs.h"
2#include <linux/mutex.h> 2#include <linux/mutex.h>
3 3
4/* 4/*
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index 146378865239..84e8a69cee9d 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -14,9 +14,9 @@
14#include <linux/time.h> 14#include <linux/time.h>
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/reiserfs_fs.h> 17#include "reiserfs.h"
18#include <linux/reiserfs_acl.h> 18#include "acl.h"
19#include <linux/reiserfs_xattr.h> 19#include "xattr.h"
20#include <linux/quotaops.h> 20#include <linux/quotaops.h>
21 21
22#define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); } 22#define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
diff --git a/fs/reiserfs/objectid.c b/fs/reiserfs/objectid.c
index 3a6de810bd61..f732d6a5251d 100644
--- a/fs/reiserfs/objectid.c
+++ b/fs/reiserfs/objectid.c
@@ -5,8 +5,7 @@
5#include <linux/string.h> 5#include <linux/string.h>
6#include <linux/random.h> 6#include <linux/random.h>
7#include <linux/time.h> 7#include <linux/time.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9#include <linux/reiserfs_fs_sb.h>
10 9
11// find where objectid map starts 10// find where objectid map starts
12#define objectid_map(s,rs) (old_format_only (s) ? \ 11#define objectid_map(s,rs) (old_format_only (s) ? \
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index 45de98b59466..c0b1112ab7e3 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -4,7 +4,7 @@
4 4
5#include <linux/time.h> 5#include <linux/time.h>
6#include <linux/fs.h> 6#include <linux/fs.h>
7#include <linux/reiserfs_fs.h> 7#include "reiserfs.h"
8#include <linux/string.h> 8#include <linux/string.h>
9#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10 10
@@ -329,7 +329,7 @@ void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
329 Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it 329 Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it
330 pointless complexity): 330 pointless complexity):
331 331
332 panics in reiserfs_fs.h have numbers from 1000 to 1999 332 panics in reiserfs.h have numbers from 1000 to 1999
333 super.c 2000 to 2999 333 super.c 2000 to 2999
334 preserve.c (unused) 3000 to 3999 334 preserve.c (unused) 3000 to 3999
335 bitmap.c 4000 to 4999 335 bitmap.c 4000 to 4999
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index 7a9981196c1c..2c1ade692cc8 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -12,8 +12,7 @@
12#include <linux/time.h> 12#include <linux/time.h>
13#include <linux/seq_file.h> 13#include <linux/seq_file.h>
14#include <asm/uaccess.h> 14#include <asm/uaccess.h>
15#include <linux/reiserfs_fs.h> 15#include "reiserfs.h"
16#include <linux/reiserfs_fs_sb.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
19 18
diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
new file mode 100644
index 000000000000..445d768eea44
--- /dev/null
+++ b/fs/reiserfs/reiserfs.h
@@ -0,0 +1,2922 @@
1/*
2 * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
3 */
4
5#include <linux/reiserfs_fs.h>
6
7#include <linux/slab.h>
8#include <linux/interrupt.h>
9#include <linux/sched.h>
10#include <linux/workqueue.h>
11#include <asm/unaligned.h>
12#include <linux/bitops.h>
13#include <linux/proc_fs.h>
14#include <linux/buffer_head.h>
15
16/* the 32 bit compat definitions with int argument */
17#define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int)
18#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
19#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
20#define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION
21#define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION
22
23struct reiserfs_journal_list;
24
25/** bitmasks for i_flags field in reiserfs-specific part of inode */
26typedef enum {
27 /** this says what format of key do all items (but stat data) of
28 an object have. If this is set, that format is 3.6 otherwise
29 - 3.5 */
30 i_item_key_version_mask = 0x0001,
31 /** If this is unset, object has 3.5 stat data, otherwise, it has
32 3.6 stat data with 64bit size, 32bit nlink etc. */
33 i_stat_data_version_mask = 0x0002,
34 /** file might need tail packing on close */
35 i_pack_on_close_mask = 0x0004,
36 /** don't pack tail of file */
37 i_nopack_mask = 0x0008,
38 /** If those is set, "safe link" was created for this file during
39 truncate or unlink. Safe link is used to avoid leakage of disk
40 space on crash with some files open, but unlinked. */
41 i_link_saved_unlink_mask = 0x0010,
42 i_link_saved_truncate_mask = 0x0020,
43 i_has_xattr_dir = 0x0040,
44 i_data_log = 0x0080,
45} reiserfs_inode_flags;
46
47struct reiserfs_inode_info {
48 __u32 i_key[4]; /* key is still 4 32 bit integers */
49 /** transient inode flags that are never stored on disk. Bitmasks
50 for this field are defined above. */
51 __u32 i_flags;
52
53 __u32 i_first_direct_byte; // offset of first byte stored in direct item.
54
55 /* copy of persistent inode flags read from sd_attrs. */
56 __u32 i_attrs;
57
58 int i_prealloc_block; /* first unused block of a sequence of unused blocks */
59 int i_prealloc_count; /* length of that sequence */
60 struct list_head i_prealloc_list; /* per-transaction list of inodes which
61 * have preallocated blocks */
62
63 unsigned new_packing_locality:1; /* new_packig_locality is created; new blocks
64 * for the contents of this directory should be
65 * displaced */
66
67 /* we use these for fsync or O_SYNC to decide which transaction
68 ** needs to be committed in order for this inode to be properly
69 ** flushed */
70 unsigned int i_trans_id;
71 struct reiserfs_journal_list *i_jl;
72 atomic_t openers;
73 struct mutex tailpack;
74#ifdef CONFIG_REISERFS_FS_XATTR
75 struct rw_semaphore i_xattr_sem;
76#endif
77 struct inode vfs_inode;
78};
79
80typedef enum {
81 reiserfs_attrs_cleared = 0x00000001,
82} reiserfs_super_block_flags;
83
84/* struct reiserfs_super_block accessors/mutators
85 * since this is a disk structure, it will always be in
86 * little endian format. */
87#define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count))
88#define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v))
89#define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks))
90#define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v))
91#define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block))
92#define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v))
93
94#define sb_jp_journal_1st_block(sbp) \
95 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block))
96#define set_sb_jp_journal_1st_block(sbp,v) \
97 ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v))
98#define sb_jp_journal_dev(sbp) \
99 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev))
100#define set_sb_jp_journal_dev(sbp,v) \
101 ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v))
102#define sb_jp_journal_size(sbp) \
103 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size))
104#define set_sb_jp_journal_size(sbp,v) \
105 ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v))
106#define sb_jp_journal_trans_max(sbp) \
107 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max))
108#define set_sb_jp_journal_trans_max(sbp,v) \
109 ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v))
110#define sb_jp_journal_magic(sbp) \
111 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic))
112#define set_sb_jp_journal_magic(sbp,v) \
113 ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v))
114#define sb_jp_journal_max_batch(sbp) \
115 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch))
116#define set_sb_jp_journal_max_batch(sbp,v) \
117 ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v))
118#define sb_jp_jourmal_max_commit_age(sbp) \
119 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age))
120#define set_sb_jp_journal_max_commit_age(sbp,v) \
121 ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v))
122
123#define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize))
124#define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v))
125#define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize))
126#define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v))
127#define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize))
128#define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v))
129#define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state))
130#define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v))
131#define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state))
132#define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v))
133#define sb_hash_function_code(sbp) \
134 (le32_to_cpu((sbp)->s_v1.s_hash_function_code))
135#define set_sb_hash_function_code(sbp,v) \
136 ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v))
137#define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height))
138#define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v))
139#define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr))
140#define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v))
141#define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version))
142#define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v))
143
144#define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count))
145#define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v))
146
147#define sb_reserved_for_journal(sbp) \
148 (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal))
149#define set_sb_reserved_for_journal(sbp,v) \
150 ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v))
151
152/* LOGGING -- */
153
154/* These all interelate for performance.
155**
156** If the journal block count is smaller than n transactions, you lose speed.
157** I don't know what n is yet, I'm guessing 8-16.
158**
159** typical transaction size depends on the application, how often fsync is
160** called, and how many metadata blocks you dirty in a 30 second period.
161** The more small files (<16k) you use, the larger your transactions will
162** be.
163**
164** If your journal fills faster than dirty buffers get flushed to disk, it must flush them before allowing the journal
165** to wrap, which slows things down. If you need high speed meta data updates, the journal should be big enough
166** to prevent wrapping before dirty meta blocks get to disk.
167**
168** If the batch max is smaller than the transaction max, you'll waste space at the end of the journal
169** because journal_end sets the next transaction to start at 0 if the next transaction has any chance of wrapping.
170**
171** The large the batch max age, the better the speed, and the more meta data changes you'll lose after a crash.
172**
173*/
174
175/* don't mess with these for a while */
176 /* we have a node size define somewhere in reiserfs_fs.h. -Hans */
177#define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */
178#define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */
179#define JOURNAL_HASH_SIZE 8192
180#define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */
181
182/* One of these for every block in every transaction
183** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a
184** hash of all the in memory transactions.
185** next and prev are used by the current transaction (journal_hash).
186** hnext and hprev are used by journal_list_hash. If a block is in more than one transaction, the journal_list_hash
187** links it in multiple times. This allows flush_journal_list to remove just the cnode belonging
188** to a given transaction.
189*/
190struct reiserfs_journal_cnode {
191 struct buffer_head *bh; /* real buffer head */
192 struct super_block *sb; /* dev of real buffer head */
193 __u32 blocknr; /* block number of real buffer head, == 0 when buffer on disk */
194 unsigned long state;
195 struct reiserfs_journal_list *jlist; /* journal list this cnode lives in */
196 struct reiserfs_journal_cnode *next; /* next in transaction list */
197 struct reiserfs_journal_cnode *prev; /* prev in transaction list */
198 struct reiserfs_journal_cnode *hprev; /* prev in hash list */
199 struct reiserfs_journal_cnode *hnext; /* next in hash list */
200};
201
202struct reiserfs_bitmap_node {
203 int id;
204 char *data;
205 struct list_head list;
206};
207
208struct reiserfs_list_bitmap {
209 struct reiserfs_journal_list *journal_list;
210 struct reiserfs_bitmap_node **bitmaps;
211};
212
213/*
214** one of these for each transaction. The most important part here is the j_realblock.
215** this list of cnodes is used to hash all the blocks in all the commits, to mark all the
216** real buffer heads dirty once all the commits hit the disk,
217** and to make sure every real block in a transaction is on disk before allowing the log area
218** to be overwritten */
219struct reiserfs_journal_list {
220 unsigned long j_start;
221 unsigned long j_state;
222 unsigned long j_len;
223 atomic_t j_nonzerolen;
224 atomic_t j_commit_left;
225 atomic_t j_older_commits_done; /* all commits older than this on disk */
226 struct mutex j_commit_mutex;
227 unsigned int j_trans_id;
228 time_t j_timestamp;
229 struct reiserfs_list_bitmap *j_list_bitmap;
230 struct buffer_head *j_commit_bh; /* commit buffer head */
231 struct reiserfs_journal_cnode *j_realblock;
232 struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */
233 /* time ordered list of all active transactions */
234 struct list_head j_list;
235
236 /* time ordered list of all transactions we haven't tried to flush yet */
237 struct list_head j_working_list;
238
239 /* list of tail conversion targets in need of flush before commit */
240 struct list_head j_tail_bh_list;
241 /* list of data=ordered buffers in need of flush before commit */
242 struct list_head j_bh_list;
243 int j_refcount;
244};
245
246struct reiserfs_journal {
247 struct buffer_head **j_ap_blocks; /* journal blocks on disk */
248 struct reiserfs_journal_cnode *j_last; /* newest journal block */
249 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */
250
251 struct block_device *j_dev_bd;
252 fmode_t j_dev_mode;
253 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */
254
255 unsigned long j_state;
256 unsigned int j_trans_id;
257 unsigned long j_mount_id;
258 unsigned long j_start; /* start of current waiting commit (index into j_ap_blocks) */
259 unsigned long j_len; /* length of current waiting commit */
260 unsigned long j_len_alloc; /* number of buffers requested by journal_begin() */
261 atomic_t j_wcount; /* count of writers for current commit */
262 unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */
263 unsigned long j_first_unflushed_offset; /* first unflushed transactions offset */
264 unsigned j_last_flush_trans_id; /* last fully flushed journal timestamp */
265 struct buffer_head *j_header_bh;
266
267 time_t j_trans_start_time; /* time this transaction started */
268 struct mutex j_mutex;
269 struct mutex j_flush_mutex;
270 wait_queue_head_t j_join_wait; /* wait for current transaction to finish before starting new one */
271 atomic_t j_jlock; /* lock for j_join_wait */
272 int j_list_bitmap_index; /* number of next list bitmap to use */
273 int j_must_wait; /* no more journal begins allowed. MUST sleep on j_join_wait */
274 int j_next_full_flush; /* next journal_end will flush all journal list */
275 int j_next_async_flush; /* next journal_end will flush all async commits */
276
277 int j_cnode_used; /* number of cnodes on the used list */
278 int j_cnode_free; /* number of cnodes on the free list */
279
280 unsigned int j_trans_max; /* max number of blocks in a transaction. */
281 unsigned int j_max_batch; /* max number of blocks to batch into a trans */
282 unsigned int j_max_commit_age; /* in seconds, how old can an async commit be */
283 unsigned int j_max_trans_age; /* in seconds, how old can a transaction be */
284 unsigned int j_default_max_commit_age; /* the default for the max commit age */
285
286 struct reiserfs_journal_cnode *j_cnode_free_list;
287 struct reiserfs_journal_cnode *j_cnode_free_orig; /* orig pointer returned from vmalloc */
288
289 struct reiserfs_journal_list *j_current_jl;
290 int j_free_bitmap_nodes;
291 int j_used_bitmap_nodes;
292
293 int j_num_lists; /* total number of active transactions */
294 int j_num_work_lists; /* number that need attention from kreiserfsd */
295
296 /* debugging to make sure things are flushed in order */
297 unsigned int j_last_flush_id;
298
299 /* debugging to make sure things are committed in order */
300 unsigned int j_last_commit_id;
301
302 struct list_head j_bitmap_nodes;
303 struct list_head j_dirty_buffers;
304 spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */
305
306 /* list of all active transactions */
307 struct list_head j_journal_list;
308 /* lists that haven't been touched by writeback attempts */
309 struct list_head j_working_list;
310
311 struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; /* array of bitmaps to record the deleted blocks */
312 struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; /* hash table for real buffer heads in current trans */
313 struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; /* hash table for all the real buffer heads in all
314 the transactions */
315 struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */
316 int j_persistent_trans;
317 unsigned long j_max_trans_size;
318 unsigned long j_max_batch_size;
319
320 int j_errno;
321
322 /* when flushing ordered buffers, throttle new ordered writers */
323 struct delayed_work j_work;
324 struct super_block *j_work_sb;
325 atomic_t j_async_throttle;
326};
327
328enum journal_state_bits {
329 J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */
330 J_WRITERS_QUEUED, /* set when log is full due to too many writers */
331 J_ABORTED, /* set when log is aborted */
332};
333
334#define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */
335
336typedef __u32(*hashf_t) (const signed char *, int);
337
338struct reiserfs_bitmap_info {
339 __u32 free_count;
340};
341
342struct proc_dir_entry;
343
344#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO )
345typedef unsigned long int stat_cnt_t;
346typedef struct reiserfs_proc_info_data {
347 spinlock_t lock;
348 int exiting;
349 int max_hash_collisions;
350
351 stat_cnt_t breads;
352 stat_cnt_t bread_miss;
353 stat_cnt_t search_by_key;
354 stat_cnt_t search_by_key_fs_changed;
355 stat_cnt_t search_by_key_restarted;
356
357 stat_cnt_t insert_item_restarted;
358 stat_cnt_t paste_into_item_restarted;
359 stat_cnt_t cut_from_item_restarted;
360 stat_cnt_t delete_solid_item_restarted;
361 stat_cnt_t delete_item_restarted;
362
363 stat_cnt_t leaked_oid;
364 stat_cnt_t leaves_removable;
365
366 /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */
367 stat_cnt_t balance_at[5]; /* XXX */
368 /* sbk == search_by_key */
369 stat_cnt_t sbk_read_at[5]; /* XXX */
370 stat_cnt_t sbk_fs_changed[5];
371 stat_cnt_t sbk_restarted[5];
372 stat_cnt_t items_at[5]; /* XXX */
373 stat_cnt_t free_at[5]; /* XXX */
374 stat_cnt_t can_node_be_removed[5]; /* XXX */
375 long int lnum[5]; /* XXX */
376 long int rnum[5]; /* XXX */
377 long int lbytes[5]; /* XXX */
378 long int rbytes[5]; /* XXX */
379 stat_cnt_t get_neighbors[5];
380 stat_cnt_t get_neighbors_restart[5];
381 stat_cnt_t need_l_neighbor[5];
382 stat_cnt_t need_r_neighbor[5];
383
384 stat_cnt_t free_block;
385 struct __scan_bitmap_stats {
386 stat_cnt_t call;
387 stat_cnt_t wait;
388 stat_cnt_t bmap;
389 stat_cnt_t retry;
390 stat_cnt_t in_journal_hint;
391 stat_cnt_t in_journal_nohint;
392 stat_cnt_t stolen;
393 } scan_bitmap;
394 struct __journal_stats {
395 stat_cnt_t in_journal;
396 stat_cnt_t in_journal_bitmap;
397 stat_cnt_t in_journal_reusable;
398 stat_cnt_t lock_journal;
399 stat_cnt_t lock_journal_wait;
400 stat_cnt_t journal_being;
401 stat_cnt_t journal_relock_writers;
402 stat_cnt_t journal_relock_wcount;
403 stat_cnt_t mark_dirty;
404 stat_cnt_t mark_dirty_already;
405 stat_cnt_t mark_dirty_notjournal;
406 stat_cnt_t restore_prepared;
407 stat_cnt_t prepare;
408 stat_cnt_t prepare_retry;
409 } journal;
410} reiserfs_proc_info_data_t;
411#else
412typedef struct reiserfs_proc_info_data {
413} reiserfs_proc_info_data_t;
414#endif
415
416/* reiserfs union of in-core super block data */
417struct reiserfs_sb_info {
418 struct buffer_head *s_sbh; /* Buffer containing the super block */
419 /* both the comment and the choice of
420 name are unclear for s_rs -Hans */
421 struct reiserfs_super_block *s_rs; /* Pointer to the super block in the buffer */
422 struct reiserfs_bitmap_info *s_ap_bitmap;
423 struct reiserfs_journal *s_journal; /* pointer to journal information */
424 unsigned short s_mount_state; /* reiserfs state (valid, invalid) */
425
426 /* Serialize writers access, replace the old bkl */
427 struct mutex lock;
428 /* Owner of the lock (can be recursive) */
429 struct task_struct *lock_owner;
430 /* Depth of the lock, start from -1 like the bkl */
431 int lock_depth;
432
433 /* Comment? -Hans */
434 void (*end_io_handler) (struct buffer_head *, int);
435 hashf_t s_hash_function; /* pointer to function which is used
436 to sort names in directory. Set on
437 mount */
438 unsigned long s_mount_opt; /* reiserfs's mount options are set
439 here (currently - NOTAIL, NOLOG,
440 REPLAYONLY) */
441
442 struct { /* This is a structure that describes block allocator options */
443 unsigned long bits; /* Bitfield for enable/disable kind of options */
444 unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */
445 int border; /* percentage of disk, border takes */
446 int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */
447 int preallocsize; /* Number of blocks we try to prealloc when file
448 reaches preallocmin size (in blocks) or
449 prealloc_list is empty. */
450 } s_alloc_options;
451
452 /* Comment? -Hans */
453 wait_queue_head_t s_wait;
454 /* To be obsoleted soon by per buffer seals.. -Hans */
455 atomic_t s_generation_counter; // increased by one every time the
456 // tree gets re-balanced
457 unsigned long s_properties; /* File system properties. Currently holds
458 on-disk FS format */
459
460 /* session statistics */
461 int s_disk_reads;
462 int s_disk_writes;
463 int s_fix_nodes;
464 int s_do_balance;
465 int s_unneeded_left_neighbor;
466 int s_good_search_by_key_reada;
467 int s_bmaps;
468 int s_bmaps_without_search;
469 int s_direct2indirect;
470 int s_indirect2direct;
471 /* set up when it's ok for reiserfs_read_inode2() to read from
472 disk inode with nlink==0. Currently this is only used during
473 finish_unfinished() processing at mount time */
474 int s_is_unlinked_ok;
475 reiserfs_proc_info_data_t s_proc_info_data;
476 struct proc_dir_entry *procdir;
477 int reserved_blocks; /* amount of blocks reserved for further allocations */
478 spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */
479 struct dentry *priv_root; /* root of /.reiserfs_priv */
480 struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */
481 int j_errno;
482#ifdef CONFIG_QUOTA
483 char *s_qf_names[MAXQUOTAS];
484 int s_jquota_fmt;
485#endif
486 char *s_jdev; /* Stored jdev for mount option showing */
487#ifdef CONFIG_REISERFS_CHECK
488
489 struct tree_balance *cur_tb; /*
490 * Detects whether more than one
491 * copy of tb exists per superblock
492 * as a means of checking whether
493 * do_balance is executing concurrently
494 * against another tree reader/writer
495 * on a same mount point.
496 */
497#endif
498};
499
500/* Definitions of reiserfs on-disk properties: */
501#define REISERFS_3_5 0
502#define REISERFS_3_6 1
503#define REISERFS_OLD_FORMAT 2
504
505enum reiserfs_mount_options {
506/* Mount options */
507 REISERFS_LARGETAIL, /* large tails will be created in a session */
508 REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */
509 REPLAYONLY, /* replay journal and return 0. Use by fsck */
510 REISERFS_CONVERT, /* -o conv: causes conversion of old
511 format super block to the new
512 format. If not specified - old
513 partition will be dealt with in a
514 manner of 3.5.x */
515
516/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting
517** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option
518** is not required. If the normal autodection code can't determine which
519** hash to use (because both hashes had the same value for a file)
520** use this option to force a specific hash. It won't allow you to override
521** the existing hash on the FS, so if you have a tea hash disk, and mount
522** with -o hash=rupasov, the mount will fail.
523*/
524 FORCE_TEA_HASH, /* try to force tea hash on mount */
525 FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */
526 FORCE_R5_HASH, /* try to force rupasov hash on mount */
527 FORCE_HASH_DETECT, /* try to detect hash function on mount */
528
529 REISERFS_DATA_LOG,
530 REISERFS_DATA_ORDERED,
531 REISERFS_DATA_WRITEBACK,
532
533/* used for testing experimental features, makes benchmarking new
534 features with and without more convenient, should never be used by
535 users in any code shipped to users (ideally) */
536
537 REISERFS_NO_BORDER,
538 REISERFS_NO_UNHASHED_RELOCATION,
539 REISERFS_HASHED_RELOCATION,
540 REISERFS_ATTRS,
541 REISERFS_XATTRS_USER,
542 REISERFS_POSIXACL,
543 REISERFS_EXPOSE_PRIVROOT,
544 REISERFS_BARRIER_NONE,
545 REISERFS_BARRIER_FLUSH,
546
547 /* Actions on error */
548 REISERFS_ERROR_PANIC,
549 REISERFS_ERROR_RO,
550 REISERFS_ERROR_CONTINUE,
551
552 REISERFS_USRQUOTA, /* User quota option specified */
553 REISERFS_GRPQUOTA, /* Group quota option specified */
554
555 REISERFS_TEST1,
556 REISERFS_TEST2,
557 REISERFS_TEST3,
558 REISERFS_TEST4,
559 REISERFS_UNSUPPORTED_OPT,
560};
561
562#define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH))
563#define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH))
564#define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH))
565#define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT))
566#define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER))
567#define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION))
568#define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION))
569#define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4))
570
571#define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL))
572#define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL))
573#define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY))
574#define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS))
575#define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5))
576#define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT))
577#define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
578#define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
579#define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
580#define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
581#define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
582#define reiserfs_expose_privroot(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_EXPOSE_PRIVROOT))
583#define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
584#define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE))
585#define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH))
586
587#define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC))
588#define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO))
589
590void reiserfs_file_buffer(struct buffer_head *bh, int list);
591extern struct file_system_type reiserfs_fs_type;
592int reiserfs_resize(struct super_block *, unsigned long);
593
594#define CARRY_ON 0
595#define SCHEDULE_OCCURRED 1
596
597#define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh)
598#define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal)
599#define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block)
600#define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free)
601#define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap)
602
603#define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->)
604
605/* A safe version of the "bdevname", which returns the "s_id" field of
606 * a superblock or else "Null superblock" if the super block is NULL.
607 */
608static inline char *reiserfs_bdevname(struct super_block *s)
609{
610 return (s == NULL) ? "Null superblock" : s->s_id;
611}
612
613#define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal)))
614static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal
615 *journal)
616{
617 return test_bit(J_ABORTED, &journal->j_state);
618}
619
620/*
621 * Locking primitives. The write lock is a per superblock
622 * special mutex that has properties close to the Big Kernel Lock
623 * which was used in the previous locking scheme.
624 */
625void reiserfs_write_lock(struct super_block *s);
626void reiserfs_write_unlock(struct super_block *s);
627int reiserfs_write_lock_once(struct super_block *s);
628void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
629
630#ifdef CONFIG_REISERFS_CHECK
631void reiserfs_lock_check_recursive(struct super_block *s);
632#else
633static inline void reiserfs_lock_check_recursive(struct super_block *s) { }
634#endif
635
636/*
637 * Several mutexes depend on the write lock.
638 * However sometimes we want to relax the write lock while we hold
639 * these mutexes, according to the release/reacquire on schedule()
640 * properties of the Bkl that were used.
641 * Reiserfs performances and locking were based on this scheme.
642 * Now that the write lock is a mutex and not the bkl anymore, doing so
643 * may result in a deadlock:
644 *
645 * A acquire write_lock
646 * A acquire j_commit_mutex
647 * A release write_lock and wait for something
648 * B acquire write_lock
649 * B can't acquire j_commit_mutex and sleep
650 * A can't acquire write lock anymore
651 * deadlock
652 *
653 * What we do here is avoiding such deadlock by playing the same game
654 * than the Bkl: if we can't acquire a mutex that depends on the write lock,
655 * we release the write lock, wait a bit and then retry.
656 *
657 * The mutexes concerned by this hack are:
658 * - The commit mutex of a journal list
659 * - The flush mutex
660 * - The journal lock
661 * - The inode mutex
662 */
663static inline void reiserfs_mutex_lock_safe(struct mutex *m,
664 struct super_block *s)
665{
666 reiserfs_lock_check_recursive(s);
667 reiserfs_write_unlock(s);
668 mutex_lock(m);
669 reiserfs_write_lock(s);
670}
671
672static inline void
673reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
674 struct super_block *s)
675{
676 reiserfs_lock_check_recursive(s);
677 reiserfs_write_unlock(s);
678 mutex_lock_nested(m, subclass);
679 reiserfs_write_lock(s);
680}
681
682static inline void
683reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)
684{
685 reiserfs_lock_check_recursive(s);
686 reiserfs_write_unlock(s);
687 down_read(sem);
688 reiserfs_write_lock(s);
689}
690
691/*
692 * When we schedule, we usually want to also release the write lock,
693 * according to the previous bkl based locking scheme of reiserfs.
694 */
695static inline void reiserfs_cond_resched(struct super_block *s)
696{
697 if (need_resched()) {
698 reiserfs_write_unlock(s);
699 schedule();
700 reiserfs_write_lock(s);
701 }
702}
703
704struct fid;
705
706/* in reading the #defines, it may help to understand that they employ
707 the following abbreviations:
708
709 B = Buffer
710 I = Item header
711 H = Height within the tree (should be changed to LEV)
712 N = Number of the item in the node
713 STAT = stat data
714 DEH = Directory Entry Header
715 EC = Entry Count
716 E = Entry number
717 UL = Unsigned Long
718 BLKH = BLocK Header
719 UNFM = UNForMatted node
720 DC = Disk Child
721 P = Path
722
723 These #defines are named by concatenating these abbreviations,
724 where first comes the arguments, and last comes the return value,
725 of the macro.
726
727*/
728
729#define USE_INODE_GENERATION_COUNTER
730
731#define REISERFS_PREALLOCATE
732#define DISPLACE_NEW_PACKING_LOCALITIES
733#define PREALLOCATION_SIZE 9
734
735/* n must be power of 2 */
736#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u))
737
738// to be ok for alpha and others we have to align structures to 8 byte
739// boundary.
740// FIXME: do not change 4 by anything else: there is code which relies on that
741#define ROUND_UP(x) _ROUND_UP(x,8LL)
742
743/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug
744** messages.
745*/
746#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */
747
748void __reiserfs_warning(struct super_block *s, const char *id,
749 const char *func, const char *fmt, ...);
750#define reiserfs_warning(s, id, fmt, args...) \
751 __reiserfs_warning(s, id, __func__, fmt, ##args)
752/* assertions handling */
753
754/** always check a condition and panic if it's false. */
755#define __RASSERT(cond, scond, format, args...) \
756do { \
757 if (!(cond)) \
758 reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \
759 __FILE__ ":%i:%s: " format "\n", \
760 in_interrupt() ? -1 : task_pid_nr(current), \
761 __LINE__, __func__ , ##args); \
762} while (0)
763
764#define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args)
765
766#if defined( CONFIG_REISERFS_CHECK )
767#define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args)
768#else
769#define RFALSE( cond, format, args... ) do {;} while( 0 )
770#endif
771
772#define CONSTF __attribute_const__
773/*
774 * Disk Data Structures
775 */
776
777/***************************************************************************/
778/* SUPER BLOCK */
779/***************************************************************************/
780
781/*
782 * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs
783 * the version in RAM is part of a larger structure containing fields never written to disk.
784 */
785#define UNSET_HASH 0 // read_super will guess about, what hash names
786 // in directories were sorted with
787#define TEA_HASH 1
788#define YURA_HASH 2
789#define R5_HASH 3
790#define DEFAULT_HASH R5_HASH
791
792struct journal_params {
793 __le32 jp_journal_1st_block; /* where does journal start from on its
794 * device */
795 __le32 jp_journal_dev; /* journal device st_rdev */
796 __le32 jp_journal_size; /* size of the journal */
797 __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */
798 __le32 jp_journal_magic; /* random value made on fs creation (this
799 * was sb_journal_block_count) */
800 __le32 jp_journal_max_batch; /* max number of blocks to batch into a
801 * trans */
802 __le32 jp_journal_max_commit_age; /* in seconds, how old can an async
803 * commit be */
804 __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction
805 * be */
806};
807
808/* this is the super from 3.5.X, where X >= 10 */
809struct reiserfs_super_block_v1 {
810 __le32 s_block_count; /* blocks count */
811 __le32 s_free_blocks; /* free blocks count */
812 __le32 s_root_block; /* root block number */
813 struct journal_params s_journal;
814 __le16 s_blocksize; /* block size */
815 __le16 s_oid_maxsize; /* max size of object id array, see
816 * get_objectid() commentary */
817 __le16 s_oid_cursize; /* current size of object id array */
818 __le16 s_umount_state; /* this is set to 1 when filesystem was
819 * umounted, to 2 - when not */
820 char s_magic[10]; /* reiserfs magic string indicates that
821 * file system is reiserfs:
822 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
823 __le16 s_fs_state; /* it is set to used by fsck to mark which
824 * phase of rebuilding is done */
825 __le32 s_hash_function_code; /* indicate, what hash function is being use
826 * to sort names in a directory*/
827 __le16 s_tree_height; /* height of disk tree */
828 __le16 s_bmap_nr; /* amount of bitmap blocks needed to address
829 * each block of file system */
830 __le16 s_version; /* this field is only reliable on filesystem
831 * with non-standard journal */
832 __le16 s_reserved_for_journal; /* size in blocks of journal area on main
833 * device, we need to keep after
834 * making fs with non-standard journal */
835} __attribute__ ((__packed__));
836
837#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
838
839/* this is the on disk super block */
840struct reiserfs_super_block {
841 struct reiserfs_super_block_v1 s_v1;
842 __le32 s_inode_generation;
843 __le32 s_flags; /* Right now used only by inode-attributes, if enabled */
844 unsigned char s_uuid[16]; /* filesystem unique identifier */
845 unsigned char s_label[16]; /* filesystem volume label */
846 __le16 s_mnt_count; /* Count of mounts since last fsck */
847 __le16 s_max_mnt_count; /* Maximum mounts before check */
848 __le32 s_lastcheck; /* Timestamp of last fsck */
849 __le32 s_check_interval; /* Interval between checks */
850 char s_unused[76]; /* zero filled by mkreiserfs and
851 * reiserfs_convert_objectid_map_v1()
852 * so any additions must be updated
853 * there as well. */
854} __attribute__ ((__packed__));
855
856#define SB_SIZE (sizeof(struct reiserfs_super_block))
857
858#define REISERFS_VERSION_1 0
859#define REISERFS_VERSION_2 2
860
861// on-disk super block fields converted to cpu form
862#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)
863#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))
864#define SB_BLOCKSIZE(s) \
865 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize))
866#define SB_BLOCK_COUNT(s) \
867 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count))
868#define SB_FREE_BLOCKS(s) \
869 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks))
870#define SB_REISERFS_MAGIC(s) \
871 (SB_V1_DISK_SUPER_BLOCK(s)->s_magic)
872#define SB_ROOT_BLOCK(s) \
873 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block))
874#define SB_TREE_HEIGHT(s) \
875 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height))
876#define SB_REISERFS_STATE(s) \
877 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state))
878#define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version))
879#define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr))
880
881#define PUT_SB_BLOCK_COUNT(s, val) \
882 do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)
883#define PUT_SB_FREE_BLOCKS(s, val) \
884 do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)
885#define PUT_SB_ROOT_BLOCK(s, val) \
886 do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)
887#define PUT_SB_TREE_HEIGHT(s, val) \
888 do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)
889#define PUT_SB_REISERFS_STATE(s, val) \
890 do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)
891#define PUT_SB_VERSION(s, val) \
892 do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)
893#define PUT_SB_BMAP_NR(s, val) \
894 do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)
895
896#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)
897#define SB_ONDISK_JOURNAL_SIZE(s) \
898 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))
899#define SB_ONDISK_JOURNAL_1st_BLOCK(s) \
900 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block))
901#define SB_ONDISK_JOURNAL_DEVICE(s) \
902 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev))
903#define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \
904 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal))
905
906#define is_block_in_log_or_reserved_area(s, block) \
907 block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \
908 && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \
909 ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
910 SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
911
912int is_reiserfs_3_5(struct reiserfs_super_block *rs);
913int is_reiserfs_3_6(struct reiserfs_super_block *rs);
914int is_reiserfs_jr(struct reiserfs_super_block *rs);
915
916/* ReiserFS leaves the first 64k unused, so that partition labels have
917 enough space. If someone wants to write a fancy bootloader that
918 needs more than 64k, let us know, and this will be increased in size.
919 This number must be larger than than the largest block size on any
920 platform, or code will break. -Hans */
921#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
922#define REISERFS_FIRST_BLOCK unused_define
923#define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES
924
925/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
926#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
927
928/* reiserfs internal error code (used by search_by_key and fix_nodes)) */
929#define CARRY_ON 0
930#define REPEAT_SEARCH -1
931#define IO_ERROR -2
932#define NO_DISK_SPACE -3
933#define NO_BALANCING_NEEDED (-4)
934#define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5)
935#define QUOTA_EXCEEDED -6
936
937typedef __u32 b_blocknr_t;
938typedef __le32 unp_t;
939
940struct unfm_nodeinfo {
941 unp_t unfm_nodenum;
942 unsigned short unfm_freespace;
943};
944
945/* there are two formats of keys: 3.5 and 3.6
946 */
947#define KEY_FORMAT_3_5 0
948#define KEY_FORMAT_3_6 1
949
950/* there are two stat datas */
951#define STAT_DATA_V1 0
952#define STAT_DATA_V2 1
953
954static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)
955{
956 return container_of(inode, struct reiserfs_inode_info, vfs_inode);
957}
958
959static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
960{
961 return sb->s_fs_info;
962}
963
964/* Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16
965 * which overflows on large file systems. */
966static inline __u32 reiserfs_bmap_count(struct super_block *sb)
967{
968 return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;
969}
970
971static inline int bmap_would_wrap(unsigned bmap_nr)
972{
973 return bmap_nr > ((1LL << 16) - 1);
974}
975
976/** this says about version of key of all items (but stat data) the
977 object consists of */
978#define get_inode_item_key_version( inode ) \
979 ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5)
980
981#define set_inode_item_key_version( inode, version ) \
982 ({ if((version)==KEY_FORMAT_3_6) \
983 REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \
984 else \
985 REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; })
986
987#define get_inode_sd_version(inode) \
988 ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1)
989
990#define set_inode_sd_version(inode, version) \
991 ({ if((version)==STAT_DATA_V2) \
992 REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \
993 else \
994 REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; })
995
996/* This is an aggressive tail suppression policy, I am hoping it
997 improves our benchmarks. The principle behind it is that percentage
998 space saving is what matters, not absolute space saving. This is
999 non-intuitive, but it helps to understand it if you consider that the
1000 cost to access 4 blocks is not much more than the cost to access 1
1001 block, if you have to do a seek and rotate. A tail risks a
1002 non-linear disk access that is significant as a percentage of total
1003 time cost for a 4 block file and saves an amount of space that is
1004 less significant as a percentage of space, or so goes the hypothesis.
1005 -Hans */
1006#define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \
1007(\
1008 (!(n_tail_size)) || \
1009 (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \
1010 ( (n_file_size) >= (n_block_size) * 4 ) || \
1011 ( ( (n_file_size) >= (n_block_size) * 3 ) && \
1012 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \
1013 ( ( (n_file_size) >= (n_block_size) * 2 ) && \
1014 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \
1015 ( ( (n_file_size) >= (n_block_size) ) && \
1016 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \
1017)
1018
1019/* Another strategy for tails, this one means only create a tail if all the
1020 file would fit into one DIRECT item.
1021 Primary intention for this one is to increase performance by decreasing
1022 seeking.
1023*/
1024#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \
1025(\
1026 (!(n_tail_size)) || \
1027 (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \
1028)
1029
1030/*
1031 * values for s_umount_state field
1032 */
1033#define REISERFS_VALID_FS 1
1034#define REISERFS_ERROR_FS 2
1035
1036//
1037// there are 5 item types currently
1038//
1039#define TYPE_STAT_DATA 0
1040#define TYPE_INDIRECT 1
1041#define TYPE_DIRECT 2
1042#define TYPE_DIRENTRY 3
1043#define TYPE_MAXTYPE 3
1044#define TYPE_ANY 15 // FIXME: comment is required
1045
1046/***************************************************************************/
1047/* KEY & ITEM HEAD */
1048/***************************************************************************/
1049
1050//
1051// directories use this key as well as old files
1052//
1053struct offset_v1 {
1054 __le32 k_offset;
1055 __le32 k_uniqueness;
1056} __attribute__ ((__packed__));
1057
1058struct offset_v2 {
1059 __le64 v;
1060} __attribute__ ((__packed__));
1061
1062static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)
1063{
1064 __u8 type = le64_to_cpu(v2->v) >> 60;
1065 return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;
1066}
1067
1068static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)
1069{
1070 v2->v =
1071 (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);
1072}
1073
1074static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)
1075{
1076 return le64_to_cpu(v2->v) & (~0ULL >> 4);
1077}
1078
1079static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)
1080{
1081 offset &= (~0ULL >> 4);
1082 v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);
1083}
1084
1085/* Key of an item determines its location in the S+tree, and
1086 is composed of 4 components */
1087struct reiserfs_key {
1088 __le32 k_dir_id; /* packing locality: by default parent
1089 directory object id */
1090 __le32 k_objectid; /* object identifier */
1091 union {
1092 struct offset_v1 k_offset_v1;
1093 struct offset_v2 k_offset_v2;
1094 } __attribute__ ((__packed__)) u;
1095} __attribute__ ((__packed__));
1096
1097struct in_core_key {
1098 __u32 k_dir_id; /* packing locality: by default parent
1099 directory object id */
1100 __u32 k_objectid; /* object identifier */
1101 __u64 k_offset;
1102 __u8 k_type;
1103};
1104
1105struct cpu_key {
1106 struct in_core_key on_disk_key;
1107 int version;
1108 int key_length; /* 3 in all cases but direct2indirect and
1109 indirect2direct conversion */
1110};
1111
1112/* Our function for comparing keys can compare keys of different
1113 lengths. It takes as a parameter the length of the keys it is to
1114 compare. These defines are used in determining what is to be passed
1115 to it as that parameter. */
1116#define REISERFS_FULL_KEY_LEN 4
1117#define REISERFS_SHORT_KEY_LEN 2
1118
1119/* The result of the key compare */
1120#define FIRST_GREATER 1
1121#define SECOND_GREATER -1
1122#define KEYS_IDENTICAL 0
1123#define KEY_FOUND 1
1124#define KEY_NOT_FOUND 0
1125
1126#define KEY_SIZE (sizeof(struct reiserfs_key))
1127#define SHORT_KEY_SIZE (sizeof (__u32) + sizeof (__u32))
1128
1129/* return values for search_by_key and clones */
1130#define ITEM_FOUND 1
1131#define ITEM_NOT_FOUND 0
1132#define ENTRY_FOUND 1
1133#define ENTRY_NOT_FOUND 0
1134#define DIRECTORY_NOT_FOUND -1
1135#define REGULAR_FILE_FOUND -2
1136#define DIRECTORY_FOUND -3
1137#define BYTE_FOUND 1
1138#define BYTE_NOT_FOUND 0
1139#define FILE_NOT_FOUND -1
1140
1141#define POSITION_FOUND 1
1142#define POSITION_NOT_FOUND 0
1143
1144// return values for reiserfs_find_entry and search_by_entry_key
1145#define NAME_FOUND 1
1146#define NAME_NOT_FOUND 0
1147#define GOTO_PREVIOUS_ITEM 2
1148#define NAME_FOUND_INVISIBLE 3
1149
1150/* Everything in the filesystem is stored as a set of items. The
1151 item head contains the key of the item, its free space (for
1152 indirect items) and specifies the location of the item itself
1153 within the block. */
1154
1155struct item_head {
1156 /* Everything in the tree is found by searching for it based on
1157 * its key.*/
1158 struct reiserfs_key ih_key;
1159 union {
1160 /* The free space in the last unformatted node of an
1161 indirect item if this is an indirect item. This
1162 equals 0xFFFF iff this is a direct item or stat data
1163 item. Note that the key, not this field, is used to
1164 determine the item type, and thus which field this
1165 union contains. */
1166 __le16 ih_free_space_reserved;
1167 /* Iff this is a directory item, this field equals the
1168 number of directory entries in the directory item. */
1169 __le16 ih_entry_count;
1170 } __attribute__ ((__packed__)) u;
1171 __le16 ih_item_len; /* total size of the item body */
1172 __le16 ih_item_location; /* an offset to the item body
1173 * within the block */
1174 __le16 ih_version; /* 0 for all old items, 2 for new
1175 ones. Highest bit is set by fsck
1176 temporary, cleaned after all
1177 done */
1178} __attribute__ ((__packed__));
1179/* size of item header */
1180#define IH_SIZE (sizeof(struct item_head))
1181
1182#define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved)
1183#define ih_version(ih) le16_to_cpu((ih)->ih_version)
1184#define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count)
1185#define ih_location(ih) le16_to_cpu((ih)->ih_item_location)
1186#define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len)
1187
1188#define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0)
1189#define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0)
1190#define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0)
1191#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)
1192#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)
1193
1194#define unreachable_item(ih) (ih_version(ih) & (1 << 15))
1195
1196#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))
1197#define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val)))
1198
1199/* these operate on indirect items, where you've got an array of ints
1200** at a possibly unaligned location. These are a noop on ia32
1201**
1202** p is the array of __u32, i is the index into the array, v is the value
1203** to store there.
1204*/
1205#define get_block_num(p, i) get_unaligned_le32((p) + (i))
1206#define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i))
1207
1208//
1209// in old version uniqueness field shows key type
1210//
1211#define V1_SD_UNIQUENESS 0
1212#define V1_INDIRECT_UNIQUENESS 0xfffffffe
1213#define V1_DIRECT_UNIQUENESS 0xffffffff
1214#define V1_DIRENTRY_UNIQUENESS 500
1215#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required
1216
1217//
1218// here are conversion routines
1219//
1220static inline int uniqueness2type(__u32 uniqueness) CONSTF;
1221static inline int uniqueness2type(__u32 uniqueness)
1222{
1223 switch ((int)uniqueness) {
1224 case V1_SD_UNIQUENESS:
1225 return TYPE_STAT_DATA;
1226 case V1_INDIRECT_UNIQUENESS:
1227 return TYPE_INDIRECT;
1228 case V1_DIRECT_UNIQUENESS:
1229 return TYPE_DIRECT;
1230 case V1_DIRENTRY_UNIQUENESS:
1231 return TYPE_DIRENTRY;
1232 case V1_ANY_UNIQUENESS:
1233 default:
1234 return TYPE_ANY;
1235 }
1236}
1237
1238static inline __u32 type2uniqueness(int type) CONSTF;
1239static inline __u32 type2uniqueness(int type)
1240{
1241 switch (type) {
1242 case TYPE_STAT_DATA:
1243 return V1_SD_UNIQUENESS;
1244 case TYPE_INDIRECT:
1245 return V1_INDIRECT_UNIQUENESS;
1246 case TYPE_DIRECT:
1247 return V1_DIRECT_UNIQUENESS;
1248 case TYPE_DIRENTRY:
1249 return V1_DIRENTRY_UNIQUENESS;
1250 case TYPE_ANY:
1251 default:
1252 return V1_ANY_UNIQUENESS;
1253 }
1254}
1255
1256//
1257// key is pointer to on disk key which is stored in le, result is cpu,
1258// there is no way to get version of object from key, so, provide
1259// version to these defines
1260//
1261static inline loff_t le_key_k_offset(int version,
1262 const struct reiserfs_key *key)
1263{
1264 return (version == KEY_FORMAT_3_5) ?
1265 le32_to_cpu(key->u.k_offset_v1.k_offset) :
1266 offset_v2_k_offset(&(key->u.k_offset_v2));
1267}
1268
1269static inline loff_t le_ih_k_offset(const struct item_head *ih)
1270{
1271 return le_key_k_offset(ih_version(ih), &(ih->ih_key));
1272}
1273
1274static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)
1275{
1276 return (version == KEY_FORMAT_3_5) ?
1277 uniqueness2type(le32_to_cpu(key->u.k_offset_v1.k_uniqueness)) :
1278 offset_v2_k_type(&(key->u.k_offset_v2));
1279}
1280
1281static inline loff_t le_ih_k_type(const struct item_head *ih)
1282{
1283 return le_key_k_type(ih_version(ih), &(ih->ih_key));
1284}
1285
1286static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,
1287 loff_t offset)
1288{
1289 (version == KEY_FORMAT_3_5) ? (void)(key->u.k_offset_v1.k_offset = cpu_to_le32(offset)) : /* jdm check */
1290 (void)(set_offset_v2_k_offset(&(key->u.k_offset_v2), offset));
1291}
1292
1293static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)
1294{
1295 set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);
1296}
1297
1298static inline void set_le_key_k_type(int version, struct reiserfs_key *key,
1299 int type)
1300{
1301 (version == KEY_FORMAT_3_5) ?
1302 (void)(key->u.k_offset_v1.k_uniqueness =
1303 cpu_to_le32(type2uniqueness(type)))
1304 : (void)(set_offset_v2_k_type(&(key->u.k_offset_v2), type));
1305}
1306
1307static inline void set_le_ih_k_type(struct item_head *ih, int type)
1308{
1309 set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);
1310}
1311
1312static inline int is_direntry_le_key(int version, struct reiserfs_key *key)
1313{
1314 return le_key_k_type(version, key) == TYPE_DIRENTRY;
1315}
1316
1317static inline int is_direct_le_key(int version, struct reiserfs_key *key)
1318{
1319 return le_key_k_type(version, key) == TYPE_DIRECT;
1320}
1321
1322static inline int is_indirect_le_key(int version, struct reiserfs_key *key)
1323{
1324 return le_key_k_type(version, key) == TYPE_INDIRECT;
1325}
1326
1327static inline int is_statdata_le_key(int version, struct reiserfs_key *key)
1328{
1329 return le_key_k_type(version, key) == TYPE_STAT_DATA;
1330}
1331
1332//
1333// item header has version.
1334//
1335static inline int is_direntry_le_ih(struct item_head *ih)
1336{
1337 return is_direntry_le_key(ih_version(ih), &ih->ih_key);
1338}
1339
1340static inline int is_direct_le_ih(struct item_head *ih)
1341{
1342 return is_direct_le_key(ih_version(ih), &ih->ih_key);
1343}
1344
1345static inline int is_indirect_le_ih(struct item_head *ih)
1346{
1347 return is_indirect_le_key(ih_version(ih), &ih->ih_key);
1348}
1349
1350static inline int is_statdata_le_ih(struct item_head *ih)
1351{
1352 return is_statdata_le_key(ih_version(ih), &ih->ih_key);
1353}
1354
1355//
1356// key is pointer to cpu key, result is cpu
1357//
1358static inline loff_t cpu_key_k_offset(const struct cpu_key *key)
1359{
1360 return key->on_disk_key.k_offset;
1361}
1362
1363static inline loff_t cpu_key_k_type(const struct cpu_key *key)
1364{
1365 return key->on_disk_key.k_type;
1366}
1367
1368static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)
1369{
1370 key->on_disk_key.k_offset = offset;
1371}
1372
1373static inline void set_cpu_key_k_type(struct cpu_key *key, int type)
1374{
1375 key->on_disk_key.k_type = type;
1376}
1377
1378static inline void cpu_key_k_offset_dec(struct cpu_key *key)
1379{
1380 key->on_disk_key.k_offset--;
1381}
1382
1383#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)
1384#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)
1385#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)
1386#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)
1387
1388/* are these used ? */
1389#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))
1390#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))
1391#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))
1392#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))
1393
1394#define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \
1395 (!COMP_SHORT_KEYS(ih, key) && \
1396 I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize))
1397
1398/* maximal length of item */
1399#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)
1400#define MIN_ITEM_LEN 1
1401
1402/* object identifier for root dir */
1403#define REISERFS_ROOT_OBJECTID 2
1404#define REISERFS_ROOT_PARENT_OBJECTID 1
1405
1406extern struct reiserfs_key root_key;
1407
1408/*
1409 * Picture represents a leaf of the S+tree
1410 * ______________________________________________________
1411 * | | Array of | | |
1412 * |Block | Object-Item | F r e e | Objects- |
1413 * | head | Headers | S p a c e | Items |
1414 * |______|_______________|___________________|___________|
1415 */
1416
1417/* Header of a disk block. More precisely, header of a formatted leaf
1418 or internal node, and not the header of an unformatted node. */
1419struct block_head {
1420 __le16 blk_level; /* Level of a block in the tree. */
1421 __le16 blk_nr_item; /* Number of keys/items in a block. */
1422 __le16 blk_free_space; /* Block free space in bytes. */
1423 __le16 blk_reserved;
1424 /* dump this in v4/planA */
1425 struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */
1426};
1427
1428#define BLKH_SIZE (sizeof(struct block_head))
1429#define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level))
1430#define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item))
1431#define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space))
1432#define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved))
1433#define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val))
1434#define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val))
1435#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))
1436#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))
1437#define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key)
1438#define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val)
1439
1440/*
1441 * values for blk_level field of the struct block_head
1442 */
1443
1444#define FREE_LEVEL 0 /* when node gets removed from the tree its
1445 blk_level is set to FREE_LEVEL. It is then
1446 used to see whether the node is still in the
1447 tree */
1448
1449#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */
1450
1451/* Given the buffer head of a formatted node, resolve to the block head of that node. */
1452#define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data))
1453/* Number of items that are in buffer. */
1454#define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh)))
1455#define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh)))
1456#define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh)))
1457
1458#define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0)
1459#define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0)
1460#define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0)
1461
1462/* Get right delimiting key. -- little endian */
1463#define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh))))
1464
1465/* Does the buffer contain a disk leaf. */
1466#define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)
1467
1468/* Does the buffer contain a disk internal node */
1469#define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \
1470 && B_LEVEL(bh) <= MAX_HEIGHT)
1471
1472/***************************************************************************/
1473/* STAT DATA */
1474/***************************************************************************/
1475
1476//
1477// old stat data is 32 bytes long. We are going to distinguish new one by
1478// different size
1479//
1480struct stat_data_v1 {
1481 __le16 sd_mode; /* file type, permissions */
1482 __le16 sd_nlink; /* number of hard links */
1483 __le16 sd_uid; /* owner */
1484 __le16 sd_gid; /* group */
1485 __le32 sd_size; /* file size */
1486 __le32 sd_atime; /* time of last access */
1487 __le32 sd_mtime; /* time file was last modified */
1488 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
1489 union {
1490 __le32 sd_rdev;
1491 __le32 sd_blocks; /* number of blocks file uses */
1492 } __attribute__ ((__packed__)) u;
1493 __le32 sd_first_direct_byte; /* first byte of file which is stored
1494 in a direct item: except that if it
1495 equals 1 it is a symlink and if it
1496 equals ~(__u32)0 there is no
1497 direct item. The existence of this
1498 field really grates on me. Let's
1499 replace it with a macro based on
1500 sd_size and our tail suppression
1501 policy. Someday. -Hans */
1502} __attribute__ ((__packed__));
1503
1504#define SD_V1_SIZE (sizeof(struct stat_data_v1))
1505#define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5)
1506#define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
1507#define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
1508#define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink))
1509#define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v))
1510#define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid))
1511#define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v))
1512#define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid))
1513#define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v))
1514#define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size))
1515#define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v))
1516#define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
1517#define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
1518#define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
1519#define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
1520#define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
1521#define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
1522#define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
1523#define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
1524#define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks))
1525#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))
1526#define sd_v1_first_direct_byte(sdp) \
1527 (le32_to_cpu((sdp)->sd_first_direct_byte))
1528#define set_sd_v1_first_direct_byte(sdp,v) \
1529 ((sdp)->sd_first_direct_byte = cpu_to_le32(v))
1530
1531/* inode flags stored in sd_attrs (nee sd_reserved) */
1532
1533/* we want common flags to have the same values as in ext2,
1534 so chattr(1) will work without problems */
1535#define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL
1536#define REISERFS_APPEND_FL FS_APPEND_FL
1537#define REISERFS_SYNC_FL FS_SYNC_FL
1538#define REISERFS_NOATIME_FL FS_NOATIME_FL
1539#define REISERFS_NODUMP_FL FS_NODUMP_FL
1540#define REISERFS_SECRM_FL FS_SECRM_FL
1541#define REISERFS_UNRM_FL FS_UNRM_FL
1542#define REISERFS_COMPR_FL FS_COMPR_FL
1543#define REISERFS_NOTAIL_FL FS_NOTAIL_FL
1544
1545/* persistent flags that file inherits from the parent directory */
1546#define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
1547 REISERFS_SYNC_FL | \
1548 REISERFS_NOATIME_FL | \
1549 REISERFS_NODUMP_FL | \
1550 REISERFS_SECRM_FL | \
1551 REISERFS_COMPR_FL | \
1552 REISERFS_NOTAIL_FL )
1553
1554/* Stat Data on disk (reiserfs version of UFS disk inode minus the
1555 address blocks) */
1556struct stat_data {
1557 __le16 sd_mode; /* file type, permissions */
1558 __le16 sd_attrs; /* persistent inode flags */
1559 __le32 sd_nlink; /* number of hard links */
1560 __le64 sd_size; /* file size */
1561 __le32 sd_uid; /* owner */
1562 __le32 sd_gid; /* group */
1563 __le32 sd_atime; /* time of last access */
1564 __le32 sd_mtime; /* time file was last modified */
1565 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
1566 __le32 sd_blocks;
1567 union {
1568 __le32 sd_rdev;
1569 __le32 sd_generation;
1570 //__le32 sd_first_direct_byte;
1571 /* first byte of file which is stored in a
1572 direct item: except that if it equals 1
1573 it is a symlink and if it equals
1574 ~(__u32)0 there is no direct item. The
1575 existence of this field really grates
1576 on me. Let's replace it with a macro
1577 based on sd_size and our tail
1578 suppression policy? */
1579 } __attribute__ ((__packed__)) u;
1580} __attribute__ ((__packed__));
1581//
1582// this is 44 bytes long
1583//
1584#define SD_SIZE (sizeof(struct stat_data))
1585#define SD_V2_SIZE SD_SIZE
1586#define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6)
1587#define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
1588#define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
1589/* sd_reserved */
1590/* set_sd_reserved */
1591#define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink))
1592#define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v))
1593#define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size))
1594#define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v))
1595#define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid))
1596#define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v))
1597#define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid))
1598#define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v))
1599#define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
1600#define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
1601#define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
1602#define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
1603#define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
1604#define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
1605#define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks))
1606#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))
1607#define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
1608#define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
1609#define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation))
1610#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))
1611#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))
1612#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))
1613
1614/***************************************************************************/
1615/* DIRECTORY STRUCTURE */
1616/***************************************************************************/
1617/*
1618 Picture represents the structure of directory items
1619 ________________________________________________
1620 | Array of | | | | | |
1621 | directory |N-1| N-2 | .... | 1st |0th|
1622 | entry headers | | | | | |
1623 |_______________|___|_____|________|_______|___|
1624 <---- directory entries ------>
1625
1626 First directory item has k_offset component 1. We store "." and ".."
1627 in one item, always, we never split "." and ".." into differing
1628 items. This makes, among other things, the code for removing
1629 directories simpler. */
1630#define SD_OFFSET 0
1631#define SD_UNIQUENESS 0
1632#define DOT_OFFSET 1
1633#define DOT_DOT_OFFSET 2
1634#define DIRENTRY_UNIQUENESS 500
1635
1636/* */
1637#define FIRST_ITEM_OFFSET 1
1638
1639/*
1640 Q: How to get key of object pointed to by entry from entry?
1641
1642 A: Each directory entry has its header. This header has deh_dir_id and deh_objectid fields, those are key
1643 of object, entry points to */
1644
1645/* NOT IMPLEMENTED:
1646 Directory will someday contain stat data of object */
1647
1648struct reiserfs_de_head {
1649 __le32 deh_offset; /* third component of the directory entry key */
1650 __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced
1651 by directory entry */
1652 __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */
1653 __le16 deh_location; /* offset of name in the whole item */
1654 __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether
1655 entry is hidden (unlinked) */
1656} __attribute__ ((__packed__));
1657#define DEH_SIZE sizeof(struct reiserfs_de_head)
1658#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))
1659#define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id))
1660#define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid))
1661#define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location))
1662#define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state))
1663
1664#define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v)))
1665#define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v)))
1666#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))
1667#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))
1668#define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v)))
1669
1670/* empty directory contains two entries "." and ".." and their headers */
1671#define EMPTY_DIR_SIZE \
1672(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen ("..")))
1673
1674/* old format directories have this size when empty */
1675#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)
1676
1677#define DEH_Statdata 0 /* not used now */
1678#define DEH_Visible 2
1679
1680/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */
1681#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)
1682# define ADDR_UNALIGNED_BITS (3)
1683#endif
1684
1685/* These are only used to manipulate deh_state.
1686 * Because of this, we'll use the ext2_ bit routines,
1687 * since they are little endian */
1688#ifdef ADDR_UNALIGNED_BITS
1689
1690# define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))
1691# define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)
1692
1693# define set_bit_unaligned(nr, addr) \
1694 __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1695# define clear_bit_unaligned(nr, addr) \
1696 __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1697# define test_bit_unaligned(nr, addr) \
1698 test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1699
1700#else
1701
1702# define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr)
1703# define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr)
1704# define test_bit_unaligned(nr, addr) test_bit_le(nr, addr)
1705
1706#endif
1707
1708#define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1709#define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1710#define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1711#define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1712
1713#define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1714#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1715#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1716
1717extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
1718 __le32 par_dirid, __le32 par_objid);
1719extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
1720 __le32 par_dirid, __le32 par_objid);
1721
1722/* array of the entry headers */
1723 /* get item body */
1724#define B_I_PITEM(bh,ih) ( (bh)->b_data + ih_location(ih) )
1725#define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))
1726
1727/* length of the directory entry in directory item. This define
1728 calculates length of i-th directory entry using directory entry
1729 locations from dir entry head. When it calculates length of 0-th
1730 directory entry, it uses length of whole item in place of entry
1731 location of the non-existent following entry in the calculation.
1732 See picture above.*/
1733/*
1734#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \
1735((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))
1736*/
1737static inline int entry_length(const struct buffer_head *bh,
1738 const struct item_head *ih, int pos_in_item)
1739{
1740 struct reiserfs_de_head *deh;
1741
1742 deh = B_I_DEH(bh, ih) + pos_in_item;
1743 if (pos_in_item)
1744 return deh_location(deh - 1) - deh_location(deh);
1745
1746 return ih_item_len(ih) - deh_location(deh);
1747}
1748
1749/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */
1750#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))
1751
1752/* name by bh, ih and entry_num */
1753#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))
1754
1755// two entries per block (at least)
1756#define REISERFS_MAX_NAME(block_size) 255
1757
1758/* this structure is used for operations on directory entries. It is
1759 not a disk structure. */
1760/* When reiserfs_find_entry or search_by_entry_key find directory
1761 entry, they return filled reiserfs_dir_entry structure */
1762struct reiserfs_dir_entry {
1763 struct buffer_head *de_bh;
1764 int de_item_num;
1765 struct item_head *de_ih;
1766 int de_entry_num;
1767 struct reiserfs_de_head *de_deh;
1768 int de_entrylen;
1769 int de_namelen;
1770 char *de_name;
1771 unsigned long *de_gen_number_bit_string;
1772
1773 __u32 de_dir_id;
1774 __u32 de_objectid;
1775
1776 struct cpu_key de_entry_key;
1777};
1778
1779/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */
1780
1781/* pointer to file name, stored in entry */
1782#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))
1783
1784/* length of name */
1785#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \
1786(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))
1787
1788/* hash value occupies bits from 7 up to 30 */
1789#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)
1790/* generation number occupies 7 bits starting from 0 up to 6 */
1791#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)
1792#define MAX_GENERATION_NUMBER 127
1793
1794#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))
1795
1796/*
1797 * Picture represents an internal node of the reiserfs tree
1798 * ______________________________________________________
1799 * | | Array of | Array of | Free |
1800 * |block | keys | pointers | space |
1801 * | head | N | N+1 | |
1802 * |______|_______________|___________________|___________|
1803 */
1804
1805/***************************************************************************/
1806/* DISK CHILD */
1807/***************************************************************************/
1808/* Disk child pointer: The pointer from an internal node of the tree
1809 to a node that is on disk. */
1810struct disk_child {
1811 __le32 dc_block_number; /* Disk child's block number. */
1812 __le16 dc_size; /* Disk child's used space. */
1813 __le16 dc_reserved;
1814};
1815
1816#define DC_SIZE (sizeof(struct disk_child))
1817#define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number))
1818#define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size))
1819#define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)
1820#define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)
1821
1822/* Get disk child by buffer header and position in the tree node. */
1823#define B_N_CHILD(bh, n_pos) ((struct disk_child *)\
1824((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos)))
1825
1826/* Get disk child number by buffer header and position in the tree node. */
1827#define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos)))
1828#define PUT_B_N_CHILD_NUM(bh, n_pos, val) \
1829 (put_dc_block_number(B_N_CHILD(bh, n_pos), val))
1830
1831 /* maximal value of field child_size in structure disk_child */
1832 /* child size is the combined size of all items and their headers */
1833#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))
1834
1835/* amount of used space in buffer (not including block head) */
1836#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))
1837
1838/* max and min number of keys in internal node */
1839#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )
1840#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2)
1841
1842/***************************************************************************/
1843/* PATH STRUCTURES AND DEFINES */
1844/***************************************************************************/
1845
1846/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the
1847 key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it
1848 does not find them in the cache it reads them from disk. For each node search_by_key finds using
1849 reiserfs_bread it then uses bin_search to look through that node. bin_search will find the
1850 position of the block_number of the next node if it is looking through an internal node. If it
1851 is looking through a leaf node bin_search will find the position of the item which has key either
1852 equal to given key, or which is the maximal key less than the given key. */
1853
1854struct path_element {
1855 struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in the tree. */
1856 int pe_position; /* Position in the tree node which is placed in the */
1857 /* buffer above. */
1858};
1859
1860#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */
1861#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */
1862#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */
1863
1864#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */
1865#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */
1866
1867/* We need to keep track of who the ancestors of nodes are. When we
1868 perform a search we record which nodes were visited while
1869 descending the tree looking for the node we searched for. This list
1870 of nodes is called the path. This information is used while
1871 performing balancing. Note that this path information may become
1872 invalid, and this means we must check it when using it to see if it
1873 is still valid. You'll need to read search_by_key and the comments
1874 in it, especially about decrement_counters_in_path(), to understand
1875 this structure.
1876
1877Paths make the code so much harder to work with and debug.... An
1878enormous number of bugs are due to them, and trying to write or modify
1879code that uses them just makes my head hurt. They are based on an
1880excessive effort to avoid disturbing the precious VFS code.:-( The
1881gods only know how we are going to SMP the code that uses them.
1882znodes are the way! */
1883
1884#define PATH_READA 0x1 /* do read ahead */
1885#define PATH_READA_BACK 0x2 /* read backwards */
1886
1887struct treepath {
1888 int path_length; /* Length of the array above. */
1889 int reada;
1890 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */
1891 int pos_in_item;
1892};
1893
1894#define pos_in_item(path) ((path)->pos_in_item)
1895
1896#define INITIALIZE_PATH(var) \
1897struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1898
1899/* Get path element by path and path position. */
1900#define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset))
1901
1902/* Get buffer header at the path by path and path position. */
1903#define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer)
1904
1905/* Get position in the element at the path by path and path position. */
1906#define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position)
1907
1908#define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length))
1909 /* you know, to the person who didn't
1910 write this the macro name does not
1911 at first suggest what it does.
1912 Maybe POSITION_FROM_PATH_END? Or
1913 maybe we should just focus on
1914 dumping paths... -Hans */
1915#define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length))
1916
1917#define PATH_PITEM_HEAD(path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path))
1918
1919/* in do_balance leaf has h == 0 in contrast with path structure,
1920 where root has level == 0. That is why we need these defines */
1921#define PATH_H_PBUFFER(path, h) PATH_OFFSET_PBUFFER (path, path->path_length - (h)) /* tb->S[h] */
1922#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */
1923#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))
1924#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */
1925
1926#define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h))
1927
1928#define get_last_bh(path) PATH_PLAST_BUFFER(path)
1929#define get_ih(path) PATH_PITEM_HEAD(path)
1930#define get_item_pos(path) PATH_LAST_POSITION(path)
1931#define get_item(path) ((void *)B_N_PITEM(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path)))
1932#define item_moved(ih,path) comp_items(ih, path)
1933#define path_changed(ih,path) comp_items (ih, path)
1934
1935/***************************************************************************/
1936/* MISC */
1937/***************************************************************************/
1938
1939/* Size of pointer to the unformatted node. */
1940#define UNFM_P_SIZE (sizeof(unp_t))
1941#define UNFM_P_SHIFT 2
1942
1943// in in-core inode key is stored on le form
1944#define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key))
1945
1946#define MAX_UL_INT 0xffffffff
1947#define MAX_INT 0x7ffffff
1948#define MAX_US_INT 0xffff
1949
1950// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset
1951#define U32_MAX (~(__u32)0)
1952
1953static inline loff_t max_reiserfs_offset(struct inode *inode)
1954{
1955 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)
1956 return (loff_t) U32_MAX;
1957
1958 return (loff_t) ((~(__u64) 0) >> 4);
1959}
1960
1961/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/
1962#define MAX_KEY_OBJECTID MAX_UL_INT
1963
1964#define MAX_B_NUM MAX_UL_INT
1965#define MAX_FC_NUM MAX_US_INT
1966
1967/* the purpose is to detect overflow of an unsigned short */
1968#define REISERFS_LINK_MAX (MAX_US_INT - 1000)
1969
1970/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */
1971#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */
1972#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
1973
1974#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
1975#define get_generation(s) atomic_read (&fs_generation(s))
1976#define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
1977#define __fs_changed(gen,s) (gen != get_generation (s))
1978#define fs_changed(gen,s) \
1979({ \
1980 reiserfs_cond_resched(s); \
1981 __fs_changed(gen, s); \
1982})
1983
1984/***************************************************************************/
1985/* FIXATE NODES */
1986/***************************************************************************/
1987
1988#define VI_TYPE_LEFT_MERGEABLE 1
1989#define VI_TYPE_RIGHT_MERGEABLE 2
1990
1991/* To make any changes in the tree we always first find node, that
1992 contains item to be changed/deleted or place to insert a new
1993 item. We call this node S. To do balancing we need to decide what
1994 we will shift to left/right neighbor, or to a new node, where new
1995 item will be etc. To make this analysis simpler we build virtual
1996 node. Virtual node is an array of items, that will replace items of
1997 node S. (For instance if we are going to delete an item, virtual
1998 node does not contain it). Virtual node keeps information about
1999 item sizes and types, mergeability of first and last items, sizes
2000 of all entries in directory item. We use this array of items when
2001 calculating what we can shift to neighbors and how many nodes we
2002 have to have if we do not any shiftings, if we shift to left/right
2003 neighbor or to both. */
2004struct virtual_item {
2005 int vi_index; // index in the array of item operations
2006 unsigned short vi_type; // left/right mergeability
2007 unsigned short vi_item_len; /* length of item that it will have after balancing */
2008 struct item_head *vi_ih;
2009 const char *vi_item; // body of item (old or new)
2010 const void *vi_new_data; // 0 always but paste mode
2011 void *vi_uarea; // item specific area
2012};
2013
2014struct virtual_node {
2015 char *vn_free_ptr; /* this is a pointer to the free space in the buffer */
2016 unsigned short vn_nr_item; /* number of items in virtual node */
2017 short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */
2018 short vn_mode; /* mode of balancing (paste, insert, delete, cut) */
2019 short vn_affected_item_num;
2020 short vn_pos_in_item;
2021 struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */
2022 const void *vn_data;
2023 struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */
2024};
2025
2026/* used by directory items when creating virtual nodes */
2027struct direntry_uarea {
2028 int flags;
2029 __u16 entry_count;
2030 __u16 entry_sizes[1];
2031} __attribute__ ((__packed__));
2032
2033/***************************************************************************/
2034/* TREE BALANCE */
2035/***************************************************************************/
2036
2037/* This temporary structure is used in tree balance algorithms, and
2038 constructed as we go to the extent that its various parts are
2039 needed. It contains arrays of nodes that can potentially be
2040 involved in the balancing of node S, and parameters that define how
2041 each of the nodes must be balanced. Note that in these algorithms
2042 for balancing the worst case is to need to balance the current node
2043 S and the left and right neighbors and all of their parents plus
2044 create a new node. We implement S1 balancing for the leaf nodes
2045 and S0 balancing for the internal nodes (S1 and S0 are defined in
2046 our papers.)*/
2047
2048#define MAX_FREE_BLOCK 7 /* size of the array of buffers to free at end of do_balance */
2049
2050/* maximum number of FEB blocknrs on a single level */
2051#define MAX_AMOUNT_NEEDED 2
2052
2053/* someday somebody will prefix every field in this struct with tb_ */
2054struct tree_balance {
2055 int tb_mode;
2056 int need_balance_dirty;
2057 struct super_block *tb_sb;
2058 struct reiserfs_transaction_handle *transaction_handle;
2059 struct treepath *tb_path;
2060 struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */
2061 struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */
2062 struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */
2063 struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */
2064 struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */
2065 struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */
2066
2067 struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals
2068 cur_blknum. */
2069 struct buffer_head *used[MAX_FEB_SIZE];
2070 struct buffer_head *thrown[MAX_FEB_SIZE];
2071 int lnum[MAX_HEIGHT]; /* array of number of items which must be
2072 shifted to the left in order to balance the
2073 current node; for leaves includes item that
2074 will be partially shifted; for internal
2075 nodes, it is the number of child pointers
2076 rather than items. It includes the new item
2077 being created. The code sometimes subtracts
2078 one to get the number of wholly shifted
2079 items for other purposes. */
2080 int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */
2081 int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and
2082 S[h] to its item number within the node CFL[h] */
2083 int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */
2084 int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from
2085 S[h]. A negative value means removing. */
2086 int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after
2087 balancing on the level h of the tree. If 0 then S is
2088 being deleted, if 1 then S is remaining and no new nodes
2089 are being created, if 2 or 3 then 1 or 2 new nodes is
2090 being created */
2091
2092 /* fields that are used only for balancing leaves of the tree */
2093 int cur_blknum; /* number of empty blocks having been already allocated */
2094 int s0num; /* number of items that fall into left most node when S[0] splits */
2095 int s1num; /* number of items that fall into first new node when S[0] splits */
2096 int s2num; /* number of items that fall into second new node when S[0] splits */
2097 int lbytes; /* number of bytes which can flow to the left neighbor from the left */
2098 /* most liquid item that cannot be shifted from S[0] entirely */
2099 /* if -1 then nothing will be partially shifted */
2100 int rbytes; /* number of bytes which will flow to the right neighbor from the right */
2101 /* most liquid item that cannot be shifted from S[0] entirely */
2102 /* if -1 then nothing will be partially shifted */
2103 int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */
2104 /* note: if S[0] splits into 3 nodes, then items do not need to be cut */
2105 int s2bytes;
2106 struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */
2107 char *vn_buf; /* kmalloced memory. Used to create
2108 virtual node and keep map of
2109 dirtied bitmap blocks */
2110 int vn_buf_size; /* size of the vn_buf */
2111 struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */
2112
2113 int fs_gen; /* saved value of `reiserfs_generation' counter
2114 see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */
2115#ifdef DISPLACE_NEW_PACKING_LOCALITIES
2116 struct in_core_key key; /* key pointer, to pass to block allocator or
2117 another low-level subsystem */
2118#endif
2119};
2120
2121/* These are modes of balancing */
2122
2123/* When inserting an item. */
2124#define M_INSERT 'i'
2125/* When inserting into (directories only) or appending onto an already
2126 existent item. */
2127#define M_PASTE 'p'
2128/* When deleting an item. */
2129#define M_DELETE 'd'
2130/* When truncating an item or removing an entry from a (directory) item. */
2131#define M_CUT 'c'
2132
2133/* used when balancing on leaf level skipped (in reiserfsck) */
2134#define M_INTERNAL 'n'
2135
2136/* When further balancing is not needed, then do_balance does not need
2137 to be called. */
2138#define M_SKIP_BALANCING 's'
2139#define M_CONVERT 'v'
2140
2141/* modes of leaf_move_items */
2142#define LEAF_FROM_S_TO_L 0
2143#define LEAF_FROM_S_TO_R 1
2144#define LEAF_FROM_R_TO_L 2
2145#define LEAF_FROM_L_TO_R 3
2146#define LEAF_FROM_S_TO_SNEW 4
2147
2148#define FIRST_TO_LAST 0
2149#define LAST_TO_FIRST 1
2150
2151/* used in do_balance for passing parent of node information that has
2152 been gotten from tb struct */
2153struct buffer_info {
2154 struct tree_balance *tb;
2155 struct buffer_head *bi_bh;
2156 struct buffer_head *bi_parent;
2157 int bi_position;
2158};
2159
2160static inline struct super_block *sb_from_tb(struct tree_balance *tb)
2161{
2162 return tb ? tb->tb_sb : NULL;
2163}
2164
2165static inline struct super_block *sb_from_bi(struct buffer_info *bi)
2166{
2167 return bi ? sb_from_tb(bi->tb) : NULL;
2168}
2169
2170/* there are 4 types of items: stat data, directory item, indirect, direct.
2171+-------------------+------------+--------------+------------+
2172| | k_offset | k_uniqueness | mergeable? |
2173+-------------------+------------+--------------+------------+
2174| stat data | 0 | 0 | no |
2175+-------------------+------------+--------------+------------+
2176| 1st directory item| DOT_OFFSET |DIRENTRY_UNIQUENESS| no |
2177| non 1st directory | hash value | | yes |
2178| item | | | |
2179+-------------------+------------+--------------+------------+
2180| indirect item | offset + 1 |TYPE_INDIRECT | if this is not the first indirect item of the object
2181+-------------------+------------+--------------+------------+
2182| direct item | offset + 1 |TYPE_DIRECT | if not this is not the first direct item of the object
2183+-------------------+------------+--------------+------------+
2184*/
2185
2186struct item_operations {
2187 int (*bytes_number) (struct item_head * ih, int block_size);
2188 void (*decrement_key) (struct cpu_key *);
2189 int (*is_left_mergeable) (struct reiserfs_key * ih,
2190 unsigned long bsize);
2191 void (*print_item) (struct item_head *, char *item);
2192 void (*check_item) (struct item_head *, char *item);
2193
2194 int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
2195 int is_affected, int insert_size);
2196 int (*check_left) (struct virtual_item * vi, int free,
2197 int start_skip, int end_skip);
2198 int (*check_right) (struct virtual_item * vi, int free);
2199 int (*part_size) (struct virtual_item * vi, int from, int to);
2200 int (*unit_num) (struct virtual_item * vi);
2201 void (*print_vi) (struct virtual_item * vi);
2202};
2203
2204extern struct item_operations *item_ops[TYPE_ANY + 1];
2205
2206#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
2207#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
2208#define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item)
2209#define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item)
2210#define op_create_vi(vn,vi,is_affected,insert_size) item_ops[le_ih_k_type ((vi)->vi_ih)]->create_vi (vn,vi,is_affected,insert_size)
2211#define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip)
2212#define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free)
2213#define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to)
2214#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)
2215#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)
2216
2217#define COMP_SHORT_KEYS comp_short_keys
2218
2219/* number of blocks pointed to by the indirect item */
2220#define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE)
2221
2222/* the used space within the unformatted node corresponding to pos within the item pointed to by ih */
2223#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))
2224
2225/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */
2226
2227/* get the item header */
2228#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) )
2229
2230/* get key */
2231#define B_N_PDELIM_KEY(bh,item_num) ( (struct reiserfs_key * )((bh)->b_data + BLKH_SIZE) + (item_num) )
2232
2233/* get the key */
2234#define B_N_PKEY(bh,item_num) ( &(B_N_PITEM_HEAD(bh,item_num)->ih_key) )
2235
2236/* get item body */
2237#define B_N_PITEM(bh,item_num) ( (bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(item_num))))
2238
2239/* get the stat data by the buffer header and the item order */
2240#define B_N_STAT_DATA(bh,nr) \
2241( (struct stat_data *)((bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(nr))) ) )
2242
2243 /* following defines use reiserfs buffer header and item header */
2244
2245/* get stat-data */
2246#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )
2247
2248// this is 3976 for size==4096
2249#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)
2250
2251/* indirect items consist of entries which contain blocknrs, pos
2252 indicates which entry, and B_I_POS_UNFM_POINTER resolves to the
2253 blocknr contained by the entry pos points to */
2254#define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))
2255#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)
2256
2257struct reiserfs_iget_args {
2258 __u32 objectid;
2259 __u32 dirid;
2260};
2261
2262/***************************************************************************/
2263/* FUNCTION DECLARATIONS */
2264/***************************************************************************/
2265
2266#define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12)
2267
2268#define journal_trans_half(blocksize) \
2269 ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32))
2270
2271/* journal.c see journal.c for all the comments here */
2272
2273/* first block written in a commit. */
2274struct reiserfs_journal_desc {
2275 __le32 j_trans_id; /* id of commit */
2276 __le32 j_len; /* length of commit. len +1 is the commit block */
2277 __le32 j_mount_id; /* mount id of this trans */
2278 __le32 j_realblock[1]; /* real locations for each block */
2279};
2280
2281#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)
2282#define get_desc_trans_len(d) le32_to_cpu((d)->j_len)
2283#define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id)
2284
2285#define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0)
2286#define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0)
2287#define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0)
2288
2289/* last block written in a commit */
2290struct reiserfs_journal_commit {
2291 __le32 j_trans_id; /* must match j_trans_id from the desc block */
2292 __le32 j_len; /* ditto */
2293 __le32 j_realblock[1]; /* real locations for each block */
2294};
2295
2296#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)
2297#define get_commit_trans_len(c) le32_to_cpu((c)->j_len)
2298#define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id)
2299
2300#define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0)
2301#define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0)
2302
2303/* this header block gets written whenever a transaction is considered fully flushed, and is more recent than the
2304** last fully flushed transaction. fully flushed means all the log blocks and all the real blocks are on disk,
2305** and this transaction does not need to be replayed.
2306*/
2307struct reiserfs_journal_header {
2308 __le32 j_last_flush_trans_id; /* id of last fully flushed transaction */
2309 __le32 j_first_unflushed_offset; /* offset in the log of where to start replay after a crash */
2310 __le32 j_mount_id;
2311 /* 12 */ struct journal_params jh_journal;
2312};
2313
2314/* biggest tunable defines are right here */
2315#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */
2316#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */
2317#define JOURNAL_TRANS_MIN_DEFAULT 256
2318#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */
2319#define JOURNAL_MIN_RATIO 2
2320#define JOURNAL_MAX_COMMIT_AGE 30
2321#define JOURNAL_MAX_TRANS_AGE 30
2322#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)
2323#define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \
2324 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \
2325 REISERFS_QUOTA_TRANS_BLOCKS(sb)))
2326
2327#ifdef CONFIG_QUOTA
2328#define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA))
2329/* We need to update data and inode (atime) */
2330#define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0)
2331/* 1 balancing, 1 bitmap, 1 data per write + stat data update */
2332#define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
2333(DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0)
2334/* same as with INIT */
2335#define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
2336(DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0)
2337#else
2338#define REISERFS_QUOTA_TRANS_BLOCKS(s) 0
2339#define REISERFS_QUOTA_INIT_BLOCKS(s) 0
2340#define REISERFS_QUOTA_DEL_BLOCKS(s) 0
2341#endif
2342
2343/* both of these can be as low as 1, or as high as you want. The min is the
2344** number of 4k bitmap nodes preallocated on mount. New nodes are allocated
2345** as needed, and released when transactions are committed. On release, if
2346** the current number of nodes is > max, the node is freed, otherwise,
2347** it is put on a free list for faster use later.
2348*/
2349#define REISERFS_MIN_BITMAP_NODES 10
2350#define REISERFS_MAX_BITMAP_NODES 100
2351
2352#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */
2353#define JBH_HASH_MASK 8191
2354
2355#define _jhashfn(sb,block) \
2356 (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \
2357 (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12))))
2358#define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK])
2359
2360// We need these to make journal.c code more readable
2361#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2362#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2363#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2364
2365enum reiserfs_bh_state_bits {
2366 BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */
2367 BH_JDirty_wait,
2368 BH_JNew, /* disk block was taken off free list before
2369 * being in a finished transaction, or
2370 * written to disk. Can be reused immed. */
2371 BH_JPrepared,
2372 BH_JRestore_dirty,
2373 BH_JTest, // debugging only will go away
2374};
2375
2376BUFFER_FNS(JDirty, journaled);
2377TAS_BUFFER_FNS(JDirty, journaled);
2378BUFFER_FNS(JDirty_wait, journal_dirty);
2379TAS_BUFFER_FNS(JDirty_wait, journal_dirty);
2380BUFFER_FNS(JNew, journal_new);
2381TAS_BUFFER_FNS(JNew, journal_new);
2382BUFFER_FNS(JPrepared, journal_prepared);
2383TAS_BUFFER_FNS(JPrepared, journal_prepared);
2384BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
2385TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
2386BUFFER_FNS(JTest, journal_test);
2387TAS_BUFFER_FNS(JTest, journal_test);
2388
2389/*
2390** transaction handle which is passed around for all journal calls
2391*/
2392struct reiserfs_transaction_handle {
2393 struct super_block *t_super; /* super for this FS when journal_begin was
2394 called. saves calls to reiserfs_get_super
2395 also used by nested transactions to make
2396 sure they are nesting on the right FS
2397 _must_ be first in the handle
2398 */
2399 int t_refcount;
2400 int t_blocks_logged; /* number of blocks this writer has logged */
2401 int t_blocks_allocated; /* number of blocks this writer allocated */
2402 unsigned int t_trans_id; /* sanity check, equals the current trans id */
2403 void *t_handle_save; /* save existing current->journal_info */
2404 unsigned displace_new_blocks:1; /* if new block allocation occurres, that block
2405 should be displaced from others */
2406 struct list_head t_list;
2407};
2408
2409/* used to keep track of ordered and tail writes, attached to the buffer
2410 * head through b_journal_head.
2411 */
2412struct reiserfs_jh {
2413 struct reiserfs_journal_list *jl;
2414 struct buffer_head *bh;
2415 struct list_head list;
2416};
2417
2418void reiserfs_free_jh(struct buffer_head *bh);
2419int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);
2420int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);
2421int journal_mark_dirty(struct reiserfs_transaction_handle *,
2422 struct super_block *, struct buffer_head *bh);
2423
2424static inline int reiserfs_file_data_log(struct inode *inode)
2425{
2426 if (reiserfs_data_log(inode->i_sb) ||
2427 (REISERFS_I(inode)->i_flags & i_data_log))
2428 return 1;
2429 return 0;
2430}
2431
2432static inline int reiserfs_transaction_running(struct super_block *s)
2433{
2434 struct reiserfs_transaction_handle *th = current->journal_info;
2435 if (th && th->t_super == s)
2436 return 1;
2437 if (th && th->t_super == NULL)
2438 BUG();
2439 return 0;
2440}
2441
2442static inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th)
2443{
2444 return th->t_blocks_allocated - th->t_blocks_logged;
2445}
2446
2447struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
2448 super_block
2449 *,
2450 int count);
2451int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);
2452int reiserfs_commit_page(struct inode *inode, struct page *page,
2453 unsigned from, unsigned to);
2454int reiserfs_flush_old_commits(struct super_block *);
2455int reiserfs_commit_for_inode(struct inode *);
2456int reiserfs_inode_needs_commit(struct inode *);
2457void reiserfs_update_inode_transaction(struct inode *);
2458void reiserfs_wait_on_write_block(struct super_block *s);
2459void reiserfs_block_writes(struct reiserfs_transaction_handle *th);
2460void reiserfs_allow_writes(struct super_block *s);
2461void reiserfs_check_lock_depth(struct super_block *s, char *caller);
2462int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,
2463 int wait);
2464void reiserfs_restore_prepared_buffer(struct super_block *,
2465 struct buffer_head *bh);
2466int journal_init(struct super_block *, const char *j_dev_name, int old_format,
2467 unsigned int);
2468int journal_release(struct reiserfs_transaction_handle *, struct super_block *);
2469int journal_release_error(struct reiserfs_transaction_handle *,
2470 struct super_block *);
2471int journal_end(struct reiserfs_transaction_handle *, struct super_block *,
2472 unsigned long);
2473int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,
2474 unsigned long);
2475int journal_mark_freed(struct reiserfs_transaction_handle *,
2476 struct super_block *, b_blocknr_t blocknr);
2477int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
2478int reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr,
2479 int bit_nr, int searchall, b_blocknr_t *next);
2480int journal_begin(struct reiserfs_transaction_handle *,
2481 struct super_block *sb, unsigned long);
2482int journal_join_abort(struct reiserfs_transaction_handle *,
2483 struct super_block *sb, unsigned long);
2484void reiserfs_abort_journal(struct super_block *sb, int errno);
2485void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
2486int reiserfs_allocate_list_bitmaps(struct super_block *s,
2487 struct reiserfs_list_bitmap *, unsigned int);
2488
2489void add_save_link(struct reiserfs_transaction_handle *th,
2490 struct inode *inode, int truncate);
2491int remove_save_link(struct inode *inode, int truncate);
2492
2493/* objectid.c */
2494__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);
2495void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
2496 __u32 objectid_to_release);
2497int reiserfs_convert_objectid_map_v1(struct super_block *);
2498
2499/* stree.c */
2500int B_IS_IN_TREE(const struct buffer_head *);
2501extern void copy_item_head(struct item_head *to,
2502 const struct item_head *from);
2503
2504// first key is in cpu form, second - le
2505extern int comp_short_keys(const struct reiserfs_key *le_key,
2506 const struct cpu_key *cpu_key);
2507extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);
2508
2509// both are in le form
2510extern int comp_le_keys(const struct reiserfs_key *,
2511 const struct reiserfs_key *);
2512extern int comp_short_le_keys(const struct reiserfs_key *,
2513 const struct reiserfs_key *);
2514
2515//
2516// get key version from on disk key - kludge
2517//
2518static inline int le_key_version(const struct reiserfs_key *key)
2519{
2520 int type;
2521
2522 type = offset_v2_k_type(&(key->u.k_offset_v2));
2523 if (type != TYPE_DIRECT && type != TYPE_INDIRECT
2524 && type != TYPE_DIRENTRY)
2525 return KEY_FORMAT_3_5;
2526
2527 return KEY_FORMAT_3_6;
2528
2529}
2530
2531static inline void copy_key(struct reiserfs_key *to,
2532 const struct reiserfs_key *from)
2533{
2534 memcpy(to, from, KEY_SIZE);
2535}
2536
2537int comp_items(const struct item_head *stored_ih, const struct treepath *path);
2538const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
2539 const struct super_block *sb);
2540int search_by_key(struct super_block *, const struct cpu_key *,
2541 struct treepath *, int);
2542#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)
2543int search_for_position_by_key(struct super_block *sb,
2544 const struct cpu_key *cpu_key,
2545 struct treepath *search_path);
2546extern void decrement_bcount(struct buffer_head *bh);
2547void decrement_counters_in_path(struct treepath *search_path);
2548void pathrelse(struct treepath *search_path);
2549int reiserfs_check_path(struct treepath *p);
2550void pathrelse_and_restore(struct super_block *s, struct treepath *search_path);
2551
2552int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
2553 struct treepath *path,
2554 const struct cpu_key *key,
2555 struct item_head *ih,
2556 struct inode *inode, const char *body);
2557
2558int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,
2559 struct treepath *path,
2560 const struct cpu_key *key,
2561 struct inode *inode,
2562 const char *body, int paste_size);
2563
2564int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
2565 struct treepath *path,
2566 struct cpu_key *key,
2567 struct inode *inode,
2568 struct page *page, loff_t new_file_size);
2569
2570int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
2571 struct treepath *path,
2572 const struct cpu_key *key,
2573 struct inode *inode, struct buffer_head *un_bh);
2574
2575void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
2576 struct inode *inode, struct reiserfs_key *key);
2577int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
2578 struct inode *inode);
2579int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
2580 struct inode *inode, struct page *,
2581 int update_timestamps);
2582
2583#define i_block_size(inode) ((inode)->i_sb->s_blocksize)
2584#define file_size(inode) ((inode)->i_size)
2585#define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1))
2586
2587#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\
2588!STORE_TAIL_IN_UNFM_S1(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):have_small_tails ((inode)->i_sb)?!STORE_TAIL_IN_UNFM_S2(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):0 )
2589
2590void padd_item(char *item, int total_length, int length);
2591
2592/* inode.c */
2593/* args for the create parameter of reiserfs_get_block */
2594#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */
2595#define GET_BLOCK_CREATE 1 /* add anything you need to find block */
2596#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */
2597#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */
2598#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */
2599#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */
2600
2601void reiserfs_read_locked_inode(struct inode *inode,
2602 struct reiserfs_iget_args *args);
2603int reiserfs_find_actor(struct inode *inode, void *p);
2604int reiserfs_init_locked_inode(struct inode *inode, void *p);
2605void reiserfs_evict_inode(struct inode *inode);
2606int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc);
2607int reiserfs_get_block(struct inode *inode, sector_t block,
2608 struct buffer_head *bh_result, int create);
2609struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
2610 int fh_len, int fh_type);
2611struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
2612 int fh_len, int fh_type);
2613int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
2614 int connectable);
2615
2616int reiserfs_truncate_file(struct inode *, int update_timestamps);
2617void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,
2618 int type, int key_length);
2619void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
2620 int version,
2621 loff_t offset, int type, int length, int entry_count);
2622struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);
2623
2624struct reiserfs_security_handle;
2625int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
2626 struct inode *dir, umode_t mode,
2627 const char *symname, loff_t i_size,
2628 struct dentry *dentry, struct inode *inode,
2629 struct reiserfs_security_handle *security);
2630
2631void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
2632 struct inode *inode, loff_t size);
2633
2634static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,
2635 struct inode *inode)
2636{
2637 reiserfs_update_sd_size(th, inode, inode->i_size);
2638}
2639
2640void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
2641void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
2642int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
2643
2644int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
2645
2646/* namei.c */
2647void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
2648int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
2649 struct treepath *path, struct reiserfs_dir_entry *de);
2650struct dentry *reiserfs_get_parent(struct dentry *);
2651
2652#ifdef CONFIG_REISERFS_PROC_INFO
2653int reiserfs_proc_info_init(struct super_block *sb);
2654int reiserfs_proc_info_done(struct super_block *sb);
2655int reiserfs_proc_info_global_init(void);
2656int reiserfs_proc_info_global_done(void);
2657
2658#define PROC_EXP( e ) e
2659
2660#define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data
2661#define PROC_INFO_MAX( sb, field, value ) \
2662 __PINFO( sb ).field = \
2663 max( REISERFS_SB( sb ) -> s_proc_info_data.field, value )
2664#define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) )
2665#define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) )
2666#define PROC_INFO_BH_STAT( sb, bh, level ) \
2667 PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \
2668 PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \
2669 PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) )
2670#else
2671static inline int reiserfs_proc_info_init(struct super_block *sb)
2672{
2673 return 0;
2674}
2675
2676static inline int reiserfs_proc_info_done(struct super_block *sb)
2677{
2678 return 0;
2679}
2680
2681static inline int reiserfs_proc_info_global_init(void)
2682{
2683 return 0;
2684}
2685
2686static inline int reiserfs_proc_info_global_done(void)
2687{
2688 return 0;
2689}
2690
2691#define PROC_EXP( e )
2692#define VOID_V ( ( void ) 0 )
2693#define PROC_INFO_MAX( sb, field, value ) VOID_V
2694#define PROC_INFO_INC( sb, field ) VOID_V
2695#define PROC_INFO_ADD( sb, field, val ) VOID_V
2696#define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V
2697#endif
2698
2699/* dir.c */
2700extern const struct inode_operations reiserfs_dir_inode_operations;
2701extern const struct inode_operations reiserfs_symlink_inode_operations;
2702extern const struct inode_operations reiserfs_special_inode_operations;
2703extern const struct file_operations reiserfs_dir_operations;
2704int reiserfs_readdir_dentry(struct dentry *, void *, filldir_t, loff_t *);
2705
2706/* tail_conversion.c */
2707int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,
2708 struct treepath *, struct buffer_head *, loff_t);
2709int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,
2710 struct page *, struct treepath *, const struct cpu_key *,
2711 loff_t, char *);
2712void reiserfs_unmap_buffer(struct buffer_head *);
2713
2714/* file.c */
2715extern const struct inode_operations reiserfs_file_inode_operations;
2716extern const struct file_operations reiserfs_file_operations;
2717extern const struct address_space_operations reiserfs_address_space_operations;
2718
2719/* fix_nodes.c */
2720
2721int fix_nodes(int n_op_mode, struct tree_balance *tb,
2722 struct item_head *ins_ih, const void *);
2723void unfix_nodes(struct tree_balance *);
2724
2725/* prints.c */
2726void __reiserfs_panic(struct super_block *s, const char *id,
2727 const char *function, const char *fmt, ...)
2728 __attribute__ ((noreturn));
2729#define reiserfs_panic(s, id, fmt, args...) \
2730 __reiserfs_panic(s, id, __func__, fmt, ##args)
2731void __reiserfs_error(struct super_block *s, const char *id,
2732 const char *function, const char *fmt, ...);
2733#define reiserfs_error(s, id, fmt, args...) \
2734 __reiserfs_error(s, id, __func__, fmt, ##args)
2735void reiserfs_info(struct super_block *s, const char *fmt, ...);
2736void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
2737void print_indirect_item(struct buffer_head *bh, int item_num);
2738void store_print_tb(struct tree_balance *tb);
2739void print_cur_tb(char *mes);
2740void print_de(struct reiserfs_dir_entry *de);
2741void print_bi(struct buffer_info *bi, char *mes);
2742#define PRINT_LEAF_ITEMS 1 /* print all items */
2743#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */
2744#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */
2745void print_block(struct buffer_head *bh, ...);
2746void print_bmap(struct super_block *s, int silent);
2747void print_bmap_block(int i, char *data, int size, int silent);
2748/*void print_super_block (struct super_block * s, char * mes);*/
2749void print_objectid_map(struct super_block *s);
2750void print_block_head(struct buffer_head *bh, char *mes);
2751void check_leaf(struct buffer_head *bh);
2752void check_internal(struct buffer_head *bh);
2753void print_statistics(struct super_block *s);
2754char *reiserfs_hashname(int code);
2755
2756/* lbalance.c */
2757int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
2758 int mov_bytes, struct buffer_head *Snew);
2759int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);
2760int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);
2761void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,
2762 int del_num, int del_bytes);
2763void leaf_insert_into_buf(struct buffer_info *bi, int before,
2764 struct item_head *inserted_item_ih,
2765 const char *inserted_item_body, int zeros_number);
2766void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,
2767 int pos_in_item, int paste_size, const char *body,
2768 int zeros_number);
2769void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
2770 int pos_in_item, int cut_size);
2771void leaf_paste_entries(struct buffer_info *bi, int item_num, int before,
2772 int new_entry_count, struct reiserfs_de_head *new_dehs,
2773 const char *records, int paste_size);
2774/* ibalance.c */
2775int balance_internal(struct tree_balance *, int, int, struct item_head *,
2776 struct buffer_head **);
2777
2778/* do_balance.c */
2779void do_balance_mark_leaf_dirty(struct tree_balance *tb,
2780 struct buffer_head *bh, int flag);
2781#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
2782#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
2783
2784void do_balance(struct tree_balance *tb, struct item_head *ih,
2785 const char *body, int flag);
2786void reiserfs_invalidate_buffer(struct tree_balance *tb,
2787 struct buffer_head *bh);
2788
2789int get_left_neighbor_position(struct tree_balance *tb, int h);
2790int get_right_neighbor_position(struct tree_balance *tb, int h);
2791void replace_key(struct tree_balance *tb, struct buffer_head *, int,
2792 struct buffer_head *, int);
2793void make_empty_node(struct buffer_info *);
2794struct buffer_head *get_FEB(struct tree_balance *);
2795
2796/* bitmap.c */
2797
2798/* structure contains hints for block allocator, and it is a container for
2799 * arguments, such as node, search path, transaction_handle, etc. */
2800struct __reiserfs_blocknr_hint {
2801 struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
2802 sector_t block; /* file offset, in blocks */
2803 struct in_core_key key;
2804 struct treepath *path; /* search path, used by allocator to deternine search_start by
2805 * various ways */
2806 struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and
2807 * bitmap blocks changes */
2808 b_blocknr_t beg, end;
2809 b_blocknr_t search_start; /* a field used to transfer search start value (block number)
2810 * between different block allocator procedures
2811 * (determine_search_start() and others) */
2812 int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed
2813 * function that do actual allocation */
2814
2815 unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for
2816 * formatted/unformatted blocks with/without preallocation */
2817 unsigned preallocate:1;
2818};
2819
2820typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;
2821
2822int reiserfs_parse_alloc_options(struct super_block *, char *);
2823void reiserfs_init_alloc_options(struct super_block *s);
2824
2825/*
2826 * given a directory, this will tell you what packing locality
2827 * to use for a new object underneat it. The locality is returned
2828 * in disk byte order (le).
2829 */
2830__le32 reiserfs_choose_packing(struct inode *dir);
2831
2832int reiserfs_init_bitmap_cache(struct super_block *sb);
2833void reiserfs_free_bitmap_cache(struct super_block *sb);
2834void reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info);
2835struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap);
2836int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);
2837void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,
2838 b_blocknr_t, int for_unformatted);
2839int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,
2840 int);
2841static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2842 b_blocknr_t * new_blocknrs,
2843 int amount_needed)
2844{
2845 reiserfs_blocknr_hint_t hint = {
2846 .th = tb->transaction_handle,
2847 .path = tb->tb_path,
2848 .inode = NULL,
2849 .key = tb->key,
2850 .block = 0,
2851 .formatted_node = 1
2852 };
2853 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,
2854 0);
2855}
2856
2857static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2858 *th, struct inode *inode,
2859 b_blocknr_t * new_blocknrs,
2860 struct treepath *path,
2861 sector_t block)
2862{
2863 reiserfs_blocknr_hint_t hint = {
2864 .th = th,
2865 .path = path,
2866 .inode = inode,
2867 .block = block,
2868 .formatted_node = 0,
2869 .preallocate = 0
2870 };
2871 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2872}
2873
2874#ifdef REISERFS_PREALLOCATE
2875static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
2876 *th, struct inode *inode,
2877 b_blocknr_t * new_blocknrs,
2878 struct treepath *path,
2879 sector_t block)
2880{
2881 reiserfs_blocknr_hint_t hint = {
2882 .th = th,
2883 .path = path,
2884 .inode = inode,
2885 .block = block,
2886 .formatted_node = 0,
2887 .preallocate = 1
2888 };
2889 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2890}
2891
2892void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
2893 struct inode *inode);
2894void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);
2895#endif
2896
2897/* hashes.c */
2898__u32 keyed_hash(const signed char *msg, int len);
2899__u32 yura_hash(const signed char *msg, int len);
2900__u32 r5_hash(const signed char *msg, int len);
2901
2902#define reiserfs_set_le_bit __set_bit_le
2903#define reiserfs_test_and_set_le_bit __test_and_set_bit_le
2904#define reiserfs_clear_le_bit __clear_bit_le
2905#define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le
2906#define reiserfs_test_le_bit test_bit_le
2907#define reiserfs_find_next_zero_le_bit find_next_zero_bit_le
2908
2909/* sometimes reiserfs_truncate may require to allocate few new blocks
2910 to perform indirect2direct conversion. People probably used to
2911 think, that truncate should work without problems on a filesystem
2912 without free disk space. They may complain that they can not
2913 truncate due to lack of free disk space. This spare space allows us
2914 to not worry about it. 500 is probably too much, but it should be
2915 absolutely safe */
2916#define SPARE_SPACE 500
2917
2918/* prototypes from ioctl.c */
2919long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
2920long reiserfs_compat_ioctl(struct file *filp,
2921 unsigned int cmd, unsigned long arg);
2922int reiserfs_unpack(struct inode *inode, struct file *filp);
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 7483279b482d..9a17f63c3fd7 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -13,8 +13,7 @@
13#include <linux/vmalloc.h> 13#include <linux/vmalloc.h>
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/reiserfs_fs.h> 16#include "reiserfs.h"
17#include <linux/reiserfs_fs_sb.h>
18#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
19 18
20int reiserfs_resize(struct super_block *s, unsigned long block_count_new) 19int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 77df82f9e70a..f8afa4b162b8 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -51,7 +51,7 @@
51#include <linux/time.h> 51#include <linux/time.h>
52#include <linux/string.h> 52#include <linux/string.h>
53#include <linux/pagemap.h> 53#include <linux/pagemap.h>
54#include <linux/reiserfs_fs.h> 54#include "reiserfs.h"
55#include <linux/buffer_head.h> 55#include <linux/buffer_head.h>
56#include <linux/quotaops.h> 56#include <linux/quotaops.h>
57 57
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index e12d8b97cd4d..8b7616ef06d8 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -16,9 +16,9 @@
16#include <linux/vmalloc.h> 16#include <linux/vmalloc.h>
17#include <linux/time.h> 17#include <linux/time.h>
18#include <asm/uaccess.h> 18#include <asm/uaccess.h>
19#include <linux/reiserfs_fs.h> 19#include "reiserfs.h"
20#include <linux/reiserfs_acl.h> 20#include "acl.h"
21#include <linux/reiserfs_xattr.h> 21#include "xattr.h"
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/blkdev.h> 23#include <linux/blkdev.h>
24#include <linux/buffer_head.h> 24#include <linux/buffer_head.h>
@@ -1874,11 +1874,9 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1874 unlock_new_inode(root_inode); 1874 unlock_new_inode(root_inode);
1875 } 1875 }
1876 1876
1877 s->s_root = d_alloc_root(root_inode); 1877 s->s_root = d_make_root(root_inode);
1878 if (!s->s_root) { 1878 if (!s->s_root)
1879 iput(root_inode);
1880 goto error; 1879 goto error;
1881 }
1882 // define and initialize hash function 1880 // define and initialize hash function
1883 sbi->s_hash_function = hash_function(s); 1881 sbi->s_hash_function = hash_function(s);
1884 if (sbi->s_hash_function == NULL) { 1882 if (sbi->s_hash_function == NULL) {
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index 8f546bd473b8..5e2624d12f70 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -5,7 +5,7 @@
5#include <linux/time.h> 5#include <linux/time.h>
6#include <linux/pagemap.h> 6#include <linux/pagemap.h>
7#include <linux/buffer_head.h> 7#include <linux/buffer_head.h>
8#include <linux/reiserfs_fs.h> 8#include "reiserfs.h"
9 9
10/* access to tail : when one is going to read tail it must make sure, that is not running. 10/* access to tail : when one is going to read tail it must make sure, that is not running.
11 direct2indirect and indirect2direct can not run concurrently */ 11 direct2indirect and indirect2direct can not run concurrently */
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index c24deda8a8bc..46fc1c20a6b1 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -33,7 +33,7 @@
33 * The xattrs themselves are protected by the xattr_sem. 33 * The xattrs themselves are protected by the xattr_sem.
34 */ 34 */
35 35
36#include <linux/reiserfs_fs.h> 36#include "reiserfs.h"
37#include <linux/capability.h> 37#include <linux/capability.h>
38#include <linux/dcache.h> 38#include <linux/dcache.h>
39#include <linux/namei.h> 39#include <linux/namei.h>
@@ -43,8 +43,8 @@
43#include <linux/file.h> 43#include <linux/file.h>
44#include <linux/pagemap.h> 44#include <linux/pagemap.h>
45#include <linux/xattr.h> 45#include <linux/xattr.h>
46#include <linux/reiserfs_xattr.h> 46#include "xattr.h"
47#include <linux/reiserfs_acl.h> 47#include "acl.h"
48#include <asm/uaccess.h> 48#include <asm/uaccess.h>
49#include <net/checksum.h> 49#include <net/checksum.h>
50#include <linux/stat.h> 50#include <linux/stat.h>
diff --git a/fs/reiserfs/xattr.h b/fs/reiserfs/xattr.h
new file mode 100644
index 000000000000..f59626c5d33b
--- /dev/null
+++ b/fs/reiserfs/xattr.h
@@ -0,0 +1,122 @@
1#include <linux/reiserfs_xattr.h>
2#include <linux/init.h>
3#include <linux/list.h>
4#include <linux/rwsem.h>
5
6struct inode;
7struct dentry;
8struct iattr;
9struct super_block;
10struct nameidata;
11
12int reiserfs_xattr_register_handlers(void) __init;
13void reiserfs_xattr_unregister_handlers(void);
14int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
15int reiserfs_lookup_privroot(struct super_block *sb);
16int reiserfs_delete_xattrs(struct inode *inode);
17int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
18int reiserfs_permission(struct inode *inode, int mask);
19
20#ifdef CONFIG_REISERFS_FS_XATTR
21#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
22ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name,
23 void *buffer, size_t size);
24int reiserfs_setxattr(struct dentry *dentry, const char *name,
25 const void *value, size_t size, int flags);
26ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
27int reiserfs_removexattr(struct dentry *dentry, const char *name);
28
29int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
30int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
31int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
32 struct inode *, const char *, const void *,
33 size_t, int);
34
35extern const struct xattr_handler reiserfs_xattr_user_handler;
36extern const struct xattr_handler reiserfs_xattr_trusted_handler;
37extern const struct xattr_handler reiserfs_xattr_security_handler;
38#ifdef CONFIG_REISERFS_FS_SECURITY
39int reiserfs_security_init(struct inode *dir, struct inode *inode,
40 const struct qstr *qstr,
41 struct reiserfs_security_handle *sec);
42int reiserfs_security_write(struct reiserfs_transaction_handle *th,
43 struct inode *inode,
44 struct reiserfs_security_handle *sec);
45void reiserfs_security_free(struct reiserfs_security_handle *sec);
46#endif
47
48static inline int reiserfs_xattrs_initialized(struct super_block *sb)
49{
50 return REISERFS_SB(sb)->priv_root != NULL;
51}
52
53#define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
54static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
55{
56 loff_t ret = 0;
57 if (reiserfs_file_data_log(inode)) {
58 ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
59 ret >>= inode->i_sb->s_blocksize_bits;
60 }
61 return ret;
62}
63
64/* We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
65 * Let's try to be smart about it.
66 * xattr root: We cache it. If it's not cached, we may need to create it.
67 * xattr dir: If anything has been loaded for this inode, we can set a flag
68 * saying so.
69 * xattr file: Since we don't cache xattrs, we can't tell. We always include
70 * blocks for it.
71 *
72 * However, since root and dir can be created between calls - YOU MUST SAVE
73 * THIS VALUE.
74 */
75static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
76{
77 size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
78
79 if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
80 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
81 if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode)
82 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
83 }
84
85 return nblocks;
86}
87
88static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
89{
90 init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
91}
92
93#else
94
95#define reiserfs_getxattr NULL
96#define reiserfs_setxattr NULL
97#define reiserfs_listxattr NULL
98#define reiserfs_removexattr NULL
99
100static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
101{
102}
103#endif /* CONFIG_REISERFS_FS_XATTR */
104
105#ifndef CONFIG_REISERFS_FS_SECURITY
106static inline int reiserfs_security_init(struct inode *dir,
107 struct inode *inode,
108 const struct qstr *qstr,
109 struct reiserfs_security_handle *sec)
110{
111 return 0;
112}
113static inline int
114reiserfs_security_write(struct reiserfs_transaction_handle *th,
115 struct inode *inode,
116 struct reiserfs_security_handle *sec)
117{
118 return 0;
119}
120static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
121{}
122#endif
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index 6da0396e5052..44474f9b990d 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -1,14 +1,14 @@
1#include <linux/capability.h> 1#include <linux/capability.h>
2#include <linux/fs.h> 2#include <linux/fs.h>
3#include <linux/posix_acl.h> 3#include <linux/posix_acl.h>
4#include <linux/reiserfs_fs.h> 4#include "reiserfs.h"
5#include <linux/errno.h> 5#include <linux/errno.h>
6#include <linux/pagemap.h> 6#include <linux/pagemap.h>
7#include <linux/xattr.h> 7#include <linux/xattr.h>
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/posix_acl_xattr.h> 9#include <linux/posix_acl_xattr.h>
10#include <linux/reiserfs_xattr.h> 10#include "xattr.h"
11#include <linux/reiserfs_acl.h> 11#include "acl.h"
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13 13
14static int reiserfs_set_acl(struct reiserfs_transaction_handle *th, 14static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
diff --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
index 534668fa41be..800a3cef6f62 100644
--- a/fs/reiserfs/xattr_security.c
+++ b/fs/reiserfs/xattr_security.c
@@ -1,10 +1,10 @@
1#include <linux/reiserfs_fs.h> 1#include "reiserfs.h"
2#include <linux/errno.h> 2#include <linux/errno.h>
3#include <linux/fs.h> 3#include <linux/fs.h>
4#include <linux/pagemap.h> 4#include <linux/pagemap.h>
5#include <linux/xattr.h> 5#include <linux/xattr.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/reiserfs_xattr.h> 7#include "xattr.h"
8#include <linux/security.h> 8#include <linux/security.h>
9#include <asm/uaccess.h> 9#include <asm/uaccess.h>
10 10
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 9883736ce3ec..a0035719f66b 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -1,10 +1,10 @@
1#include <linux/reiserfs_fs.h> 1#include "reiserfs.h"
2#include <linux/capability.h> 2#include <linux/capability.h>
3#include <linux/errno.h> 3#include <linux/errno.h>
4#include <linux/fs.h> 4#include <linux/fs.h>
5#include <linux/pagemap.h> 5#include <linux/pagemap.h>
6#include <linux/xattr.h> 6#include <linux/xattr.h>
7#include <linux/reiserfs_xattr.h> 7#include "xattr.h"
8#include <asm/uaccess.h> 8#include <asm/uaccess.h>
9 9
10static int 10static int
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index 45ae1a00013a..8667491ae7c3 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -1,9 +1,9 @@
1#include <linux/reiserfs_fs.h> 1#include "reiserfs.h"
2#include <linux/errno.h> 2#include <linux/errno.h>
3#include <linux/fs.h> 3#include <linux/fs.h>
4#include <linux/pagemap.h> 4#include <linux/pagemap.h>
5#include <linux/xattr.h> 5#include <linux/xattr.h>
6#include <linux/reiserfs_xattr.h> 6#include "xattr.h"
7#include <asm/uaccess.h> 7#include <asm/uaccess.h>
8 8
9static int 9static int
diff --git a/fs/romfs/super.c b/fs/romfs/super.c
index bb36ab74eb45..e64f6b5f7ae5 100644
--- a/fs/romfs/super.c
+++ b/fs/romfs/super.c
@@ -538,14 +538,12 @@ static int romfs_fill_super(struct super_block *sb, void *data, int silent)
538 if (IS_ERR(root)) 538 if (IS_ERR(root))
539 goto error; 539 goto error;
540 540
541 sb->s_root = d_alloc_root(root); 541 sb->s_root = d_make_root(root);
542 if (!sb->s_root) 542 if (!sb->s_root)
543 goto error_i; 543 goto error;
544 544
545 return 0; 545 return 0;
546 546
547error_i:
548 iput(root);
549error: 547error:
550 return -EINVAL; 548 return -EINVAL;
551error_rsb_inval: 549error_rsb_inval:
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index ecaa2f7bdb8f..970b1167e7cb 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -316,11 +316,10 @@ check_directory_table:
316 } 316 }
317 insert_inode_hash(root); 317 insert_inode_hash(root);
318 318
319 sb->s_root = d_alloc_root(root); 319 sb->s_root = d_make_root(root);
320 if (sb->s_root == NULL) { 320 if (sb->s_root == NULL) {
321 ERROR("Root inode create failed\n"); 321 ERROR("Root inode create failed\n");
322 err = -ENOMEM; 322 err = -ENOMEM;
323 iput(root);
324 goto failed_mount; 323 goto failed_mount;
325 } 324 }
326 325
diff --git a/fs/stat.c b/fs/stat.c
index 8806b8997d2e..86f13563a463 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -307,7 +307,7 @@ SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,
307 if (inode->i_op->readlink) { 307 if (inode->i_op->readlink) {
308 error = security_inode_readlink(path.dentry); 308 error = security_inode_readlink(path.dentry);
309 if (!error) { 309 if (!error) {
310 touch_atime(path.mnt, path.dentry); 310 touch_atime(&path);
311 error = inode->i_op->readlink(path.dentry, 311 error = inode->i_op->readlink(path.dentry,
312 buf, bufsiz); 312 buf, bufsiz);
313 } 313 }
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 140f26a34288..52c3bdb66a84 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -61,10 +61,9 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
61 } 61 }
62 62
63 /* instantiate and link root dentry */ 63 /* instantiate and link root dentry */
64 root = d_alloc_root(inode); 64 root = d_make_root(inode);
65 if (!root) { 65 if (!root) {
66 pr_debug("%s: could not get root dentry!\n",__func__); 66 pr_debug("%s: could not get root dentry!\n",__func__);
67 iput(inode);
68 return -ENOMEM; 67 return -ENOMEM;
69 } 68 }
70 root->d_fsdata = &sysfs_root; 69 root->d_fsdata = &sysfs_root;
diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c
index b217797e621b..d7466e293614 100644
--- a/fs/sysv/namei.c
+++ b/fs/sysv/namei.c
@@ -121,9 +121,6 @@ static int sysv_link(struct dentry * old_dentry, struct inode * dir,
121{ 121{
122 struct inode *inode = old_dentry->d_inode; 122 struct inode *inode = old_dentry->d_inode;
123 123
124 if (inode->i_nlink >= SYSV_SB(inode->i_sb)->s_link_max)
125 return -EMLINK;
126
127 inode->i_ctime = CURRENT_TIME_SEC; 124 inode->i_ctime = CURRENT_TIME_SEC;
128 inode_inc_link_count(inode); 125 inode_inc_link_count(inode);
129 ihold(inode); 126 ihold(inode);
@@ -134,10 +131,8 @@ static int sysv_link(struct dentry * old_dentry, struct inode * dir,
134static int sysv_mkdir(struct inode * dir, struct dentry *dentry, umode_t mode) 131static int sysv_mkdir(struct inode * dir, struct dentry *dentry, umode_t mode)
135{ 132{
136 struct inode * inode; 133 struct inode * inode;
137 int err = -EMLINK; 134 int err;
138 135
139 if (dir->i_nlink >= SYSV_SB(dir->i_sb)->s_link_max)
140 goto out;
141 inode_inc_link_count(dir); 136 inode_inc_link_count(dir);
142 137
143 inode = sysv_new_inode(dir, S_IFDIR|mode); 138 inode = sysv_new_inode(dir, S_IFDIR|mode);
@@ -251,11 +246,6 @@ static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry,
251 drop_nlink(new_inode); 246 drop_nlink(new_inode);
252 inode_dec_link_count(new_inode); 247 inode_dec_link_count(new_inode);
253 } else { 248 } else {
254 if (dir_de) {
255 err = -EMLINK;
256 if (new_dir->i_nlink >= SYSV_SB(new_dir->i_sb)->s_link_max)
257 goto out_dir;
258 }
259 err = sysv_add_link(new_dentry, old_inode); 249 err = sysv_add_link(new_dentry, old_inode);
260 if (err) 250 if (err)
261 goto out_dir; 251 goto out_dir;
diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index f60c196913ea..7491c33b6468 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -44,7 +44,7 @@ enum {
44 JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60 44 JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60
45}; 45};
46 46
47static void detected_xenix(struct sysv_sb_info *sbi) 47static void detected_xenix(struct sysv_sb_info *sbi, unsigned *max_links)
48{ 48{
49 struct buffer_head *bh1 = sbi->s_bh1; 49 struct buffer_head *bh1 = sbi->s_bh1;
50 struct buffer_head *bh2 = sbi->s_bh2; 50 struct buffer_head *bh2 = sbi->s_bh2;
@@ -59,7 +59,7 @@ static void detected_xenix(struct sysv_sb_info *sbi)
59 sbd2 = (struct xenix_super_block *) (bh2->b_data - 512); 59 sbd2 = (struct xenix_super_block *) (bh2->b_data - 512);
60 } 60 }
61 61
62 sbi->s_link_max = XENIX_LINK_MAX; 62 *max_links = XENIX_LINK_MAX;
63 sbi->s_fic_size = XENIX_NICINOD; 63 sbi->s_fic_size = XENIX_NICINOD;
64 sbi->s_flc_size = XENIX_NICFREE; 64 sbi->s_flc_size = XENIX_NICFREE;
65 sbi->s_sbd1 = (char *)sbd1; 65 sbi->s_sbd1 = (char *)sbd1;
@@ -75,7 +75,7 @@ static void detected_xenix(struct sysv_sb_info *sbi)
75 sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize); 75 sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize);
76} 76}
77 77
78static void detected_sysv4(struct sysv_sb_info *sbi) 78static void detected_sysv4(struct sysv_sb_info *sbi, unsigned *max_links)
79{ 79{
80 struct sysv4_super_block * sbd; 80 struct sysv4_super_block * sbd;
81 struct buffer_head *bh1 = sbi->s_bh1; 81 struct buffer_head *bh1 = sbi->s_bh1;
@@ -86,7 +86,7 @@ static void detected_sysv4(struct sysv_sb_info *sbi)
86 else 86 else
87 sbd = (struct sysv4_super_block *) bh2->b_data; 87 sbd = (struct sysv4_super_block *) bh2->b_data;
88 88
89 sbi->s_link_max = SYSV_LINK_MAX; 89 *max_links = SYSV_LINK_MAX;
90 sbi->s_fic_size = SYSV_NICINOD; 90 sbi->s_fic_size = SYSV_NICINOD;
91 sbi->s_flc_size = SYSV_NICFREE; 91 sbi->s_flc_size = SYSV_NICFREE;
92 sbi->s_sbd1 = (char *)sbd; 92 sbi->s_sbd1 = (char *)sbd;
@@ -103,7 +103,7 @@ static void detected_sysv4(struct sysv_sb_info *sbi)
103 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); 103 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
104} 104}
105 105
106static void detected_sysv2(struct sysv_sb_info *sbi) 106static void detected_sysv2(struct sysv_sb_info *sbi, unsigned *max_links)
107{ 107{
108 struct sysv2_super_block *sbd; 108 struct sysv2_super_block *sbd;
109 struct buffer_head *bh1 = sbi->s_bh1; 109 struct buffer_head *bh1 = sbi->s_bh1;
@@ -114,7 +114,7 @@ static void detected_sysv2(struct sysv_sb_info *sbi)
114 else 114 else
115 sbd = (struct sysv2_super_block *) bh2->b_data; 115 sbd = (struct sysv2_super_block *) bh2->b_data;
116 116
117 sbi->s_link_max = SYSV_LINK_MAX; 117 *max_links = SYSV_LINK_MAX;
118 sbi->s_fic_size = SYSV_NICINOD; 118 sbi->s_fic_size = SYSV_NICINOD;
119 sbi->s_flc_size = SYSV_NICFREE; 119 sbi->s_flc_size = SYSV_NICFREE;
120 sbi->s_sbd1 = (char *)sbd; 120 sbi->s_sbd1 = (char *)sbd;
@@ -131,14 +131,14 @@ static void detected_sysv2(struct sysv_sb_info *sbi)
131 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); 131 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
132} 132}
133 133
134static void detected_coherent(struct sysv_sb_info *sbi) 134static void detected_coherent(struct sysv_sb_info *sbi, unsigned *max_links)
135{ 135{
136 struct coh_super_block * sbd; 136 struct coh_super_block * sbd;
137 struct buffer_head *bh1 = sbi->s_bh1; 137 struct buffer_head *bh1 = sbi->s_bh1;
138 138
139 sbd = (struct coh_super_block *) bh1->b_data; 139 sbd = (struct coh_super_block *) bh1->b_data;
140 140
141 sbi->s_link_max = COH_LINK_MAX; 141 *max_links = COH_LINK_MAX;
142 sbi->s_fic_size = COH_NICINOD; 142 sbi->s_fic_size = COH_NICINOD;
143 sbi->s_flc_size = COH_NICFREE; 143 sbi->s_flc_size = COH_NICFREE;
144 sbi->s_sbd1 = (char *)sbd; 144 sbi->s_sbd1 = (char *)sbd;
@@ -154,12 +154,12 @@ static void detected_coherent(struct sysv_sb_info *sbi)
154 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); 154 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
155} 155}
156 156
157static void detected_v7(struct sysv_sb_info *sbi) 157static void detected_v7(struct sysv_sb_info *sbi, unsigned *max_links)
158{ 158{
159 struct buffer_head *bh2 = sbi->s_bh2; 159 struct buffer_head *bh2 = sbi->s_bh2;
160 struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data; 160 struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data;
161 161
162 sbi->s_link_max = V7_LINK_MAX; 162 *max_links = V7_LINK_MAX;
163 sbi->s_fic_size = V7_NICINOD; 163 sbi->s_fic_size = V7_NICINOD;
164 sbi->s_flc_size = V7_NICFREE; 164 sbi->s_flc_size = V7_NICFREE;
165 sbi->s_sbd1 = (char *)sbd; 165 sbi->s_sbd1 = (char *)sbd;
@@ -290,7 +290,7 @@ static char *flavour_names[] = {
290 [FSTYPE_AFS] = "AFS", 290 [FSTYPE_AFS] = "AFS",
291}; 291};
292 292
293static void (*flavour_setup[])(struct sysv_sb_info *) = { 293static void (*flavour_setup[])(struct sysv_sb_info *, unsigned *) = {
294 [FSTYPE_XENIX] = detected_xenix, 294 [FSTYPE_XENIX] = detected_xenix,
295 [FSTYPE_SYSV4] = detected_sysv4, 295 [FSTYPE_SYSV4] = detected_sysv4,
296 [FSTYPE_SYSV2] = detected_sysv2, 296 [FSTYPE_SYSV2] = detected_sysv2,
@@ -310,7 +310,7 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
310 310
311 sbi->s_firstinodezone = 2; 311 sbi->s_firstinodezone = 2;
312 312
313 flavour_setup[sbi->s_type](sbi); 313 flavour_setup[sbi->s_type](sbi, &sb->s_max_links);
314 314
315 sbi->s_truncate = 1; 315 sbi->s_truncate = 1;
316 sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone; 316 sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
@@ -341,9 +341,8 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
341 printk("SysV FS: get root inode failed\n"); 341 printk("SysV FS: get root inode failed\n");
342 return 0; 342 return 0;
343 } 343 }
344 sb->s_root = d_alloc_root(root_inode); 344 sb->s_root = d_make_root(root_inode);
345 if (!sb->s_root) { 345 if (!sb->s_root) {
346 iput(root_inode);
347 printk("SysV FS: get root dentry failed\n"); 346 printk("SysV FS: get root dentry failed\n");
348 return 0; 347 return 0;
349 } 348 }
diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
index 0e4b821c5691..11b07672f6c5 100644
--- a/fs/sysv/sysv.h
+++ b/fs/sysv/sysv.h
@@ -24,7 +24,6 @@ struct sysv_sb_info {
24 char s_bytesex; /* bytesex (le/be/pdp) */ 24 char s_bytesex; /* bytesex (le/be/pdp) */
25 char s_truncate; /* if 1: names > SYSV_NAMELEN chars are truncated */ 25 char s_truncate; /* if 1: names > SYSV_NAMELEN chars are truncated */
26 /* if 0: they are disallowed (ENAMETOOLONG) */ 26 /* if 0: they are disallowed (ENAMETOOLONG) */
27 nlink_t s_link_max; /* max number of hard links to a file */
28 unsigned int s_inodes_per_block; /* number of inodes per block */ 27 unsigned int s_inodes_per_block; /* number of inodes per block */
29 unsigned int s_inodes_per_block_1; /* inodes_per_block - 1 */ 28 unsigned int s_inodes_per_block_1; /* inodes_per_block - 1 */
30 unsigned int s_inodes_per_block_bits; /* log2(inodes_per_block) */ 29 unsigned int s_inodes_per_block_bits; /* log2(inodes_per_block) */
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 63765d58445b..76e4e0566ad6 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2076,15 +2076,13 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
2076 goto out_umount; 2076 goto out_umount;
2077 } 2077 }
2078 2078
2079 sb->s_root = d_alloc_root(root); 2079 sb->s_root = d_make_root(root);
2080 if (!sb->s_root) 2080 if (!sb->s_root)
2081 goto out_iput; 2081 goto out_umount;
2082 2082
2083 mutex_unlock(&c->umount_mutex); 2083 mutex_unlock(&c->umount_mutex);
2084 return 0; 2084 return 0;
2085 2085
2086out_iput:
2087 iput(root);
2088out_umount: 2086out_umount:
2089 ubifs_umount(c); 2087 ubifs_umount(c);
2090out_unlock: 2088out_unlock:
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 08bf46edf9c4..38de8f234b94 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -32,8 +32,6 @@
32#include <linux/crc-itu-t.h> 32#include <linux/crc-itu-t.h>
33#include <linux/exportfs.h> 33#include <linux/exportfs.h>
34 34
35enum { UDF_MAX_LINKS = 0xffff };
36
37static inline int udf_match(int len1, const unsigned char *name1, int len2, 35static inline int udf_match(int len1, const unsigned char *name1, int len2,
38 const unsigned char *name2) 36 const unsigned char *name2)
39{ 37{
@@ -649,10 +647,6 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
649 struct udf_inode_info *dinfo = UDF_I(dir); 647 struct udf_inode_info *dinfo = UDF_I(dir);
650 struct udf_inode_info *iinfo; 648 struct udf_inode_info *iinfo;
651 649
652 err = -EMLINK;
653 if (dir->i_nlink >= UDF_MAX_LINKS)
654 goto out;
655
656 err = -EIO; 650 err = -EIO;
657 inode = udf_new_inode(dir, S_IFDIR | mode, &err); 651 inode = udf_new_inode(dir, S_IFDIR | mode, &err);
658 if (!inode) 652 if (!inode)
@@ -1032,9 +1026,6 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
1032 struct fileIdentDesc cfi, *fi; 1026 struct fileIdentDesc cfi, *fi;
1033 int err; 1027 int err;
1034 1028
1035 if (inode->i_nlink >= UDF_MAX_LINKS)
1036 return -EMLINK;
1037
1038 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); 1029 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
1039 if (!fi) { 1030 if (!fi) {
1040 return err; 1031 return err;
@@ -1126,10 +1117,6 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1126 if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) != 1117 if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) !=
1127 old_dir->i_ino) 1118 old_dir->i_ino)
1128 goto end_rename; 1119 goto end_rename;
1129
1130 retval = -EMLINK;
1131 if (!new_inode && new_dir->i_nlink >= UDF_MAX_LINKS)
1132 goto end_rename;
1133 } 1120 }
1134 if (!nfi) { 1121 if (!nfi) {
1135 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, 1122 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
diff --git a/fs/udf/super.c b/fs/udf/super.c
index c09a84daaf50..85067b4c7e14 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -75,6 +75,8 @@
75 75
76#define UDF_DEFAULT_BLOCKSIZE 2048 76#define UDF_DEFAULT_BLOCKSIZE 2048
77 77
78enum { UDF_MAX_LINKS = 0xffff };
79
78/* These are the "meat" - everything else is stuffing */ 80/* These are the "meat" - everything else is stuffing */
79static int udf_fill_super(struct super_block *, void *, int); 81static int udf_fill_super(struct super_block *, void *, int);
80static void udf_put_super(struct super_block *); 82static void udf_put_super(struct super_block *);
@@ -2035,13 +2037,13 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2035 } 2037 }
2036 2038
2037 /* Allocate a dentry for the root inode */ 2039 /* Allocate a dentry for the root inode */
2038 sb->s_root = d_alloc_root(inode); 2040 sb->s_root = d_make_root(inode);
2039 if (!sb->s_root) { 2041 if (!sb->s_root) {
2040 udf_err(sb, "Couldn't allocate root dentry\n"); 2042 udf_err(sb, "Couldn't allocate root dentry\n");
2041 iput(inode);
2042 goto error_out; 2043 goto error_out;
2043 } 2044 }
2044 sb->s_maxbytes = MAX_LFS_FILESIZE; 2045 sb->s_maxbytes = MAX_LFS_FILESIZE;
2046 sb->s_max_links = UDF_MAX_LINKS;
2045 return 0; 2047 return 0;
2046 2048
2047error_out: 2049error_out:
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index 38cac199edff..a2281cadefa1 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -166,10 +166,6 @@ static int ufs_link (struct dentry * old_dentry, struct inode * dir,
166 int error; 166 int error;
167 167
168 lock_ufs(dir->i_sb); 168 lock_ufs(dir->i_sb);
169 if (inode->i_nlink >= UFS_LINK_MAX) {
170 unlock_ufs(dir->i_sb);
171 return -EMLINK;
172 }
173 169
174 inode->i_ctime = CURRENT_TIME_SEC; 170 inode->i_ctime = CURRENT_TIME_SEC;
175 inode_inc_link_count(inode); 171 inode_inc_link_count(inode);
@@ -183,10 +179,7 @@ static int ufs_link (struct dentry * old_dentry, struct inode * dir,
183static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode) 179static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
184{ 180{
185 struct inode * inode; 181 struct inode * inode;
186 int err = -EMLINK; 182 int err;
187
188 if (dir->i_nlink >= UFS_LINK_MAX)
189 goto out;
190 183
191 lock_ufs(dir->i_sb); 184 lock_ufs(dir->i_sb);
192 inode_inc_link_count(dir); 185 inode_inc_link_count(dir);
@@ -305,11 +298,6 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
305 drop_nlink(new_inode); 298 drop_nlink(new_inode);
306 inode_dec_link_count(new_inode); 299 inode_dec_link_count(new_inode);
307 } else { 300 } else {
308 if (dir_de) {
309 err = -EMLINK;
310 if (new_dir->i_nlink >= UFS_LINK_MAX)
311 goto out_dir;
312 }
313 err = ufs_add_link(new_dentry, old_inode); 301 err = ufs_add_link(new_dentry, old_inode);
314 if (err) 302 if (err)
315 goto out_dir; 303 goto out_dir;
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 5246ee3e5607..f636f6b460d0 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -1157,16 +1157,17 @@ magic_found:
1157 "fast symlink size (%u)\n", uspi->s_maxsymlinklen); 1157 "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
1158 uspi->s_maxsymlinklen = maxsymlen; 1158 uspi->s_maxsymlinklen = maxsymlen;
1159 } 1159 }
1160 sb->s_max_links = UFS_LINK_MAX;
1160 1161
1161 inode = ufs_iget(sb, UFS_ROOTINO); 1162 inode = ufs_iget(sb, UFS_ROOTINO);
1162 if (IS_ERR(inode)) { 1163 if (IS_ERR(inode)) {
1163 ret = PTR_ERR(inode); 1164 ret = PTR_ERR(inode);
1164 goto failed; 1165 goto failed;
1165 } 1166 }
1166 sb->s_root = d_alloc_root(inode); 1167 sb->s_root = d_make_root(inode);
1167 if (!sb->s_root) { 1168 if (!sb->s_root) {
1168 ret = -ENOMEM; 1169 ret = -ENOMEM;
1169 goto dalloc_failed; 1170 goto failed;
1170 } 1171 }
1171 1172
1172 ufs_setup_cstotal(sb); 1173 ufs_setup_cstotal(sb);
@@ -1180,8 +1181,6 @@ magic_found:
1180 UFSD("EXIT\n"); 1181 UFSD("EXIT\n");
1181 return 0; 1182 return 0;
1182 1183
1183dalloc_failed:
1184 iput(inode);
1185failed: 1184failed:
1186 if (ubh) 1185 if (ubh)
1187 ubh_brelse_uspi (uspi); 1186 ubh_brelse_uspi (uspi);
diff --git a/fs/xfs/xfs_rename.c b/fs/xfs/xfs_rename.c
index 866de277079a..e44ef7ee8ce8 100644
--- a/fs/xfs/xfs_rename.c
+++ b/fs/xfs/xfs_rename.c
@@ -118,17 +118,6 @@ xfs_rename(
118 new_parent = (src_dp != target_dp); 118 new_parent = (src_dp != target_dp);
119 src_is_directory = S_ISDIR(src_ip->i_d.di_mode); 119 src_is_directory = S_ISDIR(src_ip->i_d.di_mode);
120 120
121 if (src_is_directory) {
122 /*
123 * Check for link count overflow on target_dp
124 */
125 if (target_ip == NULL && new_parent &&
126 target_dp->i_d.di_nlink >= XFS_MAXLINK) {
127 error = XFS_ERROR(EMLINK);
128 goto std_return;
129 }
130 }
131
132 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, 121 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip,
133 inodes, &num_inodes); 122 inodes, &num_inodes);
134 123
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index ee5b695c99a7..baf40e378d35 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1341,6 +1341,7 @@ xfs_fs_fill_super(
1341 sb->s_blocksize = mp->m_sb.sb_blocksize; 1341 sb->s_blocksize = mp->m_sb.sb_blocksize;
1342 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; 1342 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1343 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); 1343 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1344 sb->s_max_links = XFS_MAXLINK;
1344 sb->s_time_gran = 1; 1345 sb->s_time_gran = 1;
1345 set_posix_acl_flag(sb); 1346 set_posix_acl_flag(sb);
1346 1347
@@ -1361,10 +1362,10 @@ xfs_fs_fill_super(
1361 error = EINVAL; 1362 error = EINVAL;
1362 goto out_syncd_stop; 1363 goto out_syncd_stop;
1363 } 1364 }
1364 sb->s_root = d_alloc_root(root); 1365 sb->s_root = d_make_root(root);
1365 if (!sb->s_root) { 1366 if (!sb->s_root) {
1366 error = ENOMEM; 1367 error = ENOMEM;
1367 goto out_iput; 1368 goto out_syncd_stop;
1368 } 1369 }
1369 1370
1370 return 0; 1371 return 0;
@@ -1383,8 +1384,6 @@ xfs_fs_fill_super(
1383 out: 1384 out:
1384 return -error; 1385 return -error;
1385 1386
1386 out_iput:
1387 iput(root);
1388 out_syncd_stop: 1387 out_syncd_stop:
1389 xfs_syncd_stop(mp); 1388 xfs_syncd_stop(mp);
1390 out_unmount: 1389 out_unmount:
diff --git a/fs/xfs/xfs_utils.c b/fs/xfs/xfs_utils.c
index 89dbb4a50872..79c05ac85bfe 100644
--- a/fs/xfs/xfs_utils.c
+++ b/fs/xfs/xfs_utils.c
@@ -296,8 +296,6 @@ xfs_bumplink(
296 xfs_trans_t *tp, 296 xfs_trans_t *tp,
297 xfs_inode_t *ip) 297 xfs_inode_t *ip)
298{ 298{
299 if (ip->i_d.di_nlink >= XFS_MAXLINK)
300 return XFS_ERROR(EMLINK);
301 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); 299 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
302 300
303 ASSERT(ip->i_d.di_nlink > 0); 301 ASSERT(ip->i_d.di_nlink > 0);
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index ebdb88840a47..64981d7e7375 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -917,14 +917,6 @@ xfs_create(
917 xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); 917 xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
918 unlock_dp_on_error = B_TRUE; 918 unlock_dp_on_error = B_TRUE;
919 919
920 /*
921 * Check for directory link count overflow.
922 */
923 if (is_dir && dp->i_d.di_nlink >= XFS_MAXLINK) {
924 error = XFS_ERROR(EMLINK);
925 goto out_trans_cancel;
926 }
927
928 xfs_bmap_init(&free_list, &first_block); 920 xfs_bmap_init(&free_list, &first_block);
929 921
930 /* 922 /*
@@ -1429,14 +1421,6 @@ xfs_link(
1429 xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); 1421 xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL);
1430 1422
1431 /* 1423 /*
1432 * If the source has too many links, we can't make any more to it.
1433 */
1434 if (sip->i_d.di_nlink >= XFS_MAXLINK) {
1435 error = XFS_ERROR(EMLINK);
1436 goto error_return;
1437 }
1438
1439 /*
1440 * If we are using project inheritance, we only allow hard link 1424 * If we are using project inheritance, we only allow hard link
1441 * creation in our tree when the project IDs are the same; else 1425 * creation in our tree when the project IDs are the same; else
1442 * the tree quota mechanism could be circumvented. 1426 * the tree quota mechanism could be circumvented.
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 9ff7a2c48b50..ed3ef1972496 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -684,7 +684,7 @@ extern void audit_log_untrustedstring(struct audit_buffer *ab,
684 const char *string); 684 const char *string);
685extern void audit_log_d_path(struct audit_buffer *ab, 685extern void audit_log_d_path(struct audit_buffer *ab,
686 const char *prefix, 686 const char *prefix,
687 struct path *path); 687 const struct path *path);
688extern void audit_log_key(struct audit_buffer *ab, 688extern void audit_log_key(struct audit_buffer *ab,
689 char *key); 689 char *key);
690extern void audit_log_lost(const char *message); 690extern void audit_log_lost(const char *message);
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 0092102db2de..366422bc1633 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -92,17 +92,17 @@ struct linux_binfmt {
92 unsigned long min_coredump; /* minimal dump size */ 92 unsigned long min_coredump; /* minimal dump size */
93}; 93};
94 94
95extern int __register_binfmt(struct linux_binfmt *fmt, int insert); 95extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
96 96
97/* Registration of default binfmt handlers */ 97/* Registration of default binfmt handlers */
98static inline int register_binfmt(struct linux_binfmt *fmt) 98static inline void register_binfmt(struct linux_binfmt *fmt)
99{ 99{
100 return __register_binfmt(fmt, 0); 100 __register_binfmt(fmt, 0);
101} 101}
102/* Same as above, but adds a new binfmt at the top of the list */ 102/* Same as above, but adds a new binfmt at the top of the list */
103static inline int insert_binfmt(struct linux_binfmt *fmt) 103static inline void insert_binfmt(struct linux_binfmt *fmt)
104{ 104{
105 return __register_binfmt(fmt, 1); 105 __register_binfmt(fmt, 1);
106} 106}
107 107
108extern void unregister_binfmt(struct linux_binfmt *); 108extern void unregister_binfmt(struct linux_binfmt *);
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index ff5f5256d175..7e11f1418203 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -222,7 +222,6 @@ extern void shrink_dcache_for_umount(struct super_block *);
222extern int d_invalidate(struct dentry *); 222extern int d_invalidate(struct dentry *);
223 223
224/* only used at mount-time */ 224/* only used at mount-time */
225extern struct dentry * d_alloc_root(struct inode *);
226extern struct dentry * d_make_root(struct inode *); 225extern struct dentry * d_make_root(struct inode *);
227 226
228/* <clickety>-<click> the ramfs-type tree */ 227/* <clickety>-<click> the ramfs-type tree */
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 6169c26fd8c8..ae36b72c22f3 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -86,7 +86,7 @@ struct dentry *debugfs_create_blob(const char *name, umode_t mode,
86 struct dentry *parent, 86 struct dentry *parent,
87 struct debugfs_blob_wrapper *blob); 87 struct debugfs_blob_wrapper *blob);
88 88
89struct dentry *debugfs_create_regset32(const char *name, mode_t mode, 89struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
90 struct dentry *parent, 90 struct dentry *parent,
91 struct debugfs_regset32 *regset); 91 struct debugfs_regset32 *regset);
92 92
@@ -208,7 +208,7 @@ static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
208} 208}
209 209
210static inline struct dentry *debugfs_create_regset32(const char *name, 210static inline struct dentry *debugfs_create_regset32(const char *name,
211 mode_t mode, struct dentry *parent, 211 umode_t mode, struct dentry *parent,
212 struct debugfs_regset32 *regset) 212 struct debugfs_regset32 *regset)
213{ 213{
214 return ERR_PTR(-ENODEV); 214 return ERR_PTR(-ENODEV);
diff --git a/include/linux/file.h b/include/linux/file.h
index 21a79958541c..58bf158c53d9 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -12,7 +12,6 @@
12struct file; 12struct file;
13 13
14extern void fput(struct file *); 14extern void fput(struct file *);
15extern void drop_file_write_access(struct file *file);
16 15
17struct file_operations; 16struct file_operations;
18struct vfsmount; 17struct vfsmount;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 69cd5bb640f5..9bbe1a9ac432 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1459,6 +1459,7 @@ struct super_block {
1459 u8 s_uuid[16]; /* UUID */ 1459 u8 s_uuid[16]; /* UUID */
1460 1460
1461 void *s_fs_info; /* Filesystem private info */ 1461 void *s_fs_info; /* Filesystem private info */
1462 unsigned int s_max_links;
1462 fmode_t s_mode; 1463 fmode_t s_mode;
1463 1464
1464 /* Granularity of c/m/atime in ns. 1465 /* Granularity of c/m/atime in ns.
@@ -1811,11 +1812,11 @@ static inline void inode_inc_iversion(struct inode *inode)
1811 spin_unlock(&inode->i_lock); 1812 spin_unlock(&inode->i_lock);
1812} 1813}
1813 1814
1814extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); 1815extern void touch_atime(struct path *);
1815static inline void file_accessed(struct file *file) 1816static inline void file_accessed(struct file *file)
1816{ 1817{
1817 if (!(file->f_flags & O_NOATIME)) 1818 if (!(file->f_flags & O_NOATIME))
1818 touch_atime(file->f_path.mnt, file->f_path.dentry); 1819 touch_atime(&file->f_path);
1819} 1820}
1820 1821
1821int sync_inode(struct inode *inode, struct writeback_control *wbc); 1822int sync_inode(struct inode *inode, struct writeback_control *wbc);
@@ -2304,7 +2305,10 @@ extern struct inode * igrab(struct inode *);
2304extern ino_t iunique(struct super_block *, ino_t); 2305extern ino_t iunique(struct super_block *, ino_t);
2305extern int inode_needs_sync(struct inode *inode); 2306extern int inode_needs_sync(struct inode *inode);
2306extern int generic_delete_inode(struct inode *inode); 2307extern int generic_delete_inode(struct inode *inode);
2307extern int generic_drop_inode(struct inode *inode); 2308static inline int generic_drop_inode(struct inode *inode)
2309{
2310 return !inode->i_nlink || inode_unhashed(inode);
2311}
2308 2312
2309extern struct inode *ilookup5_nowait(struct super_block *sb, 2313extern struct inode *ilookup5_nowait(struct super_block *sb,
2310 unsigned long hashval, int (*test)(struct inode *, void *), 2314 unsigned long hashval, int (*test)(struct inode *, void *),
diff --git a/include/linux/magic.h b/include/linux/magic.h
index 2d4beab0d5b7..b7ed4759dbb2 100644
--- a/include/linux/magic.h
+++ b/include/linux/magic.h
@@ -42,6 +42,7 @@
42#define OPENPROM_SUPER_MAGIC 0x9fa1 42#define OPENPROM_SUPER_MAGIC 0x9fa1
43#define PROC_SUPER_MAGIC 0x9fa0 43#define PROC_SUPER_MAGIC 0x9fa0
44#define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */ 44#define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */
45#define QNX6_SUPER_MAGIC 0x68191122 /* qnx6 fs detection */
45 46
46#define REISERFS_SUPER_MAGIC 0x52654973 /* used by gcc */ 47#define REISERFS_SUPER_MAGIC 0x52654973 /* used by gcc */
47 /* used by file system utilities that 48 /* used by file system utilities that
diff --git a/include/linux/qnx6_fs.h b/include/linux/qnx6_fs.h
new file mode 100644
index 000000000000..26049eab9010
--- /dev/null
+++ b/include/linux/qnx6_fs.h
@@ -0,0 +1,134 @@
1/*
2 * Name : qnx6_fs.h
3 * Author : Kai Bankett
4 * Function : qnx6 global filesystem definitions
5 * History : 17-01-2012 created
6 */
7#ifndef _LINUX_QNX6_FS_H
8#define _LINUX_QNX6_FS_H
9
10#include <linux/types.h>
11#include <linux/magic.h>
12
13#define QNX6_ROOT_INO 1
14
15/* for di_status */
16#define QNX6_FILE_DIRECTORY 0x01
17#define QNX6_FILE_DELETED 0x02
18#define QNX6_FILE_NORMAL 0x03
19
20#define QNX6_SUPERBLOCK_SIZE 0x200 /* superblock always is 512 bytes */
21#define QNX6_SUPERBLOCK_AREA 0x1000 /* area reserved for superblock */
22#define QNX6_BOOTBLOCK_SIZE 0x2000 /* heading bootblock area */
23#define QNX6_DIR_ENTRY_SIZE 0x20 /* dir entry size of 32 bytes */
24#define QNX6_INODE_SIZE 0x80 /* each inode is 128 bytes */
25#define QNX6_INODE_SIZE_BITS 7 /* inode entry size shift */
26
27#define QNX6_NO_DIRECT_POINTERS 16 /* 16 blockptrs in sbl/inode */
28#define QNX6_PTR_MAX_LEVELS 5 /* maximum indirect levels */
29
30/* for filenames */
31#define QNX6_SHORT_NAME_MAX 27
32#define QNX6_LONG_NAME_MAX 510
33
34/* list of mount options */
35#define QNX6_MOUNT_MMI_FS 0x010000 /* mount as Audi MMI 3G fs */
36
37/*
38 * This is the original qnx6 inode layout on disk.
39 * Each inode is 128 byte long.
40 */
41struct qnx6_inode_entry {
42 __fs64 di_size;
43 __fs32 di_uid;
44 __fs32 di_gid;
45 __fs32 di_ftime;
46 __fs32 di_mtime;
47 __fs32 di_atime;
48 __fs32 di_ctime;
49 __fs16 di_mode;
50 __fs16 di_ext_mode;
51 __fs32 di_block_ptr[QNX6_NO_DIRECT_POINTERS];
52 __u8 di_filelevels;
53 __u8 di_status;
54 __u8 di_unknown2[2];
55 __fs32 di_zero2[6];
56};
57
58/*
59 * Each directory entry is maximum 32 bytes long.
60 * If more characters or special characters required it is stored
61 * in the longfilenames structure.
62 */
63struct qnx6_dir_entry {
64 __fs32 de_inode;
65 __u8 de_size;
66 char de_fname[QNX6_SHORT_NAME_MAX];
67};
68
69/*
70 * Longfilename direntries have a different structure
71 */
72struct qnx6_long_dir_entry {
73 __fs32 de_inode;
74 __u8 de_size;
75 __u8 de_unknown[3];
76 __fs32 de_long_inode;
77 __fs32 de_checksum;
78};
79
80struct qnx6_long_filename {
81 __fs16 lf_size;
82 __u8 lf_fname[QNX6_LONG_NAME_MAX];
83};
84
85struct qnx6_root_node {
86 __fs64 size;
87 __fs32 ptr[QNX6_NO_DIRECT_POINTERS];
88 __u8 levels;
89 __u8 mode;
90 __u8 spare[6];
91};
92
93struct qnx6_super_block {
94 __fs32 sb_magic;
95 __fs32 sb_checksum;
96 __fs64 sb_serial;
97 __fs32 sb_ctime; /* time the fs was created */
98 __fs32 sb_atime; /* last access time */
99 __fs32 sb_flags;
100 __fs16 sb_version1; /* filesystem version information */
101 __fs16 sb_version2; /* filesystem version information */
102 __u8 sb_volumeid[16];
103 __fs32 sb_blocksize;
104 __fs32 sb_num_inodes;
105 __fs32 sb_free_inodes;
106 __fs32 sb_num_blocks;
107 __fs32 sb_free_blocks;
108 __fs32 sb_allocgroup;
109 struct qnx6_root_node Inode;
110 struct qnx6_root_node Bitmap;
111 struct qnx6_root_node Longfile;
112 struct qnx6_root_node Unknown;
113};
114
115/* Audi MMI 3G superblock layout is different to plain qnx6 */
116struct qnx6_mmi_super_block {
117 __fs32 sb_magic;
118 __fs32 sb_checksum;
119 __fs64 sb_serial;
120 __u8 sb_spare0[12];
121 __u8 sb_id[12];
122 __fs32 sb_blocksize;
123 __fs32 sb_num_inodes;
124 __fs32 sb_free_inodes;
125 __fs32 sb_num_blocks;
126 __fs32 sb_free_blocks;
127 __u8 sb_spare1[4];
128 struct qnx6_root_node Inode;
129 struct qnx6_root_node Bitmap;
130 struct qnx6_root_node Longfile;
131 struct qnx6_root_node Unknown;
132};
133
134#endif
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 2213ddcce20c..ea3700cd7367 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -1,32 +1,12 @@
1/* 1/*
2 * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details 2 * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
3 */ 3 */
4
5 /* this file has an amazingly stupid
6 name, yura please fix it to be
7 reiserfs.h, and merge all the rest
8 of our .h files that are in this
9 directory into it. */
10
11#ifndef _LINUX_REISER_FS_H 4#ifndef _LINUX_REISER_FS_H
12#define _LINUX_REISER_FS_H 5#define _LINUX_REISER_FS_H
13 6
14#include <linux/types.h> 7#include <linux/types.h>
15#include <linux/magic.h> 8#include <linux/magic.h>
16 9
17#ifdef __KERNEL__
18#include <linux/slab.h>
19#include <linux/interrupt.h>
20#include <linux/sched.h>
21#include <linux/workqueue.h>
22#include <asm/unaligned.h>
23#include <linux/bitops.h>
24#include <linux/proc_fs.h>
25#include <linux/buffer_head.h>
26#include <linux/reiserfs_fs_i.h>
27#include <linux/reiserfs_fs_sb.h>
28#endif
29
30/* 10/*
31 * include/linux/reiser_fs.h 11 * include/linux/reiser_fs.h
32 * 12 *
@@ -43,2318 +23,4 @@
43#define REISERFS_IOC_GETVERSION FS_IOC_GETVERSION 23#define REISERFS_IOC_GETVERSION FS_IOC_GETVERSION
44#define REISERFS_IOC_SETVERSION FS_IOC_SETVERSION 24#define REISERFS_IOC_SETVERSION FS_IOC_SETVERSION
45 25
46#ifdef __KERNEL__
47/* the 32 bit compat definitions with int argument */
48#define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int)
49#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
50#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
51#define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION
52#define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION
53
54/*
55 * Locking primitives. The write lock is a per superblock
56 * special mutex that has properties close to the Big Kernel Lock
57 * which was used in the previous locking scheme.
58 */
59void reiserfs_write_lock(struct super_block *s);
60void reiserfs_write_unlock(struct super_block *s);
61int reiserfs_write_lock_once(struct super_block *s);
62void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
63
64#ifdef CONFIG_REISERFS_CHECK
65void reiserfs_lock_check_recursive(struct super_block *s);
66#else
67static inline void reiserfs_lock_check_recursive(struct super_block *s) { }
68#endif
69
70/*
71 * Several mutexes depend on the write lock.
72 * However sometimes we want to relax the write lock while we hold
73 * these mutexes, according to the release/reacquire on schedule()
74 * properties of the Bkl that were used.
75 * Reiserfs performances and locking were based on this scheme.
76 * Now that the write lock is a mutex and not the bkl anymore, doing so
77 * may result in a deadlock:
78 *
79 * A acquire write_lock
80 * A acquire j_commit_mutex
81 * A release write_lock and wait for something
82 * B acquire write_lock
83 * B can't acquire j_commit_mutex and sleep
84 * A can't acquire write lock anymore
85 * deadlock
86 *
87 * What we do here is avoiding such deadlock by playing the same game
88 * than the Bkl: if we can't acquire a mutex that depends on the write lock,
89 * we release the write lock, wait a bit and then retry.
90 *
91 * The mutexes concerned by this hack are:
92 * - The commit mutex of a journal list
93 * - The flush mutex
94 * - The journal lock
95 * - The inode mutex
96 */
97static inline void reiserfs_mutex_lock_safe(struct mutex *m,
98 struct super_block *s)
99{
100 reiserfs_lock_check_recursive(s);
101 reiserfs_write_unlock(s);
102 mutex_lock(m);
103 reiserfs_write_lock(s);
104}
105
106static inline void
107reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
108 struct super_block *s)
109{
110 reiserfs_lock_check_recursive(s);
111 reiserfs_write_unlock(s);
112 mutex_lock_nested(m, subclass);
113 reiserfs_write_lock(s);
114}
115
116static inline void
117reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)
118{
119 reiserfs_lock_check_recursive(s);
120 reiserfs_write_unlock(s);
121 down_read(sem);
122 reiserfs_write_lock(s);
123}
124
125/*
126 * When we schedule, we usually want to also release the write lock,
127 * according to the previous bkl based locking scheme of reiserfs.
128 */
129static inline void reiserfs_cond_resched(struct super_block *s)
130{
131 if (need_resched()) {
132 reiserfs_write_unlock(s);
133 schedule();
134 reiserfs_write_lock(s);
135 }
136}
137
138struct fid;
139
140/* in reading the #defines, it may help to understand that they employ
141 the following abbreviations:
142
143 B = Buffer
144 I = Item header
145 H = Height within the tree (should be changed to LEV)
146 N = Number of the item in the node
147 STAT = stat data
148 DEH = Directory Entry Header
149 EC = Entry Count
150 E = Entry number
151 UL = Unsigned Long
152 BLKH = BLocK Header
153 UNFM = UNForMatted node
154 DC = Disk Child
155 P = Path
156
157 These #defines are named by concatenating these abbreviations,
158 where first comes the arguments, and last comes the return value,
159 of the macro.
160
161*/
162
163#define USE_INODE_GENERATION_COUNTER
164
165#define REISERFS_PREALLOCATE
166#define DISPLACE_NEW_PACKING_LOCALITIES
167#define PREALLOCATION_SIZE 9
168
169/* n must be power of 2 */
170#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u))
171
172// to be ok for alpha and others we have to align structures to 8 byte
173// boundary.
174// FIXME: do not change 4 by anything else: there is code which relies on that
175#define ROUND_UP(x) _ROUND_UP(x,8LL)
176
177/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug
178** messages.
179*/
180#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */
181
182void __reiserfs_warning(struct super_block *s, const char *id,
183 const char *func, const char *fmt, ...);
184#define reiserfs_warning(s, id, fmt, args...) \
185 __reiserfs_warning(s, id, __func__, fmt, ##args)
186/* assertions handling */
187
188/** always check a condition and panic if it's false. */
189#define __RASSERT(cond, scond, format, args...) \
190do { \
191 if (!(cond)) \
192 reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \
193 __FILE__ ":%i:%s: " format "\n", \
194 in_interrupt() ? -1 : task_pid_nr(current), \
195 __LINE__, __func__ , ##args); \
196} while (0)
197
198#define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args)
199
200#if defined( CONFIG_REISERFS_CHECK )
201#define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args)
202#else
203#define RFALSE( cond, format, args... ) do {;} while( 0 )
204#endif
205
206#define CONSTF __attribute_const__
207/*
208 * Disk Data Structures
209 */
210
211/***************************************************************************/
212/* SUPER BLOCK */
213/***************************************************************************/
214
215/*
216 * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs
217 * the version in RAM is part of a larger structure containing fields never written to disk.
218 */
219#define UNSET_HASH 0 // read_super will guess about, what hash names
220 // in directories were sorted with
221#define TEA_HASH 1
222#define YURA_HASH 2
223#define R5_HASH 3
224#define DEFAULT_HASH R5_HASH
225
226struct journal_params {
227 __le32 jp_journal_1st_block; /* where does journal start from on its
228 * device */
229 __le32 jp_journal_dev; /* journal device st_rdev */
230 __le32 jp_journal_size; /* size of the journal */
231 __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */
232 __le32 jp_journal_magic; /* random value made on fs creation (this
233 * was sb_journal_block_count) */
234 __le32 jp_journal_max_batch; /* max number of blocks to batch into a
235 * trans */
236 __le32 jp_journal_max_commit_age; /* in seconds, how old can an async
237 * commit be */
238 __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction
239 * be */
240};
241
242/* this is the super from 3.5.X, where X >= 10 */
243struct reiserfs_super_block_v1 {
244 __le32 s_block_count; /* blocks count */
245 __le32 s_free_blocks; /* free blocks count */
246 __le32 s_root_block; /* root block number */
247 struct journal_params s_journal;
248 __le16 s_blocksize; /* block size */
249 __le16 s_oid_maxsize; /* max size of object id array, see
250 * get_objectid() commentary */
251 __le16 s_oid_cursize; /* current size of object id array */
252 __le16 s_umount_state; /* this is set to 1 when filesystem was
253 * umounted, to 2 - when not */
254 char s_magic[10]; /* reiserfs magic string indicates that
255 * file system is reiserfs:
256 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
257 __le16 s_fs_state; /* it is set to used by fsck to mark which
258 * phase of rebuilding is done */
259 __le32 s_hash_function_code; /* indicate, what hash function is being use
260 * to sort names in a directory*/
261 __le16 s_tree_height; /* height of disk tree */
262 __le16 s_bmap_nr; /* amount of bitmap blocks needed to address
263 * each block of file system */
264 __le16 s_version; /* this field is only reliable on filesystem
265 * with non-standard journal */
266 __le16 s_reserved_for_journal; /* size in blocks of journal area on main
267 * device, we need to keep after
268 * making fs with non-standard journal */
269} __attribute__ ((__packed__));
270
271#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
272
273/* this is the on disk super block */
274struct reiserfs_super_block {
275 struct reiserfs_super_block_v1 s_v1;
276 __le32 s_inode_generation;
277 __le32 s_flags; /* Right now used only by inode-attributes, if enabled */
278 unsigned char s_uuid[16]; /* filesystem unique identifier */
279 unsigned char s_label[16]; /* filesystem volume label */
280 __le16 s_mnt_count; /* Count of mounts since last fsck */
281 __le16 s_max_mnt_count; /* Maximum mounts before check */
282 __le32 s_lastcheck; /* Timestamp of last fsck */
283 __le32 s_check_interval; /* Interval between checks */
284 char s_unused[76]; /* zero filled by mkreiserfs and
285 * reiserfs_convert_objectid_map_v1()
286 * so any additions must be updated
287 * there as well. */
288} __attribute__ ((__packed__));
289
290#define SB_SIZE (sizeof(struct reiserfs_super_block))
291
292#define REISERFS_VERSION_1 0
293#define REISERFS_VERSION_2 2
294
295// on-disk super block fields converted to cpu form
296#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)
297#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))
298#define SB_BLOCKSIZE(s) \
299 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize))
300#define SB_BLOCK_COUNT(s) \
301 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count))
302#define SB_FREE_BLOCKS(s) \
303 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks))
304#define SB_REISERFS_MAGIC(s) \
305 (SB_V1_DISK_SUPER_BLOCK(s)->s_magic)
306#define SB_ROOT_BLOCK(s) \
307 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block))
308#define SB_TREE_HEIGHT(s) \
309 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height))
310#define SB_REISERFS_STATE(s) \
311 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state))
312#define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version))
313#define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr))
314
315#define PUT_SB_BLOCK_COUNT(s, val) \
316 do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)
317#define PUT_SB_FREE_BLOCKS(s, val) \
318 do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)
319#define PUT_SB_ROOT_BLOCK(s, val) \
320 do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)
321#define PUT_SB_TREE_HEIGHT(s, val) \
322 do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)
323#define PUT_SB_REISERFS_STATE(s, val) \
324 do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)
325#define PUT_SB_VERSION(s, val) \
326 do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)
327#define PUT_SB_BMAP_NR(s, val) \
328 do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)
329
330#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)
331#define SB_ONDISK_JOURNAL_SIZE(s) \
332 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))
333#define SB_ONDISK_JOURNAL_1st_BLOCK(s) \
334 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block))
335#define SB_ONDISK_JOURNAL_DEVICE(s) \
336 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev))
337#define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \
338 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal))
339
340#define is_block_in_log_or_reserved_area(s, block) \
341 block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \
342 && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \
343 ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
344 SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
345
346int is_reiserfs_3_5(struct reiserfs_super_block *rs);
347int is_reiserfs_3_6(struct reiserfs_super_block *rs);
348int is_reiserfs_jr(struct reiserfs_super_block *rs);
349
350/* ReiserFS leaves the first 64k unused, so that partition labels have
351 enough space. If someone wants to write a fancy bootloader that
352 needs more than 64k, let us know, and this will be increased in size.
353 This number must be larger than than the largest block size on any
354 platform, or code will break. -Hans */
355#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
356#define REISERFS_FIRST_BLOCK unused_define
357#define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES
358
359/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
360#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
361
362/* reiserfs internal error code (used by search_by_key and fix_nodes)) */
363#define CARRY_ON 0
364#define REPEAT_SEARCH -1
365#define IO_ERROR -2
366#define NO_DISK_SPACE -3
367#define NO_BALANCING_NEEDED (-4)
368#define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5)
369#define QUOTA_EXCEEDED -6
370
371typedef __u32 b_blocknr_t;
372typedef __le32 unp_t;
373
374struct unfm_nodeinfo {
375 unp_t unfm_nodenum;
376 unsigned short unfm_freespace;
377};
378
379/* there are two formats of keys: 3.5 and 3.6
380 */
381#define KEY_FORMAT_3_5 0
382#define KEY_FORMAT_3_6 1
383
384/* there are two stat datas */
385#define STAT_DATA_V1 0
386#define STAT_DATA_V2 1
387
388static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)
389{
390 return container_of(inode, struct reiserfs_inode_info, vfs_inode);
391}
392
393static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
394{
395 return sb->s_fs_info;
396}
397
398/* Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16
399 * which overflows on large file systems. */
400static inline __u32 reiserfs_bmap_count(struct super_block *sb)
401{
402 return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;
403}
404
405static inline int bmap_would_wrap(unsigned bmap_nr)
406{
407 return bmap_nr > ((1LL << 16) - 1);
408}
409
410/** this says about version of key of all items (but stat data) the
411 object consists of */
412#define get_inode_item_key_version( inode ) \
413 ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5)
414
415#define set_inode_item_key_version( inode, version ) \
416 ({ if((version)==KEY_FORMAT_3_6) \
417 REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \
418 else \
419 REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; })
420
421#define get_inode_sd_version(inode) \
422 ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1)
423
424#define set_inode_sd_version(inode, version) \
425 ({ if((version)==STAT_DATA_V2) \
426 REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \
427 else \
428 REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; })
429
430/* This is an aggressive tail suppression policy, I am hoping it
431 improves our benchmarks. The principle behind it is that percentage
432 space saving is what matters, not absolute space saving. This is
433 non-intuitive, but it helps to understand it if you consider that the
434 cost to access 4 blocks is not much more than the cost to access 1
435 block, if you have to do a seek and rotate. A tail risks a
436 non-linear disk access that is significant as a percentage of total
437 time cost for a 4 block file and saves an amount of space that is
438 less significant as a percentage of space, or so goes the hypothesis.
439 -Hans */
440#define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \
441(\
442 (!(n_tail_size)) || \
443 (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \
444 ( (n_file_size) >= (n_block_size) * 4 ) || \
445 ( ( (n_file_size) >= (n_block_size) * 3 ) && \
446 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \
447 ( ( (n_file_size) >= (n_block_size) * 2 ) && \
448 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \
449 ( ( (n_file_size) >= (n_block_size) ) && \
450 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \
451)
452
453/* Another strategy for tails, this one means only create a tail if all the
454 file would fit into one DIRECT item.
455 Primary intention for this one is to increase performance by decreasing
456 seeking.
457*/
458#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \
459(\
460 (!(n_tail_size)) || \
461 (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \
462)
463
464/*
465 * values for s_umount_state field
466 */
467#define REISERFS_VALID_FS 1
468#define REISERFS_ERROR_FS 2
469
470//
471// there are 5 item types currently
472//
473#define TYPE_STAT_DATA 0
474#define TYPE_INDIRECT 1
475#define TYPE_DIRECT 2
476#define TYPE_DIRENTRY 3
477#define TYPE_MAXTYPE 3
478#define TYPE_ANY 15 // FIXME: comment is required
479
480/***************************************************************************/
481/* KEY & ITEM HEAD */
482/***************************************************************************/
483
484//
485// directories use this key as well as old files
486//
487struct offset_v1 {
488 __le32 k_offset;
489 __le32 k_uniqueness;
490} __attribute__ ((__packed__));
491
492struct offset_v2 {
493 __le64 v;
494} __attribute__ ((__packed__));
495
496static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)
497{
498 __u8 type = le64_to_cpu(v2->v) >> 60;
499 return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;
500}
501
502static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)
503{
504 v2->v =
505 (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);
506}
507
508static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)
509{
510 return le64_to_cpu(v2->v) & (~0ULL >> 4);
511}
512
513static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)
514{
515 offset &= (~0ULL >> 4);
516 v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);
517}
518
519/* Key of an item determines its location in the S+tree, and
520 is composed of 4 components */
521struct reiserfs_key {
522 __le32 k_dir_id; /* packing locality: by default parent
523 directory object id */
524 __le32 k_objectid; /* object identifier */
525 union {
526 struct offset_v1 k_offset_v1;
527 struct offset_v2 k_offset_v2;
528 } __attribute__ ((__packed__)) u;
529} __attribute__ ((__packed__));
530
531struct in_core_key {
532 __u32 k_dir_id; /* packing locality: by default parent
533 directory object id */
534 __u32 k_objectid; /* object identifier */
535 __u64 k_offset;
536 __u8 k_type;
537};
538
539struct cpu_key {
540 struct in_core_key on_disk_key;
541 int version;
542 int key_length; /* 3 in all cases but direct2indirect and
543 indirect2direct conversion */
544};
545
546/* Our function for comparing keys can compare keys of different
547 lengths. It takes as a parameter the length of the keys it is to
548 compare. These defines are used in determining what is to be passed
549 to it as that parameter. */
550#define REISERFS_FULL_KEY_LEN 4
551#define REISERFS_SHORT_KEY_LEN 2
552
553/* The result of the key compare */
554#define FIRST_GREATER 1
555#define SECOND_GREATER -1
556#define KEYS_IDENTICAL 0
557#define KEY_FOUND 1
558#define KEY_NOT_FOUND 0
559
560#define KEY_SIZE (sizeof(struct reiserfs_key))
561#define SHORT_KEY_SIZE (sizeof (__u32) + sizeof (__u32))
562
563/* return values for search_by_key and clones */
564#define ITEM_FOUND 1
565#define ITEM_NOT_FOUND 0
566#define ENTRY_FOUND 1
567#define ENTRY_NOT_FOUND 0
568#define DIRECTORY_NOT_FOUND -1
569#define REGULAR_FILE_FOUND -2
570#define DIRECTORY_FOUND -3
571#define BYTE_FOUND 1
572#define BYTE_NOT_FOUND 0
573#define FILE_NOT_FOUND -1
574
575#define POSITION_FOUND 1
576#define POSITION_NOT_FOUND 0
577
578// return values for reiserfs_find_entry and search_by_entry_key
579#define NAME_FOUND 1
580#define NAME_NOT_FOUND 0
581#define GOTO_PREVIOUS_ITEM 2
582#define NAME_FOUND_INVISIBLE 3
583
584/* Everything in the filesystem is stored as a set of items. The
585 item head contains the key of the item, its free space (for
586 indirect items) and specifies the location of the item itself
587 within the block. */
588
589struct item_head {
590 /* Everything in the tree is found by searching for it based on
591 * its key.*/
592 struct reiserfs_key ih_key;
593 union {
594 /* The free space in the last unformatted node of an
595 indirect item if this is an indirect item. This
596 equals 0xFFFF iff this is a direct item or stat data
597 item. Note that the key, not this field, is used to
598 determine the item type, and thus which field this
599 union contains. */
600 __le16 ih_free_space_reserved;
601 /* Iff this is a directory item, this field equals the
602 number of directory entries in the directory item. */
603 __le16 ih_entry_count;
604 } __attribute__ ((__packed__)) u;
605 __le16 ih_item_len; /* total size of the item body */
606 __le16 ih_item_location; /* an offset to the item body
607 * within the block */
608 __le16 ih_version; /* 0 for all old items, 2 for new
609 ones. Highest bit is set by fsck
610 temporary, cleaned after all
611 done */
612} __attribute__ ((__packed__));
613/* size of item header */
614#define IH_SIZE (sizeof(struct item_head))
615
616#define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved)
617#define ih_version(ih) le16_to_cpu((ih)->ih_version)
618#define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count)
619#define ih_location(ih) le16_to_cpu((ih)->ih_item_location)
620#define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len)
621
622#define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0)
623#define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0)
624#define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0)
625#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)
626#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)
627
628#define unreachable_item(ih) (ih_version(ih) & (1 << 15))
629
630#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))
631#define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val)))
632
633/* these operate on indirect items, where you've got an array of ints
634** at a possibly unaligned location. These are a noop on ia32
635**
636** p is the array of __u32, i is the index into the array, v is the value
637** to store there.
638*/
639#define get_block_num(p, i) get_unaligned_le32((p) + (i))
640#define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i))
641
642//
643// in old version uniqueness field shows key type
644//
645#define V1_SD_UNIQUENESS 0
646#define V1_INDIRECT_UNIQUENESS 0xfffffffe
647#define V1_DIRECT_UNIQUENESS 0xffffffff
648#define V1_DIRENTRY_UNIQUENESS 500
649#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required
650
651//
652// here are conversion routines
653//
654static inline int uniqueness2type(__u32 uniqueness) CONSTF;
655static inline int uniqueness2type(__u32 uniqueness)
656{
657 switch ((int)uniqueness) {
658 case V1_SD_UNIQUENESS:
659 return TYPE_STAT_DATA;
660 case V1_INDIRECT_UNIQUENESS:
661 return TYPE_INDIRECT;
662 case V1_DIRECT_UNIQUENESS:
663 return TYPE_DIRECT;
664 case V1_DIRENTRY_UNIQUENESS:
665 return TYPE_DIRENTRY;
666 case V1_ANY_UNIQUENESS:
667 default:
668 return TYPE_ANY;
669 }
670}
671
672static inline __u32 type2uniqueness(int type) CONSTF;
673static inline __u32 type2uniqueness(int type)
674{
675 switch (type) {
676 case TYPE_STAT_DATA:
677 return V1_SD_UNIQUENESS;
678 case TYPE_INDIRECT:
679 return V1_INDIRECT_UNIQUENESS;
680 case TYPE_DIRECT:
681 return V1_DIRECT_UNIQUENESS;
682 case TYPE_DIRENTRY:
683 return V1_DIRENTRY_UNIQUENESS;
684 case TYPE_ANY:
685 default:
686 return V1_ANY_UNIQUENESS;
687 }
688}
689
690//
691// key is pointer to on disk key which is stored in le, result is cpu,
692// there is no way to get version of object from key, so, provide
693// version to these defines
694//
695static inline loff_t le_key_k_offset(int version,
696 const struct reiserfs_key *key)
697{
698 return (version == KEY_FORMAT_3_5) ?
699 le32_to_cpu(key->u.k_offset_v1.k_offset) :
700 offset_v2_k_offset(&(key->u.k_offset_v2));
701}
702
703static inline loff_t le_ih_k_offset(const struct item_head *ih)
704{
705 return le_key_k_offset(ih_version(ih), &(ih->ih_key));
706}
707
708static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)
709{
710 return (version == KEY_FORMAT_3_5) ?
711 uniqueness2type(le32_to_cpu(key->u.k_offset_v1.k_uniqueness)) :
712 offset_v2_k_type(&(key->u.k_offset_v2));
713}
714
715static inline loff_t le_ih_k_type(const struct item_head *ih)
716{
717 return le_key_k_type(ih_version(ih), &(ih->ih_key));
718}
719
720static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,
721 loff_t offset)
722{
723 (version == KEY_FORMAT_3_5) ? (void)(key->u.k_offset_v1.k_offset = cpu_to_le32(offset)) : /* jdm check */
724 (void)(set_offset_v2_k_offset(&(key->u.k_offset_v2), offset));
725}
726
727static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)
728{
729 set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);
730}
731
732static inline void set_le_key_k_type(int version, struct reiserfs_key *key,
733 int type)
734{
735 (version == KEY_FORMAT_3_5) ?
736 (void)(key->u.k_offset_v1.k_uniqueness =
737 cpu_to_le32(type2uniqueness(type)))
738 : (void)(set_offset_v2_k_type(&(key->u.k_offset_v2), type));
739}
740
741static inline void set_le_ih_k_type(struct item_head *ih, int type)
742{
743 set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);
744}
745
746static inline int is_direntry_le_key(int version, struct reiserfs_key *key)
747{
748 return le_key_k_type(version, key) == TYPE_DIRENTRY;
749}
750
751static inline int is_direct_le_key(int version, struct reiserfs_key *key)
752{
753 return le_key_k_type(version, key) == TYPE_DIRECT;
754}
755
756static inline int is_indirect_le_key(int version, struct reiserfs_key *key)
757{
758 return le_key_k_type(version, key) == TYPE_INDIRECT;
759}
760
761static inline int is_statdata_le_key(int version, struct reiserfs_key *key)
762{
763 return le_key_k_type(version, key) == TYPE_STAT_DATA;
764}
765
766//
767// item header has version.
768//
769static inline int is_direntry_le_ih(struct item_head *ih)
770{
771 return is_direntry_le_key(ih_version(ih), &ih->ih_key);
772}
773
774static inline int is_direct_le_ih(struct item_head *ih)
775{
776 return is_direct_le_key(ih_version(ih), &ih->ih_key);
777}
778
779static inline int is_indirect_le_ih(struct item_head *ih)
780{
781 return is_indirect_le_key(ih_version(ih), &ih->ih_key);
782}
783
784static inline int is_statdata_le_ih(struct item_head *ih)
785{
786 return is_statdata_le_key(ih_version(ih), &ih->ih_key);
787}
788
789//
790// key is pointer to cpu key, result is cpu
791//
792static inline loff_t cpu_key_k_offset(const struct cpu_key *key)
793{
794 return key->on_disk_key.k_offset;
795}
796
797static inline loff_t cpu_key_k_type(const struct cpu_key *key)
798{
799 return key->on_disk_key.k_type;
800}
801
802static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)
803{
804 key->on_disk_key.k_offset = offset;
805}
806
807static inline void set_cpu_key_k_type(struct cpu_key *key, int type)
808{
809 key->on_disk_key.k_type = type;
810}
811
812static inline void cpu_key_k_offset_dec(struct cpu_key *key)
813{
814 key->on_disk_key.k_offset--;
815}
816
817#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)
818#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)
819#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)
820#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)
821
822/* are these used ? */
823#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))
824#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))
825#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))
826#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))
827
828#define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \
829 (!COMP_SHORT_KEYS(ih, key) && \
830 I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize))
831
832/* maximal length of item */
833#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)
834#define MIN_ITEM_LEN 1
835
836/* object identifier for root dir */
837#define REISERFS_ROOT_OBJECTID 2
838#define REISERFS_ROOT_PARENT_OBJECTID 1
839
840extern struct reiserfs_key root_key;
841
842/*
843 * Picture represents a leaf of the S+tree
844 * ______________________________________________________
845 * | | Array of | | |
846 * |Block | Object-Item | F r e e | Objects- |
847 * | head | Headers | S p a c e | Items |
848 * |______|_______________|___________________|___________|
849 */
850
851/* Header of a disk block. More precisely, header of a formatted leaf
852 or internal node, and not the header of an unformatted node. */
853struct block_head {
854 __le16 blk_level; /* Level of a block in the tree. */
855 __le16 blk_nr_item; /* Number of keys/items in a block. */
856 __le16 blk_free_space; /* Block free space in bytes. */
857 __le16 blk_reserved;
858 /* dump this in v4/planA */
859 struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */
860};
861
862#define BLKH_SIZE (sizeof(struct block_head))
863#define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level))
864#define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item))
865#define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space))
866#define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved))
867#define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val))
868#define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val))
869#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))
870#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))
871#define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key)
872#define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val)
873
874/*
875 * values for blk_level field of the struct block_head
876 */
877
878#define FREE_LEVEL 0 /* when node gets removed from the tree its
879 blk_level is set to FREE_LEVEL. It is then
880 used to see whether the node is still in the
881 tree */
882
883#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */
884
885/* Given the buffer head of a formatted node, resolve to the block head of that node. */
886#define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data))
887/* Number of items that are in buffer. */
888#define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh)))
889#define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh)))
890#define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh)))
891
892#define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0)
893#define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0)
894#define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0)
895
896/* Get right delimiting key. -- little endian */
897#define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh))))
898
899/* Does the buffer contain a disk leaf. */
900#define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)
901
902/* Does the buffer contain a disk internal node */
903#define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \
904 && B_LEVEL(bh) <= MAX_HEIGHT)
905
906/***************************************************************************/
907/* STAT DATA */
908/***************************************************************************/
909
910//
911// old stat data is 32 bytes long. We are going to distinguish new one by
912// different size
913//
914struct stat_data_v1 {
915 __le16 sd_mode; /* file type, permissions */
916 __le16 sd_nlink; /* number of hard links */
917 __le16 sd_uid; /* owner */
918 __le16 sd_gid; /* group */
919 __le32 sd_size; /* file size */
920 __le32 sd_atime; /* time of last access */
921 __le32 sd_mtime; /* time file was last modified */
922 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
923 union {
924 __le32 sd_rdev;
925 __le32 sd_blocks; /* number of blocks file uses */
926 } __attribute__ ((__packed__)) u;
927 __le32 sd_first_direct_byte; /* first byte of file which is stored
928 in a direct item: except that if it
929 equals 1 it is a symlink and if it
930 equals ~(__u32)0 there is no
931 direct item. The existence of this
932 field really grates on me. Let's
933 replace it with a macro based on
934 sd_size and our tail suppression
935 policy. Someday. -Hans */
936} __attribute__ ((__packed__));
937
938#define SD_V1_SIZE (sizeof(struct stat_data_v1))
939#define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5)
940#define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
941#define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
942#define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink))
943#define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v))
944#define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid))
945#define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v))
946#define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid))
947#define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v))
948#define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size))
949#define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v))
950#define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
951#define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
952#define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
953#define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
954#define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
955#define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
956#define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
957#define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
958#define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks))
959#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))
960#define sd_v1_first_direct_byte(sdp) \
961 (le32_to_cpu((sdp)->sd_first_direct_byte))
962#define set_sd_v1_first_direct_byte(sdp,v) \
963 ((sdp)->sd_first_direct_byte = cpu_to_le32(v))
964
965/* inode flags stored in sd_attrs (nee sd_reserved) */
966
967/* we want common flags to have the same values as in ext2,
968 so chattr(1) will work without problems */
969#define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL
970#define REISERFS_APPEND_FL FS_APPEND_FL
971#define REISERFS_SYNC_FL FS_SYNC_FL
972#define REISERFS_NOATIME_FL FS_NOATIME_FL
973#define REISERFS_NODUMP_FL FS_NODUMP_FL
974#define REISERFS_SECRM_FL FS_SECRM_FL
975#define REISERFS_UNRM_FL FS_UNRM_FL
976#define REISERFS_COMPR_FL FS_COMPR_FL
977#define REISERFS_NOTAIL_FL FS_NOTAIL_FL
978
979/* persistent flags that file inherits from the parent directory */
980#define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
981 REISERFS_SYNC_FL | \
982 REISERFS_NOATIME_FL | \
983 REISERFS_NODUMP_FL | \
984 REISERFS_SECRM_FL | \
985 REISERFS_COMPR_FL | \
986 REISERFS_NOTAIL_FL )
987
988/* Stat Data on disk (reiserfs version of UFS disk inode minus the
989 address blocks) */
990struct stat_data {
991 __le16 sd_mode; /* file type, permissions */
992 __le16 sd_attrs; /* persistent inode flags */
993 __le32 sd_nlink; /* number of hard links */
994 __le64 sd_size; /* file size */
995 __le32 sd_uid; /* owner */
996 __le32 sd_gid; /* group */
997 __le32 sd_atime; /* time of last access */
998 __le32 sd_mtime; /* time file was last modified */
999 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
1000 __le32 sd_blocks;
1001 union {
1002 __le32 sd_rdev;
1003 __le32 sd_generation;
1004 //__le32 sd_first_direct_byte;
1005 /* first byte of file which is stored in a
1006 direct item: except that if it equals 1
1007 it is a symlink and if it equals
1008 ~(__u32)0 there is no direct item. The
1009 existence of this field really grates
1010 on me. Let's replace it with a macro
1011 based on sd_size and our tail
1012 suppression policy? */
1013 } __attribute__ ((__packed__)) u;
1014} __attribute__ ((__packed__));
1015//
1016// this is 44 bytes long
1017//
1018#define SD_SIZE (sizeof(struct stat_data))
1019#define SD_V2_SIZE SD_SIZE
1020#define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6)
1021#define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
1022#define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
1023/* sd_reserved */
1024/* set_sd_reserved */
1025#define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink))
1026#define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v))
1027#define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size))
1028#define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v))
1029#define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid))
1030#define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v))
1031#define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid))
1032#define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v))
1033#define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
1034#define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
1035#define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
1036#define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
1037#define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
1038#define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
1039#define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks))
1040#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))
1041#define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
1042#define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
1043#define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation))
1044#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))
1045#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))
1046#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))
1047
1048/***************************************************************************/
1049/* DIRECTORY STRUCTURE */
1050/***************************************************************************/
1051/*
1052 Picture represents the structure of directory items
1053 ________________________________________________
1054 | Array of | | | | | |
1055 | directory |N-1| N-2 | .... | 1st |0th|
1056 | entry headers | | | | | |
1057 |_______________|___|_____|________|_______|___|
1058 <---- directory entries ------>
1059
1060 First directory item has k_offset component 1. We store "." and ".."
1061 in one item, always, we never split "." and ".." into differing
1062 items. This makes, among other things, the code for removing
1063 directories simpler. */
1064#define SD_OFFSET 0
1065#define SD_UNIQUENESS 0
1066#define DOT_OFFSET 1
1067#define DOT_DOT_OFFSET 2
1068#define DIRENTRY_UNIQUENESS 500
1069
1070/* */
1071#define FIRST_ITEM_OFFSET 1
1072
1073/*
1074 Q: How to get key of object pointed to by entry from entry?
1075
1076 A: Each directory entry has its header. This header has deh_dir_id and deh_objectid fields, those are key
1077 of object, entry points to */
1078
1079/* NOT IMPLEMENTED:
1080 Directory will someday contain stat data of object */
1081
1082struct reiserfs_de_head {
1083 __le32 deh_offset; /* third component of the directory entry key */
1084 __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced
1085 by directory entry */
1086 __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */
1087 __le16 deh_location; /* offset of name in the whole item */
1088 __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether
1089 entry is hidden (unlinked) */
1090} __attribute__ ((__packed__));
1091#define DEH_SIZE sizeof(struct reiserfs_de_head)
1092#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))
1093#define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id))
1094#define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid))
1095#define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location))
1096#define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state))
1097
1098#define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v)))
1099#define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v)))
1100#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))
1101#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))
1102#define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v)))
1103
1104/* empty directory contains two entries "." and ".." and their headers */
1105#define EMPTY_DIR_SIZE \
1106(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen ("..")))
1107
1108/* old format directories have this size when empty */
1109#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)
1110
1111#define DEH_Statdata 0 /* not used now */
1112#define DEH_Visible 2
1113
1114/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */
1115#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)
1116# define ADDR_UNALIGNED_BITS (3)
1117#endif
1118
1119/* These are only used to manipulate deh_state.
1120 * Because of this, we'll use the ext2_ bit routines,
1121 * since they are little endian */
1122#ifdef ADDR_UNALIGNED_BITS
1123
1124# define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))
1125# define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)
1126
1127# define set_bit_unaligned(nr, addr) \
1128 __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1129# define clear_bit_unaligned(nr, addr) \
1130 __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1131# define test_bit_unaligned(nr, addr) \
1132 test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1133
1134#else
1135
1136# define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr)
1137# define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr)
1138# define test_bit_unaligned(nr, addr) test_bit_le(nr, addr)
1139
1140#endif
1141
1142#define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1143#define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1144#define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1145#define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1146
1147#define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1148#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1149#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1150
1151extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
1152 __le32 par_dirid, __le32 par_objid);
1153extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
1154 __le32 par_dirid, __le32 par_objid);
1155
1156/* array of the entry headers */
1157 /* get item body */
1158#define B_I_PITEM(bh,ih) ( (bh)->b_data + ih_location(ih) )
1159#define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))
1160
1161/* length of the directory entry in directory item. This define
1162 calculates length of i-th directory entry using directory entry
1163 locations from dir entry head. When it calculates length of 0-th
1164 directory entry, it uses length of whole item in place of entry
1165 location of the non-existent following entry in the calculation.
1166 See picture above.*/
1167/*
1168#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \
1169((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))
1170*/
1171static inline int entry_length(const struct buffer_head *bh,
1172 const struct item_head *ih, int pos_in_item)
1173{
1174 struct reiserfs_de_head *deh;
1175
1176 deh = B_I_DEH(bh, ih) + pos_in_item;
1177 if (pos_in_item)
1178 return deh_location(deh - 1) - deh_location(deh);
1179
1180 return ih_item_len(ih) - deh_location(deh);
1181}
1182
1183/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */
1184#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))
1185
1186/* name by bh, ih and entry_num */
1187#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))
1188
1189// two entries per block (at least)
1190#define REISERFS_MAX_NAME(block_size) 255
1191
1192/* this structure is used for operations on directory entries. It is
1193 not a disk structure. */
1194/* When reiserfs_find_entry or search_by_entry_key find directory
1195 entry, they return filled reiserfs_dir_entry structure */
1196struct reiserfs_dir_entry {
1197 struct buffer_head *de_bh;
1198 int de_item_num;
1199 struct item_head *de_ih;
1200 int de_entry_num;
1201 struct reiserfs_de_head *de_deh;
1202 int de_entrylen;
1203 int de_namelen;
1204 char *de_name;
1205 unsigned long *de_gen_number_bit_string;
1206
1207 __u32 de_dir_id;
1208 __u32 de_objectid;
1209
1210 struct cpu_key de_entry_key;
1211};
1212
1213/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */
1214
1215/* pointer to file name, stored in entry */
1216#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))
1217
1218/* length of name */
1219#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \
1220(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))
1221
1222/* hash value occupies bits from 7 up to 30 */
1223#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)
1224/* generation number occupies 7 bits starting from 0 up to 6 */
1225#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)
1226#define MAX_GENERATION_NUMBER 127
1227
1228#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))
1229
1230/*
1231 * Picture represents an internal node of the reiserfs tree
1232 * ______________________________________________________
1233 * | | Array of | Array of | Free |
1234 * |block | keys | pointers | space |
1235 * | head | N | N+1 | |
1236 * |______|_______________|___________________|___________|
1237 */
1238
1239/***************************************************************************/
1240/* DISK CHILD */
1241/***************************************************************************/
1242/* Disk child pointer: The pointer from an internal node of the tree
1243 to a node that is on disk. */
1244struct disk_child {
1245 __le32 dc_block_number; /* Disk child's block number. */
1246 __le16 dc_size; /* Disk child's used space. */
1247 __le16 dc_reserved;
1248};
1249
1250#define DC_SIZE (sizeof(struct disk_child))
1251#define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number))
1252#define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size))
1253#define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)
1254#define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)
1255
1256/* Get disk child by buffer header and position in the tree node. */
1257#define B_N_CHILD(bh, n_pos) ((struct disk_child *)\
1258((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos)))
1259
1260/* Get disk child number by buffer header and position in the tree node. */
1261#define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos)))
1262#define PUT_B_N_CHILD_NUM(bh, n_pos, val) \
1263 (put_dc_block_number(B_N_CHILD(bh, n_pos), val))
1264
1265 /* maximal value of field child_size in structure disk_child */
1266 /* child size is the combined size of all items and their headers */
1267#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))
1268
1269/* amount of used space in buffer (not including block head) */
1270#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))
1271
1272/* max and min number of keys in internal node */
1273#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )
1274#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2)
1275
1276/***************************************************************************/
1277/* PATH STRUCTURES AND DEFINES */
1278/***************************************************************************/
1279
1280/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the
1281 key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it
1282 does not find them in the cache it reads them from disk. For each node search_by_key finds using
1283 reiserfs_bread it then uses bin_search to look through that node. bin_search will find the
1284 position of the block_number of the next node if it is looking through an internal node. If it
1285 is looking through a leaf node bin_search will find the position of the item which has key either
1286 equal to given key, or which is the maximal key less than the given key. */
1287
1288struct path_element {
1289 struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in the tree. */
1290 int pe_position; /* Position in the tree node which is placed in the */
1291 /* buffer above. */
1292};
1293
1294#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */
1295#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */
1296#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */
1297
1298#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */
1299#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */
1300
1301/* We need to keep track of who the ancestors of nodes are. When we
1302 perform a search we record which nodes were visited while
1303 descending the tree looking for the node we searched for. This list
1304 of nodes is called the path. This information is used while
1305 performing balancing. Note that this path information may become
1306 invalid, and this means we must check it when using it to see if it
1307 is still valid. You'll need to read search_by_key and the comments
1308 in it, especially about decrement_counters_in_path(), to understand
1309 this structure.
1310
1311Paths make the code so much harder to work with and debug.... An
1312enormous number of bugs are due to them, and trying to write or modify
1313code that uses them just makes my head hurt. They are based on an
1314excessive effort to avoid disturbing the precious VFS code.:-( The
1315gods only know how we are going to SMP the code that uses them.
1316znodes are the way! */
1317
1318#define PATH_READA 0x1 /* do read ahead */
1319#define PATH_READA_BACK 0x2 /* read backwards */
1320
1321struct treepath {
1322 int path_length; /* Length of the array above. */
1323 int reada;
1324 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */
1325 int pos_in_item;
1326};
1327
1328#define pos_in_item(path) ((path)->pos_in_item)
1329
1330#define INITIALIZE_PATH(var) \
1331struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1332
1333/* Get path element by path and path position. */
1334#define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset))
1335
1336/* Get buffer header at the path by path and path position. */
1337#define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer)
1338
1339/* Get position in the element at the path by path and path position. */
1340#define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position)
1341
1342#define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length))
1343 /* you know, to the person who didn't
1344 write this the macro name does not
1345 at first suggest what it does.
1346 Maybe POSITION_FROM_PATH_END? Or
1347 maybe we should just focus on
1348 dumping paths... -Hans */
1349#define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length))
1350
1351#define PATH_PITEM_HEAD(path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path))
1352
1353/* in do_balance leaf has h == 0 in contrast with path structure,
1354 where root has level == 0. That is why we need these defines */
1355#define PATH_H_PBUFFER(path, h) PATH_OFFSET_PBUFFER (path, path->path_length - (h)) /* tb->S[h] */
1356#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */
1357#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))
1358#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */
1359
1360#define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h))
1361
1362#define get_last_bh(path) PATH_PLAST_BUFFER(path)
1363#define get_ih(path) PATH_PITEM_HEAD(path)
1364#define get_item_pos(path) PATH_LAST_POSITION(path)
1365#define get_item(path) ((void *)B_N_PITEM(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path)))
1366#define item_moved(ih,path) comp_items(ih, path)
1367#define path_changed(ih,path) comp_items (ih, path)
1368
1369/***************************************************************************/
1370/* MISC */
1371/***************************************************************************/
1372
1373/* Size of pointer to the unformatted node. */
1374#define UNFM_P_SIZE (sizeof(unp_t))
1375#define UNFM_P_SHIFT 2
1376
1377// in in-core inode key is stored on le form
1378#define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key))
1379
1380#define MAX_UL_INT 0xffffffff
1381#define MAX_INT 0x7ffffff
1382#define MAX_US_INT 0xffff
1383
1384// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset
1385#define U32_MAX (~(__u32)0)
1386
1387static inline loff_t max_reiserfs_offset(struct inode *inode)
1388{
1389 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)
1390 return (loff_t) U32_MAX;
1391
1392 return (loff_t) ((~(__u64) 0) >> 4);
1393}
1394
1395/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/
1396#define MAX_KEY_OBJECTID MAX_UL_INT
1397
1398#define MAX_B_NUM MAX_UL_INT
1399#define MAX_FC_NUM MAX_US_INT
1400
1401/* the purpose is to detect overflow of an unsigned short */
1402#define REISERFS_LINK_MAX (MAX_US_INT - 1000)
1403
1404/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */
1405#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */
1406#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
1407
1408#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
1409#define get_generation(s) atomic_read (&fs_generation(s))
1410#define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
1411#define __fs_changed(gen,s) (gen != get_generation (s))
1412#define fs_changed(gen,s) \
1413({ \
1414 reiserfs_cond_resched(s); \
1415 __fs_changed(gen, s); \
1416})
1417
1418/***************************************************************************/
1419/* FIXATE NODES */
1420/***************************************************************************/
1421
1422#define VI_TYPE_LEFT_MERGEABLE 1
1423#define VI_TYPE_RIGHT_MERGEABLE 2
1424
1425/* To make any changes in the tree we always first find node, that
1426 contains item to be changed/deleted or place to insert a new
1427 item. We call this node S. To do balancing we need to decide what
1428 we will shift to left/right neighbor, or to a new node, where new
1429 item will be etc. To make this analysis simpler we build virtual
1430 node. Virtual node is an array of items, that will replace items of
1431 node S. (For instance if we are going to delete an item, virtual
1432 node does not contain it). Virtual node keeps information about
1433 item sizes and types, mergeability of first and last items, sizes
1434 of all entries in directory item. We use this array of items when
1435 calculating what we can shift to neighbors and how many nodes we
1436 have to have if we do not any shiftings, if we shift to left/right
1437 neighbor or to both. */
1438struct virtual_item {
1439 int vi_index; // index in the array of item operations
1440 unsigned short vi_type; // left/right mergeability
1441 unsigned short vi_item_len; /* length of item that it will have after balancing */
1442 struct item_head *vi_ih;
1443 const char *vi_item; // body of item (old or new)
1444 const void *vi_new_data; // 0 always but paste mode
1445 void *vi_uarea; // item specific area
1446};
1447
1448struct virtual_node {
1449 char *vn_free_ptr; /* this is a pointer to the free space in the buffer */
1450 unsigned short vn_nr_item; /* number of items in virtual node */
1451 short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */
1452 short vn_mode; /* mode of balancing (paste, insert, delete, cut) */
1453 short vn_affected_item_num;
1454 short vn_pos_in_item;
1455 struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */
1456 const void *vn_data;
1457 struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */
1458};
1459
1460/* used by directory items when creating virtual nodes */
1461struct direntry_uarea {
1462 int flags;
1463 __u16 entry_count;
1464 __u16 entry_sizes[1];
1465} __attribute__ ((__packed__));
1466
1467/***************************************************************************/
1468/* TREE BALANCE */
1469/***************************************************************************/
1470
1471/* This temporary structure is used in tree balance algorithms, and
1472 constructed as we go to the extent that its various parts are
1473 needed. It contains arrays of nodes that can potentially be
1474 involved in the balancing of node S, and parameters that define how
1475 each of the nodes must be balanced. Note that in these algorithms
1476 for balancing the worst case is to need to balance the current node
1477 S and the left and right neighbors and all of their parents plus
1478 create a new node. We implement S1 balancing for the leaf nodes
1479 and S0 balancing for the internal nodes (S1 and S0 are defined in
1480 our papers.)*/
1481
1482#define MAX_FREE_BLOCK 7 /* size of the array of buffers to free at end of do_balance */
1483
1484/* maximum number of FEB blocknrs on a single level */
1485#define MAX_AMOUNT_NEEDED 2
1486
1487/* someday somebody will prefix every field in this struct with tb_ */
1488struct tree_balance {
1489 int tb_mode;
1490 int need_balance_dirty;
1491 struct super_block *tb_sb;
1492 struct reiserfs_transaction_handle *transaction_handle;
1493 struct treepath *tb_path;
1494 struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */
1495 struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */
1496 struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */
1497 struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */
1498 struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */
1499 struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */
1500
1501 struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals
1502 cur_blknum. */
1503 struct buffer_head *used[MAX_FEB_SIZE];
1504 struct buffer_head *thrown[MAX_FEB_SIZE];
1505 int lnum[MAX_HEIGHT]; /* array of number of items which must be
1506 shifted to the left in order to balance the
1507 current node; for leaves includes item that
1508 will be partially shifted; for internal
1509 nodes, it is the number of child pointers
1510 rather than items. It includes the new item
1511 being created. The code sometimes subtracts
1512 one to get the number of wholly shifted
1513 items for other purposes. */
1514 int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */
1515 int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and
1516 S[h] to its item number within the node CFL[h] */
1517 int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */
1518 int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from
1519 S[h]. A negative value means removing. */
1520 int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after
1521 balancing on the level h of the tree. If 0 then S is
1522 being deleted, if 1 then S is remaining and no new nodes
1523 are being created, if 2 or 3 then 1 or 2 new nodes is
1524 being created */
1525
1526 /* fields that are used only for balancing leaves of the tree */
1527 int cur_blknum; /* number of empty blocks having been already allocated */
1528 int s0num; /* number of items that fall into left most node when S[0] splits */
1529 int s1num; /* number of items that fall into first new node when S[0] splits */
1530 int s2num; /* number of items that fall into second new node when S[0] splits */
1531 int lbytes; /* number of bytes which can flow to the left neighbor from the left */
1532 /* most liquid item that cannot be shifted from S[0] entirely */
1533 /* if -1 then nothing will be partially shifted */
1534 int rbytes; /* number of bytes which will flow to the right neighbor from the right */
1535 /* most liquid item that cannot be shifted from S[0] entirely */
1536 /* if -1 then nothing will be partially shifted */
1537 int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */
1538 /* note: if S[0] splits into 3 nodes, then items do not need to be cut */
1539 int s2bytes;
1540 struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */
1541 char *vn_buf; /* kmalloced memory. Used to create
1542 virtual node and keep map of
1543 dirtied bitmap blocks */
1544 int vn_buf_size; /* size of the vn_buf */
1545 struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */
1546
1547 int fs_gen; /* saved value of `reiserfs_generation' counter
1548 see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */
1549#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1550 struct in_core_key key; /* key pointer, to pass to block allocator or
1551 another low-level subsystem */
1552#endif
1553};
1554
1555/* These are modes of balancing */
1556
1557/* When inserting an item. */
1558#define M_INSERT 'i'
1559/* When inserting into (directories only) or appending onto an already
1560 existent item. */
1561#define M_PASTE 'p'
1562/* When deleting an item. */
1563#define M_DELETE 'd'
1564/* When truncating an item or removing an entry from a (directory) item. */
1565#define M_CUT 'c'
1566
1567/* used when balancing on leaf level skipped (in reiserfsck) */
1568#define M_INTERNAL 'n'
1569
1570/* When further balancing is not needed, then do_balance does not need
1571 to be called. */
1572#define M_SKIP_BALANCING 's'
1573#define M_CONVERT 'v'
1574
1575/* modes of leaf_move_items */
1576#define LEAF_FROM_S_TO_L 0
1577#define LEAF_FROM_S_TO_R 1
1578#define LEAF_FROM_R_TO_L 2
1579#define LEAF_FROM_L_TO_R 3
1580#define LEAF_FROM_S_TO_SNEW 4
1581
1582#define FIRST_TO_LAST 0
1583#define LAST_TO_FIRST 1
1584
1585/* used in do_balance for passing parent of node information that has
1586 been gotten from tb struct */
1587struct buffer_info {
1588 struct tree_balance *tb;
1589 struct buffer_head *bi_bh;
1590 struct buffer_head *bi_parent;
1591 int bi_position;
1592};
1593
1594static inline struct super_block *sb_from_tb(struct tree_balance *tb)
1595{
1596 return tb ? tb->tb_sb : NULL;
1597}
1598
1599static inline struct super_block *sb_from_bi(struct buffer_info *bi)
1600{
1601 return bi ? sb_from_tb(bi->tb) : NULL;
1602}
1603
1604/* there are 4 types of items: stat data, directory item, indirect, direct.
1605+-------------------+------------+--------------+------------+
1606| | k_offset | k_uniqueness | mergeable? |
1607+-------------------+------------+--------------+------------+
1608| stat data | 0 | 0 | no |
1609+-------------------+------------+--------------+------------+
1610| 1st directory item| DOT_OFFSET |DIRENTRY_UNIQUENESS| no |
1611| non 1st directory | hash value | | yes |
1612| item | | | |
1613+-------------------+------------+--------------+------------+
1614| indirect item | offset + 1 |TYPE_INDIRECT | if this is not the first indirect item of the object
1615+-------------------+------------+--------------+------------+
1616| direct item | offset + 1 |TYPE_DIRECT | if not this is not the first direct item of the object
1617+-------------------+------------+--------------+------------+
1618*/
1619
1620struct item_operations {
1621 int (*bytes_number) (struct item_head * ih, int block_size);
1622 void (*decrement_key) (struct cpu_key *);
1623 int (*is_left_mergeable) (struct reiserfs_key * ih,
1624 unsigned long bsize);
1625 void (*print_item) (struct item_head *, char *item);
1626 void (*check_item) (struct item_head *, char *item);
1627
1628 int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
1629 int is_affected, int insert_size);
1630 int (*check_left) (struct virtual_item * vi, int free,
1631 int start_skip, int end_skip);
1632 int (*check_right) (struct virtual_item * vi, int free);
1633 int (*part_size) (struct virtual_item * vi, int from, int to);
1634 int (*unit_num) (struct virtual_item * vi);
1635 void (*print_vi) (struct virtual_item * vi);
1636};
1637
1638extern struct item_operations *item_ops[TYPE_ANY + 1];
1639
1640#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
1641#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
1642#define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item)
1643#define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item)
1644#define op_create_vi(vn,vi,is_affected,insert_size) item_ops[le_ih_k_type ((vi)->vi_ih)]->create_vi (vn,vi,is_affected,insert_size)
1645#define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip)
1646#define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free)
1647#define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to)
1648#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)
1649#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)
1650
1651#define COMP_SHORT_KEYS comp_short_keys
1652
1653/* number of blocks pointed to by the indirect item */
1654#define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE)
1655
1656/* the used space within the unformatted node corresponding to pos within the item pointed to by ih */
1657#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))
1658
1659/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */
1660
1661/* get the item header */
1662#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) )
1663
1664/* get key */
1665#define B_N_PDELIM_KEY(bh,item_num) ( (struct reiserfs_key * )((bh)->b_data + BLKH_SIZE) + (item_num) )
1666
1667/* get the key */
1668#define B_N_PKEY(bh,item_num) ( &(B_N_PITEM_HEAD(bh,item_num)->ih_key) )
1669
1670/* get item body */
1671#define B_N_PITEM(bh,item_num) ( (bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(item_num))))
1672
1673/* get the stat data by the buffer header and the item order */
1674#define B_N_STAT_DATA(bh,nr) \
1675( (struct stat_data *)((bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(nr))) ) )
1676
1677 /* following defines use reiserfs buffer header and item header */
1678
1679/* get stat-data */
1680#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )
1681
1682// this is 3976 for size==4096
1683#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)
1684
1685/* indirect items consist of entries which contain blocknrs, pos
1686 indicates which entry, and B_I_POS_UNFM_POINTER resolves to the
1687 blocknr contained by the entry pos points to */
1688#define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))
1689#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)
1690
1691struct reiserfs_iget_args {
1692 __u32 objectid;
1693 __u32 dirid;
1694};
1695
1696/***************************************************************************/
1697/* FUNCTION DECLARATIONS */
1698/***************************************************************************/
1699
1700#define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12)
1701
1702#define journal_trans_half(blocksize) \
1703 ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32))
1704
1705/* journal.c see journal.c for all the comments here */
1706
1707/* first block written in a commit. */
1708struct reiserfs_journal_desc {
1709 __le32 j_trans_id; /* id of commit */
1710 __le32 j_len; /* length of commit. len +1 is the commit block */
1711 __le32 j_mount_id; /* mount id of this trans */
1712 __le32 j_realblock[1]; /* real locations for each block */
1713};
1714
1715#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)
1716#define get_desc_trans_len(d) le32_to_cpu((d)->j_len)
1717#define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id)
1718
1719#define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0)
1720#define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0)
1721#define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0)
1722
1723/* last block written in a commit */
1724struct reiserfs_journal_commit {
1725 __le32 j_trans_id; /* must match j_trans_id from the desc block */
1726 __le32 j_len; /* ditto */
1727 __le32 j_realblock[1]; /* real locations for each block */
1728};
1729
1730#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)
1731#define get_commit_trans_len(c) le32_to_cpu((c)->j_len)
1732#define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id)
1733
1734#define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0)
1735#define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0)
1736
1737/* this header block gets written whenever a transaction is considered fully flushed, and is more recent than the
1738** last fully flushed transaction. fully flushed means all the log blocks and all the real blocks are on disk,
1739** and this transaction does not need to be replayed.
1740*/
1741struct reiserfs_journal_header {
1742 __le32 j_last_flush_trans_id; /* id of last fully flushed transaction */
1743 __le32 j_first_unflushed_offset; /* offset in the log of where to start replay after a crash */
1744 __le32 j_mount_id;
1745 /* 12 */ struct journal_params jh_journal;
1746};
1747
1748/* biggest tunable defines are right here */
1749#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */
1750#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */
1751#define JOURNAL_TRANS_MIN_DEFAULT 256
1752#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */
1753#define JOURNAL_MIN_RATIO 2
1754#define JOURNAL_MAX_COMMIT_AGE 30
1755#define JOURNAL_MAX_TRANS_AGE 30
1756#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)
1757#define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \
1758 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \
1759 REISERFS_QUOTA_TRANS_BLOCKS(sb)))
1760
1761#ifdef CONFIG_QUOTA
1762#define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA))
1763/* We need to update data and inode (atime) */
1764#define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0)
1765/* 1 balancing, 1 bitmap, 1 data per write + stat data update */
1766#define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
1767(DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0)
1768/* same as with INIT */
1769#define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
1770(DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0)
1771#else
1772#define REISERFS_QUOTA_TRANS_BLOCKS(s) 0
1773#define REISERFS_QUOTA_INIT_BLOCKS(s) 0
1774#define REISERFS_QUOTA_DEL_BLOCKS(s) 0
1775#endif
1776
1777/* both of these can be as low as 1, or as high as you want. The min is the
1778** number of 4k bitmap nodes preallocated on mount. New nodes are allocated
1779** as needed, and released when transactions are committed. On release, if
1780** the current number of nodes is > max, the node is freed, otherwise,
1781** it is put on a free list for faster use later.
1782*/
1783#define REISERFS_MIN_BITMAP_NODES 10
1784#define REISERFS_MAX_BITMAP_NODES 100
1785
1786#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */
1787#define JBH_HASH_MASK 8191
1788
1789#define _jhashfn(sb,block) \
1790 (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \
1791 (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12))))
1792#define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK])
1793
1794// We need these to make journal.c code more readable
1795#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
1796#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
1797#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
1798
1799enum reiserfs_bh_state_bits {
1800 BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */
1801 BH_JDirty_wait,
1802 BH_JNew, /* disk block was taken off free list before
1803 * being in a finished transaction, or
1804 * written to disk. Can be reused immed. */
1805 BH_JPrepared,
1806 BH_JRestore_dirty,
1807 BH_JTest, // debugging only will go away
1808};
1809
1810BUFFER_FNS(JDirty, journaled);
1811TAS_BUFFER_FNS(JDirty, journaled);
1812BUFFER_FNS(JDirty_wait, journal_dirty);
1813TAS_BUFFER_FNS(JDirty_wait, journal_dirty);
1814BUFFER_FNS(JNew, journal_new);
1815TAS_BUFFER_FNS(JNew, journal_new);
1816BUFFER_FNS(JPrepared, journal_prepared);
1817TAS_BUFFER_FNS(JPrepared, journal_prepared);
1818BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
1819TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
1820BUFFER_FNS(JTest, journal_test);
1821TAS_BUFFER_FNS(JTest, journal_test);
1822
1823/*
1824** transaction handle which is passed around for all journal calls
1825*/
1826struct reiserfs_transaction_handle {
1827 struct super_block *t_super; /* super for this FS when journal_begin was
1828 called. saves calls to reiserfs_get_super
1829 also used by nested transactions to make
1830 sure they are nesting on the right FS
1831 _must_ be first in the handle
1832 */
1833 int t_refcount;
1834 int t_blocks_logged; /* number of blocks this writer has logged */
1835 int t_blocks_allocated; /* number of blocks this writer allocated */
1836 unsigned int t_trans_id; /* sanity check, equals the current trans id */
1837 void *t_handle_save; /* save existing current->journal_info */
1838 unsigned displace_new_blocks:1; /* if new block allocation occurres, that block
1839 should be displaced from others */
1840 struct list_head t_list;
1841};
1842
1843/* used to keep track of ordered and tail writes, attached to the buffer
1844 * head through b_journal_head.
1845 */
1846struct reiserfs_jh {
1847 struct reiserfs_journal_list *jl;
1848 struct buffer_head *bh;
1849 struct list_head list;
1850};
1851
1852void reiserfs_free_jh(struct buffer_head *bh);
1853int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);
1854int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);
1855int journal_mark_dirty(struct reiserfs_transaction_handle *,
1856 struct super_block *, struct buffer_head *bh);
1857
1858static inline int reiserfs_file_data_log(struct inode *inode)
1859{
1860 if (reiserfs_data_log(inode->i_sb) ||
1861 (REISERFS_I(inode)->i_flags & i_data_log))
1862 return 1;
1863 return 0;
1864}
1865
1866static inline int reiserfs_transaction_running(struct super_block *s)
1867{
1868 struct reiserfs_transaction_handle *th = current->journal_info;
1869 if (th && th->t_super == s)
1870 return 1;
1871 if (th && th->t_super == NULL)
1872 BUG();
1873 return 0;
1874}
1875
1876static inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th)
1877{
1878 return th->t_blocks_allocated - th->t_blocks_logged;
1879}
1880
1881struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
1882 super_block
1883 *,
1884 int count);
1885int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);
1886int reiserfs_commit_page(struct inode *inode, struct page *page,
1887 unsigned from, unsigned to);
1888int reiserfs_flush_old_commits(struct super_block *);
1889int reiserfs_commit_for_inode(struct inode *);
1890int reiserfs_inode_needs_commit(struct inode *);
1891void reiserfs_update_inode_transaction(struct inode *);
1892void reiserfs_wait_on_write_block(struct super_block *s);
1893void reiserfs_block_writes(struct reiserfs_transaction_handle *th);
1894void reiserfs_allow_writes(struct super_block *s);
1895void reiserfs_check_lock_depth(struct super_block *s, char *caller);
1896int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,
1897 int wait);
1898void reiserfs_restore_prepared_buffer(struct super_block *,
1899 struct buffer_head *bh);
1900int journal_init(struct super_block *, const char *j_dev_name, int old_format,
1901 unsigned int);
1902int journal_release(struct reiserfs_transaction_handle *, struct super_block *);
1903int journal_release_error(struct reiserfs_transaction_handle *,
1904 struct super_block *);
1905int journal_end(struct reiserfs_transaction_handle *, struct super_block *,
1906 unsigned long);
1907int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,
1908 unsigned long);
1909int journal_mark_freed(struct reiserfs_transaction_handle *,
1910 struct super_block *, b_blocknr_t blocknr);
1911int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
1912int reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr,
1913 int bit_nr, int searchall, b_blocknr_t *next);
1914int journal_begin(struct reiserfs_transaction_handle *,
1915 struct super_block *sb, unsigned long);
1916int journal_join_abort(struct reiserfs_transaction_handle *,
1917 struct super_block *sb, unsigned long);
1918void reiserfs_abort_journal(struct super_block *sb, int errno);
1919void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
1920int reiserfs_allocate_list_bitmaps(struct super_block *s,
1921 struct reiserfs_list_bitmap *, unsigned int);
1922
1923void add_save_link(struct reiserfs_transaction_handle *th,
1924 struct inode *inode, int truncate);
1925int remove_save_link(struct inode *inode, int truncate);
1926
1927/* objectid.c */
1928__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);
1929void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
1930 __u32 objectid_to_release);
1931int reiserfs_convert_objectid_map_v1(struct super_block *);
1932
1933/* stree.c */
1934int B_IS_IN_TREE(const struct buffer_head *);
1935extern void copy_item_head(struct item_head *to,
1936 const struct item_head *from);
1937
1938// first key is in cpu form, second - le
1939extern int comp_short_keys(const struct reiserfs_key *le_key,
1940 const struct cpu_key *cpu_key);
1941extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);
1942
1943// both are in le form
1944extern int comp_le_keys(const struct reiserfs_key *,
1945 const struct reiserfs_key *);
1946extern int comp_short_le_keys(const struct reiserfs_key *,
1947 const struct reiserfs_key *);
1948
1949//
1950// get key version from on disk key - kludge
1951//
1952static inline int le_key_version(const struct reiserfs_key *key)
1953{
1954 int type;
1955
1956 type = offset_v2_k_type(&(key->u.k_offset_v2));
1957 if (type != TYPE_DIRECT && type != TYPE_INDIRECT
1958 && type != TYPE_DIRENTRY)
1959 return KEY_FORMAT_3_5;
1960
1961 return KEY_FORMAT_3_6;
1962
1963}
1964
1965static inline void copy_key(struct reiserfs_key *to,
1966 const struct reiserfs_key *from)
1967{
1968 memcpy(to, from, KEY_SIZE);
1969}
1970
1971int comp_items(const struct item_head *stored_ih, const struct treepath *path);
1972const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
1973 const struct super_block *sb);
1974int search_by_key(struct super_block *, const struct cpu_key *,
1975 struct treepath *, int);
1976#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)
1977int search_for_position_by_key(struct super_block *sb,
1978 const struct cpu_key *cpu_key,
1979 struct treepath *search_path);
1980extern void decrement_bcount(struct buffer_head *bh);
1981void decrement_counters_in_path(struct treepath *search_path);
1982void pathrelse(struct treepath *search_path);
1983int reiserfs_check_path(struct treepath *p);
1984void pathrelse_and_restore(struct super_block *s, struct treepath *search_path);
1985
1986int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
1987 struct treepath *path,
1988 const struct cpu_key *key,
1989 struct item_head *ih,
1990 struct inode *inode, const char *body);
1991
1992int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,
1993 struct treepath *path,
1994 const struct cpu_key *key,
1995 struct inode *inode,
1996 const char *body, int paste_size);
1997
1998int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1999 struct treepath *path,
2000 struct cpu_key *key,
2001 struct inode *inode,
2002 struct page *page, loff_t new_file_size);
2003
2004int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
2005 struct treepath *path,
2006 const struct cpu_key *key,
2007 struct inode *inode, struct buffer_head *un_bh);
2008
2009void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
2010 struct inode *inode, struct reiserfs_key *key);
2011int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
2012 struct inode *inode);
2013int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
2014 struct inode *inode, struct page *,
2015 int update_timestamps);
2016
2017#define i_block_size(inode) ((inode)->i_sb->s_blocksize)
2018#define file_size(inode) ((inode)->i_size)
2019#define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1))
2020
2021#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\
2022!STORE_TAIL_IN_UNFM_S1(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):have_small_tails ((inode)->i_sb)?!STORE_TAIL_IN_UNFM_S2(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):0 )
2023
2024void padd_item(char *item, int total_length, int length);
2025
2026/* inode.c */
2027/* args for the create parameter of reiserfs_get_block */
2028#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */
2029#define GET_BLOCK_CREATE 1 /* add anything you need to find block */
2030#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */
2031#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */
2032#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */
2033#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */
2034
2035void reiserfs_read_locked_inode(struct inode *inode,
2036 struct reiserfs_iget_args *args);
2037int reiserfs_find_actor(struct inode *inode, void *p);
2038int reiserfs_init_locked_inode(struct inode *inode, void *p);
2039void reiserfs_evict_inode(struct inode *inode);
2040int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc);
2041int reiserfs_get_block(struct inode *inode, sector_t block,
2042 struct buffer_head *bh_result, int create);
2043struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
2044 int fh_len, int fh_type);
2045struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
2046 int fh_len, int fh_type);
2047int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
2048 int connectable);
2049
2050int reiserfs_truncate_file(struct inode *, int update_timestamps);
2051void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,
2052 int type, int key_length);
2053void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
2054 int version,
2055 loff_t offset, int type, int length, int entry_count);
2056struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);
2057
2058struct reiserfs_security_handle;
2059int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
2060 struct inode *dir, umode_t mode,
2061 const char *symname, loff_t i_size,
2062 struct dentry *dentry, struct inode *inode,
2063 struct reiserfs_security_handle *security);
2064
2065void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
2066 struct inode *inode, loff_t size);
2067
2068static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,
2069 struct inode *inode)
2070{
2071 reiserfs_update_sd_size(th, inode, inode->i_size);
2072}
2073
2074void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
2075void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
2076int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
2077
2078int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
2079
2080/* namei.c */
2081void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
2082int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
2083 struct treepath *path, struct reiserfs_dir_entry *de);
2084struct dentry *reiserfs_get_parent(struct dentry *);
2085
2086#ifdef CONFIG_REISERFS_PROC_INFO
2087int reiserfs_proc_info_init(struct super_block *sb);
2088int reiserfs_proc_info_done(struct super_block *sb);
2089int reiserfs_proc_info_global_init(void);
2090int reiserfs_proc_info_global_done(void);
2091
2092#define PROC_EXP( e ) e
2093
2094#define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data
2095#define PROC_INFO_MAX( sb, field, value ) \
2096 __PINFO( sb ).field = \
2097 max( REISERFS_SB( sb ) -> s_proc_info_data.field, value )
2098#define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) )
2099#define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) )
2100#define PROC_INFO_BH_STAT( sb, bh, level ) \
2101 PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \
2102 PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \
2103 PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) )
2104#else
2105static inline int reiserfs_proc_info_init(struct super_block *sb)
2106{
2107 return 0;
2108}
2109
2110static inline int reiserfs_proc_info_done(struct super_block *sb)
2111{
2112 return 0;
2113}
2114
2115static inline int reiserfs_proc_info_global_init(void)
2116{
2117 return 0;
2118}
2119
2120static inline int reiserfs_proc_info_global_done(void)
2121{
2122 return 0;
2123}
2124
2125#define PROC_EXP( e )
2126#define VOID_V ( ( void ) 0 )
2127#define PROC_INFO_MAX( sb, field, value ) VOID_V
2128#define PROC_INFO_INC( sb, field ) VOID_V
2129#define PROC_INFO_ADD( sb, field, val ) VOID_V
2130#define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V
2131#endif
2132
2133/* dir.c */
2134extern const struct inode_operations reiserfs_dir_inode_operations;
2135extern const struct inode_operations reiserfs_symlink_inode_operations;
2136extern const struct inode_operations reiserfs_special_inode_operations;
2137extern const struct file_operations reiserfs_dir_operations;
2138int reiserfs_readdir_dentry(struct dentry *, void *, filldir_t, loff_t *);
2139
2140/* tail_conversion.c */
2141int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,
2142 struct treepath *, struct buffer_head *, loff_t);
2143int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,
2144 struct page *, struct treepath *, const struct cpu_key *,
2145 loff_t, char *);
2146void reiserfs_unmap_buffer(struct buffer_head *);
2147
2148/* file.c */
2149extern const struct inode_operations reiserfs_file_inode_operations;
2150extern const struct file_operations reiserfs_file_operations;
2151extern const struct address_space_operations reiserfs_address_space_operations;
2152
2153/* fix_nodes.c */
2154
2155int fix_nodes(int n_op_mode, struct tree_balance *tb,
2156 struct item_head *ins_ih, const void *);
2157void unfix_nodes(struct tree_balance *);
2158
2159/* prints.c */
2160void __reiserfs_panic(struct super_block *s, const char *id,
2161 const char *function, const char *fmt, ...)
2162 __attribute__ ((noreturn));
2163#define reiserfs_panic(s, id, fmt, args...) \
2164 __reiserfs_panic(s, id, __func__, fmt, ##args)
2165void __reiserfs_error(struct super_block *s, const char *id,
2166 const char *function, const char *fmt, ...);
2167#define reiserfs_error(s, id, fmt, args...) \
2168 __reiserfs_error(s, id, __func__, fmt, ##args)
2169void reiserfs_info(struct super_block *s, const char *fmt, ...);
2170void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
2171void print_indirect_item(struct buffer_head *bh, int item_num);
2172void store_print_tb(struct tree_balance *tb);
2173void print_cur_tb(char *mes);
2174void print_de(struct reiserfs_dir_entry *de);
2175void print_bi(struct buffer_info *bi, char *mes);
2176#define PRINT_LEAF_ITEMS 1 /* print all items */
2177#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */
2178#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */
2179void print_block(struct buffer_head *bh, ...);
2180void print_bmap(struct super_block *s, int silent);
2181void print_bmap_block(int i, char *data, int size, int silent);
2182/*void print_super_block (struct super_block * s, char * mes);*/
2183void print_objectid_map(struct super_block *s);
2184void print_block_head(struct buffer_head *bh, char *mes);
2185void check_leaf(struct buffer_head *bh);
2186void check_internal(struct buffer_head *bh);
2187void print_statistics(struct super_block *s);
2188char *reiserfs_hashname(int code);
2189
2190/* lbalance.c */
2191int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
2192 int mov_bytes, struct buffer_head *Snew);
2193int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);
2194int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);
2195void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,
2196 int del_num, int del_bytes);
2197void leaf_insert_into_buf(struct buffer_info *bi, int before,
2198 struct item_head *inserted_item_ih,
2199 const char *inserted_item_body, int zeros_number);
2200void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,
2201 int pos_in_item, int paste_size, const char *body,
2202 int zeros_number);
2203void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
2204 int pos_in_item, int cut_size);
2205void leaf_paste_entries(struct buffer_info *bi, int item_num, int before,
2206 int new_entry_count, struct reiserfs_de_head *new_dehs,
2207 const char *records, int paste_size);
2208/* ibalance.c */
2209int balance_internal(struct tree_balance *, int, int, struct item_head *,
2210 struct buffer_head **);
2211
2212/* do_balance.c */
2213void do_balance_mark_leaf_dirty(struct tree_balance *tb,
2214 struct buffer_head *bh, int flag);
2215#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
2216#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
2217
2218void do_balance(struct tree_balance *tb, struct item_head *ih,
2219 const char *body, int flag);
2220void reiserfs_invalidate_buffer(struct tree_balance *tb,
2221 struct buffer_head *bh);
2222
2223int get_left_neighbor_position(struct tree_balance *tb, int h);
2224int get_right_neighbor_position(struct tree_balance *tb, int h);
2225void replace_key(struct tree_balance *tb, struct buffer_head *, int,
2226 struct buffer_head *, int);
2227void make_empty_node(struct buffer_info *);
2228struct buffer_head *get_FEB(struct tree_balance *);
2229
2230/* bitmap.c */
2231
2232/* structure contains hints for block allocator, and it is a container for
2233 * arguments, such as node, search path, transaction_handle, etc. */
2234struct __reiserfs_blocknr_hint {
2235 struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
2236 sector_t block; /* file offset, in blocks */
2237 struct in_core_key key;
2238 struct treepath *path; /* search path, used by allocator to deternine search_start by
2239 * various ways */
2240 struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and
2241 * bitmap blocks changes */
2242 b_blocknr_t beg, end;
2243 b_blocknr_t search_start; /* a field used to transfer search start value (block number)
2244 * between different block allocator procedures
2245 * (determine_search_start() and others) */
2246 int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed
2247 * function that do actual allocation */
2248
2249 unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for
2250 * formatted/unformatted blocks with/without preallocation */
2251 unsigned preallocate:1;
2252};
2253
2254typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;
2255
2256int reiserfs_parse_alloc_options(struct super_block *, char *);
2257void reiserfs_init_alloc_options(struct super_block *s);
2258
2259/*
2260 * given a directory, this will tell you what packing locality
2261 * to use for a new object underneat it. The locality is returned
2262 * in disk byte order (le).
2263 */
2264__le32 reiserfs_choose_packing(struct inode *dir);
2265
2266int reiserfs_init_bitmap_cache(struct super_block *sb);
2267void reiserfs_free_bitmap_cache(struct super_block *sb);
2268void reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info);
2269struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap);
2270int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);
2271void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,
2272 b_blocknr_t, int for_unformatted);
2273int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,
2274 int);
2275static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2276 b_blocknr_t * new_blocknrs,
2277 int amount_needed)
2278{
2279 reiserfs_blocknr_hint_t hint = {
2280 .th = tb->transaction_handle,
2281 .path = tb->tb_path,
2282 .inode = NULL,
2283 .key = tb->key,
2284 .block = 0,
2285 .formatted_node = 1
2286 };
2287 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,
2288 0);
2289}
2290
2291static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2292 *th, struct inode *inode,
2293 b_blocknr_t * new_blocknrs,
2294 struct treepath *path,
2295 sector_t block)
2296{
2297 reiserfs_blocknr_hint_t hint = {
2298 .th = th,
2299 .path = path,
2300 .inode = inode,
2301 .block = block,
2302 .formatted_node = 0,
2303 .preallocate = 0
2304 };
2305 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2306}
2307
2308#ifdef REISERFS_PREALLOCATE
2309static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
2310 *th, struct inode *inode,
2311 b_blocknr_t * new_blocknrs,
2312 struct treepath *path,
2313 sector_t block)
2314{
2315 reiserfs_blocknr_hint_t hint = {
2316 .th = th,
2317 .path = path,
2318 .inode = inode,
2319 .block = block,
2320 .formatted_node = 0,
2321 .preallocate = 1
2322 };
2323 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2324}
2325
2326void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
2327 struct inode *inode);
2328void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);
2329#endif
2330
2331/* hashes.c */
2332__u32 keyed_hash(const signed char *msg, int len);
2333__u32 yura_hash(const signed char *msg, int len);
2334__u32 r5_hash(const signed char *msg, int len);
2335
2336#define reiserfs_set_le_bit __set_bit_le
2337#define reiserfs_test_and_set_le_bit __test_and_set_bit_le
2338#define reiserfs_clear_le_bit __clear_bit_le
2339#define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le
2340#define reiserfs_test_le_bit test_bit_le
2341#define reiserfs_find_next_zero_le_bit find_next_zero_bit_le
2342
2343/* sometimes reiserfs_truncate may require to allocate few new blocks
2344 to perform indirect2direct conversion. People probably used to
2345 think, that truncate should work without problems on a filesystem
2346 without free disk space. They may complain that they can not
2347 truncate due to lack of free disk space. This spare space allows us
2348 to not worry about it. 500 is probably too much, but it should be
2349 absolutely safe */
2350#define SPARE_SPACE 500
2351
2352/* prototypes from ioctl.c */
2353long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
2354long reiserfs_compat_ioctl(struct file *filp,
2355 unsigned int cmd, unsigned long arg);
2356int reiserfs_unpack(struct inode *inode, struct file *filp);
2357
2358#endif /* __KERNEL__ */
2359
2360#endif /* _LINUX_REISER_FS_H */ 26#endif /* _LINUX_REISER_FS_H */
diff --git a/include/linux/reiserfs_fs_i.h b/include/linux/reiserfs_fs_i.h
deleted file mode 100644
index 97959bdfe214..000000000000
--- a/include/linux/reiserfs_fs_i.h
+++ /dev/null
@@ -1,63 +0,0 @@
1#ifndef _REISER_FS_I
2#define _REISER_FS_I
3
4#include <linux/list.h>
5
6struct reiserfs_journal_list;
7
8/** bitmasks for i_flags field in reiserfs-specific part of inode */
9typedef enum {
10 /** this says what format of key do all items (but stat data) of
11 an object have. If this is set, that format is 3.6 otherwise
12 - 3.5 */
13 i_item_key_version_mask = 0x0001,
14 /** If this is unset, object has 3.5 stat data, otherwise, it has
15 3.6 stat data with 64bit size, 32bit nlink etc. */
16 i_stat_data_version_mask = 0x0002,
17 /** file might need tail packing on close */
18 i_pack_on_close_mask = 0x0004,
19 /** don't pack tail of file */
20 i_nopack_mask = 0x0008,
21 /** If those is set, "safe link" was created for this file during
22 truncate or unlink. Safe link is used to avoid leakage of disk
23 space on crash with some files open, but unlinked. */
24 i_link_saved_unlink_mask = 0x0010,
25 i_link_saved_truncate_mask = 0x0020,
26 i_has_xattr_dir = 0x0040,
27 i_data_log = 0x0080,
28} reiserfs_inode_flags;
29
30struct reiserfs_inode_info {
31 __u32 i_key[4]; /* key is still 4 32 bit integers */
32 /** transient inode flags that are never stored on disk. Bitmasks
33 for this field are defined above. */
34 __u32 i_flags;
35
36 __u32 i_first_direct_byte; // offset of first byte stored in direct item.
37
38 /* copy of persistent inode flags read from sd_attrs. */
39 __u32 i_attrs;
40
41 int i_prealloc_block; /* first unused block of a sequence of unused blocks */
42 int i_prealloc_count; /* length of that sequence */
43 struct list_head i_prealloc_list; /* per-transaction list of inodes which
44 * have preallocated blocks */
45
46 unsigned new_packing_locality:1; /* new_packig_locality is created; new blocks
47 * for the contents of this directory should be
48 * displaced */
49
50 /* we use these for fsync or O_SYNC to decide which transaction
51 ** needs to be committed in order for this inode to be properly
52 ** flushed */
53 unsigned int i_trans_id;
54 struct reiserfs_journal_list *i_jl;
55 atomic_t openers;
56 struct mutex tailpack;
57#ifdef CONFIG_REISERFS_FS_XATTR
58 struct rw_semaphore i_xattr_sem;
59#endif
60 struct inode vfs_inode;
61};
62
63#endif
diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
deleted file mode 100644
index 8c9e85c64b46..000000000000
--- a/include/linux/reiserfs_fs_sb.h
+++ /dev/null
@@ -1,554 +0,0 @@
1/* Copyright 1996-2000 Hans Reiser, see reiserfs/README for licensing
2 * and copyright details */
3
4#ifndef _LINUX_REISER_FS_SB
5#define _LINUX_REISER_FS_SB
6
7#ifdef __KERNEL__
8#include <linux/workqueue.h>
9#include <linux/rwsem.h>
10#include <linux/mutex.h>
11#include <linux/sched.h>
12#endif
13
14typedef enum {
15 reiserfs_attrs_cleared = 0x00000001,
16} reiserfs_super_block_flags;
17
18/* struct reiserfs_super_block accessors/mutators
19 * since this is a disk structure, it will always be in
20 * little endian format. */
21#define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count))
22#define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v))
23#define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks))
24#define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v))
25#define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block))
26#define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v))
27
28#define sb_jp_journal_1st_block(sbp) \
29 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block))
30#define set_sb_jp_journal_1st_block(sbp,v) \
31 ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v))
32#define sb_jp_journal_dev(sbp) \
33 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev))
34#define set_sb_jp_journal_dev(sbp,v) \
35 ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v))
36#define sb_jp_journal_size(sbp) \
37 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size))
38#define set_sb_jp_journal_size(sbp,v) \
39 ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v))
40#define sb_jp_journal_trans_max(sbp) \
41 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max))
42#define set_sb_jp_journal_trans_max(sbp,v) \
43 ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v))
44#define sb_jp_journal_magic(sbp) \
45 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic))
46#define set_sb_jp_journal_magic(sbp,v) \
47 ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v))
48#define sb_jp_journal_max_batch(sbp) \
49 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch))
50#define set_sb_jp_journal_max_batch(sbp,v) \
51 ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v))
52#define sb_jp_jourmal_max_commit_age(sbp) \
53 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age))
54#define set_sb_jp_journal_max_commit_age(sbp,v) \
55 ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v))
56
57#define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize))
58#define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v))
59#define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize))
60#define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v))
61#define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize))
62#define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v))
63#define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state))
64#define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v))
65#define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state))
66#define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v))
67#define sb_hash_function_code(sbp) \
68 (le32_to_cpu((sbp)->s_v1.s_hash_function_code))
69#define set_sb_hash_function_code(sbp,v) \
70 ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v))
71#define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height))
72#define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v))
73#define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr))
74#define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v))
75#define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version))
76#define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v))
77
78#define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count))
79#define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v))
80
81#define sb_reserved_for_journal(sbp) \
82 (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal))
83#define set_sb_reserved_for_journal(sbp,v) \
84 ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v))
85
86/* LOGGING -- */
87
88/* These all interelate for performance.
89**
90** If the journal block count is smaller than n transactions, you lose speed.
91** I don't know what n is yet, I'm guessing 8-16.
92**
93** typical transaction size depends on the application, how often fsync is
94** called, and how many metadata blocks you dirty in a 30 second period.
95** The more small files (<16k) you use, the larger your transactions will
96** be.
97**
98** If your journal fills faster than dirty buffers get flushed to disk, it must flush them before allowing the journal
99** to wrap, which slows things down. If you need high speed meta data updates, the journal should be big enough
100** to prevent wrapping before dirty meta blocks get to disk.
101**
102** If the batch max is smaller than the transaction max, you'll waste space at the end of the journal
103** because journal_end sets the next transaction to start at 0 if the next transaction has any chance of wrapping.
104**
105** The large the batch max age, the better the speed, and the more meta data changes you'll lose after a crash.
106**
107*/
108
109/* don't mess with these for a while */
110 /* we have a node size define somewhere in reiserfs_fs.h. -Hans */
111#define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */
112#define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */
113#define JOURNAL_HASH_SIZE 8192
114#define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */
115
116/* One of these for every block in every transaction
117** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a
118** hash of all the in memory transactions.
119** next and prev are used by the current transaction (journal_hash).
120** hnext and hprev are used by journal_list_hash. If a block is in more than one transaction, the journal_list_hash
121** links it in multiple times. This allows flush_journal_list to remove just the cnode belonging
122** to a given transaction.
123*/
124struct reiserfs_journal_cnode {
125 struct buffer_head *bh; /* real buffer head */
126 struct super_block *sb; /* dev of real buffer head */
127 __u32 blocknr; /* block number of real buffer head, == 0 when buffer on disk */
128 unsigned long state;
129 struct reiserfs_journal_list *jlist; /* journal list this cnode lives in */
130 struct reiserfs_journal_cnode *next; /* next in transaction list */
131 struct reiserfs_journal_cnode *prev; /* prev in transaction list */
132 struct reiserfs_journal_cnode *hprev; /* prev in hash list */
133 struct reiserfs_journal_cnode *hnext; /* next in hash list */
134};
135
136struct reiserfs_bitmap_node {
137 int id;
138 char *data;
139 struct list_head list;
140};
141
142struct reiserfs_list_bitmap {
143 struct reiserfs_journal_list *journal_list;
144 struct reiserfs_bitmap_node **bitmaps;
145};
146
147/*
148** one of these for each transaction. The most important part here is the j_realblock.
149** this list of cnodes is used to hash all the blocks in all the commits, to mark all the
150** real buffer heads dirty once all the commits hit the disk,
151** and to make sure every real block in a transaction is on disk before allowing the log area
152** to be overwritten */
153struct reiserfs_journal_list {
154 unsigned long j_start;
155 unsigned long j_state;
156 unsigned long j_len;
157 atomic_t j_nonzerolen;
158 atomic_t j_commit_left;
159 atomic_t j_older_commits_done; /* all commits older than this on disk */
160 struct mutex j_commit_mutex;
161 unsigned int j_trans_id;
162 time_t j_timestamp;
163 struct reiserfs_list_bitmap *j_list_bitmap;
164 struct buffer_head *j_commit_bh; /* commit buffer head */
165 struct reiserfs_journal_cnode *j_realblock;
166 struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */
167 /* time ordered list of all active transactions */
168 struct list_head j_list;
169
170 /* time ordered list of all transactions we haven't tried to flush yet */
171 struct list_head j_working_list;
172
173 /* list of tail conversion targets in need of flush before commit */
174 struct list_head j_tail_bh_list;
175 /* list of data=ordered buffers in need of flush before commit */
176 struct list_head j_bh_list;
177 int j_refcount;
178};
179
180struct reiserfs_journal {
181 struct buffer_head **j_ap_blocks; /* journal blocks on disk */
182 struct reiserfs_journal_cnode *j_last; /* newest journal block */
183 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */
184
185 struct block_device *j_dev_bd;
186 fmode_t j_dev_mode;
187 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */
188
189 unsigned long j_state;
190 unsigned int j_trans_id;
191 unsigned long j_mount_id;
192 unsigned long j_start; /* start of current waiting commit (index into j_ap_blocks) */
193 unsigned long j_len; /* length of current waiting commit */
194 unsigned long j_len_alloc; /* number of buffers requested by journal_begin() */
195 atomic_t j_wcount; /* count of writers for current commit */
196 unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */
197 unsigned long j_first_unflushed_offset; /* first unflushed transactions offset */
198 unsigned j_last_flush_trans_id; /* last fully flushed journal timestamp */
199 struct buffer_head *j_header_bh;
200
201 time_t j_trans_start_time; /* time this transaction started */
202 struct mutex j_mutex;
203 struct mutex j_flush_mutex;
204 wait_queue_head_t j_join_wait; /* wait for current transaction to finish before starting new one */
205 atomic_t j_jlock; /* lock for j_join_wait */
206 int j_list_bitmap_index; /* number of next list bitmap to use */
207 int j_must_wait; /* no more journal begins allowed. MUST sleep on j_join_wait */
208 int j_next_full_flush; /* next journal_end will flush all journal list */
209 int j_next_async_flush; /* next journal_end will flush all async commits */
210
211 int j_cnode_used; /* number of cnodes on the used list */
212 int j_cnode_free; /* number of cnodes on the free list */
213
214 unsigned int j_trans_max; /* max number of blocks in a transaction. */
215 unsigned int j_max_batch; /* max number of blocks to batch into a trans */
216 unsigned int j_max_commit_age; /* in seconds, how old can an async commit be */
217 unsigned int j_max_trans_age; /* in seconds, how old can a transaction be */
218 unsigned int j_default_max_commit_age; /* the default for the max commit age */
219
220 struct reiserfs_journal_cnode *j_cnode_free_list;
221 struct reiserfs_journal_cnode *j_cnode_free_orig; /* orig pointer returned from vmalloc */
222
223 struct reiserfs_journal_list *j_current_jl;
224 int j_free_bitmap_nodes;
225 int j_used_bitmap_nodes;
226
227 int j_num_lists; /* total number of active transactions */
228 int j_num_work_lists; /* number that need attention from kreiserfsd */
229
230 /* debugging to make sure things are flushed in order */
231 unsigned int j_last_flush_id;
232
233 /* debugging to make sure things are committed in order */
234 unsigned int j_last_commit_id;
235
236 struct list_head j_bitmap_nodes;
237 struct list_head j_dirty_buffers;
238 spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */
239
240 /* list of all active transactions */
241 struct list_head j_journal_list;
242 /* lists that haven't been touched by writeback attempts */
243 struct list_head j_working_list;
244
245 struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; /* array of bitmaps to record the deleted blocks */
246 struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; /* hash table for real buffer heads in current trans */
247 struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; /* hash table for all the real buffer heads in all
248 the transactions */
249 struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */
250 int j_persistent_trans;
251 unsigned long j_max_trans_size;
252 unsigned long j_max_batch_size;
253
254 int j_errno;
255
256 /* when flushing ordered buffers, throttle new ordered writers */
257 struct delayed_work j_work;
258 struct super_block *j_work_sb;
259 atomic_t j_async_throttle;
260};
261
262enum journal_state_bits {
263 J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */
264 J_WRITERS_QUEUED, /* set when log is full due to too many writers */
265 J_ABORTED, /* set when log is aborted */
266};
267
268#define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */
269
270typedef __u32(*hashf_t) (const signed char *, int);
271
272struct reiserfs_bitmap_info {
273 __u32 free_count;
274};
275
276struct proc_dir_entry;
277
278#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO )
279typedef unsigned long int stat_cnt_t;
280typedef struct reiserfs_proc_info_data {
281 spinlock_t lock;
282 int exiting;
283 int max_hash_collisions;
284
285 stat_cnt_t breads;
286 stat_cnt_t bread_miss;
287 stat_cnt_t search_by_key;
288 stat_cnt_t search_by_key_fs_changed;
289 stat_cnt_t search_by_key_restarted;
290
291 stat_cnt_t insert_item_restarted;
292 stat_cnt_t paste_into_item_restarted;
293 stat_cnt_t cut_from_item_restarted;
294 stat_cnt_t delete_solid_item_restarted;
295 stat_cnt_t delete_item_restarted;
296
297 stat_cnt_t leaked_oid;
298 stat_cnt_t leaves_removable;
299
300 /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */
301 stat_cnt_t balance_at[5]; /* XXX */
302 /* sbk == search_by_key */
303 stat_cnt_t sbk_read_at[5]; /* XXX */
304 stat_cnt_t sbk_fs_changed[5];
305 stat_cnt_t sbk_restarted[5];
306 stat_cnt_t items_at[5]; /* XXX */
307 stat_cnt_t free_at[5]; /* XXX */
308 stat_cnt_t can_node_be_removed[5]; /* XXX */
309 long int lnum[5]; /* XXX */
310 long int rnum[5]; /* XXX */
311 long int lbytes[5]; /* XXX */
312 long int rbytes[5]; /* XXX */
313 stat_cnt_t get_neighbors[5];
314 stat_cnt_t get_neighbors_restart[5];
315 stat_cnt_t need_l_neighbor[5];
316 stat_cnt_t need_r_neighbor[5];
317
318 stat_cnt_t free_block;
319 struct __scan_bitmap_stats {
320 stat_cnt_t call;
321 stat_cnt_t wait;
322 stat_cnt_t bmap;
323 stat_cnt_t retry;
324 stat_cnt_t in_journal_hint;
325 stat_cnt_t in_journal_nohint;
326 stat_cnt_t stolen;
327 } scan_bitmap;
328 struct __journal_stats {
329 stat_cnt_t in_journal;
330 stat_cnt_t in_journal_bitmap;
331 stat_cnt_t in_journal_reusable;
332 stat_cnt_t lock_journal;
333 stat_cnt_t lock_journal_wait;
334 stat_cnt_t journal_being;
335 stat_cnt_t journal_relock_writers;
336 stat_cnt_t journal_relock_wcount;
337 stat_cnt_t mark_dirty;
338 stat_cnt_t mark_dirty_already;
339 stat_cnt_t mark_dirty_notjournal;
340 stat_cnt_t restore_prepared;
341 stat_cnt_t prepare;
342 stat_cnt_t prepare_retry;
343 } journal;
344} reiserfs_proc_info_data_t;
345#else
346typedef struct reiserfs_proc_info_data {
347} reiserfs_proc_info_data_t;
348#endif
349
350/* reiserfs union of in-core super block data */
351struct reiserfs_sb_info {
352 struct buffer_head *s_sbh; /* Buffer containing the super block */
353 /* both the comment and the choice of
354 name are unclear for s_rs -Hans */
355 struct reiserfs_super_block *s_rs; /* Pointer to the super block in the buffer */
356 struct reiserfs_bitmap_info *s_ap_bitmap;
357 struct reiserfs_journal *s_journal; /* pointer to journal information */
358 unsigned short s_mount_state; /* reiserfs state (valid, invalid) */
359
360 /* Serialize writers access, replace the old bkl */
361 struct mutex lock;
362 /* Owner of the lock (can be recursive) */
363 struct task_struct *lock_owner;
364 /* Depth of the lock, start from -1 like the bkl */
365 int lock_depth;
366
367 /* Comment? -Hans */
368 void (*end_io_handler) (struct buffer_head *, int);
369 hashf_t s_hash_function; /* pointer to function which is used
370 to sort names in directory. Set on
371 mount */
372 unsigned long s_mount_opt; /* reiserfs's mount options are set
373 here (currently - NOTAIL, NOLOG,
374 REPLAYONLY) */
375
376 struct { /* This is a structure that describes block allocator options */
377 unsigned long bits; /* Bitfield for enable/disable kind of options */
378 unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */
379 int border; /* percentage of disk, border takes */
380 int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */
381 int preallocsize; /* Number of blocks we try to prealloc when file
382 reaches preallocmin size (in blocks) or
383 prealloc_list is empty. */
384 } s_alloc_options;
385
386 /* Comment? -Hans */
387 wait_queue_head_t s_wait;
388 /* To be obsoleted soon by per buffer seals.. -Hans */
389 atomic_t s_generation_counter; // increased by one every time the
390 // tree gets re-balanced
391 unsigned long s_properties; /* File system properties. Currently holds
392 on-disk FS format */
393
394 /* session statistics */
395 int s_disk_reads;
396 int s_disk_writes;
397 int s_fix_nodes;
398 int s_do_balance;
399 int s_unneeded_left_neighbor;
400 int s_good_search_by_key_reada;
401 int s_bmaps;
402 int s_bmaps_without_search;
403 int s_direct2indirect;
404 int s_indirect2direct;
405 /* set up when it's ok for reiserfs_read_inode2() to read from
406 disk inode with nlink==0. Currently this is only used during
407 finish_unfinished() processing at mount time */
408 int s_is_unlinked_ok;
409 reiserfs_proc_info_data_t s_proc_info_data;
410 struct proc_dir_entry *procdir;
411 int reserved_blocks; /* amount of blocks reserved for further allocations */
412 spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */
413 struct dentry *priv_root; /* root of /.reiserfs_priv */
414 struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */
415 int j_errno;
416#ifdef CONFIG_QUOTA
417 char *s_qf_names[MAXQUOTAS];
418 int s_jquota_fmt;
419#endif
420 char *s_jdev; /* Stored jdev for mount option showing */
421#ifdef CONFIG_REISERFS_CHECK
422
423 struct tree_balance *cur_tb; /*
424 * Detects whether more than one
425 * copy of tb exists per superblock
426 * as a means of checking whether
427 * do_balance is executing concurrently
428 * against another tree reader/writer
429 * on a same mount point.
430 */
431#endif
432};
433
434/* Definitions of reiserfs on-disk properties: */
435#define REISERFS_3_5 0
436#define REISERFS_3_6 1
437#define REISERFS_OLD_FORMAT 2
438
439enum reiserfs_mount_options {
440/* Mount options */
441 REISERFS_LARGETAIL, /* large tails will be created in a session */
442 REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */
443 REPLAYONLY, /* replay journal and return 0. Use by fsck */
444 REISERFS_CONVERT, /* -o conv: causes conversion of old
445 format super block to the new
446 format. If not specified - old
447 partition will be dealt with in a
448 manner of 3.5.x */
449
450/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting
451** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option
452** is not required. If the normal autodection code can't determine which
453** hash to use (because both hashes had the same value for a file)
454** use this option to force a specific hash. It won't allow you to override
455** the existing hash on the FS, so if you have a tea hash disk, and mount
456** with -o hash=rupasov, the mount will fail.
457*/
458 FORCE_TEA_HASH, /* try to force tea hash on mount */
459 FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */
460 FORCE_R5_HASH, /* try to force rupasov hash on mount */
461 FORCE_HASH_DETECT, /* try to detect hash function on mount */
462
463 REISERFS_DATA_LOG,
464 REISERFS_DATA_ORDERED,
465 REISERFS_DATA_WRITEBACK,
466
467/* used for testing experimental features, makes benchmarking new
468 features with and without more convenient, should never be used by
469 users in any code shipped to users (ideally) */
470
471 REISERFS_NO_BORDER,
472 REISERFS_NO_UNHASHED_RELOCATION,
473 REISERFS_HASHED_RELOCATION,
474 REISERFS_ATTRS,
475 REISERFS_XATTRS_USER,
476 REISERFS_POSIXACL,
477 REISERFS_EXPOSE_PRIVROOT,
478 REISERFS_BARRIER_NONE,
479 REISERFS_BARRIER_FLUSH,
480
481 /* Actions on error */
482 REISERFS_ERROR_PANIC,
483 REISERFS_ERROR_RO,
484 REISERFS_ERROR_CONTINUE,
485
486 REISERFS_USRQUOTA, /* User quota option specified */
487 REISERFS_GRPQUOTA, /* Group quota option specified */
488
489 REISERFS_TEST1,
490 REISERFS_TEST2,
491 REISERFS_TEST3,
492 REISERFS_TEST4,
493 REISERFS_UNSUPPORTED_OPT,
494};
495
496#define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH))
497#define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH))
498#define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH))
499#define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT))
500#define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER))
501#define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION))
502#define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION))
503#define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4))
504
505#define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL))
506#define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL))
507#define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY))
508#define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS))
509#define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5))
510#define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT))
511#define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
512#define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
513#define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
514#define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
515#define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
516#define reiserfs_expose_privroot(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_EXPOSE_PRIVROOT))
517#define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
518#define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE))
519#define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH))
520
521#define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC))
522#define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO))
523
524void reiserfs_file_buffer(struct buffer_head *bh, int list);
525extern struct file_system_type reiserfs_fs_type;
526int reiserfs_resize(struct super_block *, unsigned long);
527
528#define CARRY_ON 0
529#define SCHEDULE_OCCURRED 1
530
531#define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh)
532#define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal)
533#define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block)
534#define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free)
535#define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap)
536
537#define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->)
538
539/* A safe version of the "bdevname", which returns the "s_id" field of
540 * a superblock or else "Null superblock" if the super block is NULL.
541 */
542static inline char *reiserfs_bdevname(struct super_block *s)
543{
544 return (s == NULL) ? "Null superblock" : s->s_id;
545}
546
547#define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal)))
548static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal
549 *journal)
550{
551 return test_bit(J_ABORTED, &journal->j_state);
552}
553
554#endif /* _LINUX_REISER_FS_SB */
diff --git a/include/linux/reiserfs_xattr.h b/include/linux/reiserfs_xattr.h
index c2b71473266e..d8ce17c2459a 100644
--- a/include/linux/reiserfs_xattr.h
+++ b/include/linux/reiserfs_xattr.h
@@ -21,132 +21,4 @@ struct reiserfs_security_handle {
21 size_t length; 21 size_t length;
22}; 22};
23 23
24#ifdef __KERNEL__
25
26#include <linux/init.h>
27#include <linux/list.h>
28#include <linux/rwsem.h>
29#include <linux/reiserfs_fs_i.h>
30#include <linux/reiserfs_fs.h>
31
32struct inode;
33struct dentry;
34struct iattr;
35struct super_block;
36struct nameidata;
37
38int reiserfs_xattr_register_handlers(void) __init;
39void reiserfs_xattr_unregister_handlers(void);
40int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
41int reiserfs_lookup_privroot(struct super_block *sb);
42int reiserfs_delete_xattrs(struct inode *inode);
43int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
44int reiserfs_permission(struct inode *inode, int mask);
45
46#ifdef CONFIG_REISERFS_FS_XATTR
47#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
48ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name,
49 void *buffer, size_t size);
50int reiserfs_setxattr(struct dentry *dentry, const char *name,
51 const void *value, size_t size, int flags);
52ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
53int reiserfs_removexattr(struct dentry *dentry, const char *name);
54
55int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
56int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
57int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
58 struct inode *, const char *, const void *,
59 size_t, int);
60
61extern const struct xattr_handler reiserfs_xattr_user_handler;
62extern const struct xattr_handler reiserfs_xattr_trusted_handler;
63extern const struct xattr_handler reiserfs_xattr_security_handler;
64#ifdef CONFIG_REISERFS_FS_SECURITY
65int reiserfs_security_init(struct inode *dir, struct inode *inode,
66 const struct qstr *qstr,
67 struct reiserfs_security_handle *sec);
68int reiserfs_security_write(struct reiserfs_transaction_handle *th,
69 struct inode *inode,
70 struct reiserfs_security_handle *sec);
71void reiserfs_security_free(struct reiserfs_security_handle *sec);
72#endif
73
74static inline int reiserfs_xattrs_initialized(struct super_block *sb)
75{
76 return REISERFS_SB(sb)->priv_root != NULL;
77}
78
79#define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
80static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
81{
82 loff_t ret = 0;
83 if (reiserfs_file_data_log(inode)) {
84 ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
85 ret >>= inode->i_sb->s_blocksize_bits;
86 }
87 return ret;
88}
89
90/* We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
91 * Let's try to be smart about it.
92 * xattr root: We cache it. If it's not cached, we may need to create it.
93 * xattr dir: If anything has been loaded for this inode, we can set a flag
94 * saying so.
95 * xattr file: Since we don't cache xattrs, we can't tell. We always include
96 * blocks for it.
97 *
98 * However, since root and dir can be created between calls - YOU MUST SAVE
99 * THIS VALUE.
100 */
101static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
102{
103 size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
104
105 if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
106 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
107 if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode)
108 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
109 }
110
111 return nblocks;
112}
113
114static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
115{
116 init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
117}
118
119#else
120
121#define reiserfs_getxattr NULL
122#define reiserfs_setxattr NULL
123#define reiserfs_listxattr NULL
124#define reiserfs_removexattr NULL
125
126static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
127{
128}
129#endif /* CONFIG_REISERFS_FS_XATTR */
130
131#ifndef CONFIG_REISERFS_FS_SECURITY
132static inline int reiserfs_security_init(struct inode *dir,
133 struct inode *inode,
134 const struct qstr *qstr,
135 struct reiserfs_security_handle *sec)
136{
137 return 0;
138}
139static inline int
140reiserfs_security_write(struct reiserfs_transaction_handle *th,
141 struct inode *inode,
142 struct reiserfs_security_handle *sec)
143{
144 return 0;
145}
146static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
147{}
148#endif
149
150#endif /* __KERNEL__ */
151
152#endif /* _LINUX_REISERFS_XATTR_H */ 24#endif /* _LINUX_REISERFS_XATTR_H */
diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h
index 7dadc3df0c77..a32d86ec8bf2 100644
--- a/include/linux/trace_seq.h
+++ b/include/linux/trace_seq.h
@@ -44,7 +44,7 @@ extern int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len);
44extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, 44extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
45 size_t len); 45 size_t len);
46extern void *trace_seq_reserve(struct trace_seq *s, size_t len); 46extern void *trace_seq_reserve(struct trace_seq *s, size_t len);
47extern int trace_seq_path(struct trace_seq *s, struct path *path); 47extern int trace_seq_path(struct trace_seq *s, const struct path *path);
48 48
49#else /* CONFIG_TRACING */ 49#else /* CONFIG_TRACING */
50static inline int trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 50static inline int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
@@ -88,7 +88,7 @@ static inline void *trace_seq_reserve(struct trace_seq *s, size_t len)
88{ 88{
89 return NULL; 89 return NULL;
90} 90}
91static inline int trace_seq_path(struct trace_seq *s, struct path *path) 91static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
92{ 92{
93 return 0; 93 return 0;
94} 94}
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index 5a4e29b168c9..ca68e2cef230 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -49,8 +49,7 @@ struct unix_sock {
49 /* WARNING: sk has to be the first member */ 49 /* WARNING: sk has to be the first member */
50 struct sock sk; 50 struct sock sk;
51 struct unix_address *addr; 51 struct unix_address *addr;
52 struct dentry *dentry; 52 struct path path;
53 struct vfsmount *mnt;
54 struct mutex readlock; 53 struct mutex readlock;
55 struct sock *peer; 54 struct sock *peer;
56 struct sock *other; 55 struct sock *other;
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 86ee272de210..28bd64ddeda3 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -188,30 +188,20 @@ static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
188{ 188{
189 struct inode *inode; 189 struct inode *inode;
190 struct ipc_namespace *ns = data; 190 struct ipc_namespace *ns = data;
191 int error;
192 191
193 sb->s_blocksize = PAGE_CACHE_SIZE; 192 sb->s_blocksize = PAGE_CACHE_SIZE;
194 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 193 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
195 sb->s_magic = MQUEUE_MAGIC; 194 sb->s_magic = MQUEUE_MAGIC;
196 sb->s_op = &mqueue_super_ops; 195 sb->s_op = &mqueue_super_ops;
197 196
198 inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO, 197 inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO, NULL);
199 NULL); 198 if (IS_ERR(inode))
200 if (IS_ERR(inode)) { 199 return PTR_ERR(inode);
201 error = PTR_ERR(inode);
202 goto out;
203 }
204 200
205 sb->s_root = d_alloc_root(inode); 201 sb->s_root = d_make_root(inode);
206 if (!sb->s_root) { 202 if (!sb->s_root)
207 iput(inode); 203 return -ENOMEM;
208 error = -ENOMEM; 204 return 0;
209 goto out;
210 }
211 error = 0;
212
213out:
214 return error;
215} 205}
216 206
217static struct dentry *mqueue_mount(struct file_system_type *fs_type, 207static struct dentry *mqueue_mount(struct file_system_type *fs_type,
diff --git a/kernel/audit.c b/kernel/audit.c
index bb0eb5bb9a0a..1c7f2c61416b 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1418,7 +1418,7 @@ void audit_log_untrustedstring(struct audit_buffer *ab, const char *string)
1418 1418
1419/* This is a helper-function to print the escaped d_path */ 1419/* This is a helper-function to print the escaped d_path */
1420void audit_log_d_path(struct audit_buffer *ab, const char *prefix, 1420void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
1421 struct path *path) 1421 const struct path *path)
1422{ 1422{
1423 char *p, *pathname; 1423 char *p, *pathname;
1424 1424
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c6877fe9a831..1ece8e20fdb5 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1472,7 +1472,6 @@ static int cgroup_get_rootdir(struct super_block *sb)
1472 1472
1473 struct inode *inode = 1473 struct inode *inode =
1474 cgroup_new_inode(S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR, sb); 1474 cgroup_new_inode(S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR, sb);
1475 struct dentry *dentry;
1476 1475
1477 if (!inode) 1476 if (!inode)
1478 return -ENOMEM; 1477 return -ENOMEM;
@@ -1481,12 +1480,9 @@ static int cgroup_get_rootdir(struct super_block *sb)
1481 inode->i_op = &cgroup_dir_inode_operations; 1480 inode->i_op = &cgroup_dir_inode_operations;
1482 /* directories start off with i_nlink == 2 (for "." entry) */ 1481 /* directories start off with i_nlink == 2 (for "." entry) */
1483 inc_nlink(inode); 1482 inc_nlink(inode);
1484 dentry = d_alloc_root(inode); 1483 sb->s_root = d_make_root(inode);
1485 if (!dentry) { 1484 if (!sb->s_root)
1486 iput(inode);
1487 return -ENOMEM; 1485 return -ENOMEM;
1488 }
1489 sb->s_root = dentry;
1490 /* for everything else we want ->d_op set */ 1486 /* for everything else we want ->d_op set */
1491 sb->s_d_op = &cgroup_dops; 1487 sb->s_d_op = &cgroup_dops;
1492 return 0; 1488 return 0;
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index c5a01873567d..859fae6b1825 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -264,7 +264,7 @@ void *trace_seq_reserve(struct trace_seq *s, size_t len)
264 return ret; 264 return ret;
265} 265}
266 266
267int trace_seq_path(struct trace_seq *s, struct path *path) 267int trace_seq_path(struct trace_seq *s, const struct path *path)
268{ 268{
269 unsigned char *p; 269 unsigned char *p;
270 270
diff --git a/mm/shmem.c b/mm/shmem.c
index 78307d5c5bd9..7a45ad004cfd 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2175,7 +2175,6 @@ static void shmem_put_super(struct super_block *sb)
2175int shmem_fill_super(struct super_block *sb, void *data, int silent) 2175int shmem_fill_super(struct super_block *sb, void *data, int silent)
2176{ 2176{
2177 struct inode *inode; 2177 struct inode *inode;
2178 struct dentry *root;
2179 struct shmem_sb_info *sbinfo; 2178 struct shmem_sb_info *sbinfo;
2180 int err = -ENOMEM; 2179 int err = -ENOMEM;
2181 2180
@@ -2232,14 +2231,11 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
2232 goto failed; 2231 goto failed;
2233 inode->i_uid = sbinfo->uid; 2232 inode->i_uid = sbinfo->uid;
2234 inode->i_gid = sbinfo->gid; 2233 inode->i_gid = sbinfo->gid;
2235 root = d_alloc_root(inode); 2234 sb->s_root = d_make_root(inode);
2236 if (!root) 2235 if (!sb->s_root)
2237 goto failed_iput; 2236 goto failed;
2238 sb->s_root = root;
2239 return 0; 2237 return 0;
2240 2238
2241failed_iput:
2242 iput(inode);
2243failed: 2239failed:
2244 shmem_put_super(sb); 2240 shmem_put_super(sb);
2245 return err; 2241 return err;
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 63a7a7add21e..7d6dd6efbdbe 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -1033,13 +1033,9 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
1033 sb->s_time_gran = 1; 1033 sb->s_time_gran = 1;
1034 1034
1035 inode = rpc_get_inode(sb, S_IFDIR | 0755); 1035 inode = rpc_get_inode(sb, S_IFDIR | 0755);
1036 if (!inode) 1036 sb->s_root = root = d_make_root(inode);
1037 return -ENOMEM; 1037 if (!root)
1038 sb->s_root = root = d_alloc_root(inode);
1039 if (!root) {
1040 iput(inode);
1041 return -ENOMEM; 1038 return -ENOMEM;
1042 }
1043 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) 1039 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
1044 return -ENOMEM; 1040 return -ENOMEM;
1045 return 0; 1041 return 0;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 8ee85aa79fa7..eb4277c33188 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -293,7 +293,7 @@ static struct sock *unix_find_socket_byinode(struct inode *i)
293 spin_lock(&unix_table_lock); 293 spin_lock(&unix_table_lock);
294 sk_for_each(s, node, 294 sk_for_each(s, node,
295 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) { 295 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
296 struct dentry *dentry = unix_sk(s)->dentry; 296 struct dentry *dentry = unix_sk(s)->path.dentry;
297 297
298 if (dentry && dentry->d_inode == i) { 298 if (dentry && dentry->d_inode == i) {
299 sock_hold(s); 299 sock_hold(s);
@@ -377,8 +377,7 @@ static void unix_sock_destructor(struct sock *sk)
377static int unix_release_sock(struct sock *sk, int embrion) 377static int unix_release_sock(struct sock *sk, int embrion)
378{ 378{
379 struct unix_sock *u = unix_sk(sk); 379 struct unix_sock *u = unix_sk(sk);
380 struct dentry *dentry; 380 struct path path;
381 struct vfsmount *mnt;
382 struct sock *skpair; 381 struct sock *skpair;
383 struct sk_buff *skb; 382 struct sk_buff *skb;
384 int state; 383 int state;
@@ -389,10 +388,9 @@ static int unix_release_sock(struct sock *sk, int embrion)
389 unix_state_lock(sk); 388 unix_state_lock(sk);
390 sock_orphan(sk); 389 sock_orphan(sk);
391 sk->sk_shutdown = SHUTDOWN_MASK; 390 sk->sk_shutdown = SHUTDOWN_MASK;
392 dentry = u->dentry; 391 path = u->path;
393 u->dentry = NULL; 392 u->path.dentry = NULL;
394 mnt = u->mnt; 393 u->path.mnt = NULL;
395 u->mnt = NULL;
396 state = sk->sk_state; 394 state = sk->sk_state;
397 sk->sk_state = TCP_CLOSE; 395 sk->sk_state = TCP_CLOSE;
398 unix_state_unlock(sk); 396 unix_state_unlock(sk);
@@ -425,10 +423,8 @@ static int unix_release_sock(struct sock *sk, int embrion)
425 kfree_skb(skb); 423 kfree_skb(skb);
426 } 424 }
427 425
428 if (dentry) { 426 if (path.dentry)
429 dput(dentry); 427 path_put(&path);
430 mntput(mnt);
431 }
432 428
433 sock_put(sk); 429 sock_put(sk);
434 430
@@ -641,8 +637,8 @@ static struct sock *unix_create1(struct net *net, struct socket *sock)
641 sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen; 637 sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen;
642 sk->sk_destruct = unix_sock_destructor; 638 sk->sk_destruct = unix_sock_destructor;
643 u = unix_sk(sk); 639 u = unix_sk(sk);
644 u->dentry = NULL; 640 u->path.dentry = NULL;
645 u->mnt = NULL; 641 u->path.mnt = NULL;
646 spin_lock_init(&u->lock); 642 spin_lock_init(&u->lock);
647 atomic_long_set(&u->inflight, 0); 643 atomic_long_set(&u->inflight, 0);
648 INIT_LIST_HEAD(&u->link); 644 INIT_LIST_HEAD(&u->link);
@@ -788,7 +784,7 @@ static struct sock *unix_find_other(struct net *net,
788 goto put_fail; 784 goto put_fail;
789 785
790 if (u->sk_type == type) 786 if (u->sk_type == type)
791 touch_atime(path.mnt, path.dentry); 787 touch_atime(&path);
792 788
793 path_put(&path); 789 path_put(&path);
794 790
@@ -802,9 +798,9 @@ static struct sock *unix_find_other(struct net *net,
802 u = unix_find_socket_byname(net, sunname, len, type, hash); 798 u = unix_find_socket_byname(net, sunname, len, type, hash);
803 if (u) { 799 if (u) {
804 struct dentry *dentry; 800 struct dentry *dentry;
805 dentry = unix_sk(u)->dentry; 801 dentry = unix_sk(u)->path.dentry;
806 if (dentry) 802 if (dentry)
807 touch_atime(unix_sk(u)->mnt, dentry); 803 touch_atime(&unix_sk(u)->path);
808 } else 804 } else
809 goto fail; 805 goto fail;
810 } 806 }
@@ -910,8 +906,7 @@ out_mknod_drop_write:
910 list = &unix_socket_table[addr->hash]; 906 list = &unix_socket_table[addr->hash];
911 } else { 907 } else {
912 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)]; 908 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
913 u->dentry = path.dentry; 909 u->path = path;
914 u->mnt = path.mnt;
915 } 910 }
916 911
917 err = 0; 912 err = 0;
@@ -1193,9 +1188,9 @@ restart:
1193 atomic_inc(&otheru->addr->refcnt); 1188 atomic_inc(&otheru->addr->refcnt);
1194 newu->addr = otheru->addr; 1189 newu->addr = otheru->addr;
1195 } 1190 }
1196 if (otheru->dentry) { 1191 if (otheru->path.dentry) {
1197 newu->dentry = dget(otheru->dentry); 1192 path_get(&otheru->path);
1198 newu->mnt = mntget(otheru->mnt); 1193 newu->path = otheru->path;
1199 } 1194 }
1200 1195
1201 /* Set credentials */ 1196 /* Set credentials */
diff --git a/net/unix/diag.c b/net/unix/diag.c
index 4195555aea65..f0486ae9ebe6 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -29,7 +29,7 @@ rtattr_failure:
29 29
30static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) 30static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb)
31{ 31{
32 struct dentry *dentry = unix_sk(sk)->dentry; 32 struct dentry *dentry = unix_sk(sk)->path.dentry;
33 struct unix_diag_vfs *uv; 33 struct unix_diag_vfs *uv;
34 34
35 if (dentry) { 35 if (dentry) {
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 293b8c45b1d1..8b8f0902f6e5 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -313,12 +313,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
313 } 313 }
314 case AF_UNIX: 314 case AF_UNIX:
315 u = unix_sk(sk); 315 u = unix_sk(sk);
316 if (u->dentry) { 316 if (u->path.dentry) {
317 struct path path = { 317 audit_log_d_path(ab, " path=", &u->path);
318 .dentry = u->dentry,
319 .mnt = u->mnt
320 };
321 audit_log_d_path(ab, " path=", &path);
322 break; 318 break;
323 } 319 }
324 if (!u->addr) 320 if (!u->addr)