diff --git a/src/extent.rs b/src/extent.rs index 773d7acca6eb177dcee60b7797cdc64222cddb65..517faf3bf2c81a7d56d6e8b0835f7e6b80d94b7d 100644 --- a/src/extent.rs +++ b/src/extent.rs @@ -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 { diff --git a/src/filesystem.rs b/src/filesystem.rs index 5be7cdee61dac2b02a20d4eeb170e5b72c2b66b4..1e7996631a838a596289e8273d6f66afce45da45 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -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) } diff --git a/src/node.rs b/src/node.rs index 1ae66c1ed77d439d7b30955ffc1e1862ee16c1dc..f8b257ca9f68204cc8e671d22e0b78f5ed586039 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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