Added errno.h, fixed vfs mapper find()
This commit is contained in:
@@ -35,4 +35,6 @@
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
|
||||
#if defined(__KERNEL__)
|
||||
const char *kstrerror(int e);
|
||||
#endif
|
||||
|
||||
@@ -264,6 +264,12 @@ static int vfs_find_tree(struct vfs_node *root_node, const char *path, struct vf
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the node belongs to a mapper-based filesystem
|
||||
_assert(root_vnode->fs && root_vnode->fs->cls);
|
||||
if (root_vnode->fs->cls->opt & FS_NODE_MAPPER) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
// 3.2. Nothing found in path tree - request the fs to find
|
||||
// the vnode for the path element given
|
||||
vnode_t *child_vnode = NULL;
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@ libc_OBJS=$(O)/libc/crt0.o \
|
||||
$(O)/libc/syscall.o \
|
||||
$(O)/libc/vsnprintf.o \
|
||||
$(O)/libc/printf.o \
|
||||
$(O)/libc/string.o
|
||||
$(O)/libc/string.o \
|
||||
$(O)/libc/errno.o \
|
||||
$(O)/libc/stdio.o \
|
||||
$(O)/libc/init.o
|
||||
|
||||
sys_CRTBEGIN=$(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
|
||||
sys_CRTEND=$(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
|
||||
|
||||
+5
-2
@@ -1,12 +1,13 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char c;
|
||||
|
||||
printf("Hello, World!\n");
|
||||
puts("Hello, World!");
|
||||
|
||||
struct stat test_stat;
|
||||
if (stat("/init", &test_stat) == 0) {
|
||||
@@ -17,12 +18,14 @@ int main(int argc, char **argv) {
|
||||
test_stat.st_mode & 0x7);
|
||||
}
|
||||
|
||||
if (stat("/etc/file.txt", &test_stat) == 0) {
|
||||
if (stat("/1etc/file.txt", &test_stat) == 0) {
|
||||
printf("stat(\"/etc/file.txt\"):\n");
|
||||
printf(" st_size = %u\n", test_stat.st_size);
|
||||
printf(" st_mode = %d%d%d\n", (test_stat.st_mode >> 6) & 0x7,
|
||||
(test_stat.st_mode >> 3) & 0x7,
|
||||
test_stat.st_mode & 0x7);
|
||||
} else {
|
||||
perror("stat()");
|
||||
}
|
||||
|
||||
int fd = open("/etc/file.txt", O_RDONLY, 0);
|
||||
|
||||
@@ -11,6 +11,8 @@ _start:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
|
||||
call __libc_init
|
||||
|
||||
call _init
|
||||
|
||||
// Ignore %rdi/%rsi for now
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *err_strings0[35] = {
|
||||
"Success",
|
||||
"Operation not permitted",
|
||||
"No such file or directory",
|
||||
"No such process",
|
||||
"Interrupted system call",
|
||||
"I/O error",
|
||||
"No such device or address",
|
||||
"Argument list too long",
|
||||
"Exec format error",
|
||||
"Bad file number",
|
||||
"No child processes",
|
||||
"Try again",
|
||||
"Out of memory",
|
||||
"Permission denied",
|
||||
"Bad address",
|
||||
"Block device required",
|
||||
"Device or resource busy",
|
||||
"File exists",
|
||||
"Cross-device link",
|
||||
"No such device",
|
||||
"Not a directory",
|
||||
"Is a directory",
|
||||
"Invalid argument",
|
||||
"File table overflow",
|
||||
"Too many open files",
|
||||
"Not a typewriter",
|
||||
"Text file busy",
|
||||
"File too large",
|
||||
"No space left on device",
|
||||
"Illegal seek",
|
||||
"Read-only file system",
|
||||
"Too many links",
|
||||
"Broken pipe",
|
||||
"Math argument out of domain of func",
|
||||
"Math result not representable"
|
||||
};
|
||||
|
||||
int errno;
|
||||
|
||||
char *strerror(int n) {
|
||||
if (n >= 0 && n <= 34) {
|
||||
return (char *) err_strings0[n];
|
||||
}
|
||||
return (char *) "Unknown error";
|
||||
}
|
||||
|
||||
void perror(const char *e) {
|
||||
if (e && *e) {
|
||||
printf("%s: %s\n", e, strerror(errno));
|
||||
} else {
|
||||
puts(strerror(errno));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <sys/errno.h>
|
||||
|
||||
extern int errno;
|
||||
|
||||
char *strerror(int errnum);
|
||||
void perror(const char *s);
|
||||
@@ -1,2 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
int puts(const char *s);
|
||||
|
||||
#include "bits/printf.h"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <errno.h>
|
||||
|
||||
void __libc_init(void) {
|
||||
errno = 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int puts(const char *s) {
|
||||
size_t l = strlen(s);
|
||||
int w = write(STDOUT_FILENO, s, l);
|
||||
char c = '\n';
|
||||
|
||||
if (w == l) {
|
||||
write(STDOUT_FILENO, &c, 1);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
+13
-4
@@ -1,4 +1,5 @@
|
||||
#include "bits/syscall.h"
|
||||
#include <errno.h>
|
||||
|
||||
#define ASM_REGISTER(name) \
|
||||
register uint64_t name asm (#name)
|
||||
@@ -39,16 +40,24 @@
|
||||
rax; \
|
||||
})
|
||||
|
||||
#define SET_ERRNO(t, r) ({ \
|
||||
t res = (t) r; \
|
||||
if (res < 0) { \
|
||||
errno = -res; \
|
||||
} \
|
||||
res; \
|
||||
})
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t count) {
|
||||
return (ssize_t) ASM_SYSCALL3(SYSCALL_NR_WRITE, fd, buf, count);
|
||||
return SET_ERRNO(ssize_t, ASM_SYSCALL3(SYSCALL_NR_WRITE, fd, buf, count));
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t count) {
|
||||
return (ssize_t) ASM_SYSCALL3(SYSCALL_NR_READ, fd, buf, count);
|
||||
return SET_ERRNO(ssize_t, ASM_SYSCALL3(SYSCALL_NR_READ, fd, buf, count));
|
||||
}
|
||||
|
||||
int open(const char *filename, int flags, int mode) {
|
||||
return (int) ASM_SYSCALL3(SYSCALL_NR_OPEN, filename, flags, mode);
|
||||
return SET_ERRNO(int, ASM_SYSCALL3(SYSCALL_NR_OPEN, filename, flags, mode));
|
||||
}
|
||||
|
||||
void close(int fd) {
|
||||
@@ -56,7 +65,7 @@ void close(int fd) {
|
||||
}
|
||||
|
||||
int stat(const char *filename, struct stat *st) {
|
||||
return (int) ASM_SYSCALL2(SYSCALL_NR_STAT, filename, st);
|
||||
return SET_ERRNO(int, ASM_SYSCALL2(SYSCALL_NR_STAT, filename, st));
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void exit(int code) {
|
||||
|
||||
Reference in New Issue
Block a user