root/fs/proc/root.c

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

DEFINITIONS

This source file includes following definitions.
  1. proc_lookuproot
  2. proc_readroot

   1 /*
   2  *  linux/fs/proc/root.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  proc root directory handling functions
   7  */
   8 
   9 #include <asm/segment.h>
  10 
  11 #include <linux/errno.h>
  12 #include <linux/sched.h>
  13 #include <linux/proc_fs.h>
  14 #include <linux/stat.h>
  15 
  16 static int proc_readroot(struct inode *, struct file *, struct dirent *, int);
  17 static int proc_lookuproot(struct inode *,const char *,int,struct inode **);
  18 
  19 static struct file_operations proc_root_operations = {
  20         NULL,                   /* lseek - default */
  21         NULL,                   /* read - bad */
  22         NULL,                   /* write - bad */
  23         proc_readroot,          /* readdir */
  24         NULL,                   /* select - default */
  25         NULL,                   /* ioctl - default */
  26         NULL,                   /* mmap */
  27         NULL,                   /* no special open code */
  28         NULL                    /* no special release code */
  29 };
  30 
  31 /*
  32  * proc directories can do almost nothing..
  33  */
  34 struct inode_operations proc_root_inode_operations = {
  35         &proc_root_operations,  /* default base directory file-ops */
  36         NULL,                   /* create */
  37         proc_lookuproot,        /* lookup */
  38         NULL,                   /* link */
  39         NULL,                   /* unlink */
  40         NULL,                   /* symlink */
  41         NULL,                   /* mkdir */
  42         NULL,                   /* rmdir */
  43         NULL,                   /* mknod */
  44         NULL,                   /* rename */
  45         NULL,                   /* readlink */
  46         NULL,                   /* follow_link */
  47         NULL,                   /* bmap */
  48         NULL                    /* truncate */
  49 };
  50 
  51 static int proc_lookuproot(struct inode * dir,const char * name, int len,
     /* [previous][next][first][last][top][bottom][index][help] */
  52         struct inode ** result)
  53 {
  54         unsigned int pid, c;
  55         int i, ino;
  56 
  57         *result = NULL;
  58         if (!dir)
  59                 return -ENOENT;
  60         if (!S_ISDIR(dir->i_mode)) {
  61                 iput(dir);
  62                 return -ENOENT;
  63         }
  64         pid = 0;
  65         if (!len || (get_fs_byte(name) == '.' && (len == 1 ||
  66             (get_fs_byte(name+1) == '.' && len == 2)))) {
  67                 *result = dir;
  68                 return 0;
  69         }
  70         while (len-- > 0) {
  71                 c = get_fs_byte(name) - '0';
  72                 name++;
  73                 if (c > 9) {
  74                         pid = 0;
  75                         break;
  76                 }
  77                 pid *= 10;
  78                 pid += c;
  79                 if (pid & 0xffff0000) {
  80                         pid = 0;
  81                         break;
  82                 }
  83         }
  84         for (i = 0 ; i < NR_TASKS ; i++)
  85                 if (task[i] && task[i]->pid == pid)
  86                         break;
  87         if (!pid || i >= NR_TASKS) {
  88                 iput(dir);
  89                 return -ENOENT;
  90         }
  91         ino = (pid << 16) + 2;
  92         if (!(*result = iget(dir->i_sb,ino))) {
  93                 iput(dir);
  94                 return -ENOENT;
  95         }
  96         iput(dir);
  97         return 0;
  98 }
  99 
 100 static int proc_readroot(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
 101         struct dirent * dirent, int count)
 102 {
 103         struct task_struct * p;
 104         unsigned int pid;
 105         int i,j;
 106 
 107         if (!inode || !S_ISDIR(inode->i_mode))
 108                 return -EBADF;
 109         while ((pid = filp->f_pos) < NR_TASKS+2) {
 110                 filp->f_pos++;
 111                 if (pid < 2) {
 112                         i = j = pid+1;
 113                         put_fs_long(1, &dirent->d_ino);
 114                         put_fs_word(i, &dirent->d_reclen);
 115                         put_fs_byte(0, i+dirent->d_name);
 116                         while (i--)
 117                                 put_fs_byte('.', i+dirent->d_name);
 118                         return j;
 119                 }                       
 120                 p = task[pid-2];
 121                 if (!p || !(pid = p->pid))
 122                         continue;
 123                 if (pid & 0xffff0000)
 124                         continue;
 125                 j = 10;
 126                 i = 1;
 127                 while (pid >= j) {
 128                         j *= 10;
 129                         i++;
 130                 }
 131                 j = i;
 132                 put_fs_long((pid << 16)+2, &dirent->d_ino);
 133                 put_fs_word(i, &dirent->d_reclen);
 134                 put_fs_byte(0, i+dirent->d_name);
 135                 while (i--) {
 136                         put_fs_byte('0'+(pid % 10), i+dirent->d_name);
 137                         pid /= 10;
 138                 }
 139                 return j;
 140         }
 141         return 0;
 142 }

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