diff options
author | srs5694 <srs5694@users.sourceforge.net> | 2009-09-21 20:51:47 -0400 |
---|---|---|
committer | srs5694 <srs5694@users.sourceforge.net> | 2009-09-21 20:51:47 -0400 |
commit | 978041ca613dcb881763b36cf53639d924e52a56 (patch) | |
tree | bcb9e01e2c62812085a7195b0e8cc4bc20cc4c2d /mbr.h | |
parent | e35eb1beb6381977ff0dd8443d91f4569779cf2d (diff) | |
download | sgdisk-978041ca613dcb881763b36cf53639d924e52a56.tar.gz |
GPT fdisk 0.5.0
Added several features, including a restructuring of the menu system,
GPT-to-MBR conversion, and the ability to re-read the MBR to generate
a fresh GPT from the current on-disk MBR.
Diffstat (limited to 'mbr.h')
-rw-r--r-- | mbr.h | 62 |
1 files changed, 31 insertions, 31 deletions
@@ -12,9 +12,12 @@ #define __MBRSTRUCTS #define MBR_SIGNATURE UINT16_C(0xAA55) +#define MAX_HEADS 255 /* numbered 0 - 254 */ +#define MAX_SECSPERTRACK 63 /* numbered 1 - 63 */ +#define MAX_CYLINDERS 1024 /* numbered 0 - 1023 */ -// Maximum number of logical partitions supported -#define NUM_LOGICALS 124 +// Maximum number of MBR partitions +#define MAX_MBR_PARTS 128 using namespace std; @@ -36,9 +39,10 @@ struct MBRRecord { uint32_t lengthLBA; }; // struct MBRRecord -// Create a 512-byte data structure into which the MBR can be loaded in one +// A 512-byte data structure into which the MBR can be loaded in one // go, for the benefit of FreeBSD which seems to flake out when loading -// from block devices in multiples other than the block size.... +// from block devices in multiples other than the block size. +// Also used when loading logical partitions. struct TempMBR { uint8_t code[440]; uint32_t diskSignature; @@ -47,20 +51,6 @@ struct TempMBR { uint16_t MBRSignature; }; // struct TempMBR -// Extended Boot Record (EBR) data, used to hold one logical partition's -// data within an extended partition. Includes pointer to next record for -// in-memory linked-list access. This is similar to MBRData, but with a -// few tweaks.... -struct EBRRecord { - uint8_t code[446]; // generally 0s (and we don't care if they aren't) - // First partition entry defines partition; second points to next - // entry in on-disk linked list; remaining two are unused. Note that - // addresses are relative to the extended partition, not to the disk - // as a whole. - struct MBRRecord partitions[4]; - uint16_t MBRSignature; -}; // struct EBRRecord - // Possible states of the MBR enum MBRValidity {invalid, gpt, hybrid, mbr}; @@ -70,45 +60,55 @@ protected: uint8_t code[440]; uint32_t diskSignature; uint16_t nulls; - struct MBRRecord partitions[4]; + // MAX_MBR_PARTS defaults to 128. This array holds both the primary and + // the logical partitions, to simplify data retrieval for GPT conversions. + struct MBRRecord partitions[MAX_MBR_PARTS]; uint16_t MBRSignature; // Above are basic MBR data; now add more stuff.... uint32_t blockSize; // block size (usually 512) uint64_t diskSize; // size in blocks + uint64_t numHeads; // number of heads, in CHS scheme + uint64_t numSecspTrack; // number of sectors per track, in CHS scheme char device[256]; - // Now an array of partitions for the logicals, in array form (easier - // than a linked list, and good enough for the GPT itself, so....) - struct MBRRecord logicals[NUM_LOGICALS]; MBRValidity state; struct MBRRecord* GetPartition(int i); // Return primary or logical partition public: MBRData(void); MBRData(char* deviceFilename); ~MBRData(void); - // Pass EmptyMBR 1 to clear the boot loader code, 0 to leave it intact - void EmptyMBR(int clearBootloader = 1); - void SetDiskSize(uint64_t ds) {diskSize = ds;} + + // File I/O functions... int ReadMBRData(char* deviceFilename); void ReadMBRData(int fd, int checkBlockSize = 1); + int ReadLogicalPart(int fd, uint32_t extendedStart, uint32_t diskOffset, + int partNum); int WriteMBRData(void); void WriteMBRData(int fd); // ReadLogicalPart() returns last partition # read to logicals[] array, // or -1 if there was a problem.... - int ReadLogicalPart(int fd, uint32_t extendedStart, uint32_t diskOffset, - int partNum); + + // Display data for user... void DisplayMBRData(void); - void MakeProtectiveMBR(int clearBoot = 0); - MBRValidity GetValidity(void) {return state;} - void ShowValidity(void); void ShowState(void); + + // Functions that set or get disk metadata (size, CHS geometry, etc.) + void SetDiskSize(uint64_t ds) {diskSize = ds;} + MBRValidity GetValidity(void) {return state;} + void SetHybrid(void) {state = hybrid;} // Set hybrid flag + void SetCHSGeom(uint32_t h, uint32_t s); + int LBAtoCHS(uint64_t lba, uint8_t * chs); // Convert LBA to CHS + + // Functions to create, delete, or change partitions + // Pass EmptyMBR 1 to clear the boot loader code, 0 to leave it intact + void EmptyMBR(int clearBootloader = 1); + void MakeProtectiveMBR(int clearBoot = 0); void MakePart(int num, uint32_t startLBA, uint32_t lengthLBA, int type = 0x07, int bootable = 0); int MakeBiggestPart(int i, int type); // Make partition filling most space void DeletePartition(int i); int DeleteByLocation(uint64_t start64, uint64_t length64); void OptimizeEESize(void); - void SetHybrid(void) {state = hybrid;} // Set hybrid flag // Functions to find information on free space.... uint32_t FindFirstAvailable(uint32_t start = 1); |