// close file int file_close(int fd) { int ret; struct file *file; if ((ret = fd2file(fd, &file)) != 0) { return ret; } fd_array_close(file); return 0; }
void files_closeall(struct files_struct *filesp) { // cprintf("[files_closeall]\n"); assert(filesp != NULL && files_count(filesp) > 0); int i; struct file *file = filesp->fd_array; //skip the stdin & stdout for (i = 2, file += 2; i < FILES_STRUCT_NENTRY; i ++, file ++) { if (file->status == FD_OPENED) { fd_array_close(file); } } }
//Called when a proc exit void files_destroy(struct files_struct *filesp) { // 用于销毁文件 // cprintf("[files_destroy]\n"); assert(filesp != NULL && files_count(filesp) == 0); if (filesp->pwd != NULL) { // 如果当前目录不为空 vop_ref_dec(filesp->pwd); } int i; struct file *file = filesp->fd_array; for (i = 0; i < FILES_STRUCT_NENTRY; i ++, file ++) { if (file->status == FD_OPENED) { fd_array_close(file); // 关闭每一个文件 } assert(file->status == FD_NONE); } kfree(filesp); }