1 Documentation/filesystems/ext2.txt | 16 ++
3 fs/ext3/iopen.c | 239 +++++++++++++++++++++++++++++++++++++
4 fs/ext3/iopen.h | 15 ++
5 fs/ext3/namei.c | 13 ++
6 fs/ext3/super.c | 17 ++
7 include/linux/ext3_fs.h | 2
8 7 files changed, 304 insertions(+), 1 deletion(-)
10 Index: linux-2.6.4-51.1/fs/ext3/inode.c
11 ===================================================================
12 --- linux-2.6.4-51.1.orig/fs/ext3/inode.c 2004-04-06 00:31:14.000000000 -0400
13 +++ linux-2.6.4-51.1/fs/ext3/inode.c 2004-04-06 00:31:24.000000000 -0400
15 #include <linux/mpage.h>
16 #include <linux/uio.h>
23 ei->i_acl = EXT3_ACL_NOT_CACHED;
24 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
26 + if (ext3_iopen_get_inode(inode))
28 if (ext3_get_inode_loc(inode, &iloc, 0))
31 Index: linux-2.6.4-51.1/fs/ext3/iopen.c
32 ===================================================================
33 --- linux-2.6.4-51.1.orig/fs/ext3/iopen.c 2004-04-06 00:31:24.000000000 -0400
34 +++ linux-2.6.4-51.1/fs/ext3/iopen.c 2004-04-06 00:31:24.000000000 -0400
39 + * linux/fs/ext3/iopen.c
41 + * Special support for open by inode number
43 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
45 + * This file may be redistributed under the terms of the GNU General
49 +#include <linux/sched.h>
50 +#include <linux/fs.h>
51 +#include <linux/ext3_jbd.h>
52 +#include <linux/jbd.h>
53 +#include <linux/ext3_fs.h>
54 +#include <linux/smp_lock.h>
58 +#define assert(test) J_ASSERT(test)
61 +#define IOPEN_NAME_LEN 32
64 + * This implements looking up an inode by number.
66 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
68 + struct inode * inode;
70 + struct list_head *lp;
71 + struct dentry *alternate;
72 + char buf[IOPEN_NAME_LEN];
74 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
75 + return ERR_PTR(-ENAMETOOLONG);
77 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
78 + buf[dentry->d_name.len] = 0;
80 + if (strcmp(buf, ".") == 0)
82 + else if (strcmp(buf, "..") == 0)
83 + ino = EXT3_ROOT_INO;
85 + ino = simple_strtoul(buf, 0, 0);
87 + if ((ino != EXT3_ROOT_INO &&
88 + //ino != EXT3_ACL_IDX_INO &&
89 + //ino != EXT3_ACL_DATA_INO &&
90 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
91 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
92 + return ERR_PTR(-ENOENT);
94 + inode = iget(dir->i_sb, ino);
96 + return ERR_PTR(-EACCES);
97 + if (is_bad_inode(inode)) {
99 + return ERR_PTR(-ENOENT);
102 + /* preferrably return a connected dentry */
103 + spin_lock(&dcache_lock);
104 + list_for_each(lp, &inode->i_dentry) {
105 + alternate = list_entry(lp, struct dentry, d_alias);
106 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
109 + if (!list_empty(&inode->i_dentry)) {
110 + alternate = list_entry(inode->i_dentry.next,
111 + struct dentry, d_alias);
112 + dget_locked(alternate);
113 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
115 + spin_unlock(&dcache_lock);
118 + dentry->d_flags |= DCACHE_DISCONNECTED;
119 + spin_unlock(&dcache_lock);
121 + d_add(dentry, inode);
125 +#define do_switch(x,y) do { \
126 + __typeof__ (x) __tmp = x; \
127 + x = y; y = __tmp; } while (0)
129 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
131 + const unsigned char *old_name, *new_name;
133 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
134 + old_name = target->d_name.name;
135 + new_name = dentry->d_name.name;
136 + if (old_name == target->d_iname)
137 + old_name = dentry->d_iname;
138 + if (new_name == dentry->d_iname)
139 + new_name = target->d_iname;
140 + target->d_name.name = new_name;
141 + dentry->d_name.name = old_name;
145 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
147 + struct dentry *tmp, *goal = NULL;
148 + struct list_head *lp;
150 + /* preferrably return a connected dentry */
151 + spin_lock(&dcache_lock);
152 + /* verify this dentry is really new */
153 + assert(!de->d_inode);
154 + assert(list_empty(&de->d_subdirs));
155 + assert(list_empty(&de->d_alias));
158 + list_for_each(lp, &inode->i_dentry) {
159 + tmp = list_entry(lp, struct dentry, d_alias);
160 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
161 + assert(tmp->d_alias.next == &inode->i_dentry);
162 + assert(tmp->d_alias.prev == &inode->i_dentry);
168 + spin_unlock(&dcache_lock);
173 + goal->d_flags &= ~DCACHE_DISCONNECTED;
181 + * These are the special structures for the iopen pseudo directory.
184 +static struct inode_operations iopen_inode_operations = {
185 + lookup: iopen_lookup, /* BKL held */
188 +static struct file_operations iopen_file_operations = {
189 + read: generic_read_dir,
192 +static int match_dentry(struct dentry *dentry, const char *name)
196 + len = strlen(name);
197 + if (dentry->d_name.len != len)
199 + if (strncmp(dentry->d_name.name, name, len))
205 + * This function is spliced into ext3_lookup and returns 1 the file
206 + * name is __iopen__ and dentry has been filled in appropriately.
208 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
210 + struct inode * inode;
212 + if (dir->i_ino != EXT3_ROOT_INO ||
213 + !test_opt(dir->i_sb, IOPEN) ||
214 + !match_dentry(dentry, "__iopen__"))
217 + inode = iget(dir->i_sb, EXT3_BAD_INO);
221 + d_add(dentry, inode);
226 + * This function is spliced into read_inode; it returns 1 if inode
227 + * number is the one for /__iopen__, in which case the inode is filled
228 + * in appropriately. Otherwise, this fuction returns 0.
230 +int ext3_iopen_get_inode(struct inode * inode)
232 + if (inode->i_ino != EXT3_BAD_INO)
235 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
236 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
237 + inode->i_mode |= 0777;
240 + inode->i_nlink = 1;
241 + inode->i_size = 4096;
242 + inode->i_atime = CURRENT_TIME;
243 + inode->i_ctime = CURRENT_TIME;
244 + inode->i_mtime = CURRENT_TIME;
245 + EXT3_I(inode)->i_dtime = 0;
246 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
247 + * (for stat), not the fs block
249 + inode->i_blocks = 0;
250 + inode->i_version = 1;
251 + inode->i_generation = 0;
253 + inode->i_op = &iopen_inode_operations;
254 + inode->i_fop = &iopen_file_operations;
255 + inode->i_mapping->a_ops = 0;
259 Index: linux-2.6.4-51.1/fs/ext3/iopen.h
260 ===================================================================
261 --- linux-2.6.4-51.1.orig/fs/ext3/iopen.h 2004-04-06 00:31:24.000000000 -0400
262 +++ linux-2.6.4-51.1/fs/ext3/iopen.h 2004-04-06 00:31:24.000000000 -0400
267 + * Special support for opening files by inode number.
269 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
271 + * This file may be redistributed under the terms of the GNU General
275 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
276 +extern int ext3_iopen_get_inode(struct inode * inode);
279 Index: linux-2.6.4-51.1/fs/ext3/namei.c
280 ===================================================================
281 --- linux-2.6.4-51.1.orig/fs/ext3/namei.c 2004-04-06 00:31:11.000000000 -0400
282 +++ linux-2.6.4-51.1/fs/ext3/namei.c 2004-04-06 00:31:24.000000000 -0400
284 #include <linux/buffer_head.h>
285 #include <linux/smp_lock.h>
291 @@ -970,15 +971,21 @@
295 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
297 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
299 struct inode * inode;
300 struct ext3_dir_entry_2 * de;
301 struct buffer_head * bh;
302 + struct dentry *alternate = NULL;
304 if (dentry->d_name.len > EXT3_NAME_LEN)
305 return ERR_PTR(-ENAMETOOLONG);
307 + if (ext3_check_for_iopen(dir, dentry))
310 bh = ext3_find_entry(dentry, &de);
315 return ERR_PTR(-EACCES);
317 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
323 return d_splice_alias(inode, dentry);
325 d_add(dentry, inode);
328 Index: linux-2.6.4-51.1/fs/ext3/super.c
329 ===================================================================
330 --- linux-2.6.4-51.1.orig/fs/ext3/super.c 2004-04-06 00:31:14.000000000 -0400
331 +++ linux-2.6.4-51.1/fs/ext3/super.c 2004-04-06 00:31:24.000000000 -0400
333 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
334 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
335 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
336 - Opt_ignore, Opt_err,
337 + Opt_ignore, Opt_err, Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
340 static match_table_t tokens = {
342 {Opt_ignore, "noquota"},
343 {Opt_ignore, "quota"},
344 {Opt_ignore, "usrquota"},
345 + {Opt_iopen, "iopen"},
346 + {Opt_noiopen, "noiopen"},
347 + {Opt_iopen_nopriv, "iopen_nopriv"},
353 set_opt(sbi->s_mount_opt, ABORT);
356 + set_opt (sbi->s_mount_opt, IOPEN);
357 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
360 + clear_opt (sbi->s_mount_opt, IOPEN);
361 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
363 + case Opt_iopen_nopriv:
364 + set_opt (sbi->s_mount_opt, IOPEN);
365 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
370 Index: linux-2.6.4-51.1/include/linux/ext3_fs.h
371 ===================================================================
372 --- linux-2.6.4-51.1.orig/include/linux/ext3_fs.h 2004-04-06 00:31:11.000000000 -0400
373 +++ linux-2.6.4-51.1/include/linux/ext3_fs.h 2004-04-06 00:31:24.000000000 -0400
375 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
376 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
377 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
378 +#define EXT3_MOUNT_IOPEN 0x10000 /* Allow access via iopen */
379 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x20000 /* Make iopen world-readable */
381 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
382 #ifndef _LINUX_EXT2_FS_H
383 Index: linux-2.6.4-51.1/fs/ext3/Makefile
384 ===================================================================
385 --- linux-2.6.4-51.1.orig/fs/ext3/Makefile 2004-04-06 00:27:21.000000000 -0400
386 +++ linux-2.6.4-51.1/fs/ext3/Makefile 2004-04-06 00:31:42.000000000 -0400
388 obj-$(CONFIG_EXT3_FS) += ext3.o
390 ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
391 - ioctl.o namei.o super.o symlink.o hash.o
392 + ioctl.o namei.o super.o symlink.o hash.o iopen.o
394 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
395 ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o