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