root.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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