int isatty(int fd) { struct msg m; m.hdr.code = FS_ISATTY; m.data[0] = fd; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return -1; return m.data[0]; }
int mkdir(const char *path, mode_t mode) { struct open_msg m; m.hdr.code = FS_MKDIR; m.flags = 0; m.mode = mode; strlcpy(m.path, (char *)path, PATH_MAX); return __posix_call(__fs_obj, &m, sizeof(m), 1); }
int fstat(int fd, struct stat *st) { struct stat_msg m; m.hdr.code = FS_FSTAT; m.fd = fd; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return -1; memcpy(st, &m.st, sizeof(struct stat)); return 0; }
pid_t getpid(void) { struct msg m; m.hdr.code = PS_GETPID; __posix_call(__proc_obj, &m, sizeof(m), 1); /* XXX: getpid can not return any error. */ return m.data[0]; }
int pipe(int fd[2]) { struct msg m; m.hdr.code = FS_PIPE; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return -1; fd[0] = m.data[0]; fd[1] = m.data[1]; return 0; }
int closedir(DIR *dir) { struct msg m; m.hdr.code = FS_CLOSEDIR; m.data[0] = dir->fd; if (__posix_call(__fs_obj, &m, sizeof(m), 0) != 0) return -1; free(dir); return 0; }
int dup2(int oldfd, int newfd) { struct msg m; m.hdr.code = FS_DUP2; m.data[0] = oldfd; m.data[1] = newfd; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return -1; return m.data[0]; }
pid_t getppid(void) { struct msg m; m.hdr.code = PS_GETPPID; __posix_call(__proc_obj, &m, sizeof(m), 1); /* XXX: getppid does not return error */ return m.data[0]; }
off_t lseek(int fd, off_t offset, int whence) { struct msg m; m.hdr.code = FS_LSEEK; m.data[0] = fd; m.data[1] = (int)offset; m.data[2] = whence; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return -1; return (off_t)m.data[0]; }
int unlink(char *path) { struct path_msg m; if (path == NULL || strlen(path) >= PATH_MAX) { errno = EINVAL; return -1; } m.hdr.code = FS_UNLINK; strlcpy(m.path, path, PATH_MAX); return __posix_call(__fs_obj, &m, sizeof(m), 1); }
struct dirent * readdir(DIR *dir) { struct dir_msg m; struct dirent *entry = &dir->dd_ent; m.hdr.code = FS_READDIR; m.fd = dir->dd_fd; if (__posix_call(__fs_obj, &m, sizeof(m), 1) != 0) return NULL; memcpy(entry, &m.dirent, sizeof(struct dirent)); return &dir->dd_ent; }
int mount(const char *dev, const char *dir, const char *fs, int flags, const void *data) { struct mount_msg m; strlcpy(m.dev, (char *)dev, PATH_MAX); strlcpy(m.dir, (char *)dir, PATH_MAX); strlcpy(m.fs, (char *)fs, 16); if (data != NULL) strlcpy(m.data, (char *)data, 64); m.flags = flags; m.hdr.code = FS_MOUNT; return __posix_call(__fs_obj, &m, sizeof(m), 1); }
void rewinddir(DIR *dir) { struct msg m; m.hdr.code = FS_REWINDDIR; m.data[0] = dir->dd_fd; __posix_call(__fs_obj, &m, sizeof(m), 1); /* * XXX: rewinddir() does not return error. But, we may get error... */ return; }
int link(char *oldpath, char *newpath) { struct path_msg m; if (oldpath == NULL || newpath == NULL) { errno = EINVAL; return -1; } if (strlen(oldpath) >= PATH_MAX || strlen(newpath) >= PATH_MAX) { errno = EINVAL; return -1; } strlcpy(m.path, oldpath, PATH_MAX); strlcpy(m.path2, newpath, PATH_MAX); m.hdr.code = FS_LINK; return __posix_call(__fs_obj, &m, sizeof(m), 1); }