From 16e75679085458276605dc372f4962bae94e4f13 Mon Sep 17 00:00:00 2001 From: klhowell Date: Tue, 12 Oct 2021 08:15:05 -0400 Subject: [PATCH] When creating a read-only loopdev, do not request write access to the backing file. (#43) --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9c12b7d..1d071de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -193,9 +193,10 @@ impl LoopDevice { backing_file: impl AsRef, info: loop_info64, ) -> io::Result<()> { + let write_access = (info.lo_flags & LO_FLAGS_READ_ONLY) == 0; let bf = OpenOptions::new() .read(true) - .write(true) + .write(write_access) .open(backing_file)?; self.attach_fd_with_loop_info(bf, info) }