docs
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ impl Iterator<> for BlockIter {
|
||||
}
|
||||
}
|
||||
|
||||
/// A disk extent
|
||||
/// A disk extent, [wikipedia](https://en.wikipedia.org/wiki/Extent_(file_systems))
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
#[repr(packed)]
|
||||
pub struct Extent {
|
||||
|
||||
@@ -43,6 +43,7 @@ impl<D: Disk> FileSystem<D> {
|
||||
|
||||
/// Create a file system on a disk, with reserved data at the beginning
|
||||
/// Reserved data will be zero padded up to the nearest block
|
||||
/// We need to pass ctime and ctime_nsec in order to initialize the unix timestamps
|
||||
pub fn create_reserved(mut disk: D, reserved: &[u8], ctime: u64, ctime_nsec: u32) -> Result<Self> {
|
||||
let size = disk.size()?;
|
||||
let block_offset = (reserved.len() as u64 + BLOCK_SIZE - 1)/BLOCK_SIZE;
|
||||
@@ -80,6 +81,7 @@ impl<D: Disk> FileSystem<D> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read at a certain spot in the disk, returning data into buffer
|
||||
pub fn read_at(&mut self, block: u64, buffer: &mut [u8]) -> Result<usize> {
|
||||
self.disk.read_at(self.block + block, buffer)
|
||||
}
|
||||
|
||||
@@ -110,19 +110,26 @@ impl Node {
|
||||
self.mode & Node::MODE_TYPE == Node::MODE_SYMLINK
|
||||
}
|
||||
|
||||
/// Tests if UID is the owner of that file, only true when uid=0 or when the UID stored in metadata is equal to the UID you supply
|
||||
pub fn owner(&self, uid: u32) -> bool {
|
||||
uid == 0 || self.uid == uid
|
||||
}
|
||||
|
||||
/// Tests if the current user has enough permissions to view the file, op is the operation,
|
||||
/// like read and write, these modes are MODE_EXEC, MODE_READ, and MODE_WRITE
|
||||
pub fn permission(&self, uid: u32, gid: u32, op: u16) -> bool {
|
||||
let mut perm = self.mode & 0o7;
|
||||
if self.uid == uid {
|
||||
// If self.mode is 101100110, >> 6 would be 000000101
|
||||
// 0o7 is octal for 111, or, when expanded to 9 digits is 000000111
|
||||
perm |= (self.mode >> 6) & 0o7;
|
||||
// Since we erased the GID and OTHER bits when >>6'ing, |= will keep those bits in place.
|
||||
}
|
||||
if self.gid == gid || gid == 0 {
|
||||
perm |= (self.mode >> 3) & 0o7;
|
||||
}
|
||||
if uid == 0 {
|
||||
//set the `other` bits to 111
|
||||
perm |= 0o7;
|
||||
}
|
||||
perm & op == op
|
||||
|
||||
Reference in New Issue
Block a user