2001-09-25 16:49:28 +04:00
/*
2002-02-11 23:50:53 +03:00
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
2001-09-25 16:49:28 +04:00
*
2002-02-11 23:50:53 +03:00
* This file is released under the LGPL .
2001-09-25 16:49:28 +04:00
*/
2001-10-09 21:20:02 +04:00
# ifndef _LVM_LVM_H
# define _LVM_LVM_H
2001-09-25 16:49:28 +04:00
2001-10-08 22:44:22 +04:00
# include "pool.h"
# include "dbg_malloc.h"
# include "list.h"
# include "log.h"
2001-12-31 22:09:51 +03:00
# include "lvm-string.h"
2002-02-11 18:42:34 +03:00
# include "lvm-file.h"
2001-10-01 19:14:39 +04:00
# include "metadata.h"
# include "config.h"
# include "dev-cache.h"
# include "device.h"
2001-12-31 22:18:44 +03:00
# include "vgcache.h"
2001-10-01 19:14:39 +04:00
# include "display.h"
2001-09-25 16:49:28 +04:00
# include "errors.h"
2001-10-01 23:36:06 +04:00
# include "filter.h"
2001-10-23 22:20:27 +04:00
# include "filter-persistent.h"
2001-10-23 15:50:49 +04:00
# include "filter-composite.h"
# include "filter-regex.h"
2001-10-08 22:44:22 +04:00
# include "format1.h"
2001-12-31 22:09:51 +03:00
# include "format-text.h"
2001-09-25 16:49:28 +04:00
# include "toollib.h"
2001-10-16 20:25:28 +04:00
# include "activate.h"
2002-01-07 14:12:11 +03:00
# include "archive.h"
2002-02-11 18:42:34 +03:00
# include "locking.h"
2002-02-11 23:50:53 +03:00
# include "toolcontext.h"
2002-01-07 14:12:11 +03:00
# include <stdio.h>
# include <stdarg.h>
# include <stdlib.h>
# include <unistd.h>
# include <sys/types.h>
# include <ctype.h>
# include <string.h>
# include <limits.h>
2001-09-25 16:49:28 +04:00
# define CMD_LEN 256
# define MAX_ARGS 64
/* command functions */
2002-02-12 00:00:35 +03:00
typedef int ( * command_fn ) ( struct cmd_context * cmd , int argc , char * * argv ) ;
2001-09-25 16:49:28 +04:00
2002-02-11 23:50:53 +03:00
# define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
2001-09-25 16:49:28 +04:00
# include "commands.h"
# undef xx
/* define the enums for the command line switches */
enum {
2001-12-17 19:58:17 +03:00
# define arg(a, b, c, d) a ,
2001-09-25 16:49:28 +04:00
# include "args.h"
2001-12-17 19:58:17 +03:00
# undef arg
2001-09-25 16:49:28 +04:00
} ;
2001-11-10 01:01:04 +03:00
typedef enum {
SIGN_NONE = 0 ,
SIGN_PLUS = 1 ,
SIGN_MINUS = 2
} sign_t ;
2001-12-17 19:58:17 +03:00
2001-09-25 16:49:28 +04:00
/* a global table of possible arguments */
struct arg {
char short_arg ;
char * long_arg ;
2002-02-12 00:00:35 +03:00
int ( * fn ) ( struct arg * a ) ;
2002-01-10 19:47:04 +03:00
2001-09-25 16:49:28 +04:00
int count ;
char * value ;
2001-11-10 01:01:04 +03:00
uint32_t i_value ;
2002-02-15 17:33:59 +03:00
uint64_t i64_value ;
2001-11-10 01:01:04 +03:00
sign_t sign ;
2001-09-25 16:49:28 +04:00
} ;
2001-11-13 17:17:50 +03:00
/* a register of the lvm commands */
struct command {
2002-02-12 00:00:35 +03:00
const char * name ;
const char * desc ;
const char * usage ;
command_fn fn ;
2001-11-13 17:17:50 +03:00
2002-02-12 00:00:35 +03:00
int num_args ;
int * valid_args ;
2001-11-13 17:17:50 +03:00
} ;
2001-09-25 16:49:28 +04:00
void usage ( const char * name ) ;
/* the argument verify/normalise functions */
int yes_no_arg ( struct arg * a ) ;
int size_arg ( struct arg * a ) ;
int int_arg ( struct arg * a ) ;
2001-11-10 01:01:04 +03:00
int int_arg_with_sign ( struct arg * a ) ;
2002-02-01 20:54:39 +03:00
int minor_arg ( struct arg * a ) ;
2001-09-25 16:49:28 +04:00
int string_arg ( struct arg * a ) ;
int permission_arg ( struct arg * a ) ;
2001-10-12 14:32:06 +04:00
char yes_no_prompt ( const char * prompt , . . . ) ;
2001-09-25 16:49:28 +04:00
/* we use the enums to access the switches */
2002-02-12 00:00:35 +03:00
static inline int arg_count ( struct cmd_context * cmd , int a )
{
2002-02-11 23:50:53 +03:00
return cmd - > args [ a ] . count ;
2001-09-25 16:49:28 +04:00
}
2002-02-12 00:00:35 +03:00
static inline char * arg_value ( struct cmd_context * cmd , int a )
{
2002-02-11 23:50:53 +03:00
return cmd - > args [ a ] . value ;
2001-09-25 16:49:28 +04:00
}
2002-02-11 23:50:53 +03:00
static inline char * arg_str_value ( struct cmd_context * cmd , int a , char * def )
2001-09-25 16:49:28 +04:00
{
2002-02-11 23:50:53 +03:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . value : def ;
2001-09-25 16:49:28 +04:00
}
2002-02-12 00:00:35 +03:00
static inline uint32_t arg_int_value ( struct cmd_context * cmd , int a ,
uint32_t def )
2001-09-25 16:49:28 +04:00
{
2002-02-11 23:50:53 +03:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . i_value : def ;
2001-09-25 16:49:28 +04:00
}
2002-02-15 17:33:59 +03:00
static inline uint64_t arg_int64_value ( struct cmd_context * cmd , int a ,
uint64_t def )
{
return arg_count ( cmd , a ) ? cmd - > args [ a ] . i64_value : def ;
}
2002-02-11 23:50:53 +03:00
static inline sign_t arg_sign_value ( struct cmd_context * cmd , int a , sign_t def )
2001-11-10 01:01:04 +03:00
{
2002-02-11 23:50:53 +03:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . sign : def ;
2001-11-10 01:01:04 +03:00
}
2002-02-11 23:50:53 +03:00
static inline int arg_count_increment ( struct cmd_context * cmd , int a )
2001-09-25 16:49:28 +04:00
{
2002-02-11 23:50:53 +03:00
return cmd - > args [ a ] . count + + ;
2001-09-25 16:49:28 +04:00
}
2002-02-11 23:50:53 +03:00
static inline const char * command_name ( struct cmd_context * cmd )
2001-11-13 17:17:50 +03:00
{
2002-02-11 23:50:53 +03:00
return cmd - > command - > name ;
2001-11-13 17:17:50 +03:00
}
2001-10-08 22:44:22 +04:00
2001-10-06 01:39:30 +04:00
# endif