Welcome to NYCU CSIT Mirror site

Ask: libfdisk Reference Manual

Ask

Ask — interface for dialog driven partitioning, warning and info messages

Types and Values

struct fdisk_ask
enum fdisk_asktype

Description

Functions

fdisk_info ()

int
fdisk_info (struct fdisk_context *cxt,
            const char *fmt,
            ...);

High-level API to print warning message (errno expected)

Parameters

cxt

context

 

fmt

printf-like formatted string

 

...

variable parametrs

 

Returns

0 on success, <0 on error


fdisk_warn ()

int
fdisk_warn (struct fdisk_context *cxt,
            const char *fmt,
            ...);

fdisk_warnx ()

int
fdisk_warnx (struct fdisk_context *cxt,
             const char *fmt,
             ...);

High-level API to print warning message

Parameters

cxt

context

 

fmt

printf-like formatted string

 

...

variable options

 

Returns

0 on success, <0 on error


fdisk_set_ask ()

int
fdisk_set_ask (struct fdisk_context *cxt,
               int (*ask_cb) (struct fdisk_context *, struct fdisk_ask *, void *),
               void *data);

Set callback for dialog driven partitioning and library warnings/errors.

Parameters

cxt

context

 

ask_cb

callback

 

data

callback data

 

Returns

0 on success, < 0 on error.


fdisk_is_ask()

#define fdisk_is_ask(a, x) (fdisk_ask_get_type(a) == FDISK_ASKTYPE_ ## x)

fdisk_ask_get_query ()

const char *
fdisk_ask_get_query (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

pointer to dialog string.


fdisk_ask_get_type ()

int
fdisk_ask_get_type (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

FDISK_ASKTYPE_*


fdisk_ask_menu_get_default ()

int
fdisk_ask_menu_get_default (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

default menu item key


fdisk_ask_menu_get_item ()

int
fdisk_ask_menu_get_item (struct fdisk_ask *ask,
                         size_t idx,
                         int *key,
                         const char **name,
                         const char **desc);

Parameters

ask

ask menu instance

 

idx

wanted menu item index

 

key

returns key of the menu item

 

name

returns name of the menu item

 

desc

returns description of the menu item

 

Returns

0 on success, <0 on error, >0 if idx out-of-range


fdisk_ask_menu_get_nitems ()

size_t
fdisk_ask_menu_get_nitems (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

number of menu items


fdisk_ask_menu_get_result ()

int
fdisk_ask_menu_get_result (struct fdisk_ask *ask,
                           int *key);

Parameters

ask

ask instance

 

key

returns selected menu item key

 

Returns

0 on success, <0 on error.


fdisk_ask_menu_set_result ()

int
fdisk_ask_menu_set_result (struct fdisk_ask *ask,
                           int key);

Parameters

ask

ask instance

 

key

result

 

Returns

0 on success, <0 on error


fdisk_ask_number ()

int
fdisk_ask_number (struct fdisk_context *cxt,
                  uintmax_t low,
                  uintmax_t dflt,
                  uintmax_t high,
                  const char *query,
                  uintmax_t *result);

Parameters

cxt

context

 

low

minimal possible number

 

dflt

default suggestion

 

high

maximal possible number

 

query

question string

 

result

returns result

 

Returns

0 on success, <0 on error.


fdisk_ask_number_get_base ()

uint64_t
fdisk_ask_number_get_base (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

base when user specify number in relative notation (+size)


fdisk_ask_number_get_default ()

uint64_t
fdisk_ask_number_get_default (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

default number


fdisk_ask_number_get_high ()

uint64_t
fdisk_ask_number_get_high (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

maximal possible number when ask for numbers in range


fdisk_ask_number_get_low ()

uint64_t
fdisk_ask_number_get_low (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

minimal possible number when ask for numbers in range


fdisk_ask_number_get_range ()

const char *
fdisk_ask_number_get_range (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

string with range (e.g. "1,3,5-10")


fdisk_ask_number_get_result ()

uint64_t
fdisk_ask_number_get_result (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

result


fdisk_ask_number_get_unit ()

uint64_t
fdisk_ask_number_get_unit (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

number of bytes per the unit


fdisk_ask_number_inchars ()

int
fdisk_ask_number_inchars (struct fdisk_ask *ask);

For example for BSD is normal to address partition by chars rather than by number (first partition is 'a').

Parameters

ask

ask instance

 

Returns

1 if number should be presented as chars


fdisk_ask_number_set_relative ()

int
fdisk_ask_number_set_relative (struct fdisk_ask *ask,
                               int relative);

Inform libfdisk that user specified number in relative notation rather than by explicit number. This info allows to fdisk do some optimization (e.g. align end of partiton, etc.)

Parameters

ask

ask instance

 

relative

0 or 1

 

Returns

0 on success, <0 on error


fdisk_ask_number_set_result ()

int
fdisk_ask_number_set_result (struct fdisk_ask *ask,
                             uint64_t result);

Parameters

ask

ask instance

 

result

dialog result

 

Returns

0 on success, <0 on error


fdisk_ask_partnum ()

int
fdisk_ask_partnum (struct fdisk_context *cxt,
                   size_t *partnum,
                   int wantnew);

High-level API to ask for used or unused partition number.

Parameters

cxt

context

 

partnum

returns partition number

 

wantnew

0|1

 

Returns

0 on success, < 0 on error, 1 if no free/used partition


fdisk_ask_print_get_errno ()

int
fdisk_ask_print_get_errno (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

error number for warning/error messages


fdisk_ask_print_get_mesg ()

const char *
fdisk_ask_print_get_mesg (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

pointer to message


fdisk_ask_string ()

int
fdisk_ask_string (struct fdisk_context *cxt,
                  const char *query,
                  char **result);

High-level API to ask for strings. Don't forget to deallocate the result .

Parameters

cxt

context:

 

query

question string

 

result

returns allocated buffer

 

Returns

0 on success, <0 on error.


fdisk_ask_string_get_result ()

char *
fdisk_ask_string_get_result (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

pointer to dialog result


fdisk_ask_string_set_result ()

int
fdisk_ask_string_set_result (struct fdisk_ask *ask,
                             char *result);

You don't have to care about the result deallocation, libfdisk is going to deallocate the result when destroy ask instance.

Parameters

ask

ask instance

 

result

pointer to allocated buffer with string

 

Returns

0 on success, <0 on error


fdisk_ask_yesno ()

int
fdisk_ask_yesno (struct fdisk_context *cxt,
                 const char *query,
                 int *result);

Hight-level API to ask Yes/No questions

Parameters

cxt

context

 

query

question string

 

result

returns 0 (no) or 1 (yes)

 

Returns

0 on success, <0 on error


fdisk_ask_yesno_get_result ()

int
fdisk_ask_yesno_get_result (struct fdisk_ask *ask);

Parameters

ask

ask instance

 

Returns

0 or 1


fdisk_ask_yesno_set_result ()

int
fdisk_ask_yesno_set_result (struct fdisk_ask *ask,
                            int result);

Parameters

ask

ask instance

 

result

1 or 0

 

Returns

0 on success, <0 on error


fdisk_ref_ask ()

void
fdisk_ref_ask (struct fdisk_ask *ask);

Incremparts reference counter.

Parameters

ask

ask instance

 

fdisk_unref_ask ()

void
fdisk_unref_ask (struct fdisk_ask *ask);

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

Parameters

ask

ask instance

 

Types and Values

struct fdisk_ask

struct fdisk_ask;

Ask API handler for dialogs with users.


enum fdisk_asktype

Ask API dialog types

Members

FDISK_ASKTYPE_NONE

   

FDISK_ASKTYPE_NUMBER

   

FDISK_ASKTYPE_OFFSET

   

FDISK_ASKTYPE_WARN

   

FDISK_ASKTYPE_WARNX

   

FDISK_ASKTYPE_INFO

   

FDISK_ASKTYPE_YESNO

   

FDISK_ASKTYPE_STRING

   

FDISK_ASKTYPE_MENU