kernel/object/capability/stream/mod.rs
1//! Stream operations capability module
2//!
3//! This module provides system calls and traits for StreamOps capability,
4//! which enables read and write operations on KernelObjects.
5
6use crate::fs::FileSystemError;
7use alloc::string::String;
8
9pub mod syscall;
10
11pub use syscall::{sys_stream_read, sys_stream_write};
12
13/// Represents errors that can occur during stream I/O operations
14#[derive(Debug, Clone)]
15pub enum StreamError {
16 /// I/O error occurred
17 IoError,
18 /// End of stream reached (EOF for reads)
19 EndOfStream,
20 /// Operation would block (for non-blocking streams)
21 WouldBlock,
22 /// Stream was closed or is invalid
23 Closed,
24 /// Invalid arguments provided (e.g., null buffer, invalid offset)
25 InvalidArgument,
26 /// Operation interrupted by signal
27 Interrupted,
28 /// Permission denied for this operation
29 PermissionDenied,
30 /// Device-specific error
31 DeviceError,
32 /// Operation not supported by this stream type
33 NotSupported,
34 /// No space left for write operations
35 NoSpace,
36 /// Broken pipe/connection
37 BrokenPipe,
38 /// Seek operation failed
39 SeekError,
40 /// FileSystemError
41 FileSystemError(FileSystemError),
42 /// Generic error with custom message
43 Other(String),
44}
45
46impl From<FileSystemError> for StreamError {
47 fn from(fs_err: FileSystemError) -> Self {
48 StreamError::FileSystemError(fs_err)
49 }
50}
51
52/// Stream operations capability
53///
54/// This trait represents the ability to perform stream-like operations
55/// such as read, write, and seek on a resource.
56pub trait StreamOps: Send + Sync {
57 /// Read data from the stream
58 fn read(&self, buffer: &mut [u8]) -> Result<usize, StreamError>;
59
60 /// Write data to the stream
61 fn write(&self, buffer: &[u8]) -> Result<usize, StreamError>;
62}