1 Documentation/filesystems/ext2.txt | 16 ++
4 fs/ext3/iopen.c | 259 +++++++++++++++++++++++++++++++++++++
8 include/linux/ext3_fs.h | 2
9 8 files changed, 318 insertions(+), 1 deletion(-)
11 --- linux-2.4.18-p4smp/Documentation/filesystems/ext2.txt~iopen-2.4.18 2003-07-09 12:17:30.000000000 -0600
12 +++ linux-2.4.18-p4smp-braam/Documentation/filesystems/ext2.txt 2003-07-09 17:13:02.000000000 -0600
13 @@ -35,6 +35,22 @@ resgid=n The group ID which may use th
15 sb=n Use alternate superblock at this location.
17 +iopen Makes an invisible pseudo-directory called
18 + __iopen__ available in the root directory
19 + of the filesystem. Allows open-by-inode-
20 + number. i.e., inode 3145 can be accessed
21 + via /mntpt/__iopen__/3145
23 +iopen_nopriv This option makes the iopen directory be
24 + world-readable. This may be safer since it
25 + allows daemons to run as an unprivileged user,
26 + however it significantly changes the security
27 + model of a Unix filesystem, since previously
28 + all files under a mode 700 directory were not
29 + generally avilable even if the
30 + permissions on the file itself is
33 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
36 --- linux-2.4.18-p4smp/fs/ext3/Makefile~iopen-2.4.18 2003-07-09 17:12:12.000000000 -0600
37 +++ linux-2.4.18-p4smp-braam/fs/ext3/Makefile 2003-07-09 17:13:15.000000000 -0600
38 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
40 export-objs := super.o inode.o xattr.o ext3-exports.o
42 -obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
43 +obj-y := balloc.o iopen.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
44 ioctl.o namei.o super.o symlink.o xattr.o ext3-exports.o
47 --- linux-2.4.18-p4smp/fs/ext3/inode.c~iopen-2.4.18 2003-07-09 17:11:19.000000000 -0600
48 +++ linux-2.4.18-p4smp-braam/fs/ext3/inode.c 2003-07-09 17:13:02.000000000 -0600
50 #include <linux/highuid.h>
51 #include <linux/quotaops.h>
52 #include <linux/module.h>
56 * SEARCH_FROM_ZERO forces each block allocation to search from the start
57 @@ -2165,6 +2166,9 @@ void ext3_read_inode(struct inode * inod
58 struct buffer_head *bh;
61 + if (ext3_iopen_get_inode(inode))
64 if(ext3_get_inode_loc(inode, &iloc))
67 --- /dev/null 2003-01-30 03:24:37.000000000 -0700
68 +++ linux-2.4.18-p4smp-braam/fs/ext3/iopen.c 2003-07-09 17:13:02.000000000 -0600
71 + * linux/fs/ext3/iopen.c
73 + * Special support for open by inode number
75 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
77 + * This file may be redistributed under the terms of the GNU General
82 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
83 + * for an inode at one time.
84 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
85 + * aliases on an inode at the same time.
87 + * If we have any connected dentry aliases for an inode, use one of those
88 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
89 + * dentry for this inode, which thereafter will be found by the dcache
90 + * when looking up this inode number in __iopen__, so we don't return here
93 + * If we get an inode via a regular name lookup, then we "rename" the
94 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
95 + * existing users of the disconnected dentry will continue to use the same
96 + * dentry as the connected users, and there will never be both kinds of
97 + * dentry aliases at one time.
100 +#include <linux/sched.h>
101 +#include <linux/fs.h>
102 +#include <linux/locks.h>
103 +#include <linux/ext3_jbd.h>
104 +#include <linux/jbd.h>
105 +#include <linux/ext3_fs.h>
106 +#include <linux/smp_lock.h>
110 +#define assert(test) J_ASSERT(test)
113 +#define IOPEN_NAME_LEN 32
116 + * This implements looking up an inode by number.
118 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
120 + struct inode *inode;
122 + struct list_head *lp;
123 + struct dentry *alternate;
124 + char buf[IOPEN_NAME_LEN];
126 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
127 + return ERR_PTR(-ENAMETOOLONG);
129 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
130 + buf[dentry->d_name.len] = 0;
132 + if (strcmp(buf, ".") == 0)
134 + else if (strcmp(buf, "..") == 0)
135 + ino = EXT3_ROOT_INO;
137 + ino = simple_strtoul(buf, 0, 0);
139 + if ((ino != EXT3_ROOT_INO &&
140 + //ino != EXT3_ACL_IDX_INO &&
141 + //ino != EXT3_ACL_DATA_INO &&
142 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
143 + ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
144 + return ERR_PTR(-ENOENT);
146 + inode = iget(dir->i_sb, ino);
148 + return ERR_PTR(-EACCES);
149 + if (is_bad_inode(inode)) {
151 + return ERR_PTR(-ENOENT);
154 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
155 + assert(list_empty(&dentry->d_hash)); /* d_rehash */
157 + /* preferrably return a connected dentry */
158 + spin_lock(&dcache_lock);
159 + list_for_each(lp, &inode->i_dentry) {
160 + alternate = list_entry(lp, struct dentry, d_alias);
161 + assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
164 + if (!list_empty(&inode->i_dentry)) {
165 + alternate = list_entry(inode->i_dentry.next,
166 + struct dentry, d_alias);
167 + dget_locked(alternate);
168 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
170 + spin_unlock(&dcache_lock);
173 + dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
175 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
176 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
177 + dentry->d_inode = inode;
179 + __d_rehash(dentry, 0); /* d_rehash */
180 + spin_unlock(&dcache_lock);
185 +#define do_switch(x,y) do { \
186 + __typeof__ (x) __tmp = x; \
187 + x = y; y = __tmp; } while (0)
189 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
191 + const unsigned char *old_name, *new_name;
193 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
194 + old_name = target->d_name.name;
195 + new_name = dentry->d_name.name;
196 + if (old_name == target->d_iname)
197 + old_name = dentry->d_iname;
198 + if (new_name == dentry->d_iname)
199 + new_name = target->d_iname;
200 + target->d_name.name = new_name;
201 + dentry->d_name.name = old_name;
204 +/* This function is spliced into ext3_lookup and does the move of a
205 + * disconnected dentry (if it exists) to a connected dentry.
206 + * Caller must hold dcache_lock.
208 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
210 + struct dentry *tmp, *goal = NULL;
211 + struct list_head *lp;
213 + /* preferrably return a connected dentry */
214 + list_for_each(lp, &inode->i_dentry) {
215 + tmp = list_entry(lp, struct dentry, d_alias);
216 + if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
217 + assert(tmp->d_alias.next == &inode->i_dentry);
218 + assert(tmp->d_alias.prev == &inode->i_dentry);
228 + /* Move the goal to the de hash queue - like d_move() */
229 + goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
230 + list_del_init(&goal->d_hash);
232 + list_del(&goal->d_child);
233 + list_del(&de->d_child);
235 + /* Switch the parents and the names.. */
236 + switch_names(goal, de);
237 + do_switch(goal->d_parent, de->d_parent);
238 + do_switch(goal->d_name.len, de->d_name.len);
239 + do_switch(goal->d_name.hash, de->d_name.hash);
241 + /* And add them back to the (new) parent lists */
242 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
243 + list_add(&de->d_child, &de->d_parent->d_subdirs);
244 + __d_rehash(goal, 0);
250 + * These are the special structures for the iopen pseudo directory.
253 +static struct inode_operations iopen_inode_operations = {
254 + lookup: iopen_lookup, /* BKL held */
257 +static struct file_operations iopen_file_operations = {
258 + read: generic_read_dir,
261 +static int match_dentry(struct dentry *dentry, const char *name)
265 + len = strlen(name);
266 + if (dentry->d_name.len != len)
268 + if (strncmp(dentry->d_name.name, name, len))
274 + * This function is spliced into ext3_lookup and returns 1 the file
275 + * name is __iopen__ and dentry has been filled in appropriately.
277 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
279 + struct inode *inode;
281 + if (dir->i_ino != EXT3_ROOT_INO ||
282 + !test_opt(dir->i_sb, IOPEN) ||
283 + !match_dentry(dentry, "__iopen__"))
286 + inode = iget(dir->i_sb, EXT3_BAD_INO);
290 + d_add(dentry, inode);
295 + * This function is spliced into read_inode; it returns 1 if inode
296 + * number is the one for /__iopen__, in which case the inode is filled
297 + * in appropriately. Otherwise, this fuction returns 0.
299 +int ext3_iopen_get_inode(struct inode *inode)
301 + if (inode->i_ino != EXT3_BAD_INO)
304 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
305 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
306 + inode->i_mode |= 0777;
309 + inode->i_nlink = 1;
310 + inode->i_size = 4096;
311 + inode->i_atime = CURRENT_TIME;
312 + inode->i_ctime = CURRENT_TIME;
313 + inode->i_mtime = CURRENT_TIME;
314 + inode->u.ext3_i.i_dtime = 0;
315 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
316 + * (for stat), not the fs block
318 + inode->i_blocks = 0;
319 + inode->i_version = 1;
320 + inode->i_generation = 0;
322 + inode->i_op = &iopen_inode_operations;
323 + inode->i_fop = &iopen_file_operations;
324 + inode->i_mapping->a_ops = 0;
328 --- /dev/null 2003-01-30 03:24:37.000000000 -0700
329 +++ linux-2.4.18-p4smp-braam/fs/ext3/iopen.h 2003-07-09 17:13:02.000000000 -0600
334 + * Special support for opening files by inode number.
336 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
338 + * This file may be redistributed under the terms of the GNU General
342 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
343 +extern int ext3_iopen_get_inode(struct inode *inode);
344 +extern struct dentry *iopen_connect_dentry(struct dentry *de,
345 + struct inode *inode);
346 --- linux-2.4.18-p4smp/fs/ext3/namei.c~iopen-2.4.18 2003-07-09 13:32:38.000000000 -0600
347 +++ linux-2.4.18-p4smp-braam/fs/ext3/namei.c 2003-07-09 17:13:02.000000000 -0600
349 #include <linux/locks.h>
350 #include <linux/quotaops.h>
351 #include <linux/slab.h>
355 * define how far ahead to read directories while searching them.
356 @@ -703,10 +704,14 @@ cleanup_and_exit:
357 struct inode * inode;
358 struct ext3_dir_entry_2 * de;
359 struct buffer_head * bh;
360 + struct dentry *alternate = NULL;
362 if (dentry->d_name.len > EXT3_NAME_LEN)
363 return ERR_PTR(-ENAMETOOLONG);
365 + if (ext3_check_for_iopen(dir, dentry))
368 bh = ext3_find_entry(dentry, &de);
371 @@ -723,7 +729,28 @@ static struct dentry *ext3_lookup(struct
373 return ERR_PTR(-EACCES);
375 - d_add(dentry, inode);
377 + /* verify this dentry is really new */
378 + assert(!dentry->d_inode);
379 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
380 + assert(list_empty(&dentry->d_hash)); /* d_rehash */
381 + assert(list_empty(&dentry->d_subdirs));
383 + spin_lock(&dcache_lock);
384 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
385 + spin_unlock(&dcache_lock);
390 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
391 + if (inode) /* d_instantiate */
392 + list_add(&dentry->d_alias, &inode->i_dentry);
393 + dentry->d_inode = inode;
395 + __d_rehash(dentry, 0); /* d_rehash */
396 + spin_unlock(&dcache_lock);
401 --- linux-2.4.18-p4smp/fs/ext3/super.c~iopen-2.4.18 2003-07-09 13:32:38.000000000 -0600
402 +++ linux-2.4.18-p4smp-braam/fs/ext3/super.c 2003-07-09 17:13:02.000000000 -0600
403 @@ -831,6 +831,18 @@ static int parse_options (char * options
404 || !strcmp (this_char, "quota")
405 || !strcmp (this_char, "usrquota"))
406 /* Don't do anything ;-) */ ;
407 + else if (!strcmp (this_char, "iopen")) {
408 + set_opt (sbi->s_mount_opt, IOPEN);
409 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
411 + else if (!strcmp (this_char, "noiopen")) {
412 + clear_opt (sbi->s_mount_opt, IOPEN);
413 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
415 + else if (!strcmp (this_char, "iopen_nopriv")) {
416 + set_opt (sbi->s_mount_opt, IOPEN);
417 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
419 else if (!strcmp (this_char, "journal")) {
421 /* Eventually we will want to be able to create
422 --- linux-2.4.18-p4smp/include/linux/ext3_fs.h~iopen-2.4.18 2003-07-09 13:32:38.000000000 -0600
423 +++ linux-2.4.18-p4smp-braam/include/linux/ext3_fs.h 2003-07-09 17:13:02.000000000 -0600
424 @@ -321,6 +321,8 @@ struct ext3_inode {
425 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
426 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
427 #define EXT3_MOUNT_INDEX 0x4000 /* Enable directory index */
428 +#define EXT3_MOUNT_IOPEN 0x8000 /* Allow access via iopen */
429 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x10000 /* Make iopen world-readable */
430 #define EXT3_MOUNT_ASYNCDEL 0x20000 /* Delayed deletion */
432 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */