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