]> sourceware.org Git - dm.git/commitdiff
A setgeometry implementation. [untested]
authorAlasdair Kergon <agk@redhat.com>
Mon, 20 Feb 2006 23:55:57 +0000 (23:55 +0000)
committerAlasdair Kergon <agk@redhat.com>
Mon, 20 Feb 2006 23:55:57 +0000 (23:55 +0000)
WHATS_NEW
dmsetup/dmsetup.c
kernel/ioctl/dm-ioctl.h
lib/.exported_symbols
lib/ioctl/libdm-compat.h
lib/ioctl/libdm-iface.c
lib/ioctl/libdm-targets.h
lib/libdevmapper.h
lib/libdm-common.c

index 53634e3ad9ee749fbba75c1f76e9b10e08501d9f..a1695b2f38371f0df05630e12229005d543c413f 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 1.02.04 - 
 ============================
+  Add setgeometry.
 
 Version 1.02.03 - 7 Feb 2006
 ============================
index 60421f8689fac87bfad1c77a6e5af904a525d047..7d37c3c9d48f7e9f7e4b1b4492a5e767a778aa22 100644 (file)
@@ -508,6 +508,39 @@ static int _message(int argc, char **argv, void *data)
        return r;
 }
 
+static int _setgeometry(int argc, char **argv, void *data)
+{
+       int r = 0;
+       struct dm_task *dmt;
+
+       if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
+               return 0;
+
+       if (_switches[UUID_ARG] || _switches[MAJOR_ARG]) {
+               if (!_set_task_device(dmt, NULL, 0))
+                       goto out;
+       } else {
+               if (!_set_task_device(dmt, argv[1], 0))
+                       goto out;
+               argc--;
+               argv++;
+       }
+
+       if (!dm_task_set_geometry(dmt, argv[1], argv[2], argv[3], argv[4]))
+               goto out;
+
+       /* run the task */
+       if (!dm_task_run(dmt))
+               goto out;
+
+       r = 1;
+
+      out:
+       dm_task_destroy(dmt);
+
+       return r;
+}
+
 static int _version(int argc, char **argv, void *data)
 {
        char version[80];
@@ -1326,6 +1359,7 @@ static struct command _commands[] = {
        {"mknodes", "[<device>]", 0, 1, _mknodes},
        {"targets", "", 0, 0, _targets},
        {"version", "", 0, 0, _version},
+       {"setgeometry", "<device> <cyl> <head> <sect> <start>", 5, 5, _setgeometry},
        {NULL, NULL, 0, 0, NULL}
 };
 
index 0d5bdabac825c9ab772d151616304817e05a7efc..472893ba04546c1c65aa4491e0e1daf6dbfbdfa1 100644 (file)
  *
  * DM_TARGET_MSG:
  * Pass a message string to the target at a specific offset of a device.
+ *
+ * DM_DEV_SET_GEOMETRY:
+ * Set the geometry of a device by passing in a string.  The
+ * string should have this format:
+ *
+ * "cylinders heads sectors_per_track start_sector"
+ * 
+ * Beware that CHS geometry is nearly obsolete and only provided
+ * for compatibility with dm devices that can be booted by a PC
+ * BIOS.  See struct hd_geometry for range limits.  Also note that
+ * the geometry is erased if the device size changes.
  */
 
 /*
@@ -220,6 +231,7 @@ enum {
        /* Added later */
        DM_LIST_VERSIONS_CMD,
        DM_TARGET_MSG_CMD,
+       DM_DEV_SET_GEOMETRY_CMD
 };
 
 /*
@@ -232,51 +244,53 @@ enum {
  */
 #ifdef CONFIG_COMPAT
 typedef char ioctl_struct[308];
-#define DM_VERSION_32       _IOWR(DM_IOCTL, DM_VERSION_CMD, ioctl_struct)
-#define DM_REMOVE_ALL_32    _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, ioctl_struct)
-#define DM_LIST_DEVICES_32  _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, ioctl_struct)
-
-#define DM_DEV_CREATE_32    _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, ioctl_struct)
-#define DM_DEV_REMOVE_32    _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, ioctl_struct)
-#define DM_DEV_RENAME_32    _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, ioctl_struct)
-#define DM_DEV_SUSPEND_32   _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, ioctl_struct)
-#define DM_DEV_STATUS_32    _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, ioctl_struct)
-#define DM_DEV_WAIT_32      _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, ioctl_struct)
-
-#define DM_TABLE_LOAD_32    _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, ioctl_struct)
-#define DM_TABLE_CLEAR_32   _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, ioctl_struct)
-#define DM_TABLE_DEPS_32    _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, ioctl_struct)
-#define DM_TABLE_STATUS_32  _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, ioctl_struct)
-#define DM_LIST_VERSIONS_32 _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, ioctl_struct)
-#define DM_TARGET_MSG_32    _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, ioctl_struct)
+#define DM_VERSION_32          _IOWR(DM_IOCTL, DM_VERSION_CMD, ioctl_struct)
+#define DM_REMOVE_ALL_32       _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, ioctl_struct)
+#define DM_LIST_DEVICES_32     _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, ioctl_struct)
+
+#define DM_DEV_CREATE_32       _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, ioctl_struct)
+#define DM_DEV_REMOVE_32       _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, ioctl_struct)
+#define DM_DEV_RENAME_32       _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, ioctl_struct)
+#define DM_DEV_SUSPEND_32      _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, ioctl_struct)
+#define DM_DEV_STATUS_32       _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, ioctl_struct)
+#define DM_DEV_WAIT_32         _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, ioctl_struct)
+
+#define DM_TABLE_LOAD_32       _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, ioctl_struct)
+#define DM_TABLE_CLEAR_32      _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, ioctl_struct)
+#define DM_TABLE_DEPS_32       _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, ioctl_struct)
+#define DM_TABLE_STATUS_32     _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, ioctl_struct)
+#define DM_LIST_VERSIONS_32    _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, ioctl_struct)
+#define DM_TARGET_MSG_32       _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, ioctl_struct)
+#define DM_DEV_SET_GEOMETRY_32 _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, ioctl_struct)
 #endif
 
 #define DM_IOCTL 0xfd
 
-#define DM_VERSION       _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
-#define DM_REMOVE_ALL    _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, struct dm_ioctl)
-#define DM_LIST_DEVICES  _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, struct dm_ioctl)
+#define DM_VERSION             _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
+#define DM_REMOVE_ALL          _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, struct dm_ioctl)
+#define DM_LIST_DEVICES                _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, struct dm_ioctl)
 
-#define DM_DEV_CREATE    _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, struct dm_ioctl)
-#define DM_DEV_REMOVE    _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, struct dm_ioctl)
-#define DM_DEV_RENAME    _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, struct dm_ioctl)
-#define DM_DEV_SUSPEND   _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, struct dm_ioctl)
-#define DM_DEV_STATUS    _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, struct dm_ioctl)
-#define DM_DEV_WAIT      _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, struct dm_ioctl)
+#define DM_DEV_CREATE          _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, struct dm_ioctl)
+#define DM_DEV_REMOVE          _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, struct dm_ioctl)
+#define DM_DEV_RENAME          _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, struct dm_ioctl)
+#define DM_DEV_SUSPEND         _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, struct dm_ioctl)
+#define DM_DEV_STATUS          _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, struct dm_ioctl)
+#define DM_DEV_WAIT            _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, struct dm_ioctl)
 
-#define DM_TABLE_LOAD    _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, struct dm_ioctl)
-#define DM_TABLE_CLEAR   _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, struct dm_ioctl)
-#define DM_TABLE_DEPS    _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, struct dm_ioctl)
-#define DM_TABLE_STATUS  _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, struct dm_ioctl)
+#define DM_TABLE_LOAD          _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, struct dm_ioctl)
+#define DM_TABLE_CLEAR         _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, struct dm_ioctl)
+#define DM_TABLE_DEPS          _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, struct dm_ioctl)
+#define DM_TABLE_STATUS                _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, struct dm_ioctl)
 
-#define DM_LIST_VERSIONS _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, struct dm_ioctl)
+#define DM_LIST_VERSIONS       _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, struct dm_ioctl)
 
-#define DM_TARGET_MSG   _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl)
+#define DM_TARGET_MSG          _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl)
+#define DM_DEV_SET_GEOMETRY    _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
 
 #define DM_VERSION_MAJOR       4
-#define DM_VERSION_MINOR       5
+#define DM_VERSION_MINOR       6
 #define DM_VERSION_PATCHLEVEL  0
-#define DM_VERSION_EXTRA       "-ioctl (2005-10-04)"
+#define DM_VERSION_EXTRA       "-ioctl (2006-02-17)"
 
 /* Status bits */
 #define DM_READONLY_FLAG       (1 << 0) /* In/Out */
index 9b398f2071305c6c7eea2c86e4d7b27a03f1e372..2407f0ab6cabfa5ec831fa0c9648cbb41e7df072 100644 (file)
@@ -108,3 +108,4 @@ dm_hash_get_data
 dm_hash_get_first
 dm_hash_get_next
 dm_set_selinux_context
+dm_task_set_geometry
index 4c06e7f3ac501f53182ce4c477a1548dad62c9d9..7a7e75237c8bacdf31c530511b3cdce569d2cbe0 100644 (file)
@@ -116,6 +116,7 @@ static struct cmd_data _cmd_data_v1[] = {
        { "mknodes",    0,                      {4, 0, 0} },
        { "versions",   0,                      {4, 1, 0} },
        { "message",    0,                      {4, 2, 0} },
+       { "setgeometry",0,                      {4, 6, 0} },
 };
 /* *INDENT-ON* */
 
index 31359b9768492d87009eb27b235b41a743b76425..4cb49a682ffdf360b91d45f7f9d40cffad47ec60 100644 (file)
@@ -103,6 +103,9 @@ static struct cmd_data _cmd_data_v4[] = {
 #ifdef DM_TARGET_MSG
        {"message",     DM_TARGET_MSG,          {4, 2, 0}},
 #endif
+#ifdef DM_DEV_SET_GEOMETRY
+       {"setgeometry", DM_DEV_SET_GEOMETRY,    {4, 6, 0}},
+#endif
 };
 /* *INDENT-ON* */
 
@@ -1001,6 +1004,23 @@ int dm_task_set_sector(struct dm_task *dmt, uint64_t sector)
        return 1;
 }
 
+int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start)
+{
+       size_t len = strlen(cylinders) + 1 + strlen(heads) + 1 + strlen(sectors) + 1 + strlen(start) + 1;
+
+       if (!(dmt->geometry = dm_malloc(len))) {
+               log_error("dm_task_set_geometry: dm_malloc failed");
+               return 0;
+       }
+
+       if (sprintf(dmt->geometry, "%s %s %s %s", cylinders, heads, sectors, start) < 0) {
+               log_error("dm_task_set_geometry: sprintf failed");
+               return 0;
+       }
+
+        return 1;
+}
+
 int dm_task_no_open_count(struct dm_task *dmt)
 {
        dmt->no_open_count = 1;
@@ -1123,11 +1143,26 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
                return NULL;
        }
 
+       if (count && dmt->geometry) {
+               log_error("targets and geometry are incompatible");
+               return NULL;
+       }
+
        if (dmt->newname && (dmt->sector || dmt->message)) {
                log_error("message and newname are incompatible");
                return NULL;
        }
 
+       if (dmt->newname && dmt->geometry) {
+               log_error("geometry and newname are incompatible");
+               return NULL;
+       }
+
+       if (dmt->geometry && (dmt->sector || dmt->message)) {
+               log_error("geometry and message are incompatible");
+               return NULL;
+       }
+
        if (dmt->sector && !dmt->message) {
                log_error("message is required with sector");
                return NULL;
@@ -1139,6 +1174,9 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
        if (dmt->message)
                len += sizeof(struct dm_target_msg) + strlen(dmt->message) + 1;
 
+       if (dmt->geometry)
+               len += strlen(dmt->geometry) + 1;
+
        /*
         * Give len a minimum size so that we have space to store
         * dependencies or status information.
@@ -1205,6 +1243,9 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
                strcpy(tmsg->message, dmt->message);
        }
 
+       if (dmt->geometry)
+               strcpy(b, dmt->geometry);
+
        return dmi;
 
       bad:
index 4eea595d4427380d6a247a2d9dbd19a4dda3691b..b850d9971e0439f1f368031a28939f4d94c06bc4 100644 (file)
@@ -50,6 +50,7 @@ struct dm_task {
        } dmi;
        char *newname;
        char *message;
+       char *geometry;
        uint64_t sector;
        int no_open_count;
        int skip_lockfs;
index 543cb7d43238d6fc4db0cfe96e54a76bdc0d99d1..68359a4fe20ade94ab443ee7b125857b648e5ca0 100644 (file)
@@ -80,7 +80,9 @@ enum {
 
        DM_DEVICE_LIST_VERSIONS,
        
-       DM_DEVICE_TARGET_MSG
+       DM_DEVICE_TARGET_MSG,
+
+       DM_DEVICE_SET_GEOMETRY
 };
 
 struct dm_task;
@@ -145,6 +147,7 @@ int dm_task_set_uid(struct dm_task *dmt, uid_t uid);
 int dm_task_set_gid(struct dm_task *dmt, gid_t gid);
 int dm_task_set_mode(struct dm_task *dmt, mode_t mode);
 int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);
+int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start);
 int dm_task_set_message(struct dm_task *dmt, const char *message);
 int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);
 int dm_task_no_open_count(struct dm_task *dmt);
index c27c077e942ba05493fdc4be049f750b11a4441c..0b2e3c24a1bf3e2197a77fc8a77812b2ca30cdae 100644 (file)
@@ -510,3 +510,4 @@ out:
        dm_task_destroy(dmt);
        return r;
 }
+
This page took 0.03775 seconds and 5 git commands to generate.