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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/proc/inode.c
3
 *
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 */
6
 
7
/*
8
 * uClinux revisions for NO_MM
9
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
10
 *                     The Silver Hammer Group, Ltd.
11
 */
12
 
13
#include <linux/sched.h>
14
#include <linux/proc_fs.h>
15
#include <linux/kernel.h>
16
#include <linux/mm.h>
17
#include <linux/string.h>
18
#include <linux/stat.h>
19
#include <linux/locks.h>
20
#include <linux/limits.h>
21
 
22
#include <asm/system.h>
23
#include <asm/segment.h>
24
 
25
static void proc_put_inode(struct inode *inode)
26
{
27
        if (inode->i_nlink)
28
                return;
29
        inode->i_size = 0;
30
}
31
 
32
static void proc_put_super(struct super_block *sb)
33
{
34
        lock_super(sb);
35
        sb->s_dev = 0;
36
        unlock_super(sb);
37
}
38
 
39
static struct super_operations proc_sops = {
40
        proc_read_inode,
41
        NULL,
42
        proc_write_inode,
43
        proc_put_inode,
44
        proc_put_super,
45
        NULL,
46
        proc_statfs,
47
        NULL
48
};
49
 
50
 
51
static int parse_options(char *options,uid_t *uid,gid_t *gid)
52
{
53
        char *this_char,*value;
54
 
55
        *uid = current->uid;
56
        *gid = current->gid;
57
        if (!options) return 1;
58
        for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
59
                if ((value = strchr(this_char,'=')) != NULL)
60
                        *value++ = 0;
61
                if (!strcmp(this_char,"uid")) {
62
                        if (!value || !*value)
63
                                return 0;
64
                        *uid = simple_strtoul(value,&value,0);
65
                        if (*value)
66
                                return 0;
67
                }
68
                else if (!strcmp(this_char,"gid")) {
69
                        if (!value || !*value)
70
                                return 0;
71
                        *gid = simple_strtoul(value,&value,0);
72
                        if (*value)
73
                                return 0;
74
                }
75
                else return 1;
76
        }
77
        return 1;
78
}
79
 
80
struct inode * proc_get_inode(struct super_block * s, int ino, struct proc_dir_entry * de)
81
{
82
        struct inode * inode = iget(s, ino);
83
        if (inode && inode->i_sb == s) {
84
                inode->u.generic_ip = (void *) de;
85
                if (de) {
86
                        if (de->mode) {
87
                                inode->i_mode = de->mode;
88
                                inode->i_uid = de->uid;
89
                                inode->i_gid = de->gid;
90
                        }
91
                        if (de->size)
92
                                inode->i_size = de->size;
93
                        if (de->ops)
94
                                inode->i_op = de->ops;
95
                        if (de->nlink)
96
                                inode->i_nlink = de->nlink;
97
                        if (de->fill_inode)
98
                                de->fill_inode(inode);
99
                }
100
        }
101
        return inode;
102
}
103
 
104
struct super_block *proc_read_super(struct super_block *s,void *data,
105
                                    int silent)
106
{
107
        proc_root_init();
108
        lock_super(s);
109
        s->s_blocksize = 1024;
110
        s->s_blocksize_bits = 10;
111
        s->s_magic = PROC_SUPER_MAGIC;
112
        s->s_op = &proc_sops;
113
        unlock_super(s);
114
        if (!(s->s_mounted = proc_get_inode(s, PROC_ROOT_INO, &proc_root))) {
115
                s->s_dev = 0;
116
                printk("get root inode failed\n");
117
                return NULL;
118
        }
119
        parse_options(data, &s->s_mounted->i_uid, &s->s_mounted->i_gid);
120
        return s;
121
}
122
 
123
void proc_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
124
{
125
        struct statfs tmp;
126
 
127
        tmp.f_type = PROC_SUPER_MAGIC;
128
        tmp.f_bsize = PAGE_SIZE/sizeof(long);
129
        tmp.f_blocks = 0;
130
        tmp.f_bfree = 0;
131
        tmp.f_bavail = 0;
132
        tmp.f_files = 0;
133
        tmp.f_ffree = 0;
134
        tmp.f_namelen = NAME_MAX;
135
        memcpy_tofs(buf, &tmp, bufsiz);
136
}
137
 
138
void proc_read_inode(struct inode * inode)
139
{
140
        unsigned long ino, pid;
141
        struct task_struct * p;
142
        int i;
143
 
144
        inode->i_op = NULL;
145
        inode->i_mode = 0;
146
        inode->i_uid = 0;
147
        inode->i_gid = 0;
148
        inode->i_nlink = 1;
149
        inode->i_size = 0;
150
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
151
        inode->i_blocks = 0;
152
        inode->i_blksize = 1024;
153
        ino = inode->i_ino;
154
        pid = ino >> 16;
155
        p = task[0];
156
        for (i = 0; i < NR_TASKS ; i++)
157
                if ((p = task[i]) && (p->pid == pid))
158
                        break;
159
        if (!p || i >= NR_TASKS)
160
                return;
161
        if (ino == PROC_ROOT_INO) {
162
                inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
163
                inode->i_nlink = 2;
164
                for (i = 1 ; i < NR_TASKS ; i++)
165
                        if (task[i])
166
                                inode->i_nlink++;
167
                return;
168
        }
169
 
170
        if (!pid) {
171
                switch (ino) {
172
                        case PROC_KMSG:
173
                                inode->i_mode = S_IFREG | S_IRUSR;
174
                                inode->i_op = &proc_kmsg_inode_operations;
175
                                break;
176
                        case PROC_NET:
177
                                inode->i_nlink = 2;
178
                                break;
179
                        case PROC_SCSI:
180
                                inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
181
                                inode->i_nlink = 2;
182
                                inode->i_op = &proc_scsi_inode_operations;
183
                                break;
184
                        case PROC_KCORE:
185
                                inode->i_mode = S_IFREG | S_IRUSR;
186
                                inode->i_op = &proc_kcore_inode_operations;
187
                                inode->i_size = (MAP_NR(high_memory) << PAGE_SHIFT) + PAGE_SIZE;
188
                                break;
189
                        case PROC_PROFILE:
190
                                inode->i_mode = S_IFREG | S_IRUGO | S_IWUSR;
191
                                inode->i_op = &proc_profile_inode_operations;
192
                                inode->i_size = (1+prof_len) * sizeof(unsigned long);
193
                                break;
194
                        default:
195
                                inode->i_mode = S_IFREG | S_IRUGO;
196
                                inode->i_op = &proc_array_inode_operations;
197
                                break;
198
                }
199
                return;
200
        }
201
        ino &= 0x0000ffff;
202
        if (ino == PROC_PID_INO || p->dumpable) {
203
                inode->i_uid = p->euid;
204
                inode->i_gid = p->egid;
205
        }
206
        switch (ino) {
207
                case PROC_PID_INO:
208
                        inode->i_nlink = 4;
209
                        return;
210
                case PROC_PID_MEM:
211
                        inode->i_op = &proc_mem_inode_operations;
212
                        inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
213
                        return;
214
                case PROC_PID_CWD:
215
                case PROC_PID_ROOT:
216
                case PROC_PID_EXE:
217
                        inode->i_op = &proc_link_inode_operations;
218
                        inode->i_size = 64;
219
                        inode->i_mode = S_IFLNK | S_IRWXU;
220
                        return;
221
                case PROC_PID_FD:
222
                        inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
223
                        inode->i_op = &proc_fd_inode_operations;
224
                        inode->i_nlink = 2;
225
                        return;
226
                case PROC_PID_ENVIRON:
227
                        inode->i_mode = S_IFREG | S_IRUSR;
228
                        inode->i_op = &proc_array_inode_operations;
229
                        return;
230
                case PROC_PID_CMDLINE:
231
                case PROC_PID_STATUS:
232
                case PROC_PID_STAT:
233
#ifndef NO_MM
234
                case PROC_PID_STATM:
235
#endif /* !NO_MM */
236
                        inode->i_mode = S_IFREG | S_IRUGO;
237
                        inode->i_op = &proc_array_inode_operations;
238
                        return;
239
#ifndef NO_MM
240
                case PROC_PID_MAPS:
241
                        inode->i_mode = S_IFIFO | S_IRUGO;
242
                        inode->i_op = &proc_arraylong_inode_operations;
243
                        return;
244
#endif /* !NO_MM */
245
        }
246
        switch (ino >> 8) {
247
                case PROC_PID_FD_DIR:
248
                        ino &= 0xff;
249
                        if (ino >= NR_OPEN || !p->files || !p->files->fd[ino])
250
                                return;
251
                        inode->i_op = &proc_link_inode_operations;
252
                        inode->i_size = 64;
253
                        inode->i_mode = S_IFLNK;
254
                        if (p->files->fd[ino]->f_mode & 1)
255
                                inode->i_mode |= S_IRUSR | S_IXUSR;
256
                        if (p->files->fd[ino]->f_mode & 2)
257
                                inode->i_mode |= S_IWUSR | S_IXUSR;
258
                        return;
259
        }
260
        return;
261
}
262
 
263
void proc_write_inode(struct inode * inode)
264
{
265
        inode->i_dirt=0;
266
}

powered by: WebSVN 2.1.0

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