Package: kpartx Version: 0.4.8-13 Severity: wishlist Tags: patch I'd like to have the ability to create targets in which are read-only to keep from accidentally modifying the newly created device. In some cases, mounting with -o ro still modifies the device (in the case of ext3 filesystems). I created a small patch that will do this. I have tested it only to the point that using -a with or without -r produces the desired effects.
-- System Information: Debian Release: 3.1 APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.24.5 Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) Versions of packages kpartx depends on: ii dmsetup 2:1.02.27-4 The Linux Kernel Device Mapper use ii libc6 2.7-5 GNU C Library: Shared libraries ii libdevmapper1.02.1 2:1.02.27-4 The Linux Kernel Device Mapper use kpartx recommends no packages. -- no debconf information
diff -ruN multipath-tools-0.4.8-orig/kpartx/devmapper.c multipath-tools-0.4.8/kpartx/devmapper.c --- multipath-tools-0.4.8-orig/kpartx/devmapper.c 2007-08-02 17:05:37.000000000 -0400 +++ multipath-tools-0.4.8/kpartx/devmapper.c 2008-11-05 21:32:51.000000000 -0500 @@ -72,7 +72,7 @@ extern int dm_addmap (int task, const char *name, const char *target, - const char *params, unsigned long size, const char *uuid, int part) { + const char *params, unsigned long size, int ro, const char *uuid, int part) { int r = 0; struct dm_task *dmt; char *prefixed_uuid; @@ -86,6 +86,9 @@ if (!dm_task_add_target (dmt, 0, size, target, params)) goto addout; + if (ro && !dm_task_set_ro (dmt)) + goto addout; + if (task == DM_DEVICE_CREATE && uuid) { prefixed_uuid = malloc(MAX_PREFIX_LEN + strlen(uuid) + 1); if (!prefixed_uuid) { diff -ruN multipath-tools-0.4.8-orig/kpartx/devmapper.h multipath-tools-0.4.8/kpartx/devmapper.h --- multipath-tools-0.4.8-orig/kpartx/devmapper.h 2007-08-02 17:05:37.000000000 -0400 +++ multipath-tools-0.4.8/kpartx/devmapper.h 2008-11-05 21:36:05.000000000 -0500 @@ -1,7 +1,7 @@ int dm_prereq (char *, int, int, int); int dm_simplecmd (int, const char *); int dm_addmap (int, const char *, const char *, const char *, unsigned long, - char *, int); + int, char *, int); int dm_map_present (char *); char * dm_mapname(int major, int minor); dev_t dm_get_first_dep(char *devname); diff -ruN multipath-tools-0.4.8-orig/kpartx/kpartx.c multipath-tools-0.4.8/kpartx/kpartx.c --- multipath-tools-0.4.8-orig/kpartx/kpartx.c 2007-08-02 17:05:37.000000000 -0400 +++ multipath-tools-0.4.8/kpartx/kpartx.c 2008-11-05 21:38:59.000000000 -0500 @@ -82,7 +82,7 @@ addpts("sun", read_sun_pt); } -static char short_opts[] = "ladgvnp:t:"; +static char short_opts[] = "rladgvnp:t:"; /* Used in gpt.c */ int force_gpt=0; @@ -91,6 +91,7 @@ usage(void) { printf("usage : kpartx [-a|-d|-l] [-v] wholedisk\n"); printf("\t-a add partition devmappings\n"); + printf("\t-r devmappings will be readonly\n"); printf("\t-d del partition devmappings\n"); printf("\t-l list partitions devmappings that would be added by -a\n"); printf("\t-p set device name-partition number delimiter\n"); @@ -183,7 +184,7 @@ int main(int argc, char **argv){ - int fd, i, j, m, n, op, off, arg, c, d; + int fd, i, j, m, n, op, off, arg, c, d, ro=0; struct slice all; struct pt *ptp; enum action what = LIST; @@ -230,6 +231,9 @@ } while ((arg = getopt(argc, argv, short_opts)) != EOF) switch(arg) { + case 'r': + ro=1; + break; case 'g': force_gpt=1; break; @@ -458,7 +462,7 @@ DM_DEVICE_RELOAD : DM_DEVICE_CREATE); dm_addmap(op, partname, DM_TARGET, params, - slices[j].size, uuid, j+1); + slices[j].size, ro, uuid, j+1); if (op == DM_DEVICE_RELOAD) dm_simplecmd(DM_DEVICE_RESUME, @@ -514,7 +518,7 @@ DM_DEVICE_RELOAD : DM_DEVICE_CREATE); dm_addmap(op, partname, DM_TARGET, params, - slices[j].size, uuid, j+1); + slices[j].size, ro, uuid, j+1); if (op == DM_DEVICE_RELOAD) dm_simplecmd(DM_DEVICE_RESUME,