OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [autofs/] [inode.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/* -*- linux-c -*- --------------------------------------------------------- *
2
 *
3
 * linux/fs/autofs/inode.c
4
 *
5
 *  Copyright 1997 Transmeta Corporation -- All Rights Reserved
6
 *
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.
10
 *
11
 * ------------------------------------------------------------------------- */
12
 
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>
18
#include "autofs_i.h"
19
#define __NO_VERSION__
20
#include <linux/module.h>
21
 
22
static void autofs_put_inode(struct inode *inode)
23
{
24
        if (inode->i_nlink)
25
                return;
26
        inode->i_size = 0;
27
}
28
 
29
static void autofs_put_super(struct super_block *sb)
30
{
31
        struct autofs_sb_info *sbi =
32
                (struct autofs_sb_info *) sb->u.generic_sbp;
33
        unsigned int n;
34
 
35
        if ( !sbi->catatonic )
36
                autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
37
 
38
        lock_super(sb);
39
        autofs_hash_nuke(&sbi->dirhash);
40
        for ( n = 0 ; n < AUTOFS_MAX_SYMLINKS ; n++ ) {
41
                if ( test_bit(n, sbi->symlink_bitmap) )
42
                        kfree(sbi->symlink[n].data);
43
        }
44
 
45
        sb->s_dev = 0;
46
        kfree(sb->u.generic_sbp);
47
        unlock_super(sb);
48
 
49
        DPRINTK(("autofs: shutting down\n"));
50
 
51
#ifdef MODULE
52
        MOD_DEC_USE_COUNT;
53
#endif
54
}
55
 
56
static void autofs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz);
57
static void autofs_read_inode(struct inode *inode);
58
static void autofs_write_inode(struct inode *inode);
59
 
60
static struct super_operations autofs_sops = {
61
        autofs_read_inode,
62
        NULL,
63
        autofs_write_inode,
64
        autofs_put_inode,
65
        autofs_put_super,
66
        NULL,
67
        autofs_statfs,
68
        NULL
69
};
70
 
71
static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, pid_t *pgrp, int *minproto, int *maxproto)
72
{
73
        char *this_char, *value;
74
 
75
        *uid = current->uid;
76
        *gid = current->gid;
77
        *pgrp = current->pgrp;
78
 
79
        *minproto = *maxproto = AUTOFS_PROTO_VERSION;
80
 
81
        *pipefd = -1;
82
 
83
        if ( !options ) return 1;
84
        for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
85
                if ((value = strchr(this_char,'=')) != NULL)
86
                        *value++ = 0;
87
                if (!strcmp(this_char,"fd")) {
88
                        if (!value || !*value)
89
                                return 1;
90
                        *pipefd = simple_strtoul(value,&value,0);
91
                        if (*value)
92
                                return 1;
93
                }
94
                else if (!strcmp(this_char,"uid")) {
95
                        if (!value || !*value)
96
                                return 1;
97
                        *uid = simple_strtoul(value,&value,0);
98
                        if (*value)
99
                                return 1;
100
                }
101
                else if (!strcmp(this_char,"gid")) {
102
                        if (!value || !*value)
103
                                return 1;
104
                        *gid = simple_strtoul(value,&value,0);
105
                        if (*value)
106
                                return 1;
107
                }
108
                else if (!strcmp(this_char,"pgrp")) {
109
                        if (!value || !*value)
110
                                return 1;
111
                        *pgrp = simple_strtoul(value,&value,0);
112
                        if (*value)
113
                                return 1;
114
                }
115
                else if (!strcmp(this_char,"minproto")) {
116
                        if (!value || !*value)
117
                                return 1;
118
                        *minproto = simple_strtoul(value,&value,0);
119
                        if (*value)
120
                                return 1;
121
                }
122
                else if (!strcmp(this_char,"maxproto")) {
123
                        if (!value || !*value)
124
                                return 1;
125
                        *maxproto = simple_strtoul(value,&value,0);
126
                        if (*value)
127
                                return 1;
128
                }
129
                else break;
130
        }
131
        return (*pipefd < 0);
132
}
133
 
134
struct super_block *autofs_read_super(struct super_block *s, void *data,
135
                                      int silent)
136
{
137
        int pipefd;
138
        struct autofs_sb_info *sbi;
139
        int minproto, maxproto;
140
 
141
        MOD_INC_USE_COUNT;
142
 
143
        lock_super(s);
144
        sbi = (struct autofs_sb_info *) kmalloc(sizeof(struct autofs_sb_info), GFP_KERNEL);
145
        if ( !sbi ) {
146
                s->s_dev = 0;
147
                MOD_DEC_USE_COUNT;
148
                return NULL;
149
        }
150
        DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
151
 
152
        s->u.generic_sbp = sbi;
153
        sbi->magic = AUTOFS_SBI_MAGIC;
154
        sbi->catatonic = 0;
155
        sbi->exp_timeout = 0;
156
        sbi->oz_pgrp = current->pgrp;
157
        autofs_initialize_hash(&sbi->dirhash);
158
        sbi->queues = NULL;
159
        memset(sbi->symlink_bitmap, 0, sizeof(u32)*AUTOFS_SYMLINK_BITMAP_LEN);
160
        sbi->next_dir_ino = AUTOFS_FIRST_DIR_INO;
161
        s->s_blocksize = 1024;
162
        s->s_blocksize_bits = 10;
163
        s->s_magic = AUTOFS_SUPER_MAGIC;
164
        s->s_op = &autofs_sops;
165
        unlock_super(s);
166
        if (!(s->s_mounted = iget(s, AUTOFS_ROOT_INO))) {
167
                s->s_dev = 0;
168
                kfree(sbi);
169
                printk("autofs: get root inode failed\n");
170
                MOD_DEC_USE_COUNT;
171
                return NULL;
172
        }
173
 
174
        if ( parse_options(data,&pipefd,&s->s_mounted->i_uid,&s->s_mounted->i_gid,&sbi->oz_pgrp,&minproto,&maxproto) ) {
175
                iput(s->s_mounted);
176
                s->s_dev = 0;
177
                kfree(sbi);
178
                printk("autofs: called with bogus options\n");
179
                MOD_DEC_USE_COUNT;
180
                return NULL;
181
        }
182
 
183
        if ( minproto > AUTOFS_PROTO_VERSION || maxproto < AUTOFS_PROTO_VERSION ) {
184
                iput(s->s_mounted);
185
                s->s_dev = 0;
186
                kfree(sbi);
187
                printk("autofs: kernel does not match daemon version\n");
188
                MOD_DEC_USE_COUNT;
189
                return NULL;
190
        }
191
 
192
        DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
193
        sbi->pipe = fget(pipefd);
194
        if ( !sbi->pipe || !sbi->pipe->f_op || !sbi->pipe->f_op->write ) {
195
                if ( sbi->pipe ) {
196
                        fput(sbi->pipe, sbi->pipe->f_inode);
197
                        printk("autofs: pipe file descriptor does not contain proper ops\n");
198
                } else {
199
                        printk("autofs: could not open pipe file descriptor\n");
200
                }
201
                iput(s->s_mounted);
202
                s->s_dev = 0;
203
                kfree(sbi);
204
                MOD_DEC_USE_COUNT;
205
                return NULL;
206
        }
207
        return s;
208
}
209
 
210
static void autofs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
211
{
212
        struct statfs tmp;
213
 
214
        tmp.f_type = AUTOFS_SUPER_MAGIC;
215
        tmp.f_bsize = 1024;
216
        tmp.f_blocks = 0;
217
        tmp.f_bfree = 0;
218
        tmp.f_bavail = 0;
219
        tmp.f_files = 0;
220
        tmp.f_ffree = 0;
221
        tmp.f_namelen = NAME_MAX;
222
        copy_to_user(buf, &tmp, bufsiz);
223
}
224
 
225
static void autofs_read_inode(struct inode *inode)
226
{
227
        ino_t ino = inode->i_ino;
228
        unsigned int n;
229
        struct autofs_sb_info *sbi =
230
                (struct autofs_sb_info *) inode->i_sb->u.generic_sbp;
231
 
232
        inode->i_op = NULL;
233
        inode->i_mode = 0;
234
        inode->i_nlink = 2;
235
        inode->i_size = 0;
236
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
237
        inode->i_blocks = 0;
238
        inode->i_blksize = 1024;
239
 
240
        if ( ino == AUTOFS_ROOT_INO ) {
241
                inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
242
                inode->i_op = &autofs_root_inode_operations;
243
                inode->i_uid = inode->i_gid = 0; /* Changed in read_super */
244
                return;
245
        }
246
 
247
        inode->i_uid = inode->i_sb->s_mounted->i_uid;
248
        inode->i_gid = inode->i_sb->s_mounted->i_gid;
249
 
250
        if ( ino >= AUTOFS_FIRST_SYMLINK && ino < AUTOFS_FIRST_DIR_INO ) {
251
                /* Symlink inode - should be in symlink list */
252
                struct autofs_symlink *sl;
253
 
254
                n = ino - AUTOFS_FIRST_SYMLINK;
255
                if ( n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap)) {
256
                        printk("autofs: Looking for bad symlink inode 0x%08x\n", (unsigned int) ino);
257
                        return;
258
                }
259
 
260
                inode->i_op = &autofs_symlink_inode_operations;
261
                sl = &sbi->symlink[n];
262
                inode->u.generic_ip = sl;
263
                inode->i_mode = S_IFLNK | S_IRWXUGO;
264
                inode->i_mtime = inode->i_ctime = sl->mtime;
265
                inode->i_size = sl->len;
266
                inode->i_nlink = 1;
267
        } else {
268
                /* All non-root directory inodes look the same */
269
                inode->i_op = &autofs_dir_inode_operations;
270
                inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
271
        }
272
}
273
 
274
static void autofs_write_inode(struct inode *inode)
275
{
276
        inode->i_dirt = 0;
277
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.