Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / proc / root.c
1 /*
2  *  linux/fs/proc/root.c
3  *
4  *  Copyright (C) 1991, 1992 Linus Torvalds
5  *
6  *  proc root directory handling functions
7  */
8
9 #include <asm/uaccess.h>
10
11 #include <linux/errno.h>
12 #include <linux/time.h>
13 #include <linux/proc_fs.h>
14 #include <linux/stat.h>
15 #include <linux/config.h>
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/bitops.h>
19 #include <linux/smp_lock.h>
20
21 #include "internal.h"
22
23 struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
24
25 #ifdef CONFIG_SYSCTL
26 struct proc_dir_entry *proc_sys_root;
27 #endif
28 struct proc_dir_entry *proc_virtual;
29
30 extern void proc_vx_init(void);
31
32 static struct super_block *proc_get_sb(struct file_system_type *fs_type,
33         int flags, const char *dev_name, void *data)
34 {
35         return get_sb_single(fs_type, flags, data, proc_fill_super);
36 }
37
38 static struct file_system_type proc_fs_type = {
39         .name           = "proc",
40         .get_sb         = proc_get_sb,
41         .kill_sb        = kill_anon_super,
42 };
43
44 void __init proc_root_init(void)
45 {
46         int err = proc_init_inodecache();
47         if (err)
48                 return;
49         err = register_filesystem(&proc_fs_type);
50         if (err)
51                 return;
52         proc_mnt = kern_mount(&proc_fs_type);
53         err = PTR_ERR(proc_mnt);
54         if (IS_ERR(proc_mnt)) {
55                 unregister_filesystem(&proc_fs_type);
56                 return;
57         }
58         proc_misc_init();
59         proc_net = proc_mkdir("net", NULL);
60         proc_net_stat = proc_mkdir("net/stat", NULL);
61
62 #ifdef CONFIG_SYSVIPC
63         proc_mkdir("sysvipc", NULL);
64 #endif
65 #ifdef CONFIG_SYSCTL
66         proc_sys_root = proc_mkdir("sys", NULL);
67 #endif
68 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
69         proc_mkdir("sys/fs", NULL);
70         proc_mkdir("sys/fs/binfmt_misc", NULL);
71 #endif
72         proc_root_fs = proc_mkdir("fs", NULL);
73         proc_root_driver = proc_mkdir("driver", NULL);
74         proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */
75 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
76         /* just give it a mountpoint */
77         proc_mkdir("openprom", NULL);
78 #endif
79         proc_tty_init();
80 #ifdef CONFIG_PROC_DEVICETREE
81         proc_device_tree_init();
82 #endif
83         proc_bus = proc_mkdir("bus", NULL);
84         proc_vx_init();
85 }
86
87 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
88 )
89 {
90         generic_fillattr(dentry->d_inode, stat);
91         stat->nlink = proc_root.nlink + nr_processes();
92         return 0;
93 }
94
95 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd)
96 {
97         if (!proc_lookup(dir, dentry, nd)) {
98                 return NULL;
99         }
100         
101         return proc_pid_lookup(dir, dentry, nd);
102 }
103
104 static int proc_root_readdir(struct file * filp,
105         void * dirent, filldir_t filldir)
106 {
107         unsigned int nr = filp->f_pos;
108         int ret;
109
110         lock_kernel();
111
112         if (nr < FIRST_PROCESS_ENTRY) {
113                 int error = proc_readdir(filp, dirent, filldir);
114                 if (error <= 0) {
115                         unlock_kernel();
116                         return error;
117                 }
118                 filp->f_pos = FIRST_PROCESS_ENTRY;
119         }
120         unlock_kernel();
121
122         ret = proc_pid_readdir(filp, dirent, filldir);
123         return ret;
124 }
125
126 /*
127  * The root /proc directory is special, as it has the
128  * <pid> directories. Thus we don't use the generic
129  * directory handling functions for that..
130  */
131 static struct file_operations proc_root_operations = {
132         .read            = generic_read_dir,
133         .readdir         = proc_root_readdir,
134 };
135
136 /*
137  * proc root can do almost nothing..
138  */
139 static struct inode_operations proc_root_inode_operations = {
140         .lookup         = proc_root_lookup,
141         .getattr        = proc_root_getattr,
142 };
143
144 /*
145  * This is the root "inode" in the /proc tree..
146  */
147 struct proc_dir_entry proc_root = {
148         .low_ino        = PROC_ROOT_INO, 
149         .namelen        = 5, 
150         .name           = "/proc",
151         .mode           = S_IFDIR | S_IRUGO | S_IXUGO, 
152         .nlink          = 2, 
153         .proc_iops      = &proc_root_inode_operations, 
154         .proc_fops      = &proc_root_operations,
155         .parent         = &proc_root,
156 };
157
158 EXPORT_SYMBOL(proc_symlink);
159 EXPORT_SYMBOL(proc_mkdir);
160 EXPORT_SYMBOL(create_proc_entry);
161 EXPORT_SYMBOL(remove_proc_entry);
162 EXPORT_SYMBOL(proc_root);
163 EXPORT_SYMBOL(proc_root_fs);
164 EXPORT_SYMBOL(proc_net);
165 EXPORT_SYMBOL(proc_net_stat);
166 EXPORT_SYMBOL(proc_bus);
167 EXPORT_SYMBOL(proc_root_driver);