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

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