124 lines
3.7 KiB
C
124 lines
3.7 KiB
C
#ifndef __FAT_H__
|
|
#define __FAT_H__
|
|
|
|
#define NULL 0
|
|
|
|
struct BPB {
|
|
unsigned char BS_jmpBoot[3];
|
|
char BS_OEMName[8];
|
|
unsigned short BPB_BytesPerSec;
|
|
unsigned char BPB_SecPerClus;
|
|
unsigned short BPB_RsvdSecCnt;
|
|
unsigned char BPB_NumFATs;
|
|
unsigned short BPB_RootEntCnt;
|
|
unsigned short BPB_TotSec16;
|
|
unsigned char BPB_Media;
|
|
unsigned short BPB_FATSz16;
|
|
unsigned short BPB_SecPerTrk;
|
|
unsigned short BPB_NumHeads;
|
|
unsigned int BPB_HiddSec;
|
|
unsigned int BPB_TotSec32;
|
|
union FatType {
|
|
struct Fat16 {
|
|
unsigned char BS_DrvNum;
|
|
unsigned char BS_Reserved1;
|
|
unsigned char BS_BootSig;
|
|
unsigned int BS_VolID;
|
|
char BS_VolLab[11];
|
|
char BS_FilSysType[8];
|
|
} Fat16;
|
|
struct Fat32 {
|
|
unsigned int BPB_FATSz32;
|
|
unsigned short BPB_ExtFlags;
|
|
unsigned short BPB_FSVer;
|
|
unsigned int BPB_RootClus;
|
|
unsigned short BPB_FSInfo;
|
|
unsigned short BPB_BkBootSec;
|
|
char BPB_Reserved[12];
|
|
unsigned char BS_DrvNum;
|
|
unsigned char BS_Reserved1;
|
|
unsigned char BS_BootSig;
|
|
unsigned int BS_VolID;
|
|
char BS_VolLab[11];
|
|
char BS_FilSysType[8];
|
|
} Fat32;
|
|
} FatType;
|
|
}__attribute__((packed));
|
|
|
|
struct fat_fsinfo {
|
|
unsigned int FSI_LeadSig;
|
|
unsigned char FSI_Reserved1[480];
|
|
unsigned int FSI_StructSig;
|
|
unsigned int FSI_Free_Count;
|
|
unsigned int FSI_Nxt_Free;
|
|
unsigned char FSI_Reserved2[12];
|
|
unsigned int FSI_TailSig;
|
|
} __attribute__((packed));
|
|
|
|
struct fat_dir {
|
|
char DIR_Name[11];
|
|
unsigned char DIR_Attribute;
|
|
unsigned char DIR_NTRes;
|
|
unsigned char DIR_CrtTimeTenth;
|
|
char DIR_Res[6];
|
|
unsigned short DIR_FirstClustHi;
|
|
unsigned short DIR_WrtTime;
|
|
unsigned short DIR_WrtDate;
|
|
unsigned short DIR_FirstClustLo;
|
|
unsigned int DIR_FileSize;
|
|
}__attribute__((packed));
|
|
|
|
struct fat_long_dir {
|
|
unsigned char LDIR_Ord;
|
|
short LDIR_Name1[5];
|
|
unsigned char LDIR_Attrib;
|
|
unsigned char LDIR_Type;
|
|
unsigned char LDIR_Chksum;
|
|
short LDIR_Name2[6];
|
|
unsigned short LDIR_FirstClustLo;
|
|
short LDIR_Name3[2];
|
|
}__attribute__((packed));
|
|
|
|
struct fat_data {
|
|
struct BPB superblock;
|
|
unsigned char fat;
|
|
unsigned int fat_size;
|
|
unsigned int root_dir_sectors;
|
|
unsigned int totsec;
|
|
unsigned int first_data_sec;
|
|
unsigned int data_sec;
|
|
unsigned int count_of_clusters;
|
|
};
|
|
|
|
struct fat_file_info {
|
|
unsigned int start_cluster;
|
|
unsigned int *clusterchain;
|
|
unsigned int file_size;
|
|
unsigned char type;
|
|
unsigned int atime;
|
|
unsigned int ctime;
|
|
unsigned int mtime;
|
|
unsigned char dirty;
|
|
};
|
|
|
|
#define ATTR_READ_ONLY 0x01
|
|
#define ATTR_HIDDEN 0x02
|
|
#define ATTR_SYSTEM 0x04
|
|
#define ATTR_VOLUME_ID 0x08
|
|
#define ATTR_DIRECTORY 0x10
|
|
#define ATTR_ARCHIVE 0x20
|
|
#define ATTR_LONG_NAME (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)
|
|
#define ATTR_LONG_NAME_MASK (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID | ATTR_DIRECTORY | ATTR_ARCHIVE)
|
|
|
|
extern int fat_load_superblock(struct vfs_device_t *device);
|
|
extern unsigned int fat_read_entire_file(struct vfs_device_t *device, unsigned int start_cluster, char **buffer);
|
|
extern struct fat_file_info *fat_check_if_exists(struct vfs_device_t *device, char *path, int type);
|
|
extern int fat_get_dents(struct vfs_device_t *device, struct fat_file_info *info, char *buffer, int len, unsigned long long offset, unsigned long long *newoffset);
|
|
extern int fat_create_directory(struct vfs_device_t *device, char *path);
|
|
extern int fat_write_data(struct vfs_device_t *device, struct fat_file_info *info, char *filename, char *buffer, int len, unsigned long long offset);
|
|
extern int fat_trunc_file(struct vfs_device_t *device, struct fat_file_info *info, char *filename);
|
|
extern int fat_create_file(struct vfs_device_t *device, char *path);
|
|
extern int fat_read_data(struct vfs_device_t *device, struct fat_file_info *info, char *buffer, int len, unsigned long long offset);
|
|
extern int fat_change_directory(struct vfs_device_t *device, char *path);
|
|
#endif
|