newland/src/system.c
/** * NewLand Kernel - (C) 2019 Tristan Ross */#include <newland/arch/proc.h>#include <newland/errno.h>#include <newland/fs.h>#include <sys/newland.h> The function `nl_getbuildprop` is never used.int nl_getbuildprop(int prop, void* output, int* size) { switch (prop) {#ifdef __nvk__ case NL_PROP_ISNVK: return 1;#else case NL_PROP_ISNVK: return 0;#endif default: return -NEWLAND_EINVAL; } return 0;} The function `nl_getpid` is never used.pid_t nl_getpid() { proc_t* proc = process_curr(); if (proc == NULL) return 0; return proc->id;} The function `nl_getuid` is never used.uid_t nl_getuid() { proc_t* proc = process_curr(); if (proc == NULL) return 0; return proc->uid;} The function `nl_getgid` is never used.gid_t nl_getgid() { proc_t* proc = process_curr(); if (proc == NULL) return 0; return proc->gid;} The function `nl_open` is never used.int nl_open(const char* path, int mode) { proc_t* proc = process_curr(); if (proc == NULL) return -NEWLAND_EINVAL; int fd = -1; for (int i = 0; i < OPEN_MAX; i++) { if (proc->fd[i].node == NULL) { fd = i; break; } } if (fd == -1) return -NEWLAND_EMFILE; int r = fs_resolve(&proc->fd[fd].node, path); if (r < 0) return r; proc->fd[fd].mode = mode; proc->fd[fd].gid = proc->gid; proc->fd[fd].uid = proc->uid; proc->fd[fd].pid = proc->id; proc->fd[fd].offset = 0; if ((r = fs_node_open(&proc->fd[fd].node, &proc->fd[fd])) < 0) { proc->fd[fd].node = NULL; proc->fd[fd].mode = 0; proc->fd[fd].gid = 0; proc->fd[fd].uid = 0; return r; } return fd;} The function `nl_close` is never used.int nl_close(int fd) { proc_t* proc = process_curr(); if (proc == NULL) return -NEWLAND_EINVAL; if (fd < 0 || fd >= OPEN_MAX) return -NEWLAND_EINVAL; int r = fs_node_close(&proc->fd[fd].node, &proc->fd[fd]); if (r < 0) return r; proc->fd[fd].node = NULL; proc->fd[fd].mode = 0; proc->fd[fd].gid = 0; proc->fd[fd].uid = 0; return 0;} The function `nl_write` is never used.size_t nl_write(int fd, const void* buff, size_t count) { proc_t* proc = process_curr(); if (proc == NULL) return -NEWLAND_EINVAL; if (fd < 0 || fd >= OPEN_MAX) return -NEWLAND_EINVAL;TODO found /* TODO: permission checking */ size_t r = fs_node_write(&proc->fd[fd].node, proc->fd[fd].offset, buff, count);Checking if unsigned variable `r` is less than zero. if (r < 0) return r; proc->fd[fd].offset += r; return r;} The function `nl_read` is never used.size_t nl_read(int fd, void* buff, size_t count) { proc_t* proc = process_curr(); if (proc == NULL) return -NEWLAND_EINVAL; if (fd < 0 || fd >= OPEN_MAX) return -NEWLAND_EINVAL;TODO found /* TODO: permission checking */ size_t r = fs_node_read(&proc->fd[fd].node, proc->fd[fd].offset, buff, count);Checking if unsigned variable `r` is less than zero. if (r < 0) return r; proc->fd[fd].offset += r; return r;}