root/fs/proc/base.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. proc_pid_fill_inode
  2. proc_base_init

   1 /*
   2  *  linux/fs/proc/base.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  proc base directory handling functions
   7  */
   8 
   9 #include <asm/segment.h>
  10 
  11 #include <linux/errno.h>
  12 #include <linux/sched.h>
  13 #include <linux/proc_fs.h>
  14 #include <linux/stat.h>
  15 
  16 static struct file_operations proc_base_operations = {
  17         NULL,                   /* lseek - default */
  18         NULL,                   /* read - bad */
  19         NULL,                   /* write - bad */
  20         proc_readdir,           /* readdir */
  21         NULL,                   /* select - default */
  22         NULL,                   /* ioctl - default */
  23         NULL,                   /* mmap */
  24         NULL,                   /* no special open code */
  25         NULL,                   /* no special release code */
  26         NULL                    /* can't fsync */
  27 };
  28 
  29 /*
  30  * proc directories can do almost nothing..
  31  */
  32 static struct inode_operations proc_base_inode_operations = {
  33         &proc_base_operations,  /* default base directory file-ops */
  34         NULL,                   /* create */
  35         proc_lookup,            /* lookup */
  36         NULL,                   /* link */
  37         NULL,                   /* unlink */
  38         NULL,                   /* symlink */
  39         NULL,                   /* mkdir */
  40         NULL,                   /* rmdir */
  41         NULL,                   /* mknod */
  42         NULL,                   /* rename */
  43         NULL,                   /* readlink */
  44         NULL,                   /* follow_link */
  45         NULL,                   /* readpage */
  46         NULL,                   /* writepage */
  47         NULL,                   /* bmap */
  48         NULL,                   /* truncate */
  49         NULL                    /* permission */
  50 };
  51 
  52 static void proc_pid_fill_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  53 {
  54         struct task_struct * p;
  55         int pid = inode->i_ino >> 16;
  56         int ino = inode->i_ino & 0xffff;
  57 
  58         for_each_task(p) {
  59                 if (p->pid == pid) {
  60                         if (p->dumpable || ino == PROC_PID_INO) {
  61                                 inode->i_uid = p->euid;
  62                                 inode->i_gid = p->gid;
  63                         }
  64                         return;
  65                 }
  66         }
  67 }
  68 
  69 /*
  70  * This is really a pseudo-entry, and only links
  71  * backwards to the parent with no link from the
  72  * root directory to this. This way we can have just
  73  * one entry for every /proc/<pid>/ directory.
  74  */
  75 struct proc_dir_entry proc_pid = {
  76         PROC_PID_INO, 5, "<pid>",
  77         S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
  78         0, &proc_base_inode_operations,
  79         NULL, proc_pid_fill_inode,
  80         NULL, &proc_root, NULL
  81 };
  82 
  83 void proc_base_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  84 {
  85         proc_register(&proc_pid, &(struct proc_dir_entry) {
  86                 PROC_PID_STATUS, 6, "status",
  87                 S_IFREG | S_IRUGO, 1, 0, 0,
  88                 0, &proc_array_inode_operations,
  89                 NULL, proc_pid_fill_inode,
  90         });
  91         proc_register(&proc_pid, &(struct proc_dir_entry) {
  92                 PROC_PID_MEM, 3, "mem",
  93                 S_IFREG | S_IRUSR | S_IWUSR, 1, 0, 0,
  94                 0, &proc_mem_inode_operations,
  95                 NULL, proc_pid_fill_inode,
  96         });
  97         proc_register(&proc_pid, &(struct proc_dir_entry) {
  98                 PROC_PID_CWD, 3, "cwd",
  99                 S_IFLNK | S_IRWXU, 1, 0, 0,
 100                 0, &proc_link_inode_operations,
 101                 NULL, proc_pid_fill_inode,
 102         });
 103         proc_register(&proc_pid, &(struct proc_dir_entry) {
 104                 PROC_PID_ROOT, 4, "root",
 105                 S_IFLNK | S_IRWXU, 1, 0, 0,
 106                 0, &proc_link_inode_operations,
 107                 NULL, proc_pid_fill_inode,
 108         });
 109         proc_register(&proc_pid, &(struct proc_dir_entry) {
 110                 PROC_PID_EXE, 3, "exe",
 111                 S_IFLNK | S_IRWXU, 1, 0, 0,
 112                 0, &proc_link_inode_operations,
 113                 NULL, proc_pid_fill_inode,
 114         });
 115         proc_register(&proc_pid, &(struct proc_dir_entry) {
 116                 PROC_PID_FD, 2, "fd",
 117                 S_IFDIR | S_IRUSR | S_IXUSR, 1, 0, 0,
 118                 0, &proc_fd_inode_operations,
 119                 NULL, proc_pid_fill_inode,
 120         });
 121         proc_register(&proc_pid, &(struct proc_dir_entry) {
 122                 PROC_PID_ENVIRON, 7, "environ",
 123                 S_IFREG | S_IRUSR, 1, 0, 0,
 124                 0, &proc_array_inode_operations,
 125                 NULL, proc_pid_fill_inode,
 126         });
 127         proc_register(&proc_pid, &(struct proc_dir_entry) {
 128                 PROC_PID_CMDLINE, 7, "cmdline",
 129                 S_IFREG | S_IRUGO, 1, 0, 0,
 130                 0, &proc_array_inode_operations,
 131                 NULL, proc_pid_fill_inode,
 132         });
 133         proc_register(&proc_pid, &(struct proc_dir_entry) {
 134                 PROC_PID_STAT, 4, "stat",
 135                 S_IFREG | S_IRUGO, 1, 0, 0,
 136                 0, &proc_array_inode_operations,
 137                 NULL, proc_pid_fill_inode,
 138         });
 139         proc_register(&proc_pid, &(struct proc_dir_entry) {
 140                 PROC_PID_STATM, 5, "statm",
 141                 S_IFREG | S_IRUGO, 1, 0, 0,
 142                 0, &proc_array_inode_operations,
 143                 NULL, proc_pid_fill_inode,
 144         });
 145         proc_register(&proc_pid, &(struct proc_dir_entry) {
 146                 PROC_PID_MAPS, 4, "maps",
 147                 S_IFIFO | S_IRUGO, 1, 0, 0,
 148                 0, &proc_arraylong_inode_operations,
 149                 NULL, proc_pid_fill_inode,
 150         });
 151 };

/* [previous][next][first][last][top][bottom][index][help] */