luxos/Kernel/hal/filesys/fat/fat.h

138 lines
3.8 KiB
C
Raw Permalink Normal View History

/*
* fat.h
*
* Created on: Aug 31, 2011
* Author: Tiberiu
*/
#ifdef NEVER
#ifndef FAT_H_
#define FAT_H_
#include <fileio.h>
/*******************************************************
* FAT: Bios Parameter Block *
*******************************************************/
typedef struct {
uint8 AsmJmp[3];
char OemId[8];
uint16 BytesPerSector;
uint8 SectorsPerCluster;
uint16 ReservedSectors;
uint8 FatsCount;
uint16 DirectoryEntriesCount;
uint16 TotalSectors;
uint8 MediaDescriptorType;
uint32 SectorsPerFat;
uint16 SectorsPerTrack;
uint16 Heads;
uint32 HiddenSectors;
uint32 TotalSectorsLarge;
} __attribute__((packed)) FatBiosParameterBlock ;
/*******************************************************
* FAT12/FAT16: Extended boot record *
*******************************************************/
typedef struct {
uint8 DriveNumber; // Useless
uint8 NtFlags;
uint8 Signature; // Must be 0x28/0x29
uint32 VolumeIdSerial;
char VolumeLabel[11];
char SystemId[8];
} __attribute__((packed)) Fat16ExtendedBootRecord; // fat12 or 16
/*******************************************************
* FAT32: Extended boot record *
*******************************************************/
typedef struct {
uint32 SectorsPerFat;
uint16 Flags;
uint16 FatVersion; // High byte=major version, low=minor
uint32 RootDirectoryCluster;
uint16 FsInfoCluster;
uint16 BackupBootSectorCluster;
uint8 Reserved[12]; // Should be set to 0 when formatting
uint8 DriveNumber;
uint8 NtFlags;
uint8 Signature; // Must be 0x28/0x29
uint32 VolumeIdSerial;
char VolumeLabel[11];
char SystemId[8]; // Always "FAT32 "
} __attribute__((packed)) Fat32ExtendedBootRecord;
/*******************************************************
* FAT: Extended boot record (union of above 2 fields) *
*******************************************************/
union FatExtendedBootRecord
{
Fat16ExtendedBootRecord fat16;
Fat32ExtendedBootRecord fat32;
};
/*******************************************************
* FAT: Complete boot sector info *
*******************************************************/
typedef struct {
FatBiosParameterBlock bpb;
union FatExtendedBootRecord ext;
} __attribute__((packed)) FatBootSector;
/*******************************************************
* FAT: Directory entry *
*******************************************************/
typedef struct {
char FileName[8];
char FileExt[3];
uint8 Attributes;
uint8 _reserved;
uint8 CreateTimeFine; // hundreds (0.01) of a second, up to 199
uint16 CreateTime; // 15-11 hour; 10-5 mins; 4-0 secs/2;
uint16 CreateDate; // 15-9 year (since 1980); 8-5 mon; 4-0 day
uint16 AccessDate;
uint16 FirstClusterHigh; // Fat32; EA-index in fat12,fat16
uint16 LastModifiedTime;
uint16 LastModifiedDate;
uint16 FirstClusterLow;
uint32 Size;
} __attribute__((packed)) FatDirectoryEntry;
/*******************************************************
* FAT: Long file name entry *
*******************************************************/
typedef struct {
uint8 SequenceNo;
uint16 Name1[5]; // Encoded in UTF-16
uint8 Attributes; // Should be 0xF;
uint8 _reserved;
uint16 Name2[6];
uint16 FirstCluster;// Should be 0x0000
uint16 Name3[2];
} FatLongFileName;
/*******************************************************
* FAT: Directory entry (union of above 2 fields) *
*******************************************************/
union FatDirEntryUnion {
FatDirectoryEntry d;
FatLongFileName lfn;
};
extern uint32 FatDetect (void* buffer);
extern void FatInstall();
extern uint32 Fat12Detect (DevReadRoutine r, uint32 blocksz);
extern uint32 Fat16Detect (DevReadRoutine r, uint32 blocksz);
extern uint32 Fat32Detect (DevReadRoutine r, uint32 blocksz);
#endif /* FAT_H_ */
#endif