diff -Naurp -x '*CVS*' device-mapper-cvs/dmsetup/dmsetup.c device-mapper/dmsetup/dmsetup.c --- device-mapper-cvs/dmsetup/dmsetup.c 2006-02-03 06:23:22.000000000 -0800 +++ device-mapper/dmsetup/dmsetup.c 2006-02-15 10:57:56.000000000 -0800 @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef HAVE_SYS_IOCTL_H # include @@ -508,6 +509,73 @@ static int _message(int argc, char **arg return r; } +static int _setgeo(int argc, char **argv, void *data) +{ + int r = 0, i; + struct dm_task *dmt; + struct hd_geometry *geo = NULL; + long long x; + + if (!(dmt = dm_task_create(DM_DEVICE_SETGEO))) + 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++; + } + + for (i = 0; i < argc; i++) { + printf("_setgeo[%d] = %s\n", i, argv[i]); + } + + geo = calloc(1, sizeof(*geo) + 1); + if (!geo) + goto out; + + /* Now start filling out the geometry structure. */ + x = strtoll(argv[1], NULL, 10); + if (x > USHRT_MAX || x < 0) + goto out; + geo->cylinders = (unsigned long)x; + + x = strtoll(argv[2], NULL, 10); + if (x > UCHAR_MAX || x < 0) + goto out; + geo->heads = x; + + x = strtoll(argv[3], NULL, 10); + if (x > UCHAR_MAX || x < 0) + goto out; + geo->sectors = x; + + x = strtoll(argv[4], NULL, 10); + if (x > UINT_MAX || x < 0) + goto out; + geo->start = x; + + /* FIXME: Is piggybacking a structure as a string too evil? */ + if (!dm_task_set_message(dmt, (char *)geo)) + goto out; + + /* run the task */ + if (!dm_task_run(dmt)) + goto out; + + r = 1; + + out: + if (geo) + free(geo); + dm_task_destroy(dmt); + + return r; +} + static int _version(int argc, char **argv, void *data) { char version[80]; @@ -1326,6 +1394,7 @@ static struct command _commands[] = { {"mknodes", "[]", 0, 1, _mknodes}, {"targets", "", 0, 0, _targets}, {"version", "", 0, 0, _version}, + {"setgeometry", " ", 5, 5, _setgeo}, {NULL, NULL, 0, 0, NULL} }; diff -Naurp -x '*CVS*' device-mapper-cvs/kernel/ioctl/dm-ioctl.h device-mapper/kernel/ioctl/dm-ioctl.h --- device-mapper-cvs/kernel/ioctl/dm-ioctl.h 2005-10-04 13:12:32.000000000 -0700 +++ device-mapper/kernel/ioctl/dm-ioctl.h 2006-02-14 14:24:08.000000000 -0800 @@ -220,6 +220,8 @@ enum { /* Added later */ DM_LIST_VERSIONS_CMD, DM_TARGET_MSG_CMD, + + DM_DEV_SETGEO_CMD }; /* @@ -249,6 +251,7 @@ typedef char ioctl_struct[308]; #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_SETGEO_32 _IOWR(DM_IOCTL, DM_DEV_SETGEO_CMD, ioctl_struct) #endif #define DM_IOCTL 0xfd @@ -272,6 +275,7 @@ typedef char ioctl_struct[308]; #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_DEV_SETGEO _IOWR(DM_IOCTL, DM_DEV_SETGEO_CMD, struct dm_ioctl) #define DM_VERSION_MAJOR 4 #define DM_VERSION_MINOR 5 diff -Naurp -x '*CVS*' device-mapper-cvs/lib/ioctl/libdm-iface.c device-mapper/lib/ioctl/libdm-iface.c --- device-mapper-cvs/lib/ioctl/libdm-iface.c 2006-02-03 06:23:22.000000000 -0800 +++ device-mapper/lib/ioctl/libdm-iface.c 2006-02-14 14:23:16.000000000 -0800 @@ -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_SETGEO + {"setgeo", DM_DEV_SETGEO, {4, 2, 0}}, +#endif }; /* *INDENT-ON* */ diff -Naurp -x '*CVS*' device-mapper-cvs/lib/libdevmapper.h device-mapper/lib/libdevmapper.h --- device-mapper-cvs/lib/libdevmapper.h 2006-02-03 06:23:22.000000000 -0800 +++ device-mapper/lib/libdevmapper.h 2006-02-14 14:04:55.000000000 -0800 @@ -80,7 +80,9 @@ enum { DM_DEVICE_LIST_VERSIONS, - DM_DEVICE_TARGET_MSG + DM_DEVICE_TARGET_MSG, + + DM_DEVICE_SETGEO }; struct dm_task;