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
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>
28 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))
36 Index: linux-stage/fs/ext3/iopen.c
37 ===================================================================
38 --- linux-2.6.5-sles9.orig/fs/ext3/iopen.c 2003-01-30 13:24:37.000000000 +0300
39 +++ linux-2.6.5-sles9/fs/ext3/iopen.c 2004-11-09 02:18:27.611913312 +0300
42 + * linux/fs/ext3/iopen.c
44 + * Special support for open by inode number
46 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
48 + * This file may be redistributed under the terms of the GNU General
53 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
54 + * for an inode at one time.
55 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
56 + * aliases on an inode at the same time.
58 + * If we have any connected dentry aliases for an inode, use one of those
59 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
60 + * dentry for this inode, which thereafter will be found by the dcache
61 + * when looking up this inode number in __iopen__, so we don't return here
64 + * If we get an inode via a regular name lookup, then we "rename" the
65 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
66 + * existing users of the disconnected dentry will continue to use the same
67 + * dentry as the connected users, and there will never be both kinds of
68 + * dentry aliases at one time.
71 +#include <linux/sched.h>
72 +#include <linux/fs.h>
73 +#include <linux/ext3_jbd.h>
74 +#include <linux/jbd.h>
75 +#include <linux/ext3_fs.h>
76 +#include <linux/smp_lock.h>
77 +#include <linux/dcache.h>
78 +#include <linux/security.h>
82 +#define assert(test) J_ASSERT(test)
85 +#define IOPEN_NAME_LEN 32
88 + * This implements looking up an inode by number.
90 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
91 + struct nameidata *nd)
93 + struct inode *inode;
95 + struct list_head *lp;
96 + struct dentry *alternate;
97 + char buf[IOPEN_NAME_LEN];
99 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
100 + return ERR_PTR(-ENAMETOOLONG);
102 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
103 + buf[dentry->d_name.len] = 0;
105 + if (strcmp(buf, ".") == 0)
107 + else if (strcmp(buf, "..") == 0)
108 + ino = EXT3_ROOT_INO;
110 + ino = simple_strtoul(buf, 0, 0);
112 + if ((ino != EXT3_ROOT_INO &&
113 + //ino != EXT3_ACL_IDX_INO &&
114 + //ino != EXT3_ACL_DATA_INO &&
115 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
116 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
117 + return ERR_PTR(-ENOENT);
119 + inode = iget(dir->i_sb, ino);
121 + return ERR_PTR(-EACCES);
122 + if (is_bad_inode(inode)) {
124 + return ERR_PTR(-ENOENT);
127 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
128 + assert(d_unhashed(dentry)); /* d_rehash */
130 + /* preferrably return a connected dentry */
131 + spin_lock(&dcache_lock);
132 + list_for_each(lp, &inode->i_dentry) {
133 + alternate = list_entry(lp, struct dentry, d_alias);
134 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
137 + if (!list_empty(&inode->i_dentry)) {
138 + alternate = list_entry(inode->i_dentry.next,
139 + struct dentry, d_alias);
140 + dget_locked(alternate);
141 + spin_lock(&alternate->d_lock);
142 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
143 + spin_unlock(&alternate->d_lock);
145 + spin_unlock(&dcache_lock);
148 + dentry->d_flags |= DCACHE_DISCONNECTED;
150 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
151 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
152 + dentry->d_inode = inode;
154 + __d_rehash(dentry, 0); /* d_rehash */
155 + spin_unlock(&dcache_lock);
160 +#define do_switch(x,y) do { \
161 + __typeof__ (x) __tmp = x; \
162 + x = y; y = __tmp; } while (0)
164 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
166 + const unsigned char *old_name, *new_name;
168 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
169 + old_name = target->d_name.name;
170 + new_name = dentry->d_name.name;
171 + if (old_name == target->d_iname)
172 + old_name = dentry->d_iname;
173 + if (new_name == dentry->d_iname)
174 + new_name = target->d_iname;
175 + target->d_name.name = new_name;
176 + dentry->d_name.name = old_name;
179 +/* This function is spliced into ext3_lookup and does the move of a
180 + * disconnected dentry (if it exists) to a connected dentry.
182 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
185 + struct dentry *tmp, *goal = NULL;
186 + struct list_head *lp;
188 + /* verify this dentry is really new */
189 + assert(dentry->d_inode == NULL);
190 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
192 + assert(d_unhashed(dentry)); /* d_rehash */
193 + assert(list_empty(&dentry->d_subdirs));
195 + spin_lock(&dcache_lock);
199 + if (!test_opt(inode->i_sb, IOPEN))
200 + goto do_instantiate;
202 + /* preferrably return a connected dentry */
203 + list_for_each(lp, &inode->i_dentry) {
204 + tmp = list_entry(lp, struct dentry, d_alias);
205 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
206 + assert(tmp->d_alias.next == &inode->i_dentry);
207 + assert(tmp->d_alias.prev == &inode->i_dentry);
215 + goto do_instantiate;
217 + /* Move the goal to the de hash queue */
218 + goal->d_flags &= ~DCACHE_DISCONNECTED;
219 + security_d_instantiate(goal, inode);
221 + __d_rehash(dentry, 0);
222 + __d_move(goal, dentry);
223 + spin_unlock(&dcache_lock);
228 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
230 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
231 + dentry->d_inode = inode;
234 + __d_rehash(dentry, 0); /* d_rehash */
235 + spin_unlock(&dcache_lock);
241 + * These are the special structures for the iopen pseudo directory.
244 +static struct inode_operations iopen_inode_operations = {
245 + lookup: iopen_lookup, /* BKL held */
248 +static struct file_operations iopen_file_operations = {
249 + read: generic_read_dir,
252 +static int match_dentry(struct dentry *dentry, const char *name)
256 + len = strlen(name);
257 + if (dentry->d_name.len != len)
259 + if (strncmp(dentry->d_name.name, name, len))
265 + * This function is spliced into ext3_lookup and returns 1 the file
266 + * name is __iopen__ and dentry has been filled in appropriately.
268 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
270 + struct inode *inode;
272 + if (dir->i_ino != EXT3_ROOT_INO ||
273 + !test_opt(dir->i_sb, IOPEN) ||
274 + !match_dentry(dentry, "__iopen__"))
277 + inode = iget(dir->i_sb, EXT3_BAD_INO);
281 + d_add(dentry, inode);
286 + * This function is spliced into read_inode; it returns 1 if inode
287 + * number is the one for /__iopen__, in which case the inode is filled
288 + * in appropriately. Otherwise, this fuction returns 0.
290 +int ext3_iopen_get_inode(struct inode *inode)
292 + if (inode->i_ino != EXT3_BAD_INO)
295 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
296 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
297 + inode->i_mode |= 0777;
300 + inode->i_nlink = 1;
301 + inode->i_size = 4096;
302 + inode->i_atime = CURRENT_TIME;
303 + inode->i_ctime = CURRENT_TIME;
304 + inode->i_mtime = CURRENT_TIME;
305 + EXT3_I(inode)->i_dtime = 0;
306 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
307 + * (for stat), not the fs block
309 + inode->i_blocks = 0;
310 + inode->i_version = 1;
311 + inode->i_generation = 0;
313 + inode->i_op = &iopen_inode_operations;
314 + inode->i_fop = &iopen_file_operations;
315 + inode->i_mapping->a_ops = 0;
319 Index: linux-stage/fs/ext3/iopen.h
320 ===================================================================
321 --- linux-stage.orig/fs/ext3/iopen.h 2005-02-25 14:41:01.017787968 +0200
322 +++ linux-stage/fs/ext3/iopen.h 2005-02-25 14:41:01.045783712 +0200
327 + * Special support for opening files by inode number.
329 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
331 + * This file may be redistributed under the terms of the GNU General
335 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
336 +extern int ext3_iopen_get_inode(struct inode *inode);
337 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
338 + struct inode *inode, int rehash);
339 Index: linux-stage/fs/ext3/namei.c
340 ===================================================================
341 --- linux-stage.orig/fs/ext3/namei.c 2005-02-25 14:37:28.975023368 +0200
342 +++ linux-stage/fs/ext3/namei.c 2005-02-25 14:46:43.090784968 +0200
344 #include <linux/buffer_head.h>
345 #include <linux/smp_lock.h>
352 if (dentry->d_name.len > EXT3_NAME_LEN)
353 return ERR_PTR(-ENAMETOOLONG);
355 + if (ext3_check_for_iopen(dir, dentry))
358 bh = ext3_find_entry(dentry, &de);
363 return ERR_PTR(-EACCES);
366 - return d_splice_alias(inode, dentry);
367 - d_add(dentry, inode);
370 + return iopen_connect_dentry(dentry, inode, 1);
374 @@ -2037,10 +2039,6 @@
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;
384 ext3_mark_inode_dirty(handle, inode);
385 @@ -2163,6 +2161,23 @@
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 @@ -2186,7 +2201,8 @@
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/super.c
420 ===================================================================
421 --- linux-stage.orig/fs/ext3/super.c 2005-02-25 14:37:30.987717392 +0200
422 +++ linux-stage/fs/ext3/super.c 2005-02-25 14:44:50.495901992 +0200
424 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
425 Opt_ignore, Opt_barrier,
427 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
430 static match_table_t tokens = {
432 {Opt_ignore, "noquota"},
433 {Opt_ignore, "quota"},
434 {Opt_ignore, "usrquota"},
435 + {Opt_iopen, "iopen"},
436 + {Opt_noiopen, "noiopen"},
437 + {Opt_iopen_nopriv, "iopen_nopriv"},
438 {Opt_barrier, "barrier=%u"},
443 clear_opt(sbi->s_mount_opt, BARRIER);
446 + set_opt (sbi->s_mount_opt, IOPEN);
447 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
450 + clear_opt (sbi->s_mount_opt, IOPEN);
451 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
453 + case Opt_iopen_nopriv:
454 + set_opt (sbi->s_mount_opt, IOPEN);
455 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
460 Index: linux-stage/include/linux/ext3_fs.h
461 ===================================================================
462 --- linux-stage.orig/include/linux/ext3_fs.h 2005-02-25 14:37:28.977023064 +0200
463 +++ linux-stage/include/linux/ext3_fs.h 2005-02-25 14:49:00.569884968 +0200
465 #define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
466 #define EXT3_MOUNT_RESERVATION 0x10000 /* Preallocation */
467 #define EXT3_MOUNT_BARRIER 0x20000 /* Use block barriers */
468 +#define EXT3_MOUNT_IOPEN 0x80000 /* Allow access via iopen */
469 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
471 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
472 #ifndef _LINUX_EXT2_FS_H