kernel+libc: Add mkdir()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d2049567c8
commit
682d3c753e
@ -1,6 +1,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -14,7 +15,10 @@ int main()
|
|||||||
atexit(bye);
|
atexit(bye);
|
||||||
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
|
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)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
perror("open");
|
perror("open");
|
||||||
@ -25,7 +29,7 @@ int main()
|
|||||||
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
||||||
buffer[nread] = 0;
|
buffer[nread] = 0;
|
||||||
|
|
||||||
printf("/etc/motd says: %s", buffer);
|
printf("/home/user/notes.txt says: %s", buffer);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ set(SOURCES
|
|||||||
src/sys/open.cpp
|
src/sys/open.cpp
|
||||||
src/sys/file.cpp
|
src/sys/file.cpp
|
||||||
src/sys/id.cpp
|
src/sys/id.cpp
|
||||||
|
src/sys/mkdir.cpp
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/tmpfs/FileSystem.cpp
|
src/fs/tmpfs/FileSystem.cpp
|
||||||
src/InitRD.cpp
|
src/InitRD.cpp
|
||||||
|
18
kernel/src/sys/mkdir.cpp
Normal file
18
kernel/src/sys/mkdir.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "Log.h"
|
||||||
|
#include "fs/VFS.h"
|
||||||
|
#include "memory/MemoryManager.h"
|
||||||
|
#include "sys/Syscall.h"
|
||||||
|
|
||||||
|
Result<u64> 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;
|
||||||
|
}
|
@ -12,6 +12,7 @@ set(SOURCES
|
|||||||
src/atexit.cpp
|
src/atexit.cpp
|
||||||
src/ctype.cpp
|
src/ctype.cpp
|
||||||
src/time.cpp
|
src/time.cpp
|
||||||
|
src/sys/stat.cpp
|
||||||
src/sys/mman.cpp
|
src/sys/mman.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* sys/mman.h: Memory allocation and deallocation. */
|
/* sys/mman.h: Memory allocation and deallocation. */
|
||||||
|
|
||||||
#ifndef _LUNA_MMAN_H
|
#ifndef _SYS_MMAN_H
|
||||||
#define _LUNA_MMAN_H
|
#define _SYS_MMAN_H
|
||||||
|
|
||||||
#include <bits/mmap-flags.h>
|
#include <bits/mmap-flags.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
20
libc/include/sys/stat.h
Normal file
20
libc/include/sys/stat.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* sys/stat.h: stat() routine and friends. */
|
||||||
|
|
||||||
|
#ifndef _SYS_STAT_H
|
||||||
|
#define _SYS_STAT_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Create a directory. */
|
||||||
|
int mkdir(const char* path, mode_t mode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
13
libc/src/sys/stat.cpp
Normal file
13
libc/src/sys/stat.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <bits/errno-return.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
int mkdir(const char* path, mode_t)
|
||||||
|
{
|
||||||
|
long rc = syscall(SYS_mkdir, path);
|
||||||
|
__errno_return(rc, int);
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define enumerate_syscalls(_e) \
|
#define enumerate_syscalls(_e) \
|
||||||
_e(exit) _e(console_write) _e(clock_gettime) _e(allocate_memory) _e(deallocate_memory) _e(usleep) _e(open) \
|
_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
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user