-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
GPTPartitionHandle.cpp
162 lines (125 loc) · 3.34 KB
/
GPTPartitionHandle.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
156
157
158
159
160
161
162
/*
* Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include "GPTPartitionHandle.h"
#include <new>
#include <stdio.h>
#include <DiskDeviceTypes.h>
#include <MutablePartition.h>
#include <PartitioningInfo.h>
#include <PartitionParameterEditor.h>
#include <AutoDeleter.h>
#include "gpt_known_guids.h"
//#define TRACE_GPT_PARTITION_HANDLE
#undef TRACE
#ifdef TRACE_GPT_PARTITION_HANDLE
# define TRACE(x...) printf(x)
#else
# define TRACE(x...) do {} while (false)
#endif
GPTPartitionHandle::GPTPartitionHandle(BMutablePartition* partition)
:
BPartitionHandle(partition)
{
}
GPTPartitionHandle::~GPTPartitionHandle()
{
}
status_t
GPTPartitionHandle::Init()
{
return B_OK;
}
uint32
GPTPartitionHandle::SupportedOperations(uint32 mask)
{
uint32 flags = B_DISK_SYSTEM_SUPPORTS_RESIZING
| B_DISK_SYSTEM_SUPPORTS_MOVING
| B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
| B_DISK_SYSTEM_SUPPORTS_INITIALIZING;
// creating child
if ((mask & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) != 0) {
BPartitioningInfo info;
if (GetPartitioningInfo(&info) == B_OK
&& info.CountPartitionableSpaces() > 1) {
flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD;
}
}
return flags;
}
uint32
GPTPartitionHandle::SupportedChildOperations(const BMutablePartition* child,
uint32 mask)
{
return B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD
| B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD
| B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE
| B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD;
}
status_t
GPTPartitionHandle::GetNextSupportedType(const BMutablePartition* child,
int32* cookie, BString* type)
{
int32 index = *cookie;
TRACE("GPTPartitionHandle::GetNextSupportedType(child: %p, cookie: %ld)\n",
child, index);
if (index >= int32(sizeof(kTypeMap) / sizeof(kTypeMap[0])))
return B_ENTRY_NOT_FOUND;
type->SetTo(kTypeMap[index].type);
*cookie = index + 1;
return B_OK;
}
status_t
GPTPartitionHandle::GetPartitioningInfo(BPartitioningInfo* info)
{
// init to the full size (minus the first sector)
off_t size = Partition()->ContentSize();
status_t status = info->SetTo(Partition()->BlockSize(),
size - Partition()->BlockSize());
if (status != B_OK)
return status;
// Exclude the space of the existing partitions
size_t count = Partition()->CountChildren();
for (size_t index = 0; index < count; index++) {
BMutablePartition* child = Partition()->ChildAt(index);
status = info->ExcludeOccupiedSpace(child->Offset(), child->Size());
if (status != B_OK)
return status;
}
return B_OK;
}
status_t
GPTPartitionHandle::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
BPartitionParameterEditor** editor)
{
*editor = NULL;
if (type == B_CREATE_PARAMETER_EDITOR) {
try {
*editor = new BPartitionParameterEditor();
} catch (std::bad_alloc) {
return B_NO_MEMORY;
}
return B_OK;
}
return B_NOT_SUPPORTED;
}
status_t
GPTPartitionHandle::ValidateCreateChild(off_t* _offset, off_t* _size,
const char* typeString, BString* name, const char* parameters)
{
return B_BAD_VALUE;
}
status_t
GPTPartitionHandle::CreateChild(off_t offset, off_t size,
const char* typeString, const char* name, const char* parameters,
BMutablePartition** _child)
{
return B_BAD_VALUE;
}
status_t
GPTPartitionHandle::DeleteChild(BMutablePartition* child)
{
BMutablePartition* parent = child->Parent();
return parent->DeleteChild(child);
}