aboutsummaryrefslogtreecommitdiffstats
path: root/fs/autofs4/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/autofs4/inode.c')
-rw-r--r--fs/autofs4/inode.c324
1 files changed, 324 insertions, 0 deletions
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
new file mode 100644
index 000000000000..a52560746628
--- /dev/null
+++ b/fs/autofs4/inode.c
@@ -0,0 +1,324 @@
1/* -*- c -*- --------------------------------------------------------------- *
2 *
3 * linux/fs/autofs/inode.c
4 *
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 *
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.
10 *
11 * ------------------------------------------------------------------------- */
12
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/file.h>
16#include <linux/pagemap.h>
17#include <linux/parser.h>
18#include <linux/bitops.h>
19#include "autofs_i.h"
20#include <linux/module.h>
21
22static void ino_lnkfree(struct autofs_info *ino)
23{
24 if (ino->u.symlink) {
25 kfree(ino->u.symlink);
26 ino->u.symlink = NULL;
27 }
28}
29
30struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
31 struct autofs_sb_info *sbi, mode_t mode)
32{
33 int reinit = 1;
34
35 if (ino == NULL) {
36 reinit = 0;
37 ino = kmalloc(sizeof(*ino), GFP_KERNEL);
38 }
39
40 if (ino == NULL)
41 return NULL;
42
43 ino->flags = 0;
44 ino->mode = mode;
45 ino->inode = NULL;
46 ino->dentry = NULL;
47 ino->size = 0;
48
49 ino->last_used = jiffies;
50
51 ino->sbi = sbi;
52
53 if (reinit && ino->free)
54 (ino->free)(ino);
55
56 memset(&ino->u, 0, sizeof(ino->u));
57
58 ino->free = NULL;
59
60 if (S_ISLNK(mode))
61 ino->free = ino_lnkfree;
62
63 return ino;
64}
65
66void autofs4_free_ino(struct autofs_info *ino)
67{
68 if (ino->dentry) {
69 ino->dentry->d_fsdata = NULL;
70 if (ino->dentry->d_inode)
71 dput(ino->dentry);
72 ino->dentry = NULL;
73 }
74 if (ino->free)
75 (ino->free)(ino);
76 kfree(ino);
77}
78
79static void autofs4_put_super(struct super_block *sb)
80{
81 struct autofs_sb_info *sbi = autofs4_sbi(sb);
82
83 sb->s_fs_info = NULL;
84
85 if ( !sbi->catatonic )
86 autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
87
88 kfree(sbi);
89
90 DPRINTK("shutting down");
91}
92
93static struct super_operations autofs4_sops = {
94 .put_super = autofs4_put_super,
95 .statfs = simple_statfs,
96};
97
98enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
99
100static match_table_t tokens = {
101 {Opt_fd, "fd=%u"},
102 {Opt_uid, "uid=%u"},
103 {Opt_gid, "gid=%u"},
104 {Opt_pgrp, "pgrp=%u"},
105 {Opt_minproto, "minproto=%u"},
106 {Opt_maxproto, "maxproto=%u"},
107 {Opt_err, NULL}
108};
109
110static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
111 pid_t *pgrp, int *minproto, int *maxproto)
112{
113 char *p;
114 substring_t args[MAX_OPT_ARGS];
115 int option;
116
117 *uid = current->uid;
118 *gid = current->gid;
119 *pgrp = process_group(current);
120
121 *minproto = AUTOFS_MIN_PROTO_VERSION;
122 *maxproto = AUTOFS_MAX_PROTO_VERSION;
123
124 *pipefd = -1;
125
126 if (!options)
127 return 1;
128
129 while ((p = strsep(&options, ",")) != NULL) {
130 int token;
131 if (!*p)
132 continue;
133
134 token = match_token(p, tokens, args);
135 switch (token) {
136 case Opt_fd:
137 if (match_int(args, pipefd))
138 return 1;
139 break;
140 case Opt_uid:
141 if (match_int(args, &option))
142 return 1;
143 *uid = option;
144 break;
145 case Opt_gid:
146 if (match_int(args, &option))
147 return 1;
148 *gid = option;
149 break;
150 case Opt_pgrp:
151 if (match_int(args, &option))
152 return 1;
153 *pgrp = option;
154 break;
155 case Opt_minproto:
156 if (match_int(args, &option))
157 return 1;
158 *minproto = option;
159 break;
160 case Opt_maxproto:
161 if (match_int(args, &option))
162 return 1;
163 *maxproto = option;
164 break;
165 default:
166 return 1;
167 }
168 }
169 return (*pipefd < 0);
170}
171
172static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
173{
174 struct autofs_info *ino;
175
176 ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
177 if (!ino)
178 return NULL;
179
180 return ino;
181}
182
183int autofs4_fill_super(struct super_block *s, void *data, int silent)
184{
185 struct inode * root_inode;
186 struct dentry * root;
187 struct file * pipe;
188 int pipefd;
189 struct autofs_sb_info *sbi;
190 struct autofs_info *ino;
191 int minproto, maxproto;
192
193 sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
194 if ( !sbi )
195 goto fail_unlock;
196 DPRINTK("starting up, sbi = %p",sbi);
197
198 memset(sbi, 0, sizeof(*sbi));
199
200 s->s_fs_info = sbi;
201 sbi->magic = AUTOFS_SBI_MAGIC;
202 sbi->catatonic = 0;
203 sbi->exp_timeout = 0;
204 sbi->oz_pgrp = process_group(current);
205 sbi->sb = s;
206 sbi->version = 0;
207 sbi->sub_version = 0;
208 init_MUTEX(&sbi->wq_sem);
209 sbi->queues = NULL;
210 s->s_blocksize = 1024;
211 s->s_blocksize_bits = 10;
212 s->s_magic = AUTOFS_SUPER_MAGIC;
213 s->s_op = &autofs4_sops;
214 s->s_time_gran = 1;
215
216 /*
217 * Get the root inode and dentry, but defer checking for errors.
218 */
219 ino = autofs4_mkroot(sbi);
220 if (!ino)
221 goto fail_free;
222 root_inode = autofs4_get_inode(s, ino);
223 kfree(ino);
224 if (!root_inode)
225 goto fail_free;
226
227 root_inode->i_op = &autofs4_root_inode_operations;
228 root_inode->i_fop = &autofs4_root_operations;
229 root = d_alloc_root(root_inode);
230 pipe = NULL;
231
232 if (!root)
233 goto fail_iput;
234
235 /* Can this call block? */
236 if (parse_options(data, &pipefd,
237 &root_inode->i_uid, &root_inode->i_gid,
238 &sbi->oz_pgrp,
239 &minproto, &maxproto)) {
240 printk("autofs: called with bogus options\n");
241 goto fail_dput;
242 }
243
244 /* Couldn't this be tested earlier? */
245 if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
246 minproto > AUTOFS_MAX_PROTO_VERSION) {
247 printk("autofs: kernel does not match daemon version "
248 "daemon (%d, %d) kernel (%d, %d)\n",
249 minproto, maxproto,
250 AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
251 goto fail_dput;
252 }
253
254 sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
255 sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
256
257 DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
258 pipe = fget(pipefd);
259
260 if ( !pipe ) {
261 printk("autofs: could not open pipe file descriptor\n");
262 goto fail_dput;
263 }
264 if ( !pipe->f_op || !pipe->f_op->write )
265 goto fail_fput;
266 sbi->pipe = pipe;
267
268 /*
269 * Success! Install the root dentry now to indicate completion.
270 */
271 s->s_root = root;
272 return 0;
273
274 /*
275 * Failure ... clean up.
276 */
277fail_fput:
278 printk("autofs: pipe file descriptor does not contain proper ops\n");
279 fput(pipe);
280 /* fall through */
281fail_dput:
282 dput(root);
283 goto fail_free;
284fail_iput:
285 printk("autofs: get root dentry failed\n");
286 iput(root_inode);
287fail_free:
288 kfree(sbi);
289fail_unlock:
290 return -EINVAL;
291}
292
293struct inode *autofs4_get_inode(struct super_block *sb,
294 struct autofs_info *inf)
295{
296 struct inode *inode = new_inode(sb);
297
298 if (inode == NULL)
299 return NULL;
300
301 inf->inode = inode;
302 inode->i_mode = inf->mode;
303 if (sb->s_root) {
304 inode->i_uid = sb->s_root->d_inode->i_uid;
305 inode->i_gid = sb->s_root->d_inode->i_gid;
306 } else {
307 inode->i_uid = 0;
308 inode->i_gid = 0;
309 }
310 inode->i_blksize = PAGE_CACHE_SIZE;
311 inode->i_blocks = 0;
312 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
313
314 if (S_ISDIR(inf->mode)) {
315 inode->i_nlink = 2;
316 inode->i_op = &autofs4_dir_inode_operations;
317 inode->i_fop = &autofs4_dir_operations;
318 } else if (S_ISLNK(inf->mode)) {
319 inode->i_size = inf->size;
320 inode->i_op = &autofs4_symlink_inode_operations;
321 }
322
323 return inode;
324}