OSDN Git Service

A command to list md subsystem versions
authorKen Sumrall <ksumrall@android.com>
Fri, 8 Feb 2013 21:33:09 +0000 (13:33 -0800)
committerKen Sumrall <ksumrall@android.com>
Fri, 8 Feb 2013 22:13:41 +0000 (14:13 -0800)
This command was written to query the dm-crypt subsystem version,
but it prints out the version of all md subsystems currently running
in the kernel.

Change-Id: Iecf67c697c23b47b4a3f8f72df6048b87687c875

tests/crypto/Android.mk [new file with mode: 0644]
tests/crypto/get_dm_versions.c [new file with mode: 0644]

diff --git a/tests/crypto/Android.mk b/tests/crypto/Android.mk
new file mode 100644 (file)
index 0000000..f1500ce
--- /dev/null
@@ -0,0 +1,12 @@
+# Copyright 2013 The Android Open Source Project
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= get_dm_versions.c
+LOCAL_MODULE:= get_dm_versions
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
+LOCAL_CFLAGS :=
+include $(BUILD_EXECUTABLE)
diff --git a/tests/crypto/get_dm_versions.c b/tests/crypto/get_dm_versions.c
new file mode 100644 (file)
index 0000000..6df7491
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/dm-ioctl.h>
+#include <stdlib.h>
+
+#define DM_CRYPT_BUF_SIZE 4096
+
+static void ioctl_init(struct dm_ioctl *io, size_t dataSize, const char *name, unsigned flags)
+{
+    memset(io, 0, dataSize);
+    io->data_size = dataSize;
+    io->data_start = sizeof(struct dm_ioctl);
+    io->version[0] = 4;
+    io->version[1] = 0;
+    io->version[2] = 0;
+    io->flags = flags;
+    if (name) {
+        strncpy(io->name, name, sizeof(io->name));
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    char buffer[DM_CRYPT_BUF_SIZE];
+    struct dm_ioctl *io;
+    struct dm_target_versions *v;
+    int i;
+    int fd;
+
+    fd = open("/dev/device-mapper", O_RDWR);
+    if (fd < 0) {
+        fprintf(stderr, "Cannot open /dev/device-mapper\n");
+        exit(1);
+    }
+
+    io = (struct dm_ioctl *) buffer;
+
+    ioctl_init(io, DM_CRYPT_BUF_SIZE, NULL, 0);
+
+    if (ioctl(fd, DM_LIST_VERSIONS, io)) {
+        fprintf(stderr, "ioctl(DM_LIST_VERSIONS) returned an error\n");
+        exit(1);
+    }
+
+    /* Iterate over the returned versions, and print each subsystem's version */
+    v = (struct dm_target_versions *) &buffer[sizeof(struct dm_ioctl)];
+    while (v->next) {
+        printf("%s: %d.%d.%d\n", v->name, v->version[0], v->version[1], v->version[2]);
+        v = (struct dm_target_versions *)(((char *)v) + v->next);
+    }
+
+    close(fd);
+    exit(0);
+}
+