Skip to content

Commit

Permalink
Implement mknodat
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Feb 3, 2020
1 parent c87e93d commit 6b5a148
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fs/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ int generic_symlinkat(const char *target, struct fd *at, const char *link_raw) {
return err;
}

int generic_mknod(const char *path_raw, mode_t_ mode, dev_t_ dev) {
int generic_mknodat(struct fd *at, const char *path_raw, mode_t_ mode, dev_t_ dev) {
if (S_ISDIR(mode) || S_ISLNK(mode))
return _EINVAL;
if (!superuser() && (S_ISBLK(mode) || S_ISCHR(mode)))
return _EPERM;

char path[MAX_PATH];
int err = path_normalize(AT_PWD, path_raw, path, N_SYMLINK_NOFOLLOW | N_PARENT_DIR_WRITE);
int err = path_normalize(at, path_raw, path, N_SYMLINK_NOFOLLOW | N_PARENT_DIR_WRITE);
if (err < 0)
return err;
struct mount *mount = find_mount_and_trim_path(path);
Expand Down
1 change: 1 addition & 0 deletions kernel/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ syscall_t syscall_table[] = {
[291] = (syscall_t) syscall_stub, // inotify_init
[295] = (syscall_t) sys_openat,
[296] = (syscall_t) sys_mkdirat,
[297] = (syscall_t) sys_mknodat,
[298] = (syscall_t) sys_fchownat,
[300] = (syscall_t) sys_fstatat64,
[301] = (syscall_t) sys_unlinkat,
Expand Down
1 change: 1 addition & 0 deletions kernel/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ dword_t sys_renameat2(fd_t src_at_f, addr_t src_addr, fd_t dst_at_f, addr_t dst_
dword_t sys_symlink(addr_t target_addr, addr_t link_addr);
dword_t sys_symlinkat(addr_t target_addr, fd_t at_f, addr_t link_addr);
dword_t sys_mknod(addr_t path_addr, mode_t_ mode, dev_t_ dev);
dword_t sys_mknodat(fd_t at_f, addr_t path_addr, mode_t_ mode, dev_t_ dev);
dword_t sys_access(addr_t path_addr, dword_t mode);
dword_t sys_faccessat(fd_t at_f, addr_t path, mode_t_ mode, dword_t flags);
dword_t sys_readlink(addr_t path, addr_t buf, dword_t bufsize);
Expand Down
13 changes: 10 additions & 3 deletions kernel/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,20 @@ dword_t sys_symlink(addr_t target_addr, addr_t link_addr) {
return sys_symlinkat(target_addr, AT_FDCWD_, link_addr);
}

dword_t sys_mknod(addr_t path_addr, mode_t_ mode, dev_t_ dev) {
dword_t sys_mknodat(fd_t at_f, addr_t path_addr, mode_t_ mode, dev_t_ dev) {
char path[MAX_PATH];
if (user_read_string(path_addr, path, sizeof(path)))
return _EFAULT;
STRACE("mknod(\"%s\", %#x, %#x)", path, mode, dev);
STRACE("mknodat(%d, \"%s\", %#x, %#x)", at_f, path, mode, dev);
apply_umask(&mode);
return generic_mknod(path, mode, dev);
struct fd *at = at_fd(at_f);
if (at == NULL)
return _EBADF;
return generic_mknodat(at, path, mode, dev);
}

dword_t sys_mknod(addr_t path_addr, mode_t_ mode, dev_t_ dev) {
return sys_mknodat(AT_FDCWD_, path_addr, mode, dev);
}

dword_t sys_read(fd_t fd_no, addr_t buf_addr, dword_t size) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int generic_unlinkat(struct fd *at, const char *path);
int generic_rmdirat(struct fd *at, const char *path);
int generic_renameat(struct fd *src_at, const char *src, struct fd *dst_at, const char *dst);
int generic_symlinkat(const char *target, struct fd *at, const char *link);
int generic_mknod(const char *path, mode_t_ mode, dev_t_ dev);
int generic_mknodat(struct fd *at, const char *path, mode_t_ mode, dev_t_ dev);
#define AC_R 4
#define AC_W 2
#define AC_X 1
Expand Down

0 comments on commit 6b5a148

Please sign in to comment.