From 6198a4102c5b171604b1ee82bd4a513be5506ab3 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 15 Jan 2002 15:21:57 +0000 Subject: [PATCH] Another ioctl interface update: Supply offset to start of variable data area (so struct size can change without breaking backward compatibility) Add command that just returns the driver version --- libdm/ioctl/libdevmapper.c | 33 +++++++++++++++++++++++++-------- libdm/libdevmapper.h | 4 ++++ tools/dmsetup.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/libdm/ioctl/libdevmapper.c b/libdm/ioctl/libdevmapper.c index 5e31cbf53..aaac6e278 100644 --- a/libdm/ioctl/libdevmapper.c +++ b/libdm/ioctl/libdevmapper.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -44,6 +43,17 @@ void dm_task_destroy(struct dm_task *dmt) free(dmt); } +int dm_task_get_driver_version(struct dm_task *dmt, char *version, + size_t size) +{ + if (!dmt->dmi) + return 0; + + strncpy(version, dmt->dmi->version, size); + + return 1; +} + int dm_task_get_info(struct dm_task *dmt, struct dm_info *info) { if (!dmt->dmi) @@ -51,12 +61,12 @@ int dm_task_get_info(struct dm_task *dmt, struct dm_info *info) memset(info, 0, sizeof(*info)); - info->exists = dmt->dmi->status & DM_EXISTS_FLAG ? 1 : 0; + info->exists = dmt->dmi->flags & DM_EXISTS_FLAG ? 1 : 0; if (!info->exists) return 1; - info->suspended = dmt->dmi->status & DM_SUSPEND_FLAG ? 1 : 0; - info->read_only = dmt->dmi->status & DM_READONLY_FLAG ? 1 : 0; + info->suspended = dmt->dmi->flags & DM_SUSPEND_FLAG ? 1 : 0; + info->read_only = dmt->dmi->flags & DM_READONLY_FLAG ? 1 : 0; info->target_count = dmt->dmi->target_count; info->open_count = dmt->dmi->open_count; info->major = MAJOR(dmt->dmi->dev); @@ -188,15 +198,18 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) strncpy(dmi->version, DM_IOCTL_VERSION, sizeof(dmi->version)); dmi->data_size = len; - strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name)); + dmi->data_start = sizeof(struct dm_ioctl); + + if (dmt->dev_name) + strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name)); if (dmt->type == DM_DEVICE_SUSPEND) - dmi->status |= DM_SUSPEND_FLAG; + dmi->flags |= DM_SUSPEND_FLAG; if (dmt->read_only) - dmi->status |= DM_READONLY_FLAG; + dmi->flags |= DM_READONLY_FLAG; if (dmt->minor > 0) { - dmi->status |= DM_PERSISTENT_DEV_FLAG; + dmi->flags |= DM_PERSISTENT_DEV_FLAG; dmi->dev = MKDEV(0, dmt->minor); } @@ -267,6 +280,10 @@ int dm_task_run(struct dm_task *dmt) command = DM_RENAME; break; + case DM_DEVICE_VERSION: + command = DM_VERSION; + break; + default: log("Internal error: unknown device-mapper task %d", dmt->type); diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 7e3cf61c9..1e5076c5b 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -8,6 +8,7 @@ #define LIB_DEVICE_MAPPER_H #include +#include /* * Since it is quite laborious to build the ioctl @@ -39,6 +40,8 @@ enum { DM_DEVICE_INFO, DM_DEVICE_RENAME, + + DM_DEVICE_VERSION, }; @@ -63,6 +66,7 @@ struct dm_info { unsigned int target_count; }; +int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size); int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); int dm_task_set_ro(struct dm_task *dmt); diff --git a/tools/dmsetup.c b/tools/dmsetup.c index a7328fbbb..4f1687d57 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -156,6 +156,32 @@ out: return r; } +static int _version(int argc, char **argv) +{ + int r = 0; + struct dm_task *dmt; + char version[16]; + + if (!(dmt = dm_task_create(DM_DEVICE_VERSION))) + return 0; + + if (!dm_task_run(dmt)) + goto out; + + if (!dm_task_get_driver_version(dmt, (char *)&version, + sizeof(version))) + goto out; + + printf("Driver version: %s\n", version); + + r = 1; + + out: + dm_task_destroy(dmt); + + return r; +} + static int _simple(int task, const char *name) { int r = 0; @@ -256,6 +282,7 @@ static struct command _commands[] = { {"reload", " ", 2, _reload}, {"info", "", 1, _info}, {"rename", " ", 2, _rename}, + {"version", "", 0, _version}, {NULL, NULL, 0, NULL} }; @@ -322,7 +349,7 @@ int main(int argc, char **argv) exit(1); } - if (argc < 2) { + if (argc == 0) { _usage(stderr); exit(1); }