static bool syscall_remove (const char *file) { lock_acquire (&filesys_lock); bool retval = filesys_remove (file); lock_release (&filesys_lock); return retval; }
static void sys_remove(struct intr_frame *f_) { unsigned int *esp = f_->esp; char *file = *(esp + 1); f_->eax = filesys_remove(file); }
static bool sys_remove (void *file_, struct intr_frame *f) { bool success; success = filesys_remove ((char*)file_); f->eax = (uint32_t) success; return success; }
bool remove(const char *file) { lock_acquire(&filesys_lock); bool i = filesys_remove(file); lock_release(&filesys_lock); return i; }
/* remove file */ bool remove(const char *file) { bool result = false; if(filesys_remove(file)==true) result = true; return result; }
/* 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; }
/* Removes file called 'file'. Returns true if successful, and false otherwise (including when no file named 'file' exists). An open file can be removed, but it is not closed. */ static bool sys_remove(const char *file) { lock_acquire(&secure_file); bool success = filesys_remove(file); lock_release(&secure_file); return success; }
bool remove (const char* file) { //Do filesys call lock_acquire(&file_lock); bool ret = filesys_remove(file); lock_release(&file_lock); return ret; }
int sys_remove(char* file_name) { int ret; if(!*file_name) // empty string check return 0; lock_acquire(&filesys_lock); ret = filesys_remove(file_name); lock_release(&filesys_lock); return ret; }
bool sys_remove(const char* filename) { bool return_code; // memory validation check_user((const uint8_t*) filename); lock_acquire (&filesys_lock); return_code = filesys_remove(filename); lock_release (&filesys_lock); return return_code; }
/* * System Call: bool remove (const char *file) * Deletes the file called file. Returns true if successful, * false otherwise. A file may be removed regardless of whether * it is open or closed, and removing an open file does not close it. * See Removing an Open File, for details. */ bool remove_handler(const char *file) { //printf("removing...\n"); if (string_access_ok(file)) { lock_acquire (&fic_m); bool ret = filesys_remove (file); lock_release (&fic_m); return ret; } else { return false; } }
void remove (struct intr_frame *f) { const char * filename = *(char **)value_stack(f->esp,4); bool success = false; //removes the file success = filesys_remove (filename); //set eax to return value f->eax = success; }
/* Tries to remove the file with name "file" from the filesystem and returns whether or not the remove was successful. A removed file will remain usable in any process that has it open when it is removed, until that process closes the file */ static bool sys_remove (const char *file) { bool success; check_ptr (file); lock_acquire (&fs_lock); success = filesys_remove (file); lock_release (&fs_lock); return success; }
/* 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; }
int SYS_REMOVE_handler(int32_t* esp) { // Default to error... int retVal = -1; // kolla minnet if(verify_variable_length(esp[1]) == false){ sys_exit(-1); } char *name = (char*)*(esp + 1); retVal = filesys_remove(name); return retVal; }
static bool my_remove(const char *file) { lock_acquire(&filesys_lock); if(file == NULL || !address_valid(file)){ lock_release(&filesys_lock); return false; } bool success = filesys_remove(file); lock_release(&filesys_lock); return success; }
/* Delete a file. */ static bool sys_remove (const char *file) { bool success; #if PRINT_DEBUG printf ("[SYSCALL] SYS_REMOVE: file: %s\n", file); #endif if (file == NULL || !is_user_vaddr (file)) sys_exit (-1); lock_acquire (&file_lock); success = filesys_remove (file); lock_release (&file_lock); return success; }
bool remove (const char *file) { if (not_valid(file)) exit (-1); lock_acquire(&file_lock); /* In case the file is opened. First check its existence. */ struct file *f = filesys_open (file); bool result; if (f == NULL) result = false; else { file_close (f); result = filesys_remove (file); } lock_release(&file_lock); return result; }
static void syscall_handler (struct intr_frame *f) { uint32_t *p = f->esp; check_ptr(p); switch (*(int *)p) { /* Halt the operating system. IN : void OUT: void */ case SYS_HALT: { shutdown_power_off(); break; } /* Terminate this process. IN : int status OUT: void */ case SYS_EXIT: { check_ptr(p + 1); int status = *(int *)(p + 1); exit(status); break; } /* Start another process. IN : const char *file OUT: pid_t */ case SYS_EXEC: { check_string(p + 1); // f->eax = process_execute(*(char **)(p + 1)); pid_t pid = process_execute(*(char **)(p + 1)); struct child_process *cp = get_child_process(pid); if(cp->load == LOAD_SUCCESS) f->eax = pid; else if(cp->load == LOAD_FAIL) f->eax = -1; break; } /* Wait for a child process to die. IN : pid_t OUT: int */ case SYS_WAIT: { check_ptr(p + 1); f->eax = process_wait(*(tid_t *)(p + 1)); break; } /* Create a file. IN :const char *file, unsigned initial_size OUT:bool */ case SYS_CREATE: { check_string(p + 1); check_ptr(p + 2); if(*(char**)(p+1)==NULL||*(int *)(p+1)>=PHYS_BASE|| pagedir_get_page(thread_current()->pagedir, (const void *)*(p+1)) == NULL) exit(-1); f->eax = filesys_create(*(const char **)(p + 1), *(off_t *)(p + 2)); break; } /* Delete a file. IN: const char *file OUT: bool */ case SYS_REMOVE: { check_string(p + 1); if(*(char**)(p+1)==NULL||*(int *)(p+1)>=PHYS_BASE|| pagedir_get_page(thread_current()->pagedir, (const void *)*(p+1)) == NULL) exit(-1); f->eax = filesys_remove(*(char**)(p + 1)); break; } /* Open a file. IN: const char *file OUT: int */ case SYS_OPEN: { check_string(p + 1); struct file *file = filesys_open(*(char**)(p + 1)); if (file == NULL) { f->eax = -1; break; } struct file_desc *desc = malloc(sizeof(struct file_desc)); desc->file = file; desc->fd = thread_current()->fd; thread_current()->fd++; list_push_back(&thread_current()->file_list, &desc->elem); f->eax = desc->fd; break; } /* Obtain a file's size. IN: int fd OUT: int */ case SYS_FILESIZE: { check_ptr(p + 1); int fd = *(p + 1); struct file *file = process_get_file(fd); if (file == NULL) { f->eax = FILE_ERROR; } else { f->eax = file_length(file); } break; } /* Read from a file. IN: int fd, void *buffer, unsigned length OUT: int */ case SYS_READ: { check_ptr(p + 1); check_ptr(p + 2); check_ptr(p + 3); check_buffer(p + 2, *(p + 3)); int fd = *(int *)(p + 1); void *buffer = *(char**)(p + 2); unsigned length = *(unsigned *)(p + 3); //read from keyboard. Fd 0 reads from keyboard using input_getc(): one each time. if (fd == STDIN_FILENO) { uint8_t *into_buffer = (uint8_t *) buffer; unsigned i; for (i = 0; i < length; i++) { into_buffer[i] = input_getc(); } f->eax = length; } else { //read from file into buffer struct file *file = process_get_file(fd); //return -1 if file couldn't be read. if (file == NULL) { f->eax = FILE_ERROR; //-1 } else { int bytes = file_read(file, buffer, length); f->eax = bytes; } } break; } /* Write to a file. IN: int fd, const void *buffer, unsigned length OUT: int */ case SYS_WRITE: { check_ptr(p + 1); check_ptr(p + 2); check_ptr(p + 3); check_buffer(p + 2, *(p + 3)); int fd = *(int *)(p + 1); void *buffer = *(char**)(p + 2); unsigned length = *(off_t *)(p + 3); if (length <= 0) { f->eax = 0; break; } //Fd=1(STDOUT_FILENO) writes to the console. if (fd == STDOUT_FILENO) { putbuf(buffer, length); f->eax = length; } else { // return file by file descriptor. struct file *file = process_get_file(fd); if (file == NULL) { f->eax = FILE_ERROR; //-1 } else { int bytes = file_write(file, buffer, length); f->eax = bytes; } } break; } /* Change position in a file. IN: int fd, unsigned position OUT: void */ case SYS_SEEK: { check_ptr(p + 1); check_ptr(p + 2); int fd = *(int *)(p+1); unsigned position = *(unsigned *)(p+2); struct file *file = process_get_file(fd); if(file != NULL) { file_seek(file, position); } break; } /* Report current position in a file. IN: int fd OUT: unsigned */ case SYS_TELL: { check_ptr(p + 1); int fd = *(int *)(p+1); struct file *file = process_get_file(fd); if(file != NULL) { f->eax = file_tell(file); } else f->eax = FILE_ERROR; //-1 break; } /* Close a file. IN: int fd OUT: void */ case SYS_CLOSE: { check_ptr(p+1); int fd = *(int*)(p+1); struct thread *t = thread_current(); struct list_elem *next, *e = list_begin(&t->file_list); while (e != list_end (&t->file_list)) { next = list_next(e); struct file_desc *fl = list_entry (e, struct file_desc, elem); if (fd == fl->fd) { file_close(fl->file); list_remove(&fl->elem); free(fl); break; } e = next; } break; } default: break; } }
bool syscall_remove(const char *file) { if(!is_valid_ptr(file)) syscall_exit(-1); return filesys_remove(file); }
bool remove(const char* file) { return (bool)filesys_remove(file); }
static bool syscall_remove (const char *file) { return filesys_remove(file); }
static bool remove_handler (const char *file) { bool destroyed = filesys_remove(file); return destroyed; }
static void syscall_handler (struct intr_frame *f) { int nsyscall, i; int *esp = (int *)f -> esp; if(!is_valid(esp)) thread_exit(); int *arg_int[3]; void **arg_ptr[3]; // Get system call number. nsyscall = *(esp++); /* argc number 0: SYS_HALT 1: SYS_EXIT, SYS_EXEC, SYS_WAIT, SYS_TELL, SYS_REMOVE, SYS_OPEN, SYS_CLOSE, SYS_FILESIZE 2: SYS_CREATE, SYS_SEEK 3: SYS_READ, SYS_WRITE */ if(nsyscall == SYS_HALT) { shutdown_power_off(); } else if(nsyscall == SYS_EXIT) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } syscall_exit(*arg_int[0]); } else if(nsyscall == SYS_EXEC) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = process_execute(*arg_ptr[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_WAIT) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } f->eax = process_wait(*arg_int[0]); } else if(nsyscall == SYS_TELL) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); f->eax = syscall_tell(*arg_int[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_REMOVE) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = filesys_remove(*arg_ptr[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_OPEN) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_open(*arg_ptr[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_CLOSE) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); syscall_close(*arg_int[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_FILESIZE) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); f->eax = syscall_filesize(*arg_int[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_CREATE) { for(i = 0; i < 2; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = filesys_create(*arg_ptr[0], *arg_int[1]); lock_release(&lock_sys); } else if(nsyscall == SYS_SEEK) { for(i = 0; i < 2; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); syscall_seek(*arg_int[0], *arg_int[1]); lock_release(&lock_sys); } else if(nsyscall == SYS_READ) { for(i = 0; i < 3; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[1])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_read(*arg_int[0], *arg_ptr[1], *arg_int[2]); lock_release(&lock_sys); } else if(nsyscall == SYS_WRITE) { for(i = 0; i < 3; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[1])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_write(*arg_int[0], *arg_ptr[1], *arg_int[2]); lock_release(&lock_sys); } else if(nsyscall == SYS_CHDIR) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_chdir(*arg_ptr[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_MKDIR) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[0])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_mkdir(*arg_ptr[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_READDIR) { for(i = 0; i < 2; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; arg_ptr[i] = (void **)(esp + i); } else thread_exit(); } if(!is_valid(*arg_ptr[1])) thread_exit(); lock_acquire(&lock_sys); f->eax = syscall_readdir(*arg_int[0], *arg_ptr[1]); lock_release(&lock_sys); } else if(nsyscall == SYS_ISDIR) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); f->eax = syscall_isdir(*arg_int[0]); lock_release(&lock_sys); } else if(nsyscall == SYS_INUMBER) { for(i = 0; i < 1; i++) { if(is_valid((esp+i))) { arg_int[i] = esp + i; } else thread_exit(); } lock_acquire(&lock_sys); f->eax = syscall_inumber(*arg_int[0]); lock_release(&lock_sys); } else thread_exit(); }
/* Handles syscalls. Gets the syscall arguments off the stack (including the syscall number) then (either directly or with the aid of helper functions) executes the system call and places any return value into the eax register. Arguments should be parsed as soon as possible and the offset_lock should be held for the least possible amount of time. */ static void syscall_handler (struct intr_frame *f) { int sys_call; uint32_t ret_val = -1; void *arg0, *arg1, *arg2; struct fd_elem **fdt = thread_current()->open_files; /* Acquire lock before manipulating offset */ lock_acquire(&offset_lock); offset = f->esp; sys_call = (int) next_arg(); switch (sys_call) { case SYS_HALT: lock_release(&offset_lock); power_off(); NOT_REACHED (); case SYS_EXIT: arg0 = next_arg();/* exit status */ lock_release(&offset_lock); thread_current()->exit_controler->value = (int) arg0; thread_exit(); NOT_REACHED (); case SYS_EXEC: arg0 = next_str(); /* executable name */ lock_release(&offset_lock); ret_val = syscall_exec((const char *) arg0); break; case SYS_WAIT: arg0 = next_arg(); /* tid */ lock_release(&offset_lock); ret_val = process_wait((tid_t) arg0); break; case SYS_CREATE: arg0 = next_str(); /* File name */ arg1 = next_arg(); /* Size */ lock_release(&offset_lock); lock_acquire(&fs_lock); ret_val = filesys_create((const char *) arg0, (unsigned) arg1); lock_release(&fs_lock); break; case SYS_REMOVE: arg0 = next_str();/* file name */ lock_release(&offset_lock); lock_acquire(&fs_lock); ret_val = filesys_remove((const char *) arg0); lock_release(&fs_lock); break; case SYS_OPEN: arg0 = next_str(); /* file name */ lock_release(&offset_lock); ret_val = syscall_open((const char *) arg0); break; case SYS_FILESIZE: arg0 = next_arg(); /* fd */ lock_release(&offset_lock); lock_acquire(&fs_lock); ret_val = file_length(fdt[(int) arg0]->file); lock_release(&fs_lock); break; case SYS_READ: arg0 = next_arg(); /* fd */ arg1 = next_arg(); /* buffer */ arg2 = next_arg(); /* size */ lock_release(&offset_lock); ret_val = syscall_read((int) arg0, arg1, (unsigned) arg2); break; case SYS_WRITE: arg0 = next_arg(); /* fd */ arg1 = next_arg(); /* buffer */ arg2 = next_arg(); /* size */ lock_release(&offset_lock); ret_val = syscall_write((int) arg0, arg1, (unsigned) arg2); break; case SYS_SEEK: arg0 = next_arg(); /* fd */ arg1 = next_arg(); /* position */ lock_release(&offset_lock); lock_acquire(&fs_lock); file_seek(thread_current()->open_files[(int) arg0]->file, (unsigned) arg1); lock_release(&fs_lock); break; case SYS_TELL: arg0 = next_arg(); /* fd */ lock_release(&offset_lock); lock_acquire(&fs_lock); ret_val = file_tell(fdt[(int) arg0]->file); lock_release(&fs_lock); break; case SYS_CLOSE: arg0 = next_arg(); /* fd */ lock_release(&offset_lock); syscall_close((int) arg0); break; default: /* Invalid system call number. */ lock_release(&offset_lock); ret_val = -1; break; } /* Put return value into eax register and return to normal execution. */ f->eax = ret_val; }
bool sys_remove(const char* file) { return filesys_remove(file); }
static bool sys_remove(const char* file_name) { return filesys_remove(file_name); }
static void syscall_handler (struct intr_frame *f) { /* printf ("system call!\n");//TODO remove thread_exit ();*/ uint32_t ret_val; offset = f->esp; int sys_call = (int) next_arg(); char *tmp; //TODO remove switch (sys_call) { case SYS_HALT: power_off(); NOT_REACHED (); case SYS_EXIT: syscall_exit((int) next_arg()); NOT_REACHED (); case SYS_EXEC: ret_val = exec(); break; case SYS_WAIT: ret_val = process_wait((tid_t) next_arg()); break; case SYS_CREATE: // printf("test\n"); // printf("file_name: %s, size: %d\n", next_str(), next_arg()); tmp = next_str(); ret_val = filesys_create(tmp, next_arg()); break; case SYS_REMOVE: ret_val = filesys_remove(next_str()); break; case SYS_OPEN: next_str(); break; case SYS_FILESIZE: next_arg(); break; case SYS_READ: /* next_arg(); next_arg(); next_arg(); */ ret_val = syscall_read(); break; case SYS_WRITE: //FIXME this is just a temporary function to print to console unil real call is implemented /*if ((int) next_arg() == STDOUT_FILENO) { printf("%s", (char *) next_arg()); }*/ ret_val = syscall_write(); break; case SYS_SEEK: break; case SYS_TELL: break; case SYS_CLOSE: break; default: //TODO print error message break; } f->eax = ret_val; }