CharDeviceFile

Struct CharDeviceFile 

Source
pub struct CharDeviceFile {
    pub dentry: Arc<Dentry>,
    pub inode: Arc<dyn Inode>,
    dev: u64,
    driver: Option<Arc<dyn Driver>>,
    pub flags: OpenFlags,
    offset: SpinLock<usize>,
    termios: SpinLock<Termios>,
    winsize: SpinLock<WinSize>,
}
Expand description

字符设备文件

Fields§

§dentry: Arc<Dentry>

关联的 dentry

§inode: Arc<dyn Inode>

关联的 inode

§dev: u64

设备号

§driver: Option<Arc<dyn Driver>>

设备驱动(缓存)

§flags: OpenFlags

打开标志位

§offset: SpinLock<usize>

偏移量(某些字符设备可能需要)

§termios: SpinLock<Termios>

终端属性(用于 TTY 设备)

§winsize: SpinLock<WinSize>

终端窗口大小(用于 TTY 设备)

Implementations§

Source§

impl CharDeviceFile

Source

pub fn new(dentry: Arc<Dentry>, flags: OpenFlags) -> Result<Self, FsError>

创建新的字符设备文件

§参数
  • dentry: 设备文件的 dentry
  • flags: 打开标志
§返回
  • Ok(CharDeviceFile): 成功
  • Err(FsError::NoDevice): 找不到对应的驱动
Source

fn mem_device_read(&self, buf: &mut [u8]) -> Result<usize, FsError>

处理内存设备的读操作

Source

fn mem_device_write(&self, buf: &[u8]) -> Result<usize, FsError>

处理内存设备的写操作

Source§

impl CharDeviceFile

Source

fn console_ioctl(&self, request: u32, arg: usize) -> Result<isize, FsError>

控制台设备 ioctl 处理

Source

fn misc_ioctl(&self, request: u32, arg: usize) -> Result<isize, FsError>

MISC 设备 ioctl 处理

Trait Implementations§

Source§

impl File for CharDeviceFile

Source§

fn readable(&self) -> bool

检查文件是否可读
Source§

fn writable(&self) -> bool

检查文件是否可写
Source§

fn read(&self, buf: &mut [u8]) -> Result<usize, FsError>

从文件读取数据 Read more
Source§

fn write(&self, buf: &[u8]) -> Result<usize, FsError>

向文件写入数据 Read more
Source§

fn metadata(&self) -> Result<InodeMetadata, FsError>

获取文件元数据
Source§

fn lseek(&self, offset: isize, whence: SeekWhence) -> Result<usize, FsError>

设置文件偏移量(可选方法) Read more
Source§

fn offset(&self) -> usize

获取当前偏移量(可选方法) Read more
Source§

fn flags(&self) -> OpenFlags

获取打开标志(可选方法) Read more
Source§

fn inode(&self) -> Result<Arc<dyn Inode>, FsError>

获取Inode(可选方法) Read more
Source§

fn dentry(&self) -> Result<Arc<Dentry>, FsError>

获取目录项(可选方法) Read more
Source§

fn ioctl(&self, request: u32, arg: usize) -> Result<isize, FsError>

执行设备特定的控制操作(可选方法,用于 ioctl) Read more
Source§

fn as_any(&self) -> &dyn Any

获取 Any trait 引用,用于安全的类型转换
Source§

fn set_status_flags(&self, _flags: OpenFlags) -> Result<(), FsError>

设置文件状态标志(可选方法,用于 F_SETFL) Read more
Source§

fn get_pipe_size(&self) -> Result<usize, FsError>

获取管道大小(可选方法,用于 F_GETPIPE_SZ) Read more
Source§

fn set_pipe_size(&self, _size: usize) -> Result<(), FsError>

设置管道大小(可选方法,用于 F_SETPIPE_SZ) Read more
Source§

fn get_owner(&self) -> Result<i32, FsError>

获取异步 I/O 所有者(可选方法,用于 F_GETOWN) Read more
Source§

fn set_owner(&self, _pid: i32) -> Result<(), FsError>

设置异步 I/O 所有者(可选方法,用于 F_SETOWN) Read more
Source§

fn read_at(&self, _offset: usize, _buf: &mut [u8]) -> Result<usize, FsError>

从指定位置读取数据(可选方法,用于 pread64/preadv) Read more
Source§

fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize, FsError>

向指定位置写入数据(可选方法,用于 pwrite64/pwritev) Read more
Source§

fn recvfrom(&self, _buf: &mut [u8]) -> Result<(usize, Option<Vec<u8>>), FsError>

从socket接收数据并获取源地址(可选方法,用于recvfrom) Read more

Auto Trait Implementations§

§

impl !Freeze for CharDeviceFile

§

impl !RefUnwindSafe for CharDeviceFile

§

impl Send for CharDeviceFile

§

impl Sync for CharDeviceFile

§

impl Unpin for CharDeviceFile

§

impl !UnwindSafe for CharDeviceFile

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.