kpartx: Properly support read-only files
PATCH 1/1 kpartx: Properly support read-only files
- Use only variable loopro instead of additionally variable ro: If the file can only be opened read-only, it does not make sense to create a writable mapping.
- Fall back to read-only mapping on EACCESS instead of only on EROFS, since immutable files causes EACCESS.
--- kpartx/kpartx.c | 8 ++++---- kpartx/lopart.c | 2 +-
2 Dateien geändert, 5 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
kpartx/kpartx.c +4 -4
@@ -192,7 +192,7 @@ get_hotplug_device(void)int main (int argc,char **argv){ -int i, j, m, n, op, off, arg, c, d, ro=0 ; +int i, j, m, n, op, off, arg, c, d;int fd =-1 ;struct slice all;struct pt *ptp;
@@ -241,7 +241,7 @@ main(int argc, char **argv){while ((arg =getopt (argc, argv, short_opts)) !=EOF )switch (arg) {case 'r' : - ro=1 ; + loopro=1 ;break ;case 'f' : force_devmap=1 ;
@@ -489,7 +489,7 @@ main(int argc, char **argv){ DM_DEVICE_RELOAD : DM_DEVICE_CREATE);if (!dm_addmap (op, partname,DM_TARGET , params, - slices[j].size, ro, uuid, j+1 , + slices[j].size, loopro, uuid, j+1 , buf.st_mode &0777 , buf.st_uid, buf.st_gid, &cookie)) { fprintf(stderr, "create/reload failed on %s\n",
@@ -552,7 +552,7 @@ main(int argc, char **argv){ DM_DEVICE_RELOAD : DM_DEVICE_CREATE);dm_addmap (op, partname,DM_TARGET , params, - slices[j].size, ro, uuid, j+1 , + slices[j].size, loopro, uuid, j+1 , buf.st_mode &0777 , buf.st_uid, buf.st_gid, &cookie);
kpartx/lopart.c +1 -1
@@ -230,7 +230,7 @@ set_loop (const char *device, const char *file, int offset, int *loopro)if ((ffd =open (file, mode)) <0 ) { -if (!*loopro && errno ==EROFS ) +if (!*loopro && (errno ==EROFS || errno ==EACCES )) ffd =open (file, mode =O_RDONLY );if (ffd <0 ) {
Signature · 6 lines
1.7.11.7 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel