mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 10:43:56 +00:00
Refactor DentryMnt and fix some issues
Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
60fa4d104a
commit
8d18a12385
@ -18,9 +18,7 @@ impl PartialEq for UnixSocketAddrBound {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::Abstract(l0), Self::Abstract(r0)) => l0 == r0,
|
||||
(Self::Path(l0), Self::Path(r0)) => {
|
||||
Arc::ptr_eq(l0.dentry().inode(), r0.dentry().inode())
|
||||
}
|
||||
(Self::Path(l0), Self::Path(r0)) => Arc::ptr_eq(l0.inode(), r0.inode()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ impl Init {
|
||||
|
||||
let bound_addr = match addr_to_bind {
|
||||
UnixSocketAddr::Abstract(_) => todo!(),
|
||||
UnixSocketAddr::Path(pathname) => {
|
||||
let dentrymnt = create_socket_file(pathname)?;
|
||||
UnixSocketAddr::Path(path) => {
|
||||
let dentrymnt = create_socket_file(path)?;
|
||||
UnixSocketAddrBound::Path(dentrymnt)
|
||||
}
|
||||
};
|
||||
@ -87,19 +87,18 @@ impl Init {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_socket_file(pathname: &str) -> Result<Arc<DentryMnt>> {
|
||||
let (parent_pathname, file_name) = split_path(pathname);
|
||||
fn create_socket_file(path: &str) -> Result<Arc<DentryMnt>> {
|
||||
let (parent_pathname, file_name) = split_path(path);
|
||||
let parent = {
|
||||
let current = current!();
|
||||
let fs = current.fs().read();
|
||||
let parent_path = FsPath::try_from(parent_pathname)?;
|
||||
fs.lookup(&parent_path)?
|
||||
};
|
||||
let dentry = parent.dentry().create(
|
||||
let dentrymnt = parent.new_fs_child(
|
||||
file_name,
|
||||
InodeType::Socket,
|
||||
InodeMode::S_IRUSR | InodeMode::S_IWUSR,
|
||||
)?;
|
||||
let dentrymnt = DentryMnt::new(parent.mount_node().clone(), dentry.clone());
|
||||
Ok(dentrymnt)
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ impl Backlog {
|
||||
}
|
||||
|
||||
fn create_keyable_inode(dentrymnt: &Arc<DentryMnt>) -> KeyableWeak<dyn Inode> {
|
||||
let weak_inode = Arc::downgrade(dentrymnt.dentry().inode());
|
||||
let weak_inode = Arc::downgrade(dentrymnt.inode());
|
||||
KeyableWeak::from(weak_inode)
|
||||
}
|
||||
|
||||
|
@ -161,8 +161,8 @@ impl Socket for UnixStreamSocket {
|
||||
UnixSocketAddr::Abstract(abstract_name) => {
|
||||
UnixSocketAddrBound::Abstract(abstract_name)
|
||||
}
|
||||
UnixSocketAddr::Path(pathname) => {
|
||||
let dentrymnt = lookup_socket_file(&pathname)?;
|
||||
UnixSocketAddr::Path(path) => {
|
||||
let dentrymnt = lookup_socket_file(&path)?;
|
||||
UnixSocketAddrBound::Path(dentrymnt)
|
||||
}
|
||||
}
|
||||
@ -287,19 +287,19 @@ impl Drop for UnixStreamSocket {
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_socket_file(pathname: &str) -> Result<Arc<DentryMnt>> {
|
||||
fn lookup_socket_file(path: &str) -> Result<Arc<DentryMnt>> {
|
||||
let dentrymnt = {
|
||||
let current = current!();
|
||||
let fs = current.fs().read();
|
||||
let fs_path = FsPath::try_from(pathname)?;
|
||||
let fs_path = FsPath::try_from(path)?;
|
||||
fs.lookup(&fs_path)?
|
||||
};
|
||||
|
||||
if dentrymnt.dentry().type_() != InodeType::Socket {
|
||||
if dentrymnt.type_() != InodeType::Socket {
|
||||
return_errno_with_message!(Errno::ENOTSOCK, "not a socket file")
|
||||
}
|
||||
|
||||
if !dentrymnt.dentry().mode()?.is_readable() || !dentrymnt.dentry().mode()?.is_writable() {
|
||||
if !dentrymnt.mode()?.is_readable() || !dentrymnt.mode()?.is_writable() {
|
||||
return_errno_with_message!(Errno::EACCES, "the socket cannot be read or written")
|
||||
}
|
||||
Ok(dentrymnt)
|
||||
|
Reference in New Issue
Block a user