int sys_open(const char *filename, int flag, int mode) { //TODO Check access int fd, status; FILE *f; if (!access_ok(VERIFY_READ, filename, VERIFY_STRLEN)) return -EFAULT; for (fd = 0; fd < NR_OPEN; fd++) if (!current_task->files[fd]) break; if (fd >= NR_OPEN) return -EMFILE; f = malloc(sizeof(FILE)); f->flags = 0; f->node = namei(filename, &status); if (!f->node) { free(f); return status; } if (flag & O_APPEND) f->offset = f->node->size; else f->offset = 0; ///////////////////////////////////// // A lot more goes here and there an everywhere ///////////////////////////////////// if ((!(flag & 3)) || (flag & O_RDWR)) f->flags |= FMODE_READ; if ((flag & O_WRONLY) || (flag & O_RDWR)) f->flags |= FMODE_WRITE; open_fs(f->node, f); f->count = 1; current_task->close_on_exec &= ~(1 << fd); f->fd = fd; current_task->files[fd] = f; return fd; }
int main(int argc, char *argv[]){ if(argc != 2){ printf("usage:\ntouch file\n"); return 1; } putenv("LOCALFS=some_fs.filesystem"); char *fs_name = getenv("LOCALFS"); struct fs *file_system; file_system = open_fs(fs_name); char *file = get_file(file_system, argv[1]); if(file == NULL){ //create the file create_file(file_system, argv[1], "", 0, 0x0000); } else { // update the timestamp on the file update_timestamp(file_system, argv[1]); } close_fs(file_system); return 1; }
static int sys_mkpipe(void) { fs_node_t * node = make_pipe(4096 * 2); open_fs(node, 0); int fd = process_append_fd((process_t *)current_process, node); FD_MODE(fd) = 03; /* read write */ return fd; }
static int sys_mkpipe(void) { fs_node_t * node = make_pipe(4096 * 2); open_fs(node, 0); return process_append_fd((process_t *)current_process, node); }