diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 6fa4bec9c..a72f43d25 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,7 +1,7 @@ Version 1.01.02 - ============================= Call dm_lib_exit() and dm_lib_release() automatically now. - Add --target filter to dmsetup table/status. + Add --target filter to dmsetup table/status/ls. Fix dmsetup getopt_long usage. Version 1.01.01 - 29 Mar 2005 diff --git a/man/dmsetup.8.in b/man/dmsetup.8.in index b98454f89..835494a99 100644 --- a/man/dmsetup.8.in +++ b/man/dmsetup.8.in @@ -29,7 +29,7 @@ dmsetup \- low level logical volume management .B dmsetup rename .I device_name new_name .br -.B dmsetup ls +.B dmsetup ls [--target target_type] .br .B dmsetup info .I [device_name] @@ -145,8 +145,10 @@ Outputs some brief information about the device in the form: .br UUID .IP \fBls +.I [--target target_type] .br -List device names. +List device names. Optionally only list devices that have at least +one target of the specified type. .IP \fBload|reload .I device_name [table_file] .br diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 19a53f875..9eab6a478 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -600,6 +600,14 @@ static int _process_all(int argc, char **argv, return r; } +static void _display_dev(struct dm_task *dmt, char *name) +{ + struct dm_info info; + + if (dm_task_get_info(dmt, &info)) + printf("%s\t(%u, %u)\n", name, info.major, info.minor); +} + static int _status(int argc, char **argv, void *data) { int r = 0; @@ -612,6 +620,7 @@ static int _status(int argc, char **argv, void *data) struct dm_names *names = (struct dm_names *) data; char *name = NULL; int matched = 0; + int ls_only = 0; if (data) name = names->name; @@ -627,6 +636,9 @@ static int _status(int argc, char **argv, void *data) else cmd = DM_DEVICE_STATUS; + if (!strcmp(argv[0], "ls")) + ls_only = 1; + if (!(dmt = dm_task_create(cmd))) return 0; @@ -647,19 +659,24 @@ static int _status(int argc, char **argv, void *data) if (_switches[TARGET_ARG] && target_type && strcmp(target_type, _target)) continue; - if (!matched && _switches[VERBOSE_ARG]) - _display_info(dmt); - if (data && !_switches[VERBOSE_ARG]) - printf("%s: ", name); - if (target_type) { - printf("%" PRIu64 " %" PRIu64 " %s %s", - start, length, target_type, params); + if (ls_only) { + _display_dev(dmt, name); + next = NULL; + } else { + if (!matched && _switches[VERBOSE_ARG]) + _display_info(dmt); + if (data && !_switches[VERBOSE_ARG]) + printf("%s: ", name); + if (target_type) { + printf("%" PRIu64 " %" PRIu64 " %s %s", + start, length, target_type, params); + } + printf("\n"); } - printf("\n"); matched = 1; } while (next); - if (data && _switches[VERBOSE_ARG] && matched) + if (data && _switches[VERBOSE_ARG] && matched && !ls_only) printf("\n"); r = 1; @@ -842,7 +859,10 @@ static int _display_name(int argc, char **argv, void *data) static int _ls(int argc, char **argv, void *data) { - return _process_all(argc, argv, _display_name); + if (_switches[TARGET_ARG] && _target) + return _status(argc, argv, data); + else + return _process_all(argc, argv, _display_name); } /* @@ -871,7 +891,7 @@ static struct command _commands[] = { {"reload", " []", 0, 2, _load}, {"rename", " ", 1, 2, _rename}, {"message", " ", 2, -1, _message}, - {"ls", "", 0, 0, _ls}, + {"ls", "[--target ]", 0, 0, _ls}, {"info", "[]", 0, 1, _info}, {"deps", "[]", 0, 1, _deps}, {"status", "[] [--target ]", 0, 1, _status},