patch-2.6.6-vs1.9.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/config.h>
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <asm/bitops.h>
19 #include <linux/smp_lock.h>
20
21 struct proc_dir_entry *proc_net, *proc_bus, *proc_root_fs, *proc_root_driver;
22
23 #ifdef CONFIG_SYSCTL
24 struct proc_dir_entry *proc_sys_root;
25 #endif
26 struct proc_dir_entry *proc_virtual;
27
28 extern void proc_vx_init(void);
29
30 static struct super_block *proc_get_sb(struct file_system_type *fs_type,
31         int flags, const char *dev_name, void *data)
32 {
33         return get_sb_single(fs_type, flags, data, proc_fill_super);
34 }
35
36 static struct file_system_type proc_fs_type = {
37         .name           = "proc",
38         .get_sb         = proc_get_sb,
39         .kill_sb        = kill_anon_super,
40 };
41
42 extern int __init proc_init_inodecache(void);
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", 0);
59 #ifdef CONFIG_SYSVIPC
60         proc_mkdir("sysvipc", 0);
61 #endif
62 #ifdef CONFIG_SYSCTL
63         proc_sys_root = proc_mkdir("sys", 0);
64 #endif
65 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
66         proc_mkdir("sys/fs", 0);
67         proc_mkdir("sys/fs/binfmt_misc", 0);
68 #endif
69         proc_root_fs = proc_mkdir("fs", 0);
70         proc_root_driver = proc_mkdir("driver", 0);
71         proc_mkdir("fs/nfsd", 0); /* somewhere for the nfsd filesystem to be mounted */
72 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
73         /* just give it a mountpoint */
74         proc_mkdir("openprom", 0);
75 #endif
76         proc_tty_init();
77 #ifdef CONFIG_PROC_DEVICETREE
78         proc_device_tree_init();
79 #endif
80         proc_bus = proc_mkdir("bus", 0);
81         proc_vx_init();
82 }
83
84 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd)
85 {
86         /*
87          * nr_threads is actually protected by the tasklist_lock;
88          * however, it's conventional to do reads, especially for
89          * reporting, without any locking whatsoever.
90          */
91         if (dir->i_ino == PROC_ROOT_INO) /* check for safety... */
92                 dir->i_nlink = proc_root.nlink + nr_threads;
93
94         if (!proc_lookup(dir, dentry, nd)) {
95                 return NULL;
96         }
97         
98         return proc_pid_lookup(dir, dentry, nd);
99 }
100
101 static int proc_root_readdir(struct file * filp,
102         void * dirent, filldir_t filldir)
103 {
104         unsigned int nr = filp->f_pos;
105         int ret;
106
107         lock_kernel();
108
109         if (nr < FIRST_PROCESS_ENTRY) {
110                 int error = proc_readdir(filp, dirent, filldir);
111                 if (error <= 0) {
112                         unlock_kernel();
113                         return error;
114                 }
115                 filp->f_pos = FIRST_PROCESS_ENTRY;
116         }
117         unlock_kernel();
118
119         ret = proc_pid_readdir(filp, dirent, filldir);
120         return ret;
121 }
122
123 /*
124  * The root /proc directory is special, as it has the
125  * <pid> directories. Thus we don't use the generic
126  * directory handling functions for that..
127  */
128 static struct file_operations proc_root_operations = {
129         .read            = generic_read_dir,
130         .readdir         = proc_root_readdir,
131 };
132
133 /*
134  * proc root can do almost nothing..
135  */
136 static struct inode_operations proc_root_inode_operations = {
137         .lookup         = proc_root_lookup,
138 };
139
140 /*
141  * This is the root "inode" in the /proc tree..
142  */
143 struct proc_dir_entry proc_root = {
144         .low_ino        = PROC_ROOT_INO, 
145         .namelen        = 5, 
146         .name           = "/proc",
147         .mode           = S_IFDIR | S_IRUGO | S_IXUGO, 
148         .nlink          = 2, 
149         .proc_iops      = &proc_root_inode_operations, 
150         .proc_fops      = &proc_root_operations,
151         .parent         = &proc_root,
152 };
153
154 #ifdef CONFIG_SYSCTL
155 EXPORT_SYMBOL(proc_sys_root);
156 #endif
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_bus);
165 EXPORT_SYMBOL(proc_root_driver);