pub trait FileOperations: Send + Sync {
// Required methods
fn open(&self, path: &str, flags: u32) -> Result<Arc<dyn FileHandle>>;
fn read_dir(&self, path: &str) -> Result<Vec<DirectoryEntry>>;
fn create_file(&self, path: &str, file_type: FileType) -> Result<()>;
fn create_dir(&self, path: &str) -> Result<()>;
fn remove(&self, path: &str) -> Result<()>;
fn metadata(&self, path: &str) -> Result<FileMetadata>;
fn root_dir(&self) -> Result<Directory<'_>>;
}
Expand description
Trait defining file operations
Required Methods§
Sourcefn open(&self, path: &str, flags: u32) -> Result<Arc<dyn FileHandle>>
fn open(&self, path: &str, flags: u32) -> Result<Arc<dyn FileHandle>>
Open a file
Sourcefn read_dir(&self, path: &str) -> Result<Vec<DirectoryEntry>>
fn read_dir(&self, path: &str) -> Result<Vec<DirectoryEntry>>
Read directory entries
Sourcefn create_file(&self, path: &str, file_type: FileType) -> Result<()>
fn create_file(&self, path: &str, file_type: FileType) -> Result<()>
Create a file with the specified type.
§Arguments
path
- The path to the file to create.file_type
- The type of file to create. This can be a regular file, a device file, or other supported types.
§Behavior
- Regular Files: These are standard files used for storing data. They are created in the filesystem and can be read from or written to using standard file operations.
- Device Files: These represent hardware devices and are typically used for interacting with device drivers. Creating a device file may involve additional steps, such as associating the file with a specific device driver or hardware resource.
§Side Effects
- Creating a device file may require elevated permissions or specific system configurations.
- If a file already exists at the specified path, the function will return an error of type
FileSystemErrorKind::AlreadyExists
.
§Returns
Result<()>
-Ok
if the file was created successfully, or an error if the operation failed. Errors may includePermissionDenied
,InvalidPath
, orDeviceError
for device files.
Sourcefn create_dir(&self, path: &str) -> Result<()>
fn create_dir(&self, path: &str) -> Result<()>
Create a directory
Sourcefn metadata(&self, path: &str) -> Result<FileMetadata>
fn metadata(&self, path: &str) -> Result<FileMetadata>
Get the metadata