#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
+#include <pshpack1.h>
struct _BootSector
{
unsigned char magic0, res0, magic1;
unsigned char VolumeLabel[11], SysType[8];
unsigned char Res2[448];
unsigned short Signatur1;
-} __attribute__((packed));
+};
struct _BootSector32
{
unsigned char VolumeLabel[11], SysType[8]; // 71
unsigned char Res2[420]; // 90
unsigned short Signature1; // 510
-} __attribute__((packed));
+};
struct _BootSectorFatX
{
unsigned short FATCount; // 12
unsigned long Unknown; // 14
unsigned char Unused[4078]; // 18
-} __attribute__((packed));
+};
struct _FsInfoSector
{
unsigned long NextCluster; // 492
unsigned char Res7[12]; // 496
unsigned long Signatur2; // 508
-} __attribute__((packed));
+};
typedef struct _BootSector BootSector;
-#define VFAT_CASE_LOWER_BASE 8 // base is lower case
-#define VFAT_CASE_LOWER_EXT 16 // extension is lower case
-
-#define LONGNAME_MAX_LENGTH 256 // max length for a long filename
-
-#define ENTRY_DELETED(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_DELETED(&((DirEntry)->FatX)) : FAT_ENTRY_DELETED(&((DirEntry)->Fat)))
-#define ENTRY_VOLUME(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_VOLUME(&((DirEntry)->FatX)) : FAT_ENTRY_VOLUME(&((DirEntry)->Fat)))
-#define ENTRY_END(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_END(&((DirEntry)->FatX)) : FAT_ENTRY_END(&((DirEntry)->Fat)))
-
-#define FAT_ENTRY_DELETED(DirEntry) ((DirEntry)->Filename[0] == 0xe5)
-#define FAT_ENTRY_END(DirEntry) ((DirEntry)->Filename[0] == 0)
-#define FAT_ENTRY_LONG(DirEntry) (((DirEntry)->Attrib & 0x3f) == 0x0f)
-#define FAT_ENTRY_VOLUME(DirEntry) (((DirEntry)->Attrib & 0x1f) == 0x08)
-
-#define FATX_ENTRY_DELETED(DirEntry) ((DirEntry)->FilenameLength == 0xe5)
-#define FATX_ENTRY_END(DirEntry) ((DirEntry)->FilenameLength == 0xff)
-#define FATX_ENTRY_LONG(DirEntry) (FALSE)
-#define FATX_ENTRY_VOLUME(DirEntry) (((DirEntry)->Attrib & 0x1f) == 0x08)
-
-#define FAT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof (FAT_DIR_ENTRY))
-#define FATX_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof (FATX_DIR_ENTRY))
-
struct _FATDirEntry
{
- unsigned char Filename[8], Ext[3];
+ union
+ {
+ struct { unsigned char Filename[8], Ext[3]; };
+ unsigned char ShortName[11];
+ };
unsigned char Attrib;
unsigned char lCase;
unsigned char CreationTimeMs;
unsigned short UpdateDate; //date create/update
unsigned short FirstCluster;
unsigned long FileSize;
-} __attribute__((packed));
+};
typedef struct _FATDirEntry FAT_DIR_ENTRY, *PFAT_DIR_ENTRY;
unsigned short CreationDate; // 58
unsigned short AccessTime; // 60
unsigned short AccessDate; // 62
-} __attribute__((packed));
-
-typedef struct _FATXDirEntry FATX_DIR_ENTRY, *PFATX_DIR_ENTRY;
-
-union _DIR_ENTRY
-{
- FAT_DIR_ENTRY Fat;
- FATX_DIR_ENTRY FatX;
};
-typedef union _DIR_ENTRY DIR_ENTRY, *PDIR_ENTRY;
-
struct _slot
{
unsigned char id; // sequence number for slot
WCHAR name5_10[6]; // 6 more characters in name
unsigned char start[2]; // starting cluster number
WCHAR name11_12[2]; // last 2 characters in name
-} __attribute__((packed));
-
+};
typedef struct _slot slot;
+#include <poppack.h>
+
+#define VFAT_CASE_LOWER_BASE 8 // base is lower case
+#define VFAT_CASE_LOWER_EXT 16 // extension is lower case
+
+#define LONGNAME_MAX_LENGTH 256 // max length for a long filename
+
+#define ENTRY_DELETED(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_DELETED(&((DirEntry)->FatX)) : FAT_ENTRY_DELETED(&((DirEntry)->Fat)))
+#define ENTRY_VOLUME(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_VOLUME(&((DirEntry)->FatX)) : FAT_ENTRY_VOLUME(&((DirEntry)->Fat)))
+#define ENTRY_END(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_END(&((DirEntry)->FatX)) : FAT_ENTRY_END(&((DirEntry)->Fat)))
+
+#define FAT_ENTRY_DELETED(DirEntry) ((DirEntry)->Filename[0] == 0xe5)
+#define FAT_ENTRY_END(DirEntry) ((DirEntry)->Filename[0] == 0)
+#define FAT_ENTRY_LONG(DirEntry) (((DirEntry)->Attrib & 0x3f) == 0x0f)
+#define FAT_ENTRY_VOLUME(DirEntry) (((DirEntry)->Attrib & 0x1f) == 0x08)
+
+#define FATX_ENTRY_DELETED(DirEntry) ((DirEntry)->FilenameLength == 0xe5)
+#define FATX_ENTRY_END(DirEntry) ((DirEntry)->FilenameLength == 0xff)
+#define FATX_ENTRY_LONG(DirEntry) (FALSE)
+#define FATX_ENTRY_VOLUME(DirEntry) (((DirEntry)->Attrib & 0x1f) == 0x08)
+
+#define FAT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof (FAT_DIR_ENTRY))
+#define FATX_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof (FATX_DIR_ENTRY))
+
+typedef struct _FATXDirEntry FATX_DIR_ENTRY, *PFATX_DIR_ENTRY;
+
+union _DIR_ENTRY
+{
+ FAT_DIR_ENTRY Fat;
+ FATX_DIR_ENTRY FatX;
+};
+
+typedef union _DIR_ENTRY DIR_ENTRY, *PDIR_ENTRY;
+
#define BLOCKSIZE 512
#define FAT16 (1)