vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / partitioning_systems / gpt / Header.h
blob458f9f7df9dff23db886c5ae53fa257e0bcceb28
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;
28 bool IsDirty() const;
30 uint64 FirstUsableBlock() const
31 { return fHeader.FirstUsableBlock(); }
32 uint64 LastUsableBlock() const
33 { return fHeader.LastUsableBlock(); }
34 const efi_table_header& TableHeader() const
35 { return fHeader; }
37 uint32 EntryCount() const
38 { return fHeader.EntryCount(); }
39 efi_partition_entry& EntryAt(int32 index) const
40 { return *(efi_partition_entry*)(fEntries
41 + fHeader.EntrySize() * index); }
43 #ifndef _BOOT_MODE
44 status_t WriteEntry(int fd, uint32 entryIndex);
45 status_t Write(int fd);
46 #endif
48 private:
49 #ifndef _BOOT_MODE
50 status_t _WriteHeader(int fd);
51 status_t _Write(int fd, off_t offset, const void* data,
52 size_t size) const;
53 void _UpdateCRC();
54 void _UpdateCRC(efi_table_header& header);
55 #endif
57 status_t _Read(int fd, off_t offset, void* data,
58 size_t size) const;
59 static bool _IsHeaderValid(efi_table_header& header,
60 uint64 block);
61 static bool _ValidateHeaderCRC(efi_table_header& header);
62 bool _ValidateEntriesCRC() const;
63 void _SetBackupHeaderFromPrimary(uint64 lastBlock);
64 size_t _EntryArraySize() const
65 { return fHeader.EntrySize()
66 * fHeader.EntryCount(); }
68 const char* _PrintGUID(const guid_t& id);
69 void _Dump(const efi_table_header& header);
70 void _DumpPartitions();
72 private:
73 uint32 fBlockSize;
74 status_t fStatus;
75 efi_table_header fHeader;
76 efi_table_header fBackupHeader;
77 uint8* fEntries;
78 bool fDirty;
82 } // namespace EFI
85 #endif // GPT_HEADER_H