[e2ad8e4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Maurizio Lombardi
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup fs
|
---|
| 30 | * @{
|
---|
[82650385] | 31 | */
|
---|
| 32 |
|
---|
| 33 | #ifndef _MINIX_FS_H_
|
---|
| 34 | #define _MINIX_FS_H_
|
---|
| 35 |
|
---|
[8d2dd7f2] | 36 | #include <stdint.h>
|
---|
[82650385] | 37 |
|
---|
[68ed0fb] | 38 | #define MFS_BLOCKSIZE 1024
|
---|
[410a065] | 39 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
---|
[7d04324] | 40 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
---|
[50a01a9] | 41 | #define S_IFDIR 0040000 /* Directory */
|
---|
| 42 | #define S_IFREG 0100000 /* Regular file */
|
---|
[410a065] | 43 | #define S_IFMT 00170000
|
---|
[68ed0fb] | 44 |
|
---|
[50a01a9] | 45 | /* The following block sizes are valid only on V3 filesystem */
|
---|
[68ed0fb] | 46 | #define MFS_MIN_BLOCKSIZE 1024
|
---|
| 47 | #define MFS_MAX_BLOCKSIZE 4096
|
---|
[82650385] | 48 |
|
---|
| 49 | #define MFS_ROOT_INO 1
|
---|
[68ed0fb] | 50 | #define MFS_SUPERBLOCK 1
|
---|
| 51 | #define MFS_SUPERBLOCK_SIZE 1024
|
---|
[340b5690] | 52 | #define MFS_BOOTBLOCK_SIZE 1024
|
---|
[e2ad8e4] | 53 |
|
---|
[82650385] | 54 | #define V2_NR_DIRECT_ZONES 7
|
---|
| 55 | #define V2_NR_INDIRECT_ZONES 3
|
---|
[e2ad8e4] | 56 |
|
---|
[82650385] | 57 | #define V1_NR_DIRECT_ZONES 7
|
---|
| 58 | #define V1_NR_INDIRECT_ZONES 2
|
---|
| 59 |
|
---|
[68ed0fb] | 60 | #define V1_INODES_PER_BLOCK (MFS_BLOCKSIZE / sizeof(struct mfs_inode))
|
---|
| 61 | #define V2_INODES_PER_BLOCK (MFS_BLOCKSIZE / sizeof(struct mfs2_inode))
|
---|
| 62 | #define V3_INODES_PER_BLOCK(bs) ((bs) / sizeof(struct mfs2_inode))
|
---|
| 63 |
|
---|
[410a065] | 64 | #define MFS_DIRSIZE 16
|
---|
| 65 | #define MFSL_DIRSIZE 32
|
---|
| 66 | #define MFS3_DIRSIZE 64
|
---|
| 67 |
|
---|
[3564cdd] | 68 | #define MFS_MAX_NAME_LEN 14
|
---|
| 69 | #define MFS_L_MAX_NAME_LEN 30
|
---|
| 70 | #define MFS3_MAX_NAME_LEN 60
|
---|
[e2ad8e4] | 71 |
|
---|
[9e3dc95] | 72 | #define MFS_MAGIC_V1 0x137F
|
---|
[57640e7] | 73 | #define MFS_MAGIC_V1R 0x7F13
|
---|
| 74 |
|
---|
[eee8007] | 75 | #define MFS_MAGIC_V1L 0x138F
|
---|
| 76 | #define MFS_MAGIC_V1LR 0x8F13
|
---|
| 77 |
|
---|
[9e3dc95] | 78 | #define MFS_MAGIC_V2 0x2468
|
---|
[57640e7] | 79 | #define MFS_MAGIC_V2R 0x6824
|
---|
| 80 |
|
---|
[eee8007] | 81 | #define MFS_MAGIC_V2L 0x2478
|
---|
| 82 | #define MFS_MAGIC_V2LR 0x7824
|
---|
| 83 |
|
---|
[9e3dc95] | 84 | #define MFS_MAGIC_V3 0x4D5A
|
---|
[57640e7] | 85 | #define MFS_MAGIC_V3R 0x5A4D
|
---|
[9e3dc95] | 86 |
|
---|
[59e670e] | 87 | #define MFS_VALID_FS 0x0001
|
---|
| 88 | #define MFS_ERROR_FS 0x0002
|
---|
| 89 |
|
---|
[50a01a9] | 90 | /* MFS V1/V2 superblock data on disk */
|
---|
[a6e094f] | 91 | struct mfs_superblock {
|
---|
[50a01a9] | 92 | /* Total number of inodes on the device */
|
---|
[63ffffd] | 93 | uint16_t s_ninodes;
|
---|
[50a01a9] | 94 | /* Total number of zones on the device */
|
---|
[a6e094f] | 95 | uint16_t s_nzones;
|
---|
[50a01a9] | 96 | /* Number of inode bitmap blocks */
|
---|
[63ffffd] | 97 | uint16_t s_ibmap_blocks;
|
---|
[50a01a9] | 98 | /* Number of zone bitmap blocks */
|
---|
[63ffffd] | 99 | uint16_t s_zbmap_blocks;
|
---|
[50a01a9] | 100 | /* First data zone on device */
|
---|
[63ffffd] | 101 | uint16_t s_first_data_zone;
|
---|
[50a01a9] | 102 | /* Base 2 logarithm of the zone to block ratio */
|
---|
[63ffffd] | 103 | uint16_t s_log2_zone_size;
|
---|
[50a01a9] | 104 | /* Maximum file size expressed in bytes */
|
---|
[63ffffd] | 105 | uint32_t s_max_file_size;
|
---|
| 106 | /*
|
---|
[47e00b83] | 107 | * Magic number used to recognize MinixFS
|
---|
| 108 | * and to detect on-disk endianness
|
---|
[63ffffd] | 109 | */
|
---|
| 110 | uint16_t s_magic;
|
---|
[50a01a9] | 111 | /* Flag used to detect FS errors*/
|
---|
[63ffffd] | 112 | uint16_t s_state;
|
---|
[50a01a9] | 113 | /* Total number of zones on the device (V2 only) */
|
---|
[63ffffd] | 114 | uint32_t s_nzones2;
|
---|
[1433ecda] | 115 | } __attribute__((packed));
|
---|
[63ffffd] | 116 |
|
---|
| 117 |
|
---|
[50a01a9] | 118 | /* MFS V3 superblock data on disk */
|
---|
[63ffffd] | 119 | struct mfs3_superblock {
|
---|
[50a01a9] | 120 | /* Total number of inodes on the device */
|
---|
[63ffffd] | 121 | uint32_t s_ninodes;
|
---|
[e80b1de] | 122 | uint16_t s_pad0;
|
---|
[50a01a9] | 123 | /* Number of inode bitmap blocks */
|
---|
[a6e094f] | 124 | int16_t s_ibmap_blocks;
|
---|
[50a01a9] | 125 | /* Number of zone bitmap blocks */
|
---|
[a6e094f] | 126 | int16_t s_zbmap_blocks;
|
---|
[50a01a9] | 127 | /* First data zone on device */
|
---|
[a6e094f] | 128 | uint16_t s_first_data_zone;
|
---|
[50a01a9] | 129 | /* Base 2 logarithm of the zone to block ratio */
|
---|
[a6e094f] | 130 | int16_t s_log2_zone_size;
|
---|
[e80b1de] | 131 | int16_t s_pad1;
|
---|
[50a01a9] | 132 | /* Maximum file size expressed in bytes */
|
---|
[59e670e] | 133 | uint32_t s_max_file_size;
|
---|
[50a01a9] | 134 | /* Total number of zones on the device */
|
---|
[e03a733] | 135 | uint32_t s_nzones;
|
---|
[63ffffd] | 136 | /*
|
---|
[47e00b83] | 137 | * Magic number used to recognize MinixFS
|
---|
| 138 | * and to detect on-disk endianness
|
---|
[63ffffd] | 139 | */
|
---|
[a6e094f] | 140 | int16_t s_magic;
|
---|
[e2ad8e4] | 141 | int16_t s_pad2;
|
---|
[50a01a9] | 142 | /* Filesystem block size expressed in bytes */
|
---|
[a6e094f] | 143 | uint16_t s_block_size;
|
---|
[50a01a9] | 144 | /* Filesystem disk format version */
|
---|
[a6e094f] | 145 | int8_t s_disk_version;
|
---|
[1433ecda] | 146 | } __attribute__((packed));
|
---|
[e2ad8e4] | 147 |
|
---|
[50a01a9] | 148 | /* MinixFS V1 inode structure as it is on disk */
|
---|
[68ed0fb] | 149 | struct mfs_inode {
|
---|
[82650385] | 150 | uint16_t i_mode;
|
---|
| 151 | int16_t i_uid;
|
---|
| 152 | int32_t i_size;
|
---|
| 153 | int32_t i_mtime;
|
---|
| 154 | uint8_t i_gid;
|
---|
| 155 | uint8_t i_nlinks;
|
---|
[50a01a9] | 156 | /* Block numbers for direct zones */
|
---|
[82650385] | 157 | uint16_t i_dzone[V1_NR_DIRECT_ZONES];
|
---|
[50a01a9] | 158 | /* Block numbers for indirect zones */
|
---|
[82650385] | 159 | uint16_t i_izone[V1_NR_INDIRECT_ZONES];
|
---|
[1433ecda] | 160 | } __attribute__((packed));
|
---|
[82650385] | 161 |
|
---|
[50a01a9] | 162 | /* MinixFS V2 inode structure as it is on disk (also valid for V3). */
|
---|
[68ed0fb] | 163 | struct mfs2_inode {
|
---|
[82650385] | 164 | uint16_t i_mode;
|
---|
| 165 | uint16_t i_nlinks;
|
---|
| 166 | int16_t i_uid;
|
---|
| 167 | uint16_t i_gid;
|
---|
| 168 | int32_t i_size;
|
---|
| 169 | int32_t i_atime;
|
---|
| 170 | int32_t i_mtime;
|
---|
| 171 | int32_t i_ctime;
|
---|
[50a01a9] | 172 | /* Block numbers for direct zones */
|
---|
[82650385] | 173 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
---|
[50a01a9] | 174 | /* Block numbers for indirect zones */
|
---|
[82650385] | 175 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
---|
[1433ecda] | 176 | } __attribute__((packed));
|
---|
[82650385] | 177 |
|
---|
[50a01a9] | 178 | /* MinixFS V1/V2 directory entry on-disk structure */
|
---|
[3564cdd] | 179 | struct mfs_dentry {
|
---|
[82650385] | 180 | uint16_t d_inum;
|
---|
[3c616f6] | 181 | char d_name[0];
|
---|
| 182 | };
|
---|
[82650385] | 183 |
|
---|
[50a01a9] | 184 | /* MinixFS V3 directory entry on-disk structure */
|
---|
[3564cdd] | 185 | struct mfs3_dentry {
|
---|
[82650385] | 186 | uint32_t d_inum;
|
---|
[3c616f6] | 187 | char d_name[0];
|
---|
| 188 | };
|
---|
[82650385] | 189 |
|
---|
[9e3dc95] | 190 |
|
---|
[e2ad8e4] | 191 | #endif
|
---|
| 192 |
|
---|
| 193 | /**
|
---|
| 194 | * @}
|
---|
[82650385] | 195 | */
|
---|
| 196 |
|
---|