Fork me on GitHub

root/fs/procfs/tree.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_procfs_by_inode

   1 /*
   2  * fiwix/fs/procfs/tree.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/stat.h>
  10 #include <fiwix/fs.h>
  11 #include <fiwix/fs_proc.h>
  12 #include <fiwix/errno.h>
  13 #include <fiwix/stdio.h>
  14 #include <fiwix/string.h>
  15 
  16 #define DIR     S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | \
  17                 S_IXOTH                                 /* dr-xr-xr-x */
  18 #define REG     S_IFREG | S_IRUSR | S_IRGRP | S_IROTH   /* -r--r--r-- */
  19 #define REGUSR  S_IFREG | S_IRUSR                       /* -r-------- */
  20 #define LNK     S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO   /* lrwxrwxrwx */
  21 #define LNKPID  S_IFLNK | S_IRWXU                       /* lrwx------ */
  22 
  23 /*
  24  * WARNING: every time a new entry is added to this array you must also change
  25  * the PROC_ARRAY_ENTRIES value defined in fs_proc.h.
  26  */
  27 struct procfs_dir_entry procfs_array[][PROC_ARRAY_ENTRIES + 1] = {
  28    {    /* [0] / */
  29         { 1,     DIR,  2, 0, 1,  ".",            NULL },
  30         { 2,     DIR,  2, 0, 2,  "..",           NULL },
  31         { 3,     DIR,  3, 3, 3,  "sys",          NULL },
  32         { 4,     REG,  1, 0, 7,  "cmdline",      data_proc_cmdline },
  33         { 5,     REG,  1, 0, 7,  "cpuinfo",      data_proc_cpuinfo },
  34         { 6,     REG,  1, 0, 7,  "devices",      data_proc_devices },
  35         { 7,     REG,  1, 0, 3,  "dma",          data_proc_dma },
  36         { 8,     REG,  1, 0, 11, "filesystems",  data_proc_filesystems },
  37         { 9,     REG,  1, 0, 10, "interrupts",   data_proc_interrupts },
  38         { 10,    REG,  1, 0, 7,  "loadavg",      data_proc_loadavg },
  39         { 11,    REG,  1, 0, 5,  "locks",        data_proc_locks },
  40         { 12,    REG,  1, 0, 7,  "meminfo",      data_proc_meminfo },
  41         { 13,    REG,  1, 0, 6,  "mounts",       data_proc_mounts },
  42         { 14,    REG,  1, 0, 10, "partitions",   data_proc_partitions },
  43         { 15,    REG,  1, 0, 3,  "rtc",          data_proc_rtc },
  44         { 16,    LNK,  1, 0, 4,  "self",         data_proc_self },
  45         { 17,    REG,  1, 0, 4,  "stat",         data_proc_stat },
  46         { 18,    REG,  1, 0, 6,  "uptime",       data_proc_uptime },
  47         { 19,    REG,  1, 0, 7,  "version",      data_proc_fullversion },
  48         { 0, 0, 0, 0, 0, NULL, NULL }
  49    },
  50    {    /* [1] /PID/ */
  51         { 1000,  DIR,  2, 1, 1,  ".",            NULL },
  52         { 1,     DIR,  2, 0, 2,  "..",           NULL },
  53 /*      { PROC_PID_FD,      DIR,    2, 2, 2,  "fd",       data_proc_pid_fd },*/
  54         { PROC_PID_CMDLINE, REG,    1, 1, 7,  "cmdline",  data_proc_pid_cmdline },
  55         { PROC_PID_CWD,     LNKPID, 1, 1, 3,  "cwd",      data_proc_pid_cwd },
  56         { PROC_PID_ENVIRON, REGUSR, 1, 1, 7,  "environ",  data_proc_pid_environ },
  57         { PROC_PID_EXE,     LNKPID, 1, 1, 3,  "exe",      data_proc_pid_exe },
  58         { PROC_PID_MAPS,    REG,    1, 1, 4,  "maps",     data_proc_pid_maps },
  59         { PROC_PID_MOUNTINFO,REG,   1, 1, 9,  "mountinfo",data_proc_pid_mountinfo },
  60         { PROC_PID_ROOT,    LNKPID, 1, 1, 4,  "root",     data_proc_pid_root },
  61         { PROC_PID_STAT,    REG,    1, 1, 4,  "stat",     data_proc_pid_stat },
  62         { PROC_PID_STATM,   REG,    1, 1, 5,  "statm",    data_proc_pid_statm },
  63         { PROC_PID_STATUS,  REG,    1, 1, 6,  "status",   data_proc_pid_status },
  64         { 0, 0, 0, 0, 0, NULL, NULL }
  65    },
  66 
  67    {
  68    },
  69 
  70    {    /* [3] /sys/ */
  71         { 3,     DIR,  2, 3, 1,  ".",            NULL },
  72         { 1,     DIR,  2, 0, 2,  "..",           NULL },
  73         { 2001,  DIR,  2, 4, 6,  "kernel",       NULL },
  74         { 0, 0, 0, 0, 0, NULL, NULL }
  75    },
  76    {    /* [4] /sys/kernel/ */
  77         { 2001,  DIR,  2, 4, 1,  ".",            NULL },
  78         { 3,     DIR,  2, 3, 2,  "..",           NULL },
  79         { 3001,  REG,  1, 4, 10, "domainname",   data_proc_domainname },
  80         { 3002,  REG,  1, 4, 8,  "file-max",     data_proc_filemax },
  81         { 3003,  REG,  1, 4, 7,  "file-nr",      data_proc_filenr },
  82         { 3004,  REG,  1, 4, 8,  "hostname",     data_proc_hostname },
  83         { 3005,  REG,  1, 4, 9,  "inode-max",    data_proc_inodemax },
  84         { 3006,  REG,  1, 4, 8,  "inode-nr",     data_proc_inodenr },
  85         { 3007,  REG,  1, 4, 9,  "osrelease",    data_proc_osrelease },
  86         { 3008,  REG,  1, 4, 6,  "ostype",       data_proc_ostype },
  87         { 3009,  REG,  1, 4, 7,  "version",      data_proc_version },
  88         { 0, 0, 0, 0, 0, NULL, NULL }
  89    }
  90 };
  91 
  92 struct procfs_dir_entry * get_procfs_by_inode(struct inode *i)
  93 {
  94         __ino_t inode;
  95         int n, lev;
  96         struct procfs_dir_entry *d;
  97 
  98         inode = i->inode;
  99         for(lev = 0; procfs_array[lev]; lev++) {
 100                 if(lev == PROC_PID_LEV) {       /* PID entries */
 101                         if((i->inode & 0xF0000000) == PROC_PID_INO) {
 102                                 inode = i->inode & 0xF0000FFF;
 103                         }
 104                 }
 105                 d = procfs_array[lev];
 106                 for(n = 0; n < PROC_ARRAY_ENTRIES && d->inode; n++) {
 107                         if(d->inode == inode) {
 108                                 return d;
 109                         }
 110                         d++;
 111                 }
 112         }
 113 
 114         return NULL;
 115 }

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