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(+), 2 deletions(-)
11 Index: linux-ia64/Documentation/filesystems/ext2.txt
12 ===================================================================
13 --- linux-ia64.orig/Documentation/filesystems/ext2.txt 2004-03-17 15:47:15.000000000 -0800
14 +++ linux-ia64/Documentation/filesystems/ext2.txt 2004-03-17 18:03:15.000000000 -0800
15 @@ -35,6 +35,22 @@ resgid=n The group ID which may use th
17 sb=n Use alternate superblock at this location.
19 +iopen Makes an invisible pseudo-directory called
20 + __iopen__ available in the root directory
21 + of the filesystem. Allows open-by-inode-
22 + number. i.e., inode 3145 can be accessed
23 + via /mntpt/__iopen__/3145
25 +iopen_nopriv This option makes the iopen directory be
26 + world-readable. This may be safer since it
27 + allows daemons to run as an unprivileged user,
28 + however it significantly changes the security
29 + model of a Unix filesystem, since previously
30 + all files under a mode 700 directory were not
31 + generally avilable even if the
32 + permissions on the file itself is
35 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
38 Index: linux-ia64/fs/ext3/Makefile
39 ===================================================================
40 --- linux-ia64.orig/fs/ext3/Makefile 2004-03-17 18:03:14.000000000 -0800
41 +++ linux-ia64/fs/ext3/Makefile 2004-03-17 18:03:15.000000000 -0800
42 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
44 export-objs := ext3-exports.o
46 -obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
47 +obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
48 ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
51 Index: linux-ia64/fs/ext3/inode.c
52 ===================================================================
53 --- linux-ia64.orig/fs/ext3/inode.c 2004-03-17 18:03:15.000000000 -0800
54 +++ linux-ia64/fs/ext3/inode.c 2004-03-17 18:10:36.000000000 -0800
56 #include <linux/highuid.h>
57 #include <linux/quotaops.h>
58 #include <linux/module.h>
62 * SEARCH_FROM_ZERO forces each block allocation to search from the start
63 @@ -2430,6 +2431,9 @@ void ext3_read_inode(struct inode * inod
64 struct buffer_head *bh;
67 + if (ext3_iopen_get_inode(inode))
70 if(ext3_get_inode_loc(inode, &iloc))
73 Index: linux-ia64/fs/ext3/iopen.c
74 ===================================================================
75 --- linux-ia64.orig/fs/ext3/iopen.c 2004-03-17 18:02:08.000000000 -0800
76 +++ linux-ia64/fs/ext3/iopen.c 2004-03-17 18:10:58.000000000 -0800
79 + * linux/fs/ext3/iopen.c
81 + * Special support for open by inode number
83 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
85 + * This file may be redistributed under the terms of the GNU General
90 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
91 + * for an inode at one time.
92 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
93 + * aliases on an inode at the same time.
95 + * If we have any connected dentry aliases for an inode, use one of those
96 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
97 + * dentry for this inode, which thereafter will be found by the dcache
98 + * when looking up this inode number in __iopen__, so we don't return here
101 + * If we get an inode via a regular name lookup, then we "rename" the
102 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
103 + * existing users of the disconnected dentry will continue to use the same
104 + * dentry as the connected users, and there will never be both kinds of
105 + * dentry aliases at one time.
108 +#include <linux/sched.h>
109 +#include <linux/fs.h>
110 +#include <linux/locks.h>
111 +#include <linux/ext3_jbd.h>
112 +#include <linux/jbd.h>
113 +#include <linux/ext3_fs.h>
114 +#include <linux/smp_lock.h>
118 +#define assert(test) J_ASSERT(test)
121 +#define IOPEN_NAME_LEN 32
124 + * This implements looking up an inode by number.
126 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
128 + struct inode *inode;
130 + struct list_head *lp;
131 + struct dentry *alternate;
132 + char buf[IOPEN_NAME_LEN];
134 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
135 + return ERR_PTR(-ENAMETOOLONG);
137 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
138 + buf[dentry->d_name.len] = 0;
140 + if (strcmp(buf, ".") == 0)
142 + else if (strcmp(buf, "..") == 0)
143 + ino = EXT3_ROOT_INO;
145 + ino = simple_strtoul(buf, 0, 0);
147 + if ((ino != EXT3_ROOT_INO &&
148 + //ino != EXT3_ACL_IDX_INO &&
149 + //ino != EXT3_ACL_DATA_INO &&
150 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
151 + ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
152 + return ERR_PTR(-ENOENT);
154 + inode = iget(dir->i_sb, ino);
156 + return ERR_PTR(-EACCES);
157 + if (is_bad_inode(inode)) {
159 + return ERR_PTR(-ENOENT);
162 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
163 + assert(list_empty(&dentry->d_hash)); /* d_rehash */
165 + /* preferrably return a connected dentry */
166 + spin_lock(&dcache_lock);
167 + list_for_each(lp, &inode->i_dentry) {
168 + alternate = list_entry(lp, struct dentry, d_alias);
169 + assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
172 + if (!list_empty(&inode->i_dentry)) {
173 + alternate = list_entry(inode->i_dentry.next,
174 + struct dentry, d_alias);
175 + dget_locked(alternate);
176 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
178 + spin_unlock(&dcache_lock);
181 + dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
183 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
184 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
185 + dentry->d_inode = inode;
187 + __d_rehash(dentry, 0); /* d_rehash */
188 + spin_unlock(&dcache_lock);
193 +#define do_switch(x,y) do { \
194 + __typeof__ (x) __tmp = x; \
195 + x = y; y = __tmp; } while (0)
197 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
199 + const unsigned char *old_name, *new_name;
201 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
202 + old_name = target->d_name.name;
203 + new_name = dentry->d_name.name;
204 + if (old_name == target->d_iname)
205 + old_name = dentry->d_iname;
206 + if (new_name == dentry->d_iname)
207 + new_name = target->d_iname;
208 + target->d_name.name = new_name;
209 + dentry->d_name.name = old_name;
212 +/* This function is spliced into ext3_lookup and does the move of a
213 + * disconnected dentry (if it exists) to a connected dentry.
215 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
218 + struct dentry *tmp, *goal = NULL;
219 + struct list_head *lp;
221 + /* verify this dentry is really new */
222 + assert(dentry->d_inode == NULL);
223 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
225 + assert(list_empty(&dentry->d_hash)); /* d_rehash */
226 + assert(list_empty(&dentry->d_subdirs));
228 + spin_lock(&dcache_lock);
232 + if (!test_opt(inode->i_sb, IOPEN))
233 + goto do_instantiate;
235 + /* preferrably return a connected dentry */
236 + list_for_each(lp, &inode->i_dentry) {
237 + tmp = list_entry(lp, struct dentry, d_alias);
238 + if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
239 + assert(tmp->d_alias.next == &inode->i_dentry);
240 + assert(tmp->d_alias.prev == &inode->i_dentry);
248 + goto do_instantiate;
250 + /* Move the goal to the de hash queue - like d_move() */
251 + goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
252 + list_del_init(&goal->d_hash);
254 + list_del(&goal->d_child);
255 + list_del(&dentry->d_child);
257 + /* Switch the parents and the names.. */
258 + switch_names(goal, dentry);
259 + do_switch(goal->d_parent, dentry->d_parent);
260 + do_switch(goal->d_name.len, dentry->d_name.len);
261 + do_switch(goal->d_name.hash, dentry->d_name.hash);
263 + /* And add them back to the (new) parent lists */
264 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
265 + list_add(&dentry->d_child, &dentry->d_parent->d_subdirs);
266 + __d_rehash(goal, 0);
267 + spin_unlock(&dcache_lock);
272 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
274 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
275 + dentry->d_inode = inode;
278 + __d_rehash(dentry, 0); /* d_rehash */
279 + spin_unlock(&dcache_lock);
285 + * These are the special structures for the iopen pseudo directory.
288 +static struct inode_operations iopen_inode_operations = {
289 + lookup: iopen_lookup, /* BKL held */
292 +static struct file_operations iopen_file_operations = {
293 + read: generic_read_dir,
296 +static int match_dentry(struct dentry *dentry, const char *name)
300 + len = strlen(name);
301 + if (dentry->d_name.len != len)
303 + if (strncmp(dentry->d_name.name, name, len))
309 + * This function is spliced into ext3_lookup and returns 1 the file
310 + * name is __iopen__ and dentry has been filled in appropriately.
312 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
314 + struct inode *inode;
316 + if (dir->i_ino != EXT3_ROOT_INO ||
317 + !test_opt(dir->i_sb, IOPEN) ||
318 + !match_dentry(dentry, "__iopen__"))
321 + inode = iget(dir->i_sb, EXT3_BAD_INO);
325 + d_add(dentry, inode);
330 + * This function is spliced into read_inode; it returns 1 if inode
331 + * number is the one for /__iopen__, in which case the inode is filled
332 + * in appropriately. Otherwise, this fuction returns 0.
334 +int ext3_iopen_get_inode(struct inode *inode)
336 + if (inode->i_ino != EXT3_BAD_INO)
339 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
340 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
341 + inode->i_mode |= 0777;
344 + inode->i_nlink = 1;
345 + inode->i_size = 4096;
346 + inode->i_atime = CURRENT_TIME;
347 + inode->i_ctime = CURRENT_TIME;
348 + inode->i_mtime = CURRENT_TIME;
349 + inode->u.ext3_i.i_dtime = 0;
350 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
351 + * (for stat), not the fs block
353 + inode->i_blocks = 0;
354 + inode->i_version = 1;
355 + inode->i_generation = 0;
357 + inode->i_op = &iopen_inode_operations;
358 + inode->i_fop = &iopen_file_operations;
359 + inode->i_mapping->a_ops = 0;
363 Index: linux-ia64/fs/ext3/iopen.h
364 ===================================================================
365 --- linux-ia64.orig/fs/ext3/iopen.h 2004-03-17 15:47:15.000000000 -0800
366 +++ linux-ia64/fs/ext3/iopen.h 2004-03-17 18:03:15.000000000 -0800
371 + * Special support for opening files by inode number.
373 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
375 + * This file may be redistributed under the terms of the GNU General
379 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
380 +extern int ext3_iopen_get_inode(struct inode *inode);
381 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
382 + struct inode *inode, int rehash);
383 Index: linux-ia64/fs/ext3/namei.c
384 ===================================================================
385 --- linux-ia64.orig/fs/ext3/namei.c 2004-03-17 18:03:15.000000000 -0800
386 +++ linux-ia64/fs/ext3/namei.c 2004-03-17 18:10:35.000000000 -0800
388 #include <linux/string.h>
389 #include <linux/locks.h>
390 #include <linux/quotaops.h>
395 * define how far ahead to read directories while searching them.
396 @@ -932,6 +932,9 @@ static struct dentry *ext3_lookup(struct
397 if (dentry->d_name.len > EXT3_NAME_LEN)
398 return ERR_PTR(-ENAMETOOLONG);
400 + if (ext3_check_for_iopen(dir, dentry))
403 bh = ext3_find_entry(dentry, &de);
406 @@ -943,8 +946,8 @@ static struct dentry *ext3_lookup(struct
407 return ERR_PTR(-EACCES);
410 - d_add(dentry, inode);
413 + return iopen_connect_dentry(dentry, inode, 1);
417 @@ -1935,10 +1938,6 @@ static int ext3_rmdir (struct inode * di
419 inode->i_version = ++event;
421 - /* There's no need to set i_disksize: the fact that i_nlink is
422 - * zero will ensure that the right thing happens during any
425 ext3_orphan_add(handle, inode);
427 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
428 @@ -2057,6 +2056,23 @@ out_stop:
432 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
433 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
434 + struct inode *inode)
436 + int err = ext3_add_entry(handle, dentry, inode);
438 + err = ext3_mark_inode_dirty(handle, inode);
440 + dput(iopen_connect_dentry(dentry, inode, 0));
444 + ext3_dec_count(handle, inode);
449 static int ext3_link (struct dentry * old_dentry,
450 struct inode * dir, struct dentry *dentry)
452 @@ -2084,7 +2100,8 @@ static int ext3_link (struct dentry * ol
453 ext3_inc_count(handle, inode);
454 atomic_inc(&inode->i_count);
456 - err = ext3_add_nondir(handle, dentry, inode);
457 + err = ext3_add_link(handle, dentry, inode);
458 + ext3_orphan_del(handle, inode);
459 ext3_journal_stop(handle, dir);
462 Index: linux-ia64/fs/ext3/super.c
463 ===================================================================
464 --- linux-ia64.orig/fs/ext3/super.c 2004-03-17 18:03:14.000000000 -0800
465 +++ linux-ia64/fs/ext3/super.c 2004-03-17 18:10:35.000000000 -0800
466 @@ -891,6 +891,18 @@ static int parse_options (char * options
467 || !strcmp (this_char, "quota")
468 || !strcmp (this_char, "usrquota"))
469 /* Don't do anything ;-) */ ;
470 + else if (!strcmp (this_char, "iopen")) {
471 + set_opt (sbi->s_mount_opt, IOPEN);
472 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
474 + else if (!strcmp (this_char, "noiopen")) {
475 + clear_opt (sbi->s_mount_opt, IOPEN);
476 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
478 + else if (!strcmp (this_char, "iopen_nopriv")) {
479 + set_opt (sbi->s_mount_opt, IOPEN);
480 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
482 else if (!strcmp (this_char, "journal")) {
484 /* Eventually we will want to be able to create
485 Index: linux-ia64/include/linux/ext3_fs.h
486 ===================================================================
487 --- linux-ia64.orig/include/linux/ext3_fs.h 2004-03-17 18:03:15.000000000 -0800
488 +++ linux-ia64/include/linux/ext3_fs.h 2004-03-17 18:03:15.000000000 -0800
489 @@ -328,6 +328,8 @@ struct ext3_inode {
490 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
491 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
492 #define EXT3_MOUNT_ASYNCDEL 0x20000 /* Delayed deletion */
493 +#define EXT3_MOUNT_IOPEN 0x80000 /* Allow access via iopen */
494 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
496 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
497 #ifndef _LINUX_EXT2_FS_H