1 Documentation/filesystems/ext2.txt | 16 ++
4 fs/ext3/iopen.c | 259 +++++++++++++++++++++++++++++++++++++
8 include/linux/ext3_fs.h | 2
9 8 files changed, 318 insertions(+), 2 deletions(-)
11 --- linux/Documentation/filesystems/ext2.txt~iopen-2.4.20 Wed Jul 11 15:44:45 2001
12 +++ linux-mmonroe/Documentation/filesystems/ext2.txt Thu Jul 10 12:28:54 2003
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/fs/ext3/Makefile~iopen-2.4.20 Thu Jul 10 12:28:44 2003
37 +++ linux-mmonroe/fs/ext3/Makefile Thu Jul 10 12:28:54 2003
38 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
40 export-objs := ext3-exports.o
42 -obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
43 +obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
44 ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
47 --- linux/fs/ext3/inode.c~iopen-2.4.20 Thu Jul 10 12:28:46 2003
48 +++ linux-mmonroe/fs/ext3/inode.c Thu Jul 10 12:28:54 2003
50 #include <linux/highuid.h>
51 #include <linux/quotaops.h>
52 #include <linux/module.h>
56 * SEARCH_FROM_ZERO forces each block allocation to search from the start
57 @@ -2253,6 +2254,9 @@ void ext3_read_inode(struct inode * inod
58 struct buffer_head *bh;
61 + if (ext3_iopen_get_inode(inode))
64 if(ext3_get_inode_loc(inode, &iloc))
67 --- /dev/null Tue Jan 28 04:00:01 2003
68 +++ linux-mmonroe/fs/ext3/iopen.c Thu Jul 10 12:28:54 2003
71 + * linux/fs/ext3/iopen.c
73 + * Special support for open by inode number
75 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
77 + * This file may be redistributed under the terms of the GNU General
82 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
83 + * for an inode at one time.
84 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
85 + * aliases on an inode at the same time.
87 + * If we have any connected dentry aliases for an inode, use one of those
88 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
89 + * dentry for this inode, which thereafter will be found by the dcache
90 + * when looking up this inode number in __iopen__, so we don't return here
93 + * If we get an inode via a regular name lookup, then we "rename" the
94 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
95 + * existing users of the disconnected dentry will continue to use the same
96 + * dentry as the connected users, and there will never be both kinds of
97 + * dentry aliases at one time.
100 +#include <linux/sched.h>
101 +#include <linux/fs.h>
102 +#include <linux/locks.h>
103 +#include <linux/ext3_jbd.h>
104 +#include <linux/jbd.h>
105 +#include <linux/ext3_fs.h>
106 +#include <linux/smp_lock.h>
110 +#define assert(test) J_ASSERT(test)
113 +#define IOPEN_NAME_LEN 32
116 + * This implements looking up an inode by number.
118 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
120 + struct inode *inode;
122 + struct list_head *lp;
123 + struct dentry *alternate;
124 + char buf[IOPEN_NAME_LEN];
126 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
127 + return ERR_PTR(-ENAMETOOLONG);
129 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
130 + buf[dentry->d_name.len] = 0;
132 + if (strcmp(buf, ".") == 0)
134 + else if (strcmp(buf, "..") == 0)
135 + ino = EXT3_ROOT_INO;
137 + ino = simple_strtoul(buf, 0, 0);
139 + if ((ino != EXT3_ROOT_INO &&
140 + //ino != EXT3_ACL_IDX_INO &&
141 + //ino != EXT3_ACL_DATA_INO &&
142 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
143 + ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
144 + return ERR_PTR(-ENOENT);
146 + inode = iget(dir->i_sb, ino);
148 + return ERR_PTR(-EACCES);
149 + if (is_bad_inode(inode)) {
151 + return ERR_PTR(-ENOENT);
154 + /* preferrably return a connected dentry */
155 + spin_lock(&dcache_lock);
156 + list_for_each(lp, &inode->i_dentry) {
157 + alternate = list_entry(lp, struct dentry, d_alias);
158 + assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
161 + if (!list_empty(&inode->i_dentry)) {
162 + alternate = list_entry(inode->i_dentry.next,
163 + struct dentry, d_alias);
164 + dget_locked(alternate);
165 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
167 + spin_unlock(&dcache_lock);
170 + dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
171 + spin_unlock(&dcache_lock);
173 + d_add(dentry, inode);
177 +#define do_switch(x,y) do { \
178 + __typeof__ (x) __tmp = x; \
179 + x = y; y = __tmp; } while (0)
181 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
183 + const unsigned char *old_name, *new_name;
185 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
186 + old_name = target->d_name.name;
187 + new_name = dentry->d_name.name;
188 + if (old_name == target->d_iname)
189 + old_name = dentry->d_iname;
190 + if (new_name == dentry->d_iname)
191 + new_name = target->d_iname;
192 + target->d_name.name = new_name;
193 + dentry->d_name.name = old_name;
196 +/* This function is spliced into ext3_lookup and does the move of a
197 + * disconnected dentry (if it exists) to a connected dentry.
199 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
201 + struct dentry *tmp, *goal = NULL;
202 + struct list_head *lp;
204 + /* preferrably return a connected dentry */
205 + spin_lock(&dcache_lock);
206 + /* verify this dentry is really new */
207 + assert(!de->d_inode);
208 + assert(list_empty(&de->d_subdirs));
209 + assert(list_empty(&de->d_alias));
212 + list_for_each(lp, &inode->i_dentry) {
213 + tmp = list_entry(lp, struct dentry, d_alias);
214 + if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
215 + assert(tmp->d_alias.next == &inode->i_dentry);
216 + assert(tmp->d_alias.prev == &inode->i_dentry);
224 + spin_unlock(&dcache_lock);
228 + /* Move the goal to the de hash queue - like d_move() */
229 + goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
230 + list_del_init(&goal->d_hash);
232 + list_del(&goal->d_child);
233 + list_del(&de->d_child);
235 + /* Switch the parents and the names.. */
236 + switch_names(goal, de);
237 + do_switch(goal->d_parent, de->d_parent);
238 + do_switch(goal->d_name.len, de->d_name.len);
239 + do_switch(goal->d_name.hash, de->d_name.hash);
241 + /* And add them back to the (new) parent lists */
242 + list_add(&goal->d_child, &goal->d_parent->d_subdirs);
243 + list_add(&de->d_child, &de->d_parent->d_subdirs);
244 + __d_rehash(goal, 0);
245 + spin_unlock(&dcache_lock);
251 + * These are the special structures for the iopen pseudo directory.
254 +static struct inode_operations iopen_inode_operations = {
255 + lookup: iopen_lookup, /* BKL held */
258 +static struct file_operations iopen_file_operations = {
259 + read: generic_read_dir,
262 +static int match_dentry(struct dentry *dentry, const char *name)
266 + len = strlen(name);
267 + if (dentry->d_name.len != len)
269 + if (strncmp(dentry->d_name.name, name, len))
275 + * This function is spliced into ext3_lookup and returns 1 the file
276 + * name is __iopen__ and dentry has been filled in appropriately.
278 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
280 + struct inode *inode;
282 + if (dir->i_ino != EXT3_ROOT_INO ||
283 + !test_opt(dir->i_sb, IOPEN) ||
284 + !match_dentry(dentry, "__iopen__"))
287 + inode = iget(dir->i_sb, EXT3_BAD_INO);
291 + d_add(dentry, inode);
296 + * This function is spliced into read_inode; it returns 1 if inode
297 + * number is the one for /__iopen__, in which case the inode is filled
298 + * in appropriately. Otherwise, this fuction returns 0.
300 +int ext3_iopen_get_inode(struct inode *inode)
302 + if (inode->i_ino != EXT3_BAD_INO)
305 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
306 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
307 + inode->i_mode |= 0777;
310 + inode->i_nlink = 1;
311 + inode->i_size = 4096;
312 + inode->i_atime = CURRENT_TIME;
313 + inode->i_ctime = CURRENT_TIME;
314 + inode->i_mtime = CURRENT_TIME;
315 + inode->u.ext3_i.i_dtime = 0;
316 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
317 + * (for stat), not the fs block
319 + inode->i_blocks = 0;
320 + inode->i_version = 1;
321 + inode->i_generation = 0;
323 + inode->i_op = &iopen_inode_operations;
324 + inode->i_fop = &iopen_file_operations;
325 + inode->i_mapping->a_ops = 0;
329 --- /dev/null Tue Jan 28 04:00:01 2003
330 +++ linux-mmonroe/fs/ext3/iopen.h Thu Jul 10 12:28:54 2003
335 + * Special support for opening files by inode number.
337 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
339 + * This file may be redistributed under the terms of the GNU General
343 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
344 +extern int ext3_iopen_get_inode(struct inode *inode);
345 --- linux/fs/ext3/namei.c~iopen-2.4.20 Thu Jul 10 12:28:46 2003
346 +++ linux-mmonroe/fs/ext3/namei.c Thu Jul 10 12:28:54 2003
348 #include <linux/string.h>
349 #include <linux/locks.h>
350 #include <linux/quotaops.h>
355 * define how far ahead to read directories while searching them.
356 @@ -921,16 +921,21 @@ errout:
360 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
362 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
364 struct inode * inode;
365 struct ext3_dir_entry_2 * de;
366 struct buffer_head * bh;
367 + struct dentry *alternate = NULL;
369 if (dentry->d_name.len > EXT3_NAME_LEN)
370 return ERR_PTR(-ENAMETOOLONG);
372 + if (ext3_check_for_iopen(dir, dentry))
375 bh = ext3_find_entry(dentry, &de);
378 @@ -942,6 +947,12 @@ static struct dentry *ext3_lookup(struct
379 return ERR_PTR(-EACCES);
383 + if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
388 d_add(dentry, inode);
391 --- linux/fs/ext3/super.c~iopen-2.4.20 Thu Jul 10 12:28:45 2003
392 +++ linux-mmonroe/fs/ext3/super.c Thu Jul 10 12:28:54 2003
393 @@ -835,6 +835,17 @@ static int parse_options (char * options
394 || !strcmp (this_char, "quota")
395 || !strcmp (this_char, "usrquota"))
396 /* Don't do anything ;-) */ ;
397 + else if (!strcmp (this_char, "iopen")) {
398 + set_opt (sbi->s_mount_opt, IOPEN);
399 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
400 + } else if (!strcmp (this_char, "noiopen")) {
401 + clear_opt (sbi->s_mount_opt, IOPEN);
402 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
404 + else if (!strcmp (this_char, "iopen_nopriv")) {
405 + set_opt (sbi->s_mount_opt, IOPEN);
406 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
408 else if (!strcmp (this_char, "journal")) {
410 /* Eventually we will want to be able to create
411 --- linux/include/linux/ext3_fs.h~iopen-2.4.20 Thu Jul 10 12:28:46 2003
412 +++ linux-mmonroe/include/linux/ext3_fs.h Thu Jul 10 12:30:12 2003
413 @@ -322,6 +322,8 @@ struct ext3_inode {
414 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
415 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
416 #define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
417 +#define EXT3_MOUNT_IOPEN 0x8000 /* Allow access via iopen */
418 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x10000 /* Make iopen world-readable */
419 #define EXT3_MOUNT_ASYNCDEL 0x20000 /* Delayed deletion */
421 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */