Covert sys_mkdir to sys_mkdirat

上级 d2e856e0
...@@ -29,7 +29,7 @@ long sys_fstat(int, struct stat*); ...@@ -29,7 +29,7 @@ long sys_fstat(int, struct stat*);
long sys_getpid(void); long sys_getpid(void);
long sys_kill(int); long sys_kill(int);
long sys_link(const char*, const char*); long sys_link(const char*, const char*);
long sys_mkdir(const char*); long sys_mkdirat(int, const char*);
long sys_mknod(const char*, int, int); long sys_mknod(const char*, int, int);
long sys_openat(int, const char*, int); long sys_openat(int, const char*, int);
long sys_pipe(int*); long sys_pipe(int*);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define SYS_unlink 12 #define SYS_unlink 12
#define SYS_fstat 13 #define SYS_fstat 13
#define SYS_link 14 #define SYS_link 14
#define SYS_mkdir 15 #define SYS_mkdirat 15
#define SYS_chdir 16 #define SYS_chdir 16
#define SYS_dup 17 #define SYS_dup 17
#define SYS_getpid 18 #define SYS_getpid 18
......
...@@ -18,6 +18,7 @@ int unlink(const char*); ...@@ -18,6 +18,7 @@ int unlink(const char*);
int fstat(int fd, struct stat*); int fstat(int fd, struct stat*);
int link(const char*, const char*); int link(const char*, const char*);
int mkdir(const char*); int mkdir(const char*);
int mkdirat(int dirfd, const char *pathname);
int chdir(const char*); int chdir(const char*);
int dup(int); int dup(int);
int getpid(void); int getpid(void);
......
...@@ -39,7 +39,7 @@ long (*syscalls[])(u64, u64, u64, u64, u64) = { ...@@ -39,7 +39,7 @@ long (*syscalls[])(u64, u64, u64, u64, u64) = {
SYSCALL(getpid), SYSCALL(getpid),
SYSCALL(kill), SYSCALL(kill),
SYSCALL(link), SYSCALL(link),
SYSCALL(mkdir), SYSCALL(mkdirat),
SYSCALL(mknod), SYSCALL(mknod),
SYSCALL(openat), SYSCALL(openat),
SYSCALL(pipe), SYSCALL(pipe),
......
...@@ -328,11 +328,25 @@ sys_openat(int dirfd, const char *path, int omode) ...@@ -328,11 +328,25 @@ sys_openat(int dirfd, const char *path, int omode)
} }
long long
sys_mkdir(const char *path) sys_mkdirat(int dirfd, const char *path)
{ {
struct inode *cwd;
struct inode *ip; struct inode *ip;
if(argcheckstr(path) < 0 || (ip = create(myproc()->cwd, path, T_DIR, 0, 0)) == 0) if (dirfd == AT_FDCWD) {
cwd = myproc()->cwd;
} else {
// XXX(sbw) do we need the sref while we touch fdir->ip?
sref<file> fdir;
if (!getfile(dirfd, &fdir) || fdir->type != file::FD_INODE)
return -1;
cwd = fdir->ip;
}
if (argcheckstr(path) < 0)
return -1;
ip = create(cwd, path, T_DIR, 0, 0);
if (ip == nullptr)
return -1; return -1;
iunlockput(ip); iunlockput(ip);
return 0; return 0;
......
...@@ -151,6 +151,12 @@ open(const char *path, int omode) ...@@ -151,6 +151,12 @@ open(const char *path, int omode)
return openat(AT_FDCWD, path, omode); return openat(AT_FDCWD, path, omode);
} }
int
mkdir(const char *path)
{
return mkdirat(AT_FDCWD, path);
}
extern void __cxa_pure_virtual(void); extern void __cxa_pure_virtual(void);
void __cxa_pure_virtual(void) void __cxa_pure_virtual(void)
{ {
......
...@@ -30,7 +30,7 @@ SYSCALL(mknod) ...@@ -30,7 +30,7 @@ SYSCALL(mknod)
SYSCALL(unlink) SYSCALL(unlink)
SYSCALL(fstat) SYSCALL(fstat)
SYSCALL(link) SYSCALL(link)
SYSCALL(mkdir) SYSCALL(mkdirat)
SYSCALL(chdir) SYSCALL(chdir)
SYSCALL(dup) SYSCALL(dup)
SYSCALL(getpid) SYSCALL(getpid)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论