int nvm_set_parameter(const char *key, const char *value) { int env_valid = 0; int isEnv1Bad = -1; int isEnv2Bad = -1; int opt_sts = CMM_SUCCESS; env_t *env_ptr = NULL; isEnv1Bad = check_block("/dev/mtd2", 0); isEnv2Bad = check_block("/dev/mtd2", CFG_ENV_SIZE); if( -1 == isEnv1Bad ) { printf(" ERROR: check env block 1 failed\n"); return CMM_FAILED; } if( -1 == isEnv2Bad ) { printf(" ERROR: check env block 2 failed\n"); return CMM_FAILED; } /* either env1 or env2 is bad block, we do not permit set operation */ if( ( isEnv1Bad != 0 ) || ( isEnv2Bad != 0 ) ) { printf(" ERROR: env is broken\n"); return CMM_FAILED; } /* Get NVM */ env_ptr = env_init(&env_valid); if( NULL == env_ptr ) { printf(" ERROR: read env failed\n"); return CMM_FAILED; } /* modify ethaddr */ __do_env_set_parameter(env_ptr, key, value); /* update env crc */ __env_crc_update(env_ptr); /* save env to flash */ if( CMM_SUCCESS != __save_env(env_ptr, env_valid) ) { printf(" ERROR: save env failed\n\n"); opt_sts = CMM_FAILED; } else { opt_sts = CMM_SUCCESS; } /* free env_ptr malloced by function env_init() */ env_destroy(env_ptr); return opt_sts; }
void nvm_dump(void) { int env_valid = 0; int isEnv1Bad = -1; int isEnv2Bad = -1; struct mtd_info_user info; env_t *env_ptr = NULL; if( CMM_SUCCESS != get_mtd_info("/dev/mtd2", &info) ) { printf(" ERROR: can not get mtd info\n"); return; } isEnv1Bad = check_block("/dev/mtd2", 0); isEnv2Bad = check_block("/dev/mtd2", CFG_ENV_SIZE); if( -1 == isEnv1Bad ) { printf(" ERROR: check env block 1 failed\n"); return; } if( -1 == isEnv2Bad ) { printf(" ERROR: check env block 2 failed\n"); return; } if( ( isEnv1Bad != 0 ) || ( isEnv2Bad != 0 ) ) { printf(" ERROR: env is broken\n"); return; } env_ptr = env_init(&env_valid); if( NULL == env_ptr ) { printf(" ERROR: read env failed\n"); return; } printf("nvm device name: mtd2\n"); printf("device type: %d\n", info.type); printf("nvm total size: %d KiB\n", info.size/1024); printf("block size: %d KiB\n", info.erasesize/1024); printf("page size: %d KiB\n", info.writesize/1024); printf("oob size: %d bytes\n", info.oobsize); printf("bad blocks: 0\n"); printf("env config size: %d KiB\n", CFG_ENV_SIZE/1024); printf("env valid: %d\n", env_valid); __debug_printf_env(env_ptr); env_destroy(env_ptr); }
static x_boolean release_block(t_mchecker mc, t_block b, x_boolean stop, x_boolean discard) { x_boolean result; result = check_block(b, stop); x_mutex_lock(test_mutex, x_eternal); x_list_remove(b); decrement_count(b, b->size); if (discard) { total_discarded += 1; if (total_discarded % 1000 == 0) { oempa("Discarding Wonka Chunk %d...\n", total_discarded); } discardMem(b); } else { releaseMem(b); } x_mutex_unlock(test_mutex); return result; }
void kfree(void* address) { kdebug("< kfree %d", address); // start of block malloc_block_t* block = address - (uint32_t)&(((malloc_block_t*)0)->data); check_block(block); int size = block->size; int flags = block->flags & ~MALLOC_USED; // if next block is free, merge with it if ((block->flags&MALLOC_LAST)==0) { malloc_block_t* next = BLOCK_NEXT(block); if ((next->flags&MALLOC_USED)==0) { size += next->size; flags |= (next->flags&MALLOC_LAST); } } // if previous block is free, merge with it if ((block->flags&MALLOC_FIRST)==0) { malloc_block_t* prev = BLOCK_PREVIOUS(block); if ((prev->flags&MALLOC_USED)==0) { size += prev->size; flags |= (prev->flags&MALLOC_FIRST); block = prev; } } setup_block(block, flags, size); kmalloc_print(); kdebug(">"); }
int check_format(const char *format) { t_struct form; int i; i = 0; init_struct(&form); while ((check_options(format[i], &form)) == 1) i++; while ((check_minimal_large(format[i], &form)) == 1) i++; if (format[i] == '.') { form.prec = 0; while ((check_precision(format[++i], &form)) == 1) continue; } while (format[i] == 'h' || format[i] == 'l' || format[i] == 'j' || format[i] == 'z') { check_size_modifier(format + i, &form); i++; if ((&form)->hh > 0 || (&form)->ll > 0) i++; } check_type(format[i]) == 1 ? (&form)->type = format[i] : 0; return (check_block(ft_strsub(format, 0, i + 1), &form)); }
void balls_update(t_ball *ball, float size) { float min; float max; float b_min; float b_max; min = -1.0f + 0.03f; max = 1.0f - 0.03f; b_min = ball->player->bar.position; b_max = ball->player->bar.position + size; ball->position.x += ball->direction.x * ball->speed; ball->position.y += ball->direction.y * ball->speed; check_block(ball); if (ball->position.x <= min) bounce(1, ball); if (ball->position.x >= max) bounce(1, ball); if (ball->position.x + 0.03f >= b_min && ball->position.x - 0.03f <= b_max) bounce_bar(b_min, b_max, ball); if (ball->position.y <= min) lost(ball); if (ball->position.y >= max) { ball->direction.y *= -1; ball->position.y += ball->direction.y * ball->speed; } }
int fileSys::delBlock(string file, int block_number){ int i,first_blk = getFirstBlock(file); if(check_n_pad(file) == 0) return 0; if(check_block(block_number, file) == 0) return 0; //check if the block_number belongs to the file if(first_blk == block_number){ for(i = 0; i < firstBlock.size(); i++){ if(firstBlock[i] == block_number){ firstBlock[i] = fat[block_number]; fat[block_number] = fat[0]; fat[0] = block_number; break; } } }else{ for(i = 0; i < fat.size();i++){ if(fat[i] == block_number){ fat[i] = fat[block_number]; fat[block_number] = fat[0]; fat[0] = block_number; break; } } } fsSynch(); return 1; }
int fileSys::putBlock(string file, int block_number, string buffer){ if(check_block(block_number, file) == 0) return 0; disk.putblock(block_number, buffer); return 1; }
static void check_new_blocks(const char *file, int line) { int i = CRT_NEW_TO_CHECK; while (i-- > 0) check_block(just_touched[i], file, line); }
int CrT_check_everything(const char *file, int line) { Header m = root.next; int i = 0;; for (; m != &root; ++i, m = m->next) check_block(m, file, line); return i; }
unsigned m_alloc_usable_size(void *v) { struct alloc_block *ab; if (v==NULL) return 0; ab = (struct alloc_block *)((char *)v - (unsigned)&((struct alloc_block*)NULL)->content); if (!check_block("Check", ab)) return 0; return ab->size; }
int nvm_get_parameter(const char *key, char *value) { int env_valid = 0; int isEnv1Bad = -1; int isEnv2Bad = -1; env_t *env_ptr = NULL; isEnv1Bad = check_block("/dev/mtd2", 0); isEnv2Bad = check_block("/dev/mtd2", CFG_ENV_SIZE); if( -1 == isEnv1Bad ) { printf(" ERROR: check env block 1 failed\n"); return CMM_FAILED; } if( -1 == isEnv2Bad ) { printf(" ERROR: check env block 2 failed\n"); return CMM_FAILED; } /* either env1 or env2 is bad block, we do not permit set operation */ if( ( isEnv1Bad != 0 ) || ( isEnv2Bad != 0 ) ) { printf(" ERROR: env is broken\n"); return CMM_FAILED; } /* Get NVM */ env_ptr = env_init(&env_valid); if( NULL == env_ptr ) { printf(" ERROR: read env failed\n"); return CMM_FAILED; } /* get parameter */ __do_env_get_parameter(env_ptr, key, value); /* free env_ptr malloced by function env_init() */ env_destroy(env_ptr); return CMM_SUCCESS; }
static void check_old_blocks(const char *file, int line) { int i = CRT_OLD_TO_CHECK; while (i-- > 0) { check_block(rover, file, line); rover = rover->next; } }
int fileSys::nextBlock(string file, int block_number){ if(check_n_pad(file) == 0) return -1; if(check_block(block_number, file) == 0) return -1; return fat[block_number]; }
/* print bad blocks in NAND flash */ void nand_print_bad(struct nand_chip* nand) { unsigned long pos; for (pos = 0; pos < nand->totlen; pos += nand->erasesize) { if (check_block(nand, pos)) printf(" 0x%8.8lx\n", pos); } puts("\n"); }
void m_alloc_check_memory(void) { int i; for (i = 0; i < HASH_SIZE; i++) { struct alloc_block *ab = SA[i]; while (ab) { check_block("check", ab); ab = ab->next; } } }
/** * @brief * chk_array_doneness - check if all subjobs are expired and if so, * purge the Array Job itself * * @param[in,out] parent - pointer to parent job. * * @return void */ void chk_array_doneness(job *parent) { char acctbuf[40]; int e; int i; struct ajtrkhd *ptbl = parent->ji_ajtrk; if (ptbl == NULL) return; if (ptbl->tkm_flags & TKMFLG_NO_DELETE) return; /* delete of subjobs in progress, don't array */ if (ptbl->tkm_subjsct[JOB_STATE_QUEUED] + ptbl->tkm_subjsct[JOB_STATE_RUNNING] + ptbl->tkm_subjsct[JOB_STATE_EXITING] == 0) { /* Array Job all done, do simple eoj processing */ for (e=i=0; i<ptbl->tkm_ct; ++i) { if (ptbl->tkm_tbl[i].trk_error > 0) e = 1; else if (ptbl->tkm_tbl[i].trk_error < 0) { e = 2; break; } } parent->ji_qs.ji_un_type = JOB_UNION_TYPE_EXEC; parent->ji_qs.ji_un.ji_exect.ji_momaddr = 0; parent->ji_qs.ji_un.ji_exect.ji_momport = 0; parent->ji_qs.ji_un.ji_exect.ji_exitstat = e; check_block(parent, ""); if (parent->ji_qs.ji_state == JOB_STATE_BEGUN) { /* if BEGUN, issue 'E' account record */ sprintf(acctbuf, msg_job_end_stat, e); account_job_update(parent, PBS_ACCT_LAST); account_jobend(parent, acctbuf, PBS_ACCT_END); svr_mailowner(parent, MAIL_END, MAIL_NORMAL, acctbuf); } if (parent->ji_wattr[(int)JOB_ATR_depend].at_flags & ATR_VFLAG_SET) (void)depend_on_term(parent); /* * Check if the history of the finished job can be saved or it needs to be purged . */ svr_saveorpurge_finjobhist(parent); } else { (void)job_save(parent, SAVEJOB_FULL); } }
int32_t ofs_update_block_pingpong_init(container_handle_t *ct, block_head_t *blk, uint64_t vbn) { int32_t ret = 0; int32_t ret2 = 0; uint32_t block_size = 0; uint8_t *buf = NULL; ret = check_block(ct, blk); if (ret < 0) { LOG_ERROR("Get blocksize failed. ct(%p) buf(%p) ret(%d)", ct, blk, ret); return ret; } block_size = ct->sb.block_size; buf = OS_MALLOC(block_size); if (buf == NULL) { LOG_ERROR("Allocate memory failed. size(%d)\n", block_size); return -BLOCK_ERR_ALLOCATE_MEMORY; } assemble_block(blk); memset(buf, 0, block_size); memcpy(buf + (blk->alloc_size * (blk->seq_no % (block_size / blk->alloc_size))), blk, blk->real_size); /*lint !e414 */ ret = ofs_update_block(ct, buf, block_size, 0, vbn); OS_FREE(buf); buf = NULL; ret2 = fixup_block(blk); if (ret2 < 0) { LOG_ERROR("Fixup object failed. blk(%p) ret(%d)\n", blk, ret2); return ret2; } if (ret != (int32_t)block_size) { LOG_ERROR("Update block data failed. ct(%p) blk(%p) size(%d) vbn(%lld) ret(%d)\n", ct, blk, block_size, vbn, ret); return -BLOCK_ERR_WRITE; } return 0; }
int check_blocks_around(t_core *c, int x, int y) { int i; if (y >= 0 && x >= 0 && y < GRID_HEIGHT && x < GRID_WIDTH) { i = -1; while (++i < 5) { if (check_block(x, y, i, c)) return (1); } } return (0); }
void check_graph() { node_set all_nodes_set(ALL_OF(g.all_nodes)); // NB: all_nodes is *unordered* check_block(g.block_); for (auto kv : anticipated_uses) { JIT_ASSERT(kv.second == -1); } // graph->stage() should be equal to max(node.stage for node in graph->nodes()) if (g.nodes().begin() == g.nodes().end()) { JIT_ASSERT(g.stage() == 0); } else { JIT_ASSERT(g.stage() == g.nodes().rbegin()->stage()); } JIT_ASSERT(std::includes(ALL_OF(sum_set), ALL_OF(all_nodes_set))); }
/****************************************** * release a block of memory by removing it from the data chain * called by user * NB: p0 is pointer to the data, need to find pointer to MemHdr first */ void release_mem( void *const p0 ) { register tMemHdr *const p = ((tMemHdr*)( (uint32)p0 - offsetof(tMemHdr, data) )); /* <<< size_t */ assert( head_mem != NULL ); /* there must be a cache !! */ assert( p->magic == MAGIC ); /* must be a valid block */ assert( ISDATA(p) ); /* must be a data block */ assert( head_data != NULL ); /* data chain can't be empty */ assert( tail_data != NULL ); assert( p->next_list != NULL || p == tail_data ); assert( p->prev_list != NULL || p == head_data ); assert( check_block(p) ); release_block( p ); } /* release_mem() */
/*************************************** * install the cache memory * the largest available memory block must be size bytes * return actual amount of memory available, * ie size of largest available block */ uint32 install_cache( uint32 size ) { register uint32 s = size; uint32 a = MemAvail(); /* available memory */ assert( head_mem == NULL ); /* must not already be installed !! */ /* restrict size to range 60k .. (mem available - 60k) */ if( s == 0 ) s = a/4; /* default value */ if( s < 60000 ) s = 60000; /* min size */ if( 60000+s > a ) s = a/2; /* too big ==> use 50% available memory */ s = ((s+3)&~3)+sizeof(tMemHdr); /* round up to exact number of longs */ assert( (sizeof(tMemHdr)&3) == 0 ); /* exact nr longs */ head_free = head_mem = (tMemHdr*)hi_malloc( s ); if( head_mem == NULL ) { /* pathological case ... */ nr_blocks = 0; total_size = 0; } else { total_size = head_mem->size = s - sizeof(tMemHdr); #ifndef NDEBUG head_free->magic = MAGIC; head_free->data[0] = -1; #endif head_free->pbase = NULL; head_free->next_mem = NULL; head_free->prev_mem = NULL; head_free->next_list = NULL; head_free->prev_list = NULL; head_data = tail_data = NULL; nr_blocks = 1; } /* if */ total_used = 0; total_free = total_size; assert( total_free + total_used + (nr_blocks-1)*sizeof(tMemHdr) == total_size ); assert( check_block(head_free) ); assert( check_cache() ); return total_size; } /* install_cache() */
void _m_free(void *v) { struct alloc_block *ab; if (v==NULL) return; ab = (struct alloc_block *)((char *)v - (unsigned)&((struct alloc_block*)NULL)->content); if (!check_block("Free", ab)) return; free_sa(ab); alloc_size-=ab->size; --alloc_count; memset(ab, 0x33, sizeof *ab + ab->size); free(ab); //GlobalFree(ab); }
void CrT_free(void *p, const char *file, int line) { #if defined(HAVE_PTHREAD_H) LOCKCRT(); #endif Header m = ((Header) p) - 1; Block b = m->b; #ifdef CRT_DEBUG_ALSO /* Look around for trashed ram blocks: */ if (*m->end == CRT_FREE_MAGIC) crash("Duplicate free()", m, file, line); check_block(m, __FILE__, __LINE__); CrT_check(file, line); /* Don't clobber 'rover': */ if (rover == m) { rover = rover->next; } /* Remove m from linklist of allocated blocks: */ REMOVE(m); /* Remove m from just_touched[], if present: */ { int i = CRT_NEW_TO_CHECK; while (i-- > 0) { if (just_touched[i] == m) { just_touched[i] = &root; } } } /* Mark m so as to give some chance of */ /* diagnosing repeat free()s of same */ /* block: */ *m->end = CRT_FREE_MAGIC; #endif b->live_bytes -= m->size; b->live_blocks--; free(m); #if defined(HAVE_PTHREAD_H) UNLOCKCRT(); #endif }
void check_command(SymTab *st, Command* c) { if(!c) return; switch(c->tag) { case COMMAND_IF: { check_exp(st, c->u.cif.exp); check_type_int(c->u.cif.exp); check_command(st, c->u.cif.comm); check_command(st, c->u.cif.celse); break; } case COMMAND_WHILE: { check_exp(st, c->u.cwhile.exp); check_type_int(c->u.cwhile.exp); check_command(st, c->u.cwhile.comm); break; } case COMMAND_ATTR: { check_var(st, c->u.attr.lvalue); check_exp(st, c->u.attr.rvalue); check_type_compatible(c->u.attr.lvalue->type, &(c->u.attr.rvalue), c->line); break; } case COMMAND_RET: { if(c->u.ret) { check_exp(st, c->u.ret); check_type_compatible(return_type, &(c->u.ret), c->line); } break; } case COMMAND_FUNCALL: { check_exp(st, c->u.funcall); break; } case COMMAND_BLOCK: { check_block(st, c->u.block); break; } } }
void* kmalloc(size_t payload) { malloc_block_t* block; malloc_block_t* ptr; kdebug("< kmalloc %d", payload); block = 0; ptr = first_block; while (1) { check_block(ptr); // free and big enough ? if (((ptr->flags&MALLOC_USED)==0) && (PAYLOAD_SIZE(ptr)>=payload)) { // better than the current fit (if any) ? if ((block==0) || (ptr->size<block->size)) { block = ptr; } } if (ptr->flags&MALLOC_LAST) { break; } ptr = BLOCK_NEXT(ptr); } if (ptr==0) { kpanic("could not allocate %d", payload); return 0; } int split_block = (block->size > (payload+BLOCK_OVERHEAD)); if (split_block) { int last = block->flags&MALLOC_LAST; size_t size = payload + BLOCK_OVERHEAD; size_t rem_size = block->size - size; setup_block(block, (block->flags&~MALLOC_LAST)|MALLOC_USED, size); setup_block(BLOCK_NEXT(block), last, rem_size); } else { block->flags |= MALLOC_USED; } kmalloc_print(); kdebug(">"); return (void*)block->data; }
void check_declr(SymTab *st, Declr* d) { switch(d->tag) { case DECLR_VAR: { if(st->prev) check_array_sizes(d->type); else check_array_empty(d->type); if(!symtab_add(st, d)) print_error("double declaration of variable", d->line); break; } case DECLR_FUNC: { check_array_empty(d->type); if(d->u.func.block) { Declr *proto; SymTab *param; proto = symtab_find(st, d->u.func.name); if(!proto) { symtab_add(st, d); proto = d; } else if(proto->u.func.block) { print_error("double declaration of function", d->line); } else { proto->u.func.block = d->u.func.block; } return_type = d->type; param = symtab_new(st); check_paramlist(param, proto->u.func.params, d->line); check_block(param, proto->u.func.block); symtab_free(param); } else { if(!symtab_add(st, d)) print_error("double declaration of function prototype", d->line); } break; } default: print_error("bug in compiler!", 0); } }
int main(int argv, char* args[]){ disk = open("/dev/fd0",O_RDWR); if (argv > 1){ if (strcmp(format, args[1]) == 0) do_format(); else if (strcmp(mkdir, args[1]) == 0){ if (argv > 2) do_mkdir(args[2]); else printf("Usage: mkdir dir\n"); } else if (strcmp(chdir, args[1]) == 0){ if (argv > 2) do_chdir(args[2]); else printf("Usage: chdir dir\n"); } else if (strcmp(copy, args[1]) == 0) { do_copy(args[2], args[3], args[4]); } else if (strcmp(dir, args[1]) == 0) do_dir(args[2]); else if (strcmp("info", args[1]) == 0){ info(args[2]); } else if (strcmp("freeblock", args[1]) == 0) free_block(); else if (strcmp("checkblock", args[1]) == 0) check_block(args[2]); else printf("Unknown dtool command.\n"); } return 0; }
/****************************************** * refresh a block of memory by moving it to the tail of the data chain * called by user to refresh a block of memory * NB: p0 is pointer to the data, need to find pointer to MemHdr first */ void use_mem( void *const p0 ) { register tMemHdr *const p = ((tMemHdr*)( (uint32)p0 - offsetof(tMemHdr, data) )); /* <<< size_t */ register tMemHdr *t0 = p->prev_list; register tMemHdr *t1 = p->next_list; assert( head_mem != NULL ); /* there must be a cache !! */ assert( p->magic == MAGIC ); assert( check_block(p) ); assert( ISDATA(p) ); assert( head_data != NULL ); assert( tail_data != NULL ); assert( t1 != NULL || p == tail_data ); assert( t0 != NULL || p == head_data ); if( t1 != NULL ) { /** not already at the end, remove block from chain **/ assert( head_data->next_list != NULL ); /* must be at least 2 blocks - this one & the one at the end */ t1->prev_list = t0; if( t0 != NULL ) { t0->next_list = t1; } else { head_data = t1; } /* if */ /** append p to current end of data chain */ p->prev_list = tail_data; tail_data->next_list = p; p->next_list = NULL; tail_data = p; } /* if */ assert( check_cache() ); assert( tail_data->data == p0 ); } /* use_mem() */
/**************************** * add block to free list * check_block() is called when block added to free list */ static void add_free( tMemHdr *const tr ) { register tMemHdr *t0; register tMemHdr *t1; assert( tr != NULL ); assert( tr->magic == MAGIC ); assert( ISFREE(tr) ); /** find where to put tr into free list **/ t0 = NULL; t1 = head_free; while( t1 != NULL && t1->size > tr->size ) { assert( t1->next_list == NULL || t1->next_list->prev_list == t1 ); assert( t1->prev_list == t0 ); t0 = t1; t1 = t1->next_list; assert( t0 != NULL ); } /* while */ tr->next_list = t1; tr->prev_list = t0; if( t1 != NULL ) { t1->prev_list = tr; } /* if */ if( t0 == NULL ) { /* the free list is empty, or this is the largest block */ head_free = tr; } else { t0->next_list = tr; } /* if */ assert( head_free != NULL ); assert( t1 == NULL || t1->next_list == NULL || t1->next_list->prev_list == t1 ); assert( t1 == NULL || t1->prev_list == NULL || t1->prev_list->next_list == t1 ); assert( tr->next_list == NULL || tr->next_list->prev_list == tr ); assert( tr->prev_list == NULL || tr->prev_list->next_list == tr ); assert( check_block( tr ) ); } /* add_free() */