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 static void autofs_put_super(struct super_block
*sb
)
25 struct autofs_sb_info
*sbi
= autofs_sbi(sb
);
28 if ( !sbi
->catatonic
)
29 autofs_catatonic_mode(sbi
); /* Free wait queues, close pipe */
31 autofs_hash_nuke(sbi
);
32 for ( n
= 0 ; n
< AUTOFS_MAX_SYMLINKS
; n
++ ) {
33 if ( test_bit(n
, sbi
->symlink_bitmap
) )
34 kfree(sbi
->symlink
[n
].data
);
39 DPRINTK(("autofs: shutting down\n"));
42 static void autofs_read_inode(struct inode
*inode
);
44 static struct super_operations autofs_sops
= {
45 .read_inode
= autofs_read_inode
,
46 .put_super
= autofs_put_super
,
47 .statfs
= simple_statfs
,
50 enum {Opt_err
, Opt_fd
, Opt_uid
, Opt_gid
, Opt_pgrp
, Opt_minproto
, Opt_maxproto
};
52 static match_table_t autofs_tokens
= {
56 {Opt_pgrp
, "pgrp=%u"},
57 {Opt_minproto
, "minproto=%u"},
58 {Opt_maxproto
, "maxproto=%u"},
62 static int parse_options(char *options
, int *pipefd
, uid_t
*uid
, gid_t
*gid
, pid_t
*pgrp
, int *minproto
, int *maxproto
)
65 substring_t args
[MAX_OPT_ARGS
];
70 *pgrp
= process_group(current
);
72 *minproto
= *maxproto
= AUTOFS_PROTO_VERSION
;
79 while ((p
= strsep(&options
, ",")) != NULL
) {
84 token
= match_token(p
, autofs_tokens
, args
);
87 if (match_int(&args
[0], &option
))
92 if (match_int(&args
[0], &option
))
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
))
120 return (*pipefd
< 0);
123 int autofs_fill_super(struct super_block
*s
, void *data
, int silent
)
125 struct inode
* root_inode
;
126 struct dentry
* root
;
129 struct autofs_sb_info
*sbi
;
130 int minproto
, maxproto
;
132 sbi
= kzalloc(sizeof(*sbi
), GFP_KERNEL
);
135 DPRINTK(("autofs: starting up, sbi = %p\n",sbi
));
138 sbi
->magic
= AUTOFS_SBI_MAGIC
;
140 sbi
->exp_timeout
= 0;
141 sbi
->oz_pgrp
= process_group(current
);
142 autofs_initialize_hash(&sbi
->dirhash
);
144 memset(sbi
->symlink_bitmap
, 0, sizeof(long)*AUTOFS_SYMLINK_BITMAP_LEN
);
145 sbi
->next_dir_ino
= AUTOFS_FIRST_DIR_INO
;
146 s
->s_blocksize
= 1024;
147 s
->s_blocksize_bits
= 10;
148 s
->s_magic
= AUTOFS_SUPER_MAGIC
;
149 s
->s_op
= &autofs_sops
;
153 root_inode
= iget(s
, AUTOFS_ROOT_INO
);
154 root
= d_alloc_root(root_inode
);
160 /* Can this call block? - WTF cares? s is locked. */
161 if ( parse_options(data
,&pipefd
,&root_inode
->i_uid
,&root_inode
->i_gid
,&sbi
->oz_pgrp
,&minproto
,&maxproto
) ) {
162 printk("autofs: called with bogus options\n");
166 /* Couldn't this be tested earlier? */
167 if ( minproto
> AUTOFS_PROTO_VERSION
||
168 maxproto
< AUTOFS_PROTO_VERSION
) {
169 printk("autofs: kernel does not match daemon version\n");
173 DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd
, sbi
->oz_pgrp
));
177 printk("autofs: could not open pipe file descriptor\n");
180 if ( !pipe
->f_op
|| !pipe
->f_op
->write
)
185 * Success! Install the root dentry now to indicate completion.
191 printk("autofs: pipe file descriptor does not contain proper ops\n");
197 printk("autofs: get root dentry failed\n");
205 static void autofs_read_inode(struct inode
*inode
)
207 ino_t ino
= inode
->i_ino
;
209 struct autofs_sb_info
*sbi
= autofs_sbi(inode
->i_sb
);
211 /* Initialize to the default case (stub directory) */
213 inode
->i_op
= &simple_dir_inode_operations
;
214 inode
->i_fop
= &simple_dir_operations
;
215 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
217 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
220 if ( ino
== AUTOFS_ROOT_INO
) {
221 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
| S_IWUSR
;
222 inode
->i_op
= &autofs_root_inode_operations
;
223 inode
->i_fop
= &autofs_root_operations
;
224 inode
->i_uid
= inode
->i_gid
= 0; /* Changed in read_super */
228 inode
->i_uid
= inode
->i_sb
->s_root
->d_inode
->i_uid
;
229 inode
->i_gid
= inode
->i_sb
->s_root
->d_inode
->i_gid
;
231 if ( ino
>= AUTOFS_FIRST_SYMLINK
&& ino
< AUTOFS_FIRST_DIR_INO
) {
232 /* Symlink inode - should be in symlink list */
233 struct autofs_symlink
*sl
;
235 n
= ino
- AUTOFS_FIRST_SYMLINK
;
236 if ( n
>= AUTOFS_MAX_SYMLINKS
|| !test_bit(n
,sbi
->symlink_bitmap
)) {
237 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino
);
241 inode
->i_op
= &autofs_symlink_inode_operations
;
242 sl
= &sbi
->symlink
[n
];
243 inode
->i_private
= sl
;
244 inode
->i_mode
= S_IFLNK
| S_IRWXUGO
;
245 inode
->i_mtime
.tv_sec
= inode
->i_ctime
.tv_sec
= sl
->mtime
;
246 inode
->i_mtime
.tv_nsec
= inode
->i_ctime
.tv_nsec
= 0;
247 inode
->i_size
= sl
->len
;