Support mount bind a file
This commit is contained in:
parent
53a1268e19
commit
0a80d55c95
|
|
@ -267,6 +267,18 @@ impl Path {
|
|||
/// Returns `EINVAL` if either source or destination path is not in the
|
||||
/// current mount namespace.
|
||||
pub fn bind_mount_to(&self, dst_path: &Self, recursive: bool, ctx: &Context) -> Result<()> {
|
||||
let can_bind = {
|
||||
let src_is_dir = self.type_() == InodeType::Dir;
|
||||
let dst_is_dir = dst_path.type_() == InodeType::Dir;
|
||||
(src_is_dir && dst_is_dir) || (!src_is_dir && !dst_is_dir)
|
||||
};
|
||||
if !can_bind {
|
||||
return_errno_with_message!(
|
||||
Errno::ENOTDIR,
|
||||
"the source and destination must both be directories or both be non-directories"
|
||||
);
|
||||
}
|
||||
|
||||
let current_ns_proxy = ctx.thread_local.borrow_ns_proxy();
|
||||
let current_mnt_ns = current_ns_proxy.unwrap().mnt_ns();
|
||||
if !current_mnt_ns.owns(&self.mount) {
|
||||
|
|
|
|||
|
|
@ -277,10 +277,6 @@ impl Mount {
|
|||
|
||||
/// Grafts the mount node tree to the mountpoint.
|
||||
pub(super) fn graft_mount_tree(&self, target_path: &Path) -> Result<()> {
|
||||
if target_path.type_() != InodeType::Dir {
|
||||
return_errno!(Errno::ENOTDIR);
|
||||
}
|
||||
|
||||
self.detach_from_parent();
|
||||
self.attach_to_path(target_path);
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -88,10 +88,6 @@ fn do_bind_mount(src_name: CString, dst_path: Path, recursive: bool, ctx: &Conte
|
|||
.lookup(&fs_path)?
|
||||
};
|
||||
|
||||
if src_path.type_() != InodeType::Dir {
|
||||
return_errno_with_message!(Errno::ENOTDIR, "src_name must be directory");
|
||||
};
|
||||
|
||||
src_path.bind_mount_to(&dst_path, recursive, ctx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue