blob: 27c762f34870a2923b49edecf78135b7dbf922b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/proc/inode.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7#include <linux/time.h>
8#include <linux/proc_fs.h>
9#include <linux/kernel.h>
Vasiliy Kulikov97412952012-01-10 15:11:27 -080010#include <linux/pid_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/mm.h>
12#include <linux/string.h>
13#include <linux/stat.h>
Alexey Dobriyan786d7e12007-07-15 23:39:00 -070014#include <linux/completion.h>
Alexey Dobriyandd23aae2007-09-11 15:23:55 -070015#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/file.h>
17#include <linux/limits.h>
18#include <linux/init.h>
19#include <linux/module.h>
Al Viro9043476f2008-07-15 08:54:06 -040020#include <linux/sysctl.h>
Vasiliy Kulikov97412952012-01-10 15:11:27 -080021#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Vasiliy Kulikov97412952012-01-10 15:11:27 -080023#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/system.h>
26#include <asm/uaccess.h>
27
Adrian Bunkfee781e2006-01-08 01:04:16 -080028#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Al Viro82679522010-06-04 22:17:56 -040030static void proc_evict_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 struct proc_dir_entry *de;
Al Virodfef6dcd32011-03-08 01:25:28 -050033 struct ctl_table_header *head;
Eric W. Biederman6b4e3062010-03-07 16:41:34 -080034 const struct proc_ns_operations *ns_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Mark Fashehfef26652005-09-09 13:01:31 -070036 truncate_inode_pages(&inode->i_data, 0);
Al Viro82679522010-06-04 22:17:56 -040037 end_writeback(inode);
Mark Fashehfef26652005-09-09 13:01:31 -070038
Eric W. Biederman99f89552006-06-26 00:25:55 -070039 /* Stop tracking associated processes */
Eric W. Biederman13b41b02006-06-26 00:25:56 -070040 put_pid(PROC_I(inode)->pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 /* Let go of any associated proc directory entry */
43 de = PROC_I(inode)->pde;
Alexey Dobriyan99b76232009-03-25 22:48:06 +030044 if (de)
Alexey Dobriyan135d5652009-12-15 16:45:39 -080045 pde_put(de);
Al Virodfef6dcd32011-03-08 01:25:28 -050046 head = PROC_I(inode)->sysctl;
47 if (head) {
48 rcu_assign_pointer(PROC_I(inode)->sysctl, NULL);
49 sysctl_head_put(head);
50 }
Eric W. Biederman6b4e3062010-03-07 16:41:34 -080051 /* Release any associated namespace */
52 ns_ops = PROC_I(inode)->ns_ops;
53 if (ns_ops && ns_ops->put)
54 ns_ops->put(PROC_I(inode)->ns);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Christoph Lametere18b8902006-12-06 20:33:20 -080057static struct kmem_cache * proc_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59static struct inode *proc_alloc_inode(struct super_block *sb)
60{
61 struct proc_inode *ei;
62 struct inode *inode;
63
Christoph Lametere94b1762006-12-06 20:33:17 -080064 ei = (struct proc_inode *)kmem_cache_alloc(proc_inode_cachep, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 if (!ei)
66 return NULL;
Eric W. Biederman13b41b02006-06-26 00:25:56 -070067 ei->pid = NULL;
Eric W. Biedermanaed7a6c2006-06-26 00:25:44 -070068 ei->fd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 ei->op.proc_get_link = NULL;
70 ei->pde = NULL;
Al Viro9043476f2008-07-15 08:54:06 -040071 ei->sysctl = NULL;
72 ei->sysctl_entry = NULL;
Eric W. Biederman6b4e3062010-03-07 16:41:34 -080073 ei->ns = NULL;
74 ei->ns_ops = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 inode = &ei->vfs_inode;
76 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
77 return inode;
78}
79
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +110080static void proc_i_callback(struct rcu_head *head)
81{
82 struct inode *inode = container_of(head, struct inode, i_rcu);
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +110083 kmem_cache_free(proc_inode_cachep, PROC_I(inode));
84}
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static void proc_destroy_inode(struct inode *inode)
87{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +110088 call_rcu(&inode->i_rcu, proc_i_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070091static void init_once(void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 struct proc_inode *ei = (struct proc_inode *) foo;
94
Christoph Lametera35afb82007-05-16 22:10:57 -070095 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
Paul Mundt20c2df82007-07-20 10:11:58 +090097
Alexey Dobriyan5bcd7ff2008-10-17 03:43:55 +040098void __init proc_init_inodecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 proc_inode_cachep = kmem_cache_create("proc_inode_cache",
101 sizeof(struct proc_inode),
Paul Jacksonfffb60f2006-03-24 03:16:06 -0800102 0, (SLAB_RECLAIM_ACCOUNT|
Alexey Dobriyan040b5c62007-10-16 23:26:10 -0700103 SLAB_MEM_SPREAD|SLAB_PANIC),
Paul Mundt20c2df82007-07-20 10:11:58 +0900104 init_once);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Vasiliy Kulikov97412952012-01-10 15:11:27 -0800107static int proc_show_options(struct seq_file *seq, struct dentry *root)
108{
109 return 0;
110}
111
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800112static const struct super_operations proc_sops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .alloc_inode = proc_alloc_inode,
114 .destroy_inode = proc_destroy_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 .drop_inode = generic_delete_inode,
Al Viro82679522010-06-04 22:17:56 -0400116 .evict_inode = proc_evict_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .statfs = simple_statfs,
Vasiliy Kulikov97412952012-01-10 15:11:27 -0800118 .remount_fs = proc_remount,
119 .show_options = proc_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700122static void __pde_users_dec(struct proc_dir_entry *pde)
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700123{
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700124 pde->pde_users--;
125 if (pde->pde_unload_completion && pde->pde_users == 0)
126 complete(pde->pde_unload_completion);
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700127}
128
Alexey Dobriyan3dec7f52009-02-20 17:04:33 +0300129void pde_users_dec(struct proc_dir_entry *pde)
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700130{
131 spin_lock(&pde->pde_unload_lock);
132 __pde_users_dec(pde);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700133 spin_unlock(&pde->pde_unload_lock);
134}
135
136static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
137{
138 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
139 loff_t rv = -EINVAL;
140 loff_t (*llseek)(struct file *, loff_t, int);
141
142 spin_lock(&pde->pde_unload_lock);
143 /*
144 * remove_proc_entry() is going to delete PDE (as part of module
145 * cleanup sequence). No new callers into module allowed.
146 */
147 if (!pde->proc_fops) {
148 spin_unlock(&pde->pde_unload_lock);
149 return rv;
150 }
151 /*
152 * Bump refcount so that remove_proc_entry will wail for ->llseek to
153 * complete.
154 */
155 pde->pde_users++;
156 /*
157 * Save function pointer under lock, to protect against ->proc_fops
158 * NULL'ifying right after ->pde_unload_lock is dropped.
159 */
160 llseek = pde->proc_fops->llseek;
161 spin_unlock(&pde->pde_unload_lock);
162
163 if (!llseek)
164 llseek = default_llseek;
165 rv = llseek(file, offset, whence);
166
167 pde_users_dec(pde);
168 return rv;
169}
170
171static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
172{
173 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
174 ssize_t rv = -EIO;
175 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
176
177 spin_lock(&pde->pde_unload_lock);
178 if (!pde->proc_fops) {
179 spin_unlock(&pde->pde_unload_lock);
180 return rv;
181 }
182 pde->pde_users++;
183 read = pde->proc_fops->read;
184 spin_unlock(&pde->pde_unload_lock);
185
186 if (read)
187 rv = read(file, buf, count, ppos);
188
189 pde_users_dec(pde);
190 return rv;
191}
192
193static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
194{
195 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
196 ssize_t rv = -EIO;
197 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
198
199 spin_lock(&pde->pde_unload_lock);
200 if (!pde->proc_fops) {
201 spin_unlock(&pde->pde_unload_lock);
202 return rv;
203 }
204 pde->pde_users++;
205 write = pde->proc_fops->write;
206 spin_unlock(&pde->pde_unload_lock);
207
208 if (write)
209 rv = write(file, buf, count, ppos);
210
211 pde_users_dec(pde);
212 return rv;
213}
214
215static unsigned int proc_reg_poll(struct file *file, struct poll_table_struct *pts)
216{
217 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
Alexey Dobriyandd23aae2007-09-11 15:23:55 -0700218 unsigned int rv = DEFAULT_POLLMASK;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700219 unsigned int (*poll)(struct file *, struct poll_table_struct *);
220
221 spin_lock(&pde->pde_unload_lock);
222 if (!pde->proc_fops) {
223 spin_unlock(&pde->pde_unload_lock);
224 return rv;
225 }
226 pde->pde_users++;
227 poll = pde->proc_fops->poll;
228 spin_unlock(&pde->pde_unload_lock);
229
230 if (poll)
231 rv = poll(file, pts);
232
233 pde_users_dec(pde);
234 return rv;
235}
236
237static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
238{
239 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
240 long rv = -ENOTTY;
Arnd Bergmannb19dd422010-07-04 00:15:10 +0200241 long (*ioctl)(struct file *, unsigned int, unsigned long);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700242
243 spin_lock(&pde->pde_unload_lock);
244 if (!pde->proc_fops) {
245 spin_unlock(&pde->pde_unload_lock);
246 return rv;
247 }
248 pde->pde_users++;
Arnd Bergmannb19dd422010-07-04 00:15:10 +0200249 ioctl = pde->proc_fops->unlocked_ioctl;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700250 spin_unlock(&pde->pde_unload_lock);
251
Arnd Bergmannb19dd422010-07-04 00:15:10 +0200252 if (ioctl)
253 rv = ioctl(file, cmd, arg);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700254
255 pde_users_dec(pde);
256 return rv;
257}
258
259#ifdef CONFIG_COMPAT
260static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
261{
262 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
263 long rv = -ENOTTY;
264 long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
265
266 spin_lock(&pde->pde_unload_lock);
267 if (!pde->proc_fops) {
268 spin_unlock(&pde->pde_unload_lock);
269 return rv;
270 }
271 pde->pde_users++;
272 compat_ioctl = pde->proc_fops->compat_ioctl;
273 spin_unlock(&pde->pde_unload_lock);
274
275 if (compat_ioctl)
276 rv = compat_ioctl(file, cmd, arg);
277
278 pde_users_dec(pde);
279 return rv;
280}
281#endif
282
283static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma)
284{
285 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
286 int rv = -EIO;
287 int (*mmap)(struct file *, struct vm_area_struct *);
288
289 spin_lock(&pde->pde_unload_lock);
290 if (!pde->proc_fops) {
291 spin_unlock(&pde->pde_unload_lock);
292 return rv;
293 }
294 pde->pde_users++;
295 mmap = pde->proc_fops->mmap;
296 spin_unlock(&pde->pde_unload_lock);
297
298 if (mmap)
299 rv = mmap(file, vma);
300
301 pde_users_dec(pde);
302 return rv;
303}
304
305static int proc_reg_open(struct inode *inode, struct file *file)
306{
307 struct proc_dir_entry *pde = PDE(inode);
308 int rv = 0;
309 int (*open)(struct inode *, struct file *);
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700310 int (*release)(struct inode *, struct file *);
311 struct pde_opener *pdeo;
312
313 /*
314 * What for, you ask? Well, we can have open, rmmod, remove_proc_entry
315 * sequence. ->release won't be called because ->proc_fops will be
316 * cleared. Depending on complexity of ->release, consequences vary.
317 *
318 * We can't wait for mercy when close will be done for real, it's
319 * deadlockable: rmmod foo </proc/foo . So, we're going to do ->release
320 * by hand in remove_proc_entry(). For this, save opener's credentials
321 * for later.
322 */
323 pdeo = kmalloc(sizeof(struct pde_opener), GFP_KERNEL);
324 if (!pdeo)
325 return -ENOMEM;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700326
327 spin_lock(&pde->pde_unload_lock);
328 if (!pde->proc_fops) {
329 spin_unlock(&pde->pde_unload_lock);
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700330 kfree(pdeo);
Daisuke Oginod2857e72011-07-26 16:08:37 -0700331 return -ENOENT;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700332 }
333 pde->pde_users++;
334 open = pde->proc_fops->open;
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700335 release = pde->proc_fops->release;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700336 spin_unlock(&pde->pde_unload_lock);
337
338 if (open)
339 rv = open(inode, file);
340
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700341 spin_lock(&pde->pde_unload_lock);
342 if (rv == 0 && release) {
343 /* To know what to release. */
344 pdeo->inode = inode;
345 pdeo->file = file;
346 /* Strictly for "too late" ->release in proc_reg_release(). */
347 pdeo->release = release;
348 list_add(&pdeo->lh, &pde->pde_openers);
349 } else
350 kfree(pdeo);
351 __pde_users_dec(pde);
352 spin_unlock(&pde->pde_unload_lock);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700353 return rv;
354}
355
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700356static struct pde_opener *find_pde_opener(struct proc_dir_entry *pde,
357 struct inode *inode, struct file *file)
358{
359 struct pde_opener *pdeo;
360
361 list_for_each_entry(pdeo, &pde->pde_openers, lh) {
362 if (pdeo->inode == inode && pdeo->file == file)
363 return pdeo;
364 }
365 return NULL;
366}
367
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700368static int proc_reg_release(struct inode *inode, struct file *file)
369{
370 struct proc_dir_entry *pde = PDE(inode);
371 int rv = 0;
372 int (*release)(struct inode *, struct file *);
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700373 struct pde_opener *pdeo;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700374
375 spin_lock(&pde->pde_unload_lock);
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700376 pdeo = find_pde_opener(pde, inode, file);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700377 if (!pde->proc_fops) {
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700378 /*
379 * Can't simply exit, __fput() will think that everything is OK,
380 * and move on to freeing struct file. remove_proc_entry() will
381 * find slacker in opener's list and will try to do non-trivial
382 * things with struct file. Therefore, remove opener from list.
383 *
384 * But if opener is removed from list, who will ->release it?
385 */
386 if (pdeo) {
387 list_del(&pdeo->lh);
388 spin_unlock(&pde->pde_unload_lock);
389 rv = pdeo->release(inode, file);
390 kfree(pdeo);
391 } else
392 spin_unlock(&pde->pde_unload_lock);
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700393 return rv;
394 }
395 pde->pde_users++;
396 release = pde->proc_fops->release;
Alexey Dobriyan881adb82008-07-25 01:48:29 -0700397 if (pdeo) {
398 list_del(&pdeo->lh);
399 kfree(pdeo);
400 }
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700401 spin_unlock(&pde->pde_unload_lock);
402
403 if (release)
404 rv = release(inode, file);
405
406 pde_users_dec(pde);
407 return rv;
408}
409
410static const struct file_operations proc_reg_file_ops = {
411 .llseek = proc_reg_llseek,
412 .read = proc_reg_read,
413 .write = proc_reg_write,
414 .poll = proc_reg_poll,
415 .unlocked_ioctl = proc_reg_unlocked_ioctl,
416#ifdef CONFIG_COMPAT
417 .compat_ioctl = proc_reg_compat_ioctl,
418#endif
419 .mmap = proc_reg_mmap,
420 .open = proc_reg_open,
421 .release = proc_reg_release,
422};
423
David Miller778f3dd2007-07-27 22:58:37 -0700424#ifdef CONFIG_COMPAT
425static const struct file_operations proc_reg_file_ops_no_compat = {
426 .llseek = proc_reg_llseek,
427 .read = proc_reg_read,
428 .write = proc_reg_write,
429 .poll = proc_reg_poll,
430 .unlocked_ioctl = proc_reg_unlocked_ioctl,
431 .mmap = proc_reg_mmap,
432 .open = proc_reg_open,
433 .release = proc_reg_release,
434};
435#endif
436
Alexey Dobriyan6d1b6e42011-01-12 17:00:33 -0800437struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 struct inode * inode;
440
Alexey Dobriyan6d1b6e42011-01-12 17:00:33 -0800441 inode = iget_locked(sb, de->low_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (!inode)
Alexey Dobriyan99b76232009-03-25 22:48:06 +0300443 return NULL;
David Howellsa1d4aeb2008-02-07 00:15:45 -0800444 if (inode->i_state & I_NEW) {
445 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
446 PROC_I(inode)->fd = 0;
447 PROC_I(inode)->pde = de;
Alexey Dobriyan5e971dc2008-04-29 01:01:41 -0700448
449 if (de->mode) {
450 inode->i_mode = de->mode;
451 inode->i_uid = de->uid;
452 inode->i_gid = de->gid;
453 }
454 if (de->size)
455 inode->i_size = de->size;
456 if (de->nlink)
Miklos Szeredibfe86842011-10-28 14:13:29 +0200457 set_nlink(inode, de->nlink);
Alexey Dobriyan5e971dc2008-04-29 01:01:41 -0700458 if (de->proc_iops)
459 inode->i_op = de->proc_iops;
460 if (de->proc_fops) {
461 if (S_ISREG(inode->i_mode)) {
David Howellsa1d4aeb2008-02-07 00:15:45 -0800462#ifdef CONFIG_COMPAT
Alexey Dobriyan5e971dc2008-04-29 01:01:41 -0700463 if (!de->proc_fops->compat_ioctl)
464 inode->i_fop =
465 &proc_reg_file_ops_no_compat;
466 else
David Howellsa1d4aeb2008-02-07 00:15:45 -0800467#endif
Alexey Dobriyan5e971dc2008-04-29 01:01:41 -0700468 inode->i_fop = &proc_reg_file_ops;
469 } else {
470 inode->i_fop = de->proc_fops;
David Howellsa1d4aeb2008-02-07 00:15:45 -0800471 }
Alexey Dobriyan786d7e12007-07-15 23:39:00 -0700472 }
David Howellsa1d4aeb2008-02-07 00:15:45 -0800473 unlock_new_inode(inode);
Alexey Dobriyan99b76232009-03-25 22:48:06 +0300474 } else
Alexey Dobriyan135d5652009-12-15 16:45:39 -0800475 pde_put(de);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Pavel Emelyanov07543f52007-10-18 23:40:08 -0700479int proc_fill_super(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 struct inode * root_inode;
482
Linus Torvalds92d03282006-07-15 12:20:05 -0700483 s->s_flags |= MS_NODIRATIME | MS_NOSUID | MS_NOEXEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 s->s_blocksize = 1024;
485 s->s_blocksize_bits = 10;
486 s->s_magic = PROC_SUPER_MAGIC;
487 s->s_op = &proc_sops;
488 s->s_time_gran = 1;
489
Alexey Dobriyan135d5652009-12-15 16:45:39 -0800490 pde_get(&proc_root);
Alexey Dobriyan6d1b6e42011-01-12 17:00:33 -0800491 root_inode = proc_get_inode(s, &proc_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!root_inode)
493 goto out_no_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 root_inode->i_uid = 0;
495 root_inode->i_gid = 0;
496 s->s_root = d_alloc_root(root_inode);
497 if (!s->s_root)
498 goto out_no_root;
499 return 0;
500
501out_no_root:
502 printk("proc_read_super: get root inode failed\n");
503 iput(root_inode);
Alexey Dobriyan135d5652009-12-15 16:45:39 -0800504 pde_put(&proc_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 return -ENOMEM;
506}