/* gpt.h -- GPT and data structure definitions, types, and
functions */
/* This program is copyright (c) 2009-2011 by Roderick W. Smith. It is distributed
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#include <stdint.h>
#include <sys/types.h>
#include "gptpart.h"
#include "support.h"
#include "mbr.h"
#include "bsd.h"
#include "gptpart.h"
#ifndef __GPTSTRUCTS
#define __GPTSTRUCTS
// Default values for sector alignment
#define DEFAULT_ALIGNMENT 2048
#define MAX_ALIGNMENT 65536
#define MIN_AF_ALIGNMENT 8
// Below constant corresponds to a ~279GiB (300GB) disk, since the
// smallest Advanced Format drive I know of is 320GB in size
#define SMALLEST_ADVANCED_FORMAT UINT64_C(585937500)
using namespace std;
/****************************************
* *
* GPTData class and related structures *
* *
****************************************/
// Validity state of GPT data
enum GPTValidity {gpt_valid, gpt_corrupt, gpt_invalid};
// Which set of partition data to use
enum WhichToUse {use_gpt, use_mbr, use_bsd, use_new, use_abort};
// Header (first 512 bytes) of GPT table
#pragma pack(1)
struct GPTHeader {
uint64_t signature;
uint32_t revision;
uint32_t headerSize;
uint32_t headerCRC;
uint32_t reserved;
uint64_t currentLBA;
uint64_t backupLBA;
uint64_t firstUsableLBA;
uint64_t lastUsableLBA;
GUIDData diskGUID;
uint64_t partitionEntriesLBA;
uint32_t numParts;
uint32_t sizeOfPartitionEntries;
uint32_t partitionEntriesCRC;
unsigned char reserved2[GPT_RESERVED];
}; // struct GPTHeader
// Data in GPT format
class GPTData {
protected:
struct GPTHeader mainHeader;
GPTPart *partitions;
uint32_t numParts; // # of partitions the table can hold
struct GPTHeader secondHeader;
MBRData protectiveMBR;
string device; // device filename
DiskIO myDisk;
uint32_t blockSize; // device block size
uint64_t diskSize; // size of device, in blocks
GPTValidity state; // is GPT valid?
int justLooking; // Set to 1 if program launched with "-l" or if read-only
int mainCrcOk;
int secondCrcOk;
int mainPartsCrcOk;
int secondPartsCrcOk;
int apmFound; // set to 1 if APM detected
int bsdFound; // set to 1 if BSD disklabel detected in MBR
uint32_t sectorAlignment; // Start partitions at multiples of sectorAlignment
int beQuiet;
WhichToUse whichWasUsed;
int LoadHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector, int *crcOk);
int LoadPartitionTable(const struct GPTHeader & header, DiskIO & disk, uint64_t sector = 0);
int CheckTable(struct GPTHeader *header);
int SaveHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector);
int SavePartitionTable(DiskIO & disk, uint64_t sector);
public:
// Basic necessary functions....
GPTData(void);
GPTData(string deviceFilename);
virtual ~GPTData(void);
GPTData & operator=(const GPTData & orig);
// Verify (or update) data integrity
int Verify(void);
int CheckGPTSize(void);
int CheckHeaderValidity(void);
int CheckHeaderCRC(struct GPTHeader* header, int warn = 0);
void RecomputeCRCs(void);
void RebuildMainHeader(void);
void RebuildSecondHeader(void);
int VerifyMBR(void) {return protectiveMBR.FindOverlaps();}
int FindHybridMismatches(void);
int FindOverlaps(void);
int FindInsanePartitions(void);
// Load or save data from/to disk
int SetDisk(const string & deviceFilename);
DiskIO* GetDisk(void) {return &myDisk;}
int LoadMBR(const string & f) {return protectiveMBR.ReadMBRData(f);}
int WriteProtectiveMBR(void) {return protectiveMBR.WriteMBRData(&myDisk);}
void PartitionScan(void);
int LoadPartitions(const string & deviceFilename);
int ForceLoadGPTData(void);
int LoadMainTable(void);
int LoadSecondTableAsMain(void);
int SaveGPTData(int quiet = 0);
int SaveGPTBackup(const string & filename);
int LoadGPTBackup(const string & filename);
int SaveMBR(void);
int DestroyGPT(void);
int DestroyMBR(void);
// Display data....
void ShowAPMState(void);
void ShowGPTState(void);
void DisplayGPTData(void);
void DisplayMBRData(void) {protectiveMBR.DisplayMBRData();}
void ShowPartDetails(uint32_t partNum);
// Convert between GPT and other formats
virtual WhichToUse UseWhichPartitions(void);
void XFormPartitions(void);
virtual int XFormDisklabel(uint32_t partNum);
int XFormDisklabel(BSDData* disklabel);
int OnePartToMBR(uint32_t gptPart, int mbrPart); // add one partition to MBR. Returns 1 if successful
// Adjust GPT structures WITHOUT user interaction...
int SetGPTSize(uint32_t numEntries);
void BlankPartitions(void);
int DeletePartition(uint32_t partNum);
uint32_t CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector);
void SortGPT(void);
int SwapPartitions(uint32_t partNum1, uint32_t partNum2);
int ClearGPTData(void);
void MoveSecondHeaderToEnd();
int SetName(uint32_t partNum, const UnicodeString & theName);
void SetDiskGUID(GUIDData newGUID);
int SetPartitionGUID(uint32_t pn, GUIDData theGUID);
void RandomizeGUIDs(void);
int ChangePartType(uint32_t pn, PartType theGUID);
void MakeProtectiveMBR(void) {protectiveMBR.MakeProtectiveMBR();}
void RecomputeCHS(void);
int Align(uint64_t* sector);
void SetProtectiveMBR(BasicMBRData & newMBR) {protectiveMBR = newMBR;}
// Return data about the GPT structures....
WhichToUse GetState(void) {return whichWasUsed;}
int GetPartRange(uint32_t* low, uint32_t* high);
int FindFirstFreePart(void);
uint32_t GetNumParts(void) {return mainHeader.numParts;}
uint64_t GetMainHeaderLBA(void) {return mainHeader.currentLBA;}
uint64_t GetSecondHeaderLBA(void) {return secondHeader.currentLBA;}
uint64_t GetMainPartsLBA(void) {return mainHeader.partitionEntriesLBA;}
uint64_t GetSecondPartsLBA(void) {return secondHeader.partitionEntriesLBA;}
uint64_t GetFirstUsableLBA(void) {return mainHeader.firstUsableLBA;}
uint64_t GetLastUsableLBA(void) {return mainHeader.lastUsableLBA;}
uint32_t CountParts(void);
bool ValidPartNum (const uint32_t partNum);
const GPTPart & operator[](uint32_t partNum) const;
const GUIDData & GetDiskGUID(void) const;
uint32_t GetBlockSize(void) {return blockSize;}
// Find information about free space
uint64_t FindFirstAvailable(uint64_t start = 0);
uint64_t FindFirstInLargest(void);
uint64_t FindLastAvailable();
uint64_t FindLastInFree(uint64_t start);
uint64_t FindFreeBlocks(uint32_t *numSegments, uint64_t *largestSegment);
int IsFree(uint64_t sector, uint32_t *partNum = NULL);
int IsFreePartNum(uint32_t partNum);
int IsUsedPartNum(uint32_t partNum);
// Change how functions work, or return information on same
void SetAlignment(uint32_t n);
uint32_t ComputeAlignment(void); // Set alignment based on current partitions
uint32_t GetAlignment(void) {return sectorAlignment;}
void JustLooking(int i = 1) {justLooking = i;}
void BeQuiet(int i = 1) {beQuiet = i;}
WhichToUse WhichWasUsed(void) {return whichWasUsed;}
// Endianness functions
void ReverseHeaderBytes(struct GPTHeader* header);
void ReversePartitionBytes(); // for endianness
// Attributes functions
int ManageAttributes(int partNum, const string & command, const string & bits);
void ShowAttributes(const uint32_t partNum);
void GetAttribute(const uint32_t partNum, const string& attributeBits);
}; // class GPTData
// Function prototypes....
int SizesOK(void);
#endif
没有合适的资源?快使用搜索试试~ 我知道了~
分区GPT fdisk源码
共63个文件
cc:21个
h:15个
o:14个
4星 · 超过85%的资源 需积分: 5 23 下载量 122 浏览量
2013-05-08
12:28:19
上传
评论
收藏 259KB RAR 举报
温馨提示
MBR分区表:(MBR含义:主引导记录) 所支持的最大卷:2T (T; terabytes,1TB=1024GB) 对分区的设限:最多4个主分区或3个主分区加一个扩展分区。 GPT分区表:(GPT含义:GUID分区表) 支持最大卷:18EB,(E:exabytes,1EB=1024TB) 每个磁盘最多支持128个分区 所以如果要大于2TB的卷或分区就必须得用GPT分区表。 Linux下fdisk工具不支持GPT。
资源推荐
资源详情
资源评论
收起资源包目录
gptfdisk-0.8.1.rar (63个子文件)
gptfdisk-0.8.1
gptcl.h 2KB
diskio-unix.o 8KB
guid.cc 7KB
sgdisk.cc 681B
support.h 2KB
gptcl.cc 22KB
gptcurses.h 4KB
current.spec 2KB
diskio-windows.cc 11KB
gpt.h 7KB
gpt.o 91KB
parttypes.o 21KB
fixparts.8 11KB
cgdisk.cc 2KB
gpt.cc 90KB
crc32.cc 2KB
mbrpart.o 12KB
mbrpart.cc 11KB
cgdisk.o 11KB
basicmbr.o 60KB
attributes.cc 7KB
guid.h 2KB
basicmbr.h 5KB
gdisk.8 28KB
fixparts.cc 4KB
README 13KB
mbr.o 8KB
gdisk.cc 2KB
gpttext.cc 32KB
bsd.h 4KB
basicmbr.cc 57KB
guid.o 7KB
support.cc 11KB
crc32.o 1KB
parttypes.cc 15KB
diskio.h 2KB
gpttext.h 2KB
Makefile.mac 1KB
sgdisk.8 26KB
mbr.cc 6KB
crc32.h 610B
parttypes.h 2KB
Makefile 1KB
attributes.h 1KB
gptcurses.cc 26KB
support.o 11KB
bsd.cc 11KB
mbrpart.h 4KB
bsd.o 15KB
NEWS 37KB
gptpart.h 3KB
diskio.o 5KB
attributes.o 14KB
gdisk_test.sh 7KB
gptpart.cc 9KB
diskio.cc 2KB
COPYING 18KB
gptpart.o 20KB
diskio-unix.cc 14KB
cgdisk.8 15KB
Makefile.freebsd 1KB
mbr.h 1KB
Makefile.mingw 1KB
共 63 条
- 1
资源评论
- 每个季节都是夏天2013-12-14了解一下分区,但是我们这种外行还真看不懂,很想了解GP5,GP6即GUITAR PRO 5和6的源代码!
- gliet5082013-10-12OK!看源码了解下分区原理
wangbinbow
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 案例分析:研发人员绩效和薪酬管理的困境.doc
- 企业中薪酬管理存在的问题分析及对策.doc
- 员工年度薪酬收入结构分析报告.doc
- 薪酬分析报告.docx
- 西门子S7-1200控制四轴伺服程序案例: 1.内容涵盖伺服,步进点动,回原,相对定位,绝对定位,速度模式控制 特别适合学习伺服和步进的朋友们 PTO伺服轴脉冲定位控制+速度模式控制+扭矩模式; 2
- 企业公司薪酬保密协议.doc
- 薪酬保密制度 (1).docx
- 薪酬保密管理规定制度.doc
- 薪酬保密制度.docx
- 薪酬保密协议书.docx
- 薪酬保密承诺书.docx
- 薪酬管理制度.doc
- 员工工资薪酬保密协议.docx
- 员工工资保密暂行管理条例.docx
- 员工薪酬保密协议.doc
- 1Redis基础认识与安装.html
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功