Script

Script — text based sfdisk compatible description of partition table

Functions

Types and Values

struct fdisk_script

Description

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.

Functions

fdisk_set_script ()

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().

Parameters

cxt

context

 

dp

script (or NULL to remove previous reference)

 

Returns

<0 on error, 0 on success.


fdisk_get_script ()

struct fdisk_script *
fdisk_get_script (struct fdisk_context *cxt);

Parameters

cxt

context

 

Returns

the current script or NULL.


fdisk_apply_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.

Parameters

cxt

context

 

dp

script

 

Returns

0 on error, <0 on error.


fdisk_apply_script_headers ()

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.

Parameters

cxt

context

 

dp

script

 

Returns

0 on success, <0 on error.


fdisk_new_script ()

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.

Parameters

cxt

context

 

Returns

newly allocated script struct.


fdisk_new_script_from_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 .

Parameters

cxt

context

 

filename

path to the script file

 

Returns

new script instance or NULL in case of error (check errno for more details).


fdisk_ref_script ()

void
fdisk_ref_script (struct fdisk_script *dp);

Incremparts reference counter.

Parameters

dp

script pointer

 

fdisk_script_get_header ()

const char *
fdisk_script_get_header (struct fdisk_script *dp,
                         const char *name);

Parameters

dp

script instance

 

name

header name

 

Returns

pointer to header data or NULL.


fdisk_script_get_nlines ()

int
fdisk_script_get_nlines (struct fdisk_script *dp);

Parameters

dp

script

 

Returns

number of parsed lines or <0 on error.


fdisk_script_get_table ()

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.

Parameters

dp

script

 

Returns

NULL or script.


fdisk_script_read_context ()

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.

Parameters

dp

script

 

cxt

context

 

fdisk_script_read_file ()

int
fdisk_script_read_file (struct fdisk_script *dp,
                        FILE *f);

Reads file f into script dp .

Parameters

dp

script

 

f

input file

 

Returns

0 on success, <0 on error.


fdisk_script_read_line ()

int
fdisk_script_read_line (struct fdisk_script *dp,
                        FILE *f,
                        char *buf,
                        size_t bufsz);

Reads next line into dump.

Parameters

dp

script

 

f

file

 

buf

buffer to store one line of the file

 

bufsz

buffer size

 

Returns

0 on success, <0 on error, 1 when nothing to read.


fdisk_script_set_header ()

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).

Parameters

dp

script instance

 

name

header name

 

data

header data (or NULL)

 

Returns

0 on success, <0 on error


fdisk_script_write_file ()

int
fdisk_script_write_file (struct fdisk_script *dp,
                         FILE *f);

Writes script dp to the ile f .

Parameters

dp

script

 

f

output file

 

Returns

0 on success, <0 on error.


fdisk_unref_script ()

void
fdisk_unref_script (struct fdisk_script *dp);

De-incremparts reference counter, on zero the dp is automatically deallocated.

Parameters

dp

script pointer

 

Types and Values

struct fdisk_script

struct fdisk_script;

library handler for sfdisk compatible scripts