/************************************************************************/
/*									*/
/* fat.h								*/
/* FAT File System Definitions						*/
/*									*/
/* Version 1.0								*/
/*									*/
/* Written by Bob Herlien (rah)						*/
/* 									*/
/************************************************************************/

#ifndef	FAT_H 
#define	FAT_H 

#define SECTOR_SIZE	512
#define DIR_ENTRY_SIZE	 32

#ifndef UInt8
#define UInt8	unsigned char
#endif
#ifndef UInt16
#define UInt16	unsigned short
#endif
#ifndef UInt32
#define UInt32	unsigned long
#endif

typedef struct			/****************************************/
{				/* Partition Table struct of MBR	*/
  UInt8		state;		/* 00 = inactive, 80h = active		*/
  UInt8		startHead;	/* Beginning of Partition - Head	*/
  UInt16	startCylSect;	/* Beginning of Partition - Cyl/Sector	*/
  UInt8		partType;	/* 00=Unk, 01=FAT12, 04=FAT16 < 32 MB	*/
				/* 05=Extended, 06= FAT16 > 32 MB	*/
				/* 0B=FAT32, 0C=FAT32 LBA, 0E=FAT16 LBA	*/
			 	/* 0F=Extended MSDOS LBA		*/
  UInt8		endHead;	/* End of Partition - Head		*/
  UInt16	endCylSect;	/* End of Partition - Cyl/Sector	*/
  UInt32	sectStartOffset; /* Num Sectors between MBR & partition start*/
  UInt32	numSects;	/* Num Sectors in partition		*/
} PartitionTable;		/****************************************/

typedef struct			/****************************************/
{				/* Master Boot Record			*/
  char		bootcode[446];	/* Boot code				*/
  PartitionTable partition[4];	/* Four Partition Tables		*/
  UInt16       	signature;	/* Must be 55AAh (Intel order)		*/
} MBR;				/****************************************/

typedef struct			/****************************************/
{				/* FAT16 Boot Record			*/
  char		jmpcode[3];	/* Jump to boot code			*/
  char		OEMname[8];	/* OEM Name				*/
  UInt8		bytesPerSect_low; /* Low byte of Bytes per sector	*/
  UInt8		bytesPerSect_hi;  /* High byte of Bytes per sector	*/
  UInt8		sectorsPerCluster;/* Sectors per cluster		*/
  UInt16	reservedSectors;  /* Reserved Sectors			*/
  UInt8		numberOfFats;	  /* Number of FATs			*/
  UInt8		rootDirEntries_low; /* Low byte of # of root dir entries*/
  UInt8		rootDirEntries_hi;  /* Hi byte of # of root dir entries	*/
  UInt8		sectorsSmall_low;   /* Low byte of # sects in partition < 32 MB*/
  UInt8		sectorsSmall_hi;    /* High byte of # sects in part < 32 MB*/
  UInt8		mediaDescriptor;  /* Media descriptor byte		*/
  UInt16	sectorsPerFat;	  /* Sectors per FAT			*/
  UInt16	sectorsPerTrack;  /* Sectors per Track			*/
  UInt16	numberHeads;	/* Number of heads			*/
  UInt32	hiddenSectors;	/* Number of hidden sectors in Partition*/
  UInt32	numberSectors;	/* Number of sectors in Partition	*/
  UInt16	logicalDrive;	/* Logical drive number of partition	*/
  UInt8		extSignature;	/* Extended signature (s/b 0x29)	*/
  char		serialNumber[4];/* Serial number of partition		*/
  char		volumeName[11];	/* Volume Name				*/
  char		fatName[8];	/* FAT Name (FAT16)			*/
  char		bootcode[448];	/* Boot code				*/
  UInt16	signature;	/* Must be 55AAh (Intel order)		*/
} Fat16BR;			/*************************************((*/

#endif	/* FAT_H */
