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 };
  42 
  43 struct super_block *proc_read_super(struct super_block *s,void *data)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45         lock_super(s);
  46         s->s_blocksize = 1024;
  47         s->s_magic = PROC_SUPER_MAGIC;
  48         s->s_op = &proc_sops;
  49         unlock_super(s);
  50         if (!(s->s_mounted = iget(s,PROC_ROOT_INO))) {
  51                 s->s_dev = 0;
  52                 printk("get root inode failed\n");
  53                 return NULL;
  54         }
  55         return s;
  56 }
  57 
  58 void proc_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         put_fs_long(PROC_SUPER_MAGIC, &buf->f_type);
  61         put_fs_long(1024, &buf->f_bsize);
  62         put_fs_long(0, &buf->f_blocks);
  63         put_fs_long(0, &buf->f_bfree);
  64         put_fs_long(0, &buf->f_bavail);
  65         put_fs_long(0, &buf->f_files);
  66         put_fs_long(0, &buf->f_ffree);
  67         /* Don't know what value to put in buf->f_fsid */
  68 }
  69 
  70 void proc_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72         unsigned long ino, pid;
  73         struct task_struct * p;
  74         int i;
  75         
  76         inode->i_op = NULL;
  77         inode->i_mode = 0;
  78         inode->i_uid = 0;
  79         inode->i_gid = 0;
  80         inode->i_nlink = 1;
  81         inode->i_size = 0;
  82         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  83         inode->i_blocks = inode->i_blksize = 0;
  84         ino = inode->i_ino;
  85         pid = ino >> 16;
  86         p = task[0];
  87         for (i = 0; i < NR_TASKS ; i++)
  88                 if ((p = task[i]) && (p->pid == pid))
  89                         break;
  90         if (!p || i >= NR_TASKS)
  91                 return;
  92         if (ino == PROC_ROOT_INO) {
  93                 inode->i_mode = S_IFDIR | 0555;
  94                 inode->i_nlink = 2;
  95                 for (i = 1 ; i < NR_TASKS ; i++)
  96                         if (task[i])
  97                                 inode->i_nlink++;
  98                 inode->i_op = &proc_root_inode_operations;
  99                 return;
 100         }
 101         if (!pid) {
 102                 inode->i_mode = S_IFREG | 0444;
 103                 inode->i_op = &proc_array_inode_operations;
 104                 if (ino == 5)
 105                         inode->i_op = &proc_kmsg_inode_operations;
 106                 return;
 107         }
 108         ino &= 0x0000ffff;
 109         inode->i_uid = p->euid;
 110         inode->i_gid = p->egid;
 111         switch (ino) {
 112                 case 2:
 113                         inode->i_nlink = 4;
 114                         inode->i_mode = S_IFDIR | 0555;
 115                         inode->i_op = &proc_base_inode_operations;
 116                         return;
 117                 case 3:
 118                         inode->i_op = &proc_mem_inode_operations;
 119                         inode->i_mode = S_IFCHR | 0600;
 120                         inode->i_rdev = 0x0101;
 121                         return;
 122                 case 4:
 123                 case 5:
 124                 case 6:
 125                         inode->i_op = &proc_link_inode_operations;
 126                         inode->i_size = 64;
 127                         inode->i_mode = S_IFLNK | 0700;
 128                         return;
 129                 case 7:
 130                 case 8:
 131                         inode->i_mode = S_IFDIR | 0500;
 132                         inode->i_op = &proc_fd_inode_operations;
 133                         inode->i_nlink = 2;
 134                         return;
 135                 case 9:
 136                 case 10:
 137                 case 11:
 138                 case 12:
 139                         inode->i_mode = S_IFREG | 0444;
 140                         inode->i_op = &proc_array_inode_operations;
 141                         return;
 142         }
 143         switch (ino >> 8) {
 144                 case 1:
 145                         ino &= 0xff;
 146                         if (ino >= NR_OPEN || !p->filp[ino])
 147                                 return;
 148                         inode->i_op = &proc_link_inode_operations;
 149                         inode->i_size = 64;
 150                         inode->i_mode = S_IFLNK | 0700;
 151                         return;
 152                 case 2:
 153                         ino &= 0xff;
 154                         if (ino >= p->numlibraries)
 155                                 return;
 156                         inode->i_op = &proc_link_inode_operations;
 157                         inode->i_size = 64;
 158                         inode->i_mode = S_IFLNK | 0700;
 159                         return;
 160         }
 161         return;
 162 }
 163 
 164 void proc_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         inode->i_dirt=0;
 167 }

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