V4L/DVB (6864): upd64031a: CodingStyle cleanup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / autofs / inode.c
blob45f5992a0957173bc0c7e744028ef40e5743aa8e
1 /* -*- linux-c -*- --------------------------------------------------------- *
3 * linux/fs/autofs/inode.c
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
7 * This file is part of the Linux kernel and is made available under
8 * the terms of the GNU General Public License, version 2, or at your
9 * option, any later version, incorporated herein by reference.
11 * ------------------------------------------------------------------------- */
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/slab.h>
16 #include <linux/file.h>
17 #include <linux/parser.h>
18 #include <linux/bitops.h>
19 #include <linux/magic.h>
20 #include "autofs_i.h"
21 #include <linux/module.h>
23 void autofs_kill_sb(struct super_block *sb)
25 struct autofs_sb_info *sbi = autofs_sbi(sb);
26 unsigned int n;
29 * In the event of a failure in get_sb_nodev the superblock
30 * info is not present so nothing else has been setup, so
31 * just call kill_anon_super when we are called from
32 * deactivate_super.
34 if (!sbi)
35 goto out_kill_sb;
37 if (!sbi->catatonic)
38 autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
40 put_pid(sbi->oz_pgrp);
42 autofs_hash_nuke(sbi);
43 for (n = 0; n < AUTOFS_MAX_SYMLINKS; n++) {
44 if (test_bit(n, sbi->symlink_bitmap))
45 kfree(sbi->symlink[n].data);
48 kfree(sb->s_fs_info);
50 out_kill_sb:
51 DPRINTK(("autofs: shutting down\n"));
52 kill_anon_super(sb);
55 static void autofs_read_inode(struct inode *inode);
57 static const struct super_operations autofs_sops = {
58 .read_inode = autofs_read_inode,
59 .statfs = simple_statfs,
62 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
64 static match_table_t autofs_tokens = {
65 {Opt_fd, "fd=%u"},
66 {Opt_uid, "uid=%u"},
67 {Opt_gid, "gid=%u"},
68 {Opt_pgrp, "pgrp=%u"},
69 {Opt_minproto, "minproto=%u"},
70 {Opt_maxproto, "maxproto=%u"},
71 {Opt_err, NULL}
74 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
75 pid_t *pgrp, int *minproto, int *maxproto)
77 char *p;
78 substring_t args[MAX_OPT_ARGS];
79 int option;
81 *uid = current->uid;
82 *gid = current->gid;
83 *pgrp = task_pgrp_nr(current);
85 *minproto = *maxproto = AUTOFS_PROTO_VERSION;
87 *pipefd = -1;
89 if (!options)
90 return 1;
92 while ((p = strsep(&options, ",")) != NULL) {
93 int token;
94 if (!*p)
95 continue;
97 token = match_token(p, autofs_tokens, args);
98 switch (token) {
99 case Opt_fd:
100 if (match_int(&args[0], &option))
101 return 1;
102 *pipefd = option;
103 break;
104 case Opt_uid:
105 if (match_int(&args[0], &option))
106 return 1;
107 *uid = option;
108 break;
109 case Opt_gid:
110 if (match_int(&args[0], &option))
111 return 1;
112 *gid = option;
113 break;
114 case Opt_pgrp:
115 if (match_int(&args[0], &option))
116 return 1;
117 *pgrp = option;
118 break;
119 case Opt_minproto:
120 if (match_int(&args[0], &option))
121 return 1;
122 *minproto = option;
123 break;
124 case Opt_maxproto:
125 if (match_int(&args[0], &option))
126 return 1;
127 *maxproto = option;
128 break;
129 default:
130 return 1;
133 return (*pipefd < 0);
136 int autofs_fill_super(struct super_block *s, void *data, int silent)
138 struct inode * root_inode;
139 struct dentry * root;
140 struct file * pipe;
141 int pipefd;
142 struct autofs_sb_info *sbi;
143 int minproto, maxproto;
144 pid_t pgid;
146 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
147 if (!sbi)
148 goto fail_unlock;
149 DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
151 s->s_fs_info = sbi;
152 sbi->magic = AUTOFS_SBI_MAGIC;
153 sbi->pipe = NULL;
154 sbi->catatonic = 1;
155 sbi->exp_timeout = 0;
156 autofs_initialize_hash(&sbi->dirhash);
157 sbi->queues = NULL;
158 memset(sbi->symlink_bitmap, 0, sizeof(long)*AUTOFS_SYMLINK_BITMAP_LEN);
159 sbi->next_dir_ino = AUTOFS_FIRST_DIR_INO;
160 s->s_blocksize = 1024;
161 s->s_blocksize_bits = 10;
162 s->s_magic = AUTOFS_SUPER_MAGIC;
163 s->s_op = &autofs_sops;
164 s->s_time_gran = 1;
165 sbi->sb = s;
167 root_inode = iget(s, AUTOFS_ROOT_INO);
168 root = d_alloc_root(root_inode);
169 pipe = NULL;
171 if (!root)
172 goto fail_iput;
174 /* Can this call block? - WTF cares? s is locked. */
175 if (parse_options(data, &pipefd, &root_inode->i_uid,
176 &root_inode->i_gid, &pgid, &minproto,
177 &maxproto)) {
178 printk("autofs: called with bogus options\n");
179 goto fail_dput;
182 /* Couldn't this be tested earlier? */
183 if (minproto > AUTOFS_PROTO_VERSION ||
184 maxproto < AUTOFS_PROTO_VERSION) {
185 printk("autofs: kernel does not match daemon version\n");
186 goto fail_dput;
189 DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, pgid));
190 sbi->oz_pgrp = find_get_pid(pgid);
192 if (!sbi->oz_pgrp) {
193 printk("autofs: could not find process group %d\n", pgid);
194 goto fail_dput;
197 pipe = fget(pipefd);
199 if (!pipe) {
200 printk("autofs: could not open pipe file descriptor\n");
201 goto fail_put_pid;
204 if (!pipe->f_op || !pipe->f_op->write)
205 goto fail_fput;
206 sbi->pipe = pipe;
207 sbi->catatonic = 0;
210 * Success! Install the root dentry now to indicate completion.
212 s->s_root = root;
213 return 0;
215 fail_fput:
216 printk("autofs: pipe file descriptor does not contain proper ops\n");
217 fput(pipe);
218 fail_put_pid:
219 put_pid(sbi->oz_pgrp);
220 fail_dput:
221 dput(root);
222 goto fail_free;
223 fail_iput:
224 printk("autofs: get root dentry failed\n");
225 iput(root_inode);
226 fail_free:
227 kfree(sbi);
228 s->s_fs_info = NULL;
229 fail_unlock:
230 return -EINVAL;
233 static void autofs_read_inode(struct inode *inode)
235 ino_t ino = inode->i_ino;
236 unsigned int n;
237 struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
239 /* Initialize to the default case (stub directory) */
241 inode->i_op = &simple_dir_inode_operations;
242 inode->i_fop = &simple_dir_operations;
243 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
244 inode->i_nlink = 2;
245 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
246 inode->i_blocks = 0;
248 if (ino == AUTOFS_ROOT_INO) {
249 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
250 inode->i_op = &autofs_root_inode_operations;
251 inode->i_fop = &autofs_root_operations;
252 inode->i_uid = inode->i_gid = 0; /* Changed in read_super */
253 return;
256 inode->i_uid = inode->i_sb->s_root->d_inode->i_uid;
257 inode->i_gid = inode->i_sb->s_root->d_inode->i_gid;
259 if (ino >= AUTOFS_FIRST_SYMLINK && ino < AUTOFS_FIRST_DIR_INO) {
260 /* Symlink inode - should be in symlink list */
261 struct autofs_symlink *sl;
263 n = ino - AUTOFS_FIRST_SYMLINK;
264 if (n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap)) {
265 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino);
266 return;
269 inode->i_op = &autofs_symlink_inode_operations;
270 sl = &sbi->symlink[n];
271 inode->i_private = sl;
272 inode->i_mode = S_IFLNK | S_IRWXUGO;
273 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec = sl->mtime;
274 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = 0;
275 inode->i_size = sl->len;
276 inode->i_nlink = 1;