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>
14 #include <linux/malloc.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 autofs_put_super(struct super_block
*sb
)
24 struct autofs_sb_info
*sbi
= autofs_sbi(sb
);
27 if ( !sbi
->catatonic
)
28 autofs_catatonic_mode(sbi
); /* Free wait queues, close pipe */
30 autofs_hash_nuke(&sbi
->dirhash
);
31 for ( n
= 0 ; n
< AUTOFS_MAX_SYMLINKS
; n
++ ) {
32 if ( test_bit(n
, sbi
->symlink_bitmap
) )
33 kfree(sbi
->symlink
[n
].data
);
36 kfree(sb
->u
.generic_sbp
);
38 DPRINTK(("autofs: shutting down\n"));
41 static int autofs_statfs(struct super_block
*sb
, struct statfs
*buf
);
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
: autofs_statfs
,
50 static int parse_options(char *options
, int *pipefd
, uid_t
*uid
, gid_t
*gid
, pid_t
*pgrp
, int *minproto
, int *maxproto
)
52 char *this_char
, *value
;
56 *pgrp
= current
->pgrp
;
58 *minproto
= *maxproto
= AUTOFS_PROTO_VERSION
;
62 if ( !options
) return 1;
63 for (this_char
= strtok(options
,","); this_char
; this_char
= strtok(NULL
,",")) {
64 if ((value
= strchr(this_char
,'=')) != NULL
)
66 if (!strcmp(this_char
,"fd")) {
67 if (!value
|| !*value
)
69 *pipefd
= simple_strtoul(value
,&value
,0);
73 else if (!strcmp(this_char
,"uid")) {
74 if (!value
|| !*value
)
76 *uid
= simple_strtoul(value
,&value
,0);
80 else if (!strcmp(this_char
,"gid")) {
81 if (!value
|| !*value
)
83 *gid
= simple_strtoul(value
,&value
,0);
87 else if (!strcmp(this_char
,"pgrp")) {
88 if (!value
|| !*value
)
90 *pgrp
= simple_strtoul(value
,&value
,0);
94 else if (!strcmp(this_char
,"minproto")) {
95 if (!value
|| !*value
)
97 *minproto
= simple_strtoul(value
,&value
,0);
101 else if (!strcmp(this_char
,"maxproto")) {
102 if (!value
|| !*value
)
104 *maxproto
= simple_strtoul(value
,&value
,0);
110 return (*pipefd
< 0);
113 struct super_block
*autofs_read_super(struct super_block
*s
, void *data
,
116 struct inode
* root_inode
;
117 struct dentry
* root
;
120 struct autofs_sb_info
*sbi
;
121 int minproto
, maxproto
;
123 sbi
= (struct autofs_sb_info
*) kmalloc(sizeof(struct autofs_sb_info
), GFP_KERNEL
);
126 DPRINTK(("autofs: starting up, sbi = %p\n",sbi
));
128 s
->u
.generic_sbp
= sbi
;
129 sbi
->magic
= AUTOFS_SBI_MAGIC
;
131 sbi
->exp_timeout
= 0;
132 sbi
->oz_pgrp
= current
->pgrp
;
133 autofs_initialize_hash(&sbi
->dirhash
);
135 memset(sbi
->symlink_bitmap
, 0, sizeof(u32
)*AUTOFS_SYMLINK_BITMAP_LEN
);
136 sbi
->next_dir_ino
= AUTOFS_FIRST_DIR_INO
;
137 s
->s_blocksize
= 1024;
138 s
->s_blocksize_bits
= 10;
139 s
->s_magic
= AUTOFS_SUPER_MAGIC
;
140 s
->s_op
= &autofs_sops
;
142 root_inode
= iget(s
, AUTOFS_ROOT_INO
);
143 root
= d_alloc_root(root_inode
);
149 /* Can this call block? - WTF cares? s is locked. */
150 if ( parse_options(data
,&pipefd
,&root_inode
->i_uid
,&root_inode
->i_gid
,&sbi
->oz_pgrp
,&minproto
,&maxproto
) ) {
151 printk("autofs: called with bogus options\n");
155 /* Couldn't this be tested earlier? */
156 if ( minproto
> AUTOFS_PROTO_VERSION
||
157 maxproto
< AUTOFS_PROTO_VERSION
) {
158 printk("autofs: kernel does not match daemon version\n");
162 DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd
, sbi
->oz_pgrp
));
166 printk("autofs: could not open pipe file descriptor\n");
169 if ( !pipe
->f_op
|| !pipe
->f_op
->write
)
174 * Success! Install the root dentry now to indicate completion.
180 printk("autofs: pipe file descriptor does not contain proper ops\n");
186 printk("autofs: get root dentry failed\n");
194 static int autofs_statfs(struct super_block
*sb
, struct statfs
*buf
)
196 buf
->f_type
= AUTOFS_SUPER_MAGIC
;
198 buf
->f_namelen
= NAME_MAX
;
202 static void autofs_read_inode(struct inode
*inode
)
204 ino_t ino
= inode
->i_ino
;
206 struct autofs_sb_info
*sbi
= autofs_sbi(inode
->i_sb
);
208 /* Initialize to the default case (stub directory) */
210 inode
->i_op
= &autofs_dir_inode_operations
;
211 inode
->i_fop
= &autofs_dir_operations
;
212 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
215 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
217 inode
->i_blksize
= 1024;
219 if ( ino
== AUTOFS_ROOT_INO
) {
220 inode
->i_mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
| S_IWUSR
;
221 inode
->i_op
= &autofs_root_inode_operations
;
222 inode
->i_fop
= &autofs_root_operations
;
223 inode
->i_uid
= inode
->i_gid
= 0; /* Changed in read_super */
227 inode
->i_uid
= inode
->i_sb
->s_root
->d_inode
->i_uid
;
228 inode
->i_gid
= inode
->i_sb
->s_root
->d_inode
->i_gid
;
230 if ( ino
>= AUTOFS_FIRST_SYMLINK
&& ino
< AUTOFS_FIRST_DIR_INO
) {
231 /* Symlink inode - should be in symlink list */
232 struct autofs_symlink
*sl
;
234 n
= ino
- AUTOFS_FIRST_SYMLINK
;
235 if ( n
>= AUTOFS_MAX_SYMLINKS
|| !test_bit(n
,sbi
->symlink_bitmap
)) {
236 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino
);
240 inode
->i_op
= &autofs_symlink_inode_operations
;
241 sl
= &sbi
->symlink
[n
];
242 inode
->u
.generic_ip
= sl
;
243 inode
->i_mode
= S_IFLNK
| S_IRWXUGO
;
244 inode
->i_mtime
= inode
->i_ctime
= sl
->mtime
;
245 inode
->i_size
= sl
->len
;