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