// If this is the file server (type == ENV_TYPE_FS) give it I/O privileges. // LAB 5: Your code here. structEnv* env; env_alloc(&env, 0); load_icode(env, binary); env->env_type = type; if(type == ENV_TYPE_FS) env->env_tf.tf_eflags |= FL_IOPL_3;
Question
Do you have to do anything else to ensure that this I/O privilege setting is saved and restored properly when you subsequently switch from one environment to another? Why?
// Check that the fault was within the block cache region if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE)) panic("page fault in FS: eip %08x, va %08x, err %04x", utf->utf_eip, addr, utf->utf_err);
// Sanity check the block number. if (super && blockno >= super->s_nblocks) panic("reading non-existent block %08x\n", blockno);
// Allocate a page in the disk map region, read the contents // of the block from the disk into that page. // Hint: first round addr to page boundary. fs/ide.c has code to read // the disk. // // LAB 5: you code here:
// Clear the dirty bit for the disk block page since we just read the // block from disk if ((r = sys_page_map(0, addr, 0, addr, uvpt[PGNUM(addr)] & PTE_SYSCALL)) < 0) panic("in bc_pgfault, sys_page_map: %e", r);
// Check that the block we read was allocated. (exercise for // the reader: why do we do this *after* reading the block // in?) if (bitmap && block_is_free(blockno)) panic("reading free block %08x\n", blockno);
对于注释中提问的问题:
exercise for the reader: why do we do this after reading the block in?
case'<': // Input redirection // Grab the filename from the argument list if (gettoken(0, &t) != 'w') { cprintf("syntax error: < not followed by word\n"); exit(); } // Open 't' for reading as file descriptor 0 // (which environments use as standard input). // We can't open a file onto a particular descriptor, // so open the file as 'fd', // then check whether 'fd' is 0. // If not, dup 'fd' onto file descriptor 0, // then close the original 'fd'.
case'>': // Output redirection // Grab the filename from the argument list if (gettoken(0, &t) != 'w') { cprintf("syntax error: > not followed by word\n"); exit(); } if ((fd = open(t, O_WRONLY|O_CREAT|O_TRUNC)) < 0) { cprintf("open %s for write: %e", t, fd); exit(); } if (fd != 1) { dup(fd, 1); close(fd); } break;