root/fs/proc/inode.c

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

DEFINITIONS

This source file includes following definitions.
  1. proc_put_inode
  2. proc_put_super
  3. proc_read_super
  4. proc_statfs
  5. proc_read_inode
  6. proc_write_inode

   1 /*
   2  *  linux/fs/proc/inode.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/sched.h>
   8 #include <linux/proc_fs.h>
   9 #include <linux/kernel.h>
  10 #include <linux/mm.h>
  11 #include <linux/string.h>
  12 #include <linux/stat.h>
  13 #include <linux/locks.h>
  14 #include <linux/limits.h>
  15 
  16 #include <asm/system.h>
  17 #include <asm/segment.h>
  18 
  19 void proc_put_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21         if (inode->i_nlink)
  22                 return;
  23         inode->i_size = 0;
  24 }
  25 
  26 void proc_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28         lock_super(sb);
  29         sb->s_dev = 0;
  30         unlock_super(sb);
  31 }
  32 
  33 static struct super_operations proc_sops = { 
  34         proc_read_inode,
  35         NULL,
  36         proc_write_inode,
  37         proc_put_inode,
  38         proc_put_super,
  39         NULL,
  40         proc_statfs,
  41         NULL
  42 };
  43 
  44 struct super_block *proc_read_super(struct super_block *s,void *data, 
     /* [previous][next][first][last][top][bottom][index][help] */
  45                                     int silent)
  46 {
  47         lock_super(s);
  48         s->s_blocksize = 1024;
  49         s->s_blocksize_bits = 10;
  50         s->s_magic = PROC_SUPER_MAGIC;
  51         s->s_op = &proc_sops;
  52         unlock_super(s);
  53         if (!(s->s_mounted = iget(s,PROC_ROOT_INO))) {
  54                 s->s_dev = 0;
  55                 printk("get root inode failed\n");
  56                 return NULL;
  57         }
  58         return s;
  59 }
  60 
  61 void proc_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
  62 {
  63         put_fs_long(PROC_SUPER_MAGIC, &buf->f_type);
  64         put_fs_long(PAGE_SIZE/sizeof(long), &buf->f_bsize);
  65         put_fs_long(0, &buf->f_blocks);
  66         put_fs_long(0, &buf->f_bfree);
  67         put_fs_long(0, &buf->f_bavail);
  68         put_fs_long(0, &buf->f_files);
  69         put_fs_long(0, &buf->f_ffree);
  70         put_fs_long(NAME_MAX, &buf->f_namelen);
  71         /* Don't know what value to put in buf->f_fsid */
  72 }
  73 
  74 void proc_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         unsigned long ino, pid;
  77         struct task_struct * p;
  78         int i;
  79         
  80         inode->i_op = NULL;
  81         inode->i_mode = 0;
  82         inode->i_uid = 0;
  83         inode->i_gid = 0;
  84         inode->i_nlink = 1;
  85         inode->i_size = 0;
  86         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  87         inode->i_blocks = 0;
  88         inode->i_blksize = 1024;
  89         ino = inode->i_ino;
  90         pid = ino >> 16;
  91         p = task[0];
  92         for (i = 0; i < NR_TASKS ; i++)
  93                 if ((p = task[i]) && (p->pid == pid))
  94                         break;
  95         if (!p || i >= NR_TASKS)
  96                 return;
  97         if (ino == PROC_ROOT_INO) {
  98                 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
  99                 inode->i_nlink = 2;
 100                 for (i = 1 ; i < NR_TASKS ; i++)
 101                         if (task[i])
 102                                 inode->i_nlink++;
 103                 inode->i_op = &proc_root_inode_operations;
 104                 return;
 105         }
 106 
 107         /* files within /proc/net */
 108         if ((ino >= PROC_NET_UNIX) && (ino < PROC_NET_LAST)) {
 109                 inode->i_mode = S_IFREG | S_IRUGO;
 110                 inode->i_op = &proc_net_inode_operations;
 111                 return;
 112         }
 113 
 114         if (!pid) {
 115                 switch (ino) {
 116                         case PROC_KMSG:
 117                                 inode->i_mode = S_IFREG | S_IRUGO;
 118                                 inode->i_op = &proc_kmsg_inode_operations;
 119                                 break;
 120                         case PROC_NET:
 121                                 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
 122                                 inode->i_nlink = 2;
 123                                 inode->i_op = &proc_net_inode_operations;
 124                                 break;
 125                         case PROC_KCORE:
 126                                 inode->i_mode = S_IFREG | S_IRUSR;
 127                                 inode->i_op = &proc_kcore_inode_operations;
 128                                 inode->i_size = high_memory + PAGE_SIZE;
 129                                 break;
 130                         default:
 131                                 inode->i_mode = S_IFREG | S_IRUGO;
 132                                 inode->i_op = &proc_array_inode_operations;
 133                                 break;
 134                 }
 135                 return;
 136         }
 137         ino &= 0x0000ffff;
 138         inode->i_uid = p->euid;
 139         inode->i_gid = p->egid;
 140         switch (ino) {
 141                 case PROC_PID_INO:
 142                         inode->i_nlink = 4;
 143                         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
 144                         inode->i_op = &proc_base_inode_operations;
 145                         return;
 146                 case PROC_PID_MEM:
 147                         inode->i_op = &proc_mem_inode_operations;
 148                         inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
 149                         return;
 150                 case PROC_PID_CWD:
 151                 case PROC_PID_ROOT:
 152                 case PROC_PID_EXE:
 153                         inode->i_op = &proc_link_inode_operations;
 154                         inode->i_size = 64;
 155                         inode->i_mode = S_IFLNK | S_IRWXU;
 156                         return;
 157                 case PROC_PID_FD:
 158                         inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
 159                         inode->i_op = &proc_fd_inode_operations;
 160                         inode->i_nlink = 2;
 161                         return;
 162                 case PROC_PID_ENVIRON:
 163                 case PROC_PID_CMDLINE:
 164                 case PROC_PID_STAT:
 165                 case PROC_PID_STATM:
 166                 case PROC_PID_MAPS:
 167                         inode->i_mode = S_IFREG | S_IRUGO;
 168                         inode->i_op = &proc_array_inode_operations;
 169                         return;
 170         }
 171         switch (ino >> 8) {
 172                 case PROC_PID_FD_DIR:
 173                         ino &= 0xff;
 174                         if (ino >= NR_OPEN || !p->files->fd[ino])
 175                                 return;
 176                         inode->i_op = &proc_link_inode_operations;
 177                         inode->i_size = 64;
 178                         inode->i_mode = S_IFLNK | S_IRWXU;
 179                         return;
 180         }
 181         return;
 182 }
 183 
 184 void proc_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 185 {
 186         inode->i_dirt=0;
 187 }

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