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