2 * linux/fs/proc/inode.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/time.h>
8 #include <linux/proc_fs.h>
9 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/stat.h>
13 #include <linux/file.h>
14 #include <linux/limits.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/parser.h>
18 #include <linux/smp_lock.h>
20 #include <asm/system.h>
21 #include <asm/uaccess.h>
23 extern void free_proc_entry(struct proc_dir_entry *);
25 static inline struct proc_dir_entry * de_get(struct proc_dir_entry *de)
28 atomic_inc(&de->count);
33 * Decrements the use count and checks for deferred deletion.
35 static void de_put(struct proc_dir_entry *de)
39 if (!atomic_read(&de->count)) {
40 printk("de_put: entry %s already free!\n", de->name);
45 if (atomic_dec_and_test(&de->count)) {
47 printk("de_put: deferred delete of %s\n",
57 * Decrement the use count of the proc_dir_entry.
59 static void proc_delete_inode(struct inode *inode)
61 struct proc_dir_entry *de;
62 struct task_struct *tsk;
64 /* Let go of any associated process */
65 tsk = PROC_I(inode)->task;
69 /* Let go of any associated proc directory entry */
70 de = PROC_I(inode)->pde;
73 module_put(de->owner);
79 struct vfsmount *proc_mnt;
81 static void proc_read_inode(struct inode * inode)
83 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
86 static kmem_cache_t * proc_inode_cachep;
88 static struct inode *proc_alloc_inode(struct super_block *sb)
90 struct proc_inode *ei;
93 ei = (struct proc_inode *)kmem_cache_alloc(proc_inode_cachep, SLAB_KERNEL);
98 ei->op.proc_get_link = NULL;
100 inode = &ei->vfs_inode;
101 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
105 static void proc_destroy_inode(struct inode *inode)
107 kmem_cache_free(proc_inode_cachep, PROC_I(inode));
110 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
112 struct proc_inode *ei = (struct proc_inode *) foo;
114 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
115 SLAB_CTOR_CONSTRUCTOR)
116 inode_init_once(&ei->vfs_inode);
119 int __init proc_init_inodecache(void)
121 proc_inode_cachep = kmem_cache_create("proc_inode_cache",
122 sizeof(struct proc_inode),
123 0, SLAB_RECLAIM_ACCOUNT,
125 if (proc_inode_cachep == NULL)
130 static int proc_remount(struct super_block *sb, int *flags, char *data)
132 *flags |= MS_NODIRATIME;
136 static struct super_operations proc_sops = {
137 .alloc_inode = proc_alloc_inode,
138 .destroy_inode = proc_destroy_inode,
139 .read_inode = proc_read_inode,
140 .drop_inode = generic_delete_inode,
141 .delete_inode = proc_delete_inode,
142 .statfs = simple_statfs,
143 .remount_fs = proc_remount,
147 Opt_uid, Opt_gid, Opt_err
150 static match_table_t tokens = {
156 static int parse_options(char *options,uid_t *uid,gid_t *gid)
166 while ((p = strsep(&options, ",")) != NULL) {
167 substring_t args[MAX_OPT_ARGS];
172 token = match_token(p, tokens, args);
175 if (match_int(args, &option))
180 if (match_int(args, &option))
191 struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
192 struct proc_dir_entry *de)
194 struct inode * inode;
197 * Increment the use count so the dir entry can't disappear.
201 WARN_ON(de && de->deleted);
203 inode = iget(sb, ino);
207 PROC_I(inode)->pde = de;
210 inode->i_mode = de->mode;
211 inode->i_uid = de->uid;
212 inode->i_gid = de->gid;
215 PROC_I(inode)->vx_flags = de->vx_flags;
217 inode->i_size = de->size;
219 inode->i_nlink = de->nlink;
220 if (!try_module_get(de->owner))
223 inode->i_op = de->proc_iops;
225 inode->i_fop = de->proc_fops;
236 int proc_fill_super(struct super_block *s, void *data, int silent)
238 struct inode * root_inode;
240 s->s_flags |= MS_NODIRATIME;
241 s->s_blocksize = 1024;
242 s->s_blocksize_bits = 10;
243 s->s_magic = PROC_SUPER_MAGIC;
244 s->s_op = &proc_sops;
247 root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root);
251 * Fixup the root inode's nlink value
253 root_inode->i_nlink += nr_processes();
254 s->s_root = d_alloc_root(root_inode);
257 parse_options(data, &root_inode->i_uid, &root_inode->i_gid);
261 printk("proc_read_super: get root inode failed\n");
265 MODULE_LICENSE("GPL");