Implement dummy metadata() for epoll and socket files

This commit is contained in:
Shaowei Song
2024-10-30 03:42:01 +00:00
committed by Tate, Hongliang Tian
parent 3461bd5de6
commit 96a153dfc5
8 changed files with 78 additions and 9 deletions

View File

@ -12,7 +12,10 @@ use ostd::sync::LocalIrqDisabled;
use super::*; use super::*;
use crate::{ use crate::{
events::Observer, events::Observer,
fs::{file_handle::FileLike, utils::IoctlCmd}, fs::{
file_handle::FileLike,
utils::{InodeMode, IoctlCmd, Metadata},
},
process::signal::{Pollable, Pollee, Poller}, process::signal::{Pollable, Pollee, Poller},
}; };
@ -341,7 +344,6 @@ impl Pollable for EpollFile {
} }
} }
// Implement the common methods required by FileHandle
impl FileLike for EpollFile { impl FileLike for EpollFile {
fn read(&self, _writer: &mut VmWriter) -> Result<usize> { fn read(&self, _writer: &mut VmWriter) -> Result<usize> {
return_errno_with_message!(Errno::EINVAL, "epoll files do not support read"); return_errno_with_message!(Errno::EINVAL, "epoll files do not support read");
@ -370,6 +372,16 @@ impl FileLike for EpollFile {
) -> Option<Weak<dyn Observer<IoEvents>>> { ) -> Option<Weak<dyn Observer<IoEvents>>> {
self.pollee.unregister_observer(observer) self.pollee.unregister_observer(observer)
} }
fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "anonymous inode fs" and link `EpollFile` to it.
Metadata::new_file(
0,
InodeMode::from_bits_truncate(0o600),
aster_block::BLOCK_SIZE,
)
}
} }
/// An epoll entry that is contained in an epoll file. /// An epoll entry that is contained in an epoll file.

View File

@ -54,9 +54,8 @@ pub trait FileLike: Pollable + Send + Sync + Any {
return_errno_with_message!(Errno::EINVAL, "resize is not supported"); return_errno_with_message!(Errno::EINVAL, "resize is not supported");
} }
fn metadata(&self) -> Metadata { /// Get the metadata that describes this file.
panic!("metadata unsupported"); fn metadata(&self) -> Metadata;
}
fn mode(&self) -> Result<InodeMode> { fn mode(&self) -> Result<InodeMode> {
return_errno_with_message!(Errno::EINVAL, "mode is not supported"); return_errno_with_message!(Errno::EINVAL, "mode is not supported");

View File

@ -84,6 +84,8 @@ impl FileLike for PipeReader {
} }
fn metadata(&self) -> Metadata { fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "PipeFS" and link `PipeReader` to it.
let now = RealTimeCoarseClock::get().read_time(); let now = RealTimeCoarseClock::get().read_time();
Metadata { Metadata {
dev: 0, dev: 0,
@ -166,6 +168,8 @@ impl FileLike for PipeWriter {
} }
fn metadata(&self) -> Metadata { fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "PipeFS" and link `PipeWriter` to it.
let now = RealTimeCoarseClock::get().read_time(); let now = RealTimeCoarseClock::get().read_time();
Metadata { Metadata {
dev: 0, dev: 0,

View File

@ -9,7 +9,10 @@ use self::{bound::BoundDatagram, unbound::UnboundDatagram};
use super::{common::get_ephemeral_endpoint, UNSPECIFIED_LOCAL_ENDPOINT}; use super::{common::get_ephemeral_endpoint, UNSPECIFIED_LOCAL_ENDPOINT};
use crate::{ use crate::{
events::{IoEvents, Observer}, events::{IoEvents, Observer},
fs::{file_handle::FileLike, utils::StatusFlags}, fs::{
file_handle::FileLike,
utils::{InodeMode, Metadata, StatusFlags},
},
match_sock_option_mut, match_sock_option_mut,
net::{ net::{
iface::poll_ifaces, iface::poll_ifaces,
@ -271,6 +274,16 @@ impl FileLike for DatagramSocket {
) -> Option<Weak<dyn Observer<IoEvents>>> { ) -> Option<Weak<dyn Observer<IoEvents>>> {
self.pollee.unregister_observer(observer) self.pollee.unregister_observer(observer)
} }
fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "SockFS" and link `DatagramSocket` to it.
Metadata::new_socket(
0,
InodeMode::from_bits_truncate(0o140777),
aster_block::BLOCK_SIZE,
)
}
} }
impl Socket for DatagramSocket { impl Socket for DatagramSocket {

View File

@ -15,7 +15,10 @@ use util::TcpOptionSet;
use super::UNSPECIFIED_LOCAL_ENDPOINT; use super::UNSPECIFIED_LOCAL_ENDPOINT;
use crate::{ use crate::{
events::{IoEvents, Observer}, events::{IoEvents, Observer},
fs::{file_handle::FileLike, utils::StatusFlags}, fs::{
file_handle::FileLike,
utils::{InodeMode, Metadata, StatusFlags},
},
match_sock_option_mut, match_sock_option_ref, match_sock_option_mut, match_sock_option_ref,
net::{ net::{
iface::poll_ifaces, iface::poll_ifaces,
@ -428,6 +431,16 @@ impl FileLike for StreamSocket {
) -> Option<Weak<dyn Observer<IoEvents>>> { ) -> Option<Weak<dyn Observer<IoEvents>>> {
self.pollee.unregister_observer(observer) self.pollee.unregister_observer(observer)
} }
fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "SockFS" and link `StreamSocket` to it.
Metadata::new_socket(
0,
InodeMode::from_bits_truncate(0o140777),
aster_block::BLOCK_SIZE,
)
}
} }
impl Socket for StreamSocket { impl Socket for StreamSocket {

View File

@ -11,7 +11,10 @@ use super::{
}; };
use crate::{ use crate::{
events::{IoEvents, Observer}, events::{IoEvents, Observer},
fs::{file_handle::FileLike, utils::StatusFlags}, fs::{
file_handle::FileLike,
utils::{InodeMode, Metadata, StatusFlags},
},
net::socket::{ net::socket::{
unix::UnixSocketAddr, unix::UnixSocketAddr,
util::{send_recv_flags::SendRecvFlags, socket_addr::SocketAddr, MessageHeader}, util::{send_recv_flags::SendRecvFlags, socket_addr::SocketAddr, MessageHeader},
@ -213,6 +216,16 @@ impl FileLike for UnixStreamSocket {
State::Connected(connected) => connected.unregister_observer(observer), State::Connected(connected) => connected.unregister_observer(observer),
} }
} }
fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "SockFS" and link `UnixStreamSocket` to it.
Metadata::new_socket(
0,
InodeMode::from_bits_truncate(0o140777),
aster_block::BLOCK_SIZE,
)
}
} }
impl Socket for UnixStreamSocket { impl Socket for UnixStreamSocket {

View File

@ -5,7 +5,10 @@ use core::sync::atomic::{AtomicBool, Ordering};
use super::{connected::Connected, connecting::Connecting, init::Init, listen::Listen}; use super::{connected::Connected, connecting::Connecting, init::Init, listen::Listen};
use crate::{ use crate::{
events::IoEvents, events::IoEvents,
fs::{file_handle::FileLike, utils::StatusFlags}, fs::{
file_handle::FileLike,
utils::{InodeMode, Metadata, StatusFlags},
},
net::socket::{ net::socket::{
vsock::{addr::VsockSocketAddr, VSOCK_GLOBAL}, vsock::{addr::VsockSocketAddr, VSOCK_GLOBAL},
MessageHeader, SendRecvFlags, SockShutdownCmd, Socket, SocketAddr, MessageHeader, SendRecvFlags, SockShutdownCmd, Socket, SocketAddr,
@ -171,6 +174,16 @@ impl FileLike for VsockStreamSocket {
} }
Ok(()) Ok(())
} }
fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "SockFS" and link `VsockStreamSocket` to it.
Metadata::new_socket(
0,
InodeMode::from_bits_truncate(0o140777),
aster_block::BLOCK_SIZE,
)
}
} }
impl Socket for VsockStreamSocket { impl Socket for VsockStreamSocket {

View File

@ -262,6 +262,8 @@ impl FileLike for EventFile {
} }
fn metadata(&self) -> Metadata { fn metadata(&self) -> Metadata {
// This is a dummy implementation.
// TODO: Add "anonymous inode fs" and link `EventFile` to it.
let now = RealTimeClock::get().read_time(); let now = RealTimeClock::get().read_time();
Metadata { Metadata {
dev: 0, dev: 0,