linux-old/fs/proc/root.c
<<
>>
Prefs
   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
  20struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
  21
  22#ifdef CONFIG_SYSCTL
  23struct proc_dir_entry *proc_sys_root;
  24#endif
  25
  26static DECLARE_FSTYPE(proc_fs_type, "proc", proc_read_super, FS_SINGLE);
  27
  28void __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        proc_net_stat = proc_mkdir("net/stat", NULL);
  42
  43#ifdef CONFIG_SYSVIPC
  44        proc_mkdir("sysvipc", 0);
  45#endif
  46#ifdef CONFIG_SYSCTL
  47        proc_sys_root = proc_mkdir("sys", 0);
  48#endif
  49#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  50        proc_mkdir("sys/fs", 0);
  51        proc_mkdir("sys/fs/binfmt_misc", 0);
  52#endif
  53        proc_root_fs = proc_mkdir("fs", 0);
  54        proc_root_driver = proc_mkdir("driver", 0);
  55#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
  56        /* just give it a mountpoint */
  57        proc_mkdir("openprom", 0);
  58#endif
  59        proc_tty_init();
  60#ifdef CONFIG_PROC_DEVICETREE
  61        proc_device_tree_init();
  62#endif
  63#ifdef CONFIG_PPC_ISERIES
  64        iSeries_proc_create();
  65#endif
  66#ifdef CONFIG_PPC64
  67        proc_ppc64_init(); 
  68#endif
  69#ifdef CONFIG_PPC_RTAS
  70        proc_rtas_init();
  71#endif
  72        proc_bus = proc_mkdir("bus", 0);
  73}
  74
  75static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
  76{
  77        if (dir->i_ino == PROC_ROOT_INO) { /* check for safety... */
  78                int nlink = proc_root.nlink;
  79
  80                nlink += nr_threads;
  81
  82                dir->i_nlink = nlink;
  83        }
  84
  85        if (!proc_lookup(dir, dentry))
  86                return NULL;
  87        
  88        return proc_pid_lookup(dir, dentry);
  89}
  90
  91static int proc_root_readdir(struct file * filp,
  92        void * dirent, filldir_t filldir)
  93{
  94        unsigned int nr = filp->f_pos;
  95
  96        if (nr < FIRST_PROCESS_ENTRY) {
  97                int error = proc_readdir(filp, dirent, filldir);
  98                if (error <= 0)
  99                        return error;
 100                filp->f_pos = FIRST_PROCESS_ENTRY;
 101        }
 102
 103        return proc_pid_readdir(filp, dirent, filldir);
 104}
 105
 106/*
 107 * The root /proc directory is special, as it has the
 108 * <pid> directories. Thus we don't use the generic
 109 * directory handling functions for that..
 110 */
 111static struct file_operations proc_root_operations = {
 112        read:            generic_read_dir,
 113        readdir:         proc_root_readdir,
 114};
 115
 116/*
 117 * proc root can do almost nothing..
 118 */
 119static struct inode_operations proc_root_inode_operations = {
 120        lookup:         proc_root_lookup,
 121};
 122
 123/*
 124 * This is the root "inode" in the /proc tree..
 125 */
 126struct proc_dir_entry proc_root = {
 127        low_ino:        PROC_ROOT_INO, 
 128        namelen:        5, 
 129        name:           "/proc",
 130        mode:           S_IFDIR | S_IRUGO | S_IXUGO, 
 131        nlink:          2, 
 132        proc_iops:      &proc_root_inode_operations, 
 133        proc_fops:      &proc_root_operations,
 134        parent:         &proc_root,
 135};
 136
 137#ifdef CONFIG_SYSCTL
 138EXPORT_SYMBOL(proc_sys_root);
 139#endif
 140EXPORT_SYMBOL(proc_symlink);
 141EXPORT_SYMBOL(proc_mknod);
 142EXPORT_SYMBOL(proc_mkdir);
 143EXPORT_SYMBOL(create_proc_entry);
 144EXPORT_SYMBOL(remove_proc_entry);
 145EXPORT_SYMBOL(proc_root);
 146EXPORT_SYMBOL(proc_root_fs);
 147EXPORT_SYMBOL(proc_net);
 148EXPORT_SYMBOL(proc_net_stat);
 149EXPORT_SYMBOL(proc_bus);
 150EXPORT_SYMBOL(proc_root_driver);
 151
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.