1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/tools/tools.h

179 lines
4.1 KiB
C
Raw Normal View History

2001-09-25 16:49:28 +04:00
/*
* Copyright (C) 2001 Sistina Software (UK) Limited.
2001-09-25 16:49:28 +04:00
*
* This file is released under the LGPL.
2001-09-25 16:49:28 +04:00
*/
#ifndef _LVM_TOOLS_H
#define _LVM_TOOLS_H
2001-09-25 16:49:28 +04:00
2002-11-18 17:04:08 +03:00
#define _GNU_SOURCE
#include <assert.h>
#include "log.h"
2002-11-18 17:04:08 +03:00
#include "activate.h"
#include "archive.h"
#include "lvmcache.h"
2001-10-01 19:14:39 +04:00
#include "config.h"
#include "defaults.h"
2002-11-18 17:04:08 +03:00
#include "dbg_malloc.h"
2001-10-01 19:14:39 +04:00
#include "dev-cache.h"
#include "device.h"
#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 15:50:49 +04:00
#include "filter-composite.h"
2002-11-18 17:04:08 +03:00
#include "filter-persistent.h"
2001-10-23 15:50:49 +04:00
#include "filter-regex.h"
#include "format-text.h"
2002-11-18 17:04:08 +03:00
#include "metadata.h"
#include "list.h"
#include "locking.h"
2002-11-18 17:04:08 +03:00
#include "lvm-file.h"
#include "lvm-string.h"
#include "pool.h"
#include "toolcontext.h"
2002-11-18 17:04:08 +03:00
#include "toollib.h"
2002-01-07 14:12:11 +03:00
#include <stdlib.h>
#include <unistd.h>
2002-11-18 17:04:08 +03:00
#include <ctype.h>
#include <limits.h>
2002-01-07 14:12:11 +03:00
#include <stdarg.h>
#include <sys/types.h>
2001-09-25 16:49:28 +04:00
#define CMD_LEN 256
#define MAX_ARGS 64
/* command functions */
typedef int (*command_fn) (struct cmd_context * cmd, int argc, char **argv);
2001-09-25 16:49:28 +04: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 {
#define arg(a, b, c, d) a ,
2001-09-25 16:49:28 +04:00
#include "args.h"
#undef arg
2001-09-25 16:49:28 +04:00
};
typedef enum {
SIGN_NONE = 0,
SIGN_PLUS = 1,
SIGN_MINUS = 2
} sign_t;
2001-09-25 16:49:28 +04:00
/* a global table of possible arguments */
struct arg {
const char short_arg;
const char *long_arg;
2002-11-18 17:04:08 +03:00
int (*fn) (struct cmd_context * cmd, struct arg * a);
unsigned int count;
2001-09-25 16:49:28 +04:00
char *value;
int32_t i_value;
uint32_t ui_value;
int64_t i64_value;
uint64_t ui64_value;
sign_t sign;
void *ptr;
2001-09-25 16:49:28 +04:00
};
/* a register of the lvm commands */
struct command {
const char *name;
const char *desc;
const char *usage;
command_fn fn;
int num_args;
int *valid_args;
};
2001-09-25 16:49:28 +04:00
void usage(const char *name);
/* the argument verify/normalise functions */
2002-11-18 17:04:08 +03:00
int yes_no_arg(struct cmd_context *cmd, struct arg *a);
2002-12-03 16:24:38 +03: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 17:04:08 +03:00
int int_arg(struct cmd_context *cmd, struct arg *a);
int int_arg_with_sign(struct cmd_context *cmd, struct arg *a);
int major_arg(struct cmd_context *cmd, struct arg *a);
2002-11-18 17:04:08 +03:00
int minor_arg(struct cmd_context *cmd, struct arg *a);
int string_arg(struct cmd_context *cmd, struct arg *a);
int permission_arg(struct cmd_context *cmd, struct arg *a);
int metadatatype_arg(struct cmd_context *cmd, struct arg *a);
int units_arg(struct cmd_context *cmd, struct arg *a);
2001-09-25 16:49:28 +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 */
static inline const unsigned int arg_count(struct cmd_context *cmd, int a)
{
return cmd->args[a].count;
2001-09-25 16:49:28 +04:00
}
static inline const char *arg_value(struct cmd_context *cmd, int a)
{
return cmd->args[a].value;
2001-09-25 16:49:28 +04:00
}
static inline const char *arg_str_value(struct cmd_context *cmd, int a,
const char *def)
2001-09-25 16:49:28 +04:00
{
return arg_count(cmd, a) ? cmd->args[a].value : def;
2001-09-25 16:49:28 +04:00
}
static inline const int32_t arg_int_value(struct cmd_context *cmd, int a,
const int32_t def)
2001-09-25 16:49:28 +04:00
{
return arg_count(cmd, a) ? cmd->args[a].i_value : def;
2001-09-25 16:49:28 +04: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 17:33:59 +03:00
{
return arg_count(cmd, a) ? cmd->args[a].i64_value : def;
}
static inline const uint64_t arg_uint64_value(struct cmd_context *cmd, int a,
const uint64_t def)
{
return arg_count(cmd, a) ? cmd->args[a].ui64_value : def;
}
static inline const void *arg_ptr_value(struct cmd_context *cmd, int a,
const void *def)
{
return arg_count(cmd, a) ? cmd->args[a].ptr : def;
}
static inline const sign_t arg_sign_value(struct cmd_context *cmd, int a,
const sign_t def)
{
return arg_count(cmd, a) ? cmd->args[a].sign : def;
}
static inline const int arg_count_increment(struct cmd_context *cmd, int a)
2001-09-25 16:49:28 +04:00
{
return cmd->args[a].count++;
2001-09-25 16:49:28 +04:00
}
static inline const char *command_name(struct cmd_context *cmd)
{
return cmd->command->name;
}
2001-10-08 22:44:22 +04:00
int pvmove_poll(struct cmd_context *cmd, const char *pv, unsigned background);
2001-10-06 01:39:30 +04:00
#endif