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