fk98/src/dosfs.h
2020-11-13 21:43:35 -08:00

85 lines
2 KiB
C

/* fat12 */
#ifndef _FAT12_H
#define _FAT12_H
struct __attribute__((__packed__)) bpb {
uint8_t jmp[3]; /* presumably some machine code */
char oem_id[8];
uint16_t sect_size;
uint8_t sect_per_cluster;
uint16_t resv_sect;
uint8_t fat_ct;
uint16_t dirent_ct;
uint16_t sect_ct;
uint8_t media_type;
uint16_t fat_size;
uint16_t track_size;
uint16_t heads;
uint32_t hidden_sect;
uint32_t larg_sect_ct;
/*
* XXX: Most PC98 disks don't seem to have the extended
* BPB. Should we even care about these?
*/
uint8_t drive_num;
uint8_t _reserved;
uint8_t signature;
uint32_t serial_num;
char label[11];
char sys_id[8];
};
struct __attribute__((__packed__)) dos_dirent {
char filename[11];
uint8_t attributes;
#define ATTR_READONLY 0x01
#define ATTR_HIDDEN 0x02
#define ATTR_SYSTEM 0x04
#define ATTR_VOLID 0x08
#define ATTR_ISDIR 0x10
#define ATTR_ARCHIVE 0x20
#define ATTR_LFN (ATTR_READONLY|ATTR_HIDDEN|ATTR_SYSTEM|ATTR_VOLID)
uint8_t _reserved;
uint8_t creation_time_tenths;
uint16_t creation_time;
uint16_t creation_date;
uint16_t access_date;
uint16_t high_loc; /* only used with FAT32 */
uint16_t mod_time;
uint16_t mod_date;
uint16_t low_loc; /* entry cluster location */
uint32_t size;
};
#define FAT12_MAX_CLUSTERS 4085
#define FAT16_MAX_CLUSTERS 65525
typedef struct dosfs_t {
struct bpb ib;
unsigned int fs_ver;
int ifd;
unsigned int root_loc;
unsigned int root_size;
unsigned int data_loc;
unsigned int data_size;
} dosfs_t;
typedef struct dosfile_t {
struct dos_dirent ent;
char fname[9];
char fext[4];
struct dosfile_t *next;
} dosfile_t;
int open_image(const char *, int, dosfs_t *);
void close_image(dosfs_t *);
dosfile_t *dos_listdir(dosfs_t *, unsigned int);
int dos_fread(dosfs_t *, dosfile_t *, void *, int);
void dos_freedir(dosfile_t *);
#endif /* !_FAT12_H */