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