Ejercicio 1: int block_read(struct buffer_dev *dev, void *buffer, int block_number) { int i = hash(block_number); struct buffer *b = dev->buff[i]; int res = 0; mutex_lock(b->m); if (block_number != b->block_number) { if (b->dirty) { block_write(dev->dev, b->block, b->block_number); b->dirty = 0; } res = block_read(dev->dev, b->block, block_number); b->block_number = block_number; } memcpy(buffer, b->block, BLOCKSIZE); mutex_unlock(b->m); return res; } int block_write(struct buffer_dev *dev, void *buffer, int block_number) { int i = hash(block_number); struct buffer *b = dev->buff[i]; mutex_lock(b->m); if (block_number != b->block_number) { if (b->dirty) { block_write(dev->dev, b->block, b->block_number); b->dirty = 0; } b->block_number = block_number; } memcpy(b->block, buffer, BLOCKSIZE); mutex_unlock(b->m); return 0; } Ejercicio 2: int second_chance(struct frames *frames) { while(1) { struct *f = &frames->frame[frames->next]; int current = frames->next; frames->next = (frames->next+1) % NUMFRAMES; if (mutex_trylock(f->busy)) continue; if (!f->access && !f->modify) { mutex_unlock(f->busy); return current; else if (!f->access && f->modify) { f->modify = 0; /* no importa si suponemos que lo cambia page_write */ page_write(f->num_page, current); } else { f->access = 0; mutex_unlock(f->busy); } } /* never rearch here */ } /* siempre hay que hacer mutex_unlock() excepto en el caso de la escritura */ Ejercicio 3: No hay que actualizar ning�ún otro campo del dirent. static int search_position(struct entry *e_fs, struct entry *e_arg) { if (e_fs->inode == -1) return 0; if (e_arg->inode == 0) { e_arg->inode = e_fs->inode; strncpy(e_arg->name, e_fs->name, ENTRY_SIZE); return 1; } e_arg->inode--; return 0; } struct dirent *mfs_readdir(MFS_DIR *dir) { struct entry arg; arg.inode = dir->siguiente; if (walk_directory(fs, &dir->d, search_position, &arg)) { strcpy(dir->e.d_name,arg.name); dir->siguiente++; return &mfs_dir.e; } return NULL; } Ejercicio 4: int file_read(struct file_system *fs, struct disk_inode *ino, void *buf, int block) { int i; /* extent */ if (block < 0) return -EINVAL; if (block > ino->block_size) return -EINVAL; /* too big */ for (i = 0; i < NUM_EXTENTS; i++) { if (block < ino->e[i].size) return data_read(fs, buffer, ino->e[i].start+block); block -= ino->e[i].size } return -BIGERROR; /* shouldn't never arrive here in a correct filesystem */ } int file_write(struct file_system *fs, struct disk_inode *ino, void *buf, int block) { int i; /* extent */ if (block < 0) return -1; else if (block == ino->block_size + 1) { if (add_one_block(fs, ino) == 0) return -1; } else if (block > ino->block_size) return -1; /* too big */ for (i = 0; i < NUM_EXTENTS; i++) { if (block < ino->e[i].size) return data_write(fs, buffer, ino->e[i].start + block); block -= ino->e[i].size } return -1; /* shouldn't never arrive here in a correct filesystem */ }