2
libparted - a library for manipulating disk partitions
3
Copyright (C) 1999-2002, 2007-2012 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
26
#ifndef PED_DISK_H_INCLUDED
27
#define PED_DISK_H_INCLUDED
33
/* This flag (which defaults to true) controls if disk types for
34
which cylinder alignment is optional do cylinder alignment when a
35
new partition gets added.
36
This flag is available for msdos and sun disklabels (for sun labels
37
it only controls the aligning of the end of the partition) */
38
PED_DISK_CYLINDER_ALIGNMENT=1,
39
/* This flag controls whether the boot flag of a GPT PMBR is set */
40
PED_DISK_GPT_PMBR_BOOT=2,
42
#define PED_DISK_FIRST_FLAG PED_DISK_CYLINDER_ALIGNMENT
43
#define PED_DISK_LAST_FLAG PED_DISK_GPT_PMBR_BOOT
48
enum _PedPartitionType {
49
PED_PARTITION_NORMAL = 0x00,
50
PED_PARTITION_LOGICAL = 0x01,
51
PED_PARTITION_EXTENDED = 0x02,
52
PED_PARTITION_FREESPACE = 0x04,
53
PED_PARTITION_METADATA = 0x08,
54
PED_PARTITION_PROTECTED = 0x10
60
enum _PedPartitionFlag {
64
PED_PARTITION_HIDDEN=4,
68
PED_PARTITION_HPSERVICE=8,
70
PED_PARTITION_PREP=10,
71
PED_PARTITION_MSFT_RESERVED=11,
72
PED_PARTITION_BIOS_GRUB=12,
73
PED_PARTITION_APPLE_TV_RECOVERY=13,
74
PED_PARTITION_DIAG=14,
75
PED_PARTITION_LEGACY_BOOT=15
77
#define PED_PARTITION_FIRST_FLAG PED_PARTITION_BOOT
78
#define PED_PARTITION_LAST_FLAG PED_PARTITION_LEGACY_BOOT
80
enum _PedDiskTypeFeature {
81
PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */
82
PED_DISK_TYPE_PARTITION_NAME=2 /**< supports partition names */
84
#define PED_DISK_TYPE_FIRST_FEATURE PED_DISK_TYPE_EXTENDED
85
#define PED_DISK_TYPE_LAST_FEATURE PED_DISK_TYPE_PARTITION_NAME
91
struct _PedDiskArchOps;
93
typedef enum _PedDiskFlag PedDiskFlag;
94
typedef enum _PedPartitionType PedPartitionType;
95
typedef enum _PedPartitionFlag PedPartitionFlag;
96
typedef enum _PedDiskTypeFeature PedDiskTypeFeature;
97
typedef struct _PedDisk PedDisk;
98
typedef struct _PedPartition PedPartition;
99
typedef const struct _PedDiskOps PedDiskOps;
100
typedef struct _PedDiskType PedDiskType;
101
typedef const struct _PedDiskArchOps PedDiskArchOps;
103
#include <parted/device.h>
104
#include <parted/filesys.h>
105
#include <parted/natmath.h>
106
#include <parted/geom.h>
112
* \addtogroup PedPartition
120
* PedPartition structure represents a partition.
122
struct _PedPartition {
126
/**< the partition table of the partition */
128
PedGeometry geom; /**< geometry of the partition */
130
/**< the partition number: In Linux, this is the
131
same as the minor number. No assumption
132
should be made about "num" and "type"
133
- different disk labels have different rules. */
136
PedPartitionType type; /**< the type of partition: a bit field of
137
PED_PARTITION_LOGICAL, PED_PARTITION_EXTENDED,
138
PED_PARTITION_METADATA
139
and PED_PARTITION_FREESPACE.
140
Both the first two, and the last two are
142
An extended partition is a primary
143
partition that may contain logical partitions.
144
There is at most one extended partition on
146
A logical partition is like a primary
147
partition, except it's inside an extended
148
partition. Internally, pseudo partitions are
149
allocated to represent free space, or disk
150
label meta-data. These have the
151
PED_PARTITION_FREESPACE or
152
PED_PARTITION_METADATA bit set. */
154
/**< The type of file system on the partition. NULL if unknown. */
155
const PedFileSystemType* fs_type;
157
/**< Only used for an extended partition. The list of logical
158
partitions (and free space and metadata within the extended
160
PedPartition* part_list;
168
* \addtogroup PedDisk
173
* Represents a disk label (partition table).
176
PedDevice* dev; /**< the device where the
177
partition table lies */
178
const PedDiskType* type; /**< type of disk label */
179
const int* block_sizes; /**< block sizes supported
181
PedPartition* part_list; /**< list of partitions. Access with
182
ped_disk_next_partition() */
186
/* office use only ;-) */
187
int needs_clobber; /**< clobber before write? */
188
int update_mode; /**< mode without free/metadata
189
partitions, for easier
194
/* disk label operations */
195
int (*probe) (const PedDevice *dev);
196
int (*clobber) (PedDevice* dev);
197
PedDisk* (*alloc) (const PedDevice* dev);
198
PedDisk* (*duplicate) (const PedDisk* disk);
199
void (*free) (PedDisk* disk);
200
int (*read) (PedDisk* disk);
201
int (*write) (const PedDisk* disk);
202
int (*disk_set_flag) (
206
int (*disk_get_flag) (
209
int (*disk_is_flag_available) (
212
/** \todo add label guessing op here */
214
/* partition operations */
215
PedPartition* (*partition_new) (
217
PedPartitionType part_type,
218
const PedFileSystemType* fs_type,
221
PedPartition* (*partition_duplicate) (const PedPartition* part);
222
void (*partition_destroy) (PedPartition* part);
223
int (*partition_set_system) (PedPartition* part,
224
const PedFileSystemType* fs_type);
225
int (*partition_set_flag) (
227
PedPartitionFlag flag,
229
int (*partition_get_flag) (
230
const PedPartition* part,
231
PedPartitionFlag flag);
232
int (*partition_is_flag_available) (
233
const PedPartition* part,
234
PedPartitionFlag flag);
235
void (*partition_set_name) (PedPartition* part, const char* name);
236
const char* (*partition_get_name) (const PedPartition* part);
237
int (*partition_align) (PedPartition* part,
238
const PedConstraint* constraint);
239
int (*partition_enumerate) (PedPartition* part);
240
bool (*partition_check) (const PedPartition* part);
243
int (*alloc_metadata) (PedDisk* disk);
244
int (*get_max_primary_partition_count) (const PedDisk* disk);
245
bool (*get_max_supported_partition_count) (const PedDisk* disk,
247
PedAlignment *(*get_partition_alignment)(const PedDisk *disk);
248
PedSector (*max_length) (void);
249
PedSector (*max_start_sector) (void);
252
struct _PedDiskType {
254
const char* name; /**< the name of the partition table type.
255
\todo not very intuitive name */
256
PedDiskOps* const ops;
258
PedDiskTypeFeature features; /**< bitmap of supported features */
262
* Architecture-specific operations. i.e. communication with kernel (or
263
* whatever) about changes, etc.
265
struct _PedDiskArchOps {
266
char* (*partition_get_path) (const PedPartition* part);
267
int (*partition_is_busy) (const PedPartition* part);
268
int (*disk_commit) (PedDisk* disk);
271
extern void ped_disk_type_register (PedDiskType* type);
272
extern void ped_disk_type_unregister (PedDiskType* type);
274
extern PedDiskType* ped_disk_type_get_next (PedDiskType const *type)
276
extern PedDiskType* ped_disk_type_get (const char* name)
278
extern int ped_disk_type_check_feature (const PedDiskType* disk_type,
279
PedDiskTypeFeature feature)
282
extern PedDiskType* ped_disk_probe (PedDevice* dev);
283
extern int ped_disk_clobber (PedDevice* dev);
284
extern PedDisk* ped_disk_new (PedDevice* dev);
285
extern PedDisk* ped_disk_new_fresh (PedDevice* dev,
286
const PedDiskType* disk_type);
287
extern PedDisk* ped_disk_duplicate (const PedDisk* old_disk);
288
extern void ped_disk_destroy (PedDisk* disk);
289
extern int ped_disk_commit (PedDisk* disk);
290
extern int ped_disk_commit_to_dev (PedDisk* disk);
291
extern int ped_disk_commit_to_os (PedDisk* disk);
292
extern int ped_disk_check (const PedDisk* disk);
293
extern void ped_disk_print (const PedDisk* disk);
295
extern int ped_disk_get_primary_partition_count (const PedDisk* disk)
297
extern int ped_disk_get_last_partition_num (const PedDisk* disk)
299
extern int ped_disk_get_max_primary_partition_count (const PedDisk* disk);
300
extern bool ped_disk_get_max_supported_partition_count(const PedDisk* disk,
302
extern PedAlignment *ped_disk_get_partition_alignment(const PedDisk *disk);
304
extern int ped_disk_set_flag(PedDisk *disk, PedDiskFlag flag, int state);
305
extern int ped_disk_get_flag(const PedDisk *disk, PedDiskFlag flag);
306
extern int ped_disk_is_flag_available(const PedDisk *disk, PedDiskFlag flag);
308
extern const char *ped_disk_flag_get_name(PedDiskFlag flag);
309
extern PedDiskFlag ped_disk_flag_get_by_name(const char *name);
310
extern PedDiskFlag ped_disk_flag_next(PedDiskFlag flag) _GL_ATTRIBUTE_CONST;
315
* \addtogroup PedPartition
320
extern PedPartition* ped_partition_new (const PedDisk* disk,
321
PedPartitionType type,
322
const PedFileSystemType* fs_type,
325
extern void ped_partition_destroy (PedPartition* part);
326
extern int ped_partition_is_active (const PedPartition* part) _GL_ATTRIBUTE_PURE;
327
extern int ped_partition_set_flag (PedPartition* part, PedPartitionFlag flag,
329
extern int ped_partition_get_flag (const PedPartition* part,
330
PedPartitionFlag flag);
331
extern int ped_partition_is_flag_available (const PedPartition* part,
332
PedPartitionFlag flag);
333
extern int ped_partition_set_system (PedPartition* part,
334
const PedFileSystemType* fs_type);
335
extern int ped_partition_set_name (PedPartition* part, const char* name);
336
extern const char* ped_partition_get_name (const PedPartition* part);
337
extern int ped_partition_is_busy (const PedPartition* part);
338
extern char* ped_partition_get_path (const PedPartition* part);
340
extern const char* ped_partition_type_get_name (PedPartitionType part_type)
342
extern const char* ped_partition_flag_get_name (PedPartitionFlag flag);
343
extern PedPartitionFlag ped_partition_flag_get_by_name (const char* name);
344
extern PedPartitionFlag ped_partition_flag_next (PedPartitionFlag flag)
350
* \addtogroup PedDisk
354
extern int ped_disk_add_partition (PedDisk* disk, PedPartition* part,
355
const PedConstraint* constraint);
356
extern int ped_disk_remove_partition (PedDisk* disk, PedPartition* part);
357
extern int ped_disk_delete_partition (PedDisk* disk, PedPartition* part);
358
extern int ped_disk_delete_all (PedDisk* disk);
359
extern int ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
360
const PedConstraint* constraint,
361
PedSector start, PedSector end);
362
extern int ped_disk_maximize_partition (PedDisk* disk, PedPartition* part,
363
const PedConstraint* constraint);
364
extern PedGeometry* ped_disk_get_max_partition_geometry (PedDisk* disk,
365
PedPartition* part, const PedConstraint* constraint);
366
extern int ped_disk_minimize_extended_partition (PedDisk* disk);
368
extern PedPartition* ped_disk_next_partition (const PedDisk* disk,
369
const PedPartition* part)
371
extern PedPartition* ped_disk_get_partition (const PedDisk* disk, int num)
373
extern PedPartition* ped_disk_get_partition_by_sector (const PedDisk* disk,
376
extern PedPartition* ped_disk_extended_partition (const PedDisk* disk)
379
extern PedSector ped_disk_max_partition_length (const PedDisk *disk);
380
extern PedSector ped_disk_max_partition_start_sector (const PedDisk *disk);
382
/* internal functions */
383
extern PedDisk* _ped_disk_alloc (const PedDevice* dev, const PedDiskType* type);
384
extern void _ped_disk_free (PedDisk* disk);
390
* \addtogroup PedPartition
395
extern PedPartition* _ped_partition_alloc (const PedDisk* disk,
396
PedPartitionType type,
397
const PedFileSystemType* fs_type,
400
extern void _ped_partition_free (PedPartition* part);
402
extern int _ped_partition_attempt_align (
403
PedPartition* part, const PedConstraint* external,
404
PedConstraint* internal);
406
#endif /* PED_DISK_H_INCLUDED */