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 = inode->i_blksize = 0;
  88         ino = inode->i_ino;
  89         pid = ino >> 16;
  90         p = task[0];
  91         for (i = 0; i < NR_TASKS ; i++)
  92                 if ((p = task[i]) && (p->pid == pid))
  93                         break;
  94         if (!p || i >= NR_TASKS)
  95                 return;
  96         if (ino == PROC_ROOT_INO) {
  97                 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
  98                 inode->i_nlink = 2;
  99                 for (i = 1 ; i < NR_TASKS ; i++)
 100                         if (task[i])
 101                                 inode->i_nlink++;
 102                 inode->i_op = &proc_root_inode_operations;
 103                 return;
 104         }
 105         if ((ino >= 128) && (ino <= 160)) { /* files within /proc/net */
 106                 inode->i_mode = S_IFREG | S_IRUGO;
 107                 inode->i_op = &proc_net_inode_operations;
 108                 return;
 109         }
 110         if (!pid) {
 111                 switch (ino) {
 112                         case 5:
 113                                 inode->i_mode = S_IFREG | S_IRUGO;
 114                                 inode->i_op = &proc_kmsg_inode_operations;
 115                                 break;
 116                         case 8: /* for the net directory */
 117                                 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
 118                                 inode->i_nlink = 2;
 119                                 inode->i_op = &proc_net_inode_operations;
 120                                 break;
 121                         case 14:
 122                                 inode->i_mode = S_IFREG | S_IRUSR;
 123                                 inode->i_op = &proc_array_inode_operations;
 124                                 inode->i_size = high_memory + PAGE_SIZE;
 125                                 break;
 126                         default:
 127                                 inode->i_mode = S_IFREG | S_IRUGO;
 128                                 inode->i_op = &proc_array_inode_operations;
 129                                 break;
 130                 }
 131                 return;
 132         }
 133         ino &= 0x0000ffff;
 134         inode->i_uid = p->euid;
 135         inode->i_gid = p->egid;
 136         switch (ino) {
 137                 case 2:
 138                         inode->i_nlink = 4;
 139                         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
 140                         inode->i_op = &proc_base_inode_operations;
 141                         return;
 142                 case 3:
 143                         inode->i_op = &proc_mem_inode_operations;
 144                         inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
 145                         return;
 146                 case 4:
 147                 case 5:
 148                 case 6:
 149                         inode->i_op = &proc_link_inode_operations;
 150                         inode->i_size = 64;
 151                         inode->i_mode = S_IFLNK | S_IRWXU;
 152                         return;
 153                 case 7:
 154                 case 8:
 155                         inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
 156                         inode->i_op = &proc_fd_inode_operations;
 157                         inode->i_nlink = 2;
 158                         return;
 159                 case 9:
 160                 case 10:
 161                 case 11:
 162                 case 12:
 163                 case 15:
 164                         inode->i_mode = S_IFREG | S_IRUGO;
 165                         inode->i_op = &proc_array_inode_operations;
 166                         return;
 167         }
 168         switch (ino >> 8) {
 169                 case 1:
 170                         ino &= 0xff;
 171                         if (ino >= NR_OPEN || !p->filp[ino])
 172                                 return;
 173                         inode->i_op = &proc_link_inode_operations;
 174                         inode->i_size = 64;
 175                         inode->i_mode = S_IFLNK | S_IRWXU;
 176                         return;
 177                 case 2:
 178                         ino &= 0xff;
 179                         {
 180                                 int j = 0;
 181                                 struct vm_area_struct * mpnt;
 182                                 for (mpnt = p->mmap ; mpnt ; mpnt = mpnt->vm_next)
 183                                         if(mpnt->vm_inode)
 184                                                 j++;
 185                                 if (ino >= j)
 186                                         return;
 187                         }
 188                         inode->i_op = &proc_link_inode_operations;
 189                         inode->i_size = 64;
 190                         inode->i_mode = S_IFLNK | S_IRWXU;
 191                         return;
 192         }
 193         return;
 194 }
 195 
 196 void proc_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 197 {
 198         inode->i_dirt=0;
 199 }

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