1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add mkdirat(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2012-10-24 00:07:39 +02:00
parent caf4a1f2c5
commit 7dd59dd2e0
5 changed files with 47 additions and 4 deletions

View file

@ -167,6 +167,7 @@ link.o \
localeconv.o \
lseek.o \
memstat.o \
mkdirat.o \
mkdir.o \
mktemp.o \
on_exit.o \

View file

@ -52,6 +52,7 @@ int fstat(int fd, struct stat* st);
int fstatat(int dirfd, const char* path, struct stat* buf, int flags);
int lstat(const char* restrict path, struct stat* restrict st);
int mkdir(const char* path, mode_t mode);
int mkdirat(int dirfd, const char* path, mode_t mode);
int stat(const char* restrict path, struct stat* restrict st);
mode_t umask(mode_t mask);

35
libc/mkdirat.cpp Normal file
View file

@ -0,0 +1,35 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
mkdirat.cpp
Creates a new directory.
*******************************************************************************/
#include <sys/stat.h>
#include <sys/syscall.h>
#include <fcntl.h>
DEFN_SYSCALL3(int, sys_mkdirat, SYSCALL_MKDIRAT, int, const char*, mode_t);
extern "C" int mkdirat(int dirfd, const char* path, mode_t mode)
{
return sys_mkdirat(dirfd, path, mode);
}

View file

@ -84,6 +84,7 @@
#define SYSCALL_DUP2 60
#define SYSCALL_UNLINKAT 61
#define SYSCALL_FACCESSAT 62
#define SYSCALL_MAX_NUM 63 /* index of highest constant + 1 */
#define SYSCALL_MKDIRAT 63
#define SYSCALL_MAX_NUM 64 /* index of highest constant + 1 */
#endif

View file

@ -202,20 +202,24 @@ static int sys_unlink(const char* path)
return sys_unlinkat(AT_FDCWD, path, 0);
}
static int sys_mkdir(const char* path, mode_t mode)
static int sys_mkdirat(int dirfd, const char* path, mode_t mode)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
return -1;
ioctx_t ctx; SetupUserIOCtx(&ctx);
const char* relpath = pathcopy;
Ref<Descriptor> from = PrepareLookup(&relpath);
Ref<Descriptor> from = PrepareLookup(&relpath, dirfd);
if ( !from ) { delete[] pathcopy; return -1; }
int ret = from->mkdir(&ctx, relpath, mode);
delete[] pathcopy;
return ret;
}
// TODO: mkdirat
static int sys_mkdir(const char* path, mode_t mode)
{
return sys_mkdirat(AT_FDCWD, path, mode);
}
static int sys_rmdir(const char* path)
{
@ -445,6 +449,7 @@ void Init()
Syscall::Register(SYSCALL_GETTERMMODE, (void*) sys_gettermmode);
Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty);
Syscall::Register(SYSCALL_LINK, (void*) sys_link);
Syscall::Register(SYSCALL_MKDIRAT, (void*) sys_mkdirat);
Syscall::Register(SYSCALL_MKDIR, (void*) sys_mkdir);
Syscall::Register(SYSCALL_OPENAT, (void*) sys_openat);
Syscall::Register(SYSCALL_OPEN, (void*) sys_open);