]>
Commit | Line | Data |
---|---|---|
d56a7c23 KZ |
1 | /* |
2 | * fdiskP.h - private library header file | |
3 | * | |
4 | * Copyright (C) 2012 Karel Zak <kzak@redhat.com> | |
5 | * | |
6 | * This file may be redistributed under the terms of the | |
7 | * GNU Lesser General Public License. | |
8 | */ | |
9 | ||
10 | #ifndef _LIBFDISK_PRIVATE_H | |
11 | #define _LIBFDISK_PRIVATE_H | |
12 | ||
13 | #include <errno.h> | |
14 | #include <stdlib.h> | |
15 | #include <string.h> | |
16 | #include <sys/stat.h> | |
17 | #include <sys/types.h> | |
18 | #include <unistd.h> | |
9f20d800 | 19 | #include <uuid.h> |
d56a7c23 KZ |
20 | |
21 | #include "c.h" | |
22 | #include "libfdisk.h" | |
23 | ||
b48cdebc | 24 | #include "list.h" |
2618b9cc | 25 | #include "debug.h" |
88141067 KZ |
26 | #include <stdio.h> |
27 | #include <stdarg.h> | |
9475cc78 | 28 | |
d56a7c23 KZ |
29 | /* |
30 | * Debug | |
31 | */ | |
4dcea320 KZ |
32 | #define LIBFDISK_DEBUG_HELP (1 << 0) |
33 | #define LIBFDISK_DEBUG_INIT (1 << 1) | |
34 | #define LIBFDISK_DEBUG_CXT (1 << 2) | |
35 | #define LIBFDISK_DEBUG_LABEL (1 << 3) | |
36 | #define LIBFDISK_DEBUG_ASK (1 << 4) | |
37 | #define LIBFDISK_DEBUG_PART (1 << 6) | |
38 | #define LIBFDISK_DEBUG_PARTTYPE (1 << 7) | |
39 | #define LIBFDISK_DEBUG_TAB (1 << 8) | |
40 | #define LIBFDISK_DEBUG_SCRIPT (1 << 9) | |
131e38a2 | 41 | #define LIBFDISK_DEBUG_WIPE (1 << 10) |
40c9c3a6 | 42 | #define LIBFDISK_DEBUG_ITEM (1 << 11) |
4dcea320 | 43 | #define LIBFDISK_DEBUG_ALL 0xFFFF |
d56a7c23 | 44 | |
2618b9cc | 45 | UL_DEBUG_DECLARE_MASK(libfdisk); |
4dcea320 KZ |
46 | #define DBG(m, x) __UL_DBG(libfdisk, LIBFDISK_DEBUG_, m, x) |
47 | #define ON_DBG(m, x) __UL_DBG_CALL(libfdisk, LIBFDISK_DEBUG_, m, x) | |
48 | #define DBG_FLUSH __UL_DBG_FLUSH(libfdisk, LIBFDISK_DEBUG_) | |
d56a7c23 | 49 | |
6d00cfb2 KZ |
50 | #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libfdisk) |
51 | #include "debugobj.h" | |
52 | ||
7095232d KZ |
53 | /* |
54 | * NLS -- the library has to be independent on main program, so define | |
55 | * UL_TEXTDOMAIN_EXPLICIT before you include nls.h. | |
56 | * | |
57 | * Now we use util-linux.po (=PACKAGE), rather than maintain the texts | |
58 | * in the separate libfdisk.po file. | |
59 | */ | |
60 | #define LIBFDISK_TEXTDOMAIN PACKAGE | |
61 | #define UL_TEXTDOMAIN_EXPLICIT LIBFDISK_TEXTDOMAIN | |
62 | #include "nls.h" | |
63 | ||
64 | ||
58d62d2f KZ |
65 | #ifdef TEST_PROGRAM |
66 | struct fdisk_test { | |
67 | const char *name; | |
68 | int (*body)(struct fdisk_test *ts, int argc, char *argv[]); | |
69 | const char *usage; | |
70 | }; | |
71 | ||
72 | /* test.c */ | |
73 | extern int fdisk_run_test(struct fdisk_test *tests, int argc, char *argv[]); | |
74 | #endif | |
75 | ||
74760053 | 76 | #define FDISK_GPT_NPARTITIONS_DEFAULT 128 |
58d62d2f | 77 | |
6c89f750 KZ |
78 | /* |
79 | * Generic iterator | |
80 | */ | |
81 | struct fdisk_iter { | |
82 | struct list_head *p; /* current position */ | |
83 | struct list_head *head; /* start position */ | |
84 | int direction; /* FDISK_ITER_{FOR,BACK}WARD */ | |
85 | }; | |
86 | ||
87 | #define IS_ITER_FORWARD(_i) ((_i)->direction == FDISK_ITER_FORWARD) | |
88 | #define IS_ITER_BACKWARD(_i) ((_i)->direction == FDISK_ITER_BACKWARD) | |
89 | ||
90 | #define FDISK_ITER_INIT(itr, list) \ | |
91 | do { \ | |
92 | (itr)->p = IS_ITER_FORWARD(itr) ? \ | |
93 | (list)->next : (list)->prev; \ | |
94 | (itr)->head = (list); \ | |
95 | } while(0) | |
96 | ||
97 | #define FDISK_ITER_ITERATE(itr, res, restype, member) \ | |
98 | do { \ | |
99 | res = list_entry((itr)->p, restype, member); \ | |
100 | (itr)->p = IS_ITER_FORWARD(itr) ? \ | |
101 | (itr)->p->next : (itr)->p->prev; \ | |
102 | } while(0) | |
103 | ||
a8019843 KZ |
104 | /* |
105 | * Partition types | |
106 | */ | |
107 | struct fdisk_parttype { | |
a745611d | 108 | unsigned int code; /* type as number or zero */ |
dfc6db2a | 109 | char *name; /* description */ |
a8019843 KZ |
110 | char *typestr; /* type as string or NULL */ |
111 | ||
112 | unsigned int flags; /* FDISK_PARTTYPE_* flags */ | |
dfc6db2a | 113 | int refcount; /* reference counter for allocated types */ |
a8019843 KZ |
114 | }; |
115 | ||
116 | enum { | |
117 | FDISK_PARTTYPE_UNKNOWN = (1 << 1), | |
118 | FDISK_PARTTYPE_INVISIBLE = (1 << 2), | |
119 | FDISK_PARTTYPE_ALLOCATED = (1 << 3) | |
120 | }; | |
121 | ||
a8019843 KZ |
122 | #define fdisk_parttype_is_invisible(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_INVISIBLE)) |
123 | #define fdisk_parttype_is_allocated(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_ALLOCATED)) | |
124 | ||
8c0a7f91 | 125 | struct fdisk_partition { |
b48cdebc | 126 | int refcount; /* reference counter */ |
ecf40cda | 127 | |
b48cdebc | 128 | size_t partno; /* partition number */ |
03643931 | 129 | size_t parent_partno; /* for logical partitions */ |
82ebc7de | 130 | |
0073a4cf | 131 | fdisk_sector_t start; /* first sectors */ |
0073a4cf | 132 | fdisk_sector_t size; /* size in sectors */ |
82ebc7de | 133 | |
6f163929 KZ |
134 | int movestart; /* FDISK_MOVE_* (scripts only) */ |
135 | int resize; /* FDISK_RESIZE_* (scripts only) */ | |
136 | ||
b48cdebc KZ |
137 | char *name; /* partition name */ |
138 | char *uuid; /* partition UUID */ | |
139 | char *attrs; /* partition flags/attributes converted to string */ | |
140 | struct fdisk_parttype *type; /* partition type */ | |
8c0a7f91 | 141 | |
131e38a2 KZ |
142 | char *fstype; /* filesystem type */ |
143 | char *fsuuid; /* filesystem uuid */ | |
144 | char *fslabel; /* filesystem label */ | |
145 | ||
b48cdebc | 146 | struct list_head parts; /* list of partitions */ |
8c0a7f91 | 147 | |
b48cdebc KZ |
148 | /* extra fields for partition_to_string() */ |
149 | char start_post; /* start postfix (e.g. '+') */ | |
150 | char end_post; /* end postfix */ | |
151 | char size_post; /* size postfix */ | |
152 | ||
153 | uint64_t fsize; /* bsd junk */ | |
82ebc7de KZ |
154 | uint64_t bsize; |
155 | uint64_t cpg; | |
156 | ||
ecf40cda KZ |
157 | char *start_chs; /* start C/H/S in string */ |
158 | char *end_chs; /* end C/H/S in string */ | |
82ebc7de | 159 | |
ecf40cda | 160 | unsigned int boot; /* MBR: bootable */ |
150d98ee | 161 | |
ecf40cda | 162 | unsigned int container : 1, /* container partition (e.g. extended partition) */ |
b48cdebc | 163 | end_follow_default : 1, /* use default end */ |
ecf40cda KZ |
164 | freespace : 1, /* this is free space */ |
165 | partno_follow_default : 1, /* use default partno */ | |
892c89eb | 166 | size_explicit : 1, /* don't align the size */ |
ecf40cda | 167 | start_follow_default : 1, /* use default start */ |
131e38a2 | 168 | fs_probed : 1, /* already probed by blkid */ |
ecf40cda KZ |
169 | used : 1, /* partition already used */ |
170 | wholedisk : 1; /* special system partition */ | |
8c0a7f91 KZ |
171 | }; |
172 | ||
6f163929 KZ |
173 | enum { |
174 | FDISK_MOVE_NONE = 0, | |
175 | FDISK_MOVE_DOWN = -1, | |
176 | FDISK_MOVE_UP = 1 | |
177 | }; | |
178 | ||
179 | enum { | |
180 | FDISK_RESIZE_NONE = 0, | |
181 | FDISK_RESIZE_REDUCE = -1, | |
182 | FDISK_RESIZE_ENLARGE = 1 | |
183 | }; | |
184 | ||
ecf40cda KZ |
185 | #define FDISK_INIT_UNDEF(_x) ((_x) = (__typeof__(_x)) -1) |
186 | #define FDISK_IS_UNDEF(_x) ((_x) == (__typeof__(_x)) -1) | |
8c0a7f91 | 187 | |
b48cdebc KZ |
188 | struct fdisk_table { |
189 | struct list_head parts; /* partitions */ | |
190 | int refcount; | |
04406c0d | 191 | size_t nents; /* number of partitions */ |
b48cdebc KZ |
192 | }; |
193 | ||
a8019843 KZ |
194 | /* |
195 | * Legacy CHS based geometry | |
196 | */ | |
197 | struct fdisk_geometry { | |
198 | unsigned int heads; | |
0073a4cf KZ |
199 | fdisk_sector_t sectors; |
200 | fdisk_sector_t cylinders; | |
a8019843 KZ |
201 | }; |
202 | ||
0c5d095e KZ |
203 | /* |
204 | * Label specific operations | |
205 | */ | |
206 | struct fdisk_label_operations { | |
207 | /* probe disk label */ | |
9ffeb235 | 208 | int (*probe)(struct fdisk_context *cxt); |
0c5d095e | 209 | /* write in-memory changes to disk */ |
9ffeb235 | 210 | int (*write)(struct fdisk_context *cxt); |
0c5d095e | 211 | /* verify the partition table */ |
9ffeb235 | 212 | int (*verify)(struct fdisk_context *cxt); |
0c5d095e | 213 | /* create new disk label */ |
9ffeb235 | 214 | int (*create)(struct fdisk_context *cxt); |
c0d20aae | 215 | /* returns offset and size of the 'n' part of the PT */ |
9bbcf43f KZ |
216 | int (*locate)(struct fdisk_context *cxt, int n, const char **name, |
217 | uint64_t *offset, size_t *size); | |
dd7ba604 KZ |
218 | /* reorder partitions */ |
219 | int (*reorder)(struct fdisk_context *cxt); | |
5989556a KZ |
220 | /* get details from label */ |
221 | int (*get_item)(struct fdisk_context *cxt, struct fdisk_labelitem *item); | |
35b1f0a4 KZ |
222 | /* set disk label ID */ |
223 | int (*set_id)(struct fdisk_context *cxt); | |
3c5fb475 | 224 | |
77d6a70a | 225 | |
e11c6684 KZ |
226 | /* new partition */ |
227 | int (*add_part)(struct fdisk_context *cxt, struct fdisk_partition *pa, | |
228 | size_t *partno); | |
0c5d095e | 229 | /* delete partition */ |
e11c6684 KZ |
230 | int (*del_part)(struct fdisk_context *cxt, size_t partnum); |
231 | ||
232 | /* fill in partition struct */ | |
233 | int (*get_part)(struct fdisk_context *cxt, size_t n, | |
234 | struct fdisk_partition *pa); | |
0dad2177 KZ |
235 | /* modify partition */ |
236 | int (*set_part)(struct fdisk_context *cxt, size_t n, | |
237 | struct fdisk_partition *pa); | |
e11c6684 | 238 | |
8c0a7f91 KZ |
239 | /* return state of the partition */ |
240 | int (*part_is_used)(struct fdisk_context *cxt, size_t partnum); | |
47b8e7c0 | 241 | |
fb1caca7 KZ |
242 | int (*part_toggle_flag)(struct fdisk_context *cxt, size_t i, unsigned long flag); |
243 | ||
0c5d095e | 244 | /* refresh alignment setting */ |
9ffeb235 | 245 | int (*reset_alignment)(struct fdisk_context *cxt); |
0c5d095e KZ |
246 | |
247 | /* free in-memory label stuff */ | |
248 | void (*free)(struct fdisk_label *lb); | |
9ffeb235 | 249 | |
4e0e8253 KZ |
250 | /* deinit in-memory label stuff */ |
251 | void (*deinit)(struct fdisk_label *lb); | |
0c5d095e KZ |
252 | }; |
253 | ||
21a44c9b | 254 | /* |
bd85d11f | 255 | * The fields describes how to display libfdisk_partition |
21a44c9b | 256 | */ |
bd85d11f KZ |
257 | struct fdisk_field { |
258 | int id; /* FDISK_FIELD_* */ | |
259 | const char *name; /* field name */ | |
260 | double width; /* field width (compatible with libsmartcols whint) */ | |
261 | int flags; /* FDISK_FIELDFL_* */ | |
d6faa8e0 KZ |
262 | }; |
263 | ||
9e930041 | 264 | /* note that the defaults is to display a column always */ |
d6faa8e0 | 265 | enum { |
6a632136 KZ |
266 | FDISK_FIELDFL_DETAIL = (1 << 1), /* only display if fdisk_is_details() */ |
267 | FDISK_FIELDFL_EYECANDY = (1 << 2), /* don't display if fdisk_is_details() */ | |
bd85d11f | 268 | FDISK_FIELDFL_NUMBER = (1 << 3), /* column display numbers */ |
21a44c9b KZ |
269 | }; |
270 | ||
0c5d095e KZ |
271 | /* |
272 | * Generic label | |
273 | */ | |
274 | struct fdisk_label { | |
9fcd49d5 | 275 | const char *name; /* label name */ |
53b422ab | 276 | enum fdisk_labeltype id; /* FDISK_DISKLABEL_* */ |
9fcd49d5 | 277 | struct fdisk_parttype *parttypes; /* supported partitions types */ |
0c5d095e KZ |
278 | size_t nparttypes; /* number of items in parttypes[] */ |
279 | ||
9fcd49d5 KZ |
280 | size_t nparts_max; /* maximal number of partitions */ |
281 | size_t nparts_cur; /* number of currently used partitions */ | |
0c5d095e | 282 | |
baa7cccc KZ |
283 | int flags; /* FDISK_LABEL_FL_* flags */ |
284 | ||
2dd2880f KZ |
285 | struct fdisk_geometry geom_min; /* minimal geometry */ |
286 | struct fdisk_geometry geom_max; /* maximal geometry */ | |
287 | ||
7a188aed KZ |
288 | unsigned int changed:1, /* label has been modified */ |
289 | disabled:1; /* this driver is disabled at all */ | |
2e3b40d3 | 290 | |
bd85d11f KZ |
291 | const struct fdisk_field *fields; /* all possible fields */ |
292 | size_t nfields; | |
21a44c9b | 293 | |
9fcd49d5 | 294 | const struct fdisk_label_operations *op; |
0c5d095e KZ |
295 | }; |
296 | ||
21a44c9b | 297 | |
baa7cccc KZ |
298 | /* label driver flags */ |
299 | enum { | |
181aab40 KZ |
300 | FDISK_LABEL_FL_REQUIRE_GEOMETRY = (1 << 2), |
301 | FDISK_LABEL_FL_INCHARS_PARTNO = (1 << 3) | |
baa7cccc KZ |
302 | }; |
303 | ||
0c5d095e KZ |
304 | /* label allocators */ |
305 | extern struct fdisk_label *fdisk_new_gpt_label(struct fdisk_context *cxt); | |
306 | extern struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt); | |
0c5d095e | 307 | extern struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt); |
0c5d095e KZ |
308 | extern struct fdisk_label *fdisk_new_sgi_label(struct fdisk_context *cxt); |
309 | extern struct fdisk_label *fdisk_new_sun_label(struct fdisk_context *cxt); | |
310 | ||
7845ca8d | 311 | |
20f878fe KZ |
312 | struct ask_menuitem { |
313 | char key; | |
314 | const char *name; | |
315 | const char *desc; | |
316 | ||
317 | struct ask_menuitem *next; | |
318 | }; | |
319 | ||
7845ca8d KZ |
320 | /* fdisk dialog -- note that nothing from this stuff will be directly exported, |
321 | * we will have get/set() function for everything. | |
322 | */ | |
323 | struct fdisk_ask { | |
7845ca8d | 324 | int type; /* FDISK_ASKTYPE_* */ |
7845ca8d | 325 | char *query; |
7845ca8d | 326 | |
a3d83488 KZ |
327 | int refcount; |
328 | ||
7845ca8d | 329 | union { |
4114da08 | 330 | /* FDISK_ASKTYPE_{NUMBER,OFFSET} */ |
7845ca8d KZ |
331 | struct ask_number { |
332 | uint64_t hig; /* high limit */ | |
333 | uint64_t low; /* low limit */ | |
334 | uint64_t dfl; /* default */ | |
335 | uint64_t result; | |
4114da08 KZ |
336 | uint64_t base; /* for relative results */ |
337 | uint64_t unit; /* unit for offsets */ | |
5673f30d | 338 | const char *range; /* by library generated list */ |
181aab40 | 339 | unsigned int relative :1, |
757cefbb AG |
340 | inchars :1, |
341 | wrap_negative :1; | |
7845ca8d | 342 | } num; |
ab6ea0e8 KZ |
343 | /* FDISK_ASKTYPE_{WARN,WARNX,..} */ |
344 | struct ask_print { | |
345 | const char *mesg; | |
ab6ea0e8 KZ |
346 | int errnum; /* errno */ |
347 | } print; | |
ccf48af5 KZ |
348 | /* FDISK_ASKTYPE_YESNO */ |
349 | struct ask_yesno { | |
350 | int result; /* TRUE or FALSE */ | |
351 | } yesno; | |
34b06299 KZ |
352 | /* FDISK_ASKTYPE_STRING */ |
353 | struct ask_string { | |
354 | char *result; /* allocated */ | |
355 | } str; | |
20f878fe KZ |
356 | /* FDISK_ASKTYPE_MENU */ |
357 | struct ask_menu { | |
9e930041 | 358 | int dfl; /* default menu item */ |
20f878fe KZ |
359 | int result; |
360 | struct ask_menuitem *first; | |
361 | } menu; | |
7845ca8d KZ |
362 | } data; |
363 | }; | |
364 | ||
a8019843 KZ |
365 | struct fdisk_context { |
366 | int dev_fd; /* device descriptor */ | |
367 | char *dev_path; /* device path */ | |
745801e4 | 368 | char *dev_model; /* on linux /sys/block/<name>/device/model or NULL */ |
7526c305 KZ |
369 | struct stat dev_st; /* stat(2) result */ |
370 | ||
c7119037 | 371 | int refcount; |
7c2cfb18 | 372 | |
a8019843 | 373 | unsigned char *firstsector; /* buffer with master boot record */ |
7c2cfb18 | 374 | unsigned long firstsector_bufsz; |
a8019843 | 375 | |
7526c305 | 376 | |
a8019843 KZ |
377 | /* topology */ |
378 | unsigned long io_size; /* I/O size used by fdisk */ | |
379 | unsigned long optimal_io_size; /* optional I/O returned by device */ | |
380 | unsigned long min_io_size; /* minimal I/O size */ | |
381 | unsigned long phy_sector_size; /* physical size */ | |
382 | unsigned long sector_size; /* logical size */ | |
383 | unsigned long alignment_offset; | |
384 | ||
e146ae4e KZ |
385 | unsigned int readonly : 1, /* don't write to the device */ |
386 | display_in_cyl_units : 1, /* for obscure labels */ | |
c10937dc | 387 | display_details : 1, /* expert display mode */ |
9e930041 | 388 | protect_bootbits : 1, /* don't zeroize first sector */ |
0cec78a3 | 389 | pt_collision : 1, /* another PT detected by libblkid */ |
992f7cba | 390 | no_disalogs : 1, /* disable dialog-driven partititoning */ |
745801e4 | 391 | dev_model_probed : 1, /* tried to read from sys */ |
7571ec08 | 392 | private_fd : 1, /* open by libfdisk */ |
c10937dc | 393 | listonly : 1; /* list partition, nothing else */ |
cb7ce873 | 394 | |
6cbb7371 | 395 | char *collision; /* name of already existing FS/PT */ |
131e38a2 | 396 | struct list_head wipes; /* list of areas to wipe before write */ |
6cbb7371 | 397 | |
354f8cc8 KZ |
398 | int sizeunit; /* SIZE fields, FDISK_SIZEUNIT_* */ |
399 | ||
a8019843 KZ |
400 | /* alignment */ |
401 | unsigned long grain; /* alignment unit */ | |
0073a4cf | 402 | fdisk_sector_t first_lba; /* recommended begin of the first partition */ |
9e930041 | 403 | fdisk_sector_t last_lba; /* recommended end of last partition */ |
a8019843 KZ |
404 | |
405 | /* geometry */ | |
0073a4cf | 406 | fdisk_sector_t total_sectors; /* in logical sectors */ |
a8019843 KZ |
407 | struct fdisk_geometry geom; |
408 | ||
1653f0b0 KZ |
409 | /* user setting to overwrite device default */ |
410 | struct fdisk_geometry user_geom; | |
411 | unsigned long user_pyh_sector; | |
412 | unsigned long user_log_sector; | |
adf09b5c | 413 | unsigned long user_grain; |
1653f0b0 | 414 | |
0c5d095e | 415 | struct fdisk_label *label; /* current label, pointer to labels[] */ |
a8019843 | 416 | |
0c5d095e KZ |
417 | size_t nlabels; /* number of initialized label drivers */ |
418 | struct fdisk_label *labels[8]; /* all supported labels, | |
419 | * FIXME: use any enum rather than hardcoded number */ | |
a8019843 | 420 | |
7845ca8d KZ |
421 | int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *); /* fdisk dialogs callback */ |
422 | void *ask_data; /* ask_cb() data */ | |
01b20713 KZ |
423 | |
424 | struct fdisk_context *parent; /* for nested PT */ | |
9138d6f9 | 425 | struct fdisk_script *script; /* what we want to follow */ |
7845ca8d | 426 | }; |
58d62d2f | 427 | |
1dd63a3b KZ |
428 | /* table */ |
429 | enum { | |
430 | FDISK_DIFF_UNCHANGED = 0, | |
431 | FDISK_DIFF_REMOVED, | |
432 | FDISK_DIFF_ADDED, | |
433 | FDISK_DIFF_MOVED, | |
434 | FDISK_DIFF_RESIZED | |
435 | }; | |
436 | extern int fdisk_diff_tables(struct fdisk_table *a, struct fdisk_table *b, | |
437 | struct fdisk_iter *itr, | |
438 | struct fdisk_partition **res, int *change); | |
264ef987 KZ |
439 | extern void fdisk_debug_print_table(struct fdisk_table *tb); |
440 | ||
7526c305 | 441 | |
53b422ab | 442 | /* context.c */ |
6a632136 | 443 | extern int __fdisk_switch_label(struct fdisk_context *cxt, |
53b422ab | 444 | struct fdisk_label *lb); |
72d2965c | 445 | extern int fdisk_missing_geometry(struct fdisk_context *cxt); |
a8019843 | 446 | |
9475cc78 | 447 | /* alignment.c */ |
0073a4cf KZ |
448 | fdisk_sector_t fdisk_scround(struct fdisk_context *cxt, fdisk_sector_t num); |
449 | fdisk_sector_t fdisk_cround(struct fdisk_context *cxt, fdisk_sector_t num); | |
aa42788d KZ |
450 | |
451 | extern int fdisk_discover_geometry(struct fdisk_context *cxt); | |
452 | extern int fdisk_discover_topology(struct fdisk_context *cxt); | |
453 | ||
502dd53c | 454 | extern int fdisk_has_user_device_geometry(struct fdisk_context *cxt); |
1653f0b0 | 455 | extern int fdisk_apply_user_device_properties(struct fdisk_context *cxt); |
b2140d2f | 456 | extern int fdisk_apply_label_device_properties(struct fdisk_context *cxt); |
1653f0b0 KZ |
457 | extern void fdisk_zeroize_device_properties(struct fdisk_context *cxt); |
458 | ||
3eb78aa7 | 459 | /* utils.c */ |
3457d90e KZ |
460 | extern int fdisk_init_firstsector_buffer(struct fdisk_context *cxt, |
461 | unsigned int protect_off, unsigned int protect_size); | |
3eb78aa7 KZ |
462 | extern int fdisk_read_firstsector(struct fdisk_context *cxt); |
463 | ||
7ce10975 KZ |
464 | /* label.c */ |
465 | extern int fdisk_probe_labels(struct fdisk_context *cxt); | |
0559e742 | 466 | extern void fdisk_deinit_label(struct fdisk_label *lb); |
62d50bbe | 467 | |
5989556a | 468 | struct fdisk_labelitem { |
40c9c3a6 | 469 | int refcount; /* reference counter */ |
5989556a KZ |
470 | int id; /* <label>_ITEM_* */ |
471 | char type; /* s = string, j = uint64 */ | |
40c9c3a6 | 472 | const char *name; /* human readable name */ |
5989556a KZ |
473 | |
474 | union { | |
475 | char *str; | |
476 | uint64_t num64; | |
477 | } data; | |
478 | }; | |
479 | ||
a50c8490 KZ |
480 | /* Use only internally for non-allocated items, never use |
481 | * refcouting for such items! | |
482 | */ | |
483 | #define FDISK_LABELITEM_INIT { .type = 0, .refcount = 0 } | |
5989556a | 484 | |
7845ca8d | 485 | /* ask.c */ |
1c01e44f KZ |
486 | struct fdisk_ask *fdisk_new_ask(void); |
487 | void fdisk_reset_ask(struct fdisk_ask *ask); | |
488 | int fdisk_ask_set_query(struct fdisk_ask *ask, const char *str); | |
489 | int fdisk_ask_set_type(struct fdisk_ask *ask, int type); | |
490 | int fdisk_do_ask(struct fdisk_context *cxt, struct fdisk_ask *ask); | |
491 | int fdisk_ask_number_set_range(struct fdisk_ask *ask, const char *range); | |
492 | int fdisk_ask_number_set_default(struct fdisk_ask *ask, uint64_t dflt); | |
493 | int fdisk_ask_number_set_low(struct fdisk_ask *ask, uint64_t low); | |
494 | int fdisk_ask_number_set_high(struct fdisk_ask *ask, uint64_t high); | |
495 | int fdisk_ask_number_set_base(struct fdisk_ask *ask, uint64_t base); | |
496 | int fdisk_ask_number_set_unit(struct fdisk_ask *ask, uint64_t unit); | |
497 | int fdisk_ask_number_is_relative(struct fdisk_ask *ask); | |
757cefbb | 498 | int fdisk_ask_number_set_wrap_negative(struct fdisk_ask *ask, int wrap_negative); |
1c01e44f KZ |
499 | int fdisk_ask_menu_set_default(struct fdisk_ask *ask, int dfl); |
500 | int fdisk_ask_menu_add_item(struct fdisk_ask *ask, int key, | |
501 | const char *name, const char *desc); | |
502 | int fdisk_ask_print_set_errno(struct fdisk_ask *ask, int errnum); | |
503 | int fdisk_ask_print_set_mesg(struct fdisk_ask *ask, const char *mesg); | |
504 | int fdisk_info_new_partition( | |
b4bfbadd | 505 | struct fdisk_context *cxt, |
0073a4cf | 506 | int num, fdisk_sector_t start, fdisk_sector_t stop, |
b4bfbadd KZ |
507 | struct fdisk_parttype *t); |
508 | ||
b7d101a2 KZ |
509 | /* dos.c */ |
510 | extern struct dos_partition *fdisk_dos_get_partition( | |
511 | struct fdisk_context *cxt, | |
512 | size_t i); | |
513 | ||
131e38a2 KZ |
514 | /* wipe.c */ |
515 | void fdisk_free_wipe_areas(struct fdisk_context *cxt); | |
516 | int fdisk_set_wipe_area(struct fdisk_context *cxt, uint64_t start, uint64_t size, int enable); | |
517 | int fdisk_do_wipe(struct fdisk_context *cxt); | |
518 | int fdisk_has_wipe_area(struct fdisk_context *cxt, uint64_t start, uint64_t size); | |
37204dc6 | 519 | int fdisk_check_collisions(struct fdisk_context *cxt); |
131e38a2 | 520 | |
d56a7c23 | 521 | #endif /* _LIBFDISK_PRIVATE_H */ |