summaryrefslogtreecommitdiff
path: root/libinstaller/syslxint.h
diff options
context:
space:
mode:
Diffstat (limited to 'libinstaller/syslxint.h')
-rw-r--r--libinstaller/syslxint.h98
1 files changed, 87 insertions, 11 deletions
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index 80c40f76..e5428b79 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -2,6 +2,7 @@
*
* Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin
+ * Copyright 2011 Paulo Alcantara <pcacjr@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +23,17 @@
# define X86_MEM 0
#endif
+#ifdef __GNUC__
+# ifdef __MINGW32__
+ /* gcc 4.7 miscompiles packed structures in MS-bitfield mode */
+# define PACKED __attribute__((packed,gcc_struct))
+# else
+# define PACKED __attribute__((packed))
+# endif
+#else
+# error "Need to define PACKED for this compiler"
+#endif
+
/*
* Access functions for littleendian numbers, possibly misaligned.
*/
@@ -189,10 +201,10 @@ struct ext_patch_area {
struct syslinux_extent {
uint64_t lba;
uint16_t len;
-} __attribute__((packed));
+} PACKED;
/* FAT bootsector format, also used by other disk-based derivatives */
-struct boot_sector {
+struct fat_boot_sector {
uint8_t bsJump[3];
char bsOemName[8];
uint16_t bsBytesPerSec;
@@ -217,7 +229,7 @@ struct boot_sector {
char VolumeLabel[11];
char FileSysType[8];
uint8_t Code[442];
- } __attribute__ ((packed)) bs16;
+ } PACKED bs16;
struct {
uint32_t FATSz32;
uint16_t ExtFlags;
@@ -233,18 +245,82 @@ struct boot_sector {
char VolumeLabel[11];
char FileSysType[8];
uint8_t Code[414];
- } __attribute__ ((packed)) bs32;
- } __attribute__ ((packed));
+ } PACKED bs32;
+ } PACKED;
uint32_t bsMagic;
uint16_t bsForwardPtr;
uint16_t bsSignature;
-} __attribute__ ((packed));
+} PACKED;
-#define bsHead bsJump
-#define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec)
-#define bsCode bs32.Code /* The common safe choice */
-#define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
- offsetof(struct boot_sector, bsCode))
+/* NTFS bootsector format */
+struct ntfs_boot_sector {
+ uint8_t bsJump[3];
+ char bsOemName[8];
+ uint16_t bsBytesPerSec;
+ uint8_t bsSecPerClust;
+ uint16_t bsResSectors;
+ uint8_t bsZeroed_0[3];
+ uint16_t bsZeroed_1;
+ uint8_t bsMedia;
+ uint16_t bsZeroed_2;
+ uint16_t bsUnused_0;
+ uint16_t bsUnused_1;
+ uint32_t bsUnused_2;
+ uint32_t bsZeroed_3;
+ uint32_t bsUnused_3;
+ uint64_t bsTotalSectors;
+ uint64_t bsMFTLogicalClustNr;
+ uint64_t bsMFTMirrLogicalClustNr;
+ uint8_t bsClustPerMFTrecord;
+ uint8_t bsUnused_4[3];
+ uint8_t bsClustPerIdxBuf;
+ uint8_t bsUnused_5[3];
+ uint64_t bsVolSerialNr;
+ uint32_t bsUnused_6;
+
+ uint8_t Code[420];
+
+ uint32_t bsMagic;
+ uint16_t bsForwardPtr;
+ uint16_t bsSignature;
+} PACKED;
+
+#define FAT_bsHead bsJump
+#define FAT_bsHeadLen offsetof(struct fat_boot_sector, bsBytesPerSec)
+#define FAT_bsCode bs32.Code /* The common safe choice */
+#define FAT_bsCodeLen (offsetof(struct fat_boot_sector, bsSignature) - \
+ offsetof(struct fat_boot_sector, FAT_bsCode))
+
+#define NTFS_bsHead bsJump
+#define NTFS_bsHeadLen offsetof(struct ntfs_boot_sector, bsOemName)
+#define NTFS_bsCode Code
+#define NTFS_bsCodeLen (offsetof(struct ntfs_boot_sector, bsSignature) - \
+ offsetof(struct ntfs_boot_sector, NTFS_bsCode))
+
+/* Check if there are specific zero fields in an NTFS boot sector */
+static inline int ntfs_check_zero_fields(const struct ntfs_boot_sector *sb)
+{
+ return !sb->bsResSectors && (!sb->bsZeroed_0[0] && !sb->bsZeroed_0[1] &&
+ !sb->bsZeroed_0[2]) && !sb->bsZeroed_1 && !sb->bsZeroed_2 &&
+ !sb->bsZeroed_3;
+}
+
+static inline int ntfs_check_sb_fields(const struct ntfs_boot_sector *sb)
+{
+ return ntfs_check_zero_fields(sb) &&
+ (!memcmp(sb->bsOemName, "NTFS ", 8) ||
+ !memcmp(sb->bsOemName, "MSWIN4.0", 8) ||
+ !memcmp(sb->bsOemName, "MSWIN4.1", 8));
+}
+
+static inline int fat_check_sb_fields(const struct fat_boot_sector *sb)
+{
+ return sb->bsResSectors && sb->bsFATs &&
+ (!memcmp(sb->bs16.FileSysType, "FAT12 ", 8) ||
+ !memcmp(sb->bs16.FileSysType, "FAT16 ", 8) ||
+ !memcmp(sb->bs16.FileSysType, "FAT ", 8) ||
+ !memcmp(sb->bs32.FileSysType, "FAT32 ", 8));
+}
#endif /* SYSLXINT_H */