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