2001-09-25 12:49:28 +00:00
/*
2004-03-30 19:35:44 +00:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
2001-09-25 12:49:28 +00:00
*
2004-03-30 19:35:44 +00:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-09-25 12:49:28 +00:00
*/
2002-04-24 18:20:51 +00:00
# ifndef _LVM_TOOLS_H
# define _LVM_TOOLS_H
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
# define _GNU_SOURCE
2002-12-19 23:25:55 +00:00
# include <assert.h>
# include "log.h"
2002-11-18 14:04:08 +00:00
# include "activate.h"
2004-03-26 12:25:15 +00:00
# include "archiver.h"
2003-07-04 22:34:56 +00:00
# include "lvmcache.h"
2001-10-01 15:14:39 +00:00
# include "config.h"
2002-12-19 23:25:55 +00:00
# include "defaults.h"
2002-11-18 14:04:08 +00:00
# include "dbg_malloc.h"
2001-10-01 15:14:39 +00:00
# include "dev-cache.h"
# include "device.h"
# include "display.h"
2001-09-25 12:49:28 +00:00
# include "errors.h"
2001-10-01 19:36:06 +00:00
# include "filter.h"
2001-10-23 11:50:49 +00:00
# include "filter-composite.h"
2002-11-18 14:04:08 +00:00
# include "filter-persistent.h"
2001-10-23 11:50:49 +00:00
# include "filter-regex.h"
2001-12-31 19:09:51 +00:00
# include "format-text.h"
2002-11-18 14:04:08 +00:00
# include "metadata.h"
# include "list.h"
2002-02-11 15:42:34 +00:00
# include "locking.h"
2002-11-18 14:04:08 +00:00
# include "lvm-file.h"
# include "lvm-string.h"
# include "pool.h"
2004-03-08 17:19:15 +00:00
# include "str_list.h"
2002-02-11 20:50:53 +00:00
# include "toolcontext.h"
2002-11-18 14:04:08 +00:00
# include "toollib.h"
2002-01-07 11:12:11 +00:00
2002-12-19 23:25:55 +00:00
# include <stdlib.h>
# include <unistd.h>
2002-11-18 14:04:08 +00:00
# include <ctype.h>
# include <limits.h>
2002-01-07 11:12:11 +00:00
# include <stdarg.h>
# include <sys/types.h>
2001-09-25 12:49:28 +00:00
# define CMD_LEN 256
# define MAX_ARGS 64
/* command functions */
2002-02-11 21:00:35 +00:00
typedef int ( * command_fn ) ( struct cmd_context * cmd , int argc , char * * argv ) ;
2001-09-25 12:49:28 +00:00
2002-02-11 20:50:53 +00:00
# define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
2001-09-25 12:49:28 +00:00
# include "commands.h"
# undef xx
/* define the enums for the command line switches */
enum {
2001-12-17 16:58:17 +00:00
# define arg(a, b, c, d) a ,
2001-09-25 12:49:28 +00:00
# include "args.h"
2001-12-17 16:58:17 +00:00
# undef arg
2001-09-25 12:49:28 +00:00
} ;
2001-11-09 22:01:04 +00:00
typedef enum {
SIGN_NONE = 0 ,
SIGN_PLUS = 1 ,
SIGN_MINUS = 2
} sign_t ;
2001-12-17 16:58:17 +00:00
2001-09-25 12:49:28 +00:00
/* a global table of possible arguments */
struct arg {
2002-12-19 23:25:55 +00:00
const char short_arg ;
const char * long_arg ;
2002-11-18 14:04:08 +00:00
int ( * fn ) ( struct cmd_context * cmd , struct arg * a ) ;
2002-01-10 16:47:04 +00:00
2003-07-04 22:34:56 +00:00
unsigned int count ;
2001-09-25 12:49:28 +00:00
char * value ;
2002-12-19 23:25:55 +00:00
int32_t i_value ;
uint32_t ui_value ;
2002-12-12 20:55:49 +00:00
int64_t i64_value ;
uint64_t ui64_value ;
2001-11-09 22:01:04 +00:00
sign_t sign ;
2002-04-24 18:20:51 +00:00
void * ptr ;
2001-09-25 12:49:28 +00:00
} ;
2001-11-13 14:17:50 +00:00
/* a register of the lvm commands */
struct command {
2002-02-11 21:00:35 +00:00
const char * name ;
const char * desc ;
const char * usage ;
command_fn fn ;
2001-11-13 14:17:50 +00:00
2002-02-11 21:00:35 +00:00
int num_args ;
int * valid_args ;
2001-11-13 14:17:50 +00:00
} ;
2001-09-25 12:49:28 +00:00
void usage ( const char * name ) ;
/* the argument verify/normalise functions */
2002-11-18 14:04:08 +00:00
int yes_no_arg ( struct cmd_context * cmd , struct arg * a ) ;
2002-12-03 13:24:38 +00:00
int size_kb_arg ( struct cmd_context * cmd , struct arg * a ) ;
int size_mb_arg ( struct cmd_context * cmd , struct arg * a ) ;
2002-11-18 14:04:08 +00:00
int int_arg ( struct cmd_context * cmd , struct arg * a ) ;
int int_arg_with_sign ( struct cmd_context * cmd , struct arg * a ) ;
2003-04-02 19:14:43 +00:00
int major_arg ( struct cmd_context * cmd , struct arg * a ) ;
2002-11-18 14:04:08 +00:00
int minor_arg ( struct cmd_context * cmd , struct arg * a ) ;
int string_arg ( struct cmd_context * cmd , struct arg * a ) ;
2004-03-08 17:19:15 +00:00
int tag_arg ( struct cmd_context * cmd , struct arg * a ) ;
2002-11-18 14:04:08 +00:00
int permission_arg ( struct cmd_context * cmd , struct arg * a ) ;
int metadatatype_arg ( struct cmd_context * cmd , struct arg * a ) ;
2002-12-12 20:55:49 +00:00
int units_arg ( struct cmd_context * cmd , struct arg * a ) ;
2001-09-25 12:49:28 +00:00
2001-10-12 10:32:06 +00:00
char yes_no_prompt ( const char * prompt , . . . ) ;
2001-09-25 12:49:28 +00:00
/* we use the enums to access the switches */
2003-07-04 22:34:56 +00:00
static inline const unsigned int arg_count ( struct cmd_context * cmd , int a )
2002-02-11 21:00:35 +00:00
{
2002-02-11 20:50:53 +00:00
return cmd - > args [ a ] . count ;
2001-09-25 12:49:28 +00:00
}
2002-12-19 23:25:55 +00:00
static inline const char * arg_value ( struct cmd_context * cmd , int a )
2002-02-11 21:00:35 +00:00
{
2002-02-11 20:50:53 +00:00
return cmd - > args [ a ] . value ;
2001-09-25 12:49:28 +00:00
}
2002-12-19 23:25:55 +00:00
static inline const char * arg_str_value ( struct cmd_context * cmd , int a ,
const char * def )
2001-09-25 12:49:28 +00:00
{
2002-02-11 20:50:53 +00:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . value : def ;
2001-09-25 12:49:28 +00:00
}
2002-12-19 23:25:55 +00:00
static inline const int32_t arg_int_value ( struct cmd_context * cmd , int a ,
const int32_t def )
2001-09-25 12:49:28 +00:00
{
2002-02-11 20:50:53 +00:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . i_value : def ;
2001-09-25 12:49:28 +00:00
}
2002-12-19 23:25:55 +00:00
static inline const uint32_t arg_uint_value ( struct cmd_context * cmd , int a ,
const uint32_t def )
{
return arg_count ( cmd , a ) ? cmd - > args [ a ] . ui_value : def ;
}
static inline const int64_t arg_int64_value ( struct cmd_context * cmd , int a ,
const uint64_t def )
2002-02-15 14:33:59 +00:00
{
return arg_count ( cmd , a ) ? cmd - > args [ a ] . i64_value : def ;
}
2002-12-19 23:25:55 +00:00
static inline const uint64_t arg_uint64_value ( struct cmd_context * cmd , int a ,
const uint64_t def )
2002-12-12 20:55:49 +00:00
{
return arg_count ( cmd , a ) ? cmd - > args [ a ] . ui64_value : def ;
}
2002-12-19 23:25:55 +00:00
static inline const void * arg_ptr_value ( struct cmd_context * cmd , int a ,
const void * def )
2002-04-24 18:20:51 +00:00
{
return arg_count ( cmd , a ) ? cmd - > args [ a ] . ptr : def ;
}
2002-12-19 23:25:55 +00:00
static inline const sign_t arg_sign_value ( struct cmd_context * cmd , int a ,
const sign_t def )
2001-11-09 22:01:04 +00:00
{
2002-02-11 20:50:53 +00:00
return arg_count ( cmd , a ) ? cmd - > args [ a ] . sign : def ;
2001-11-09 22:01:04 +00:00
}
2002-12-19 23:25:55 +00:00
static inline const int arg_count_increment ( struct cmd_context * cmd , int a )
2001-09-25 12:49:28 +00:00
{
2002-02-11 20:50:53 +00:00
return cmd - > args [ a ] . count + + ;
2001-09-25 12:49:28 +00:00
}
2002-02-11 20:50:53 +00:00
static inline const char * command_name ( struct cmd_context * cmd )
2001-11-13 14:17:50 +00:00
{
2002-02-11 20:50:53 +00:00
return cmd - > command - > name ;
2001-11-13 14:17:50 +00:00
}
2001-10-08 18:44:22 +00:00
2003-05-06 12:20:11 +00:00
int pvmove_poll ( struct cmd_context * cmd , const char * pv , unsigned background ) ;
2001-10-05 21:39:30 +00:00
# endif