Skip to content

Commit 16e7567

Browse files
authored
When creating a read-only loopdev, do not request write access to the backing file. (mdaffin#43)
1 parent 5e7cbb3 commit 16e7567

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ impl LoopDevice {
193193
backing_file: impl AsRef<Path>,
194194
info: loop_info64,
195195
) -> io::Result<()> {
196+
let write_access = (info.lo_flags & LO_FLAGS_READ_ONLY) == 0;
196197
let bf = OpenOptions::new()
197198
.read(true)
198-
.write(true)
199+
.write(write_access)
199200
.open(backing_file)?;
200201
self.attach_fd_with_loop_info(bf, info)
201202
}

0 commit comments

Comments
 (0)