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

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