1 Index: linux-2.6.9-67/fs/ext3/Makefile
2 ===================================================================
3 --- linux-2.6.9-67.orig/fs/ext3/Makefile
4 +++ linux-2.6.9-67/fs/ext3/Makefile
7 obj-$(CONFIG_EXT3_FS) += ext3.o
9 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
10 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
11 ioctl.o namei.o super.o symlink.o hash.o resize.o
13 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
14 Index: linux-2.6.9-67/fs/ext3/inode.c
15 ===================================================================
16 --- linux-2.6.9-67.orig/fs/ext3/inode.c
17 +++ linux-2.6.9-67/fs/ext3/inode.c
19 #include <linux/mpage.h>
20 #include <linux/uio.h>
26 @@ -2409,6 +2410,8 @@ void ext3_read_inode(struct inode * inod
27 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
29 ei->i_rsv_window.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED;
30 + if (ext3_iopen_get_inode(inode))
33 if (ext3_get_inode_loc(inode, &iloc, 0))
35 Index: linux-2.6.9-67/fs/ext3/iopen.c
36 ===================================================================
38 +++ linux-2.6.9-67/fs/ext3/iopen.c
41 + * linux/fs/ext3/iopen.c
43 + * Special support for open by inode number
45 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
47 + * This file may be redistributed under the terms of the GNU General
52 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
53 + * for an inode at one time.
54 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
55 + * aliases on an inode at the same time.
57 + * If we have any connected dentry aliases for an inode, use one of those
58 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
59 + * dentry for this inode, which thereafter will be found by the dcache
60 + * when looking up this inode number in __iopen__, so we don't return here
63 + * If we get an inode via a regular name lookup, then we "rename" the
64 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
65 + * existing users of the disconnected dentry will continue to use the same
66 + * dentry as the connected users, and there will never be both kinds of
67 + * dentry aliases at one time.
70 +#include <linux/sched.h>
71 +#include <linux/fs.h>
72 +#include <linux/ext3_jbd.h>
73 +#include <linux/jbd.h>
74 +#include <linux/ext3_fs.h>
75 +#include <linux/smp_lock.h>
76 +#include <linux/dcache.h>
77 +#include <linux/security.h>
81 +#define assert(test) J_ASSERT(test)
84 +#define IOPEN_NAME_LEN 32
87 + * This implements looking up an inode by number.
89 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
90 + struct nameidata *nd)
92 + struct inode *inode;
94 + struct list_head *lp;
95 + struct dentry *alternate;
96 + char buf[IOPEN_NAME_LEN];
98 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
99 + return ERR_PTR(-ENAMETOOLONG);
101 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
102 + buf[dentry->d_name.len] = 0;
104 + if (strcmp(buf, ".") == 0)
106 + else if (strcmp(buf, "..") == 0)
107 + ino = EXT3_ROOT_INO;
109 + ino = simple_strtoul(buf, 0, 0);
111 + if ((ino != EXT3_ROOT_INO &&
112 + //ino != EXT3_ACL_IDX_INO &&
113 + //ino != EXT3_ACL_DATA_INO &&
114 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
115 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
116 + return ERR_PTR(-ENOENT);
118 + inode = iget(dir->i_sb, ino);
120 + return ERR_PTR(-EACCES);
121 + if (is_bad_inode(inode)) {
123 + return ERR_PTR(-ENOENT);
126 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
127 + assert(d_unhashed(dentry)); /* d_rehash */
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 + spin_lock(&alternate->d_lock);
141 + alternate->d_flags |= DCACHE_REFERENCED;
142 + spin_unlock(&alternate->d_lock);
144 + spin_unlock(&dcache_lock);
147 + dentry->d_flags |= DCACHE_DISCONNECTED;
149 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
150 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
151 + dentry->d_inode = inode;
153 + d_rehash_cond(dentry, 0); /* d_rehash */
154 + spin_unlock(&dcache_lock);
159 +#define do_switch(x,y) do { \
160 + __typeof__ (x) __tmp = x; \
161 + x = y; y = __tmp; } while (0)
163 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
165 + const unsigned char *old_name, *new_name;
167 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN_MIN);
168 + old_name = target->d_name.name;
169 + new_name = dentry->d_name.name;
170 + if (old_name == target->d_iname)
171 + old_name = dentry->d_iname;
172 + if (new_name == dentry->d_iname)
173 + new_name = target->d_iname;
174 + target->d_name.name = new_name;
175 + dentry->d_name.name = old_name;
178 +/* This function is spliced into ext3_lookup and does the move of a
179 + * disconnected dentry (if it exists) to a connected dentry.
181 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
184 + struct dentry *tmp, *goal = NULL;
185 + struct list_head *lp;
187 + /* verify this dentry is really new */
188 + assert(dentry->d_inode == NULL);
189 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
191 + assert(d_unhashed(dentry)); /* d_rehash */
192 + assert(list_empty(&dentry->d_subdirs));
194 + spin_lock(&dcache_lock);
198 + if (!test_opt(inode->i_sb, IOPEN))
199 + goto do_instantiate;
201 + /* preferrably return a connected dentry */
202 + list_for_each(lp, &inode->i_dentry) {
203 + tmp = list_entry(lp, struct dentry, d_alias);
204 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
205 + assert(tmp->d_alias.next == &inode->i_dentry);
206 + assert(tmp->d_alias.prev == &inode->i_dentry);
214 + goto do_instantiate;
216 + /* Move the goal to the de hash queue */
217 + goal->d_flags &= ~DCACHE_DISCONNECTED;
218 + security_d_instantiate(goal, inode);
220 + d_rehash_cond(dentry, 0);
221 + d_move_locked(goal, dentry);
222 + spin_unlock(&dcache_lock);
227 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
229 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
230 + dentry->d_inode = inode;
233 + d_rehash_cond(dentry, 0); /* d_rehash */
234 + spin_unlock(&dcache_lock);
240 + * Similar as d_instantiate() except that it drops the disconnected
243 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
245 + struct dentry *dis_dentry;
247 + /* verify this dentry is really new */
248 + assert(dentry->d_inode == NULL);
249 + assert(list_empty(&dentry->d_alias));
251 + spin_lock(&dcache_lock);
252 + if (!inode || !test_opt(inode->i_sb, IOPEN) ||
253 + list_empty(&inode->i_dentry))
254 + goto do_instantiate;
256 + /* a disconnected dentry has been added in our back,
257 + * we have to drop this dentry, see bug 16362/15713*/
258 + dis_dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
259 + spin_lock(&dis_dentry->d_lock);
260 + assert(dis_dentry->d_alias.next == &inode->i_dentry);
261 + assert(dis_dentry->d_alias.prev == &inode->i_dentry);
262 + assert(dis_dentry->d_flags & DCACHE_DISCONNECTED);
263 + __d_drop(dis_dentry);
264 + list_del_init(&dis_dentry->d_alias);
265 + spin_unlock(&dis_dentry->d_lock);
269 + list_add(&dentry->d_alias, &inode->i_dentry);
270 + dentry->d_inode = inode;
271 + spin_unlock(&dcache_lock);
272 + security_d_instantiate(dentry, inode);
276 + * These are the special structures for the iopen pseudo directory.
279 +static struct inode_operations iopen_inode_operations = {
280 + lookup: iopen_lookup, /* BKL held */
283 +static struct file_operations iopen_file_operations = {
284 + read: generic_read_dir,
287 +static int match_dentry(struct dentry *dentry, const char *name)
291 + len = strlen(name);
292 + if (dentry->d_name.len != len)
294 + if (strncmp(dentry->d_name.name, name, len))
300 + * This function is spliced into ext3_lookup and returns 1 the file
301 + * name is __iopen__ and dentry has been filled in appropriately.
303 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
305 + struct inode *inode;
307 + if (dir->i_ino != EXT3_ROOT_INO ||
308 + !test_opt(dir->i_sb, IOPEN) ||
309 + !match_dentry(dentry, "__iopen__"))
312 + inode = iget(dir->i_sb, EXT3_BAD_INO);
316 + d_add(dentry, inode);
321 + * This function is spliced into read_inode; it returns 1 if inode
322 + * number is the one for /__iopen__, in which case the inode is filled
323 + * in appropriately. Otherwise, this fuction returns 0.
325 +int ext3_iopen_get_inode(struct inode *inode)
327 + if (inode->i_ino != EXT3_BAD_INO)
330 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
331 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
332 + inode->i_mode |= 0777;
335 + inode->i_nlink = 1;
336 + inode->i_size = 4096;
337 + inode->i_atime = CURRENT_TIME;
338 + inode->i_ctime = CURRENT_TIME;
339 + inode->i_mtime = CURRENT_TIME;
340 + EXT3_I(inode)->i_dtime = 0;
341 + EXT3_I(inode)->i_file_acl = 0;
342 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
343 + * (for stat), not the fs block
345 + inode->i_blocks = 0;
346 + inode->i_version = 1;
347 + inode->i_generation = 0;
349 + inode->i_op = &iopen_inode_operations;
350 + inode->i_fop = &iopen_file_operations;
351 + inode->i_mapping->a_ops = 0;
355 Index: linux-2.6.9-67/fs/ext3/iopen.h
356 ===================================================================
358 +++ linux-2.6.9-67/fs/ext3/iopen.h
363 + * Special support for opening files by inode number.
365 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
367 + * This file may be redistributed under the terms of the GNU General
371 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
372 +extern int ext3_iopen_get_inode(struct inode *inode);
373 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
374 + struct inode *inode, int rehash);
375 +extern void iopen_d_instantiate(struct dentry *dentry, struct inode * inode);
377 +#if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
378 +#define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
381 +#if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
382 +#define d_move_locked(dentry, target) __d_move(dentry, target)
384 Index: linux-2.6.9-67/fs/ext3/namei.c
385 ===================================================================
386 --- linux-2.6.9-67.orig/fs/ext3/namei.c
387 +++ linux-2.6.9-67/fs/ext3/namei.c
389 #include <linux/buffer_head.h>
390 #include <linux/smp_lock.h>
396 @@ -1017,6 +1018,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 @@ -1027,10 +1031,8 @@ static struct dentry *ext3_lookup(struct
408 return ERR_PTR(-EACCES);
411 - return d_splice_alias(inode, dentry);
412 - d_add(dentry, inode);
415 + return iopen_connect_dentry(dentry, inode, 1);
419 @@ -1669,7 +1671,7 @@ static int ext3_add_nondir(handle_t *han
420 int err = ext3_add_entry(handle, dentry, inode);
422 ext3_mark_inode_dirty(handle, inode);
423 - d_instantiate(dentry, inode);
424 + iopen_d_instantiate(dentry, inode);
427 ext3_dec_count(handle, inode);
428 @@ -1831,7 +1833,7 @@ retry:
430 ext3_update_dx_flag(dir);
431 ext3_mark_inode_dirty(handle, dir);
432 - d_instantiate(dentry, inode);
433 + iopen_d_instantiate(dentry, inode);
435 ext3_journal_stop(handle);
436 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
437 @@ -2099,10 +2101,6 @@ static int ext3_rmdir (struct inode * di
441 - /* There's no need to set i_disksize: the fact that i_nlink is
442 - * zero will ensure that the right thing happens during any
445 ext3_orphan_add(handle, inode);
446 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
447 ext3_mark_inode_dirty(handle, inode);
448 @@ -2225,6 +2223,23 @@ out_stop:
452 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
453 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
454 + struct inode *inode)
456 + int err = ext3_add_entry(handle, dentry, inode);
458 + err = ext3_mark_inode_dirty(handle, inode);
460 + dput(iopen_connect_dentry(dentry, inode, 0));
464 + ext3_dec_count(handle, inode);
469 static int ext3_link (struct dentry * old_dentry,
470 struct inode * dir, struct dentry *dentry)
472 @@ -2254,7 +2269,8 @@ retry:
473 ext3_inc_count(handle, inode);
474 atomic_inc(&inode->i_count);
476 - err = ext3_add_nondir(handle, dentry, inode);
477 + err = ext3_add_link(handle, dentry, inode);
478 + ext3_orphan_del(handle, inode);
479 ext3_journal_stop(handle);
480 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
482 Index: linux-2.6.9-67/fs/ext3/super.c
483 ===================================================================
484 --- linux-2.6.9-67.orig/fs/ext3/super.c
485 +++ linux-2.6.9-67/fs/ext3/super.c
486 @@ -632,6 +632,7 @@ enum {
487 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
488 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
489 Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
490 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
493 static match_table_t tokens = {
494 @@ -678,6 +679,9 @@ static match_table_t tokens = {
495 {Opt_ignore, "noquota"},
496 {Opt_ignore, "quota"},
497 {Opt_ignore, "usrquota"},
498 + {Opt_iopen, "iopen"},
499 + {Opt_noiopen, "noiopen"},
500 + {Opt_iopen_nopriv, "iopen_nopriv"},
501 {Opt_barrier, "barrier=%u"},
503 {Opt_resize, "resize"},
504 @@ -959,6 +963,18 @@ clear_qf_name:
506 clear_opt(sbi->s_mount_opt, BARRIER);
509 + set_opt (sbi->s_mount_opt, IOPEN);
510 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
513 + clear_opt (sbi->s_mount_opt, IOPEN);
514 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
516 + case Opt_iopen_nopriv:
517 + set_opt (sbi->s_mount_opt, IOPEN);
518 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
523 Index: linux-2.6.9-67/include/linux/ext3_fs.h
524 ===================================================================
525 --- linux-2.6.9-67.orig/include/linux/ext3_fs.h
526 +++ linux-2.6.9-67/include/linux/ext3_fs.h
527 @@ -355,6 +355,8 @@ struct ext3_inode {
528 #define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
529 #define EXT3_MOUNT_BARRIER 0x10000 /* Use block barriers */
530 #define EXT3_MOUNT_RESERVATION 0x20000 /* Preallocation */
531 +#define EXT3_MOUNT_IOPEN 0x80000 /* Allow access via iopen */
532 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
534 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
535 #ifndef _LINUX_EXT2_FS_H