-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
GPTDiskAddOn.cpp
155 lines (119 loc) · 3.26 KB
/
GPTDiskAddOn.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include "GPTDiskAddOn.h"
#include <new>
#include <stdio.h>
#include <DiskDeviceTypes.h>
#include <MutablePartition.h>
#include <PartitioningInfo.h>
#include <PartitionParameterEditor.h>
#include <AutoDeleter.h>
#include <disk_device_types.h>
#include "efi_gpt.h"
#include "GPTPartitionHandle.h"
#include "Utility.h"
//#define TRACE_GPT_DISK_ADD_ON
#undef TRACE
#ifdef TRACE_GPT_DISK_ADD_ON
# define TRACE(x...) printf(x)
#else
# define TRACE(x...) do {} while (false)
#endif
static const uint32 kDiskSystemFlags =
0
// | B_DISK_SYSTEM_SUPPORTS_CHECKING
// | B_DISK_SYSTEM_SUPPORTS_REPAIRING
// | B_DISK_SYSTEM_SUPPORTS_RESIZING
// | B_DISK_SYSTEM_SUPPORTS_MOVING
// | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME
// | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
| B_DISK_SYSTEM_SUPPORTS_INITIALIZING
// | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
// | B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD
// | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD
// | B_DISK_SYSTEM_SUPPORTS_SETTING_NAME
| B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE
// | B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS
| B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD
| B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD
// | B_DISK_SYSTEM_SUPPORTS_NAME
;
// #pragma mark - GPTDiskAddOn
GPTDiskAddOn::GPTDiskAddOn()
:
BDiskSystemAddOn(EFI_PARTITION_NAME, kDiskSystemFlags)
{
}
GPTDiskAddOn::~GPTDiskAddOn()
{
}
status_t
GPTDiskAddOn::CreatePartitionHandle(BMutablePartition* partition,
BPartitionHandle** _handle)
{
GPTPartitionHandle* handle
= new(std::nothrow) GPTPartitionHandle(partition);
if (handle == NULL)
return B_NO_MEMORY;
status_t error = handle->Init();
if (error != B_OK) {
delete handle;
return error;
}
*_handle = handle;
return B_OK;
}
bool
GPTDiskAddOn::CanInitialize(const BMutablePartition* partition)
{
// If it's big enough, we can initialize it.
return partition->Size() >= round_up(partition->BlockSize()
+ EFI_PARTITION_ENTRY_COUNT * EFI_PARTITION_ENTRY_SIZE,
partition->BlockSize());
}
status_t
GPTDiskAddOn::GetInitializationParameterEditor(
const BMutablePartition* partition, BPartitionParameterEditor** editor)
{
// Nothing to edit, really.
*editor = NULL;
return B_OK;
}
status_t
GPTDiskAddOn::ValidateInitialize(const BMutablePartition* partition,
BString* name, const char* parameters)
{
if (!CanInitialize(partition)
|| (parameters != NULL && parameters[0] != '\0'))
return B_BAD_VALUE;
// we don't support a content name
if (name != NULL)
name->Truncate(0);
return B_OK;
}
status_t
GPTDiskAddOn::Initialize(BMutablePartition* partition, const char* name,
const char* parameters, BPartitionHandle** _handle)
{
if (!CanInitialize(partition)
|| (name != NULL && name[0] != '\0')
|| (parameters != NULL && parameters[0] != '\0'))
return B_BAD_VALUE;
GPTPartitionHandle* handle
= new(std::nothrow) GPTPartitionHandle(partition);
if (handle == NULL)
return B_NO_MEMORY;
status_t status = partition->SetContentType(Name());
if (status != B_OK) {
delete handle;
return status;
}
partition->SetContentName(NULL);
partition->SetContentParameters(NULL);
partition->SetContentSize(
round_down(partition->Size(), partition->BlockSize()));
*_handle = handle;
return B_OK;
}