3 --- linux-2.4.18-chaos52/Documentation/filesystems/ext2.txt~iopen-2.4.18 2003-04-13 15:21:33.000000000 +0800
4 +++ linux-2.4.18-chaos52-root/Documentation/filesystems/ext2.txt 2003-06-03 17:10:55.000000000 +0800
5 @@ -35,6 +35,22 @@ resgid=n The group ID which may use th
7 sb=n Use alternate superblock at this location.
9 +iopen Makes an invisible pseudo-directory called
10 + __iopen__ available in the root directory
11 + of the filesystem. Allows open-by-inode-
12 + number. i.e., inode 3145 can be accessed
13 + via /mntpt/__iopen__/3145
15 +iopen_nopriv This option makes the iopen directory be
16 + world-readable. This may be safer since it
17 + allows daemons to run as an unprivileged user,
18 + however it significantly changes the security
19 + model of a Unix filesystem, since previously
20 + all files under a mode 700 directory were not
21 + generally avilable even if the
22 + permissions on the file itself is
25 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
28 --- linux-2.4.18-chaos52/fs/ext3/Makefile~iopen-2.4.18 2003-06-01 03:24:07.000000000 +0800
29 +++ linux-2.4.18-chaos52-root/fs/ext3/Makefile 2003-06-03 17:10:55.000000000 +0800
30 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
32 export-objs := super.o inode.o xattr.o
34 -obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
35 +obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
36 ioctl.o namei.o super.o symlink.o xattr.o
39 --- linux-2.4.18-chaos52/fs/ext3/inode.c~iopen-2.4.18 2003-06-03 17:10:21.000000000 +0800
40 +++ linux-2.4.18-chaos52-root/fs/ext3/inode.c 2003-06-03 17:10:55.000000000 +0800
42 #include <linux/highuid.h>
43 #include <linux/quotaops.h>
44 #include <linux/module.h>
48 * SEARCH_FROM_ZERO forces each block allocation to search from the start
49 @@ -2135,6 +2136,9 @@ void ext3_read_inode(struct inode * inod
50 struct buffer_head *bh;
53 + if (ext3_iopen_get_inode(inode))
56 if(ext3_get_inode_loc(inode, &iloc))
59 --- /dev/null 2002-08-31 07:31:37.000000000 +0800
60 +++ linux-2.4.18-chaos52-root/fs/ext3/iopen.c 2003-06-03 17:10:55.000000000 +0800
63 + * linux/fs/ext3/iopen.c
65 + * Special support for open by inode number
67 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
69 + * This file may be redistributed under the terms of the GNU General
74 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
75 + * for an inode at one time.
76 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
77 + * aliases on an inode at the same time.
79 + * If we have any connected dentry aliases for an inode, use one of those
80 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
81 + * dentry for this inode, which thereafter will be found by the dcache
82 + * when looking up this inode number in __iopen__, so we don't return here
85 + * If we get an inode via a regular name lookup, then we "rename" the
86 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
87 + * existing users of the disconnected dentry will continue to use the same
88 + * dentry as the connected users, and there will never be both kinds of
89 + * dentry aliases at one time.
92 +#include <linux/sched.h>
93 +#include <linux/fs.h>
94 +#include <linux/locks.h>
95 +#include <linux/ext3_jbd.h>
96 +#include <linux/jbd.h>
97 +#include <linux/ext3_fs.h>
98 +#include <linux/smp_lock.h>
102 +#define assert(test) J_ASSERT(test)
105 +#define IOPEN_NAME_LEN 32
108 + * This implements looking up an inode by number.
110 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
112 + struct inode *inode;
114 + struct list_head *lp;
115 + struct dentry *alternate;
116 + char buf[IOPEN_NAME_LEN];
118 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
119 + return ERR_PTR(-ENAMETOOLONG);
121 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
122 + buf[dentry->d_name.len] = 0;
124 + if (strcmp(buf, ".") == 0)
126 + else if (strcmp(buf, "..") == 0)
127 + ino = EXT3_ROOT_INO;
129 + ino = simple_strtoul(buf, 0, 0);
131 + if ((ino != EXT3_ROOT_INO &&
132 + //ino != EXT3_ACL_IDX_INO &&
133 + //ino != EXT3_ACL_DATA_INO &&
134 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
135 + ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
136 + return ERR_PTR(-ENOENT);
138 + inode = iget(dir->i_sb, ino);
140 + return ERR_PTR(-EACCES);
141 + if (is_bad_inode(inode)) {
143 + return ERR_PTR(-ENOENT);
146 + /* preferrably return a connected dentry */
147 + spin_lock(&dcache_lock);
148 + list_for_each(lp, &inode->i_dentry) {
149 + alternate = list_entry(lp, struct dentry, d_alias);
150 + assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
153 + if (!list_empty(&inode->i_dentry)) {
154 + alternate = list_entry(inode->i_dentry.next,
155 + struct dentry, d_alias);
156 + dget_locked(alternate);
157 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
159 + spin_unlock(&dcache_lock);
162 + dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
163 + spin_unlock(&dcache_lock);
165 + d_add(dentry, inode);
169 +#define do_switch(x,y) do { \
170 + __typeof__ (x) __tmp = x; \
171 + x = y; y = __tmp; } while (0)
173 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
175 + const unsigned char *old_name, *new_name;
177 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
178 + old_name = target->d_name.name;
179 + new_name = dentry->d_name.name;
180 + if (old_name == target->d_iname)
181 + old_name = dentry->d_iname;
182 + if (new_name == dentry->d_iname)
183 + new_name = target->d_iname;
184 + target->d_name.name = new_name;
185 + dentry->d_name.name = old_name;
188 +/* This function is spliced into ext3_lookup and does the move of a
189 + * disconnected dentry (if it exists) to a connected dentry.
191 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
193 + struct dentry *tmp, *goal = NULL;
194 + struct list_head *lp;
196 + /* preferrably return a connected dentry */
197 + spin_lock(&dcache_lock);
198 + /* verify this dentry is really new */
199 + assert(!de->d_inode);
200 + assert(list_empty(&de->d_subdirs));
201 + assert(list_empty(&de->d_alias));
204 + list_for_each(lp, &inode->i_dentry) {
205 + tmp = list_entry(lp, struct dentry, d_alias);
206 + if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
207 + assert(tmp->d_alias.next == &inode->i_dentry);
208 + assert(tmp->d_alias.prev == &inode->i_dentry);
216 + spin_unlock(&dcache_lock);
220 + /* Move the goal to the de hash queue - like d_move() */
221 + goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
222 + list_del(&goal->d_hash);
223 + list_add(&goal->d_hash, &de->d_hash);
225 + list_del(&goal->d_child);
226 + list_del(&de->d_child);
228 + /* Switch the parents and the names.. */
229 + switch_names(goal, de);
230 + do_switch(goal->d_parent, de->d_parent);
231 + do_switch(goal->d_name.len, de->d_name.len);
232 + do_switch(goal->d_name.hash, de->d_name.hash);
234 + /* And add them back to the (new) parent lists */
235 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
236 + list_add(&de->d_child, &de->d_parent->d_subdirs);
237 + spin_unlock(&dcache_lock);
243 + * These are the special structures for the iopen pseudo directory.
246 +static struct inode_operations iopen_inode_operations = {
247 + lookup: iopen_lookup, /* BKL held */
250 +static struct file_operations iopen_file_operations = {
251 + read: generic_read_dir,
254 +static int match_dentry(struct dentry *dentry, const char *name)
258 + len = strlen(name);
259 + if (dentry->d_name.len != len)
261 + if (strncmp(dentry->d_name.name, name, len))
267 + * This function is spliced into ext3_lookup and returns 1 the file
268 + * name is __iopen__ and dentry has been filled in appropriately.
270 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
272 + struct inode *inode;
274 + if (dir->i_ino != EXT3_ROOT_INO ||
275 + !test_opt(dir->i_sb, IOPEN) ||
276 + !match_dentry(dentry, "__iopen__"))
279 + inode = iget(dir->i_sb, EXT3_BAD_INO);
283 + d_add(dentry, inode);
288 + * This function is spliced into read_inode; it returns 1 if inode
289 + * number is the one for /__iopen__, in which case the inode is filled
290 + * in appropriately. Otherwise, this fuction returns 0.
292 +int ext3_iopen_get_inode(struct inode *inode)
294 + if (inode->i_ino != EXT3_BAD_INO)
297 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
298 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
299 + inode->i_mode |= 0777;
302 + inode->i_nlink = 1;
303 + inode->i_size = 4096;
304 + inode->i_atime = CURRENT_TIME;
305 + inode->i_ctime = CURRENT_TIME;
306 + inode->i_mtime = CURRENT_TIME;
307 + inode->u.ext3_i.i_dtime = 0;
308 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
309 + * (for stat), not the fs block
311 + inode->i_blocks = 0;
312 + inode->i_version = 1;
313 + inode->i_generation = 0;
315 + inode->i_op = &iopen_inode_operations;
316 + inode->i_fop = &iopen_file_operations;
317 + inode->i_mapping->a_ops = 0;
321 --- /dev/null 2002-08-31 07:31:37.000000000 +0800
322 +++ linux-2.4.18-chaos52-root/fs/ext3/iopen.h 2003-06-03 17:10:55.000000000 +0800
327 + * Special support for opening files by inode number.
329 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
331 + * This file may be redistributed under the terms of the GNU General
335 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
336 +extern int ext3_iopen_get_inode(struct inode *inode);
337 --- linux-2.4.18-chaos52/fs/ext3/namei.c~iopen-2.4.18 2003-06-03 17:10:20.000000000 +0800
338 +++ linux-2.4.18-chaos52-root/fs/ext3/namei.c 2003-06-03 17:10:55.000000000 +0800
340 #include <linux/locks.h>
341 #include <linux/quotaops.h>
342 #include <linux/slab.h>
346 * define how far ahead to read directories while searching them.
347 @@ -703,16 +704,21 @@ cleanup_and_exit:
348 brelse (bh_use[ra_ptr]);
351 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
353 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
355 struct inode * inode;
356 struct ext3_dir_entry_2 * de;
357 struct buffer_head * bh;
358 + struct dentry *alternate = NULL;
360 if (dentry->d_name.len > EXT3_NAME_LEN)
361 return ERR_PTR(-ENAMETOOLONG);
363 + if (ext3_check_for_iopen(dir, dentry))
366 bh = ext3_find_entry(dentry, &de);
369 @@ -723,6 +729,12 @@ static struct dentry *ext3_lookup(struct
371 return ERR_PTR(-EACCES);
374 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
379 d_add(dentry, inode);
382 --- linux-2.4.18-chaos52/fs/ext3/super.c~iopen-2.4.18 2003-06-03 17:10:21.000000000 +0800
383 +++ linux-2.4.18-chaos52-root/fs/ext3/super.c 2003-06-03 17:10:55.000000000 +0800
384 @@ -820,6 +820,17 @@ static int parse_options (char * options
385 || !strcmp (this_char, "quota")
386 || !strcmp (this_char, "usrquota"))
387 /* Don't do anything ;-) */ ;
388 + else if (!strcmp (this_char, "iopen")) {
389 + set_opt (sbi->s_mount_opt, IOPEN);
390 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
391 + } else if (!strcmp (this_char, "noiopen")) {
392 + clear_opt (sbi->s_mount_opt, IOPEN);
393 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
395 + else if (!strcmp (this_char, "iopen_nopriv")) {
396 + set_opt (sbi->s_mount_opt, IOPEN);
397 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
399 else if (!strcmp (this_char, "journal")) {
401 /* Eventually we will want to be able to create
402 --- linux-2.4.18-chaos52/include/linux/ext3_fs.h~iopen-2.4.18 2003-06-03 17:10:22.000000000 +0800
403 +++ linux-2.4.18-chaos52-root/include/linux/ext3_fs.h 2003-06-03 17:12:08.000000000 +0800
404 @@ -321,6 +321,8 @@ struct ext3_inode {
405 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
406 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
407 #define EXT3_MOUNT_INDEX 0x4000 /* Enable directory index */
408 +#define EXT3_MOUNT_IOPEN 0x8000 /* Allow access via iopen */
409 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x10000 /* Make iopen world-readable */
410 #define EXT3_MOUNT_ASYNCDEL 0x20000 /* Delayed deletion */
412 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */