Add file and directory creation, mkdir

This commit is contained in:
2026-06-30 20:37:24 +03:00
parent 01cd3f528c
commit 1148596a81
18 changed files with 241 additions and 110 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
#include "src/lib/syscall.h"
#include "src/lib/util.h"
#include "src/user/syscall.h"
@@ -7,7 +8,7 @@
#define PRINT_D(s) write(1, s, string_length(s));
exit_code_t cat(const char *path) {
uint64_t fd = open(path);
uint64_t fd = open(path, OPEN_FILE);
if (fd == (uint64_t)-1) {
PRINT_S("cat: path does not exist\n");
+4 -3
View File
@@ -1,3 +1,4 @@
#include "src/lib/syscall.h"
#include "src/lib/util.h"
#include "src/user/syscall.h"
@@ -12,15 +13,15 @@ exit_code_t main(uint64_t argc, const char **argv) {
return EXIT_CODE_GENERAL_FAILURE;
}
uint64_t source = open(argv[1]);
uint64_t source = open(argv[1], OPEN_FILE);
if (source == (uint64_t)-1) {
PRINT_S("cp: source does not exist\n");
return EXIT_CODE_GENERAL_FAILURE;
}
uint64_t target = open(argv[2]);
uint64_t target = open(argv[2], OPEN_FILE | OPEN_CREATE);
if (target == (uint64_t)-1) {
PRINT_S("cp: target does not exist\n");
PRINT_S("cp: target path does not exist\n");
close(source);
return EXIT_CODE_GENERAL_FAILURE;
}
+2 -1
View File
@@ -1,4 +1,5 @@
#include "src/lib/string.h"
#include "src/lib/syscall.h"
#include "src/lib/util.h"
#include "src/user/syscall.h"
@@ -6,7 +7,7 @@
#define PRINT_D(s) write(1, s, string_length(s));
exit_code_t ls(const char *path) {
uint64_t fd = open(path);
uint64_t fd = open(path, OPEN_DIRECTORY);
if (fd == (uint64_t)-1) {
PRINT_S("ls: path does not exist\n");
+28
View File
@@ -0,0 +1,28 @@
#include "src/lib/syscall.h"
#include "src/lib/util.h"
#include "src/user/syscall.h"
#include <stdint.h>
#define BLOCK_SIZE 65536
#define PRINT_S(s) write(1, s, sizeof(s) - 1);
#define PRINT_D(s) write(1, s, string_length(s));
exit_code_t main(uint64_t argc, const char **argv) {
if (argc < 2) {
PRINT_S("mkdir: requires target(s)\n");
return EXIT_CODE_GENERAL_FAILURE;
}
for (uint64_t i = 1; i < argc; i++) {
uint64_t fd = open(argv[i], OPEN_DIRECTORY | OPEN_CREATE | OPEN_EXCLUSIVE);
if (fd == (uint64_t)-1) {
PRINT_S("mkdir: could not create directory\n");
return EXIT_CODE_GENERAL_FAILURE;
} else {
close(fd);
}
}
return EXIT_CODE_OK;
}