mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Some internal renaming.
Add --separator and --sort to dmsetup (unused as yet). Make alignment flag optional when specifying report fields.
This commit is contained in:
parent
07473c2be3
commit
03c6979264
@ -1,5 +1,8 @@
|
||||
Version 1.02.16 -
|
||||
===================================
|
||||
Add --separator and --sort to dmsetup (unused).
|
||||
Make alignment flag optional when specifying report fields.
|
||||
|
||||
Version 1.02.15 - 17th January 2007
|
||||
===================================
|
||||
Add basic reporting functions to libdevmapper.
|
||||
|
@ -646,11 +646,13 @@ struct dm_report_field;
|
||||
/*
|
||||
* dm_report_field_type flags
|
||||
*/
|
||||
#define DM_REPORT_FIELD_MASK 0x0000000F
|
||||
#define DM_REPORT_FIELD_MASK 0x000000FF
|
||||
#define DM_REPORT_FIELD_ALIGN_MASK 0x0000000F
|
||||
#define DM_REPORT_FIELD_ALIGN_LEFT 0x00000001
|
||||
#define DM_REPORT_FIELD_ALIGN_RIGHT 0x00000002
|
||||
#define DM_REPORT_FIELD_STRING 0x00000004
|
||||
#define DM_REPORT_FIELD_NUMBER 0x00000008
|
||||
#define DM_REPORT_FIELD_TYPE_MASK 0x000000F0
|
||||
#define DM_REPORT_FIELD_TYPE_STRING 0x00000010
|
||||
#define DM_REPORT_FIELD_TYPE_NUMBER 0x00000020
|
||||
|
||||
struct dm_report;
|
||||
struct dm_report_field_type {
|
||||
@ -668,7 +670,7 @@ struct dm_report_field_type {
|
||||
/*
|
||||
* dm_report_init output_flags
|
||||
*/
|
||||
#define DM_REPORT_OUTPUT_MASK 0x00000007
|
||||
#define DM_REPORT_OUTPUT_MASK 0x000000FF
|
||||
#define DM_REPORT_OUTPUT_ALIGNED 0x00000001
|
||||
#define DM_REPORT_OUTPUT_BUFFERED 0x00000002
|
||||
#define DM_REPORT_OUTPUT_HEADINGS 0x00000004
|
||||
|
@ -672,7 +672,7 @@ static int _row_compare(const void *a, const void *b)
|
||||
for (cnt = 0; cnt < rowa->rh->keys_count; cnt++) {
|
||||
sfa = (*rowa->sort_fields)[cnt];
|
||||
sfb = (*rowb->sort_fields)[cnt];
|
||||
if (sfa->props->flags & DM_REPORT_FIELD_NUMBER) {
|
||||
if (sfa->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) {
|
||||
const uint64_t numa =
|
||||
*(const uint64_t *) sfa->sort_value;
|
||||
const uint64_t numb =
|
||||
@ -686,7 +686,7 @@ static int _row_compare(const void *a, const void *b)
|
||||
} else { /* FLD_DESCENDING */
|
||||
return (numa < numb) ? 1 : -1;
|
||||
}
|
||||
} else { /* DM_REPORT_FIELD_STRING */
|
||||
} else { /* DM_REPORT_FIELD_TYPE_STRING */
|
||||
const char *stra = (const char *) sfa->sort_value;
|
||||
const char *strb = (const char *) sfb->sort_value;
|
||||
int cmp = strcmp(stra, strb);
|
||||
@ -740,6 +740,7 @@ int dm_report_output(struct dm_report *rh)
|
||||
const char *repstr;
|
||||
char buf[4096];
|
||||
unsigned width;
|
||||
uint32_t align;
|
||||
|
||||
if (list_empty(&rh->rows))
|
||||
return 1;
|
||||
@ -771,7 +772,11 @@ int dm_report_output(struct dm_report *rh)
|
||||
if (!dm_pool_grow_object(rh->mem, repstr,
|
||||
strlen(repstr)))
|
||||
goto bad_grow;
|
||||
} else if (field->props->flags & DM_REPORT_FIELD_ALIGN_LEFT) {
|
||||
} else {
|
||||
if (!(align = field->props->flags & DM_REPORT_FIELD_ALIGN_MASK))
|
||||
align = (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) ?
|
||||
DM_REPORT_FIELD_ALIGN_RIGHT : DM_REPORT_FIELD_ALIGN_LEFT;
|
||||
if (align & DM_REPORT_FIELD_ALIGN_LEFT) {
|
||||
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
|
||||
width, width, repstr) < 0)
|
||||
goto bad_snprintf;
|
||||
@ -784,6 +789,7 @@ int dm_report_output(struct dm_report *rh)
|
||||
if (!dm_pool_grow_object(rh->mem, buf, width))
|
||||
goto bad_grow;
|
||||
}
|
||||
}
|
||||
|
||||
if (!list_end(&row->fields, fh))
|
||||
if (!dm_pool_grow_object(rh->mem, rh->separator,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
||||
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 NEC Corperation
|
||||
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2005-2007 NEC Corperation
|
||||
*
|
||||
* This file is part of the device-mapper userspace tools.
|
||||
*
|
||||
@ -114,7 +114,9 @@ enum {
|
||||
NOOPENCOUNT_ARG,
|
||||
NOTABLE_ARG,
|
||||
OPTIONS_ARG,
|
||||
SEPARATOR_ARG,
|
||||
SHOWKEYS_ARG,
|
||||
SORT_ARG,
|
||||
TABLE_ARG,
|
||||
TARGET_ARG,
|
||||
TREE_ARG,
|
||||
@ -126,10 +128,10 @@ enum {
|
||||
};
|
||||
|
||||
static int _switches[NUM_SWITCHES];
|
||||
static int _values[NUM_SWITCHES];
|
||||
static int _int_args[NUM_SWITCHES];
|
||||
static char *_string_args[NUM_SWITCHES];
|
||||
static int _num_devices;
|
||||
static char *_uuid;
|
||||
static char *_fields;
|
||||
static char *_table;
|
||||
static char *_target;
|
||||
static char *_command;
|
||||
@ -348,8 +350,8 @@ static int _set_task_device(struct dm_task *dmt, const char *name, int optional)
|
||||
if (!dm_task_set_uuid(dmt, _uuid))
|
||||
return 0;
|
||||
} else if (_switches[MAJOR_ARG] && _switches[MINOR_ARG]) {
|
||||
if (!dm_task_set_major(dmt, _values[MAJOR_ARG]) ||
|
||||
!dm_task_set_minor(dmt, _values[MINOR_ARG]))
|
||||
if (!dm_task_set_major(dmt, _int_args[MAJOR_ARG]) ||
|
||||
!dm_task_set_minor(dmt, _int_args[MINOR_ARG]))
|
||||
return 0;
|
||||
} else if (!optional) {
|
||||
fprintf(stderr, "No device specified.\n");
|
||||
@ -440,19 +442,19 @@ static int _create(int argc, char **argv, void *data __attribute((unused)))
|
||||
if (_switches[READ_ONLY] && !dm_task_set_ro(dmt))
|
||||
goto out;
|
||||
|
||||
if (_switches[MAJOR_ARG] && !dm_task_set_major(dmt, _values[MAJOR_ARG]))
|
||||
if (_switches[MAJOR_ARG] && !dm_task_set_major(dmt, _int_args[MAJOR_ARG]))
|
||||
goto out;
|
||||
|
||||
if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _values[MINOR_ARG]))
|
||||
if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _int_args[MINOR_ARG]))
|
||||
goto out;
|
||||
|
||||
if (_switches[UID_ARG] && !dm_task_set_uid(dmt, _values[UID_ARG]))
|
||||
if (_switches[UID_ARG] && !dm_task_set_uid(dmt, _int_args[UID_ARG]))
|
||||
goto out;
|
||||
|
||||
if (_switches[GID_ARG] && !dm_task_set_gid(dmt, _values[GID_ARG]))
|
||||
if (_switches[GID_ARG] && !dm_task_set_gid(dmt, _int_args[GID_ARG]))
|
||||
goto out;
|
||||
|
||||
if (_switches[MODE_ARG] && !dm_task_set_mode(dmt, _values[MODE_ARG]))
|
||||
if (_switches[MODE_ARG] && !dm_task_set_mode(dmt, _int_args[MODE_ARG]))
|
||||
goto out;
|
||||
|
||||
if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
|
||||
@ -1888,7 +1890,9 @@ static int _process_switches(int *argc, char ***argv)
|
||||
{"noopencount", 0, &ind, NOOPENCOUNT_ARG},
|
||||
{"notable", 0, &ind, NOTABLE_ARG},
|
||||
{"options", 1, &ind, OPTIONS_ARG},
|
||||
{"separator", 1, &ind, SEPARATOR_ARG},
|
||||
{"showkeys", 0, &ind, SHOWKEYS_ARG},
|
||||
{"sort", 1, &ind, SORT_ARG},
|
||||
{"table", 1, &ind, TABLE_ARG},
|
||||
{"target", 1, &ind, TARGET_ARG},
|
||||
{"tree", 0, &ind, TREE_ARG},
|
||||
@ -1906,7 +1910,7 @@ static int _process_switches(int *argc, char ***argv)
|
||||
* Zero all the index counts.
|
||||
*/
|
||||
memset(&_switches, 0, sizeof(_switches));
|
||||
memset(&_values, 0, sizeof(_values));
|
||||
memset(&_int_args, 0, sizeof(_int_args));
|
||||
|
||||
namebase = strdup((*argv)[0]);
|
||||
base = basename(namebase);
|
||||
@ -1918,17 +1922,17 @@ static int _process_switches(int *argc, char ***argv)
|
||||
_switches[OPTIONS_ARG]++;
|
||||
_switches[MAJOR_ARG]++;
|
||||
_switches[MINOR_ARG]++;
|
||||
_fields = (char *) "name";
|
||||
_string_args[OPTIONS_ARG] = (char *) "name";
|
||||
|
||||
if (*argc == 3) {
|
||||
_values[MAJOR_ARG] = atoi((*argv)[1]);
|
||||
_values[MINOR_ARG] = atoi((*argv)[2]);
|
||||
_int_args[MAJOR_ARG] = atoi((*argv)[1]);
|
||||
_int_args[MINOR_ARG] = atoi((*argv)[2]);
|
||||
*argc -= 2;
|
||||
*argv += 2;
|
||||
} else if ((*argc == 2) &&
|
||||
(2 == sscanf((*argv)[1], "%i:%i",
|
||||
&_values[MAJOR_ARG],
|
||||
&_values[MINOR_ARG]))) {
|
||||
&_int_args[MAJOR_ARG],
|
||||
&_int_args[MINOR_ARG]))) {
|
||||
*argc -= 1;
|
||||
*argv += 1;
|
||||
} else {
|
||||
@ -1950,7 +1954,7 @@ static int _process_switches(int *argc, char ***argv)
|
||||
|
||||
optarg = 0;
|
||||
optind = OPTIND_INIT;
|
||||
while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCfGj:m:Mno:ru:Uv",
|
||||
while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCfGj:m:Mno:O:ru:Uv",
|
||||
long_options, NULL)) != -1) {
|
||||
if (c == ':' || c == '?')
|
||||
return 0;
|
||||
@ -1962,17 +1966,25 @@ static int _process_switches(int *argc, char ***argv)
|
||||
_switches[READ_ONLY]++;
|
||||
if (c == 'j' || ind == MAJOR_ARG) {
|
||||
_switches[MAJOR_ARG]++;
|
||||
_values[MAJOR_ARG] = atoi(optarg);
|
||||
_int_args[MAJOR_ARG] = atoi(optarg);
|
||||
}
|
||||
if (c == 'm' || ind == MINOR_ARG) {
|
||||
_switches[MINOR_ARG]++;
|
||||
_values[MINOR_ARG] = atoi(optarg);
|
||||
_int_args[MINOR_ARG] = atoi(optarg);
|
||||
}
|
||||
if (c == 'n' || ind == NOTABLE_ARG)
|
||||
_switches[NOTABLE_ARG]++;
|
||||
if (c == 'o' || ind == OPTIONS_ARG) {
|
||||
_switches[OPTIONS_ARG]++;
|
||||
_fields = optarg;
|
||||
_string_args[OPTIONS_ARG] = optarg;
|
||||
}
|
||||
if (ind == SEPARATOR_ARG) {
|
||||
_switches[SEPARATOR_ARG]++;
|
||||
_string_args[SEPARATOR_ARG] = optarg;
|
||||
}
|
||||
if (c == 'O' || ind == SORT_ARG) {
|
||||
_switches[SORT_ARG]++;
|
||||
_string_args[SORT_ARG] = optarg;
|
||||
}
|
||||
if (c == 'v' || ind == VERBOSE_ARG)
|
||||
_switches[VERBOSE_ARG]++;
|
||||
@ -1982,16 +1994,16 @@ static int _process_switches(int *argc, char ***argv)
|
||||
}
|
||||
if (c == 'G' || ind == GID_ARG) {
|
||||
_switches[GID_ARG]++;
|
||||
_values[GID_ARG] = atoi(optarg);
|
||||
_int_args[GID_ARG] = atoi(optarg);
|
||||
}
|
||||
if (c == 'U' || ind == UID_ARG) {
|
||||
_switches[UID_ARG]++;
|
||||
_values[UID_ARG] = atoi(optarg);
|
||||
_int_args[UID_ARG] = atoi(optarg);
|
||||
}
|
||||
if (c == 'M' || ind == MODE_ARG) {
|
||||
_switches[MODE_ARG]++;
|
||||
/* FIXME Accept modes as per chmod */
|
||||
_values[MODE_ARG] = (int) strtol(optarg, NULL, 8);
|
||||
_int_args[MODE_ARG] = (int) strtol(optarg, NULL, 8);
|
||||
}
|
||||
if ((ind == EXEC_ARG)) {
|
||||
_switches[EXEC_ARG]++;
|
||||
@ -2032,12 +2044,12 @@ static int _process_switches(int *argc, char ***argv)
|
||||
}
|
||||
|
||||
if (_switches[COLS_ARG] && _switches[OPTIONS_ARG] &&
|
||||
strcmp(_fields, "name")) {
|
||||
strcmp(_string_args[OPTIONS_ARG], "name")) {
|
||||
fprintf(stderr, "Only -o name is supported so far.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_switches[TREE_ARG] && !_process_tree_options(_fields))
|
||||
if (_switches[TREE_ARG] && !_process_tree_options(_string_args[OPTIONS_ARG]))
|
||||
return 0;
|
||||
|
||||
if (_switches[TABLE_ARG] && _switches[NOTABLE_ARG]) {
|
||||
|
Loading…
Reference in New Issue
Block a user