Skip to content

Commit

Permalink
mount: Fall back to read-only on -EROFS
Browse files Browse the repository at this point in the history
this is the mount helper's job, and since we're the mount helper...

fixes: xfstests generic/050

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Jul 20, 2024
1 parent 60ff4f2 commit 59ccde4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/commands/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn mount_inner(
src: String,
target: impl AsRef<std::path::Path>,
fstype: &str,
mountflags: libc::c_ulong,
mut mountflags: libc::c_ulong,
data: Option<String>,
) -> anyhow::Result<()> {
// bind the CStrings to keep them alive
Expand All @@ -38,11 +38,23 @@ fn mount_inner(
let data = data.map_or(ptr::null(), |data| data.as_ptr().cast());
let fstype = fstype.as_ptr();

let ret = {
info!("mounting filesystem");
// REQUIRES: CAP_SYS_ADMIN
unsafe { libc::mount(src, target, fstype, mountflags, data) }
};
let mut ret;
loop {
ret = {
info!("mounting filesystem");
// REQUIRES: CAP_SYS_ADMIN
unsafe { libc::mount(src, target, fstype, mountflags, data) }
};

let err = errno::errno().0;

if ret == 0 || (err != libc::EACCES && err != libc::EROFS) || (mountflags & libc::MS_RDONLY) != 0 {
break;
}

println!("mount: device write-protected, mounting read-only");
mountflags |= libc::MS_RDONLY;
}
match ret {
0 => Ok(()),
_ => Err(crate::ErrnoError(errno::errno()).into()),
Expand Down

0 comments on commit 59ccde4

Please sign in to comment.