1 Documentation/filesystems/ext2.txt | 16 ++
3 fs/ext3/iopen.c | 239 +++++++++++++++++++++++++++++++++++++
4 fs/ext3/iopen.h | 15 ++
5 fs/ext3/namei.c | 13 ++
6 fs/ext3/super.c | 17 ++
7 include/linux/ext3_fs.h | 2
8 7 files changed, 304 insertions(+), 1 deletion(-)
10 Index: linux-2.6.3-mm4/Documentation/filesystems/ext2.txt
11 ===================================================================
12 --- linux-2.6.3-mm4.orig/Documentation/filesystems/ext2.txt 2004-01-09 14:59:18.000000000 +0800
13 +++ linux-2.6.3-mm4/Documentation/filesystems/ext2.txt 2004-03-08 14:58:44.431196112 +0800
16 sb=n Use alternate superblock at this location.
18 +iopen Makes an invisible pseudo-directory called
19 + __iopen__ available in the root directory
20 + of the filesystem. Allows open-by-inode-
21 + number. i.e., inode 3145 can be accessed
22 + via /mntpt/__iopen__/3145
24 +iopen_nopriv This option makes the iopen directory be
25 + world-readable. This may be safer since it
26 + allows daemons to run as an unprivileged user,
27 + however it significantly changes the security
28 + model of a Unix filesystem, since previously
29 + all files under a mode 700 directory were not
30 + generally avilable even if the
31 + permissions on the file itself is
34 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
37 Index: linux-2.6.3-mm4/fs/ext3/inode.c
38 ===================================================================
39 --- linux-2.6.3-mm4.orig/fs/ext3/inode.c 2004-03-08 14:57:54.969715400 +0800
40 +++ linux-2.6.3-mm4/fs/ext3/inode.c 2004-03-08 14:58:44.504185016 +0800
42 #include <linux/mpage.h>
43 #include <linux/uio.h>
50 ei->i_acl = EXT3_ACL_NOT_CACHED;
51 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
53 + if (ext3_iopen_get_inode(inode))
55 if (ext3_get_inode_loc(inode, &iloc, 0))
58 Index: linux-2.6.3-mm4/fs/ext3/iopen.c
59 ===================================================================
60 --- linux-2.6.3-mm4.orig/fs/ext3/iopen.c 2004-03-08 14:58:44.413198848 +0800
61 +++ linux-2.6.3-mm4/fs/ext3/iopen.c 2004-03-08 14:58:44.576174072 +0800
64 + * linux/fs/ext3/iopen.c
66 + * Special support for open by inode number
68 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
70 + * This file may be redistributed under the terms of the GNU General
74 +#include <linux/sched.h>
75 +#include <linux/fs.h>
76 +#include <linux/ext3_jbd.h>
77 +#include <linux/jbd.h>
78 +#include <linux/ext3_fs.h>
79 +#include <linux/smp_lock.h>
83 +#define assert(test) J_ASSERT(test)
86 +#define IOPEN_NAME_LEN 32
89 + * This implements looking up an inode by number.
91 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry,
92 + struct nameidata *nd)
94 + struct inode * inode;
96 + struct list_head *lp;
97 + struct dentry *alternate;
98 + char buf[IOPEN_NAME_LEN];
100 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
101 + return ERR_PTR(-ENAMETOOLONG);
103 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
104 + buf[dentry->d_name.len] = 0;
106 + if (strcmp(buf, ".") == 0)
108 + else if (strcmp(buf, "..") == 0)
109 + ino = EXT3_ROOT_INO;
111 + ino = simple_strtoul(buf, 0, 0);
113 + if ((ino != EXT3_ROOT_INO && ino < EXT3_FIRST_INO(dir->i_sb)) ||
114 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
115 + return ERR_PTR(-ENOENT);
117 + inode = iget(dir->i_sb, ino);
119 + return ERR_PTR(-EACCES);
120 + if (is_bad_inode(inode)) {
122 + return ERR_PTR(-ENOENT);
125 + /* preferrably return a connected dentry */
126 + spin_lock(&dcache_lock);
127 + list_for_each(lp, &inode->i_dentry) {
128 + alternate = list_entry(lp, struct dentry, d_alias);
129 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
132 + if (!list_empty(&inode->i_dentry)) {
133 + alternate = list_entry(inode->i_dentry.next,
134 + struct dentry, d_alias);
135 + dget_locked(alternate);
136 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
138 + spin_unlock(&dcache_lock);
141 + dentry->d_flags |= DCACHE_DISCONNECTED;
142 + spin_unlock(&dcache_lock);
144 + d_add(dentry, inode);
148 +#define do_switch(x,y) do { \
149 + __typeof__ (x) __tmp = x; \
150 + x = y; y = __tmp; } while (0)
152 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
154 + const unsigned char *old_name, *new_name;
156 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
157 + old_name = target->d_name.name;
158 + new_name = dentry->d_name.name;
159 + if (old_name == target->d_iname)
160 + old_name = dentry->d_iname;
161 + if (new_name == dentry->d_iname)
162 + new_name = target->d_iname;
163 + target->d_name.name = new_name;
164 + dentry->d_name.name = old_name;
168 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
170 + struct dentry *tmp, *goal = NULL;
171 + struct list_head *lp;
173 + /* preferrably return a connected dentry */
174 + spin_lock(&dcache_lock);
175 + /* verify this dentry is really new */
176 + assert(!de->d_inode);
177 + assert(list_empty(&de->d_subdirs));
178 + assert(list_empty(&de->d_alias));
180 + list_for_each(lp, &inode->i_dentry) {
181 + tmp = list_entry(lp, struct dentry, d_alias);
182 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
183 + assert(tmp->d_alias.next == &inode->i_dentry);
184 + assert(tmp->d_alias.prev == &inode->i_dentry);
190 + spin_unlock(&dcache_lock);
195 + goal->d_flags &= ~DCACHE_DISCONNECTED;
203 + * These are the special structures for the iopen pseudo directory.
206 +static struct inode_operations iopen_inode_operations = {
207 + lookup: iopen_lookup, /* BKL held */
210 +static struct file_operations iopen_file_operations = {
211 + read: generic_read_dir,
214 +static int match_dentry(struct dentry *dentry, const char *name)
218 + len = strlen(name);
219 + if (dentry->d_name.len != len)
221 + if (strncmp(dentry->d_name.name, name, len))
227 + * This function is spliced into ext3_lookup and returns 1 the file
228 + * name is __iopen__ and dentry has been filled in appropriately.
230 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
232 + struct inode * inode;
234 + if (dir->i_ino != EXT3_ROOT_INO ||
235 + !test_opt(dir->i_sb, IOPEN) ||
236 + !match_dentry(dentry, "__iopen__"))
239 + inode = iget(dir->i_sb, EXT3_BAD_INO);
243 + d_add(dentry, inode);
248 + * This function is spliced into read_inode; it returns 1 if inode
249 + * number is the one for /__iopen__, in which case the inode is filled
250 + * in appropriately. Otherwise, this fuction returns 0.
252 +int ext3_iopen_get_inode(struct inode * inode)
254 + if (inode->i_ino != EXT3_BAD_INO)
257 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
258 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
259 + inode->i_mode |= 0777;
262 + inode->i_nlink = 1;
263 + inode->i_size = 4096;
264 + inode->i_atime = CURRENT_TIME;
265 + inode->i_ctime = CURRENT_TIME;
266 + inode->i_mtime = CURRENT_TIME;
267 + EXT3_I(inode)->i_dtime = 0;
268 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
269 + * (for stat), not the fs block
271 + inode->i_blocks = 0;
272 + inode->i_version = 1;
273 + inode->i_generation = 0;
275 + inode->i_op = &iopen_inode_operations;
276 + inode->i_fop = &iopen_file_operations;
277 + inode->i_mapping->a_ops = 0;
281 Index: linux-2.6.3-mm4/fs/ext3/iopen.h
282 ===================================================================
283 --- linux-2.6.3-mm4.orig/fs/ext3/iopen.h 2004-03-08 14:58:44.413198848 +0800
284 +++ linux-2.6.3-mm4/fs/ext3/iopen.h 2004-03-08 14:58:44.577173920 +0800
289 + * Special support for opening files by inode number.
291 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
293 + * This file may be redistributed under the terms of the GNU General
297 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
298 +extern int ext3_iopen_get_inode(struct inode * inode);
301 Index: linux-2.6.3-mm4/fs/ext3/namei.c
302 ===================================================================
303 --- linux-2.6.3-mm4.orig/fs/ext3/namei.c 2004-03-08 14:57:52.978018184 +0800
304 +++ linux-2.6.3-mm4/fs/ext3/namei.c 2004-03-08 14:58:44.648163128 +0800
306 #include <linux/buffer_head.h>
307 #include <linux/smp_lock.h>
313 @@ -970,15 +971,21 @@
317 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
319 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
321 struct inode * inode;
322 struct ext3_dir_entry_2 * de;
323 struct buffer_head * bh;
324 + struct dentry *alternate = NULL;
326 if (dentry->d_name.len > EXT3_NAME_LEN)
327 return ERR_PTR(-ENAMETOOLONG);
329 + if (ext3_check_for_iopen(dir, dentry))
332 bh = ext3_find_entry(dentry, &de);
337 return ERR_PTR(-EACCES);
339 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
345 return d_splice_alias(inode, dentry);
347 d_add(dentry, inode);
350 Index: linux-2.6.3-mm4/fs/ext3/super.c
351 ===================================================================
352 --- linux-2.6.3-mm4.orig/fs/ext3/super.c 2004-03-08 14:57:55.049703240 +0800
353 +++ linux-2.6.3-mm4/fs/ext3/super.c 2004-03-08 15:03:18.310560120 +0800
355 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
356 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
357 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
358 - Opt_ignore, Opt_err,
359 + Opt_ignore, Opt_err, Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
362 static match_table_t tokens = {
364 {Opt_ignore, "noquota"},
365 {Opt_ignore, "quota"},
366 {Opt_ignore, "usrquota"},
367 + {Opt_iopen, "iopen"},
368 + {Opt_noiopen, "noiopen"},
369 + {Opt_iopen_nopriv, "iopen_nopriv"},
375 set_opt(sbi->s_mount_opt, ABORT);
378 + set_opt (sbi->s_mount_opt, IOPEN);
379 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
382 + clear_opt (sbi->s_mount_opt, IOPEN);
383 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
385 + case Opt_iopen_nopriv:
386 + set_opt (sbi->s_mount_opt, IOPEN);
387 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
392 Index: linux-2.6.3-mm4/fs/ext3/Makefile
393 ===================================================================
394 --- linux-2.6.3-mm4.orig/fs/ext3/Makefile 2004-01-09 14:59:08.000000000 +0800
395 +++ linux-2.6.3-mm4/fs/ext3/Makefile 2004-03-08 14:58:44.794140936 +0800
397 obj-$(CONFIG_EXT3_FS) += ext3.o
399 ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
400 - ioctl.o namei.o super.o symlink.o hash.o
401 + ioctl.o namei.o super.o symlink.o hash.o iopen.o
403 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
404 ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
405 Index: linux-2.6.3-mm4/include/linux/ext3_fs.h
406 ===================================================================
407 --- linux-2.6.3-mm4.orig/include/linux/ext3_fs.h 2004-03-08 14:57:53.057006176 +0800
408 +++ linux-2.6.3-mm4/include/linux/ext3_fs.h 2004-03-08 14:58:44.795140784 +0800
410 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
411 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
412 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
413 +#define EXT3_MOUNT_IOPEN 0x10000 /* Allow access via iopen */
414 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x20000 /* Make iopen world-readable */
416 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
417 #ifndef _LINUX_EXT2_FS_H