All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kpartx: Properly support read-only files
@ 2013-06-10 16:40 Till Maas
  0 siblings, 0 replies; only message in thread
From: Till Maas @ 2013-06-10 16:40 UTC (permalink / raw)
  To: dm-devel

- 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(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 98d88c0..82c3bb2 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -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);
diff --git a/kpartx/lopart.c b/kpartx/lopart.c
index 79a7593..9082ca8 100644
--- a/kpartx/lopart.c
+++ b/kpartx/lopart.c
@@ -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) {
-- 
1.7.11.7

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-10 16:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-10 16:40 [PATCH] kpartx: Properly support read-only files Till Maas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.