Fork me on GitHub

root/fs/procfs/inode.c

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

DEFINITIONS

This source file includes following definitions.
  1. procfs_read_inode
  2. procfs_bmap
  3. procfs_statfs

   1 /*
   2  * fiwix/fs/procfs/inode.c
   3  *
   4  * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/kernel.h>
   9 #include <fiwix/fs.h>
  10 #include <fiwix/filesystems.h>
  11 #include <fiwix/fs_proc.h>
  12 #include <fiwix/statfs.h>
  13 #include <fiwix/sleep.h>
  14 #include <fiwix/stat.h>
  15 #include <fiwix/sched.h>
  16 #include <fiwix/mm.h>
  17 #include <fiwix/process.h>
  18 #include <fiwix/errno.h>
  19 #include <fiwix/stdio.h>
  20 #include <fiwix/string.h>
  21 
  22 int procfs_read_inode(struct inode *i)
  23 {
  24         int lev;
  25         __mode_t mode;
  26         __nlink_t nlink;
  27         struct procfs_dir_entry *d;
  28 
  29         if((i->inode & 0xF0000FFF) == PROC_PID_INO) {   /* dynamic PID dir */
  30                 mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
  31                 nlink = 3;
  32                 lev = PROC_PID_LEV;
  33         } else {
  34                 if(!(d = get_procfs_by_inode(i))) {
  35                         return -ENOENT;
  36                 }
  37                 mode = d->mode;
  38                 nlink = d->nlink;
  39                 lev = d->lev;
  40         }
  41 
  42         i->i_mode = mode;
  43         i->i_uid = 0;
  44         i->i_size = 0;
  45         i->i_atime = CURRENT_TIME;
  46         i->i_ctime = CURRENT_TIME;
  47         i->i_mtime = CURRENT_TIME;
  48         i->i_gid = 0;
  49         i->i_nlink = nlink;
  50         i->i_blocks = 0;
  51         i->i_flags = 0;
  52         i->locked = 1;
  53         i->dirty = 0;
  54         i->count = 1;
  55         i->u.procfs.i_lev = lev;
  56         switch(i->i_mode & S_IFMT) {
  57                 case S_IFDIR:
  58                         i->fsop = &procfs_dir_fsop;
  59                         break;
  60                 case S_IFREG:
  61                         i->fsop = &procfs_file_fsop;
  62                         break;
  63                 case S_IFLNK:
  64                         i->fsop = &procfs_symlink_fsop;
  65                         break;
  66                 default:
  67                         PANIC("invalid inode (%d) mode %08o.\n", i->inode, i->i_mode);
  68         }
  69         return 0;
  70 }
  71 
  72 int procfs_bmap(struct inode *i, __off_t offset, int mode)
  73 {
  74         return i->u.procfs.i_lev;
  75 }
  76 
  77 void procfs_statfs(struct superblock *sb, struct statfs *statfsbuf)
  78 {
  79         statfsbuf->f_type = PROC_SUPER_MAGIC;
  80         statfsbuf->f_bsize = sb->s_blocksize;
  81         statfsbuf->f_blocks = 0;
  82         statfsbuf->f_bfree = 0;
  83         statfsbuf->f_bavail = 0;
  84         statfsbuf->f_files = 0;
  85         statfsbuf->f_ffree = 0;
  86         /* statfsbuf->f_fsid = ? */
  87         statfsbuf->f_namelen = NAME_MAX;
  88 }

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