vfs: FsNode::new()

This commit is contained in:
TheOddGarlic 2022-08-03 19:45:04 +03:00
parent 52ff9f8a3c
commit 9ed5ffc521

View file

@ -41,8 +41,24 @@ pub struct FsNode {
} }
impl FsNode { impl FsNode {
pub fn new(
flags: FsNodeFlags,
length: u32,
inode: u32,
device_handle: Handle,
ptr: Weak<FsNode>,
) -> Self {
Self {
flags,
length,
inode,
device_handle,
ptr,
}
}
// TODO: make this take flags // TODO: make this take flags
fn open(&self) -> Result<Handle> { pub fn open(&self) -> Result<Handle> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)
@ -51,7 +67,7 @@ impl FsNode {
device.open(self) device.open(self)
} }
fn close(&self) -> Result<()> { pub fn close(&self) -> Result<()> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)
@ -60,7 +76,7 @@ impl FsNode {
device.close(self) device.close(self)
} }
fn read(&self, offset: u32, size: u32) -> Result<Box<[u8]>> { pub fn read(&self, offset: u32, size: u32) -> Result<Box<[u8]>> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)
@ -69,7 +85,7 @@ impl FsNode {
device.read(self, offset, size) device.read(self, offset, size)
} }
fn write(&self, offset: u32, buffer: Box<[u8]>) -> Result<()> { pub fn write(&self, offset: u32, buffer: Box<[u8]>) -> Result<()> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)
@ -78,7 +94,7 @@ impl FsNode {
device.write(self, offset, buffer) device.write(self, offset, buffer)
} }
fn read_dir(&self, index: u32) -> Result<DirectoryEntry> { pub fn read_dir(&self, index: u32) -> Result<DirectoryEntry> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)
@ -87,7 +103,7 @@ impl FsNode {
device.read_dir(self, index) device.read_dir(self, index)
} }
fn find_dir(&self, name: &str) -> Result<FsNode> { pub fn find_dir(&self, name: &str) -> Result<FsNode> {
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
let device = state let device = state
.get_storage_device(self.device_handle) .get_storage_device(self.device_handle)