int comm_buf_init2( void ) { struct comm_buffer_s *b; int i,n,num; num=comm_nr_connections; n=0; while(num>0) { for(i=0;i<1;i++) if( (b=malloc_buf(4096))!=NULL ) { b->_n=0; b->free(b); n++; } for(i=0;i<1;i++) if( (b=malloc_buf(8192))!=NULL ) { b->_n=1; b->free(b); n++; } num--; } if( n==0 ) return(-1); return(n); }
struct comm_buffer_s *comm_buf_get( int size, struct comm_s *comm ) { int i; struct comm_buffer_s *b; for(i=0;i<BN;i++) { if( (b=buffers[i]) && size<=b->size ) { buffers[i]=b->next; b->len=0; b->want=0; b->pbuf=b->buf; b->comm=comm; b->open_counter=comm->open_counter; b->completed=NULL; b->to_wake.first=b->to_wake.last=NULL; b->do_phase=0; b->ehh_list=EHH_VS_ALLOW; b->context.cb=b; b->temp=NULL; return(b); } } b=malloc_buf(size); b->open_counter=comm->open_counter; b->comm=comm; b->do_phase=0; b->ehh_list=EHH_VS_ALLOW; b->context.cb=b; b->temp=NULL; return(b); }
/* * Note, we allocate a big buffer in the tree root * from which we allocate nodes. This runs more * than 100 times as fast as directly using malloc() * for each of the nodes. */ TREE_ROOT *new_tree(int count) { TREE_ROOT *root; uint32_t size; if (count < 1000) { /* minimum tree size */ count = 1000; } root = (TREE_ROOT *)malloc(sizeof(TREE_ROOT)); memset(root, 0, sizeof(TREE_ROOT)); /* * Assume filename + node = 40 characters average length */ size = count * (BALIGN(sizeof(TREE_NODE)) + 40); if (count > 1000000 || size > (MAX_BUF_SIZE / 2)) { size = MAX_BUF_SIZE; } Dmsg2(400, "count=%d size=%d\n", count, size); malloc_buf(root, size); root->cached_path_len = -1; root->cached_path = get_pool_memory(PM_FNAME); root->type = TN_ROOT; root->fname = ""; HL_ENTRY* entry = NULL; root->hardlinks.init(entry, &entry->link, 0, 1); return root; }
/* * Allocate bytes for filename in tree structure. * Keep the pointers properly aligned by allocating * sizes that are aligned. */ static char *tree_alloc(TREE_ROOT *root, int size) { char *buf; int asize = BALIGN(size); if (root->mem->rem < asize) { uint32_t mb_size; if (root->total_size >= (MAX_BUF_SIZE / 2)) { mb_size = MAX_BUF_SIZE; } else { mb_size = MAX_BUF_SIZE / 2; } malloc_buf(root, mb_size); } root->mem->rem -= asize; buf = root->mem->mem; root->mem->mem += asize; return buf; }
void Register_NandDriver(NandInterface *ni) { int ret; unsigned int *databuf; unsigned int ppb; // unsigned int i=0; PPartition *tmp_ppart=0; dprintf("\nDEBUG nand:nand_test_init *******\n"); vnand_manager.pt =&partarray; vnand_interface = ni; vnand_interface->iInitNand((void *)&vnand_manager); dprintf("VNandManager : StartBlockID = %d\n",vnand_manager.info.startBlockID); dprintf("VNandManager : PagePerBlock = %d\n",vnand_manager.info.PagePerBlock); dprintf("VNandManager : BytePerPage = %d\n",vnand_manager.info.BytePerPage); dprintf("VNandManager : TotalBlocks = %d\n",vnand_manager.info.TotalBlocks); dprintf("VNandManager : MaxBadBlockCount = %d\n",vnand_manager.info.MaxBadBlockCount); dprintf("VNandManager : hwsector = %d\n",vnand_manager.info.hwSector); ppb = vnand_manager.info.PagePerBlock; dump_ppartarray(vnand_manager.pt); tmp_ppart =vnand_manager.pt->ppt; dprintf("\nDEBUG nand:nand_test_init ok *******\n"); databuf = malloc_buf(); if(!databuf) { eprintf("nand_test: error!get databuf failed.\n"); } //#define test_spl_page #ifdef test_spl_page ret = spl_test(&tmp_ppart[0],0, databuf, ppb); if(ret != 0) { eprintf("test_spl_page error.\n"); } #endif #define test_1_page #ifdef test_1_page { unsigned char data; int i,j; /* while(1) { for(j=0;j<tmp_ppart[4].totalblocks;j++) { for (i = 0; i < 4; i++) { if (i % 2 == 0) data = 0x00; else data = 0xff; ret = page_test(&tmp_ppart[4],j, databuf, tmp_ppart[4].pageperblock, data); if(ret != 0) { eprintf("test_1_page ok ret=%d.\n",ret); } } } } */ printk("pt name = %s\n",tmp_ppart[4].name); ret = page_test(&tmp_ppart[4],101, databuf, tmp_ppart[4].pageperblock, data); if(ret != 0) { eprintf("test_1_page ok ret=%d.\n",ret); } } #endif //#define test_1p_block #ifdef test_1p_block for(j=256;j<512;j++){ ret = block_test_pages(&tmp_ppart[4],j, databuf, tmp_ppart[4].pageperblock);//tmp_ppart[3].pageperblock); if(ret != 0) { eprintf("test_1p_block error.\n"); } } #endif // dprintf("\n****** g_vnand.operator->DeInitNand = 0x%x *****\n",(unsigned int)g_vnand.operator->DeInitNand); vnand_interface->iDeInitNand((void *)&vnand_manager); }
void extensions_remove_save(void) { int old_size,size,index=0,result=0; int ret_value=0,iserror=0; int remove_num,old_num,new_num,new_size,new_index; char name[STRING_LENGTH]={"aa1"}; struct mgtcgi_xml_extensions *old_nodes = NULL; struct mgtcgi_xml_extensions *new_nodes = NULL; //与对象关联的结构定义 struct mgtcgi_xml_group_array *group = NULL; //对象组 struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL; cgiFormString("name",name,STRING_LENGTH); /******************************参数检查*****************************/ if(strlen(name) < STRING_LITTLE_LENGTH){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&old_nodes,&old_size); if ( NULL == old_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } if (old_nodes->num < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } remove_num = -1; for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, name)){ remove_num = index; break; } } if (!((-1 != remove_num) && (remove_num < old_nodes->num))){//没有找到要删除的条目 iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } //如果名称修改了,检查是否重复和检查是否正在使用 get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size); if ( NULL == httpdirpolicys){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //对象组检查 ret_value = group_name_check(group, name, name); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else if (2 == ret_value){ ; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } //HTTPS_DIR策略检查 ret_value = httpdir_policy_name_check(httpdirpolicys, name, name, 1); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } /***********************可以删除,构建新结构***************************************/ old_num = old_nodes->num; new_num = old_num - 1; if (new_num < 0) new_num = 0; old_size = sizeof(struct mgtcgi_xml_extensions) + old_num * sizeof(struct mgtcgi_xml_extension_info); new_size = sizeof(struct mgtcgi_xml_extensions) + new_num * sizeof(struct mgtcgi_xml_extension_info); new_nodes = (struct mgtcgi_xml_extensions *)malloc_buf(new_size); if (NULL == new_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } new_nodes->num = new_num; for (index=0,new_index=0; index < old_nodes->num; index++){ if ((remove_num != index) && (new_index < new_nodes->num)){ strcpy(new_nodes->pinfo[new_index].name, old_nodes->pinfo[index].name); strcpy(new_nodes->pinfo[new_index].value, old_nodes->pinfo[index].value); strcpy(new_nodes->pinfo[new_index].comment, old_nodes->pinfo[index].comment); new_index++; } } if (new_index == new_nodes->num){ result = save_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSIONS,(void*)new_nodes, new_size); if (result < 0){ iserror = MGTCGI_WRITE_FILE_ERR; goto ERROR_EXIT; } } else { iserror = MGTCGI_NO_TARGET_ERR; goto ERROR_EXIT; } #if _MGTCGI_DEBUG_GET_ for (index=0; index < new_nodes->num; index++){ printf("new_nodes->pinfo[%d].name:%s\n",index,old_nodes->pinfo[index].name); printf("new_nodes->pinfo[%d].value:%s\n",index,old_nodes->pinfo[index].value); printf("new_nodes->pinfo[%d].comment:%s\n",index,old_nodes->pinfo[index].comment); } #endif /**************************成功,释放内存***************************/ printf("{\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&old_nodes); free_malloc_buf((void*)&new_nodes); free_xml_node((void*)&group); free_xml_node((void*)&httpdirpolicys); return; }
void extensions_add_save(void) { int old_size,new_size,index=0,size,iserror=0,result=0; char name[STRING_LENGTH]={"1"}; char value[STRING_LENGTH]={"10000"}; char comment[STRING_LENGTH]; struct mgtcgi_xml_extensions *old_nodes = NULL; struct mgtcgi_xml_extensions *new_nodes = NULL; struct mgtcgi_xml_group_array * group = NULL; cgiFormString("name",name,STRING_LENGTH); cgiFormString("value",value,DIGITAL_LENGTH); cgiFormString("comment",comment,DIGITAL_LENGTH); /******************************参数检查*****************************/ if((strlen(name) < STRING_LITTLE_LENGTH) || (strlen(value) < STRING_LITTLE_LENGTH)){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } /******************************重复性检查*****************************/ get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&old_nodes,&old_size); if ( NULL == old_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } for (index=0; index < group->num; index++){ if (0 == strcmp(group->pinfo[index].group_name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } /****************************重新构建新结构***************************/ old_size = sizeof(struct mgtcgi_xml_extensions) + old_nodes->num * sizeof(struct mgtcgi_xml_extension_info); new_size = sizeof(struct mgtcgi_xml_extensions) + (old_nodes->num + 1) * sizeof(struct mgtcgi_xml_extension_info); new_nodes = (struct mgtcgi_xml_extensions *)malloc_buf(new_size); if (NULL == new_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } memcpy(new_nodes, old_nodes, old_size); new_nodes->num = old_nodes->num + 1; strcpy(new_nodes->pinfo[old_nodes->num].name, name); strcpy(new_nodes->pinfo[old_nodes->num].value, value); strcpy(new_nodes->pinfo[old_nodes->num].comment, comment); #if _MGTCGI_DEBUG_GET_ for (index=0; index < new_nodes->num; index++){ printf("new_nodes->pinfo[%d].name:%s\n",index,new_nodes->pinfo[index].name); printf("new_nodes->pinfo[%d].value:%s\n",index,new_nodes->pinfo[index].value); printf("new_nodes->pinfo[%d].comment:%s\n",index,new_nodes->pinfo[index].comment); } #endif result = save_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSIONS,(void*)new_nodes, new_size); if (result < 0){ iserror = MGTCGI_WRITE_FILE_ERR; goto ERROR_EXIT; } /**************************成功,释放内存***************************/ printf("{\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&group); free_xml_node((void*)&old_nodes); free_malloc_buf((void*)&new_nodes); return; }