Fork me on GitHub

root/fs/filesystems.c

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

DEFINITIONS

This source file includes following definitions.
  1. register_filesystem
  2. get_filesystem
  3. fs_init

   1 /*
   2  * fiwix/fs/filesystems.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/fs_iso9660.h>
  14 #include <fiwix/fs_proc.h>
  15 #include <fiwix/stdio.h>
  16 #include <fiwix/string.h>
  17 
  18 int register_filesystem(const char *name, struct fs_operations *fsop)
  19 {
  20         int n;
  21         __dev_t dev;
  22 
  23         for(n = 0; n < NR_FILESYSTEMS; n++) {
  24                 if(filesystems_table[n].name) {
  25                         if(strcmp(filesystems_table[n].name, name) == 0) {
  26                                 printk("WARNING: %s(): filesystem '%s' already registered!\n", __FUNCTION__, name);
  27                                 return 1;
  28                         }
  29                 }
  30                 if(!filesystems_table[n].name) {
  31                         filesystems_table[n].name = name;
  32                         filesystems_table[n].fsop = fsop;
  33                         if((fsop->flags & FSOP_KERN_MOUNT)) {
  34                                 dev = fsop->fsdev;
  35                                 return kern_mount(dev, &filesystems_table[n]);
  36                         }
  37                         return 0;
  38                 }
  39         }
  40         printk("WARNING: %s(): filesystems table is full!\n", __FUNCTION__);
  41         return 1;
  42 }
  43 
  44 struct filesystems * get_filesystem(const char *name)
  45 {
  46         int n;
  47 
  48         if(!name) {
  49                 return NULL;
  50         }
  51         for(n = 0; n < NR_FILESYSTEMS; n++) {
  52                 if(!filesystems_table[n].name) {
  53                         continue;
  54                 }
  55                 if(strcmp(filesystems_table[n].name, name) == 0) {
  56                         return &filesystems_table[n];
  57                 }
  58         }
  59         return NULL;
  60 }
  61 
  62 void fs_init(void)
  63 {
  64         memset_b(filesystems_table, NULL, sizeof(filesystems_table));
  65 
  66         if(minix_init()) {
  67                 printk("%s(): unable to register 'minix' filesystem.\n", __FUNCTION__);
  68         }
  69         if(ext2_init()) {
  70                 printk("%s(): unable to register 'ext2' filesystem.\n", __FUNCTION__);
  71         }
  72         if(pipefs_init()) {
  73                 printk("%s(): unable to register 'pipefs' filesystem.\n", __FUNCTION__);
  74         }
  75         if(iso9660_init()) {
  76                 printk("%s(): unable to register 'iso9660' filesystem.\n", __FUNCTION__);
  77         }
  78         if(procfs_init()) {
  79                 printk("%s(): unable to register 'procfs' filesystem.\n", __FUNCTION__);
  80         }
  81 }

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