BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / partitioning_systems / gpt / Header.h
blob64566d08b2ee6559ad4f763b8804112e535fd372
1 /*
2 * Copyright 2007-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch. All rights reserved.
5 * Distributed under the terms of the MIT License.
6 */
7 #ifndef GPT_HEADER_H
8 #define GPT_HEADER_H
11 #include "efi_gpt.h"
14 namespace EFI {
17 class Header {
18 public:
19 Header(int fd, uint64 lastBlock,
20 uint32 blockSize);
21 #ifndef _BOOT_MODE
22 // constructor for empty header
23 Header(uint64 lastBlock, uint32 blockSize);
24 #endif
25 ~Header();
27 status_t InitCheck() const;
29 uint64 FirstUsableBlock() const
30 { return fHeader.FirstUsableBlock(); }
31 uint64 LastUsableBlock() const
32 { return fHeader.LastUsableBlock(); }
34 uint32 EntryCount() const
35 { return fHeader.EntryCount(); }
36 efi_partition_entry& EntryAt(int32 index) const
37 { return *(efi_partition_entry*)(fEntries
38 + fHeader.EntrySize() * index); }
40 #ifndef _BOOT_MODE
41 status_t WriteEntry(int fd, uint32 entryIndex);
42 status_t Write(int fd);
43 #endif
45 private:
46 #ifndef _BOOT_MODE
47 status_t _WriteHeader(int fd);
48 status_t _Write(int fd, off_t offset, const void* data,
49 size_t size) const;
50 void _UpdateCRC();
51 void _UpdateCRC(efi_table_header& header);
52 #endif
54 status_t _Read(int fd, off_t offset, void* data,
55 size_t size) const;
56 static bool _IsHeaderValid(efi_table_header& header,
57 uint64 block);
58 static bool _ValidateHeaderCRC(efi_table_header& header);
59 bool _ValidateEntriesCRC() const;
60 void _SetBackupHeaderFromPrimary(uint64 lastBlock);
61 size_t _EntryArraySize() const
62 { return fHeader.EntrySize()
63 * fHeader.EntryCount(); }
65 const char* _PrintGUID(const guid_t& id);
66 void _Dump(const efi_table_header& header);
67 void _DumpPartitions();
69 private:
70 uint32 fBlockSize;
71 status_t fStatus;
72 efi_table_header fHeader;
73 efi_table_header fBackupHeader;
74 uint8* fEntries;
78 } // namespace EFI
81 #endif // GPT_HEADER_H