1 Index: linux-stage/fs/ext3/iopen.c
2 ===================================================================
4 +++ linux-stage/fs/ext3/iopen.c
7 + * linux/fs/ext3/iopen.c
9 + * Special support for open by inode number
11 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
13 + * This file may be redistributed under the terms of the GNU General
18 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
19 + * for an inode at one time.
20 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
21 + * aliases on an inode at the same time.
23 + * If we have any connected dentry aliases for an inode, use one of those
24 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
25 + * dentry for this inode, which thereafter will be found by the dcache
26 + * when looking up this inode number in __iopen__, so we don't return here
29 + * If we get an inode via a regular name lookup, then we "rename" the
30 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
31 + * existing users of the disconnected dentry will continue to use the same
32 + * dentry as the connected users, and there will never be both kinds of
33 + * dentry aliases at one time.
36 +#include <linux/sched.h>
37 +#include <linux/fs.h>
38 +#include <linux/ext3_jbd.h>
39 +#include <linux/jbd.h>
40 +#include <linux/ext3_fs.h>
41 +#include <linux/smp_lock.h>
42 +#include <linux/dcache.h>
43 +#include <linux/security.h>
47 +#define assert(test) J_ASSERT(test)
50 +#define IOPEN_NAME_LEN 32
53 + * This implements looking up an inode by number.
55 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
56 + struct nameidata *nd)
58 + struct inode *inode;
60 + struct list_head *lp;
61 + struct dentry *alternate;
62 + char buf[IOPEN_NAME_LEN];
64 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
65 + return ERR_PTR(-ENAMETOOLONG);
67 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
68 + buf[dentry->d_name.len] = 0;
70 + if (strcmp(buf, ".") == 0)
72 + else if (strcmp(buf, "..") == 0)
73 + ino = EXT3_ROOT_INO;
75 + ino = simple_strtoul(buf, 0, 0);
77 + if ((ino != EXT3_ROOT_INO &&
78 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
79 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
80 + return ERR_PTR(-ENOENT);
82 + inode = iget(dir->i_sb, ino);
84 + return ERR_PTR(-EACCES);
85 + if (is_bad_inode(inode)) {
87 + return ERR_PTR(-ENOENT);
90 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
91 + assert(d_unhashed(dentry)); /* d_rehash */
93 + /* preferrably return a connected dentry */
94 + spin_lock(&dcache_lock);
95 + list_for_each(lp, &inode->i_dentry) {
96 + alternate = list_entry(lp, struct dentry, d_alias);
97 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
100 + if (!list_empty(&inode->i_dentry)) {
101 + alternate = list_entry(inode->i_dentry.next,
102 + struct dentry, d_alias);
103 + dget_locked(alternate);
104 + spin_lock(&alternate->d_lock);
105 + alternate->d_flags |= DCACHE_REFERENCED;
106 + spin_unlock(&alternate->d_lock);
108 + spin_unlock(&dcache_lock);
111 + dentry->d_flags |= DCACHE_DISCONNECTED;
113 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
114 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
115 + dentry->d_inode = inode;
117 + d_rehash_cond(dentry, 0);
118 + spin_unlock(&dcache_lock);
123 +/* This function is spliced into ext3_lookup and does the move of a
124 + * disconnected dentry (if it exists) to a connected dentry.
126 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
129 + struct dentry *tmp, *goal = NULL;
130 + struct list_head *lp;
132 + /* verify this dentry is really new */
133 + assert(dentry->d_inode == NULL);
134 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
136 + assert(d_unhashed(dentry)); /* d_rehash */
137 + assert(list_empty(&dentry->d_subdirs));
139 + spin_lock(&dcache_lock);
143 + if (!test_opt(inode->i_sb, IOPEN))
144 + goto do_instantiate;
146 + /* preferrably return a connected dentry */
147 + list_for_each(lp, &inode->i_dentry) {
148 + tmp = list_entry(lp, struct dentry, d_alias);
149 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
150 + assert(tmp->d_alias.next == &inode->i_dentry);
151 + assert(tmp->d_alias.prev == &inode->i_dentry);
159 + goto do_instantiate;
161 + /* Move the goal to the de hash queue */
162 + goal->d_flags &= ~DCACHE_DISCONNECTED;
163 + security_d_instantiate(goal, inode);
165 + d_rehash_cond(dentry, 0);
166 + d_move_locked(goal, dentry);
167 + spin_unlock(&dcache_lock);
172 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
174 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
175 + dentry->d_inode = inode;
178 + d_rehash_cond(dentry, 0);
179 + spin_unlock(&dcache_lock);
185 + * These are the special structures for the iopen pseudo directory.
188 +static struct inode_operations iopen_inode_operations = {
189 + lookup: iopen_lookup, /* BKL held */
192 +static struct file_operations iopen_file_operations = {
193 + read: generic_read_dir,
196 +static int match_dentry(struct dentry *dentry, const char *name)
200 + len = strlen(name);
201 + if (dentry->d_name.len != len)
203 + if (strncmp(dentry->d_name.name, name, len))
209 + * This function is spliced into ext3_lookup and returns 1 the file
210 + * name is __iopen__ and dentry has been filled in appropriately.
212 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
214 + struct inode *inode;
216 + if (dir->i_ino != EXT3_ROOT_INO ||
217 + !test_opt(dir->i_sb, IOPEN) ||
218 + !match_dentry(dentry, "__iopen__"))
221 + inode = iget(dir->i_sb, EXT3_BAD_INO);
225 + d_add(dentry, inode);
230 + * This function is spliced into read_inode; it returns 1 if inode
231 + * number is the one for /__iopen__, in which case the inode is filled
232 + * in appropriately. Otherwise, this fuction returns 0.
234 +int ext3_iopen_get_inode(struct inode *inode)
236 + if (inode->i_ino != EXT3_BAD_INO)
239 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
240 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
241 + inode->i_mode |= 0777;
244 + inode->i_nlink = 1;
245 + inode->i_size = 4096;
246 + inode->i_atime = CURRENT_TIME;
247 + inode->i_ctime = CURRENT_TIME;
248 + inode->i_mtime = CURRENT_TIME;
249 + EXT3_I(inode)->i_dtime = 0;
250 + inode->i_blocks = 0;
251 + inode->i_version = 1;
252 + inode->i_generation = 0;
254 + inode->i_op = &iopen_inode_operations;
255 + inode->i_fop = &iopen_file_operations;
256 + inode->i_mapping->a_ops = 0;
260 Index: linux-stage/fs/ext3/iopen.h
261 ===================================================================
263 +++ linux-stage/fs/ext3/iopen.h
268 + * Special support for opening files by inode number.
270 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
272 + * This file may be redistributed under the terms of the GNU General
276 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
277 +extern int ext3_iopen_get_inode(struct inode *inode);
278 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
279 + struct inode *inode, int rehash);
280 Index: linux-stage/fs/ext3/inode.c
281 ===================================================================
282 --- linux-stage.orig/fs/ext3/inode.c
283 +++ linux-stage/fs/ext3/inode.c
285 #include <linux/mpage.h>
286 #include <linux/uio.h>
291 static int ext3_writepage_trans_blocks(struct inode *inode);
292 @@ -2593,6 +2594,8 @@ void ext3_read_inode(struct inode * inod
293 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
295 ei->i_block_alloc_info = NULL;
296 + if (ext3_iopen_get_inode(inode))
299 if (__ext3_get_inode_loc(inode, &iloc, 0))
301 Index: linux-stage/fs/ext3/super.c
302 ===================================================================
303 --- linux-stage.orig/fs/ext3/super.c
304 +++ linux-stage/fs/ext3/super.c
305 @@ -677,6 +677,7 @@ enum {
306 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
307 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
308 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
309 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
313 @@ -726,6 +727,9 @@ static match_table_t tokens = {
314 {Opt_noquota, "noquota"},
315 {Opt_quota, "quota"},
316 {Opt_usrquota, "usrquota"},
317 + {Opt_iopen, "iopen"},
318 + {Opt_noiopen, "noiopen"},
319 + {Opt_iopen_nopriv, "iopen_nopriv"},
320 {Opt_barrier, "barrier=%u"},
322 {Opt_resize, "resize"},
323 @@ -1041,6 +1045,18 @@ clear_qf_name:
325 clear_opt(sbi->s_mount_opt, BARRIER);
328 + set_opt (sbi->s_mount_opt, IOPEN);
329 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
332 + clear_opt (sbi->s_mount_opt, IOPEN);
333 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
335 + case Opt_iopen_nopriv:
336 + set_opt (sbi->s_mount_opt, IOPEN);
337 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
342 Index: linux-stage/fs/ext3/namei.c
343 ===================================================================
344 --- linux-stage.orig/fs/ext3/namei.c
345 +++ linux-stage/fs/ext3/namei.c
354 @@ -1013,6 +1014,9 @@ static struct dentry *ext3_lookup(struct
355 if (dentry->d_name.len > EXT3_NAME_LEN)
356 return ERR_PTR(-ENAMETOOLONG);
358 + if (ext3_check_for_iopen(dir, dentry))
361 bh = ext3_find_entry(dentry, &de);
364 @@ -1028,7 +1032,8 @@ static struct dentry *ext3_lookup(struct
366 return ERR_PTR(-EACCES);
368 - return d_splice_alias(inode, dentry);
370 + return iopen_connect_dentry(dentry, inode, 1);
374 @@ -2077,10 +2082,6 @@ static int ext3_rmdir (struct inode * di
378 - /* There's no need to set i_disksize: the fact that i_nlink is
379 - * zero will ensure that the right thing happens during any
382 ext3_orphan_add(handle, inode);
383 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
384 ext3_mark_inode_dirty(handle, inode);
385 @@ -2204,6 +2205,23 @@ out_stop:
389 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
390 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
391 + struct inode *inode)
393 + int err = ext3_add_entry(handle, dentry, inode);
395 + err = ext3_mark_inode_dirty(handle, inode);
397 + dput(iopen_connect_dentry(dentry, inode, 0));
401 + ext3_dec_count(handle, inode);
406 static int ext3_link (struct dentry * old_dentry,
407 struct inode * dir, struct dentry *dentry)
409 @@ -2233,7 +2251,8 @@ retry:
410 ext3_inc_count(handle, inode);
411 atomic_inc(&inode->i_count);
413 - err = ext3_add_nondir(handle, dentry, inode);
414 + err = ext3_add_link(handle, dentry, inode);
415 + ext3_orphan_del(handle, inode);
416 ext3_journal_stop(handle);
417 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
419 Index: linux-stage/fs/ext3/Makefile
420 ===================================================================
421 --- linux-stage.orig/fs/ext3/Makefile
422 +++ linux-stage/fs/ext3/Makefile
425 obj-$(CONFIG_EXT3_FS) += ext3.o
427 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
428 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
429 ioctl.o namei.o super.o symlink.o hash.o resize.o
431 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
432 Index: linux-stage/include/linux/ext3_fs.h
433 ===================================================================
434 --- linux-stage.orig/include/linux/ext3_fs.h
435 +++ linux-stage/include/linux/ext3_fs.h
436 @@ -371,6 +371,8 @@ struct ext3_inode {
437 #define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */
438 #define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
439 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
440 +#define EXT3_MOUNT_IOPEN 0x400000 /* Allow access via iopen */
441 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
443 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
444 #ifndef _LINUX_EXT2_FS_H