/* Open system call. */ static int sys_open (const char *ufile) { char *kfile = copy_in_string (ufile); struct file_descriptor *fd; int handle = -1; fd = malloc (sizeof *fd); if (fd != NULL) { lock_acquire (&fs_lock); fd->file = filesys_open (kfile); if (fd->file != NULL) { struct thread *cur = thread_current (); handle = fd->handle = cur->next_handle++; list_push_front (&cur->fds, &fd->elem); } else free (fd); lock_release (&fs_lock); } palloc_free_page (kfile); return handle; }
/* Open system call. */ static int sys_open (const char *ufile) { char *kfile = copy_in_string (ufile); struct file_descriptor *fd; int handle = -1; fd = calloc (1, sizeof *fd); if (fd != NULL) { struct inode *inode = filesys_open (kfile); if (inode != NULL) { if (inode_get_type (inode) == FILE_INODE) fd->file = file_open (inode); else fd->dir = dir_open (inode); if (fd->file != NULL || fd->dir != NULL) { struct thread *cur = thread_current (); handle = fd->handle = cur->next_handle++; list_push_front (&cur->fds, &fd->elem); } else { free (fd); inode_close (inode); } } } palloc_free_page (kfile); return handle; }
/* Remove system call. */ static int sys_remove (const char *ufile) { char *kfile = copy_in_string (ufile); bool ok = filesys_remove (kfile); palloc_free_page (kfile); return ok; }
/* Create system call. */ static int sys_create (const char *ufile, unsigned initial_size) { char *kfile = copy_in_string (ufile); bool ok = filesys_create (kfile, initial_size, FILE_INODE); palloc_free_page (kfile); return ok; }
/* Exec system call. */ static int sys_exec (const char *ufile) { tid_t tid; char *kfile = copy_in_string (ufile); tid = process_execute (kfile); palloc_free_page (kfile); return tid; }
/* Remove system call. */ static int sys_remove (const char *ufile) { char *kfile = copy_in_string (ufile); bool ok; lock_acquire (&fs_lock); ok = filesys_remove (kfile); lock_release (&fs_lock); palloc_free_page (kfile); return ok; }
/* Create system call. */ static int sys_create (const char *ufile, unsigned initial_size) { char *kfile = copy_in_string (ufile); bool ok; lock_acquire (&fs_lock); ok = filesys_create (kfile, initial_size); lock_release (&fs_lock); palloc_free_page (kfile); return ok; }
/* Exec system call. */ static int sys_exec (const char *ufile) { tid_t tid; char *kfile = copy_in_string (ufile); lock_acquire (&fs_lock); tid = process_execute (kfile); lock_release (&fs_lock); palloc_free_page (kfile); return tid; }