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
3 changes: 3 additions & 0 deletions fs/vfs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ int sys_link(char *oldpath, char *newpath);
int sys_unlink(char *path);
int sys_symlink(const char *oldpath, const char *newpath);
int sys_access(char *path, int mode);

/* inotify VFS notification hook (libc/inotify.cc). */
void osv_inotify_notify(const char *path, uint32_t mask, int is_dir);
int sys_stat(char *path, struct stat *st);
int sys_lstat(char *path, struct stat *st);
int sys_statfs(char *path, struct statfs *buf);
Expand Down
24 changes: 24 additions & 0 deletions fs/vfs/vfs_syscalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <sys/stat.h>
#include <dirent.h>
#include <sys/inotify.h>

#include <limits.h>
#include <unistd.h>
Expand Down Expand Up @@ -141,6 +142,7 @@ sys_open(char *path, int flags, mode_t mode, struct file **fpp)

if (error)
return error;
osv_inotify_notify(path, IN_CREATE, 0);
if ((error = namei(path, &dp)) != 0)
return error;

Expand Down Expand Up @@ -568,6 +570,9 @@ sys_mkdir(char *path, mode_t mode)
mode |= S_IFDIR;

error = VOP_MKDIR(ddp->d_vnode, name, mode);
if (!error) {
osv_inotify_notify(path, IN_CREATE, 1);
}
out:
vn_unlock(ddp->d_vnode);
drele(ddp);
Expand Down Expand Up @@ -609,6 +614,9 @@ sys_rmdir(char *path)
error = VOP_RMDIR(ddp->d_vnode, vp, name);
vn_unlock(ddp->d_vnode);

if (!error) {
osv_inotify_notify(path, IN_DELETE, 1);
}
vn_unlock(vp);
dentry_remove(dp);
drele(ddp);
Expand Down Expand Up @@ -824,6 +832,19 @@ sys_rename(char *src, char *dest)

error = VOP_RENAME(dvp1, vp1, sname, dvp2, vp2, dname);

if (!error) {
int is_dir = (vp1->v_type == VDIR) ? 1 : 0;
// `src` is still the full source path, but `dest` was truncated to its
// parent above (*dname was NUL'd), so rebuild the full dest path.
char full_dest[PATH_MAX];
if (dest[0] == '/' && dest[1] == '\0') {
snprintf(full_dest, sizeof(full_dest), "/%s", dname);
} else {
snprintf(full_dest, sizeof(full_dest), "%s/%s", dest, dname);
}
osv_inotify_notify(src, IN_MOVED_FROM, is_dir);
osv_inotify_notify(full_dest, IN_MOVED_TO, is_dir);
}
dentry_move(dp1, ddp2, dname);
if (dp2)
dentry_remove(dp2);
Expand Down Expand Up @@ -1016,6 +1037,9 @@ sys_unlink(char *path)
error = VOP_REMOVE(ddp->d_vnode, vp, name);
vn_unlock(ddp->d_vnode);

if (!error) {
osv_inotify_notify(path, IN_DELETE, 0);
}
vn_unlock(vp);
dentry_remove(dp);
drele(ddp);
Expand Down
Loading