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 --- linux-2.6.0-test6/Documentation/filesystems/ext2.txt~iopen-2.6.0-test6 2002-11-11 06:28:06.000000000 +0300
11 +++ linux-2.6.0-test6-alexey/Documentation/filesystems/ext2.txt 2003-10-14 17:03:48.000000000 +0400
12 @@ -35,6 +35,22 @@ resgid=n The group ID which may use th
14 sb=n Use alternate superblock at this location.
16 +iopen Makes an invisible pseudo-directory called
17 + __iopen__ available in the root directory
18 + of the filesystem. Allows open-by-inode-
19 + number. i.e., inode 3145 can be accessed
20 + via /mntpt/__iopen__/3145
22 +iopen_nopriv This option makes the iopen directory be
23 + world-readable. This may be safer since it
24 + allows daemons to run as an unprivileged user,
25 + however it significantly changes the security
26 + model of a Unix filesystem, since previously
27 + all files under a mode 700 directory were not
28 + generally avilable even if the
29 + permissions on the file itself is
32 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
35 --- linux-2.6.0-test6/fs/ext3/inode.c~iopen-2.6.0-test6 2003-10-14 17:03:47.000000000 +0400
36 +++ linux-2.6.0-test6-alexey/fs/ext3/inode.c 2003-10-14 17:03:48.000000000 +0400
38 #include <linux/mpage.h>
39 #include <linux/uio.h>
45 @@ -2479,6 +2480,8 @@ void ext3_read_inode(struct inode * inod
46 ei->i_acl = EXT3_ACL_NOT_CACHED;
47 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
49 + if (ext3_iopen_get_inode(inode))
51 if (ext3_get_inode_loc(inode, &iloc, 0))
54 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
55 +++ linux-2.6.0-test6-alexey/fs/ext3/iopen.c 2003-10-14 17:03:48.000000000 +0400
60 + * linux/fs/ext3/iopen.c
62 + * Special support for open by inode number
64 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
66 + * This file may be redistributed under the terms of the GNU General
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>
79 +#define assert(test) J_ASSERT(test)
82 +#define IOPEN_NAME_LEN 32
85 + * This implements looking up an inode by number.
87 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
89 + struct inode * inode;
91 + struct list_head *lp;
92 + struct dentry *alternate;
93 + char buf[IOPEN_NAME_LEN];
95 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
96 + return ERR_PTR(-ENAMETOOLONG);
98 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
99 + buf[dentry->d_name.len] = 0;
101 + if (strcmp(buf, ".") == 0)
103 + else if (strcmp(buf, "..") == 0)
104 + ino = EXT3_ROOT_INO;
106 + ino = simple_strtoul(buf, 0, 0);
108 + if ((ino != EXT3_ROOT_INO &&
109 + //ino != EXT3_ACL_IDX_INO &&
110 + //ino != EXT3_ACL_DATA_INO &&
111 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
112 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
113 + return ERR_PTR(-ENOENT);
115 + inode = iget(dir->i_sb, ino);
117 + return ERR_PTR(-EACCES);
118 + if (is_bad_inode(inode)) {
120 + return ERR_PTR(-ENOENT);
123 + /* preferrably return a connected dentry */
124 + spin_lock(&dcache_lock);
125 + list_for_each(lp, &inode->i_dentry) {
126 + alternate = list_entry(lp, struct dentry, d_alias);
127 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
130 + if (!list_empty(&inode->i_dentry)) {
131 + alternate = list_entry(inode->i_dentry.next,
132 + struct dentry, d_alias);
133 + dget_locked(alternate);
134 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
136 + spin_unlock(&dcache_lock);
139 + dentry->d_flags |= DCACHE_DISCONNECTED;
140 + spin_unlock(&dcache_lock);
142 + d_add(dentry, inode);
146 +#define do_switch(x,y) do { \
147 + __typeof__ (x) __tmp = x; \
148 + x = y; y = __tmp; } while (0)
150 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
152 + const unsigned char *old_name, *new_name;
154 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
155 + old_name = target->d_name.name;
156 + new_name = dentry->d_name.name;
157 + if (old_name == target->d_iname)
158 + old_name = dentry->d_iname;
159 + if (new_name == dentry->d_iname)
160 + new_name = target->d_iname;
161 + target->d_name.name = new_name;
162 + dentry->d_name.name = old_name;
166 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
168 + struct dentry *tmp, *goal = NULL;
169 + struct list_head *lp;
171 + /* preferrably return a connected dentry */
172 + spin_lock(&dcache_lock);
173 + /* verify this dentry is really new */
174 + assert(!de->d_inode);
175 + assert(list_empty(&de->d_subdirs));
176 + assert(list_empty(&de->d_alias));
179 + list_for_each(lp, &inode->i_dentry) {
180 + tmp = list_entry(lp, struct dentry, d_alias);
181 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
182 + assert(tmp->d_alias.next == &inode->i_dentry);
183 + assert(tmp->d_alias.prev == &inode->i_dentry);
191 + spin_unlock(&dcache_lock);
195 + /* Move the goal to the de hash queue */
196 + goal->d_flags &= ~DCACHE_DISCONNECTED;
197 + hlist_add_before(&goal->d_hash, &de->d_hash);
198 + hlist_del(&goal->d_hash);
200 + list_del(&goal->d_child);
201 + list_del(&de->d_child);
203 + /* Switch the parents and the names.. */
204 + switch_names(goal, de);
205 + do_switch(goal->d_parent, de->d_parent);
206 + do_switch(goal->d_name.len, de->d_name.len);
207 + do_switch(goal->d_name.hash, de->d_name.hash);
209 + /* And add them back to the (new) parent lists */
210 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
211 + list_add(&de->d_child, &de->d_parent->d_subdirs);
213 + spin_unlock(&dcache_lock);
218 + * These are the special structures for the iopen pseudo directory.
221 +static struct inode_operations iopen_inode_operations = {
222 + lookup: iopen_lookup, /* BKL held */
225 +static struct file_operations iopen_file_operations = {
226 + read: generic_read_dir,
229 +static int match_dentry(struct dentry *dentry, const char *name)
233 + len = strlen(name);
234 + if (dentry->d_name.len != len)
236 + if (strncmp(dentry->d_name.name, name, len))
242 + * This function is spliced into ext3_lookup and returns 1 the file
243 + * name is __iopen__ and dentry has been filled in appropriately.
245 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
247 + struct inode * inode;
249 + if (dir->i_ino != EXT3_ROOT_INO ||
250 + !test_opt(dir->i_sb, IOPEN) ||
251 + !match_dentry(dentry, "__iopen__"))
254 + inode = iget(dir->i_sb, EXT3_BAD_INO);
258 + d_add(dentry, inode);
263 + * This function is spliced into read_inode; it returns 1 if inode
264 + * number is the one for /__iopen__, in which case the inode is filled
265 + * in appropriately. Otherwise, this fuction returns 0.
267 +int ext3_iopen_get_inode(struct inode * inode)
269 + if (inode->i_ino != EXT3_BAD_INO)
272 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
273 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
274 + inode->i_mode |= 0777;
277 + inode->i_nlink = 1;
278 + inode->i_size = 4096;
279 + inode->i_atime = CURRENT_TIME;
280 + inode->i_ctime = CURRENT_TIME;
281 + inode->i_mtime = CURRENT_TIME;
282 + EXT3_I(inode)->i_dtime = 0;
283 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
284 + * (for stat), not the fs block
286 + inode->i_blocks = 0;
287 + inode->i_version = 1;
288 + inode->i_generation = 0;
290 + inode->i_op = &iopen_inode_operations;
291 + inode->i_fop = &iopen_file_operations;
292 + inode->i_mapping->a_ops = 0;
296 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
297 +++ linux-2.6.0-test6-alexey/fs/ext3/iopen.h 2003-10-14 17:03:48.000000000 +0400
302 + * Special support for opening files by inode number.
304 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
306 + * This file may be redistributed under the terms of the GNU General
310 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
311 +extern int ext3_iopen_get_inode(struct inode * inode);
314 --- linux-2.6.0-test6/fs/ext3/namei.c~iopen-2.6.0-test6 2003-10-14 17:03:47.000000000 +0400
315 +++ linux-2.6.0-test6-alexey/fs/ext3/namei.c 2003-10-14 17:03:48.000000000 +0400
317 #include <linux/buffer_head.h>
318 #include <linux/smp_lock.h>
324 @@ -970,15 +971,21 @@ errout:
328 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
330 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
332 struct inode * inode;
333 struct ext3_dir_entry_2 * de;
334 struct buffer_head * bh;
335 + struct dentry *alternate = NULL;
337 if (dentry->d_name.len > EXT3_NAME_LEN)
338 return ERR_PTR(-ENAMETOOLONG);
340 + if (ext3_check_for_iopen(dir, dentry))
343 bh = ext3_find_entry(dentry, &de);
346 @@ -991,6 +998,12 @@ static struct dentry *ext3_lookup(struct
349 return d_splice_alias(inode, dentry);
351 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
356 d_add(dentry, inode);
359 --- linux-2.6.0-test6/fs/ext3/super.c~iopen-2.6.0-test6 2003-10-14 17:03:47.000000000 +0400
360 +++ linux-2.6.0-test6-alexey/fs/ext3/super.c 2003-10-14 17:03:48.000000000 +0400
361 @@ -534,7 +534,7 @@ enum {
362 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, Opt_noload,
363 Opt_commit, Opt_journal_update, Opt_journal_inum,
364 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
365 - Opt_ignore, Opt_err,
366 + Opt_ignore, Opt_err, Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
369 static match_table_t tokens = {
370 @@ -573,6 +573,9 @@ static match_table_t tokens = {
371 {Opt_ignore, "noquota"},
372 {Opt_ignore, "quota"},
373 {Opt_ignore, "usrquota"},
374 + {Opt_iopen, "iopen"},
375 + {Opt_noiopen, "noiopen"},
376 + {Opt_iopen_nopriv, "iopen_nopriv"},
380 @@ -760,6 +763,18 @@ static int parse_options (char * options
382 set_opt(sbi->s_mount_opt, ABORT);
385 + set_opt (sbi->s_mount_opt, IOPEN);
386 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
389 + clear_opt (sbi->s_mount_opt, IOPEN);
390 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
392 + case Opt_iopen_nopriv:
393 + set_opt (sbi->s_mount_opt, IOPEN);
394 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
399 --- linux-2.6.0-test6/include/linux/ext3_fs.h~iopen-2.6.0-test6 2003-10-14 17:03:47.000000000 +0400
400 +++ linux-2.6.0-test6-alexey/include/linux/ext3_fs.h 2003-10-14 17:03:48.000000000 +0400
401 @@ -325,6 +325,8 @@ struct ext3_inode {
402 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
403 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
404 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
405 +#define EXT3_MOUNT_IOPEN 0x10000 /* Allow access via iopen */
406 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x20000 /* Make iopen world-readable */
408 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
409 #ifndef _LINUX_EXT2_FS_H