This commit is contained in:
p-w-rs
2022-09-07 11:18:56 -05:00
commit 7bb91e666d
121 changed files with 5306 additions and 0 deletions

57
TTOS/src/fs/fs.c Normal file
View File

@@ -0,0 +1,57 @@
#include <unistd.h>
#include <sys/syscall.h>
#include "errorCode.h"
errorCode_t fs_open(const char* path, int flags, int* fd) {
if(fd == 0) {
return EBADPARM;
}
int rc = syscall(SYS_open, path, flags);
if(rc == -1) {
return EFILESYS;
}
*fd = rc;
return SUCCESS;
}
errorCode_t fs_write(int fd, const void *buf, int count, int* bytes_written) {
int rc = syscall(SYS_write, fd, buf, count);
if(rc == -1) {
return EFILESYS;
}
if(bytes_written != 0) {
*bytes_written = rc;
}
return SUCCESS;
}
errorCode_t fs_read(int fd, void *buf, int count, int* bytes_read) {
int rc = syscall(SYS_read, fd, buf, count);
if(rc == -1) {
return EFILESYS;
}
if(bytes_read != 0) {
*bytes_read = rc;
}
return SUCCESS;
}
errorCode_t fs_seek(int fd, int offset, int whence, int* distance) {
int rc = syscall(SYS_lseek, fd, offset, whence);
if(rc == -1) {
return EFILESYS;
}
if(distance != 0) {
*distance = rc;
}
return SUCCESS;
}
errorCode_t fs_close(int fd) {
int rc = syscall(SYS_close, fd);
if(rc == -1) {
return EFILESYS;
}
return SUCCESS;
}