rpms/cryptsetup-luks/devel cryptsetup-1.0.5-readonly_detection.patch, NONE, 1.1

Till Maas (till) fedora-extras-commits at redhat.com
Fri Aug 17 17:27:32 UTC 2007


Author: till

Update of /cvs/pkgs/rpms/cryptsetup-luks/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv14647

Added Files:
	cryptsetup-1.0.5-readonly_detection.patch 
Log Message:
Patch to better detect read-only devices, see #194249

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=194249


cryptsetup-1.0.5-readonly_detection.patch:

--- NEW FILE cryptsetup-1.0.5-readonly_detection.patch ---
--- cryptsetup-1.0.5.orig/lib/setup.c	2007-05-02 16:44:06.000000000 +0200
+++ cryptsetup-1.0.5/lib/setup.c	2007-08-17 19:18:31.000000000 +0200
@@ -318,11 +318,21 @@
 	char buf[128];
 	uint64_t size;
 	unsigned long size_small;
-	int readonly;
+	int readonly = 0;
 	int ret = -1;
 	int fd;
 
-	fd = open(device, O_RDONLY);
+	/* Try to open read-write to check whether it is a read-only device */
+	fd = open(device, O_RDWR);
+	if (fd < 0) {
+		if (errno == EROFS) {
+			readonly = 1;
+			fd = open(device, O_RDONLY);
+		}
+	} else {
+		close(fd);
+		fd = open(device, O_RDONLY);
+	}
 	if (fd < 0) {
 		set_error("Error opening device: %s",
 		          strerror_r(errno, buf, 128));
@@ -330,13 +340,19 @@
 	}
 
 #ifdef BLKROGET
-	if (ioctl(fd, BLKROGET, &readonly) < 0) {
-		set_error("BLKROGET failed on device: %s",
-		          strerror_r(errno, buf, 128));
-		return -1;
+	/* If the device can be opened read-write, i.e. readonly is still 0, then
+	 * check whether BKROGET says that it is read-only. E.g. read-only loop
+	 * devices may be openend read-write but are read-only according to BLKROGET
+	 */
+	if (readonly == 0) {
+		if (ioctl(fd, BLKROGET, &readonly) < 0) {
+			set_error("BLKROGET failed on device: %s",
+			          strerror_r(errno, buf, 128));
+			return -1;
+		}
 	}
 #else
-#	error BLKROGET not available
+#error BLKROGET not available
 #endif
 
 #ifdef BLKGETSIZE64




More information about the fedora-extras-commits mailing list