1
1
mirror of https://github.com/mgree/ffs.git synced 2024-09-11 11:15:48 +03:00
This commit is contained in:
Michael Greenberg 2021-06-14 19:54:04 -04:00
parent b34d86c3de
commit d8dfe960c8
3 changed files with 101 additions and 7 deletions

View File

@ -85,6 +85,7 @@ for examples of external dependency installation.
# TODO
- [x] `ListDirectory` (need element names, otherwise basically the same)
- [ ] Settable mode
- [ ] Filenames
+ [x] Check on validity of filenames/fieldnames
+ [ ] Options for naming of ListDirectory elements
@ -96,13 +97,14 @@ for examples of external dependency installation.
+ [ ] Quiet mode
- [ ] Writable FS
+ [ ] rename
+ [x] write
+ [ ] rmdir
+ [ ] fsync
+ [ ] fallocate
+ [ ] access
+ [ ] create
+ [ ] copy_file_range
+ [ ] JSON output
- [ ] Output final FS to file at unmount
+ [ ] Choose target
- [ ] Other formats
+ [ ] TOML
+ [ ] XML

View File

@ -74,6 +74,10 @@ impl FS {
inum
}
fn check_access(&self, req: &Request) -> bool {
req.uid() == self.config.uid && req.gid() == self.config.gid
}
fn get(&self, inum: u64) -> Result<&Inode, FSError> {
let idx = inum as usize;
@ -296,7 +300,7 @@ impl Filesystem for FS {
reply: ReplyEntry,
) {
// access control
if req.uid() != self.config.uid || req.gid() != self.config.gid {
if !self.check_access(req) {
reply.error(libc::EACCES);
return;
}
@ -382,9 +386,7 @@ impl Filesystem for FS {
if mode != 0o755 {
warn!("Given mode {:o}, using 755", mode);
}
// access control
if req.uid() != self.config.uid || req.gid() != self.config.gid {
if !self.check_access(req) {
reply.error(libc::EACCES);
return;
}
@ -442,7 +444,7 @@ impl Filesystem for FS {
fn write(
&mut self,
_req: &Request<'_>,
req: &Request,
ino: u64,
_fh: u64,
offset: i64,
@ -454,6 +456,12 @@ impl Filesystem for FS {
) {
assert!(offset >= 0);
// access control
if !self.check_access(req) {
reply.error(libc::EACCES);
return;
}
// find inode
let file = match self.get_mut(ino) {
Err(_e) => {
@ -485,6 +493,45 @@ impl Filesystem for FS {
reply.written(data.len() as u32);
}
fn unlink(&mut self, req: &Request, parent: u64, name: &OsStr, reply: ReplyEmpty) {
// access control
if !self.check_access(req) {
reply.error(libc::EACCES);
return;
}
// get the filename
let filename = match name.to_str() {
None => {
reply.error(libc::ENOENT);
return;
}
Some(name) => name,
};
// find the parent
let files = match self.get_mut(parent) {
Err(_e) => {
reply.error(libc::ENOENT);
return;
}
Ok(Inode { entry: Entry::Directory(_dirtype, files), .. }) => {
files
}
Ok(Inode { entry: Entry::File(_), .. }) => {
reply.error(libc::ENOTDIR);
return;
}
};
// try to remove it
if files.remove(filename).is_some() {
reply.ok();
} else {
reply.error(libc::ENOENT);
}
}
// TODO
fn rename(
&mut self,

45
tests/unlink.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
fail() {
echo FAILED: $1
if [ "$MNT" ]
then
cd
umount "$MNT"
rmdir "$MNT"
fi
exit 1
}
MNT=$(mktemp -d)
ffs "$MNT" ../json/object.json &
PID=$!
sleep 2
cd "$MNT"
case $(ls) in
(eyes*fingernails*human*name) ;;
(*) fail ls;;
esac
[ "$(cat name)" = "Michael Greenberg" ] || fail name
[ "$(cat eyes)" -eq 2 ] || fail eyes
[ "$(cat fingernails)" -eq 10 ] || fail fingernails
[ "$(cat human)" = "true" ] || fail human1
rm human
case $(ls) in
(eyes*fingernails*name) ;;
(*) fail ls2;;
esac
echo false >human
case $(ls) in
(eyes*fingernails*human*name) ;;
(*) fail ls3;;
esac
[ "$(cat human)" = "true" ] || fail human2
cd - >/dev/null 2>&1
umount "$MNT" || fail unmount
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process
rmdir "$MNT" || fail mount