-
Notifications
You must be signed in to change notification settings - Fork 75
Mount syscall #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arihant2math
wants to merge
3
commits into
hexagonal-sun:master
Choose a base branch
from
arihant2math:mount
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mount syscall #196
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use crate::fs::VFS; | ||
| use crate::memory::uaccess::cstr::UserCStr; | ||
| use crate::sched::current::current_task_shared; | ||
| use bitflags::bitflags; | ||
| use core::ffi::c_char; | ||
| use libkernel::error::{KernelError, Result}; | ||
| use libkernel::fs::path::Path; | ||
| use libkernel::memory::address::{TUA, UA}; | ||
|
|
||
| bitflags! { | ||
| #[derive(Debug)] | ||
| pub struct MountFlags: u64 { | ||
| const MS_RDONLY = 1; | ||
| const MS_NOSUID = 2; | ||
| const MS_NODEV = 4; | ||
| const MS_NOEXEC = 8; | ||
| const MS_SYNCHRONOUS = 16; | ||
| const MS_REMOUNT = 32; | ||
| const MS_MANDLOCK = 64; | ||
| const MS_DIRSYNC = 128; | ||
| const NOSYMFOLLOW = 256; | ||
| const MS_NOATIME = 1024; | ||
| const MS_NODIRATIME = 2048; | ||
| const MS_BIND = 4096; | ||
| const MS_MOVE = 8192; | ||
| const MS_REC = 16384; | ||
| const MS_VERBOSE = 32768; | ||
| const MS_SILENT = 65536; | ||
| const MS_POSIXACL = 1 << 16; | ||
| const MS_UNBINDABLE = 1 << 17; | ||
| const MS_PRIVATE = 1 << 18; | ||
| const MS_SLAVE = 1 << 19; | ||
| const MS_SHARED = 1 << 20; | ||
| const MS_RELATIME = 1 << 21; | ||
| const MS_KERNMOUNT = 1 << 22; | ||
| const MS_I_VERSION = 1 << 23; | ||
| const MS_STRICTATIME = 1 << 24; | ||
| const MS_LAZYTIME = 1 << 25; | ||
| const MS_SUBMOUNT = 1 << 26; | ||
| const MS_NOREMOTELOCK = 1 << 27; | ||
| const MS_NOSEC = 1 << 28; | ||
| const MS_BORN = 1 << 29; | ||
| const MS_ACTIVE = 1 << 30; | ||
| const MS_NOUSER = 1 << 31; | ||
| } | ||
| } | ||
|
|
||
| pub async fn sys_mount( | ||
| dev_name: TUA<c_char>, | ||
| dir_name: TUA<c_char>, | ||
| type_: TUA<c_char>, | ||
| flags: i64, | ||
| _data: UA, | ||
| ) -> Result<usize> { | ||
| let flags = MountFlags::from_bits_truncate(flags as u64); | ||
| if flags.contains(MountFlags::MS_REC) { | ||
| // TODO: Handle later | ||
| return Ok(0); | ||
| } | ||
| let mut buf = [0u8; 1024]; | ||
| let dev_name = if dev_name.is_null() { | ||
| None | ||
| } else { | ||
| Some( | ||
| UserCStr::from_ptr(dev_name) | ||
| .copy_from_user(&mut buf) | ||
| .await?, | ||
| ) | ||
| }; | ||
| let mut buf = [0u8; 1024]; | ||
| let dir_name = UserCStr::from_ptr(dir_name) | ||
| .copy_from_user(&mut buf) | ||
| .await?; | ||
| let mount_point = VFS | ||
| .resolve_path( | ||
| Path::new(dir_name), | ||
| VFS.root_inode(), | ||
| ¤t_task_shared(), | ||
| ) | ||
| .await?; | ||
| let mut buf = [0u8; 1024]; | ||
| let _type = if type_.is_null() { | ||
| None | ||
| } else { | ||
| Some(UserCStr::from_ptr(type_).copy_from_user(&mut buf).await?) | ||
| }; | ||
| if let Some(dev_name) = dev_name { | ||
| let dev_name = match dev_name { | ||
| "proc" => "procfs", | ||
| "devtmpfs" => "devfs", | ||
| "cgroup2" => "cgroupfs", | ||
| s => s, | ||
| }; | ||
| VFS.mount(mount_point, dev_name, None).await?; | ||
| Ok(0) | ||
| } else { | ||
| Err(KernelError::NotSupported) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by the args. According to the man page,
mountlooks like:But the following code looks as though it's inspecting the
sourceargument for the filesystem type. Shouldn't that betype?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the table in
etc/it says:filesystemtype(ortype) isnullwhensystemdcalls this (which was what led to theEFAULTerrors). I've got no clue why systemd calls this API the way does. Perhapssourcecould also be a device file, in which casetypeis used to specify the filesystem type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, odd. I can understand why
typecould be null, you'd read the FS type from/etc/fstab, or inspect the block device to see if any of your FS driver match the magic and try to mount. Odd that it's not specified as nullable in the man page through.