1 /* -*- 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/slab.h>
15 #include <linux/file.h>
16 #include <linux/pagemap.h>
17 #include <linux/parser.h>
18 #include <linux/bitops.h>
20 #include <linux/module.h>
22 static void ino_lnkfree(struct autofs_info *ino)
25 kfree(ino->u.symlink);
26 ino->u.symlink = NULL;
30 struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
31 struct autofs_sb_info *sbi, mode_t mode)
37 ino = kmalloc(sizeof(*ino), GFP_KERNEL);
49 ino->last_used = jiffies;
53 if (reinit && ino->free)
56 memset(&ino->u, 0, sizeof(ino->u));
61 ino->free = ino_lnkfree;
66 void autofs4_free_ino(struct autofs_info *ino)
69 ino->dentry->d_fsdata = NULL;
70 if (ino->dentry->d_inode)
79 static void autofs4_put_super(struct super_block *sb)
81 struct autofs_sb_info *sbi = autofs4_sbi(sb);
85 if ( !sbi->catatonic )
86 autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
90 DPRINTK("shutting down");
93 static struct super_operations autofs4_sops = {
94 .put_super = autofs4_put_super,
95 .statfs = simple_statfs,
98 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
100 static match_table_t tokens = {
104 {Opt_pgrp, "pgrp=%u"},
105 {Opt_minproto, "minproto=%u"},
106 {Opt_maxproto, "maxproto=%u"},
110 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
111 pid_t *pgrp, int *minproto, int *maxproto)
114 substring_t args[MAX_OPT_ARGS];
119 *pgrp = process_group(current);
121 *minproto = AUTOFS_MIN_PROTO_VERSION;
122 *maxproto = AUTOFS_MAX_PROTO_VERSION;
129 while ((p = strsep(&options, ",")) != NULL) {
134 token = match_token(p, tokens, args);
137 if (match_int(args, pipefd))
141 if (match_int(args, &option))
146 if (match_int(args, &option))
151 if (match_int(args, &option))
156 if (match_int(args, &option))
161 if (match_int(args, &option))
169 return (*pipefd < 0);
172 static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
174 struct autofs_info *ino;
176 ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
183 int autofs4_fill_super(struct super_block *s, void *data, int silent)
185 struct inode * root_inode;
186 struct dentry * root;
189 struct autofs_sb_info *sbi;
190 struct autofs_info *ino;
191 int minproto, maxproto;
193 sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
196 DPRINTK("starting up, sbi = %p",sbi);
198 memset(sbi, 0, sizeof(*sbi));
201 sbi->magic = AUTOFS_SBI_MAGIC;
203 sbi->exp_timeout = 0;
204 sbi->oz_pgrp = process_group(current);
207 sbi->sub_version = 0;
208 init_MUTEX(&sbi->wq_sem);
210 s->s_blocksize = 1024;
211 s->s_blocksize_bits = 10;
212 s->s_magic = AUTOFS_SUPER_MAGIC;
213 s->s_op = &autofs4_sops;
217 * Get the root inode and dentry, but defer checking for errors.
219 ino = autofs4_mkroot(sbi);
222 root_inode = autofs4_get_inode(s, ino);
227 root_inode->i_op = &autofs4_root_inode_operations;
228 root_inode->i_fop = &autofs4_root_operations;
229 root = d_alloc_root(root_inode);
235 /* Can this call block? */
236 if (parse_options(data, &pipefd,
237 &root_inode->i_uid, &root_inode->i_gid,
239 &minproto, &maxproto)) {
240 printk("autofs: called with bogus options\n");
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",
250 AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
254 sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
255 sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
257 DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
261 printk("autofs: could not open pipe file descriptor\n");
264 if ( !pipe->f_op || !pipe->f_op->write )
269 * Success! Install the root dentry now to indicate completion.
275 * Failure ... clean up.
278 printk("autofs: pipe file descriptor does not contain proper ops\n");
285 printk("autofs: get root dentry failed\n");
293 struct inode *autofs4_get_inode(struct super_block *sb,
294 struct autofs_info *inf)
296 struct inode *inode = new_inode(sb);
302 inode->i_mode = inf->mode;
304 inode->i_uid = sb->s_root->d_inode->i_uid;
305 inode->i_gid = sb->s_root->d_inode->i_gid;
310 inode->i_blksize = PAGE_CACHE_SIZE;
312 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
314 if (S_ISDIR(inf->mode)) {
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;