Top |
int | fdisk_set_script () |
struct fdisk_script * | fdisk_get_script () |
int | fdisk_apply_script () |
int | fdisk_apply_script_headers () |
struct fdisk_script * | fdisk_new_script () |
struct fdisk_script * | fdisk_new_script_from_file () |
void | fdisk_ref_script () |
int | fdisk_script_enable_json () |
const char * | fdisk_script_get_header () |
int | fdisk_script_get_nlines () |
struct fdisk_table * | fdisk_script_get_table () |
int | fdisk_script_read_context () |
int | fdisk_script_read_file () |
int | fdisk_script_read_line () |
int | fdisk_script_set_header () |
int | fdisk_script_set_fgets () |
int | fdisk_script_write_file () |
int | fdisk_script_set_userdata () |
void * | fdisk_script_get_userdata () |
void | fdisk_unref_script () |
The libfdisk scripts are based on original sfdisk script (dumps). Each script has two parts: script headers and partition table entries (partitions).
For more details about script format see sfdisk man page.
int fdisk_set_script (struct fdisk_context *cxt
,struct fdisk_script *dp
);
Sets reference to the dp
script. The script headers might be used by label
drivers to overwrite built-in defaults (for example disk label Id) and label
driver might optimize the default semantic to be more usable for scripts
(for example to not ask for primary/logical/extended partition type).
Note that script also contains reference to the fdisk context (see
fdisk_new_script()
). This context may be completely independent on
context used for fdisk_set_script()
.
int fdisk_apply_script (struct fdisk_context *cxt
,struct fdisk_script *dp
);
This function creates a new disklabel and partition within context cxt
. You
have to call fdisk_write_disklabel()
to apply changes to the device.
int fdisk_apply_script_headers (struct fdisk_context *cxt
,struct fdisk_script *dp
);
Associte context cxt
with script dp
and creates a new empty disklabel.
struct fdisk_script *
fdisk_new_script (struct fdisk_context *cxt
);
The script hold fdisk_table and additional information to read/write script to the file.
struct fdisk_script * fdisk_new_script_from_file (struct fdisk_context *cxt
,const char *filename
);
Allocates a new script and reads script from filename
.
int fdisk_script_enable_json (struct fdisk_script *dp
,int json
);
Disable/Enable JSON output format.
const char * fdisk_script_get_header (struct fdisk_script *dp
,const char *name
);
struct fdisk_table *
fdisk_script_get_table (struct fdisk_script *dp
);
The table (container with partitions) is possible to create by
fdisk_script_read_context()
or fdisk_script_read_file()
, otherwise
this function returns NULL.
int fdisk_script_read_context (struct fdisk_script *dp
,struct fdisk_context *cxt
);
Reads data from the cxt
context (on disk partition table) into the script.
If the context is no specified than defaults to context used for fdisk_new_script()
.
Return: 0 on success, <0 on error.
int fdisk_script_read_file (struct fdisk_script *dp
,FILE *f
);
Reads file f
into script dp
.
int fdisk_script_read_line (struct fdisk_script *dp
,FILE *f
,char *buf
,size_t bufsz
);
Reads next line into dump.
int fdisk_script_set_header (struct fdisk_script *dp
,const char *name
,const char *data
);
The headers are used as global options for whole partition table, always one header per line.
If no data
is specified then the header is removed. If header does not exist
and data
is specified then a new header is added.
Note that libfdisk allows to specify arbitrary custom header, the default build-in headers are "unit" and "label", and some label specific headers (for example "uuid" and "name" for GPT).
int fdisk_script_set_fgets (struct fdisk_script *dp
,char* (*fn_fgets) (struct fdisk_script *, char *, size_t, FILE *)
);
The library uses fgets()
function to read the next line from the script.
This default maybe overrided to another function. Note that the function has
to return the line terminated by \n (for example readline(3) removes \n).
Return: 0 on success, <0 on error
int fdisk_script_write_file (struct fdisk_script *dp
,FILE *f
);
Writes script dp
to the ile f
.
int fdisk_script_set_userdata (struct fdisk_script *dp
,void *data
);
Sets data usable for example in callbacks (e.g fdisk_script_set_fgets()
).