]> git.ipfire.org Git - thirdparty/util-linux.git/blame - libfdisk/src/libfdisk.h.in
libfdisk: (docs) add missing docs blocks
[thirdparty/util-linux.git] / libfdisk / src / libfdisk.h.in
CommitLineData
d56a7c23
KZ
1/*
2 * libfdisk.h - libfdisk API
3 *
0bb4c979 4 * Copyright (C) 2012-2014 Karel Zak <kzak@redhat.com>
d56a7c23
KZ
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
0bb4c979
KZ
21#ifndef _LIBFDISK_H
22#define _LIBFDISK_H
d56a7c23
KZ
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
fdb006e8 28#include <stdio.h>
ab6ea0e8
KZ
29#include <stdarg.h>
30#include <stdint.h>
31
0bb4c979
KZ
32/**
33 * LIBFDISK_VERSION:
34 *
35 * Library version string
36 */
37#define LIBFDISK_VERSION "@LIBFDISK_VERSION@"
38
791da22d
KZ
39#define LIBFDISK_MAJOR_VERSION @LIBFDISK_MAJOR_VERSION@
40#define LIBFDISK_MINOR_VERSION @LIBFDISK_MINOR_VERSION@
41#define LIBFDISK_PATCH_VERSION @LIBFDISK_PATCH_VERSION@
42
a78dba34
KZ
43/**
44 * fdisk_context:
45 *
46 * Basic library handler.
47 */
a5fe1b3f 48struct fdisk_context;
a78dba34
KZ
49
50/**
51 * fdisk_label:
52 *
53 * Disk label specific driver and setting.
54 */
0c5d095e 55struct fdisk_label;
a78dba34
KZ
56
57/**
58 * fdisk_parttype:
59 *
60 * Partition type.
61 */
a5fe1b3f 62struct fdisk_parttype;
a78dba34
KZ
63
64/**
65 * fdisk_partition:
66 *
67 * Partition abstraction (and template).
68 */
8c0a7f91 69struct fdisk_partition;
a78dba34
KZ
70
71/**
72 * fdisk_ask:
73 *
74 * Ask API handler for dialogs with users.
75 */
7845ca8d 76struct fdisk_ask;
a78dba34
KZ
77
78/**
79 * fdisk_iter:
80 *
81 * Unified iterator.
82 */
04406c0d 83struct fdisk_iter;
a78dba34
KZ
84
85/**
86 * fdisk_table:
87 *
88 * Container for fdisk_partition objects
89 */
04406c0d 90struct fdisk_table;
a78dba34
KZ
91
92/**
93 * fdisk_field
94 *
95 * Output field description.
96 */
bd85d11f 97struct fdisk_field;
a78dba34
KZ
98
99/**
100 * fdisk_script
101 *
5989556a 102 * library handler for sfdisk compatible scripts and dumps
a78dba34 103 */
9138d6f9 104struct fdisk_script;
a5fe1b3f 105
0073a4cf
KZ
106/**
107 * fdisk_sector_t
108 *
73afd3f8 109 * LBA addresses type
0073a4cf
KZ
110 */
111typedef uint64_t fdisk_sector_t;
8d605c88 112
a78dba34
KZ
113/**
114 * fdisk_labeltype:
f92c9f37
KZ
115 * @FDISK_DISKLABEL_DOS: MBR label type
116 * @FDISK_DISKLABEL_SUN: SUN label type
117 * @FDISK_DISKLABEL_SGI: SGI label type
118 * @FDISK_DISKLABEL_BSD: BSD label type
119 * @FDISK_DISKLABEL_GPT: UEFI GPT type
a78dba34 120 *
8adbcf0c
KZ
121 * Supported partition table types (labels)
122 */
123enum fdisk_labeltype {
8c14a743
KZ
124 FDISK_DISKLABEL_DOS = (1 << 1), /* MBR label type */
125 FDISK_DISKLABEL_SUN = (1 << 2), /* SUN label type */
126 FDISK_DISKLABEL_SGI = (1 << 3), /* SGI label type */
127 FDISK_DISKLABEL_BSD = (1 << 4), /* BSD label t ype */
128 FDISK_DISKLABEL_GPT = (1 << 5) /* UEFI GPT type */
8adbcf0c
KZ
129};
130
5989556a 131/**
f92c9f37 132 * fdisk_labelitem:
5989556a
KZ
133 *
134 * library handler for label specific information. See
135 * generic FDISK_LABELITEM_* and label specific {GPT,MBR,..}_LABELITEM_*.
136 */
137struct fdisk_labelitem;
138
a78dba34
KZ
139/**
140 * fdisk_asktype:
f92c9f37
KZ
141 * @FDISK_ASKTYPE_NONE: undefined type
142 * @FDISK_ASKTYPE_NUMBER: ask for number
143 * @FDISK_ASKTYPE_OFFSET: ask for offset
144 * @FDISK_ASKTYPE_WARN: print warning message and errno
145 * @FDISK_ASKTYPE_WARNX: print warning message
146 * @FDISK_ASKTYPE_INFO: print infor message
147 * @FDISK_ASKTYPE_YESNO: ask Yes/No question
148 * @FDISK_ASKTYPE_STRING: ask for string
149 * @FDISK_ASKTYPE_MENU: ask for menu item
a78dba34
KZ
150 *
151 * Ask API dialog types
152 */
153enum fdisk_asktype {
f92c9f37
KZ
154 FDISK_ASKTYPE_NONE = 0,
155 FDISK_ASKTYPE_NUMBER,
156 FDISK_ASKTYPE_OFFSET,
157 FDISK_ASKTYPE_WARN,
158 FDISK_ASKTYPE_WARNX,
159 FDISK_ASKTYPE_INFO,
160 FDISK_ASKTYPE_YESNO,
161 FDISK_ASKTYPE_STRING,
162 FDISK_ASKTYPE_MENU
4114da08
KZ
163};
164
d56a7c23
KZ
165/* init.c */
166extern void fdisk_init_debug(int mask);
167
791da22d
KZ
168/* version.c */
169extern int fdisk_parse_version_string(const char *ver_string);
170extern int fdisk_get_library_version(const char **ver_string);
171extern int fdisk_get_library_features(const char ***features);
172
f4be9e2b 173/* context.h */
b4bfbadd 174
385810d2
KZ
175#define FDISK_PLURAL 0
176#define FDISK_SINGULAR 1
b4bfbadd 177
6a632136
KZ
178struct fdisk_context *fdisk_new_context(void);
179struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent, const char *name);
c7119037 180void fdisk_unref_context(struct fdisk_context *cxt);
62a9ef3e 181void fdisk_ref_context(struct fdisk_context *cxt);
6a632136 182
1753a234 183struct fdisk_context *fdisk_get_parent(struct fdisk_context *cxt);
59c8e95b 184size_t fdisk_get_npartitions(struct fdisk_context *cxt);
1753a234 185
6a632136
KZ
186struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name);
187int fdisk_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
188size_t fdisk_get_nlabels(struct fdisk_context *cxt);
6a632136 189
aa36c2cf 190int fdisk_has_label(struct fdisk_context *cxt);
705854f3 191int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype id);
aa36c2cf
KZ
192#define fdisk_is_label(c, x) fdisk_is_labeltype(c, FDISK_DISKLABEL_ ## x)
193
194
6a632136
KZ
195int fdisk_assign_device(struct fdisk_context *cxt,
196 const char *fname, int readonly);
197int fdisk_deassign_device(struct fdisk_context *cxt, int nosync);
2469ba36
KZ
198int fdisk_reassign_device(struct fdisk_context *cxt);
199
6a632136 200int fdisk_is_readonly(struct fdisk_context *cxt);
7526c305 201int fdisk_is_regfile(struct fdisk_context *cxt);
b9da1532 202int fdisk_device_is_used(struct fdisk_context *cxt);
6a632136 203
992f7cba
KZ
204int fdisk_disable_dialogs(struct fdisk_context *cxt, int disable);
205int fdisk_has_dialogs(struct fdisk_context *cxt);
206
6a632136
KZ
207int fdisk_enable_details(struct fdisk_context *cxt, int enable);
208int fdisk_is_details(struct fdisk_context *cxt);
209
210int fdisk_enable_listonly(struct fdisk_context *cxt, int enable);
211int fdisk_is_listonly(struct fdisk_context *cxt);
212
6cbb7371
KZ
213int fdisk_enable_wipe(struct fdisk_context *cxt, int enable);
214int fdisk_has_wipe(struct fdisk_context *cxt);
215const char *fdisk_get_collision(struct fdisk_context *cxt);
0cec78a3 216int fdisk_is_ptcollision(struct fdisk_context *cxt);
6cbb7371 217
6a632136
KZ
218int fdisk_set_unit(struct fdisk_context *cxt, const char *str);
219const char *fdisk_get_unit(struct fdisk_context *cxt, int n);
220int fdisk_use_cylinders(struct fdisk_context *cxt);
221unsigned int fdisk_get_units_per_sector(struct fdisk_context *cxt);
222
223unsigned long fdisk_get_optimal_iosize(struct fdisk_context *cxt);
1753a234 224unsigned long fdisk_get_minimal_iosize(struct fdisk_context *cxt);
6a632136
KZ
225unsigned long fdisk_get_physector_size(struct fdisk_context *cxt);
226unsigned long fdisk_get_sector_size(struct fdisk_context *cxt);
227unsigned long fdisk_get_alignment_offset(struct fdisk_context *cxt);
228unsigned long fdisk_get_grain_size(struct fdisk_context *cxt);
0073a4cf
KZ
229fdisk_sector_t fdisk_get_first_lba(struct fdisk_context *cxt);
230fdisk_sector_t fdisk_set_first_lba(struct fdisk_context *cxt, fdisk_sector_t lba);
231fdisk_sector_t fdisk_get_last_lba(struct fdisk_context *cxt);
232fdisk_sector_t fdisk_set_last_lba(struct fdisk_context *cxt, fdisk_sector_t lba);
233fdisk_sector_t fdisk_get_nsectors(struct fdisk_context *cxt);
6a632136 234const char *fdisk_get_devname(struct fdisk_context *cxt);
1753a234
KZ
235int fdisk_get_devfd(struct fdisk_context *cxt);
236
237unsigned int fdisk_get_geom_heads(struct fdisk_context *cxt);
0073a4cf
KZ
238fdisk_sector_t fdisk_get_geom_sectors(struct fdisk_context *cxt);
239fdisk_sector_t fdisk_get_geom_cylinders(struct fdisk_context *cxt);
a5c1b0fa 240
354f8cc8
KZ
241enum {
242 FDISK_SIZEUNIT_HUMAN = 0, /* default, human readable {M,G,P,...} */
243 FDISK_SIZEUNIT_BYTES /* bytes */
244};
245int fdisk_set_size_unit(struct fdisk_context *cxt, int unit);
246int fdisk_get_size_unit(struct fdisk_context *cxt);
6d37c2ce 247
3457d90e
KZ
248int fdisk_has_protected_bootbits(struct fdisk_context *cxt);
249int fdisk_enable_bootbits_protection(struct fdisk_context *cxt, int enable);
6d37c2ce 250
a5fe1b3f 251/* parttype.c */
dfc6db2a
KZ
252struct fdisk_parttype *fdisk_new_parttype(void);
253void fdisk_ref_parttype(struct fdisk_parttype *t);
254void fdisk_unref_parttype(struct fdisk_parttype *t);
255int fdisk_parttype_set_name(struct fdisk_parttype *t, const char *str);
256int fdisk_parttype_set_typestr(struct fdisk_parttype *t, const char *str);
257int fdisk_parttype_set_code(struct fdisk_parttype *t, int code);
eac3aac9 258size_t fdisk_label_get_nparttypes(const struct fdisk_label *lb);
dfc6db2a 259struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, size_t n);
eac3aac9 260int fdisk_label_has_code_parttypes(const struct fdisk_label *lb);
a745611d 261struct fdisk_parttype *fdisk_label_get_parttype_from_code(
eac3aac9 262 const struct fdisk_label *lb,
a745611d 263 unsigned int code);
a745611d 264struct fdisk_parttype *fdisk_label_get_parttype_from_string(
eac3aac9 265 const struct fdisk_label *lb,
a745611d
KZ
266 const char *str);
267struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int code,
268 const char *typestr);
dfc6db2a 269struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type);
a745611d 270struct fdisk_parttype *fdisk_label_parse_parttype(
eac3aac9 271 const struct fdisk_label *lb,
a745611d 272 const char *str);
a745611d
KZ
273const char *fdisk_parttype_get_string(const struct fdisk_parttype *t);
274unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t);
275const char *fdisk_parttype_get_name(const struct fdisk_parttype *t);
c1ba5863 276int fdisk_parttype_is_unknown(const struct fdisk_parttype *t);
950edd1a 277
e4c5250d
KZ
278
279/* field.c */
280extern int fdisk_field_get_id(const struct fdisk_field *field);
281extern const char *fdisk_field_get_name(const struct fdisk_field *field);
282extern double fdisk_field_get_width(const struct fdisk_field *field);
283extern int fdisk_field_is_number(const struct fdisk_field *field);
284
285
8adbcf0c 286/* label.c */
a78dba34
KZ
287
288/**
f854eca3 289 * fdisk_fieldtype:
9070c2e2
KZ
290 * @FDISK_FIELD_NONE: unspecified item
291 * @FDISK_FIELD_DEVICE: partition device name
292 * @FDISK_FIELD_START: start offset of the partition
293 * @FDISK_FIELD_END: end offset of the partition
294 * @FDISK_FIELD_SECTORS: number of sectors
295 * @FDISK_FIELD_CYLINDERS: number of cylinders (deprecated)
296 * @FDISK_FIELD_SIZE: partition size
297 * @FDISK_FIELD_TYPE: partition type
298 * @FDISK_FIELD_TYPEID: partition type ID
299 * @FDISK_FIELD_ATTR: partition attribute (GPT)
300 * @FDISK_FIELD_BOOT: partition boot flag
301 * @FDISK_FIELD_BSIZE: size of the boot area (BSD)
302 * @FDISK_FIELD_CPG: BSD
303 * @FDISK_FIELD_EADDR: End-C/H/S (MBR)
304 * @FDISK_FIELD_FSIZE: BSD
305 * @FDISK_FIELD_NAME: partition label/name
306 * @FDISK_FIELD_SADDR: Start-C/H/S (MBR)
307 * @FDISK_FIELD_UUID: partition UUID (GPT)
308 * @FDISK_FIELD_FSUUID: Filesystem UUID
309 * @FDISK_FIELD_FSLABEL: Filesystem LABEL
310 * @FDISK_FIELD_FSTYPE: Filesystem type
311 * @FDISK_NFIELDS: Don't use, counter.
a78dba34 312 *
5989556a 313 * Types of fdisk_field. The fields describe a partition.
a78dba34
KZ
314 */
315enum fdisk_fieldtype {
bd85d11f 316 FDISK_FIELD_NONE = 0,
d6faa8e0
KZ
317
318 /* generic */
9070c2e2
KZ
319 FDISK_FIELD_DEVICE,
320 FDISK_FIELD_START,
321 FDISK_FIELD_END,
322 FDISK_FIELD_SECTORS,
323 FDISK_FIELD_CYLINDERS,
324 FDISK_FIELD_SIZE,
325 FDISK_FIELD_TYPE,
326 FDISK_FIELD_TYPEID,
d6faa8e0
KZ
327
328 /* label specific */
9070c2e2
KZ
329 FDISK_FIELD_ATTR,
330 FDISK_FIELD_BOOT,
331 FDISK_FIELD_BSIZE,
332 FDISK_FIELD_CPG,
333 FDISK_FIELD_EADDR,
334 FDISK_FIELD_FSIZE,
335 FDISK_FIELD_NAME,
336 FDISK_FIELD_SADDR,
337 FDISK_FIELD_UUID,
eac3aac9 338
131e38a2
KZ
339 FDISK_FIELD_FSUUID,
340 FDISK_FIELD_FSLABEL,
341 FDISK_FIELD_FSTYPE,
342
eac3aac9 343 FDISK_NFIELDS /* must be last */
21a44c9b
KZ
344};
345
eac3aac9
KZ
346int fdisk_label_get_type(const struct fdisk_label *lb);
347const char *fdisk_label_get_name(const struct fdisk_label *lb);
348int fdisk_label_require_geometry(const struct fdisk_label *lb);
0b52b94c 349
8adbcf0c
KZ
350
351extern int fdisk_write_disklabel(struct fdisk_context *cxt);
352extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
171372d3 353extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
3c5fb475 354extern int fdisk_list_disklabel(struct fdisk_context *cxt);
9bbcf43f
KZ
355extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n,
356 const char **name,
357 uint64_t *offset,
358 size_t *size);
8adbcf0c 359
2dd2880f
KZ
360extern int fdisk_label_get_geomrange_cylinders(const struct fdisk_label *lb,
361 fdisk_sector_t *mi, fdisk_sector_t *ma);
362extern int fdisk_label_get_geomrange_heads(const struct fdisk_label *lb,
363 unsigned int *mi, unsigned int *ma);
364extern int fdisk_label_get_geomrange_sectors(const struct fdisk_label *lb,
365 fdisk_sector_t *mi, fdisk_sector_t *ma);
366
5989556a 367/**
f854eca3 368 * fdisk_labelitem_gen:
9070c2e2
KZ
369 * @FDISK_LABELITEM_ID: Unique disk identifier
370 * @__FDISK_NLABELITEMS: Specifies reserved range for generic items (0..7)
5989556a 371 *
9070c2e2 372 * Generic disklabel items.
5989556a
KZ
373 */
374enum fdisk_labelitem_gen {
9070c2e2
KZ
375 FDISK_LABELITEM_ID = 0,
376 __FDISK_NLABELITEMS = 8
5989556a
KZ
377};
378
40c9c3a6
KZ
379/* item.c */
380extern struct fdisk_labelitem *fdisk_new_labelitem(void);
381extern void fdisk_ref_labelitem(struct fdisk_labelitem *li);
382extern int fdisk_reset_labelitem(struct fdisk_labelitem *li);
383extern void fdisk_unref_labelitem(struct fdisk_labelitem *li);
384extern const char *fdisk_labelitem_get_name(struct fdisk_labelitem *li);
385extern int fdisk_labelitem_get_id(struct fdisk_labelitem *li);
386extern int fdisk_labelitem_get_data_u64(struct fdisk_labelitem *li, uint64_t *data);
387extern int fdisk_labelitem_get_data_string(struct fdisk_labelitem *li, const char **data);
388extern int fdisk_labelitem_is_string(struct fdisk_labelitem *li);
389extern int fdisk_labelitem_is_number(struct fdisk_labelitem *li);
390
5989556a 391extern int fdisk_get_disklabel_item(struct fdisk_context *cxt, int id, struct fdisk_labelitem *item);
40c9c3a6 392
21fe3dde 393extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
35b1f0a4 394extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
8c0a7f91 395
85151521 396extern int fdisk_get_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition **pa);
0dad2177 397extern int fdisk_set_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition *pa);
c3bc7483 398extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_partition *pa, size_t *partno);
e11c6684 399extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partno);
3c0e6b15 400extern int fdisk_delete_all_partitions(struct fdisk_context *cxt);
8adbcf0c 401
131e38a2
KZ
402extern int fdisk_wipe_partition(struct fdisk_context *cxt, size_t partno, int enable);
403
9ffeb235 404extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
171372d3
KZ
405 struct fdisk_parttype *t);
406
0dad2177 407
11ee1177 408extern int fdisk_label_get_fields_ids(
eac3aac9 409 const struct fdisk_label *lb,
11ee1177
KZ
410 struct fdisk_context *cxt,
411 int **ids, size_t *nids);
eac3aac9 412
31ea7fa6
KZ
413extern int fdisk_label_get_fields_ids_all(
414 const struct fdisk_label *lb,
415 struct fdisk_context *cxt,
416 int **ids, size_t *nids);
417
eac3aac9
KZ
418extern const struct fdisk_field *fdisk_label_get_field(const struct fdisk_label *lb, int id);
419extern const struct fdisk_field *fdisk_label_get_field_by_name(
420 const struct fdisk_label *lb,
421 const char *name);
bd85d11f 422
2e3b40d3 423extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
eac3aac9 424extern int fdisk_label_is_changed(const struct fdisk_label *lb);
2e3b40d3 425
7a188aed 426extern void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled);
eac3aac9 427extern int fdisk_label_is_disabled(const struct fdisk_label *lb);
7a188aed 428
8c0a7f91
KZ
429extern int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n);
430
a1ef792f 431extern int fdisk_toggle_partition_flag(struct fdisk_context *cxt, size_t partnum, unsigned long flag);
2e3b40d3 432
8c0a7f91
KZ
433extern struct fdisk_partition *fdisk_new_partition(void);
434extern void fdisk_reset_partition(struct fdisk_partition *pa);
d6cfa8b3
KZ
435extern void fdisk_ref_partition(struct fdisk_partition *pa);
436extern void fdisk_unref_partition(struct fdisk_partition *pa);
1de9fddb 437extern int fdisk_partition_is_freespace(struct fdisk_partition *pa);
e5c93999 438
ecf40cda
KZ
439int fdisk_partition_set_start(struct fdisk_partition *pa, uint64_t off);
440int fdisk_partition_unset_start(struct fdisk_partition *pa);
ac6a6b0d 441fdisk_sector_t fdisk_partition_get_start(struct fdisk_partition *pa);
ecf40cda
KZ
442int fdisk_partition_has_start(struct fdisk_partition *pa);
443int fdisk_partition_cmp_start(struct fdisk_partition *a,
e5c93999 444 struct fdisk_partition *b);
ecf40cda
KZ
445int fdisk_partition_start_follow_default(struct fdisk_partition *pa, int enable);
446int fdisk_partition_start_is_default(struct fdisk_partition *pa);
e5c93999 447
ecf40cda
KZ
448int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t sz);
449int fdisk_partition_unset_size(struct fdisk_partition *pa);
ac6a6b0d 450fdisk_sector_t fdisk_partition_get_size(struct fdisk_partition *pa);
ecf40cda
KZ
451int fdisk_partition_has_size(struct fdisk_partition *pa);
452int fdisk_partition_size_explicit(struct fdisk_partition *pa, int enable);
e5c93999 453
bbfc2429
KZ
454int fdisk_partition_has_end(struct fdisk_partition *pa);
455fdisk_sector_t fdisk_partition_get_end(struct fdisk_partition *pa);
456
0123bd1a
KZ
457int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t num);
458int fdisk_partition_unset_partno(struct fdisk_partition *pa);
459size_t fdisk_partition_get_partno(struct fdisk_partition *pa);
460int fdisk_partition_has_partno(struct fdisk_partition *pa);
461int fdisk_partition_cmp_partno(struct fdisk_partition *a,
462 struct fdisk_partition *b);
131e38a2 463
0123bd1a
KZ
464int fdisk_partition_partno_follow_default(struct fdisk_partition *pa, int enable);
465
dfc6db2a
KZ
466extern int fdisk_partition_set_type(struct fdisk_partition *pa, struct fdisk_parttype *type);
467extern struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa);
8c0a7f91
KZ
468extern int fdisk_partition_set_name(struct fdisk_partition *pa, const char *name);
469extern const char *fdisk_partition_get_name(struct fdisk_partition *pa);
470extern int fdisk_partition_set_uuid(struct fdisk_partition *pa, const char *uuid);
c77ba531 471extern int fdisk_partition_set_attrs(struct fdisk_partition *pa, const char *attrs);
8c0a7f91
KZ
472extern const char *fdisk_partition_get_uuid(struct fdisk_partition *pa);
473extern const char *fdisk_partition_get_attrs(struct fdisk_partition *pa);
8c0a7f91 474extern int fdisk_partition_is_nested(struct fdisk_partition *pa);
bd5e8291 475extern int fdisk_partition_is_container(struct fdisk_partition *pa);
03643931 476extern int fdisk_partition_get_parent(struct fdisk_partition *pa, size_t *parent);
8c0a7f91 477extern int fdisk_partition_is_used(struct fdisk_partition *pa);
59c8e95b 478extern int fdisk_partition_is_bootable(struct fdisk_partition *pa);
943271e2 479extern int fdisk_partition_is_wholedisk(struct fdisk_partition *pa);
6c89f750
KZ
480extern int fdisk_partition_to_string(struct fdisk_partition *pa,
481 struct fdisk_context *cxt,
482 int id, char **data);
8c0a7f91 483
0123bd1a 484int fdisk_partition_next_partno(struct fdisk_partition *pa,
6c89f750
KZ
485 struct fdisk_context *cxt,
486 size_t *n);
77d6a70a 487
20f878fe 488extern int fdisk_partition_end_follow_default(struct fdisk_partition *pa, int enable);
0051ec9b 489extern int fdisk_partition_end_is_default(struct fdisk_partition *pa);
20f878fe 490
dd7ba604
KZ
491extern int fdisk_reorder_partitions(struct fdisk_context *cxt);
492
29f2e825
KZ
493extern int fdisk_partition_has_wipe(struct fdisk_context *cxt, struct fdisk_partition *pa);
494
495
b48cdebc
KZ
496/* table.c */
497extern struct fdisk_table *fdisk_new_table(void);
498extern int fdisk_reset_table(struct fdisk_table *tb);
499extern void fdisk_ref_table(struct fdisk_table *tb);
500extern void fdisk_unref_table(struct fdisk_table *tb);
e54b1c6f 501extern size_t fdisk_table_get_nents(struct fdisk_table *tb);
b48cdebc
KZ
502extern int fdisk_table_is_empty(struct fdisk_table *tb);
503extern int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
504extern int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
505
2cec7949
KZ
506extern int fdisk_get_partitions(struct fdisk_context *cxt, struct fdisk_table **tb);
507extern int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb);
508
1dd63a3b 509
8b60872e 510extern int fdisk_table_wrong_order(struct fdisk_table *tb);
e5c93999
KZ
511extern int fdisk_table_sort_partitions(struct fdisk_table *tb,
512 int (*cmp)(struct fdisk_partition *,
513 struct fdisk_partition *));
514
04406c0d
KZ
515extern int fdisk_table_next_partition(
516 struct fdisk_table *tb,
517 struct fdisk_iter *itr,
518 struct fdisk_partition **pa);
28b6a23c
KZ
519
520extern struct fdisk_partition *fdisk_table_get_partition(
521 struct fdisk_table *tb,
522 size_t n);
b17c1f14
KZ
523extern struct fdisk_partition *fdisk_table_get_partition_by_partno(
524 struct fdisk_table *tb,
525 size_t partno);
526
3c0e6b15 527extern int fdisk_apply_table(struct fdisk_context *cxt, struct fdisk_table *tb);
28b6a23c 528
c578f9af 529/* alignment.c */
8d605c88
KZ
530#define FDISK_ALIGN_UP 1
531#define FDISK_ALIGN_DOWN 2
532#define FDISK_ALIGN_NEAREST 3
533
0073a4cf
KZ
534fdisk_sector_t fdisk_align_lba(struct fdisk_context *cxt, fdisk_sector_t lba, int direction);
535fdisk_sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
536 fdisk_sector_t lba, fdisk_sector_t start, fdisk_sector_t stop);
537int fdisk_lba_is_phy_aligned(struct fdisk_context *cxt, fdisk_sector_t lba);
1653f0b0 538
8d605c88 539int fdisk_override_geometry(struct fdisk_context *cxt,
1653f0b0
KZ
540 unsigned int cylinders,
541 unsigned int heads,
542 unsigned int sectors);
8d605c88
KZ
543int fdisk_save_user_geometry(struct fdisk_context *cxt,
544 unsigned int cylinders,
545 unsigned int heads,
546 unsigned int sectors);
547int fdisk_save_user_sector_size(struct fdisk_context *cxt,
1653f0b0
KZ
548 unsigned int phy,
549 unsigned int log);
adf09b5c
KZ
550
551int fdisk_save_user_grain(struct fdisk_context *cxt, unsigned long grain);
552
8d605c88
KZ
553int fdisk_has_user_device_properties(struct fdisk_context *cxt);
554int fdisk_reset_alignment(struct fdisk_context *cxt);
7190b9b2 555int fdisk_reset_device_properties(struct fdisk_context *cxt);
8d605c88 556int fdisk_reread_partition_table(struct fdisk_context *cxt);
1dd63a3b 557int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org);
852ce62b 558
6c89f750
KZ
559/* iter.c */
560enum {
561
562 FDISK_ITER_FORWARD = 0,
563 FDISK_ITER_BACKWARD
564};
565extern struct fdisk_iter *fdisk_new_iter(int direction);
566extern void fdisk_free_iter(struct fdisk_iter *itr);
567extern void fdisk_reset_iter(struct fdisk_iter *itr, int direction);
568extern int fdisk_iter_get_direction(struct fdisk_iter *itr);
569
570
852ce62b 571/* dos.c */
b7d101a2
KZ
572#define DOS_FLAG_ACTIVE 1
573
574extern int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i);
852ce62b
KZ
575extern int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable);
576extern int fdisk_dos_is_compatible(struct fdisk_label *lb);
577
4170ae9c
KZ
578/* sun.h */
579extern int fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
580extern int fdisk_sun_set_xcyl(struct fdisk_context *cxt);
581extern int fdisk_sun_set_ilfact(struct fdisk_context *cxt);
582extern int fdisk_sun_set_rspeed(struct fdisk_context *cxt);
583extern int fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
584
f854eca3
KZ
585/**
586 * fdisk_labelitem_sun:
f92c9f37
KZ
587 * @SUN_LABELITEM_LABELID: Label ID
588 * @SUN_LABELITEM_VTOCID: Volume ID
589 * @SUN_LABELITEM_RPM: Rpm
590 * @SUN_LABELITEM_ACYL: Alternate cylinders
591 * @SUN_LABELITEM_PCYL: Physical cylinders
592 * @SUN_LABELITEM_APC: Extra sects/cyl
593 * @SUN_LABELITEM_INTRLV: Interleave
f854eca3
KZ
594 *
595 * SUN specific label items.
596 */
5989556a
KZ
597enum fdisk_labelitem_sun {
598 SUN_LABELITEM_LABELID = __FDISK_NLABELITEMS,
599 SUN_LABELITEM_VTOCID,
600 SUN_LABELITEM_RPM,
601 SUN_LABELITEM_ACYL,
602 SUN_LABELITEM_PCYL,
603 SUN_LABELITEM_APC,
604 SUN_LABELITEM_INTRLV
605};
606
d5b2b8db
KZ
607/* bsd.c */
608extern int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt);
609extern int fdisk_bsd_write_bootstrap(struct fdisk_context *cxt);
610extern int fdisk_bsd_link_partition(struct fdisk_context *cxt);
611
f854eca3
KZ
612/**
613 * fdisk_labelitem_bsd:
f92c9f37
KZ
614 * @BSD_LABELITEM_TYPE: type
615 * @BSD_LABELITEM_DISK: disk
616 * @BSD_LABELITEM_PACKNAME: packname
617 * @BSD_LABELITEM_FLAGS: flags (removeable, ecc, badsect)
618 * @BSD_LABELITEM_SECSIZE: Bytes/Sector
619 * @BSD_LABELITEM_NTRACKS: Tracks/Cylinder
620 * @BSD_LABELITEM_SECPERCYL: Sectors/Cylinder
621 * @BSD_LABELITEM_CYLINDERS: Cylinders
622 * @BSD_LABELITEM_RPM: rpm
623 * @BSD_LABELITEM_INTERLEAVE: interleave
624 * @BSD_LABELITEM_TRACKSKEW: trackskew
625 * @BSD_LABELITEM_CYLINDERSKEW: cylinderskew
626 * @BSD_LABELITEM_HEADSWITCH: headswitch
627 * @BSD_LABELITEM_TRKSEEK: track-to-track seek
f854eca3
KZ
628 *
629 * BSD specific label items.
630 */
5989556a
KZ
631enum fdisk_labelitem_bsd {
632 /* specific */
633 BSD_LABELITEM_TYPE = __FDISK_NLABELITEMS,
634 BSD_LABELITEM_DISK,
635 BSD_LABELITEM_PACKNAME,
636 BSD_LABELITEM_FLAGS,
637 BSD_LABELITEM_SECSIZE,
638 BSD_LABELITEM_NTRACKS,
639 BSD_LABELITEM_SECPERCYL,
640 BSD_LABELITEM_CYLINDERS,
641 BSD_LABELITEM_RPM,
642 BSD_LABELITEM_INTERLEAVE,
643 BSD_LABELITEM_TRACKSKEW,
644 BSD_LABELITEM_CYLINDERSKEW,
645 BSD_LABELITEM_HEADSWITCH,
646 BSD_LABELITEM_TRKSEEK
647};
648
067686d8
KZ
649/* sgi.h */
650#define SGI_FLAG_BOOT 1
651#define SGI_FLAG_SWAP 2
ac84272d
KZ
652extern int fdisk_sgi_set_bootfile(struct fdisk_context *cxt);
653extern int fdisk_sgi_create_info(struct fdisk_context *cxt);
067686d8 654
f854eca3
KZ
655/**
656 * fdisk_labelitem_sgi:
f92c9f37
KZ
657 * @SGI_LABELITEM_PCYLCOUNT: Physical cylinders
658 * @SGI_LABELITEM_SPARECYL: Extra sects/cyl
659 * @SGI_LABELITEM_ILFACT: nterleave
660 * @SGI_LABELITEM_BOOTFILE: Bootfile
f854eca3
KZ
661 *
662 * SGI specific label items.
663 */
5989556a
KZ
664enum fdisk_labelitem_sgi {
665 SGI_LABELITEM_PCYLCOUNT = __FDISK_NLABELITEMS,
666 SGI_LABELITEM_SPARECYL,
667 SGI_LABELITEM_ILFACT,
668 SGI_LABELITEM_BOOTFILE
669};
670
34b06299 671/* gpt */
773aae5c 672
0c07055c
KZ
673/*
674 * GPT partition attributes
675 */
676
677/**
678 * GPT_FLAG_REQUIRED:
679 *
680 * GPT attribute; marks a partition as system partition (disk
681 * partitioning utilities must preserve the partition as is)
682 */
683#define GPT_FLAG_REQUIRED 1
684
685/**
686 * GPT_FLAG_NOBLOCK:
687 *
688 * GPT attribute; EFI firmware should ignore the content of the
689 * partition and not try to read from it
690 */
691#define GPT_FLAG_NOBLOCK 2
692
693/**
694 * GPT_FLAG_LEGACYBOOT:
695 *
696 * GPT attribute; use the partition for legacy boot method
697 */
698#define GPT_FLAG_LEGACYBOOT 3
699
700/**
701 * GPT_FLAG_GUIDSPECIFIC:
702 *
703 * GPT attribute; for bites 48-63, defined and used by the individual partition
704 * type.
705 *
706 * The flag GPT_FLAG_GUIDSPECIFIC forces libfdisk to ask (by ask API)
707 * for a bit number. If you want to toggle specific bit and avoid any
708 * dialog, then use the bit number (in range 48..63). For example:
709 *
710 * // start dialog to ask for bit number
711 * fdisk_toggle_partition_flag(cxt, n, GPT_FLAG_GUIDSPECIFIC);
712 *
713 * // toggle bit 60
714 * fdisk_toggle_partition_flag(cxt, n, 60);
715 */
716#define GPT_FLAG_GUIDSPECIFIC 4
c83f772e 717
433d05ff 718extern int fdisk_gpt_is_hybrid(struct fdisk_context *cxt);
f88eeb25 719extern int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t entries);
4a4a0927
MM
720extern int fdisk_gpt_get_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t *attrs);
721extern int fdisk_gpt_set_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t attrs);
34b06299 722
f854eca3
KZ
723/**
724 * fdisk_labelitem_gpt:
f92c9f37
KZ
725 * @GPT_LABELITEM_ID: GPT disklabel UUID (!= partition UUID)
726 * @GPT_LABELITEM_FIRSTLBA: First Usable LBA
727 * @GPT_LABELITEM_LASTLBA: Usable LBA
728 * @GPT_LABELITEM_ALTLBA: Alternative LBA (backup header LBA)
729 * @GPT_LABELITEM_ENTRIESLBA: Partitions entires array LBA
730 * @GPT_LABELITEM_ENTRIESALLOC: Number of allocated entries in entries array
f854eca3
KZ
731 *
732 * GPT specific label items.
733 */
5989556a
KZ
734enum fdisk_labelitem_gpt {
735 /* generic */
f92c9f37 736 GPT_LABELITEM_ID = FDISK_LABELITEM_ID,
5989556a 737 /* specific */
f92c9f37
KZ
738 GPT_LABELITEM_FIRSTLBA = __FDISK_NLABELITEMS,
739 GPT_LABELITEM_LASTLBA,
740 GPT_LABELITEM_ALTLBA,
741 GPT_LABELITEM_ENTRIESLBA,
742 GPT_LABELITEM_ENTRIESALLOC
5989556a 743};
50992267 744
9138d6f9
KZ
745/* script.c */
746struct fdisk_script *fdisk_new_script(struct fdisk_context *cxt);
747struct fdisk_script *fdisk_new_script_from_file(struct fdisk_context *cxt,
748 const char *filename);
749void fdisk_ref_script(struct fdisk_script *dp);
750void fdisk_unref_script(struct fdisk_script *dp);
751
752const char *fdisk_script_get_header(struct fdisk_script *dp, const char *name);
753int fdisk_script_set_header(struct fdisk_script *dp, const char *name, const char *data);
754struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp);
3186f4a9 755int fdisk_script_get_nlines(struct fdisk_script *dp);
35ca5118 756int fdisk_script_has_force_label(struct fdisk_script *dp);
9138d6f9 757
5cdbe36f
KZ
758int fdisk_script_set_userdata(struct fdisk_script *dp, void *data);
759void *fdisk_script_get_userdata(struct fdisk_script *dp);
760
761int fdisk_script_set_fgets(struct fdisk_script *dp,
762 char *(*fn_fgets)(struct fdisk_script *, char *, size_t, FILE *));
9138d6f9 763int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt);
3c7fde5f 764int fdisk_script_enable_json(struct fdisk_script *dp, int json);
9138d6f9 765int fdisk_script_write_file(struct fdisk_script *dp, FILE *f);
9138d6f9 766int fdisk_script_read_file(struct fdisk_script *dp, FILE *f);
705854f3 767int fdisk_script_read_line(struct fdisk_script *dp, FILE *f, char *buf, size_t bufsz);
9138d6f9
KZ
768
769int fdisk_set_script(struct fdisk_context *cxt, struct fdisk_script *dp);
770struct fdisk_script *fdisk_get_script(struct fdisk_context *cxt);
771
0051ec9b 772int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *dp);
9138d6f9
KZ
773int fdisk_apply_script(struct fdisk_context *cxt, struct fdisk_script *dp);
774
775
7845ca8d 776/* ask.c */
ab6ea0e8
KZ
777#define fdisk_is_ask(a, x) (fdisk_ask_get_type(a) == FDISK_ASKTYPE_ ## x)
778
a1ef792f
KZ
779int fdisk_set_ask(struct fdisk_context *cxt,
780 int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *),
781 void *data);
782
783
1c01e44f
KZ
784void fdisk_ref_ask(struct fdisk_ask *ask);
785void fdisk_unref_ask(struct fdisk_ask *ask);
786const char *fdisk_ask_get_query(struct fdisk_ask *ask);
787int fdisk_ask_get_type(struct fdisk_ask *ask);
788const char *fdisk_ask_number_get_range(struct fdisk_ask *ask);
789uint64_t fdisk_ask_number_get_default(struct fdisk_ask *ask);
790uint64_t fdisk_ask_number_get_low(struct fdisk_ask *ask);
791uint64_t fdisk_ask_number_get_high(struct fdisk_ask *ask);
792uint64_t fdisk_ask_number_get_result(struct fdisk_ask *ask);
793int fdisk_ask_number_set_result(struct fdisk_ask *ask, uint64_t result);
794uint64_t fdisk_ask_number_get_base(struct fdisk_ask *ask);
795uint64_t fdisk_ask_number_get_unit(struct fdisk_ask *ask);
796int fdisk_ask_number_set_relative(struct fdisk_ask *ask, int relative);
797int fdisk_ask_number_inchars(struct fdisk_ask *ask);
798int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew);
799
800int fdisk_ask_number(struct fdisk_context *cxt,
24fc19a1
KZ
801 uintmax_t low,
802 uintmax_t dflt,
803 uintmax_t high,
804 const char *query,
805 uintmax_t *result);
1c01e44f
KZ
806char *fdisk_ask_string_get_result(struct fdisk_ask *ask);
807int fdisk_ask_string_set_result(struct fdisk_ask *ask, char *result);
808int fdisk_ask_string(struct fdisk_context *cxt,
34b06299
KZ
809 const char *query,
810 char **result);
1c01e44f
KZ
811int fdisk_ask_yesno(struct fdisk_context *cxt,
812 const char *query,
813 int *result);
814int fdisk_ask_yesno_get_result(struct fdisk_ask *ask);
815int fdisk_ask_yesno_set_result(struct fdisk_ask *ask, int result);
816int fdisk_ask_menu_get_default(struct fdisk_ask *ask);
817int fdisk_ask_menu_set_result(struct fdisk_ask *ask, int key);
818int fdisk_ask_menu_get_result(struct fdisk_ask *ask, int *key);
819int fdisk_ask_menu_get_item(struct fdisk_ask *ask, size_t idx, int *key,
20f878fe 820 const char **name, const char **desc);
1c01e44f
KZ
821size_t fdisk_ask_menu_get_nitems(struct fdisk_ask *ask);
822int fdisk_ask_print_get_errno(struct fdisk_ask *ask);
823const char *fdisk_ask_print_get_mesg(struct fdisk_ask *ask);
20f878fe 824
1c01e44f
KZ
825int fdisk_info(struct fdisk_context *cxt, const char *fmt, ...);
826int fdisk_warn(struct fdisk_context *cxt, const char *fmt, ...);
827int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...);
20f878fe 828
0051ec9b
KZ
829/* utils.h */
830extern char *fdisk_partname(const char *dev, size_t partno);
831
d56a7c23
KZ
832#ifdef __cplusplus
833}
834#endif
835
0bb4c979 836#endif /* _LIBFDISK_H */