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>
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>
21 #include <linux/module.h>
23 void autofs_kill_sb(struct super_block
*sb
)
25 struct autofs_sb_info
*sbi
= autofs_sbi(sb
);
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
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
);
51 DPRINTK(("autofs: shutting down\n"));
55 static const struct super_operations autofs_sops
= {
56 .statfs
= simple_statfs
,
59 enum {Opt_err
, Opt_fd
, Opt_uid
, Opt_gid
, Opt_pgrp
, Opt_minproto
, Opt_maxproto
};
61 static match_table_t autofs_tokens
= {
65 {Opt_pgrp
, "pgrp=%u"},
66 {Opt_minproto
, "minproto=%u"},
67 {Opt_maxproto
, "maxproto=%u"},
71 static int parse_options(char *options
, int *pipefd
, uid_t
*uid
, gid_t
*gid
,
72 pid_t
*pgrp
, int *minproto
, int *maxproto
)
75 substring_t args
[MAX_OPT_ARGS
];
80 *pgrp
= task_pgrp_nr(current
);
82 *minproto
= *maxproto
= AUTOFS_PROTO_VERSION
;
89 while ((p
= strsep(&options
, ",")) != NULL
) {
94 token
= match_token(p
, autofs_tokens
, args
);
97 if (match_int(&args
[0], &option
))
102 if (match_int(&args
[0], &option
))
107 if (match_int(&args
[0], &option
))
112 if (match_int(&args
[0], &option
))
117 if (match_int(&args
[0], &option
))
122 if (match_int(&args
[0], &option
))
130 return (*pipefd
< 0);
133 int autofs_fill_super(struct super_block
*s
, void *data
, int silent
)
135 struct inode
* root_inode
;
136 struct dentry
* root
;
139 struct autofs_sb_info
*sbi
;
140 int minproto
, maxproto
;
143 sbi
= kzalloc(sizeof(*sbi
), GFP_KERNEL
);
146 DPRINTK(("autofs: starting up, sbi = %p\n",sbi
));
149 sbi
->magic
= AUTOFS_SBI_MAGIC
;
152 sbi
->exp_timeout
= 0;
153 autofs_initialize_hash(&sbi
->dirhash
);
155 memset(sbi
->symlink_bitmap
, 0, sizeof(long)*AUTOFS_SYMLINK_BITMAP_LEN
);
156 sbi
->next_dir_ino
= AUTOFS_FIRST_DIR_INO
;
157 s
->s_blocksize
= 1024;
158 s
->s_blocksize_bits
= 10;
159 s
->s_magic
= AUTOFS_SUPER_MAGIC
;
160 s
->s_op
= &autofs_sops
;
164 root_inode
= autofs_iget(s
, AUTOFS_ROOT_INO
);
165 if (IS_ERR(root_inode
))
167 root
= d_alloc_root(root_inode
);
173 /* Can this call block? - WTF cares? s is locked. */
174 if (parse_options(data
, &pipefd
, &root_inode
->i_uid
,
175 &root_inode
->i_gid
, &pgid
, &minproto
,
177 printk("autofs: called with bogus options\n");
181 /* Couldn't this be tested earlier? */
182 if (minproto
> AUTOFS_PROTO_VERSION
||
183 maxproto
< AUTOFS_PROTO_VERSION
) {
184 printk("autofs: kernel does not match daemon version\n");
188 DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd
, pgid
));
189 sbi
->oz_pgrp
= find_get_pid(pgid
);
192 printk("autofs: could not find process group %d\n", pgid
);
199 printk("autofs: could not open pipe file descriptor\n");
203 if (!pipe
->f_op
|| !pipe
->f_op
->write
)
209 * Success! Install the root dentry now to indicate completion.
215 printk("autofs: pipe file descriptor does not contain proper ops\n");
218 put_pid(sbi
->oz_pgrp
);
223 printk("autofs: get root dentry failed\n");
232 struct inode
*autofs_iget(struct super_block
*sb
, unsigned long ino
)
235 struct autofs_sb_info
*sbi
= autofs_sbi(sb
);
238 inode
= iget_locked(sb
, ino
);
240 return ERR_PTR(-ENOMEM
);
241 if (!(inode
->i_state
& I_NEW
))
244 /* Initialize to the default case (stub directory) */
246 inode
->i_op
= &simple_dir_inode_operations
;
247 inode
->i_fop
= &simple_dir_operations
;
248 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
250 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
253 if (ino
== AUTOFS_ROOT_INO
) {
254 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
| S_IWUSR
;
255 inode
->i_op
= &autofs_root_inode_operations
;
256 inode
->i_fop
= &autofs_root_operations
;
257 inode
->i_uid
= inode
->i_gid
= 0; /* Changed in read_super */
261 inode
->i_uid
= inode
->i_sb
->s_root
->d_inode
->i_uid
;
262 inode
->i_gid
= inode
->i_sb
->s_root
->d_inode
->i_gid
;
264 if (ino
>= AUTOFS_FIRST_SYMLINK
&& ino
< AUTOFS_FIRST_DIR_INO
) {
265 /* Symlink inode - should be in symlink list */
266 struct autofs_symlink
*sl
;
268 n
= ino
- AUTOFS_FIRST_SYMLINK
;
269 if (n
>= AUTOFS_MAX_SYMLINKS
|| !test_bit(n
,sbi
->symlink_bitmap
)) {
270 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino
);
274 inode
->i_op
= &autofs_symlink_inode_operations
;
275 sl
= &sbi
->symlink
[n
];
276 inode
->i_private
= sl
;
277 inode
->i_mode
= S_IFLNK
| S_IRWXUGO
;
278 inode
->i_mtime
.tv_sec
= inode
->i_ctime
.tv_sec
= sl
->mtime
;
279 inode
->i_mtime
.tv_nsec
= inode
->i_ctime
.tv_nsec
= 0;
280 inode
->i_size
= sl
->len
;
285 unlock_new_inode(inode
);