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/locks.h>
17 #include <asm/bitops.h>
19 #define __NO_VERSION__
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);
83 sb->u.generic_sbp = NULL;
85 if ( !sbi->catatonic )
86 autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
90 DPRINTK(("autofs: shutting down\n"));
93 static int autofs4_statfs(struct super_block *sb, struct statfs *buf);
95 static struct super_operations autofs4_sops = {
96 put_super: autofs4_put_super,
97 statfs: autofs4_statfs,
100 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
101 pid_t *pgrp, int *minproto, int *maxproto)
103 char *this_char, *value;
107 *pgrp = current->pgrp;
109 *minproto = AUTOFS_MIN_PROTO_VERSION;
110 *maxproto = AUTOFS_MAX_PROTO_VERSION;
114 if ( !options ) return 1;
115 for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
116 if ((value = strchr(this_char,'=')) != NULL)
118 if (!strcmp(this_char,"fd")) {
119 if (!value || !*value)
121 *pipefd = simple_strtoul(value,&value,0);
125 else if (!strcmp(this_char,"uid")) {
126 if (!value || !*value)
128 *uid = simple_strtoul(value,&value,0);
132 else if (!strcmp(this_char,"gid")) {
133 if (!value || !*value)
135 *gid = simple_strtoul(value,&value,0);
139 else if (!strcmp(this_char,"pgrp")) {
140 if (!value || !*value)
142 *pgrp = simple_strtoul(value,&value,0);
146 else if (!strcmp(this_char,"minproto")) {
147 if (!value || !*value)
149 *minproto = simple_strtoul(value,&value,0);
153 else if (!strcmp(this_char,"maxproto")) {
154 if (!value || !*value)
156 *maxproto = simple_strtoul(value,&value,0);
162 return (*pipefd < 0);
165 static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
167 struct autofs_info *ino;
169 ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
176 struct super_block *autofs4_read_super(struct super_block *s, void *data,
179 struct inode * root_inode;
180 struct dentry * root;
183 struct autofs_sb_info *sbi;
184 int minproto, maxproto;
186 sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
189 DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
191 memset(sbi, 0, sizeof(*sbi));
193 s->u.generic_sbp = sbi;
194 sbi->magic = AUTOFS_SBI_MAGIC;
196 sbi->exp_timeout = 0;
197 sbi->oz_pgrp = current->pgrp;
201 s->s_blocksize = 1024;
202 s->s_blocksize_bits = 10;
203 s->s_magic = AUTOFS_SUPER_MAGIC;
204 s->s_op = &autofs4_sops;
207 * Get the root inode and dentry, but defer checking for errors.
209 root_inode = autofs4_get_inode(s, autofs4_mkroot(sbi));
210 root_inode->i_op = &autofs4_root_inode_operations;
211 root_inode->i_fop = &autofs4_root_operations;
212 root = d_alloc_root(root_inode);
218 /* Can this call block? */
219 if (parse_options(data, &pipefd,
220 &root_inode->i_uid, &root_inode->i_gid,
222 &minproto, &maxproto)) {
223 printk("autofs: called with bogus options\n");
227 /* Couldn't this be tested earlier? */
228 if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
229 minproto > AUTOFS_MAX_PROTO_VERSION) {
230 printk("autofs: kernel does not match daemon version "
231 "daemon (%d, %d) kernel (%d, %d)\n",
233 AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
237 sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
239 DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
243 printk("autofs: could not open pipe file descriptor\n");
246 if ( !pipe->f_op || !pipe->f_op->write )
251 * Success! Install the root dentry now to indicate completion.
257 * Failure ... clean up.
260 printk("autofs: pipe file descriptor does not contain proper ops\n");
262 * fput() can block, so we clear the super block first.
268 * dput() can block, so we clear the super block first.
273 printk("autofs: get root dentry failed\n");
275 * iput() can block, so we clear the super block first.
284 static int autofs4_statfs(struct super_block *sb, struct statfs *buf)
286 buf->f_type = AUTOFS_SUPER_MAGIC;
288 buf->f_namelen = NAME_MAX;
292 struct inode *autofs4_get_inode(struct super_block *sb,
293 struct autofs_info *inf)
295 struct inode *inode = new_inode(sb);
301 inode->i_mode = inf->mode;
303 inode->i_uid = sb->s_root->d_inode->i_uid;
304 inode->i_gid = sb->s_root->d_inode->i_gid;
309 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 = &dcache_dir_ops;
318 } else if (S_ISLNK(inf->mode)) {
319 inode->i_size = inf->size;
320 inode->i_op = &autofs4_symlink_inode_operations;