From 7dd59dd2e022161df8e37e6e42ebda6f1c4fd5fc Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 24 Oct 2012 00:07:39 +0200 Subject: [PATCH] Add mkdirat(2). --- libc/Makefile | 1 + libc/include/sys/stat.h | 1 + libc/mkdirat.cpp | 35 ++++++++++++++++++++++++++++++ sortix/include/sortix/syscallnum.h | 3 ++- sortix/io.cpp | 11 +++++++--- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 libc/mkdirat.cpp diff --git a/libc/Makefile b/libc/Makefile index 408d35c7..9d7e1740 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -167,6 +167,7 @@ link.o \ localeconv.o \ lseek.o \ memstat.o \ +mkdirat.o \ mkdir.o \ mktemp.o \ on_exit.o \ diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 064fa345..46422061 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -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); diff --git a/libc/mkdirat.cpp b/libc/mkdirat.cpp new file mode 100644 index 00000000..065e8d8b --- /dev/null +++ b/libc/mkdirat.cpp @@ -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 . + + mkdirat.cpp + Creates a new directory. + +*******************************************************************************/ + +#include +#include + +#include + +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); +} diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index cde733ed..8e67b243 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -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 diff --git a/sortix/io.cpp b/sortix/io.cpp index 23e5c9b3..b5994d89 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -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 from = PrepareLookup(&relpath); + Ref 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);