import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.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/sched.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 #ifdef CONFIG_PPC_ISERIES
20 #include <asm/iSeries/iSeries_proc.h>
21 #endif
22
23 struct proc_dir_entry *proc_net, *proc_bus, *proc_root_fs, *proc_root_driver;
24
25 #ifdef CONFIG_SYSCTL
26 struct proc_dir_entry *proc_sys_root;
27 #endif
28
29 static DECLARE_FSTYPE(proc_fs_type, "proc", proc_read_super, FS_SINGLE);
30
31 void __init proc_root_init(void)
32 {
33         int err = register_filesystem(&proc_fs_type);
34         if (err)
35                 return;
36         proc_mnt = kern_mount(&proc_fs_type);
37         err = PTR_ERR(proc_mnt);
38         if (IS_ERR(proc_mnt)) {
39                 unregister_filesystem(&proc_fs_type);
40                 return;
41         }
42         proc_misc_init();
43         proc_net = proc_mkdir("net", 0);
44 #ifdef CONFIG_SYSVIPC
45         proc_mkdir("sysvipc", 0);
46 #endif
47 #ifdef CONFIG_SYSCTL
48         proc_sys_root = proc_mkdir("sys", 0);
49 #endif
50 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
51         proc_mkdir("sys/fs", 0);
52         proc_mkdir("sys/fs/binfmt_misc", 0);
53 #endif
54         proc_root_fs = proc_mkdir("fs", 0);
55         proc_root_driver = proc_mkdir("driver", 0);
56 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
57         /* just give it a mountpoint */
58         proc_mkdir("openprom", 0);
59 #endif
60         proc_tty_init();
61 #ifdef CONFIG_PROC_DEVICETREE
62         proc_device_tree_init();
63 #endif
64 #ifdef CONFIG_PPC_ISERIES
65         iSeries_proc_create();
66 #endif
67 #ifdef CONFIG_PPC64
68         proc_ppc64_init(); 
69 #endif
70 #ifdef CONFIG_PPC_RTAS
71         proc_rtas_init();
72 #endif
73         proc_bus = proc_mkdir("bus", 0);
74 }
75
76 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
77 {
78         if (dir->i_ino == PROC_ROOT_INO) { /* check for safety... */
79                 int nlink = proc_root.nlink;
80
81                 nlink += nr_threads;
82
83                 dir->i_nlink = nlink;
84         }
85
86         if (!proc_lookup(dir, dentry))
87                 return NULL;
88         
89         return proc_pid_lookup(dir, dentry);
90 }
91
92 static int proc_root_readdir(struct file * filp,
93         void * dirent, filldir_t filldir)
94 {
95         unsigned int nr = filp->f_pos;
96
97         if (nr < FIRST_PROCESS_ENTRY) {
98                 int error = proc_readdir(filp, dirent, filldir);
99                 if (error <= 0)
100                         return error;
101                 filp->f_pos = FIRST_PROCESS_ENTRY;
102         }
103
104         return proc_pid_readdir(filp, dirent, filldir);
105 }
106
107 /*
108  * The root /proc directory is special, as it has the
109  * <pid> directories. Thus we don't use the generic
110  * directory handling functions for that..
111  */
112 static struct file_operations proc_root_operations = {
113         read:            generic_read_dir,
114         readdir:         proc_root_readdir,
115 };
116
117 /*
118  * proc root can do almost nothing..
119  */
120 static struct inode_operations proc_root_inode_operations = {
121         lookup:         proc_root_lookup,
122 };
123
124 /*
125  * This is the root "inode" in the /proc tree..
126  */
127 struct proc_dir_entry proc_root = {
128         low_ino:        PROC_ROOT_INO, 
129         namelen:        5, 
130         name:           "/proc",
131         mode:           S_IFDIR | S_IRUGO | S_IXUGO, 
132         nlink:          2, 
133         proc_iops:      &proc_root_inode_operations, 
134         proc_fops:      &proc_root_operations,
135         parent:         &proc_root,
136 };
137
138 #ifdef CONFIG_SYSCTL
139 EXPORT_SYMBOL(proc_sys_root);
140 #endif
141 EXPORT_SYMBOL(proc_symlink);
142 EXPORT_SYMBOL(proc_mknod);
143 EXPORT_SYMBOL(proc_mkdir);
144 EXPORT_SYMBOL(create_proc_entry);
145 EXPORT_SYMBOL(remove_proc_entry);
146 EXPORT_SYMBOL(proc_root);
147 EXPORT_SYMBOL(proc_root_fs);
148 EXPORT_SYMBOL(proc_net);
149 EXPORT_SYMBOL(proc_bus);
150 EXPORT_SYMBOL(proc_root_driver);