[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 |
|
---|
| 36 | #include <sys/types.h>
|
---|
| 37 |
|
---|
[68ed0fb] | 38 | #define MFS_BLOCKSIZE 1024
|
---|
| 39 |
|
---|
| 40 | /*The following block sizes are valid only on V3 filesystem*/
|
---|
| 41 | #define MFS_MIN_BLOCKSIZE 1024
|
---|
| 42 | #define MFS_MAX_BLOCKSIZE 4096
|
---|
[82650385] | 43 |
|
---|
| 44 | #define MFS_ROOT_INO 1
|
---|
[68ed0fb] | 45 | #define MFS_SUPERBLOCK 1
|
---|
| 46 | #define MFS_SUPERBLOCK_SIZE 1024
|
---|
[e2ad8e4] | 47 |
|
---|
[82650385] | 48 | #define V2_NR_DIRECT_ZONES 7
|
---|
| 49 | #define V2_NR_INDIRECT_ZONES 3
|
---|
[e2ad8e4] | 50 |
|
---|
[82650385] | 51 | #define V1_NR_DIRECT_ZONES 7
|
---|
| 52 | #define V1_NR_INDIRECT_ZONES 2
|
---|
| 53 |
|
---|
[68ed0fb] | 54 | #define V1_INODES_PER_BLOCK (MFS_BLOCKSIZE / sizeof(struct mfs_inode))
|
---|
| 55 | #define V2_INODES_PER_BLOCK (MFS_BLOCKSIZE / sizeof(struct mfs2_inode))
|
---|
| 56 | #define V3_INODES_PER_BLOCK(bs) ((bs) / sizeof(struct mfs2_inode))
|
---|
| 57 |
|
---|
[3564cdd] | 58 | #define MFS_MAX_NAME_LEN 14
|
---|
| 59 | #define MFS_L_MAX_NAME_LEN 30
|
---|
| 60 | #define MFS3_MAX_NAME_LEN 60
|
---|
[e2ad8e4] | 61 |
|
---|
[9e3dc95] | 62 | #define MFS_MAGIC_V1 0x137F
|
---|
[57640e7] | 63 | #define MFS_MAGIC_V1R 0x7F13
|
---|
| 64 |
|
---|
[eee8007] | 65 | #define MFS_MAGIC_V1L 0x138F
|
---|
| 66 | #define MFS_MAGIC_V1LR 0x8F13
|
---|
| 67 |
|
---|
[9e3dc95] | 68 | #define MFS_MAGIC_V2 0x2468
|
---|
[57640e7] | 69 | #define MFS_MAGIC_V2R 0x6824
|
---|
| 70 |
|
---|
[eee8007] | 71 | #define MFS_MAGIC_V2L 0x2478
|
---|
| 72 | #define MFS_MAGIC_V2LR 0x7824
|
---|
| 73 |
|
---|
[9e3dc95] | 74 | #define MFS_MAGIC_V3 0x4D5A
|
---|
[57640e7] | 75 | #define MFS_MAGIC_V3R 0x5A4D
|
---|
[9e3dc95] | 76 |
|
---|
[63ffffd] | 77 | /*MFS V1/V2 superblock data on disk*/
|
---|
[a6e094f] | 78 | struct mfs_superblock {
|
---|
| 79 | /*Total number of inodes on the device*/
|
---|
[63ffffd] | 80 | uint16_t s_ninodes;
|
---|
| 81 | /*Total number of zones on the device*/
|
---|
[a6e094f] | 82 | uint16_t s_nzones;
|
---|
| 83 | /*Number of inode bitmap blocks*/
|
---|
[63ffffd] | 84 | uint16_t s_ibmap_blocks;
|
---|
| 85 | /*Number of zone bitmap blocks*/
|
---|
| 86 | uint16_t s_zbmap_blocks;
|
---|
| 87 | /*First data zone on device*/
|
---|
| 88 | uint16_t s_first_data_zone;
|
---|
| 89 | /*Base 2 logarithm of the zone to block ratio*/
|
---|
| 90 | uint16_t s_log2_zone_size;
|
---|
| 91 | /*Maximum file size expressed in bytes*/
|
---|
| 92 | uint32_t s_max_file_size;
|
---|
| 93 | /*
|
---|
| 94 | *Magic number used to recognize MinixFS
|
---|
| 95 | *and to detect on-disk endianness
|
---|
| 96 | */
|
---|
| 97 | uint16_t s_magic;
|
---|
| 98 | /*Flag used to detect FS errors*/
|
---|
| 99 | uint16_t s_state;
|
---|
| 100 | /*Total number of zones on the device (V2 only)*/
|
---|
| 101 | uint32_t s_nzones2;
|
---|
| 102 | } __attribute__ ((packed));
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /*MFS V3 superblock data on disk*/
|
---|
| 106 | struct mfs3_superblock {
|
---|
| 107 | /*Total number of inodes on the device*/
|
---|
| 108 | uint32_t s_ninodes;
|
---|
[e80b1de] | 109 | uint16_t s_pad0;
|
---|
[63ffffd] | 110 | /*Number of inode bitmap blocks*/
|
---|
[a6e094f] | 111 | int16_t s_ibmap_blocks;
|
---|
| 112 | /*Number of zone bitmap blocks*/
|
---|
| 113 | int16_t s_zbmap_blocks;
|
---|
| 114 | /*First data zone on device*/
|
---|
| 115 | uint16_t s_first_data_zone;
|
---|
| 116 | /*Base 2 logarithm of the zone to block ratio*/
|
---|
| 117 | int16_t s_log2_zone_size;
|
---|
[e80b1de] | 118 | int16_t s_pad1;
|
---|
[a6e094f] | 119 | /*Maximum file size expressed in bytes*/
|
---|
| 120 | int32_t s_max_file_size;
|
---|
| 121 | /*Total number of zones on the device*/
|
---|
[e03a733] | 122 | uint32_t s_nzones;
|
---|
[63ffffd] | 123 | /*
|
---|
| 124 | *Magic number used to recognize MinixFS
|
---|
| 125 | *and to detect on-disk endianness
|
---|
| 126 | */
|
---|
[a6e094f] | 127 | int16_t s_magic;
|
---|
[e2ad8e4] | 128 | int16_t s_pad2;
|
---|
[a6e094f] | 129 | /*Filesystem block size expressed in bytes*/
|
---|
| 130 | uint16_t s_block_size;
|
---|
| 131 | /*Filesystem disk format version*/
|
---|
| 132 | int8_t s_disk_version;
|
---|
[e2ad8e4] | 133 | } __attribute__ ((packed));
|
---|
| 134 |
|
---|
[82650385] | 135 | /*MinixFS V1 inode structure as it is on disk*/
|
---|
[68ed0fb] | 136 | struct mfs_inode {
|
---|
[82650385] | 137 | uint16_t i_mode;
|
---|
| 138 | int16_t i_uid;
|
---|
| 139 | int32_t i_size;
|
---|
| 140 | int32_t i_mtime;
|
---|
| 141 | uint8_t i_gid;
|
---|
| 142 | uint8_t i_nlinks;
|
---|
| 143 | /*Block numbers for direct zones*/
|
---|
| 144 | uint16_t i_dzone[V1_NR_DIRECT_ZONES];
|
---|
| 145 | /*Block numbers for indirect zones*/
|
---|
| 146 | uint16_t i_izone[V1_NR_INDIRECT_ZONES];
|
---|
| 147 | } __attribute__ ((packed));
|
---|
| 148 |
|
---|
[68ed0fb] | 149 | /*MinixFS V2 inode structure as it is on disk (also valid for V3).*/
|
---|
| 150 | struct mfs2_inode {
|
---|
[82650385] | 151 | uint16_t i_mode;
|
---|
| 152 | uint16_t i_nlinks;
|
---|
| 153 | int16_t i_uid;
|
---|
| 154 | uint16_t i_gid;
|
---|
| 155 | int32_t i_size;
|
---|
| 156 | int32_t i_atime;
|
---|
| 157 | int32_t i_mtime;
|
---|
| 158 | int32_t i_ctime;
|
---|
| 159 | /*Block numbers for direct zones*/
|
---|
| 160 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
---|
| 161 | /*Block numbers for indirect zones*/
|
---|
| 162 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
---|
| 163 | } __attribute__ ((packed));
|
---|
| 164 |
|
---|
[3564cdd] | 165 | /*MinixFS V1/V2 directory entry on-disk structure*/
|
---|
| 166 | struct mfs_dentry {
|
---|
[82650385] | 167 | uint16_t d_inum;
|
---|
[3564cdd] | 168 | char d_name[MFS_MAX_NAME_LEN];
|
---|
[82650385] | 169 | } __attribute__ ((packed));
|
---|
| 170 |
|
---|
[3564cdd] | 171 | /*MinixFS V1/V2 with 30-char filenames (Linux variant)*/
|
---|
[5a81c5b] | 172 | struct mfs_l_dentry {
|
---|
[82650385] | 173 | uint16_t d_inum;
|
---|
[3564cdd] | 174 | char d_name[MFS_L_MAX_NAME_LEN];
|
---|
[82650385] | 175 | } __attribute__ ((packed));
|
---|
| 176 |
|
---|
| 177 | /*MinixFS V3 directory entry on-disk structure*/
|
---|
[3564cdd] | 178 | struct mfs3_dentry {
|
---|
[82650385] | 179 | uint32_t d_inum;
|
---|
[3564cdd] | 180 | char d_name[MFS3_MAX_NAME_LEN];
|
---|
[82650385] | 181 | } __attribute__ ((packed));
|
---|
| 182 |
|
---|
[9e3dc95] | 183 |
|
---|
[e2ad8e4] | 184 | #endif
|
---|
| 185 |
|
---|
| 186 | /**
|
---|
| 187 | * @}
|
---|
[82650385] | 188 | */
|
---|
| 189 |
|
---|