1 Index: linux-stage/fs/ext3/Makefile
2 ===================================================================
3 --- linux-stage.orig/fs/ext3/Makefile 2005-02-25 14:31:53.151076368 +0200
4 +++ linux-stage/fs/ext3/Makefile 2005-02-25 14:41:51.259150120 +0200
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-stage/fs/ext3/inode.c
15 ===================================================================
16 --- linux-stage.orig/fs/ext3/inode.c 2005-02-25 14:37:30.983718000 +0200
17 +++ linux-stage/fs/ext3/inode.c 2005-02-25 14:47:42.069818792 +0200
19 #include <linux/mpage.h>
20 #include <linux/uio.h>
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-stage/fs/ext3/iopen.c
36 ===================================================================
37 --- linux-stage.orig/fs/ext3/iopen.c 2005-02-25 14:41:01.017787968 +0200
38 +++ linux-stage/fs/ext3/iopen.c 2005-02-25 14:41:01.045783712 +0200
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(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(dentry, 0);
221 + __d_move(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(dentry, 0); /* d_rehash */
234 + spin_unlock(&dcache_lock);
240 + * These are the special structures for the iopen pseudo directory.
243 +static struct inode_operations iopen_inode_operations = {
244 + lookup: iopen_lookup, /* BKL held */
247 +static struct file_operations iopen_file_operations = {
248 + read: generic_read_dir,
251 +static int match_dentry(struct dentry *dentry, const char *name)
255 + len = strlen(name);
256 + if (dentry->d_name.len != len)
258 + if (strncmp(dentry->d_name.name, name, len))
264 + * This function is spliced into ext3_lookup and returns 1 the file
265 + * name is __iopen__ and dentry has been filled in appropriately.
267 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
269 + struct inode *inode;
271 + if (dir->i_ino != EXT3_ROOT_INO ||
272 + !test_opt(dir->i_sb, IOPEN) ||
273 + !match_dentry(dentry, "__iopen__"))
276 + inode = iget(dir->i_sb, EXT3_BAD_INO);
280 + d_add(dentry, inode);
285 + * This function is spliced into read_inode; it returns 1 if inode
286 + * number is the one for /__iopen__, in which case the inode is filled
287 + * in appropriately. Otherwise, this fuction returns 0.
289 +int ext3_iopen_get_inode(struct inode *inode)
291 + if (inode->i_ino != EXT3_BAD_INO)
294 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
295 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
296 + inode->i_mode |= 0777;
299 + inode->i_nlink = 1;
300 + inode->i_size = 4096;
301 + inode->i_atime = CURRENT_TIME;
302 + inode->i_ctime = CURRENT_TIME;
303 + inode->i_mtime = CURRENT_TIME;
304 + EXT3_I(inode)->i_dtime = 0;
305 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
306 + * (for stat), not the fs block
308 + inode->i_blocks = 0;
309 + inode->i_version = 1;
310 + inode->i_generation = 0;
312 + inode->i_op = &iopen_inode_operations;
313 + inode->i_fop = &iopen_file_operations;
314 + inode->i_mapping->a_ops = 0;
318 Index: linux-stage/fs/ext3/iopen.h
319 ===================================================================
320 --- linux-stage.orig/fs/ext3/iopen.h 2005-02-25 14:41:01.017787968 +0200
321 +++ linux-stage/fs/ext3/iopen.h 2005-02-25 14:41:01.045783712 +0200
326 + * Special support for opening files by inode number.
328 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
330 + * This file may be redistributed under the terms of the GNU General
334 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
335 +extern int ext3_iopen_get_inode(struct inode *inode);
336 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
337 + struct inode *inode, int rehash);
338 Index: linux-stage/fs/ext3/namei.c
339 ===================================================================
340 --- linux-stage.orig/fs/ext3/namei.c 2005-02-25 14:37:28.975023368 +0200
341 +++ linux-stage/fs/ext3/namei.c 2005-02-25 14:46:43.090784968 +0200
343 #include <linux/buffer_head.h>
344 #include <linux/smp_lock.h>
351 if (dentry->d_name.len > EXT3_NAME_LEN)
352 return ERR_PTR(-ENAMETOOLONG);
354 + if (ext3_check_for_iopen(dir, dentry))
357 bh = ext3_find_entry(dentry, &de);
362 return ERR_PTR(-EACCES);
365 - return d_splice_alias(inode, dentry);
366 - d_add(dentry, inode);
369 + return iopen_connect_dentry(dentry, inode, 1);
373 @@ -2037,10 +2039,6 @@
377 - /* There's no need to set i_disksize: the fact that i_nlink is
378 - * zero will ensure that the right thing happens during any
381 ext3_orphan_add(handle, inode);
382 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
383 ext3_mark_inode_dirty(handle, inode);
384 @@ -2163,6 +2161,23 @@
388 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
389 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
390 + struct inode *inode)
392 + int err = ext3_add_entry(handle, dentry, inode);
394 + err = ext3_mark_inode_dirty(handle, inode);
396 + dput(iopen_connect_dentry(dentry, inode, 0));
400 + ext3_dec_count(handle, inode);
405 static int ext3_link (struct dentry * old_dentry,
406 struct inode * dir, struct dentry *dentry)
408 @@ -2186,7 +2201,8 @@
409 ext3_inc_count(handle, inode);
410 atomic_inc(&inode->i_count);
412 - err = ext3_add_nondir(handle, dentry, inode);
413 + err = ext3_add_link(handle, dentry, inode);
414 + ext3_orphan_del(handle, inode);
415 ext3_journal_stop(handle);
416 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
418 Index: linux-stage/fs/ext3/super.c
419 ===================================================================
420 --- linux-stage.orig/fs/ext3/super.c 2005-02-25 14:37:30.987717392 +0200
421 +++ linux-stage/fs/ext3/super.c 2005-02-25 14:44:50.495901992 +0200
423 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
424 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
425 Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
426 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
429 static match_table_t tokens = {
431 {Opt_ignore, "noquota"},
432 {Opt_ignore, "quota"},
433 {Opt_ignore, "usrquota"},
434 + {Opt_iopen, "iopen"},
435 + {Opt_noiopen, "noiopen"},
436 + {Opt_iopen_nopriv, "iopen_nopriv"},
437 {Opt_barrier, "barrier=%u"},
439 {Opt_resize, "resize"},
442 clear_opt(sbi->s_mount_opt, BARRIER);
445 + set_opt (sbi->s_mount_opt, IOPEN);
446 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
449 + clear_opt (sbi->s_mount_opt, IOPEN);
450 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
452 + case Opt_iopen_nopriv:
453 + set_opt (sbi->s_mount_opt, IOPEN);
454 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
459 Index: linux-stage/include/linux/ext3_fs.h
460 ===================================================================
461 --- linux-stage.orig/include/linux/ext3_fs.h 2005-02-25 14:37:28.977023064 +0200
462 +++ linux-stage/include/linux/ext3_fs.h 2005-02-25 14:49:00.569884968 +0200
464 #define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
465 #define EXT3_MOUNT_BARRIER 0x10000 /* Use block barriers */
466 #define EXT3_MOUNT_RESERVATION 0x20000 /* Preallocation */
467 +#define EXT3_MOUNT_IOPEN 0x80000 /* Allow access via iopen */
468 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
470 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
471 #ifndef _LINUX_EXT2_FS_H