1 Documentation/filesystems/ext2.txt | 16 ++
4 fs/ext3/iopen.c | 239 +++++++++++++++++++++++++++++++++++++
5 fs/ext3/iopen.h | 15 ++
6 fs/ext3/namei.c | 13 ++
8 include/linux/ext3_fs.h | 2
9 8 files changed, 300 insertions(+), 1 deletion(-)
11 --- linux-2.6.0-test1/Documentation/filesystems/ext2.txt~iopen-2.5.73 2003-07-13 21:31:56.000000000 -0600
12 +++ linux-2.6.0-test1-braam/Documentation/filesystems/ext2.txt 2003-07-22 13:03:47.000000000 -0600
13 @@ -35,6 +35,22 @@ resgid=n The group ID which may use th
15 sb=n Use alternate superblock at this location.
17 +iopen Makes an invisible pseudo-directory called
18 + __iopen__ available in the root directory
19 + of the filesystem. Allows open-by-inode-
20 + number. i.e., inode 3145 can be accessed
21 + via /mntpt/__iopen__/3145
23 +iopen_nopriv This option makes the iopen directory be
24 + world-readable. This may be safer since it
25 + allows daemons to run as an unprivileged user,
26 + however it significantly changes the security
27 + model of a Unix filesystem, since previously
28 + all files under a mode 700 directory were not
29 + generally avilable even if the
30 + permissions on the file itself is
33 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
36 --- linux-2.6.0-test1/fs/ext3/Makefile~iopen-2.5.73 2003-07-13 21:30:37.000000000 -0600
37 +++ linux-2.6.0-test1-braam/fs/ext3/Makefile 2003-07-22 13:03:47.000000000 -0600
39 obj-$(CONFIG_EXT3_FS) += ext3.o
41 ext3-objs := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
42 - ioctl.o namei.o super.o symlink.o hash.o
43 + iopen.o ioctl.o namei.o super.o symlink.o hash.o
45 ifeq ($(CONFIG_EXT3_FS_XATTR),y)
46 ext3-objs += xattr.o xattr_user.o xattr_trusted.o
47 --- linux-2.6.0-test1/fs/ext3/inode.c~iopen-2.5.73 2003-07-22 13:03:47.000000000 -0600
48 +++ linux-2.6.0-test1-braam/fs/ext3/inode.c 2003-07-22 13:03:47.000000000 -0600
50 #include <linux/mpage.h>
51 #include <linux/uio.h>
57 @@ -2478,6 +2479,8 @@ void ext3_read_inode(struct inode * inod
58 ei->i_acl = EXT3_ACL_NOT_CACHED;
59 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
61 + if (ext3_iopen_get_inode(inode))
63 if (ext3_get_inode_loc(inode, &iloc, 0))
66 --- /dev/null 2003-01-30 03:24:37.000000000 -0700
67 +++ linux-2.6.0-test1-braam/fs/ext3/iopen.c 2003-07-22 13:07:32.000000000 -0600
72 + * linux/fs/ext3/iopen.c
74 + * Special support for open by inode number
76 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
78 + * This file may be redistributed under the terms of the GNU General
82 +#include <linux/sched.h>
83 +#include <linux/fs.h>
84 +#include <linux/ext3_jbd.h>
85 +#include <linux/jbd.h>
86 +#include <linux/ext3_fs.h>
87 +#include <linux/smp_lock.h>
91 +#define assert(test) J_ASSERT(test)
94 +#define IOPEN_NAME_LEN 32
97 + * This implements looking up an inode by number.
99 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
101 + struct inode * inode;
103 + struct list_head *lp;
104 + struct dentry *alternate;
105 + char buf[IOPEN_NAME_LEN];
107 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
108 + return ERR_PTR(-ENAMETOOLONG);
110 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
111 + buf[dentry->d_name.len] = 0;
113 + if (strcmp(buf, ".") == 0)
115 + else if (strcmp(buf, "..") == 0)
116 + ino = EXT3_ROOT_INO;
118 + ino = simple_strtoul(buf, 0, 0);
120 + if ((ino != EXT3_ROOT_INO &&
121 + //ino != EXT3_ACL_IDX_INO &&
122 + //ino != EXT3_ACL_DATA_INO &&
123 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
124 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
125 + return ERR_PTR(-ENOENT);
127 + inode = iget(dir->i_sb, ino);
129 + return ERR_PTR(-EACCES);
130 + if (is_bad_inode(inode)) {
132 + return ERR_PTR(-ENOENT);
135 + /* preferrably return a connected dentry */
136 + spin_lock(&dcache_lock);
137 + list_for_each(lp, &inode->i_dentry) {
138 + alternate = list_entry(lp, struct dentry, d_alias);
139 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
142 + if (!list_empty(&inode->i_dentry)) {
143 + alternate = list_entry(inode->i_dentry.next,
144 + struct dentry, d_alias);
145 + dget_locked(alternate);
146 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
148 + spin_unlock(&dcache_lock);
151 + dentry->d_flags |= DCACHE_DISCONNECTED;
152 + spin_unlock(&dcache_lock);
154 + d_add(dentry, inode);
158 +#define do_switch(x,y) do { \
159 + __typeof__ (x) __tmp = x; \
160 + x = y; y = __tmp; } while (0)
162 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
164 + const unsigned char *old_name, *new_name;
166 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
167 + old_name = target->d_name.name;
168 + new_name = dentry->d_name.name;
169 + if (old_name == target->d_iname)
170 + old_name = dentry->d_iname;
171 + if (new_name == dentry->d_iname)
172 + new_name = target->d_iname;
173 + target->d_name.name = new_name;
174 + dentry->d_name.name = old_name;
178 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
180 + struct dentry *tmp, *goal = NULL;
181 + struct list_head *lp;
183 + /* preferrably return a connected dentry */
184 + spin_lock(&dcache_lock);
185 + /* verify this dentry is really new */
186 + assert(!de->d_inode);
187 + assert(list_empty(&de->d_subdirs));
188 + assert(list_empty(&de->d_alias));
191 + list_for_each(lp, &inode->i_dentry) {
192 + tmp = list_entry(lp, struct dentry, d_alias);
193 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
194 + assert(tmp->d_alias.next == &inode->i_dentry);
195 + assert(tmp->d_alias.prev == &inode->i_dentry);
203 + spin_unlock(&dcache_lock);
207 + /* Move the goal to the de hash queue */
208 + goal->d_flags &= ~DCACHE_DISCONNECTED;
209 + hlist_add_before(&goal->d_hash, &de->d_hash);
210 + hlist_del(&goal->d_hash);
212 + list_del(&goal->d_child);
213 + list_del(&de->d_child);
215 + /* Switch the parents and the names.. */
216 + switch_names(goal, de);
217 + do_switch(goal->d_parent, de->d_parent);
218 + do_switch(goal->d_name.len, de->d_name.len);
219 + do_switch(goal->d_name.hash, de->d_name.hash);
221 + /* And add them back to the (new) parent lists */
222 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
223 + list_add(&de->d_child, &de->d_parent->d_subdirs);
225 + spin_unlock(&dcache_lock);
230 + * These are the special structures for the iopen pseudo directory.
233 +static struct inode_operations iopen_inode_operations = {
234 + lookup: iopen_lookup, /* BKL held */
237 +static struct file_operations iopen_file_operations = {
238 + read: generic_read_dir,
241 +static int match_dentry(struct dentry *dentry, const char *name)
245 + len = strlen(name);
246 + if (dentry->d_name.len != len)
248 + if (strncmp(dentry->d_name.name, name, len))
254 + * This function is spliced into ext3_lookup and returns 1 the file
255 + * name is __iopen__ and dentry has been filled in appropriately.
257 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
259 + struct inode * inode;
261 + if (dir->i_ino != EXT3_ROOT_INO ||
262 + !test_opt(dir->i_sb, IOPEN) ||
263 + !match_dentry(dentry, "__iopen__"))
266 + inode = iget(dir->i_sb, EXT3_BAD_INO);
270 + d_add(dentry, inode);
275 + * This function is spliced into read_inode; it returns 1 if inode
276 + * number is the one for /__iopen__, in which case the inode is filled
277 + * in appropriately. Otherwise, this fuction returns 0.
279 +int ext3_iopen_get_inode(struct inode * inode)
281 + if (inode->i_ino != EXT3_BAD_INO)
284 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
285 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
286 + inode->i_mode |= 0777;
289 + inode->i_nlink = 1;
290 + inode->i_size = 4096;
291 + inode->i_atime = CURRENT_TIME;
292 + inode->i_ctime = CURRENT_TIME;
293 + inode->i_mtime = CURRENT_TIME;
294 + EXT3_I(inode)->i_dtime = 0;
295 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
296 + * (for stat), not the fs block
298 + inode->i_blocks = 0;
299 + inode->i_version = 1;
300 + inode->i_generation = 0;
302 + inode->i_op = &iopen_inode_operations;
303 + inode->i_fop = &iopen_file_operations;
304 + inode->i_mapping->a_ops = 0;
308 --- /dev/null 2003-01-30 03:24:37.000000000 -0700
309 +++ linux-2.6.0-test1-braam/fs/ext3/iopen.h 2003-07-22 13:03:47.000000000 -0600
314 + * Special support for opening files by inode number.
316 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
318 + * This file may be redistributed under the terms of the GNU General
322 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
323 +extern int ext3_iopen_get_inode(struct inode * inode);
326 --- linux-2.6.0-test1/fs/ext3/namei.c~iopen-2.5.73 2003-07-13 21:34:43.000000000 -0600
327 +++ linux-2.6.0-test1-braam/fs/ext3/namei.c 2003-07-22 13:03:47.000000000 -0600
329 #include <linux/buffer_head.h>
330 #include <linux/smp_lock.h>
336 @@ -970,15 +971,21 @@ errout:
340 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
342 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
344 struct inode * inode;
345 struct ext3_dir_entry_2 * de;
346 struct buffer_head * bh;
347 + struct dentry *alternate = NULL;
349 if (dentry->d_name.len > EXT3_NAME_LEN)
350 return ERR_PTR(-ENAMETOOLONG);
352 + if (ext3_check_for_iopen(dir, dentry))
355 bh = ext3_find_entry(dentry, &de);
358 @@ -991,6 +998,12 @@ static struct dentry *ext3_lookup(struct
361 return d_splice_alias(inode, dentry);
363 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
368 d_add(dentry, inode);
371 --- linux-2.6.0-test1/fs/ext3/super.c~iopen-2.5.73 2003-07-22 13:03:47.000000000 -0600
372 +++ linux-2.6.0-test1-braam/fs/ext3/super.c 2003-07-22 13:03:47.000000000 -0600
373 @@ -755,6 +755,17 @@ static int parse_options (char * options
374 || !strcmp (this_char, "quota")
375 || !strcmp (this_char, "usrquota"))
376 /* Don't do anything ;-) */ ;
377 + else if (!strcmp (this_char, "iopen")) {
378 + set_opt (sbi->s_mount_opt, IOPEN);
379 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
380 + } else if (!strcmp (this_char, "noiopen")) {
381 + clear_opt (sbi->s_mount_opt, IOPEN);
382 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
384 + else if (!strcmp (this_char, "iopen_nopriv")) {
385 + set_opt (sbi->s_mount_opt, IOPEN);
386 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
388 else if (!strcmp (this_char, "journal")) {
390 /* Eventually we will want to be able to create
391 --- linux-2.6.0-test1/include/linux/ext3_fs.h~iopen-2.5.73 2003-07-22 11:04:35.000000000 -0600
392 +++ linux-2.6.0-test1-braam/include/linux/ext3_fs.h 2003-07-22 13:03:47.000000000 -0600
393 @@ -324,6 +324,8 @@ struct ext3_inode {
394 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
395 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
396 #define EXT3_MOUNT_POSIX_ACL 0x8000 /* POSIX Access Control Lists */
397 +#define EXT3_MOUNT_IOPEN 0x10000 /* Allow access via iopen */
398 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x20000 /* Make iopen world-readable */
400 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
401 #ifndef _LINUX_EXT2_FS_H