Fork me on GitHub

root/include/fiwix/fs_minix.h

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

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/fs_minix.h
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #ifndef _FIWIX_FS_MINIX_H
   9 #define _FIWIX_FS_MINIX_H
  10 
  11 #include <fiwix/types.h>
  12 #include <fiwix/limits.h>
  13 
  14 #define MINIX_ROOT_INO          1       /* root inode */
  15 
  16 #define MINIX_SUPER_MAGIC       0x137F  /* Minix v1, 14 char names */
  17 #define MINIX_SUPER_MAGIC2      0x138F  /* Minix v1, 30 char names */
  18 #define MINIX2_SUPER_MAGIC      0x2468  /* Minix v2, 14 char names */
  19 #define MINIX2_SUPER_MAGIC2     0x2478  /* Minix v2, 30 char names */
  20 
  21 #define MINIX_VALID_FS          1       /* clean filesystem */
  22 #define MINIX_ERROR_FS          2       /* needs fsck */
  23 
  24 #define CLEAR_BIT               0
  25 #define SET_BIT                 1
  26 
  27 #define V1_MAX_BITMAP_BLOCKS    8       /* 64MB filesystem size */
  28 #define V2_MAX_BITMAP_BLOCKS    128     /* 1GB filesystem size */
  29 
  30 /*
  31  * Minix (v1 and v2) file system physical layout:
  32  *
  33  *               +-----------------------------------------------
  34  *               |   size in blocks of BLKSIZE_1K (1024 bytes)  |
  35  * +-------------+----------------------------------------------+
  36  * | block 0     |                                            1 |
  37  * +-------------+----------------------------------------------+
  38  * | superblock  |                                            1 |
  39  * +-------------+----------------------------------------------+
  40  * | inode map   |          number of inodes / (BLKSIZE_1K * 8) | 
  41  * +-------------+----------------------------------------------+
  42  * | zone map    |           number of zones / (BLKSIZE_1K * 8) | 
  43  * +-------------+----------------------------------------------+
  44  * | inode table | ((32 or 64) * number of inodes) / BLKSIZE_1K |
  45  * +-------------+----------------------------------------------+
  46  * | data zones  |                                          ... | 
  47  * +-------------+----------------------------------------------+
  48  *
  49  * The implementation of this filesystem in Fiwix might have slow disk writes
  50  * because I don't keep in memory the superblock, nor the blocks of the inode
  51  * map nor the blocks of the zone map. Keeping them in memory would be a waste
  52  * of 137KB per each mounted v2 filesystem (1GB of size).
  53  *
  54  * - superblock    ->   1KB
  55  * - inode map     ->   8KB (1KB (8192 bits) x   8 = 65536 inodes)
  56  * - zone map      -> 128KB (1KB (8192 bits) x 128 = 1048576 1k-blocks)
  57  *
  58  */
  59 
  60 struct minix_super_block {
  61         __u16 s_ninodes;                /* number of inodes */
  62         __u16 s_nzones;                 /* number of data zones */
  63         __u16 s_imap_blocks;            /* blocks used by inode bitmap */
  64         __u16 s_zmap_blocks;            /* blocks used by zone bitmap */
  65         __u16 s_firstdatazone;          /* number of first data zone */
  66         __u16 s_log_zone_size;          /* 1024 << s_log_zone_size */
  67         __u32 s_max_size;               /* maximum file size (in bytes) */
  68         __u16 s_magic;                  /* magic number */
  69         __u16 s_state;                  /* filesystem state */
  70         __u32 s_zones;                  /* number of data zones (for v2 only) */
  71 };
  72 
  73 struct minix_inode {
  74         __u16 i_mode;
  75         __u16 i_uid;
  76         __u32 i_size;
  77         __u32 i_time;
  78         __u8  i_gid;
  79         __u8  i_nlinks;
  80         __u16 i_zone[9];
  81 };
  82 
  83 struct minix2_inode {
  84         __u16 i_mode;
  85         __u16 i_nlink;
  86         __u16 i_uid;
  87         __u16 i_gid;
  88         __u32 i_size;
  89         __u32 i_atime;
  90         __u32 i_mtime;
  91         __u32 i_ctime;
  92         __u32 i_zone[10];
  93 };
  94 
  95 struct minix_dir_entry {
  96         __u16 inode;
  97         char name[0];
  98 };
  99 
 100 /* super block in memory */
 101 struct minix_sb_info {
 102         unsigned char namelen;
 103         unsigned char dirsize;
 104         unsigned short int version;
 105         unsigned int nzones;
 106         struct minix_super_block sb;
 107 };
 108 
 109 /* inode in memory */
 110 struct minix_i_info {
 111         union {
 112                 __u16 i1_zone[9];
 113                 __u32 i2_zone[10];
 114         } u;
 115 };
 116 
 117 int v1_minix_read_inode(struct inode *);
 118 int v1_minix_write_inode(struct inode *);
 119 int v1_minix_ialloc(struct inode *, int);
 120 void v1_minix_ifree(struct inode *);
 121 int v1_minix_bmap(struct inode *, __off_t, int);
 122 int v1_minix_truncate(struct inode *, __off_t);
 123 
 124 int v2_minix_read_inode(struct inode *);
 125 int v2_minix_write_inode(struct inode *);
 126 int v2_minix_ialloc(struct inode *, int);
 127 void v2_minix_ifree(struct inode *);
 128 int v2_minix_bmap(struct inode *, __off_t, int);
 129 int v2_minix_truncate(struct inode *, __off_t);
 130 
 131 #endif /* _FIWIX_FS_MINIX_H */

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