libfdisk.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. #ifndef _LIBFDISK_H
  21. #define _LIBFDISK_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include <stdio.h>
  26. #include <stdarg.h>
  27. #include <stdint.h>
  28. /**
  29. * LIBFDISK_VERSION:
  30. *
  31. * Library version string
  32. */
  33. #define LIBFDISK_VERSION "2.28.1"
  34. #define LIBFDISK_MAJOR_VERSION 2
  35. #define LIBFDISK_MINOR_VERSION 28
  36. #define LIBFDISK_PATCH_VERSION 1
  37. /**
  38. * fdisk_context:
  39. *
  40. * Basic library handler.
  41. */
  42. struct fdisk_context;
  43. /**
  44. * fdisk_label:
  45. *
  46. * Disk label specific driver and setting.
  47. */
  48. struct fdisk_label;
  49. /**
  50. * fdisk_parttype:
  51. *
  52. * Partition type.
  53. */
  54. struct fdisk_parttype;
  55. /**
  56. * fdisk_partition:
  57. *
  58. * Partition abstraction (and template).
  59. */
  60. struct fdisk_partition;
  61. /**
  62. * fdisk_ask:
  63. *
  64. * Ask API handler for dialogs with users.
  65. */
  66. struct fdisk_ask;
  67. /**
  68. * fdisk_iter:
  69. *
  70. * Unified iterator.
  71. */
  72. struct fdisk_iter;
  73. /**
  74. * fdisk_table:
  75. *
  76. * Container for fdisk_partition objects
  77. */
  78. struct fdisk_table;
  79. /**
  80. * fdisk_field
  81. *
  82. * Output field description.
  83. */
  84. struct fdisk_field;
  85. /**
  86. * fdisk_script
  87. *
  88. * library handler for sfdisk compatible scripts and dumps
  89. */
  90. struct fdisk_script;
  91. /**
  92. * fdisk_sector_t
  93. *
  94. * LBA adresses type
  95. */
  96. typedef uint64_t fdisk_sector_t;
  97. /**
  98. * fdisk_labeltype:
  99. *
  100. * Supported partition table types (labels)
  101. */
  102. enum fdisk_labeltype {
  103. FDISK_DISKLABEL_DOS = (1 << 1), /* MBR label type */
  104. FDISK_DISKLABEL_SUN = (1 << 2), /* SUN label type */
  105. FDISK_DISKLABEL_SGI = (1 << 3), /* SGI label type */
  106. FDISK_DISKLABEL_BSD = (1 << 4), /* BSD label t ype */
  107. FDISK_DISKLABEL_GPT = (1 << 5) /* UEFI GPT type */
  108. };
  109. /**
  110. * fdisk_labelitem
  111. *
  112. * library handler for label specific information. See
  113. * generic FDISK_LABELITEM_* and label specific {GPT,MBR,..}_LABELITEM_*.
  114. */
  115. struct fdisk_labelitem;
  116. /**
  117. * fdisk_asktype:
  118. *
  119. * Ask API dialog types
  120. */
  121. enum fdisk_asktype {
  122. FDISK_ASKTYPE_NONE = 0, /* undefined type */
  123. FDISK_ASKTYPE_NUMBER, /* ask for number */
  124. FDISK_ASKTYPE_OFFSET, /* ask for offset */
  125. FDISK_ASKTYPE_WARN, /* print warning message and errno */
  126. FDISK_ASKTYPE_WARNX, /* print warning message */
  127. FDISK_ASKTYPE_INFO, /* print infor message */
  128. FDISK_ASKTYPE_YESNO, /* ask Yes/No question */
  129. FDISK_ASKTYPE_STRING, /* ask for string */
  130. FDISK_ASKTYPE_MENU /* ask for menu item */
  131. };
  132. /* init.c */
  133. extern void fdisk_init_debug(int mask);
  134. /* version.c */
  135. extern int fdisk_parse_version_string(const char *ver_string);
  136. extern int fdisk_get_library_version(const char **ver_string);
  137. extern int fdisk_get_library_features(const char ***features);
  138. /* context.h */
  139. #define FDISK_PLURAL 0
  140. #define FDISK_SINGULAR 1
  141. struct fdisk_context *fdisk_new_context(void);
  142. struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent, const char *name);
  143. void fdisk_unref_context(struct fdisk_context *cxt);
  144. void fdisk_ref_context(struct fdisk_context *cxt);
  145. struct fdisk_context *fdisk_get_parent(struct fdisk_context *cxt);
  146. size_t fdisk_get_npartitions(struct fdisk_context *cxt);
  147. struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name);
  148. int fdisk_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
  149. size_t fdisk_get_nlabels(struct fdisk_context *cxt);
  150. int fdisk_has_label(struct fdisk_context *cxt);
  151. int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype id);
  152. #define fdisk_is_label(c, x) fdisk_is_labeltype(c, FDISK_DISKLABEL_ ## x)
  153. int fdisk_assign_device(struct fdisk_context *cxt,
  154. const char *fname, int readonly);
  155. int fdisk_deassign_device(struct fdisk_context *cxt, int nosync);
  156. int fdisk_is_readonly(struct fdisk_context *cxt);
  157. int fdisk_enable_details(struct fdisk_context *cxt, int enable);
  158. int fdisk_is_details(struct fdisk_context *cxt);
  159. int fdisk_enable_listonly(struct fdisk_context *cxt, int enable);
  160. int fdisk_is_listonly(struct fdisk_context *cxt);
  161. int fdisk_enable_wipe(struct fdisk_context *cxt, int enable);
  162. int fdisk_has_wipe(struct fdisk_context *cxt);
  163. const char *fdisk_get_collision(struct fdisk_context *cxt);
  164. int fdisk_set_unit(struct fdisk_context *cxt, const char *str);
  165. const char *fdisk_get_unit(struct fdisk_context *cxt, int n);
  166. int fdisk_use_cylinders(struct fdisk_context *cxt);
  167. unsigned int fdisk_get_units_per_sector(struct fdisk_context *cxt);
  168. unsigned long fdisk_get_optimal_iosize(struct fdisk_context *cxt);
  169. unsigned long fdisk_get_minimal_iosize(struct fdisk_context *cxt);
  170. unsigned long fdisk_get_physector_size(struct fdisk_context *cxt);
  171. unsigned long fdisk_get_sector_size(struct fdisk_context *cxt);
  172. unsigned long fdisk_get_alignment_offset(struct fdisk_context *cxt);
  173. unsigned long fdisk_get_grain_size(struct fdisk_context *cxt);
  174. fdisk_sector_t fdisk_get_first_lba(struct fdisk_context *cxt);
  175. fdisk_sector_t fdisk_set_first_lba(struct fdisk_context *cxt, fdisk_sector_t lba);
  176. fdisk_sector_t fdisk_get_last_lba(struct fdisk_context *cxt);
  177. fdisk_sector_t fdisk_set_last_lba(struct fdisk_context *cxt, fdisk_sector_t lba);
  178. fdisk_sector_t fdisk_get_nsectors(struct fdisk_context *cxt);
  179. const char *fdisk_get_devname(struct fdisk_context *cxt);
  180. int fdisk_get_devfd(struct fdisk_context *cxt);
  181. unsigned int fdisk_get_geom_heads(struct fdisk_context *cxt);
  182. fdisk_sector_t fdisk_get_geom_sectors(struct fdisk_context *cxt);
  183. fdisk_sector_t fdisk_get_geom_cylinders(struct fdisk_context *cxt);
  184. enum {
  185. FDISK_SIZEUNIT_HUMAN = 0, /* default, human readable {M,G,P,...} */
  186. FDISK_SIZEUNIT_BYTES /* bytes */
  187. };
  188. int fdisk_set_size_unit(struct fdisk_context *cxt, int unit);
  189. int fdisk_get_size_unit(struct fdisk_context *cxt);
  190. int fdisk_has_protected_bootbits(struct fdisk_context *cxt);
  191. int fdisk_enable_bootbits_protection(struct fdisk_context *cxt, int enable);
  192. /* parttype.c */
  193. struct fdisk_parttype *fdisk_new_parttype(void);
  194. void fdisk_ref_parttype(struct fdisk_parttype *t);
  195. void fdisk_unref_parttype(struct fdisk_parttype *t);
  196. int fdisk_parttype_set_name(struct fdisk_parttype *t, const char *str);
  197. int fdisk_parttype_set_typestr(struct fdisk_parttype *t, const char *str);
  198. int fdisk_parttype_set_code(struct fdisk_parttype *t, int code);
  199. size_t fdisk_label_get_nparttypes(const struct fdisk_label *lb);
  200. struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, size_t n);
  201. int fdisk_label_has_code_parttypes(const struct fdisk_label *lb);
  202. struct fdisk_parttype *fdisk_label_get_parttype_from_code(
  203. const struct fdisk_label *lb,
  204. unsigned int code);
  205. struct fdisk_parttype *fdisk_label_get_parttype_from_string(
  206. const struct fdisk_label *lb,
  207. const char *str);
  208. struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int code,
  209. const char *typestr);
  210. struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type);
  211. struct fdisk_parttype *fdisk_label_parse_parttype(
  212. const struct fdisk_label *lb,
  213. const char *str);
  214. const char *fdisk_parttype_get_string(const struct fdisk_parttype *t);
  215. unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t);
  216. const char *fdisk_parttype_get_name(const struct fdisk_parttype *t);
  217. int fdisk_parttype_is_unknown(const struct fdisk_parttype *t);
  218. /* label.c */
  219. /**
  220. * fdisk_fieldtype
  221. *
  222. * Types of fdisk_field. The fields describe a partition.
  223. */
  224. enum fdisk_fieldtype {
  225. FDISK_FIELD_NONE = 0,
  226. /* generic */
  227. FDISK_FIELD_DEVICE, /* partition device name */
  228. FDISK_FIELD_START, /* start offset of the partition */
  229. FDISK_FIELD_END, /* end offset of the partition */
  230. FDISK_FIELD_SECTORS, /* number of sectors */
  231. FDISK_FIELD_CYLINDERS, /* number of cylinders (deprecated) */
  232. FDISK_FIELD_SIZE, /* partition size */
  233. FDISK_FIELD_TYPE, /* partition type */
  234. FDISK_FIELD_TYPEID, /* partition type ID */
  235. /* label specific */
  236. FDISK_FIELD_ATTR, /* partition attribute (GPT) */
  237. FDISK_FIELD_BOOT, /* partition boot flag */
  238. FDISK_FIELD_BSIZE, /* size of the boot area (BSD) */
  239. FDISK_FIELD_CPG, /* BSD */
  240. FDISK_FIELD_EADDR, /* End-C/H/S (MBR) */
  241. FDISK_FIELD_FSIZE, /* BSD */
  242. FDISK_FIELD_NAME, /* partition label/name (GPT) */
  243. FDISK_FIELD_SADDR, /* Start-C/H/S (MBR) */
  244. FDISK_FIELD_UUID, /* partition UUID (GPT) */
  245. FDISK_NFIELDS /* must be last */
  246. };
  247. int fdisk_label_get_type(const struct fdisk_label *lb);
  248. const char *fdisk_label_get_name(const struct fdisk_label *lb);
  249. int fdisk_label_require_geometry(const struct fdisk_label *lb);
  250. extern int fdisk_write_disklabel(struct fdisk_context *cxt);
  251. extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
  252. extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
  253. extern int fdisk_list_disklabel(struct fdisk_context *cxt);
  254. extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n,
  255. const char **name,
  256. uint64_t *offset,
  257. size_t *size);
  258. /**
  259. * fdisk_labelitem_gen
  260. *
  261. * Generic disklabel items
  262. */
  263. enum fdisk_labelitem_gen {
  264. FDISK_LABELITEM_ID = 0, /* Unique disk identifier */
  265. __FDISK_NLABELITEMS = 8 /* Specifies reserved range for generic items (0..7) */
  266. };
  267. extern int fdisk_get_disklabel_item(struct fdisk_context *cxt, int id, struct fdisk_labelitem *item);
  268. extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
  269. extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
  270. extern int fdisk_get_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition **pa);
  271. extern int fdisk_set_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition *pa);
  272. extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_partition *pa, size_t *partno);
  273. extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partno);
  274. extern int fdisk_delete_all_partitions(struct fdisk_context *cxt);
  275. extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
  276. struct fdisk_parttype *t);
  277. extern int fdisk_label_get_fields_ids(
  278. const struct fdisk_label *lb,
  279. struct fdisk_context *cxt,
  280. int **ids, size_t *nids);
  281. extern int fdisk_label_get_fields_ids_all(
  282. const struct fdisk_label *lb,
  283. struct fdisk_context *cxt,
  284. int **ids, size_t *nids);
  285. extern const struct fdisk_field *fdisk_label_get_field(const struct fdisk_label *lb, int id);
  286. extern const struct fdisk_field *fdisk_label_get_field_by_name(
  287. const struct fdisk_label *lb,
  288. const char *name);
  289. extern int fdisk_field_get_id(const struct fdisk_field *field);
  290. extern const char *fdisk_field_get_name(const struct fdisk_field *field);
  291. extern double fdisk_field_get_width(const struct fdisk_field *field);
  292. extern int fdisk_field_is_number(const struct fdisk_field *field);
  293. extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
  294. extern int fdisk_label_is_changed(const struct fdisk_label *lb);
  295. extern void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled);
  296. extern int fdisk_label_is_disabled(const struct fdisk_label *lb);
  297. extern int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n);
  298. extern int fdisk_toggle_partition_flag(struct fdisk_context *cxt, size_t partnum, unsigned long flag);
  299. extern struct fdisk_partition *fdisk_new_partition(void);
  300. extern void fdisk_reset_partition(struct fdisk_partition *pa);
  301. extern void fdisk_ref_partition(struct fdisk_partition *pa);
  302. extern void fdisk_unref_partition(struct fdisk_partition *pa);
  303. extern int fdisk_partition_is_freespace(struct fdisk_partition *pa);
  304. int fdisk_partition_set_start(struct fdisk_partition *pa, uint64_t off);
  305. int fdisk_partition_unset_start(struct fdisk_partition *pa);
  306. uint64_t fdisk_partition_get_start(struct fdisk_partition *pa);
  307. int fdisk_partition_has_start(struct fdisk_partition *pa);
  308. int fdisk_partition_cmp_start(struct fdisk_partition *a,
  309. struct fdisk_partition *b);
  310. int fdisk_partition_start_follow_default(struct fdisk_partition *pa, int enable);
  311. int fdisk_partition_start_is_default(struct fdisk_partition *pa);
  312. int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t sz);
  313. int fdisk_partition_unset_size(struct fdisk_partition *pa);
  314. uint64_t fdisk_partition_get_size(struct fdisk_partition *pa);
  315. int fdisk_partition_has_size(struct fdisk_partition *pa);
  316. int fdisk_partition_size_explicit(struct fdisk_partition *pa, int enable);
  317. int fdisk_partition_has_end(struct fdisk_partition *pa);
  318. fdisk_sector_t fdisk_partition_get_end(struct fdisk_partition *pa);
  319. int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t num);
  320. int fdisk_partition_unset_partno(struct fdisk_partition *pa);
  321. size_t fdisk_partition_get_partno(struct fdisk_partition *pa);
  322. int fdisk_partition_has_partno(struct fdisk_partition *pa);
  323. int fdisk_partition_cmp_partno(struct fdisk_partition *a,
  324. struct fdisk_partition *b);
  325. int fdisk_partition_partno_follow_default(struct fdisk_partition *pa, int enable);
  326. extern int fdisk_partition_set_type(struct fdisk_partition *pa, struct fdisk_parttype *type);
  327. extern struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa);
  328. extern int fdisk_partition_set_name(struct fdisk_partition *pa, const char *name);
  329. extern const char *fdisk_partition_get_name(struct fdisk_partition *pa);
  330. extern int fdisk_partition_set_uuid(struct fdisk_partition *pa, const char *uuid);
  331. extern int fdisk_partition_set_attrs(struct fdisk_partition *pa, const char *attrs);
  332. extern const char *fdisk_partition_get_uuid(struct fdisk_partition *pa);
  333. extern const char *fdisk_partition_get_attrs(struct fdisk_partition *pa);
  334. extern int fdisk_partition_is_nested(struct fdisk_partition *pa);
  335. extern int fdisk_partition_is_container(struct fdisk_partition *pa);
  336. extern int fdisk_partition_get_parent(struct fdisk_partition *pa, size_t *parent);
  337. extern int fdisk_partition_is_used(struct fdisk_partition *pa);
  338. extern int fdisk_partition_is_bootable(struct fdisk_partition *pa);
  339. extern int fdisk_partition_is_wholedisk(struct fdisk_partition *pa);
  340. extern int fdisk_partition_to_string(struct fdisk_partition *pa,
  341. struct fdisk_context *cxt,
  342. int id, char **data);
  343. int fdisk_partition_next_partno(struct fdisk_partition *pa,
  344. struct fdisk_context *cxt,
  345. size_t *n);
  346. extern int fdisk_partition_end_follow_default(struct fdisk_partition *pa, int enable);
  347. extern int fdisk_partition_end_is_default(struct fdisk_partition *pa);
  348. extern int fdisk_reorder_partitions(struct fdisk_context *cxt);
  349. /* table.c */
  350. extern struct fdisk_table *fdisk_new_table(void);
  351. extern int fdisk_reset_table(struct fdisk_table *tb);
  352. extern void fdisk_ref_table(struct fdisk_table *tb);
  353. extern void fdisk_unref_table(struct fdisk_table *tb);
  354. extern size_t fdisk_table_get_nents(struct fdisk_table *tb);
  355. extern int fdisk_table_is_empty(struct fdisk_table *tb);
  356. extern int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
  357. extern int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
  358. extern int fdisk_get_partitions(struct fdisk_context *cxt, struct fdisk_table **tb);
  359. extern int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb);
  360. extern int fdisk_table_wrong_order(struct fdisk_table *tb);
  361. extern int fdisk_table_sort_partitions(struct fdisk_table *tb,
  362. int (*cmp)(struct fdisk_partition *,
  363. struct fdisk_partition *));
  364. extern int fdisk_table_next_partition(
  365. struct fdisk_table *tb,
  366. struct fdisk_iter *itr,
  367. struct fdisk_partition **pa);
  368. extern struct fdisk_partition *fdisk_table_get_partition(
  369. struct fdisk_table *tb,
  370. size_t n);
  371. extern struct fdisk_partition *fdisk_table_get_partition_by_partno(
  372. struct fdisk_table *tb,
  373. size_t partno);
  374. extern int fdisk_apply_table(struct fdisk_context *cxt, struct fdisk_table *tb);
  375. /* alignment.c */
  376. #define FDISK_ALIGN_UP 1
  377. #define FDISK_ALIGN_DOWN 2
  378. #define FDISK_ALIGN_NEAREST 3
  379. fdisk_sector_t fdisk_align_lba(struct fdisk_context *cxt, fdisk_sector_t lba, int direction);
  380. fdisk_sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
  381. fdisk_sector_t lba, fdisk_sector_t start, fdisk_sector_t stop);
  382. int fdisk_lba_is_phy_aligned(struct fdisk_context *cxt, fdisk_sector_t lba);
  383. int fdisk_override_geometry(struct fdisk_context *cxt,
  384. unsigned int cylinders,
  385. unsigned int heads,
  386. unsigned int sectors);
  387. int fdisk_save_user_geometry(struct fdisk_context *cxt,
  388. unsigned int cylinders,
  389. unsigned int heads,
  390. unsigned int sectors);
  391. int fdisk_save_user_sector_size(struct fdisk_context *cxt,
  392. unsigned int phy,
  393. unsigned int log);
  394. int fdisk_has_user_device_properties(struct fdisk_context *cxt);
  395. int fdisk_reset_alignment(struct fdisk_context *cxt);
  396. int fdisk_reset_device_properties(struct fdisk_context *cxt);
  397. int fdisk_reread_partition_table(struct fdisk_context *cxt);
  398. /* iter.c */
  399. enum {
  400. FDISK_ITER_FORWARD = 0,
  401. FDISK_ITER_BACKWARD
  402. };
  403. extern struct fdisk_iter *fdisk_new_iter(int direction);
  404. extern void fdisk_free_iter(struct fdisk_iter *itr);
  405. extern void fdisk_reset_iter(struct fdisk_iter *itr, int direction);
  406. extern int fdisk_iter_get_direction(struct fdisk_iter *itr);
  407. /* dos.c */
  408. #define DOS_FLAG_ACTIVE 1
  409. extern int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i);
  410. extern int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable);
  411. extern int fdisk_dos_is_compatible(struct fdisk_label *lb);
  412. /* sun.h */
  413. extern int fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
  414. extern int fdisk_sun_set_xcyl(struct fdisk_context *cxt);
  415. extern int fdisk_sun_set_ilfact(struct fdisk_context *cxt);
  416. extern int fdisk_sun_set_rspeed(struct fdisk_context *cxt);
  417. extern int fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
  418. enum fdisk_labelitem_sun {
  419. SUN_LABELITEM_LABELID = __FDISK_NLABELITEMS,
  420. SUN_LABELITEM_VTOCID,
  421. SUN_LABELITEM_RPM,
  422. SUN_LABELITEM_ACYL,
  423. SUN_LABELITEM_PCYL,
  424. SUN_LABELITEM_APC,
  425. SUN_LABELITEM_INTRLV
  426. };
  427. /* bsd.c */
  428. extern int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt);
  429. extern int fdisk_bsd_write_bootstrap(struct fdisk_context *cxt);
  430. extern int fdisk_bsd_link_partition(struct fdisk_context *cxt);
  431. enum fdisk_labelitem_bsd {
  432. /* specific */
  433. BSD_LABELITEM_TYPE = __FDISK_NLABELITEMS,
  434. BSD_LABELITEM_DISK,
  435. BSD_LABELITEM_PACKNAME,
  436. BSD_LABELITEM_FLAGS,
  437. BSD_LABELITEM_SECSIZE,
  438. BSD_LABELITEM_NTRACKS,
  439. BSD_LABELITEM_SECPERCYL,
  440. BSD_LABELITEM_CYLINDERS,
  441. BSD_LABELITEM_RPM,
  442. BSD_LABELITEM_INTERLEAVE,
  443. BSD_LABELITEM_TRACKSKEW,
  444. BSD_LABELITEM_CYLINDERSKEW,
  445. BSD_LABELITEM_HEADSWITCH,
  446. BSD_LABELITEM_TRKSEEK
  447. };
  448. /* sgi.h */
  449. #define SGI_FLAG_BOOT 1
  450. #define SGI_FLAG_SWAP 2
  451. extern int fdisk_sgi_set_bootfile(struct fdisk_context *cxt);
  452. extern int fdisk_sgi_create_info(struct fdisk_context *cxt);
  453. enum fdisk_labelitem_sgi {
  454. SGI_LABELITEM_PCYLCOUNT = __FDISK_NLABELITEMS,
  455. SGI_LABELITEM_SPARECYL,
  456. SGI_LABELITEM_ILFACT,
  457. SGI_LABELITEM_BOOTFILE
  458. };
  459. /* gpt */
  460. /*
  461. * GPT partition attributes
  462. */
  463. /**
  464. * GPT_FLAG_REQUIRED:
  465. *
  466. * GPT attribute; marks a partition as system partition (disk
  467. * partitioning utilities must preserve the partition as is)
  468. */
  469. #define GPT_FLAG_REQUIRED 1
  470. /**
  471. * GPT_FLAG_NOBLOCK:
  472. *
  473. * GPT attribute; EFI firmware should ignore the content of the
  474. * partition and not try to read from it
  475. */
  476. #define GPT_FLAG_NOBLOCK 2
  477. /**
  478. * GPT_FLAG_LEGACYBOOT:
  479. *
  480. * GPT attribute; use the partition for legacy boot method
  481. */
  482. #define GPT_FLAG_LEGACYBOOT 3
  483. /**
  484. * GPT_FLAG_GUIDSPECIFIC:
  485. *
  486. * GPT attribute; for bites 48-63, defined and used by the individual partition
  487. * type.
  488. *
  489. * The flag GPT_FLAG_GUIDSPECIFIC forces libfdisk to ask (by ask API)
  490. * for a bit number. If you want to toggle specific bit and avoid any
  491. * dialog, then use the bit number (in range 48..63). For example:
  492. *
  493. * // start dialog to ask for bit number
  494. * fdisk_toggle_partition_flag(cxt, n, GPT_FLAG_GUIDSPECIFIC);
  495. *
  496. * // toggle bit 60
  497. * fdisk_toggle_partition_flag(cxt, n, 60);
  498. */
  499. #define GPT_FLAG_GUIDSPECIFIC 4
  500. extern int fdisk_gpt_is_hybrid(struct fdisk_context *cxt);
  501. extern int fdisk_gpt_get_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t *attrs);
  502. extern int fdisk_gpt_set_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t attrs);
  503. enum fdisk_labelitem_gpt {
  504. /* generic */
  505. GPT_LABELITEM_ID = FDISK_LABELITEM_ID, /* GPT disklabel UUID (!= partition UUID) */
  506. /* specific */
  507. GPT_LABELITEM_FIRSTLBA = __FDISK_NLABELITEMS, /* First Usable LBA */
  508. GPT_LABELITEM_LASTLBA, /* Last Usable LBA */
  509. GPT_LABELITEM_ALTLBA, /* Alternative LBA (backup header LBA) */
  510. GPT_LABELITEM_ENTRIESLBA, /* Partitions entires array LBA */
  511. GPT_LABELITEM_ENTRIESALLOC /* Number of allocated entries in entries array */
  512. };
  513. /* script.c */
  514. struct fdisk_script *fdisk_new_script(struct fdisk_context *cxt);
  515. struct fdisk_script *fdisk_new_script_from_file(struct fdisk_context *cxt,
  516. const char *filename);
  517. void fdisk_ref_script(struct fdisk_script *dp);
  518. void fdisk_unref_script(struct fdisk_script *dp);
  519. const char *fdisk_script_get_header(struct fdisk_script *dp, const char *name);
  520. int fdisk_script_set_header(struct fdisk_script *dp, const char *name, const char *data);
  521. struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp);
  522. int fdisk_script_get_nlines(struct fdisk_script *dp);
  523. int fdisk_script_set_userdata(struct fdisk_script *dp, void *data);
  524. void *fdisk_script_get_userdata(struct fdisk_script *dp);
  525. int fdisk_script_set_fgets(struct fdisk_script *dp,
  526. char *(*fn_fgets)(struct fdisk_script *, char *, size_t, FILE *));
  527. int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt);
  528. int fdisk_script_enable_json(struct fdisk_script *dp, int json);
  529. int fdisk_script_write_file(struct fdisk_script *dp, FILE *f);
  530. int fdisk_script_read_file(struct fdisk_script *dp, FILE *f);
  531. int fdisk_script_read_line(struct fdisk_script *dp, FILE *f, char *buf, size_t bufsz);
  532. int fdisk_set_script(struct fdisk_context *cxt, struct fdisk_script *dp);
  533. struct fdisk_script *fdisk_get_script(struct fdisk_context *cxt);
  534. int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *dp);
  535. int fdisk_apply_script(struct fdisk_context *cxt, struct fdisk_script *dp);
  536. /* ask.c */
  537. #define fdisk_is_ask(a, x) (fdisk_ask_get_type(a) == FDISK_ASKTYPE_ ## x)
  538. int fdisk_set_ask(struct fdisk_context *cxt,
  539. int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *),
  540. void *data);
  541. void fdisk_ref_ask(struct fdisk_ask *ask);
  542. void fdisk_unref_ask(struct fdisk_ask *ask);
  543. const char *fdisk_ask_get_query(struct fdisk_ask *ask);
  544. int fdisk_ask_get_type(struct fdisk_ask *ask);
  545. const char *fdisk_ask_number_get_range(struct fdisk_ask *ask);
  546. uint64_t fdisk_ask_number_get_default(struct fdisk_ask *ask);
  547. uint64_t fdisk_ask_number_get_low(struct fdisk_ask *ask);
  548. uint64_t fdisk_ask_number_get_high(struct fdisk_ask *ask);
  549. uint64_t fdisk_ask_number_get_result(struct fdisk_ask *ask);
  550. int fdisk_ask_number_set_result(struct fdisk_ask *ask, uint64_t result);
  551. uint64_t fdisk_ask_number_get_base(struct fdisk_ask *ask);
  552. uint64_t fdisk_ask_number_get_unit(struct fdisk_ask *ask);
  553. int fdisk_ask_number_set_relative(struct fdisk_ask *ask, int relative);
  554. int fdisk_ask_number_inchars(struct fdisk_ask *ask);
  555. int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew);
  556. int fdisk_ask_number(struct fdisk_context *cxt,
  557. uintmax_t low,
  558. uintmax_t dflt,
  559. uintmax_t high,
  560. const char *query,
  561. uintmax_t *result);
  562. char *fdisk_ask_string_get_result(struct fdisk_ask *ask);
  563. int fdisk_ask_string_set_result(struct fdisk_ask *ask, char *result);
  564. int fdisk_ask_string(struct fdisk_context *cxt,
  565. const char *query,
  566. char **result);
  567. int fdisk_ask_yesno(struct fdisk_context *cxt,
  568. const char *query,
  569. int *result);
  570. int fdisk_ask_yesno_get_result(struct fdisk_ask *ask);
  571. int fdisk_ask_yesno_set_result(struct fdisk_ask *ask, int result);
  572. int fdisk_ask_menu_get_default(struct fdisk_ask *ask);
  573. int fdisk_ask_menu_set_result(struct fdisk_ask *ask, int key);
  574. int fdisk_ask_menu_get_result(struct fdisk_ask *ask, int *key);
  575. int fdisk_ask_menu_get_item(struct fdisk_ask *ask, size_t idx, int *key,
  576. const char **name, const char **desc);
  577. size_t fdisk_ask_menu_get_nitems(struct fdisk_ask *ask);
  578. int fdisk_ask_print_get_errno(struct fdisk_ask *ask);
  579. const char *fdisk_ask_print_get_mesg(struct fdisk_ask *ask);
  580. int fdisk_info(struct fdisk_context *cxt, const char *fmt, ...);
  581. int fdisk_warn(struct fdisk_context *cxt, const char *fmt, ...);
  582. int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...);
  583. /* utils.h */
  584. extern char *fdisk_partname(const char *dev, size_t partno);
  585. #ifdef __cplusplus
  586. }
  587. #endif
  588. #endif /* _LIBFDISK_H */