Skip to content

Commit

Permalink
Fix mkdir syscall issue and implement mkdirat
Browse files Browse the repository at this point in the history
Signed-off-by: David Smith <d7878291@gmail.com>
Message-Id: <20210115133359.119099-1-d7878291@gmail.com>
  • Loading branch information
David Smith authored and nyh committed Jan 18, 2021
1 parent 0a591e0 commit a0761f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions fs/vfs/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,43 @@ mkdir(const char *pathname, mode_t mode)
return -1;
}

int mkdirat(int dirfd, const char *pathname, mode_t mode)
{
mode = apply_umask(mode);

if (pathname[0] == '/' || dirfd == AT_FDCWD) {
// Supplied path is either absolute or relative to cwd
return mkdir(pathname, mode);
}

// Supplied path is relative to folder specified by dirfd
struct file *fp;
int error = fget(dirfd, &fp);
if (error) {
errno = error;
return -1;
}

struct vnode *vp = fp->f_dentry->d_vnode;
vn_lock(vp);

std::unique_ptr<char []> up (new char[PATH_MAX]);
char *p = up.get();

/* build absolute path */
strlcpy(p, fp->f_dentry->d_mount->m_path, PATH_MAX);
strlcat(p, fp->f_dentry->d_path, PATH_MAX);
strlcat(p, "/", PATH_MAX);
strlcat(p, pathname, PATH_MAX);

error = mkdir(p, mode);

vn_unlock(vp);
fdrop(fp);

return error;
}

TRACEPOINT(trace_vfs_rmdir, "\"%s\"", const char*);
TRACEPOINT(trace_vfs_rmdir_ret, "");
TRACEPOINT(trace_vfs_rmdir_err, "%d", int);
Expand Down
2 changes: 2 additions & 0 deletions libc/syscall_to_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define __OSV_TO_FUNCTION_SYS_writev writev
#define __OSV_TO_FUNCTION_SYS_fstatat fstatat
#define __OSV_TO_FUNCTION_SYS_unlinkat unlinkat
#define __OSV_TO_FUNCTION_SYS_mkdir mkdir
#define __OSV_TO_FUNCTION_SYS_mkdirat mkdirat

#undef __syscall
#define __syscall(sys_number, ...) (__OSV_TO_FUNCTION_##sys_number(__VA_ARGS__) < 0 ? -errno : 0)
Expand Down
2 changes: 2 additions & 0 deletions linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ long syscall(long number, ...)
SYSCALL0(getpid);
SYSCALL3(set_mempolicy, int, unsigned long *, unsigned long);
SYSCALL3(sched_setaffinity_syscall, pid_t, unsigned, unsigned long *);
SYSCALL2(mkdir, char*, mode_t);
SYSCALL3(mkdirat, int, char*, mode_t);
}

debug_always("syscall(): unimplemented system call %d\n", number);
Expand Down

0 comments on commit a0761f8

Please sign in to comment.