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.0/Documentation/filesystems/ext2.txt
11 ===================================================================
12 --- linux-2.6.0.orig/Documentation/filesystems/ext2.txt 2002-11-11 06:28:06.000000000 +0300
13 +++ linux-2.6.0/Documentation/filesystems/ext2.txt 2004-01-07 17:12:07.000000000 +0300
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.0/fs/ext3/inode.c
38 ===================================================================
39 --- linux-2.6.0.orig/fs/ext3/inode.c 2004-01-04 15:27:40.000000000 +0300
40 +++ linux-2.6.0/fs/ext3/inode.c 2004-01-07 17:12:07.000000000 +0300
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.0/fs/ext3/iopen.c
59 ===================================================================
60 --- linux-2.6.0.orig/fs/ext3/iopen.c 2003-01-30 13:24:37.000000000 +0300
61 +++ linux-2.6.0/fs/ext3/iopen.c 2004-01-07 17:14:22.000000000 +0300
66 + * linux/fs/ext3/iopen.c
68 + * Special support for open by inode number
70 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
72 + * This file may be redistributed under the terms of the GNU General
76 +#include <linux/sched.h>
77 +#include <linux/fs.h>
78 +#include <linux/ext3_jbd.h>
79 +#include <linux/jbd.h>
80 +#include <linux/ext3_fs.h>
81 +#include <linux/smp_lock.h>
85 +#define assert(test) J_ASSERT(test)
88 +#define IOPEN_NAME_LEN 32
91 + * This implements looking up an inode by number.
93 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
95 + struct inode * inode;
97 + struct list_head *lp;
98 + struct dentry *alternate;
99 + char buf[IOPEN_NAME_LEN];
101 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
102 + return ERR_PTR(-ENAMETOOLONG);
104 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
105 + buf[dentry->d_name.len] = 0;
107 + if (strcmp(buf, ".") == 0)
109 + else if (strcmp(buf, "..") == 0)
110 + ino = EXT3_ROOT_INO;
112 + ino = simple_strtoul(buf, 0, 0);
114 + if ((ino != EXT3_ROOT_INO &&
115 + //ino != EXT3_ACL_IDX_INO &&
116 + //ino != EXT3_ACL_DATA_INO &&
117 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
118 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
119 + return ERR_PTR(-ENOENT);
121 + inode = iget(dir->i_sb, ino);
123 + return ERR_PTR(-EACCES);
124 + if (is_bad_inode(inode)) {
126 + return ERR_PTR(-ENOENT);
129 + /* preferrably return a connected dentry */
130 + spin_lock(&dcache_lock);
131 + list_for_each(lp, &inode->i_dentry) {
132 + alternate = list_entry(lp, struct dentry, d_alias);
133 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
136 + if (!list_empty(&inode->i_dentry)) {
137 + alternate = list_entry(inode->i_dentry.next,
138 + struct dentry, d_alias);
139 + dget_locked(alternate);
140 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
142 + spin_unlock(&dcache_lock);
145 + dentry->d_flags |= DCACHE_DISCONNECTED;
146 + spin_unlock(&dcache_lock);
148 + d_add(dentry, inode);
152 +#define do_switch(x,y) do { \
153 + __typeof__ (x) __tmp = x; \
154 + x = y; y = __tmp; } while (0)
156 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
158 + const unsigned char *old_name, *new_name;
160 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
161 + old_name = target->d_name.name;
162 + new_name = dentry->d_name.name;
163 + if (old_name == target->d_iname)
164 + old_name = dentry->d_iname;
165 + if (new_name == dentry->d_iname)
166 + new_name = target->d_iname;
167 + target->d_name.name = new_name;
168 + dentry->d_name.name = old_name;
172 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
174 + struct dentry *tmp, *goal = NULL;
175 + struct list_head *lp;
177 + /* preferrably return a connected dentry */
178 + spin_lock(&dcache_lock);
179 + /* verify this dentry is really new */
180 + assert(!de->d_inode);
181 + assert(list_empty(&de->d_subdirs));
182 + assert(list_empty(&de->d_alias));
185 + list_for_each(lp, &inode->i_dentry) {
186 + tmp = list_entry(lp, struct dentry, d_alias);
187 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
188 + assert(tmp->d_alias.next == &inode->i_dentry);
189 + assert(tmp->d_alias.prev == &inode->i_dentry);
195 + spin_unlock(&dcache_lock);
200 + goal->d_flags &= ~DCACHE_DISCONNECTED;
208 + * These are the special structures for the iopen pseudo directory.
211 +static struct inode_operations iopen_inode_operations = {
212 + lookup: iopen_lookup, /* BKL held */
215 +static struct file_operations iopen_file_operations = {
216 + read: generic_read_dir,
219 +static int match_dentry(struct dentry *dentry, const char *name)
223 + len = strlen(name);
224 + if (dentry->d_name.len != len)
226 + if (strncmp(dentry->d_name.name, name, len))
232 + * This function is spliced into ext3_lookup and returns 1 the file
233 + * name is __iopen__ and dentry has been filled in appropriately.
235 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
237 + struct inode * inode;
239 + if (dir->i_ino != EXT3_ROOT_INO ||
240 + !test_opt(dir->i_sb, IOPEN) ||
241 + !match_dentry(dentry, "__iopen__"))
244 + inode = iget(dir->i_sb, EXT3_BAD_INO);
248 + d_add(dentry, inode);
253 + * This function is spliced into read_inode; it returns 1 if inode
254 + * number is the one for /__iopen__, in which case the inode is filled
255 + * in appropriately. Otherwise, this fuction returns 0.
257 +int ext3_iopen_get_inode(struct inode * inode)
259 + if (inode->i_ino != EXT3_BAD_INO)
262 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
263 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
264 + inode->i_mode |= 0777;
267 + inode->i_nlink = 1;
268 + inode->i_size = 4096;
269 + inode->i_atime = CURRENT_TIME;
270 + inode->i_ctime = CURRENT_TIME;
271 + inode->i_mtime = CURRENT_TIME;
272 + EXT3_I(inode)->i_dtime = 0;
273 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
274 + * (for stat), not the fs block
276 + inode->i_blocks = 0;
277 + inode->i_version = 1;
278 + inode->i_generation = 0;
280 + inode->i_op = &iopen_inode_operations;
281 + inode->i_fop = &iopen_file_operations;
282 + inode->i_mapping->a_ops = 0;
286 Index: linux-2.6.0/fs/ext3/iopen.h
287 ===================================================================
288 --- linux-2.6.0.orig/fs/ext3/iopen.h 2003-01-30 13:24:37.000000000 +0300
289 +++ linux-2.6.0/fs/ext3/iopen.h 2004-01-07 17:12:07.000000000 +0300
294 + * Special support for opening files by inode number.
296 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
298 + * This file may be redistributed under the terms of the GNU General
302 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
303 +extern int ext3_iopen_get_inode(struct inode * inode);
306 Index: linux-2.6.0/fs/ext3/namei.c
307 ===================================================================
308 --- linux-2.6.0.orig/fs/ext3/namei.c 2004-01-04 15:27:40.000000000 +0300
309 +++ linux-2.6.0/fs/ext3/namei.c 2004-01-07 17:12:45.000000000 +0300
311 #include <linux/buffer_head.h>
312 #include <linux/smp_lock.h>
318 @@ -970,15 +971,21 @@
322 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
324 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
326 struct inode * inode;
327 struct ext3_dir_entry_2 * de;
328 struct buffer_head * bh;
329 + struct dentry *alternate = NULL;
331 if (dentry->d_name.len > EXT3_NAME_LEN)
332 return ERR_PTR(-ENAMETOOLONG);
334 + if (ext3_check_for_iopen(dir, dentry))
337 bh = ext3_find_entry(dentry, &de);
342 return ERR_PTR(-EACCES);
344 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
350 return d_splice_alias(inode, dentry);
352 d_add(dentry, inode);
355 Index: linux-2.6.0/fs/ext3/super.c
356 ===================================================================
357 --- linux-2.6.0.orig/fs/ext3/super.c 2004-01-04 15:27:40.000000000 +0300
358 +++ linux-2.6.0/fs/ext3/super.c 2004-01-07 17:12:07.000000000 +0300
360 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, Opt_noload,
361 Opt_commit, Opt_journal_update, Opt_journal_inum,
362 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
363 - Opt_ignore, Opt_err,
364 + Opt_ignore, Opt_err, Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
367 static match_table_t tokens = {
369 {Opt_ignore, "noquota"},
370 {Opt_ignore, "quota"},
371 {Opt_ignore, "usrquota"},
372 + {Opt_iopen, "iopen"},
373 + {Opt_noiopen, "noiopen"},
374 + {Opt_iopen_nopriv, "iopen_nopriv"},
380 set_opt(sbi->s_mount_opt, ABORT);
383 + set_opt (sbi->s_mount_opt, IOPEN);
384 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
387 + clear_opt (sbi->s_mount_opt, IOPEN);
388 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
390 + case Opt_iopen_nopriv:
391 + set_opt (sbi->s_mount_opt, IOPEN);
392 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
397 Index: linux-2.6.0/fs/ext3/Makefile
398 ===================================================================
399 --- linux-2.6.0.orig/fs/ext3/Makefile 2003-09-19 18:00:24.000000000 +0400
400 +++ linux-2.6.0/fs/ext3/Makefile 2004-01-07 17:12:07.000000000 +0300
402 obj-$(CONFIG_EXT3_FS) += ext3.o
404 ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
405 - ioctl.o namei.o super.o symlink.o hash.o
406 + ioctl.o namei.o super.o symlink.o hash.o iopen.o
408 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
409 ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
410 Index: linux-2.6.0/include/linux/ext3_fs.h
411 ===================================================================
412 --- linux-2.6.0.orig/include/linux/ext3_fs.h 2004-01-04 15:27:40.000000000 +0300
413 +++ linux-2.6.0/include/linux/ext3_fs.h 2004-01-07 17:12:07.000000000 +0300
415 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
416 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
417 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
418 +#define EXT3_MOUNT_IOPEN 0x10000 /* Allow access via iopen */
419 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x20000 /* Make iopen world-readable */
421 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
422 #ifndef _LINUX_EXT2_FS_H