fuse: support general mount options

MountOption::Extra is added to pass mount options that are not specific
to FUSE, such as fscontext.

BUG=b:189096565
TEST=cargo test

Change-Id: I27f720a028a6133339d03cba6ed473a63c74edab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2927178
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Jiyong Park <jiyong@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
This commit is contained in:
Jiyong Park 2021-05-31 13:49:20 +09:00 committed by Commit Bot
parent a2c71de3a3
commit 7b6672a33c

View file

@ -11,7 +11,7 @@ use std::os::unix::io::RawFd;
/// Mount options to pass to mount(2) for a FUSE filesystem. See the [official document](
/// https://www.kernel.org/doc/html/latest/filesystems/fuse.html#mount-options) for the
/// descriptions.
pub enum MountOption {
pub enum MountOption<'a> {
FD(RawFd),
RootMode(u32),
UserId(libc::uid_t),
@ -20,10 +20,13 @@ pub enum MountOption {
AllowOther,
MaxRead(u32),
BlockSize(u32),
// General mount options that are not specific to FUSE. Note that the value is not checked
// or interpreted by this library, but by kernel.
Extra(&'a str),
}
// Implement Display for ToString to convert to actual mount options.
impl fmt::Display for MountOption {
impl<'a> fmt::Display for MountOption<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
MountOption::FD(fd) => write!(f, "fd={}", fd),
@ -34,6 +37,7 @@ impl fmt::Display for MountOption {
MountOption::AllowOther => write!(f, "allow_other"),
MountOption::MaxRead(size) => write!(f, "max_read={}", size),
MountOption::BlockSize(size) => write!(f, "blksize={}", size),
MountOption::Extra(text) => write!(f, "{}", text),
}
}
}
@ -122,5 +126,10 @@ mod tests {
MountOption::MaxRead(4096),
])
);
assert_eq!(
"option1=a,option2=b".to_string(),
join_mount_options(&[MountOption::Extra("option1=a,option2=b"),])
);
}
}