diff --git a/apps/app.c b/apps/app.c index 3794c0e6..16d92096 100644 --- a/apps/app.c +++ b/apps/app.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -14,7 +15,10 @@ int main() atexit(bye); printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid()); - int fd = open("/etc/motd", O_RDONLY); + mkdir("/home", 0); + mkdir("/home/user", 0); + + int fd = open("/home/user/notes.txt", O_RDWR | O_CREAT); if (fd < 0) { perror("open"); @@ -25,7 +29,7 @@ int main() ssize_t nread = read(fd, buffer, sizeof(buffer)); buffer[nread] = 0; - printf("/etc/motd says: %s", buffer); + printf("/home/user/notes.txt says: %s", buffer); close(fd); diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index ffc1b5fe..740fbc1a 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -29,6 +29,7 @@ set(SOURCES src/sys/open.cpp src/sys/file.cpp src/sys/id.cpp + src/sys/mkdir.cpp src/fs/VFS.cpp src/fs/tmpfs/FileSystem.cpp src/InitRD.cpp diff --git a/kernel/src/sys/mkdir.cpp b/kernel/src/sys/mkdir.cpp new file mode 100644 index 00000000..7af9da44 --- /dev/null +++ b/kernel/src/sys/mkdir.cpp @@ -0,0 +1,18 @@ +#include "Log.h" +#include "fs/VFS.h" +#include "memory/MemoryManager.h" +#include "sys/Syscall.h" + +Result sys_mkdir(Registers*, SyscallArgs args) +{ + u64 path_address = args[0]; + if (!MemoryManager::validate_userspace_string(path_address)) return err(EFAULT); + + const char* path = (const char*)path_address; + + kinfoln("mkdir: attempting to create %s", path); + + TRY(VFS::create_directory(path)); + + return 0; +} diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 2a1b5048..4b707260 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES src/atexit.cpp src/ctype.cpp src/time.cpp + src/sys/stat.cpp src/sys/mman.cpp ) diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h index 0158ddd0..967147da 100644 --- a/libc/include/sys/mman.h +++ b/libc/include/sys/mman.h @@ -1,7 +1,7 @@ /* sys/mman.h: Memory allocation and deallocation. */ -#ifndef _LUNA_MMAN_H -#define _LUNA_MMAN_H +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H #include #include diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h new file mode 100644 index 00000000..2f49059c --- /dev/null +++ b/libc/include/sys/stat.h @@ -0,0 +1,20 @@ +/* sys/stat.h: stat() routine and friends. */ + +#ifndef _SYS_STAT_H +#define _SYS_STAT_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Create a directory. */ + int mkdir(const char* path, mode_t mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libc/src/sys/stat.cpp b/libc/src/sys/stat.cpp new file mode 100644 index 00000000..8bce55fb --- /dev/null +++ b/libc/src/sys/stat.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +extern "C" +{ + int mkdir(const char* path, mode_t) + { + long rc = syscall(SYS_mkdir, path); + __errno_return(rc, int); + } +} diff --git a/libluna/include/luna/Syscall.h b/libluna/include/luna/Syscall.h index f4356f28..85349469 100644 --- a/libluna/include/luna/Syscall.h +++ b/libluna/include/luna/Syscall.h @@ -2,7 +2,7 @@ #define enumerate_syscalls(_e) \ _e(exit) _e(console_write) _e(clock_gettime) _e(allocate_memory) _e(deallocate_memory) _e(usleep) _e(open) \ - _e(close) _e(read) _e(getpid) _e(write) _e(lseek) + _e(close) _e(read) _e(getpid) _e(write) _e(lseek) _e(mkdir) enum Syscalls {