Next Previous Contents

11.1 Command Line User Interface (technical documentation)

This section is intended for whose who wants to extend the command line user interface. The interface can be easily extended in two ways: either new commands can be added or behaviour of command line can be modified (for detailed description see section General structure of command line user interface code). This section is not definitely interested for you if you plan only using command line interface of Partition Surprise.

General structure of command line user interface code

The implementation of command line user interface can be found in src/client/cmdline/interface.c. This file contains the only function int cmdline(void) which initializes used data structures and starts a loop in which it reads in a command and processes it. Library libreadline is used for reading input if available. The processing of input is simple - all the implemented commands are listed in array cmdline_implemented located in src/client/cmdline/implemented.c. The function simply scans the array and if the command is found the appropriate routine is called. The number of implemented commands is stored in constant int cmdline_numimplemented. Each of the routines can be found in a separate file named src/client/cmdline/cmdline_name.c where `name' is the name of the command. The cmdline_implemented array is an array of the following data structure:


struct cmdline_commands {
  char *cc_name;
  int (*cc_command)(char *,struct resources *,struct final *,ERR_PARAM);
  char *cc_description;
  };                                                            

The member item cc_name contains the name of the command (e.g. `start'). The member item cc_command is the routine to be called if the command is read from the user. This routine has four parameters - the first one is the command of the user, the second one is struct resources describing resources of the computer returned by a call of get_resources(), the third one is struct final which is passed to commit() during the partition modification process and the last one is a pseudoparameter of error system. The last member item cc_description contains simple info about the command (e.g. `start - restarts Partition Surprise').

The function cmdline() maintains two main global structures - one is of type struct resources and the other of type struct final. Both these structures are passed and can be modified and routines for performing user commands. Routine for `start' command simply discards both these structures, calls get_resources() to obatin an original struct resources and fills in appropriately (with defaults) struct final. Routine for `move' command will only modify struct final to reflect the move of a partition requested by a user.

The routine function usually takes use of some special macros or special functions for parsing input and modifiing the structures struct resources and struct final; their description can be found in Section Special purpose functions of command line user interface code. The routine function can returned one of the following three values: CMDL_OKAY if the command was succesfully processed, CMDL_QUIT if the command line user interface should be quited after the command or CMDL_ERROR if a fatal error occured. Note that if only there are only non-fatal errors returned by calling surprise library CMDL_OKAY should be returned. The value CMDL_ERROR should be returned only in cases such as low memory. After the routine is performed all the errors returned by the routine are shown to the user.

Progress indicator and aborting the conversion

There are two special functions to perform progress indicating and conversion abort during the conversion (when commit() is called in modification mode). These functions are:

int cmdline_progress(float progress,ERR_PARAM)

This function is called during conversion to update the progress bar to the user. If the flag cmdline_gotabort it returns an appropriate value to notify the converter (part of Surprise Library) to abort the conversion if possible (i.e. not dangerous).

void cmdline_sigabort(int signo)

This function si called during conversion if SIGINT received. The only purpose of this function is to set flag cmdline_gotabort.

Implemented commands

The list of routines implementing the commands follows. Each of the routine is located in a separate file src/client/cmdline/name.c where `name' is the name of the routine.

int cmdline_start(char *,struct resources *,struct final *,ERR_PARAM)

This routine initializes data structures by calling function get_resources.

int cmdline_quit(char *,struct resources *,struct final *,ERR_PARAM)

This routine causes the interface to quit.

int cmdline_version(char *,struct resources *,char ***,struct final *,ERR_PARAM)

This routine prints out the version of the Surprise library.

int cmdline_help(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out basic help containg information about implemented commands.

int cmdline_adddevice(char *,struct resources *,char ***,struct final *,ERR_PARAM)

This routine add a new device to the list of probed devices; the routine does not call get_resources(), the routine only add the device to the list.

int cmdline_listdevice(char *,struct resources *,char ***,struct final *,ERR_PARAM)

This routine prints the list of probed devices.

int cmdline_rmdevice(char *,struct resources *,char ***,struct final *,ERR_PARAM)

This routine removes a device from the list of probed devices.

int cmdline_info(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out basic information about disk or partition.

int cmdline_free(char *,struct resources *,struct final *,ERR_PARAM)

This routine summarizes available space on disk.

int cmdline_state(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out the state - e.g. the information about the original and the planned partitioning of the disk.

int cmdline_verify(char *,struct resources *,struct final *,ERR_PARAM)

This routine calls commit() in check-only mode.

int cmdline_confirm(char *,struct resources *,struct final *,ERR_PARAM)

This routine calls commit() in modification mode.

int cmdline_new(char *,struct resources *,struct final *,ERR_PARAM)

This routine creates a new partition.

int cmdline_del(char *,struct resources *,struct final *,ERR_PARAM)

This routine deletes a partition.

int cmdline_mkfs(char *,struct resources *,struct final *,ERR_PARAM)

This routine creates an empty filesystem on a specified partition.

int cmdline_convert(char *,struct resources *,struct final *,ERR_PARAM)

This routine converts (changes) the filesystem on a specified partition.

int cmdline_renumber(char *,struct resources *,char ***,struct final *,ERR_PARAM)

This routine changes the name (i.e. the order) of a specified partition.

int cmdline_move(char *,struct resources *,struct final *,ERR_PARAM)

This routine moves a specified partition.

int cmdline_copy(char *,struct resources *,struct final *,ERR_PARAM)

This routine makes a copy of a specified partition.

int cmdline_resize(char *,struct resources *,struct final *,ERR_PARAM)

This routine changes the size (shrinks or enlarge) a specified partition.

int cmdline_detected(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out the parameters of the filesystem detected by Surprise Library and allows to change them.

int cmdline_gparam(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out and modifies the global conversion parameters.

int cmdline_param(char *,struct resources *,struct final *,ERR_PARAM)

This routine prints out and modifies parameters of created filesystems.

Special purpose functions of command line user interface code

There are generally three kinds of special purpose functions: ones for parsing input, the others for printing out output and the last ones for modifiing data structures struct resources and struct final. All of these functions are desribed in this section.

Functions and macros for parsing input

macro CMD_DECL

This macro declares local variables used for parsing input.

macro CMD_ANALYZE

This macro calls function cmd_analyze to analyze the input line.

macro CMD_OPTION(p,s)

This macro sets int variable p to one if the option s is present.

macro CMD_INVALID_OPTION

This macro adds an error if there is an option not processed by CMD_OPTION.

macro CMD_RETURN_FREE

This macro frees memory used for storing the input line if library libreadline used.

macro CMD_RETURN(x)

This macro uses CMD_RETURN_FREE and quits the routine with a value of x returned.

const char *DELIM

This string contains all the characters to be considered as white characters.

void cmd_analyze(char *line,int *optnum,char ***options,int *parnum,char ***parameters,ERR_PARAM)

This functions parses input line pointed by line. The number of options is stored in optnum and the optiones theirselves in the array options. The number of parameters is stored in parnum and the parameters theirselves in the array parameters.

int cmd_blocknum(char *c,block_t *b,ERR_PARAM)

This functions reads in number pointed by c and stores in memory location pointed by b. The function support suffixes k, M and G.

int cmd_finddisk(int count,struct disk_info *r,char **c1,char *c2,ERR_PARAM)

This function search array r containing count structures for a disk named *c1. If search is unsuccessful parameter c2 is used in an error message.

int cmd_findpart(int count,struct user_partition *r,char **c1,char *c2,ERR_PARAM)

This function search array r containing count structures for a partition with number *c1. If search is unsuccessful parameter c2 is used in an error message.

Functions and macros for printing output

macro cmd_printout(Fmt...)

This macro prints out the string specified by Fmt.

void cmd_printdir(struct resources *,struct user_directory *,ERR_PARAM)

This function prints out information about the partition on which data pointed by struct user_directory * are planned to be stored. The strcuture struct resources * is used to obtain information about original location of datas.

void cmd_printpar(struct user_parameter *,int,ERR_PARAM)

This function prints out the parameter pointed by its first argument.

char *cmd_fsname(struct resources *r,enum fs_types type,ERR_PARAM)

This function returns the name of filesystem type; the information about supported filesystems are stored in struct resources *r.

Functions for modification of data structures and other functions

void cmd_sortpar(int num,struct user_partition *par)

This function sorts the partitions in array par (the number of partitions is num) accroding to their numbers (up_num).

int cmd_changepar(int num,struct user_parameter *par,char *which,char *value,int imp,ERR_PARAM)

This function sets the parameter which in array par of containing num parameters to value. The flag imp is set if the partition is considered as imported and unset otherwise.

void cmd_invalidate(int num,struct disk_info *p)

This function invalidates partition entries in struct disk_info *p supposing that partition numbered num was modified.

void cmd_filter_imp(int *,struct user_parameter **,ERR_PARAM)

This function removes all the parameters with unset `import flag'.

void cmd_filter_exp(int *,struct user_parameter **,ERR_PARAM)

This function removes all the parameters with unset `export flag'.

int cmd_defpars(struct resources *,struct user_partition *,ERR_PARAM)

This function fills struct user_partition with defaults proposed by struct resources.


Next Previous Contents