int main(int argc, char *argv[]){ assert((fs_img_fd = open (argv[1], O_RDWR)) > 0); struct superblock sb; assert(pread(fs_img_fd, &sb, BSIZE, BSIZE) == BSIZE); superblock_reader(&sb); struct dinode inodes[200]; assert(pread(fs_img_fd, inodes, 200 * sizeof(struct dinode), 2 * BSIZE) == 200 * sizeof(struct dinode)); char bitmap_from_inode[BSIZE]; bitmap_generator(inodes,bitmap_from_inode); dir_checker(inodes); inodes_checker(inodes); char bitmap[BSIZE]; assert(pread(fs_img_fd, bitmap, BSIZE, 28* BSIZE) == BSIZE); /**int i; printf("on disk bitmap: \n"); for(i = 0; i < fs_size; i++){ printf("%d",read_bit(bitmap,i)); } printf("\n"); printf("bitmap build from inode info: \n"); for(i = 0; i < fs_size; i++){ printf("%d",read_bit(bitmap_from_inode,i)); } printf("\n"); **/ if(memcmp(bitmap,bitmap_from_inode,BSIZE)){ //write the correct version bitmap to the fs img assert(pwrite(fs_img_fd, bitmap_from_inode, BSIZE, BSIZE * 28) == BSIZE); } return 0; }
ir_node_t *create_bitmap(expr_t *expr_set) { op_t op; var_t *tmp; ir_node_t *new_binary; ir_node_t *bitmap1; ir_node_t *bitmap2; ir_node_t *ir_final; if (!expr_set || expr_set->expr_is==EXPR_LOST) { die("UNEXPECTED_ERROR: 72-1"); } if (expr_set->expr_is==EXPR_LVAL && expr_set->datatype->is==TYPE_SET) { return calculate_lvalue(expr_set->var); } if (expr_set->expr_is==EXPR_NULL_SET) { ir_final = new_ir_node_t(NODE_INIT_NULL_SET); ir_final->ir_lval = calculate_lvalue(x); //create the NULL set at factory 'x' } if (expr_set->expr_is!=EXPR_SET) { die("UNEXPECTED_ERROR: 72-2"); } normalize_expr_set(expr_set); op = expr_set->op; //check first if the set is basic if (op==OP_IGNORE) { //result goes to x //in this case the bitmap_generator() calls immediately the create_basic_bitmap() //but we want the later to be known only from the bitmap_generator() return bitmap_generator(x,expr_set); } //else //call the bitmap_generator for the child sets //run left subtree bitmap1 = bitmap_generator(ll,expr_set->l1); //swap (lr,x) tmp = x; x = ll; ll = tmp; //run right subtree bitmap2 = bitmap_generator(rr,expr_set->l2); //swap (lr,x) tmp = x; x = ll; ll = tmp; //result goes to x if (op==OP_PLUS) { //new_binary = new_ir_node_t(NODE_BINARY_OR); new_binary = new_ir_node_t(NODE_RVAL); new_binary->op_rval = OP_OR; new_binary->ir_lval = calculate_lvalue(ll); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(x); return new_binary; } else if (op==OP_MINUS) { //should never reach here, we cannot assign an expression of set datatype die("UNEXPECTED_ERROR: 71-1"); /* //tmp_node = new_ir_node_t(NODE_BINARY_NOT); tmp_node = new_ir_node_t(NODE_RVAL); tmp_node->op_rval = OP_NOT; tmp_node->ir_lval = calculate_lvalue(rr); tmp_node->ir_lval_dest = calculate_lvalue(rr); new_binary = new_ir_node_t(NODE_BINARY_AND); new_binary->ir_lval = calculate_lvalue(lr); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(x); return new_binary; */ } else if (op==OP_MULT) { //new_binary = new_ir_node_t(NODE_BINARY_AND); new_binary = new_ir_node_t(NODE_RVAL); new_binary->op_rval = OP_AND; new_binary->ir_lval = calculate_lvalue(ll); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(x); return new_binary; } else { die("UNEXPECTED_ERROR: 71-2 :bad operator in create_bitmap()"); } ir_final = NULL; ir_final = link_ir_to_ir(bitmap1,ir_final); ir_final = link_ir_to_ir(bitmap2,ir_final); ir_final = link_ir_to_ir(new_binary,ir_final); return ir_final; }
ir_node_t *bitmap_generator(var_t *factory,expr_t *expr_set) { //return the lvalue which contains the new bitmap //remember the bitmap_left bitmap_right bitmap_result in ir.c op_t op; var_t *tmp; ir_node_t *new_binary; ir_node_t *bitmap1; ir_node_t *bitmap2; ir_node_t *tmp_node; ir_node_t *ir_final; op = expr_set->op; if (op==OP_IGNORE) { return create_basic_bitmap(factory,expr_set); } //first the left bitmap (left child) bitmap1 = bitmap_generator(ll,expr_set->l1); //swap (lr,x), protect lr tmp = x; x = ll; ll = tmp; bitmap2 = bitmap_generator(rr,expr_set->l2); //swap (lr,x), restore lr tmp = x; x = ll; ll = tmp; if (op==OP_PLUS) { //new_binary = new_ir_node_t(NODE_BINARY_OR); new_binary = new_ir_node_t(NODE_RVAL); new_binary->op_rval = OP_OR; new_binary->ir_lval = calculate_lvalue(ll); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(factory); } else if (op==OP_MINUS) { //tmp_node = new_ir_node_t(NODE_BINARY_NOT); tmp_node = new_ir_node_t(NODE_RVAL); tmp_node->op_rval = OP_NOT; tmp_node->ir_lval = calculate_lvalue(rr); tmp_node->ir_lval_dest = calculate_lvalue(rr); //new_binary = new_ir_node_t(NODE_BINARY_AND); new_binary = new_ir_node_t(NODE_RVAL); new_binary->op_rval = OP_AND; new_binary->ir_lval = calculate_lvalue(ll); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(factory); new_binary = link_ir_to_ir(new_binary,tmp_node); } else if (op==OP_MULT) { //new_binary = new_ir_node_t(NODE_BINARY_AND); new_binary = new_ir_node_t(NODE_RVAL); new_binary->op_rval = OP_AND; new_binary->ir_lval = calculate_lvalue(ll); new_binary->ir_lval2 = calculate_lvalue(rr); new_binary->ir_lval_dest = calculate_lvalue(factory); } ir_final = NULL; ir_final = link_ir_to_ir(bitmap1,ir_final); ir_final = link_ir_to_ir(bitmap2,ir_final); ir_final = link_ir_to_ir(new_binary,ir_final); return ir_final; }