2023-10-27 21:54:33 -07:00
|
|
|
#ifndef MOTHFS_H
|
|
|
|
#define MOTHFS_H
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define MFS_FILE 0
|
|
|
|
#define MFS_DIR 1
|
|
|
|
|
2023-08-06 21:35:05 -07:00
|
|
|
typedef struct {
|
|
|
|
uint32_t jmp; // used to jump past the header
|
|
|
|
uint8_t magic[7]; // 'MOTHFS\0'
|
|
|
|
uint8_t version; // currently fs version 0
|
|
|
|
uint32_t size; // partition size in sectors - sectors always 512b
|
|
|
|
// this means the max size is 'only' 2tb but i would
|
|
|
|
// be surprised if anyone managed to use 2tb in dos
|
|
|
|
|
|
|
|
uint32_t offset; // offset of partition from start of disk
|
|
|
|
uint8_t volname[15]; // name of partition
|
|
|
|
uint8_t reserved; // number of sectors reserved for boot code. these
|
|
|
|
// are stored immediately following this header
|
|
|
|
|
|
|
|
uint32_t abm; // number of sectors reserved for the allocation
|
|
|
|
// bitmap. these immediately follow the boot code
|
|
|
|
// sectors. the root directory is stored in the first
|
|
|
|
// non-reserved sector
|
|
|
|
|
|
|
|
uint8_t bootcode[470];
|
|
|
|
uint16_t signature; // 0xAA55 as usual to make it directly bootable
|
|
|
|
} mothfs_header; // 512 bytes
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t sector; // sector offset relative to the partition, not the disk
|
|
|
|
uint32_t length; // number of consecutive sectors to address
|
|
|
|
} ptrlen; // 8 bytes
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t type; // 0 - file
|
|
|
|
// 1 - directory
|
|
|
|
|
2023-10-27 21:54:33 -07:00
|
|
|
uint8_t pad; // keep 2-byte alignment
|
|
|
|
uint16_t freebytes; // number of bytes unused in last sector of file data
|
|
|
|
|
|
|
|
uint32_t dir; // pointer to parent directory
|
2023-08-06 21:35:05 -07:00
|
|
|
|
2023-10-27 21:54:33 -07:00
|
|
|
uint32_t ext; // undefined in version 0 - contains pointer to uid, gid,
|
|
|
|
// data for other file types, long filename, linux caps,
|
|
|
|
// unix permissions, etc. if missing, must be zero
|
2023-08-06 21:35:05 -07:00
|
|
|
|
2023-10-27 21:54:33 -07:00
|
|
|
// both of these values are zero padded
|
2023-08-06 21:35:05 -07:00
|
|
|
uint8_t name[8]; // filename
|
2023-10-27 21:54:33 -07:00
|
|
|
uint8_t fxt[3]; // extension
|
2023-08-06 21:35:05 -07:00
|
|
|
|
2023-10-27 21:54:33 -07:00
|
|
|
uint8_t lfn; // size of long filename - should be zero in version 0
|
|
|
|
// max length of 255 is on par with most filesystems
|
2023-08-06 21:35:05 -07:00
|
|
|
|
|
|
|
uint32_t data[122];
|
|
|
|
|
|
|
|
// for files - `data` is 61 `ptrlen`s. if not all 60 are used, it must be null
|
|
|
|
// terminated by setting ptrlen.sector to zero. if there is no terminator,
|
|
|
|
// data[60].sector points to a sector containing 64 more `ptrlen`s. if there is
|
|
|
|
// no terminator in that sector, the last `ptrlen` points to another sector of
|
|
|
|
// identical layout. this continues until a sector with a terminator is found
|
|
|
|
|
|
|
|
// for directories - `data` is 122 sector offsets. if not all 121 are used, it
|
|
|
|
// must be null terminated. if there is no terminator, data[121] points to a
|
|
|
|
// sector containing 128 more sector offsets. the rules for this are similar
|
|
|
|
// enough to how files work that i do not want to write it out again
|
|
|
|
} mothfs_file; // 512 bytes
|
2023-10-27 21:54:33 -07:00
|
|
|
|
|
|
|
#endif
|