Fork me on GitHub

root/fs/pipefs/super.c

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

DEFINITIONS

This source file includes following definitions.
  1. pipefs_read_superblock
  2. pipefs_ialloc
  3. pipefs_ifree
  4. pipefs_init

   1 /*
   2  * fiwix/fs/pipefs/super.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/errno.h>
  10 #include <fiwix/fs.h>
  11 #include <fiwix/filesystems.h>
  12 #include <fiwix/fs_pipe.h>
  13 #include <fiwix/stat.h>
  14 #include <fiwix/mm.h>
  15 #include <fiwix/sched.h>
  16 #include <fiwix/stdio.h>
  17 #include <fiwix/string.h>
  18 
  19 static unsigned int i_counter;
  20 
  21 struct fs_operations pipefs_fsop = {
  22         FSOP_KERN_MOUNT,
  23         PIPE_DEV,
  24 
  25         fifo_open,
  26         pipefs_close,
  27         pipefs_read,
  28         pipefs_write,
  29         pipefs_ioctl,
  30         pipefs_lseek,
  31         NULL,                   /* readdir */
  32         NULL,                   /* mmap */
  33         pipefs_select,
  34 
  35         NULL,                   /* readlink */
  36         NULL,                   /* followlink */
  37         NULL,                   /* bmap */
  38         NULL,                   /* lookup */
  39         NULL,                   /* rmdir */
  40         NULL,                   /* link */
  41         NULL,                   /* unlink */
  42         NULL,                   /* symlink */
  43         NULL,                   /* mkdir */
  44         NULL,                   /* mknod */
  45         NULL,                   /* truncate */
  46         NULL,                   /* create */
  47         NULL,                   /* rename */
  48 
  49         NULL,                   /* read_block */
  50         NULL,                   /* write_block */
  51 
  52         NULL,                   /* read_inode */
  53         NULL,                   /* write_inode */
  54         pipefs_ialloc,
  55         pipefs_ifree,
  56         NULL,                   /* statfs */
  57         pipefs_read_superblock,
  58         NULL,                   /* remount_fs */
  59         NULL,                   /* write_superblock */
  60         NULL                    /* release_superblock */
  61 };
  62 
  63 int pipefs_read_superblock(__dev_t dev, struct superblock *sb)
  64 {
  65         superblock_lock(sb);
  66         sb->dev = dev;
  67         sb->fsop = &pipefs_fsop;
  68         sb->s_blocksize = BLKSIZE_1K;
  69         i_counter = 0;
  70         superblock_unlock(sb);
  71         return 0;
  72 }
  73 
  74 int pipefs_ialloc(struct inode *i, int mode)
  75 {
  76         struct superblock *sb = i->sb;
  77 
  78         superblock_lock(sb);
  79         i_counter++;
  80         superblock_unlock(sb);
  81 
  82         i->i_mode = S_IFIFO;
  83         i->dev = i->rdev = sb->dev;
  84         i->fsop = &pipefs_fsop;
  85         i->inode = i_counter;
  86         i->count = 2;
  87         if(!(i->u.pipefs.i_data = (void *)kmalloc())) {
  88                 return -ENOMEM;
  89         }
  90         i->u.pipefs.i_readoff = 0;
  91         i->u.pipefs.i_writeoff = 0;
  92         i->u.pipefs.i_readers = 1;
  93         i->u.pipefs.i_writers = 1;
  94         return 0;
  95 }
  96 
  97 void pipefs_ifree(struct inode *i)
  98 {
  99         if(!i->u.pipefs.i_readers && !i->u.pipefs.i_writers) {
 100                 /*
 101                  * We need to ask before to kfree() because this function is
 102                  * also called to free removed (with sys_unlink) fifo files.
 103                  */
 104                 if(i->u.pipefs.i_data) {
 105                         kfree((unsigned int)i->u.pipefs.i_data);
 106                 }
 107         }
 108 }
 109 
 110 int pipefs_init(void)
 111 {
 112         return register_filesystem("pipefs", &pipefs_fsop);
 113 }

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