All of lore.kernel.org
 help / color / mirror / Atom feed
From: Till Maas <opensource@till.name>
To: dm-devel@redhat.com
Subject: [PATCH] kpartx: Properly support read-only files
Date: Mon, 10 Jun 2013 18:40:58 +0200	[thread overview]
Message-ID: <20130610164058.GF12715@genius.invalid> (raw)

- 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

                 reply	other threads:[~2013-06-10 16:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130610164058.GF12715@genius.invalid \
    --to=opensource@till.name \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.