From 76ac602c3d79bb39c133c81a38425a77bc0b8b1f Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Sat, 25 Nov 2023 02:13:22 -0800 Subject: Some FUSE callbacks, some POSIX interface implementation --- src/disk/inode.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/disk/inode.rs') diff --git a/src/disk/inode.rs b/src/disk/inode.rs index 1095aca..256d2f5 100644 --- a/src/disk/inode.rs +++ b/src/disk/inode.rs @@ -1,11 +1,11 @@ use bitflags::bitflags; use fuser::{FileAttr, FileType}; -use std::fs::File; +use crate::utils; -const DIRECT_NUMBER: usize = 15; +pub const DIRECT_NUMBER: usize = 15; #[derive(Debug, Clone, Copy)] -pub struct InodeMode(u16); +pub struct InodeMode(pub u16); bitflags! { impl InodeMode: u16 { @@ -33,6 +33,34 @@ bitflags! { } impl InodeMode { + pub(crate) fn exec_other(&self) -> bool { + self.0 & Self::IXOTH.0 != 0 + } + pub(crate) fn write_other(&self) -> bool { + self.0 & Self::IWOTH.0 != 0 + } + pub(crate) fn read_other(&self) -> bool { + self.0 & Self::IROTH.0 != 0 + } + pub(crate) fn exec_group(&self) -> bool { + self.0 & Self::IXGRP.0 != 0 + } + pub(crate) fn write_group(&self) -> bool { + self.0 & Self::IWGRP.0 != 0 + } + pub(crate) fn read_group(&self) -> bool { + self.0 & Self::IRGRP.0 != 0 + } + pub(crate) fn exec_user(&self) -> bool { + self.0 & Self::IXUSR.0 != 0 + } + pub(crate) fn write_user(&self) -> bool { + self.0 & Self::IWUSR.0 != 0 + } + pub(crate) fn read_user(&self) -> bool { + self.0 & Self::IRUSR.0 != 0 + } + pub(crate) fn perm(&self) -> u16 { self.0 & 0x0FFF } @@ -69,6 +97,13 @@ impl From for FileType { } } +impl From for u8 { + fn from(value: InodeMode) -> Self { + utils::from_filetype(value.into()) + } +} + + /// Pretty much the same with ext2, with minor changes: /// - removed OS dependent attributes (osd1 & osd2) /// - removed i_faddr since fragmentation is not supported -- cgit v1.2.3-70-g09d2