From 7b6672a33c92a4e8447c6a23da5c074d4f66ce92 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 31 May 2021 13:49:20 +0900 Subject: [PATCH] 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 Auto-Submit: Jiyong Park Tested-by: kokoro Commit-Queue: Victor Hsieh --- fuse/src/mount.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fuse/src/mount.rs b/fuse/src/mount.rs index 66276d4d4e..427f696703 100644 --- a/fuse/src/mount.rs +++ b/fuse/src/mount.rs @@ -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"),]) + ); } }