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.6.0 2002-11-11 06:28:06.000000000 +0300
12 +++ linux-2.6.0-test1-alexey/Documentation/filesystems/ext2.txt 2003-08-24 13:02:02.000000000 +0400
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/inode.c~iopen-2.6.0 2003-08-24 13:00:36.000000000 +0400
37 +++ linux-2.6.0-test1-alexey/fs/ext3/inode.c 2003-08-24 13:02:02.000000000 +0400
39 #include <linux/mpage.h>
40 #include <linux/uio.h>
46 @@ -2477,6 +2478,8 @@ void ext3_read_inode(struct inode * inod
47 ei->i_acl = EXT3_ACL_NOT_CACHED;
48 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
50 + if (ext3_iopen_get_inode(inode))
52 if (ext3_get_inode_loc(inode, &iloc, 0))
55 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
56 +++ linux-2.6.0-test1-alexey/fs/ext3/iopen.c 2003-08-24 13:02:02.000000000 +0400
61 + * linux/fs/ext3/iopen.c
63 + * Special support for open by inode number
65 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
67 + * This file may be redistributed under the terms of the GNU General
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>
80 +#define assert(test) J_ASSERT(test)
83 +#define IOPEN_NAME_LEN 32
86 + * This implements looking up an inode by number.
88 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
90 + struct inode * inode;
92 + struct list_head *lp;
93 + struct dentry *alternate;
94 + char buf[IOPEN_NAME_LEN];
96 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
97 + return ERR_PTR(-ENAMETOOLONG);
99 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
100 + buf[dentry->d_name.len] = 0;
102 + if (strcmp(buf, ".") == 0)
104 + else if (strcmp(buf, "..") == 0)
105 + ino = EXT3_ROOT_INO;
107 + ino = simple_strtoul(buf, 0, 0);
109 + if ((ino != EXT3_ROOT_INO &&
110 + //ino != EXT3_ACL_IDX_INO &&
111 + //ino != EXT3_ACL_DATA_INO &&
112 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
113 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
114 + return ERR_PTR(-ENOENT);
116 + inode = iget(dir->i_sb, ino);
118 + return ERR_PTR(-EACCES);
119 + if (is_bad_inode(inode)) {
121 + return ERR_PTR(-ENOENT);
124 + /* preferrably return a connected dentry */
125 + spin_lock(&dcache_lock);
126 + list_for_each(lp, &inode->i_dentry) {
127 + alternate = list_entry(lp, struct dentry, d_alias);
128 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
131 + if (!list_empty(&inode->i_dentry)) {
132 + alternate = list_entry(inode->i_dentry.next,
133 + struct dentry, d_alias);
134 + dget_locked(alternate);
135 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
137 + spin_unlock(&dcache_lock);
140 + dentry->d_flags |= DCACHE_DISCONNECTED;
141 + spin_unlock(&dcache_lock);
143 + d_add(dentry, inode);
147 +#define do_switch(x,y) do { \
148 + __typeof__ (x) __tmp = x; \
149 + x = y; y = __tmp; } while (0)
151 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
153 + const unsigned char *old_name, *new_name;
155 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
156 + old_name = target->d_name.name;
157 + new_name = dentry->d_name.name;
158 + if (old_name == target->d_iname)
159 + old_name = dentry->d_iname;
160 + if (new_name == dentry->d_iname)
161 + new_name = target->d_iname;
162 + target->d_name.name = new_name;
163 + dentry->d_name.name = old_name;
167 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
169 + struct dentry *tmp, *goal = NULL;
170 + struct list_head *lp;
172 + /* preferrably return a connected dentry */
173 + spin_lock(&dcache_lock);
174 + /* verify this dentry is really new */
175 + assert(!de->d_inode);
176 + assert(list_empty(&de->d_subdirs));
177 + assert(list_empty(&de->d_alias));
180 + list_for_each(lp, &inode->i_dentry) {
181 + tmp = list_entry(lp, struct dentry, d_alias);
182 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
183 + assert(tmp->d_alias.next == &inode->i_dentry);
184 + assert(tmp->d_alias.prev == &inode->i_dentry);
192 + spin_unlock(&dcache_lock);
196 + /* Move the goal to the de hash queue */
197 + goal->d_flags &= ~DCACHE_DISCONNECTED;
198 + hlist_add_before(&goal->d_hash, &de->d_hash);
199 + hlist_del(&goal->d_hash);
201 + list_del(&goal->d_child);
202 + list_del(&de->d_child);
204 + /* Switch the parents and the names.. */
205 + switch_names(goal, de);
206 + do_switch(goal->d_parent, de->d_parent);
207 + do_switch(goal->d_name.len, de->d_name.len);
208 + do_switch(goal->d_name.hash, de->d_name.hash);
210 + /* And add them back to the (new) parent lists */
211 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
212 + list_add(&de->d_child, &de->d_parent->d_subdirs);
214 + spin_unlock(&dcache_lock);
219 + * These are the special structures for the iopen pseudo directory.
222 +static struct inode_operations iopen_inode_operations = {
223 + lookup: iopen_lookup, /* BKL held */
226 +static struct file_operations iopen_file_operations = {
227 + read: generic_read_dir,
230 +static int match_dentry(struct dentry *dentry, const char *name)
234 + len = strlen(name);
235 + if (dentry->d_name.len != len)
237 + if (strncmp(dentry->d_name.name, name, len))
243 + * This function is spliced into ext3_lookup and returns 1 the file
244 + * name is __iopen__ and dentry has been filled in appropriately.
246 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
248 + struct inode * inode;
250 + if (dir->i_ino != EXT3_ROOT_INO ||
251 + !test_opt(dir->i_sb, IOPEN) ||
252 + !match_dentry(dentry, "__iopen__"))
255 + inode = iget(dir->i_sb, EXT3_BAD_INO);
259 + d_add(dentry, inode);
264 + * This function is spliced into read_inode; it returns 1 if inode
265 + * number is the one for /__iopen__, in which case the inode is filled
266 + * in appropriately. Otherwise, this fuction returns 0.
268 +int ext3_iopen_get_inode(struct inode * inode)
270 + if (inode->i_ino != EXT3_BAD_INO)
273 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
274 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
275 + inode->i_mode |= 0777;
278 + inode->i_nlink = 1;
279 + inode->i_size = 4096;
280 + inode->i_atime = CURRENT_TIME;
281 + inode->i_ctime = CURRENT_TIME;
282 + inode->i_mtime = CURRENT_TIME;
283 + EXT3_I(inode)->i_dtime = 0;
284 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
285 + * (for stat), not the fs block
287 + inode->i_blocks = 0;
288 + inode->i_version = 1;
289 + inode->i_generation = 0;
291 + inode->i_op = &iopen_inode_operations;
292 + inode->i_fop = &iopen_file_operations;
293 + inode->i_mapping->a_ops = 0;
297 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
298 +++ linux-2.6.0-test1-alexey/fs/ext3/iopen.h 2003-08-24 13:02:02.000000000 +0400
303 + * Special support for opening files by inode number.
305 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
307 + * This file may be redistributed under the terms of the GNU General
311 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
312 +extern int ext3_iopen_get_inode(struct inode * inode);
315 --- linux-2.6.0-test1/fs/ext3/Makefile~iopen-2.6.0 2003-08-24 12:58:32.000000000 +0400
316 +++ linux-2.6.0-test1-alexey/fs/ext3/Makefile 2003-08-24 13:02:40.000000000 +0400
318 obj-$(CONFIG_EXT3_FS) += ext3.o
320 ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
321 - ioctl.o namei.o super.o symlink.o hash.o
322 + iopen.o ioctl.o namei.o super.o symlink.o hash.o
324 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
325 ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
326 --- linux-2.6.0-test1/fs/ext3/namei.c~iopen-2.6.0 2003-07-24 15:52:30.000000000 +0400
327 +++ linux-2.6.0-test1-alexey/fs/ext3/namei.c 2003-08-24 13:02:02.000000000 +0400
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.6.0 2003-08-24 13:00:36.000000000 +0400
372 +++ linux-2.6.0-test1-alexey/fs/ext3/super.c 2003-08-24 13:02:02.000000000 +0400
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.6.0 2003-08-24 12:58:57.000000000 +0400
392 +++ linux-2.6.0-test1-alexey/include/linux/ext3_fs.h 2003-08-24 13:02:02.000000000 +0400
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