//******** cnopen ********************* //mode: FD_READ/FD_WRITE int16_t cnopen(dir_ptr* dir, const char* name, uint8_t mode) { stat_st stat_buf; if(cnstat(dir,name,&stat_buf) != 0) { if(mode == FD_WRITE) { check(cncreat(dir,name) == 0, "Could not create %s", name); } check(cnstat(dir,name,&stat_buf) == 0, "Could not stat %s", name); } //TODO: The fd bitmap is not 1 block long, hope we don't run out of fds int16_t fd = (int16_t)(uint16_t)find_free_bit((block*)fd_bm); set_bitmap((block*)fd_bm, fd); fd_tbl[fd].cursor = 0; fd_tbl[fd].state = mode; fd_tbl[fd].inode_id = stat_buf.inode_id; inode_read(stat_buf.inode_id, &fd_tbl[fd].inode); if(fd_tbl[fd].inode.blocks > 0) { fd_tbl[fd].data = calloc(fd_tbl[fd].inode.blocks,sizeof(block)); llread(&fd_tbl[fd].inode, fd_tbl[fd].data); } else { fd_tbl[fd].data = NULL; } return fd; error: return -1; }
//*************reserve_block************ iptr reserve_block(void) { superblock* super = (superblock*)&superblk_cache; if(super->free_block_count == 0) { return 0; } iptr blockid = find_free_bit(&block_bm_cache); set_bitmap(&block_bm_cache, blockid); super->free_block_count--; flush_metadata(); return blockid; }
//*************reserve_inode************ iptr reserve_inode(void) { superblock* super = (superblock*)&superblk_cache; if(super->free_inode_count == 0) { return 0; } iptr inode_ptr = find_free_bit(&inode_bm_cache); set_bitmap(&inode_bm_cache, inode_ptr); super->free_inode_count--; flush_metadata(); return inode_ptr; }
int search_bitmap(void) { int i; int free_bit = VOID_IDX; for(i = 0; i < VMEM_BMSIZE; i++) { Bmword bitmap = vmem->adm.bitmap[i]; Bmword mask = (i == (VMEM_BMSIZE - 1) ? VMEM_LASTBMMASK : 0); free_bit = find_free_bit(bitmap, mask); if(free_bit != VOID_IDX) { break; } } return free_bit; }
/** * Combine basic bitmap fragment program with the user-defined program. * \param st current context * \param fpIn the incoming fragment program * \param fpOut the new fragment program which does fragment culling * \param bitmap_sampler sampler number for the bitmap texture */ void st_make_bitmap_fragment_program(struct st_context *st, struct gl_fragment_program *fpIn, struct gl_fragment_program **fpOut, GLuint *bitmap_sampler) { struct st_fragment_program *bitmap_prog; struct st_fragment_program *stfpIn = (struct st_fragment_program *) fpIn; struct gl_program *newProg; uint sampler; /* * Generate new program which is the user-defined program prefixed * with the bitmap sampler/kill instructions. */ sampler = find_free_bit(fpIn->Base.SamplersUsed); if (stfpIn->glsl_to_tgsi) newProg = make_bitmap_fragment_program_glsl(st, stfpIn, sampler); else { bitmap_prog = make_bitmap_fragment_program(st->ctx, sampler); newProg = _mesa_combine_programs(st->ctx, &bitmap_prog->Base.Base, &fpIn->Base); /* done with this after combining */ st_reference_fragprog(st, &bitmap_prog, NULL); } #if 0 { printf("Combined bitmap program:\n"); _mesa_print_program(newProg); printf("InputsRead: 0x%x\n", newProg->InputsRead); printf("OutputsWritten: 0x%x\n", newProg->OutputsWritten); _mesa_print_parameter_list(newProg->Parameters); } #endif /* return results */ *fpOut = (struct gl_fragment_program *) newProg; *bitmap_sampler = sampler; }