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/smp_lock.h>
19 #include <asm/system.h>
20 #include <asm/uaccess.h>
24 struct proc_dir_entry
*de_get(struct proc_dir_entry
*de
)
27 atomic_inc(&de
->count
);
32 * Decrements the use count and checks for deferred deletion.
34 void de_put(struct proc_dir_entry
*de
)
38 if (!atomic_read(&de
->count
)) {
39 printk("de_put: entry %s already free!\n", de
->name
);
44 if (atomic_dec_and_test(&de
->count
))
51 * Decrement the use count of the proc_dir_entry.
53 static void proc_delete_inode(struct inode
*inode
)
55 struct proc_dir_entry
*de
;
57 truncate_inode_pages(&inode
->i_data
, 0);
59 /* Stop tracking associated processes */
60 put_pid(PROC_I(inode
)->pid
);
62 /* Let go of any associated proc directory entry */
63 de
= PROC_I(inode
)->pde
;
66 module_put(de
->owner
);
72 struct vfsmount
*proc_mnt
;
74 static void proc_read_inode(struct inode
* inode
)
76 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
79 static struct kmem_cache
* proc_inode_cachep
;
81 static struct inode
*proc_alloc_inode(struct super_block
*sb
)
83 struct proc_inode
*ei
;
86 ei
= (struct proc_inode
*)kmem_cache_alloc(proc_inode_cachep
, GFP_KERNEL
);
91 ei
->op
.proc_get_link
= NULL
;
93 inode
= &ei
->vfs_inode
;
94 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
98 static void proc_destroy_inode(struct inode
*inode
)
100 kmem_cache_free(proc_inode_cachep
, PROC_I(inode
));
103 static void init_once(void * foo
, struct kmem_cache
* cachep
, unsigned long flags
)
105 struct proc_inode
*ei
= (struct proc_inode
*) foo
;
107 inode_init_once(&ei
->vfs_inode
);
110 int __init
proc_init_inodecache(void)
112 proc_inode_cachep
= kmem_cache_create("proc_inode_cache",
113 sizeof(struct proc_inode
),
114 0, (SLAB_RECLAIM_ACCOUNT
|
117 if (proc_inode_cachep
== NULL
)
122 static int proc_remount(struct super_block
*sb
, int *flags
, char *data
)
124 *flags
|= MS_NODIRATIME
;
128 static const struct super_operations proc_sops
= {
129 .alloc_inode
= proc_alloc_inode
,
130 .destroy_inode
= proc_destroy_inode
,
131 .read_inode
= proc_read_inode
,
132 .drop_inode
= generic_delete_inode
,
133 .delete_inode
= proc_delete_inode
,
134 .statfs
= simple_statfs
,
135 .remount_fs
= proc_remount
,
138 struct inode
*proc_get_inode(struct super_block
*sb
, unsigned int ino
,
139 struct proc_dir_entry
*de
)
141 struct inode
* inode
;
143 if (de
!= NULL
&& !try_module_get(de
->owner
))
146 inode
= iget(sb
, ino
);
150 PROC_I(inode
)->fd
= 0;
151 PROC_I(inode
)->pde
= de
;
154 inode
->i_mode
= de
->mode
;
155 inode
->i_uid
= de
->uid
;
156 inode
->i_gid
= de
->gid
;
159 inode
->i_size
= de
->size
;
161 inode
->i_nlink
= de
->nlink
;
163 inode
->i_op
= de
->proc_iops
;
165 inode
->i_fop
= de
->proc_fops
;
172 module_put(de
->owner
);
177 int proc_fill_super(struct super_block
*s
, void *data
, int silent
)
179 struct inode
* root_inode
;
181 s
->s_flags
|= MS_NODIRATIME
| MS_NOSUID
| MS_NOEXEC
;
182 s
->s_blocksize
= 1024;
183 s
->s_blocksize_bits
= 10;
184 s
->s_magic
= PROC_SUPER_MAGIC
;
185 s
->s_op
= &proc_sops
;
189 root_inode
= proc_get_inode(s
, PROC_ROOT_INO
, &proc_root
);
192 root_inode
->i_uid
= 0;
193 root_inode
->i_gid
= 0;
194 s
->s_root
= d_alloc_root(root_inode
);
200 printk("proc_read_super: get root inode failed\n");
205 MODULE_LICENSE("GPL");