2024年Linux最全【嵌入式Linux】MBR分区表 和 GPT分区表_gpt_code 0xee

            reserved,
            my_lba,
            alternate_lba,
            first_usable_lba,
            last_usable_lba,
            disk_guid,
            partition_entry_lba,
            number_of_partition_entries,
            size_of_partition_entry,
            partition_entry_array_crc32):
    self.signature = signature
    self.revision = revision
    self.header_size = header_size
    self.header_crc32 = header_crc32
    self.reserved = reserved
    self.my_lba = my_lba
    self.alternate_lba = alternate_lba
    self.first_usable_lba = first_usable_lba
    self.last_usable_lba = last_usable_lba
    self.disk_guid = disk_guid
    self.partition_entry_lba = partition_entry_lba
    self.number_of_partition_entries = number_of_partition_entries
    self.size_of_partition_entry = size_of_partition_entry
    self.partition_of_entry_array_crc32 = partition_entry_array_crc32 

def is\_valid(self):
    return self.signature == 'EFI PART'.encode('ascii')

def calculate\_header\_crc32(self):
    header_crc32_input = pack('<8s 4s I I 4s Q Q Q Q 16s Q I I I',
                                  self.signature,
                                  self.revision,
                                  self.header_size,
                                  0,
                                  self.reserved,
                                  self.my_lba,
                                  self.alternate_lba,
                                  self.first_usable_lba,
                                  self.last_usable_lba,
                                  self.disk_guid,
                                  self.partition_entry_lba,
                                  self.number_of_partition_entries,
                                  self.size_of_partition_entry,
                                  self.partition_entry_array_crc32)
    return binascii.crc32(header_crc32_input) & 0xffffffff

def encode_gpt_header(gpt_header):
data = pack(
‘< 8s 4s I I 4s Q Q Q Q 16s Q I I I’,
gpt_header.signature,
gpt_header.revision,
gpt_header.header_size,
gpt_header.header_crc32,
gpt_header.reserved,
gpt_header.my_lba,
gpt_header.alternate_lba,
gpt_header.first_usable_lba,
gpt_header.last_usable_lba,
gpt_header.disk_guid,
gpt_header.partition_entry_lba,
gpt_header.number_of_partition_entries,
gpt_header.size_of_partition_entry,
gpt_header.partition_entry_array_crc32)
return data

def decode_gpt_header(gpt_header):
(signature,
revision,
header_size,
header_crc32,
reserved,
my_lba,
alternate_lba,
first_usable_lba,
last_usable_lba,
disk_guid,
partition_entry_lba,
number_of_partition_entrires,
size_of_partition_entry,
partition_entry_array_crc32) = unpack(
‘< 8s 4s I I 4s Q Q Q Q 16s Q I I I’,
data[0:92]
)
gpt_header = GPTheader(signature,
revision,
header_size,
header_crc32,
reserved,
my_lba,
alternate_lba,
first_usable_lba,
last_usable_lba,
disk_guid,
partition_entry_lba,
number_of_partition_entries,
size_of_partition_entry,
partition_entry_array_crc32)
return gpt_header

def create_empty_gpt_entry():
partition_type_guid = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
unique_partition_guid = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
starting_lba = 0
ending_lba = 0
attributes = 0
partition_name = “\x00\x00”.encode(‘utf-16’)[2:]
print(partition_name)

entry = GPTPartitionEntry(partition_type_guid, unique_partition_guid,
                            starting_lba,
                            ending_lba,
                            attributes,
                            partition_name)
return entry

def create_gpt_entry(start_lba, end_lba, name):
partition_type_guid = uuid.uuid4().bytes
unique_partition_guid = uuid.uuid4().bytes
starting_lba = start_lba
ending_lba = end_lba
attributes = 0
partition_name = name.decode(“utf-8”).encode(‘utf-16’)[2:]

entry = GPTPartitionEntry(partition_type_guid,
                          unique_partition_guid,
                          starting_lba,
                          ending_lba,
                          attributes,
                          partition_name)
return entry

def complete_gpt_entries(entrylist):
an = create_empty_gpt_entry()
for i in range(len(entrylist), 0x80, 1):
entrylist.append(an)

def create_gpt_header(current_lba):
signature = b"EFI PART"
revision = b"\x00\x00\x01\x00"
header_size = 0x5c
header_crc32 = 0
reserved = b"\x00\x00\x00\x00&

  • 22
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值