Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions etc/syscalls_linux_aarch64.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
| 0x17 (23) | dup | (unsigned int fildes) | __arm64_sys_dup | true |
| 0x18 (24) | dup3 | (unsigned int oldfd, unsigned int newfd, int flags) | __arm64_sys_dup3 | true |
| 0x19 (25) | fcntl | (unsigned int fd, unsigned int cmd, unsigned long arg) | __arm64_sys_fcntl | true |
| 0x1a (26) | inotify_init1 | (int flags) | __arm64_sys_inotify_init1 | false |
| 0x1b (27) | inotify_add_watch | (int fd, const char *pathname, u32 mask) | __arm64_sys_inotify_add_watch | false |
| 0x1c (28) | inotify_rm_watch | (int fd, __s32 wd) | __arm64_sys_inotify_rm_watch | false |
| 0x1a (26) | inotify_init1 | (int flags) | __arm64_sys_inotify_init1 | true |
| 0x1b (27) | inotify_add_watch | (int fd, const char *pathname, u32 mask) | __arm64_sys_inotify_add_watch | true |
| 0x1c (28) | inotify_rm_watch | (int fd, __s32 wd) | __arm64_sys_inotify_rm_watch | true |
| 0x1d (29) | ioctl | (unsigned int fd, unsigned int cmd, unsigned long arg) | __arm64_sys_ioctl | true |
| 0x1e (30) | ioprio_set | (int which, int who, int ioprio) | __arm64_sys_ioprio_set | false |
| 0x1f (31) | ioprio_get | (int which, int who) | __arm64_sys_ioprio_get | false |
Expand Down
6 changes: 6 additions & 0 deletions src/arch/arm64/exceptions/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use crate::{
fcntl::sys_fcntl,
select::{sys_ppoll, sys_pselect6},
},
inotify::{sys_inotify_add_watch, sys_inotify_init1, sys_inotify_rm_watch},
pidfd::sys_pidfd_open,
prctl::sys_prctl,
ptrace::{TracePoint, ptrace_stop, sys_ptrace},
Expand Down Expand Up @@ -160,6 +161,11 @@ pub async fn handle_syscall(mut ctx: ProcessCtx) {
)
.await
}
0x1a => sys_inotify_init1(&ctx, arg1 as _).await,
0x1b => {
sys_inotify_add_watch(&ctx, arg1.into(), TUA::from_value(arg2 as _), arg3 as _).await
}
0x1c => sys_inotify_rm_watch(&ctx, arg1.into(), arg2 as i32).await,
0x5 => {
sys_setxattr(
&ctx,
Expand Down
4 changes: 4 additions & 0 deletions src/fs/fops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,8 @@ pub trait FileOps: Send + Sync {
) -> Option<&mut crate::process::thread_group::signal::signalfd::SignalFd> {
None
}

fn as_inotify(&mut self) -> Option<&mut crate::process::inotify::Inotify> {
None
}
}
43 changes: 36 additions & 7 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::clock::realtime::date;
use crate::{
drivers::{DM, Driver},
process::Task,
process::{
Task,
inotify::{notify_create, notify_delete, notify_delete_self, notify_modify, notify_move},
},
sync::SpinLock,
};
use alloc::{borrow::ToOwned, boxed::Box, collections::btree_map::BTreeMap, sync::Arc, vec::Vec};
Expand Down Expand Up @@ -377,9 +380,11 @@ impl VFS {
return Err(FsError::NotADirectory.into());
}

parent_inode
let target_inode = parent_inode
.create(file_name, FileType::File, mode, Some(date()))
.await?
.await?;
notify_create(parent_inode.id(), file_name, false).await;
target_inode
} else {
// O_CREAT was not specified, so NotFound is the correct error.
return Err(FsError::NotFound.into());
Expand Down Expand Up @@ -409,6 +414,7 @@ impl VFS {
{
// TODO: Check for write permissions on the inode itself.
target_inode.truncate(0).await?;
notify_modify(target_inode.id()).await;
}

match attr.file_type {
Expand Down Expand Up @@ -485,6 +491,7 @@ impl VFS {
parent_inode
.create(dir_name, FileType::Directory, mode, Some(date()))
.await?;
notify_create(parent_inode.id(), dir_name, true).await;

Ok(())
}
Expand Down Expand Up @@ -547,6 +554,9 @@ impl VFS {
let name = path.file_name().ok_or(FsError::InvalidInput)?;

parent_inode.unlink(name).await?;
let is_dir = attr.file_type == FileType::Directory;
notify_delete(parent_inode.id(), name, is_dir).await;
notify_delete_self(target_inode.id(), is_dir).await;

Ok(())
}
Expand All @@ -558,7 +568,9 @@ impl VFS {
name: &str,
) -> Result<()> {
// just delegate to inode only, all handling is done at the syscall level
new_parent.link(name, target).await
new_parent.link(name, target).await?;
notify_create(new_parent.id(), name, false).await;
Ok(())
}

pub async fn symlink(
Expand All @@ -584,7 +596,9 @@ impl VFS {
return Err(FsError::NotADirectory.into());
}

parent_inode.symlink(name, target).await
parent_inode.symlink(name, target).await?;
notify_create(parent_inode.id(), name, false).await;
Ok(())
}
Err(e) => Err(e),
}
Expand All @@ -598,9 +612,24 @@ impl VFS {
new_name: &str,
no_replace: bool,
) -> Result<()> {
let target_inode = old_parent_inode.lookup(old_name).await?;
let target_attr = target_inode.getattr().await?;

new_parent_inode
.rename_from(old_parent_inode, old_name, new_name, no_replace)
.await
.rename_from(old_parent_inode.clone(), old_name, new_name, no_replace)
.await?;

notify_move(
old_parent_inode.id(),
old_name,
new_parent_inode.id(),
new_name,
target_inode.id(),
target_attr.file_type == FileType::Directory,
)
.await;

Ok(())
}

pub async fn exchange(
Expand Down
9 changes: 8 additions & 1 deletion src/fs/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
page::ClaimedPage,
uaccess::{copy_from_user_slice, copy_to_user_slice},
},
process::inotify::notify_modify,
};
use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
Expand Down Expand Up @@ -88,11 +89,17 @@ impl FileOps for RegFile {
buf = buf.add_bytes(bytes_written);
}

if total_bytes_written > 0 {
notify_modify(self.inode.id()).await;
}

Ok(total_bytes_written)
}

async fn truncate(&mut self, _ctx: &FileCtx, new_size: usize) -> Result<()> {
self.inode.truncate(new_size as _).await
self.inode.truncate(new_size as _).await?;
notify_modify(self.inode.id()).await;
Ok(())
}

fn poll_read_ready(&self) -> Pin<Box<dyn Future<Output = Result<()>> + 'static + Send>> {
Expand Down
3 changes: 2 additions & 1 deletion src/fs/syscalls/at/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ringbuf::Arc;
use crate::{
fs::syscalls::at::{AtFlags, resolve_at_start_node, resolve_path_flags},
memory::uaccess::cstr::UserCStr,
process::{Task, fd_table::Fd},
process::{Task, fd_table::Fd, inotify::notify_attrib},
sched::syscall_ctx::ProcessCtx,
};

Expand Down Expand Up @@ -45,6 +45,7 @@ pub async fn sys_fchmodat(

attr.permissions = mode;
node.setattr(attr).await?;
notify_attrib(node.id()).await;

Ok(0)
}
3 changes: 2 additions & 1 deletion src/fs/syscalls/at/chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use libkernel::{
use crate::{
fs::syscalls::at::{AtFlags, resolve_at_start_node, resolve_path_flags},
memory::uaccess::cstr::UserCStr,
process::fd_table::Fd,
process::{fd_table::Fd, inotify::notify_attrib},
sched::syscall_ctx::ProcessCtx,
};

Expand Down Expand Up @@ -51,6 +51,7 @@ pub async fn sys_fchownat(
}
}
node.setattr(attr).await?;
notify_attrib(node.id()).await;

Ok(0)
}
3 changes: 2 additions & 1 deletion src/fs/syscalls/at/utime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
clock::{realtime::date, timespec::TimeSpec},
fs::syscalls::at::{AtFlags, resolve_at_start_node, resolve_path_flags},
memory::uaccess::{copy_from_user, cstr::UserCStr},
process::fd_table::Fd,
process::{fd_table::Fd, inotify::notify_attrib},
sched::syscall_ctx::ProcessCtx,
};

Expand Down Expand Up @@ -88,6 +88,7 @@ pub async fn sys_utimensat(
}

node.setattr(attr).await?;
notify_attrib(node.id()).await;

Ok(0)
}
Expand Down
6 changes: 5 additions & 1 deletion src/fs/syscalls/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use libkernel::{
fs::attr::FilePermissions,
};

use crate::{process::fd_table::Fd, sched::syscall_ctx::ProcessCtx};
use crate::{
process::{fd_table::Fd, inotify::notify_attrib},
sched::syscall_ctx::ProcessCtx,
};

pub async fn sys_fchmod(ctx: &ProcessCtx, fd: Fd, mode: u16) -> Result<usize> {
let task = ctx.shared().clone();
Expand All @@ -24,6 +27,7 @@ pub async fn sys_fchmod(ctx: &ProcessCtx, fd: Fd, mode: u16) -> Result<usize> {

attr.permissions = permissions;
inode.setattr(attr).await?;
notify_attrib(inode.id()).await;

Ok(0)
}
6 changes: 5 additions & 1 deletion src/fs/syscalls/chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use libkernel::{
},
};

use crate::{process::fd_table::Fd, sched::syscall_ctx::ProcessCtx};
use crate::{
process::{fd_table::Fd, inotify::notify_attrib},
sched::syscall_ctx::ProcessCtx,
};

pub async fn sys_fchown(ctx: &ProcessCtx, fd: Fd, owner: i32, group: i32) -> Result<usize> {
let task = ctx.shared().clone();
Expand Down Expand Up @@ -35,6 +38,7 @@ pub async fn sys_fchown(ctx: &ProcessCtx, fd: Fd, owner: i32, group: i32) -> Res
}
}
inode.setattr(attr).await?;
notify_attrib(inode.id()).await;

Ok(0)
}
3 changes: 2 additions & 1 deletion src/fs/syscalls/setxattr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::fs::VFS;
use crate::memory::uaccess::copy_from_user_slice;
use crate::memory::uaccess::cstr::UserCStr;
use crate::process::fd_table::Fd;
use crate::process::{fd_table::Fd, inotify::notify_attrib};
use crate::sched::syscall_ctx::ProcessCtx;
use alloc::sync::Arc;
use alloc::vec;
Expand Down Expand Up @@ -47,6 +47,7 @@ async fn setxattr(
flags.contains(SetXattrFlags::REPLACE),
)
.await?;
notify_attrib(node.id()).await;
Ok(size)
}

Expand Down
Loading
Loading