root.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * linux/fs/proc/root.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * proc root directory handling functions
  7. */
  8. #include <asm/uaccess.h>
  9. #include <linux/errno.h>
  10. #include <linux/time.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/stat.h>
  13. #include <linux/config.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/bitops.h>
  17. #include <linux/smp_lock.h>
  18. #include "internal.h"
  19. struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
  20. #ifdef CONFIG_SYSCTL
  21. struct proc_dir_entry *proc_sys_root;
  22. #endif
  23. static struct super_block *proc_get_sb(struct file_system_type *fs_type,
  24. int flags, const char *dev_name, void *data)
  25. {
  26. return get_sb_single(fs_type, flags, data, proc_fill_super);
  27. }
  28. static struct file_system_type proc_fs_type = {
  29. .name = "proc",
  30. .get_sb = proc_get_sb,
  31. .kill_sb = kill_anon_super,
  32. };
  33. void __init proc_root_init(void)
  34. {
  35. int err = proc_init_inodecache();
  36. if (err)
  37. return;
  38. err = register_filesystem(&proc_fs_type);
  39. if (err)
  40. return;
  41. proc_mnt = kern_mount(&proc_fs_type);
  42. err = PTR_ERR(proc_mnt);
  43. if (IS_ERR(proc_mnt)) {
  44. unregister_filesystem(&proc_fs_type);
  45. return;
  46. }
  47. proc_misc_init();
  48. proc_net = proc_mkdir("net", NULL);
  49. proc_net_stat = proc_mkdir("net/stat", NULL);
  50. #ifdef CONFIG_SYSVIPC
  51. proc_mkdir("sysvipc", NULL);
  52. #endif
  53. #ifdef CONFIG_SYSCTL
  54. proc_sys_root = proc_mkdir("sys", NULL);
  55. #endif
  56. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  57. proc_mkdir("sys/fs", NULL);
  58. proc_mkdir("sys/fs/binfmt_misc", NULL);
  59. #endif
  60. proc_root_fs = proc_mkdir("fs", NULL);
  61. proc_root_driver = proc_mkdir("driver", NULL);
  62. proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */
  63. #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
  64. /* just give it a mountpoint */
  65. proc_mkdir("openprom", NULL);
  66. #endif
  67. proc_tty_init();
  68. #ifdef CONFIG_PROC_DEVICETREE
  69. proc_device_tree_init();
  70. #endif
  71. proc_bus = proc_mkdir("bus", NULL);
  72. }
  73. static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
  74. )
  75. {
  76. generic_fillattr(dentry->d_inode, stat);
  77. stat->nlink = proc_root.nlink + nr_processes();
  78. return 0;
  79. }
  80. static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd)
  81. {
  82. if (!proc_lookup(dir, dentry, nd)) {
  83. return NULL;
  84. }
  85. return proc_pid_lookup(dir, dentry, nd);
  86. }
  87. static int proc_root_readdir(struct file * filp,
  88. void * dirent, filldir_t filldir)
  89. {
  90. unsigned int nr = filp->f_pos;
  91. int ret;
  92. lock_kernel();
  93. if (nr < FIRST_PROCESS_ENTRY) {
  94. int error = proc_readdir(filp, dirent, filldir);
  95. if (error <= 0) {
  96. unlock_kernel();
  97. return error;
  98. }
  99. filp->f_pos = FIRST_PROCESS_ENTRY;
  100. }
  101. unlock_kernel();
  102. ret = proc_pid_readdir(filp, dirent, filldir);
  103. return ret;
  104. }
  105. /*
  106. * The root /proc directory is special, as it has the
  107. * <pid> directories. Thus we don't use the generic
  108. * directory handling functions for that..
  109. */
  110. static struct file_operations proc_root_operations = {
  111. .read = generic_read_dir,
  112. .readdir = proc_root_readdir,
  113. };
  114. /*
  115. * proc root can do almost nothing..
  116. */
  117. static struct inode_operations proc_root_inode_operations = {
  118. .lookup = proc_root_lookup,
  119. .getattr = proc_root_getattr,
  120. };
  121. /*
  122. * This is the root "inode" in the /proc tree..
  123. */
  124. struct proc_dir_entry proc_root = {
  125. .low_ino = PROC_ROOT_INO,
  126. .namelen = 5,
  127. .name = "/proc",
  128. .mode = S_IFDIR | S_IRUGO | S_IXUGO,
  129. .nlink = 2,
  130. .proc_iops = &proc_root_inode_operations,
  131. .proc_fops = &proc_root_operations,
  132. .parent = &proc_root,
  133. };
  134. EXPORT_SYMBOL(proc_symlink);
  135. EXPORT_SYMBOL(proc_mkdir);
  136. EXPORT_SYMBOL(create_proc_entry);
  137. EXPORT_SYMBOL(remove_proc_entry);
  138. EXPORT_SYMBOL(proc_root);
  139. EXPORT_SYMBOL(proc_root_fs);
  140. EXPORT_SYMBOL(proc_net);
  141. EXPORT_SYMBOL(proc_net_stat);
  142. EXPORT_SYMBOL(proc_bus);
  143. EXPORT_SYMBOL(proc_root_driver);