/* Name: applyLRU
 * Expected arguments: BM_BufferPool
 * Behavior: Would apply LRU as page replacement strategy on the buffer pool and return us the appropriate
 * 			 page to be replaced.
 * Returns: Success/failure flag.
 * Version: 1.0.0 */
int applyLRU(BM_BufferPool * const bm, BM_PageHandle * const page,
		const PageNumber pageNum) {
	BufferPool_Node *bf_node;
	bf_node = search_data(BP_StNode_ptr, bm);
	Buffer_page_Dtl *lowestPossiblePage;
	lowestPossiblePage = sortWeights(bm, bf_node);
	char *replacementAddress;
	replacementAddress = lowestPossiblePage->pageframes;

	RC writeVal = RC_OK;
	RC readVal = RC_OK;
	if (lowestPossiblePage->isdirty == TRUE) {
		writeVal = writeBlock(page->pageNum, bm->mgmtData, replacementAddress);
		lowestPossiblePage->isdirty=FALSE;
		bf_node->numwriteIO++;
	}
	readVal = readBlock(pageNum, bm->mgmtData, replacementAddress);
	if(readVal==RC_READ_NON_EXISTING_PAGE)
    {
        readVal =appendEmptyBlock(bm->mgmtData);
        readVal = readBlock(pageNum, bm->mgmtData, replacementAddress);
    }
	page->pageNum  = pageNum;
	page->data = lowestPossiblePage->pageframes;
    lowestPossiblePage->pagenums = pageNum;
    lowestPossiblePage->fixcounts+=1;
	lowestPossiblePage->replacementWeight =
    lowestPossiblePage->replacementWeight + 1;
	lowestPossiblePage->timeStamp =(long double)univtime++;
    bf_node->numreadIO++;
	if (readVal == RC_OK && writeVal == RC_OK)
		return 1; //success flag
	else
		return 0;
}
/* Name: ForceFlush BufferPool
 * Behavior:Write the data to disk forecefully with fix count =0
 * Version: 1.0.0 */
RC forceFlushPool(BM_BufferPool *const bm)
{
    RC ret=RC_OK;
    int i;
    Buffer_page_Dtl *pg_dtl;
    BufferPool_Node *bufnode;
    char *frame;
//    pthread_mutex_lock(&work_mutex_forceflush);
    bufnode=search_data(BP_StNode_ptr,bm);
    if(bufnode!=NULL)
        {
            pg_dtl=bufnode->buffer_page_dtl;
            for(i=0;i<bm->numPages;i++)
            {
                frame=pg_dtl[i].pageframes;
                if(pg_dtl[i].isdirty==TRUE && pg_dtl[i].fixcounts==0)//Writes the data with fixcount=0
                {
                   ret=writeBlock(pg_dtl[i].pagenums,bm->mgmtData,frame)==RC_OK?RC_OK:RC_WRITE_FAILED;
                   pg_dtl[i].isdirty=FALSE;
                   bufnode->numwriteIO++;
                }
            }
        }
//    pthread_mutex_unlock(&work_mutex_forceflush);
    return ret;
}
Esempio n. 3
0
ROAD_INFO *get_imei_road(RBT_IMEI *root, long long IMEI)
{
	RBT_IMEI *parent = NULL, *node = NULL;
	if((node = search_data(IMEI, root, &parent))) {
		return node->road;
	}
	return NULL;
}
Esempio n. 4
0
char *get_redis_road_info_value(RBT_IMEI *root, long long IMEI)
{
	RBT_IMEI *parent = NULL, *node = NULL;
        if((node = search_data(IMEI, root, &parent))) {
		return get_road_id(node->road);
	}
	return NULL;
}
Esempio n. 5
0
/*
adiciona a matriz em forma de array na priority queue
checa se ja nao existe a mesma matriz na mesma
*/
void add_priority_queue(heap_node **leaf, int key, int *array, int size) {
    if(leaf == NULL || array == NULL || size < 1) return;

    int i = search_data(search_root(*leaf), array, key, size);
    if(i == 0) return; // array exist in priority queue

    *leaf = (heap_node*) insert_node(leaf, key, array);
}
Esempio n. 6
0
NJ_INT16 njd_f_search_word(NJ_SEARCH_CONDITION *con, NJ_SEARCH_LOCATION_SET *loctset)
{
    NJ_UINT16 ret;

    switch (con->operation) {
    case NJ_CUR_OP_LINK:
        
        
        if ((con->hinsi.yominasi_fore == NULL) ||
            (con->hinsi.foreSize == 0)) {
            loctset->loct.status = NJ_ST_SEARCH_END;
            return 0;
        }
        break;
    case NJ_CUR_OP_FORE:
        
        
        if (NJ_CHAR_STRLEN_IS_0(con->yomi)) {
            loctset->loct.status = NJ_ST_SEARCH_END;
            return 0;
        }

        
        if ((con->hinsi.yominasi_fore == NULL) ||
            (con->hinsi.foreSize == 0)) {
            loctset->loct.status = NJ_ST_SEARCH_END;
            return 0;
        }
        break;
    default:
        
        loctset->loct.status = NJ_ST_SEARCH_END;
        return 0;
    } 

    
    if (con->mode != NJ_CUR_MODE_FREQ) {
        
        loctset->loct.status = NJ_ST_SEARCH_END;
        return 0;
    }

    
    if ((GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_NO_INIT)
        || (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_READY)) {
        
        ret = search_data(con, loctset);
        if (ret < 1) {
            
            loctset->loct.status = NJ_ST_SEARCH_END;
        }
        return ret;
    } else {
        
        loctset->loct.status = NJ_ST_SEARCH_END; 
        return 0; 
    }
}
/* Name: getNumReadIO
 * Behavior:Would return total number of writes that has taken place.
 * Version: 1.0.0 */
int getNumWriteIO (BM_BufferPool *const bm){
    int  nOwriteIO=0;
    Nodeptr _buffernode=search_data(BP_StNode_ptr,bm);
    if(_buffernode!=NULL)
    {
        nOwriteIO=_buffernode->numwriteIO;
    }
    return nOwriteIO;
}
/* Name: getNumReadIO
 * Behavior:Would return total number of reads that has taken place.
 * Version: 1.0.0 */
int getNumReadIO (BM_BufferPool *const bm)
{
    int  nOreadIO=0;
    Nodeptr _bufferNode=search_data(BP_StNode_ptr,bm);
    if(_bufferNode!=NULL)
    {
        nOreadIO=_bufferNode->numreadIO;
    }

    return nOreadIO;

}
Esempio n. 9
0
void search_data(AVL *tree, char *chh, int op_ls, int op_wp) {

	time_t ctime;

	if (tree == NULL) return;
	
	//word
	if (op_wp == 0) {
		if (!strcmp((tree)->key, chh)) {
			printf("%s, %d\n", tree->key, tree->line_num);
			search_data(tree->left, chh, op_ls, op_wp);
			search_data(tree->right, chh, op_ls, op_wp);
		}
	}
	
	//pattern
	else if (op_wp == 1) {
		if (NULL != strstr((tree)->key, chh)) {
			printf("%s, %d\n", tree->key, tree->line_num);
			search_data(tree->left, chh, op_ls, op_wp);
			search_data(tree->right, chh, op_ls, op_wp);
		}
	}
	else {
		search_data(tree->left, chh, op_ls, op_wp);
		search_data(tree->right, chh, op_ls, op_wp);
	}

}
Esempio n. 10
0
static bool delete_data(char *database_name, char *table_name, void *data) {
    int len = strlen(database_name) + strlen(table_name) + 1;
    char *table = (char*)malloc(sizeof(char) * len);
    table = strcat(table, database_name);
    table = strcat(table, "/");
    table = strcat(table, table_name);
    if (0 != search_data(table, data)) {
        printf("data \"%s\" is not find in \"%s\"\n");
        return false;
    } else {
    }
    return true;
}
/* Name: ShutDown BufferPool
 * Behavior:Would shutdown an existing buffer pool.
 * Version: 1.0.0 */
RC shutdownBufferPool(BM_BufferPool *const bm)
{
    RC ret=RC_WRITE_FAILED;
    int i ,*pgnums, *fixounts;
    bool ispinned=FALSE;
    Buffer_page_Dtl *pg_dtl;
    BufferPool_Node *bufnode;
    char *frame;
    int currentaccessed;
//    pthread_mutex_lock(&work_mutex_shutdown);//1st Incoming thread hold a lock.
    fixounts=getFixCounts(bm);
    pgnums=getFrameContents(bm);
    for(i=0 ; i < bm->numPages ; i++)
    {
        if(fixounts[i] > 0)
        {
            ispinned=TRUE;//Condition to check for pinned pages before shut down.
        }
    }
    free(fixounts);
    if(ispinned==FALSE)
    {
        ret=RC_OK;
        bufnode=search_data(BP_StNode_ptr,bm);//Get the active buffer pool from collection of pools.
        currentaccessed=getfilebeingused(BP_StNode_ptr,bm->pageFile);//Check if the same pool is being shared.
        if(bufnode!=NULL)
        {
            pg_dtl=bufnode->buffer_page_dtl;
            if(pg_dtl!=NULL)
            for(i=0;i<bm->numPages;i++)
            {
                frame=pg_dtl[i].pageframes;
                if(pg_dtl[i].isdirty==TRUE)
                {
                   ret=writeBlock(pg_dtl[i].pagenums,bm->mgmtData,frame)==RC_OK?RC_OK:RC_WRITE_FAILED;//Write the content with dirty to disk.
                }
                currentaccessed == 1 ?free(frame):' ';
            }
            currentaccessed == 1 ?free(pg_dtl):' ';
            pg_dtl=NULL;
            delete_node(&BP_StNode_ptr,bm);
        }
    currentaccessed == 1 ?closePageFile(bm->mgmtData):' ';
    currentaccessed == 1 ?free(bm->mgmtData):' ';

  }
//  pthread_mutex_unlock(&work_mutex_shutdown);//1st Incoming thread release a lock.
    free(pgnums);
    return ret;
}
/* Name: markDirty
 * Expected arguments: BM_BufferPool *const bm, BM_PageHandle *const page
 * Behavior: Would mark a particular page from a particular BufferPool as dirty
 * Version: 1.0.0 */
RC markDirty(BM_BufferPool * const bm, BM_PageHandle * const page) {
	int i;
	BufferPool_Node *pg_node;
	Buffer_page_Dtl *bf_pg_dtl;
	pg_node = search_data(BP_StNode_ptr, bm);
	bf_pg_dtl = pg_node->buffer_page_dtl;
	for (i = 0; i < bm->numPages; i++) {
		if (((bf_pg_dtl + i)->pagenums) == page->pageNum) {
			(bf_pg_dtl + i)->isdirty = TRUE;
			return RC_OK;
		}
	}
return RC_WRITE_FAILED; /*Should have been markdirty:failure*/
}
/* Name: forcePage
 * Expected arguments: BM_BufferPool *const bm, BM_PageHandle *const page
 * Behavior:
 * Version: 1.0.0 */
RC forcePage(BM_BufferPool * const bm, BM_PageHandle * const page) {
	BufferPool_Node *bf_node;
	bf_node = search_data(BP_StNode_ptr, bm);
	if(bf_node!=NULL)
    {

	if (bm->mgmtData!= NULL) {
		writeBlock(page->pageNum, bm->mgmtData, page->data);
		bf_node->numwriteIO++;
	} else {
		return RC_FILE_NOT_FOUND;
	}
    }
	return RC_OK;
}
Esempio n. 14
0
int main()
{
 Link *Head =NULL;
 insert_data(&Head,10);  //삽입
 insert_data(&Head,20);  //삽입
 insert_data(&Head,30);  //삽입
 insert_data(&Head,40);  //삽입
 modify_data(Head,20,22);  //수정  20을22로변경
 delete_data(&Head,20);  //삭제//20이라는 데이터를 삭제해라
 search_data(Head,22);  //검색  //22라는데이터를검색(출력값은 데이터와 노드의 주소)
 print_data(Head);  //출력 현재존재하는 노트의 데이터가 모두 출력
 add_data(Head,22,26);  //추가 //22뒤에 26을 추가
 print_data(Head);
 return 0;
}
/* Name: unpinPage
 * Expected arguments: BM_BufferPool *const bm, BM_PageHandle *const page
 * Behavior: Would check if a page is dirty. If dirty, this function would write the change back to the file
 * 			 and unpin it from the buffer pool. If clean, this function would simply write the change back to
 * 			 the file and unpin the page from buffer pool.
 * Version: 1.0.0
 * Algorithm:   1) Check if the page to be unpinned has fixcounts==0
 * 				2) If not throw an error that "this page has been currently accessed"
 * 				3) If fixcounts==0, check if isDirty==TRUE
 * 				4) If isDirty==TRUE, forcePage
 * 				5) Free the page from the memory reference*/
RC unpinPage(BM_BufferPool * const bm, BM_PageHandle * const page) {

	int totalPages = bm->numPages, i, k;
	BufferPool_Node *bf_node;
	bf_node = search_data(BP_StNode_ptr, bm);
	Buffer_page_Dtl *pg_dtl;
	pg_dtl = bf_node->buffer_page_dtl;
	for (i = 0; i < totalPages; i++) {
		if ((pg_dtl + i)->pagenums == page->pageNum) {
			if ((pg_dtl + i)->isdirty == TRUE) {
			}
			(pg_dtl + i)->fixcounts -= 1;
			return RC_OK;
		}
	}

	return RC_WRITE_FAILED; //should be unpin failed
}
Esempio n. 16
0
int imei_insert(RBT_IMEI **root, ROAD_INFO *road, long long IMEI, int speed, long time)
{
	RBT_IMEI *parent = NULL, *node = NULL;
	if ((node = search_data(IMEI, *root, &parent))) {
		if(road_insert(&(node->road), road) == -1) {
			return -1;
		}
		node->speed = speed;
		node->time = time;
		return 0;
	}

	node = (RBT_IMEI *)malloc(sizeof(RBT_IMEI));
	if(!node) {
		x_printf(E,  "rbt imei node malloc error!\n");
		return -1;
	}

        node->IMEI = IMEI;
	node->road = NULL;
	if(road_insert(&(node->road), road) == -1) {
		return -1;
	}
	node->speed = speed;
	node->time = time;
        node->parent = parent;
	node->left = node->right = NULL;
	node->color = RED;
	if (parent) {
                if(parent->IMEI > IMEI) {
                        parent->left = node;
                }
                else {
                        parent->right = node;
                }

	} else {
		*root = node;
	}
	insert_case(node, root);

        return 0;
}
Esempio n. 17
0
int main(){
	char chh[50];
	int op_ls;
	int op_wp;

	printf("대소문자를 구분하지 않으면 0, 구분하면 1을 입력하시오. ");
	scanf("%d", &op_ls);
	printf("단어단위로 검색하려면 0, 패턴단위로 검색하려면 1을 입력하시오. ");
	scanf("%d", &op_wp);

	printf("검색단어 입력: \n");
	gets(chh);
	//fflush(stdin);
	while( getchar() != '\n' );

	search_data(text_read(), chh, op_ls, op_wp);

	return 0;
}
Esempio n. 18
0
int main(int argc, char **argv) {
	int n, id;
	char name[21];
	printf("请输入代表数字:\n0.建表\n1.添加\n2.查看全部\n3.根据id查看\n4.根据name查看\n5.删除\n");
	printf("choose[0 - 5]:");
	scanf("%d", &n);
	switch(n) {
		case 0:
			creat_table();
			printf("建表成功\n");
			break;
		case 1:
			insert_data();
			printf("添加成功\n");
			break;
		case 2:
			search_data();
			printf("查看成功\n");
			break;
		case 3:
			printf("请输入id:");
			scanf("%d", &id);
			user_info(id, NULL);
			printf("查看成功\n");
			break;
		case 4:
			printf("请输入name:");
			scanf("%s", name);
			user_info(0, name);
			printf("查看成功\n");
			break;
		case 5:
			printf("请输入id:");
			scanf("%d", &id);
			user_del(id);
			printf("删除成功\n");
			break;
		default :
			printf("\nerror\n");
	}
	return 0;
}
/* Name: getFrameContents
 * Behavior:Would return an array pointer with array size equals total number of frames in buffer pool. Each array value equals page numbers.
 * Version: 1.0.0 */
PageNumber *getFrameContents (BM_BufferPool *const bm)
{
    PageNumber i,*pgnum=NULL;
    Buffer_page_Dtl *bf_pg_dtl;
    Nodeptr _bufferNode=search_data(BP_StNode_ptr,bm);
    if(_bufferNode!=NULL)
    {
        pgnum=(PageNumber *)calloc(bm->numPages,sizeof(PageNumber));
        bf_pg_dtl=_bufferNode->buffer_page_dtl;
        if(bf_pg_dtl!=NULL){
        for(i=0;i < bm->numPages;i++)
        {
            pgnum[i]=bf_pg_dtl[i].pagenums;
        }
        }else
          {
              free(bf_pg_dtl);
              bf_pg_dtl=NULL;
          }

    }
    return pgnum;
}
/* Name: getDirtyFlags
 * Behavior:Would return an array pointer with array size equals total number of frames in buffer pool. Each array value equals true or false w.r.t corresponding page.
 * Version: 1.0.0 */
bool *getDirtyFlags (BM_BufferPool *const bm)
{
    int i;
    bool  *dirtyflags;
    Buffer_page_Dtl *bf_pg_dtl;
    Nodeptr _bufferNode=search_data(BP_StNode_ptr,bm);
    if(_bufferNode!=NULL)
    {
        dirtyflags=(bool *)calloc(bm->numPages,sizeof(bool));
        bf_pg_dtl=_bufferNode->buffer_page_dtl;
        if(bf_pg_dtl!=NULL){
        for(i=0;i < bm->numPages;i++)
        {
            dirtyflags[i]=bf_pg_dtl[i].isdirty;
        }
        }else
          {
              free(bf_pg_dtl);
              bf_pg_dtl=NULL;
          }
    }
return dirtyflags;
}
/* Name: getFixCounts
 * Behavior:Would return an array pointer with array size equals total number of frames in buffer pool. Each array value equals fixcount of a frame.
 * Version: 1.0.0 */
int *getFixCounts (BM_BufferPool *const bm)
{
int i,*fixcounts;
Buffer_page_Dtl *bf_pg_dtl;
Nodeptr _buffernode=search_data(BP_StNode_ptr,bm);
    if(_buffernode!=NULL)
      {
          fixcounts=(int *)calloc(bm->numPages,sizeof(int));
          bf_pg_dtl=_buffernode->buffer_page_dtl;
          if(bf_pg_dtl!=NULL){
          for(i=0 ; i < bm->numPages ; i++)
          {
              fixcounts[i]=bf_pg_dtl[i].fixcounts;
          }
          }
          else
          {
              free(bf_pg_dtl);
              bf_pg_dtl=NULL;
          }

      }
return fixcounts;
}
Esempio n. 22
0
int main()
{
	int i;

	insert_data(1000);
	insert_data(2432);
	insert_data(5433);
	insert_data(3432);
	insert_data(3322);
	insert_data(3232);
	insert_data(5454);
	insert_data(6564);
	insert_data(7655);
	insert_data(8675);
	insert_data(9798);
	insert_data(1222);
	insert_data(2122);

	printf("\n\n");

	i = 5433;
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));

	i = 5422;
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));

	i = 3432;
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));

	i = 3431;
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));

	i = 5433;
	delete_data(i);
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));
	insert_data(i);
	printf("%d %sfound.\n", i, (search_data(i) ? "" : "not "));
	
	i = 5431;
	delete_data(i);
	
	return 0;
}
/* Name: pinPage
 * Expected arguments: BM_BufferPool *const bm, BM_PageHandle *const page, covnst PageNumber pageNum
 * Behavior: Would perform the applicable page replacement strategy on the buffer pool and pin the page from
 * 			 file at the appropriate position.
 * Version: 1.0.0
 * Algorithm:   1) Check if the page is already present in buffer
 * 				2) Add a replcementWeight to each page.
 * 				2) Get the appropriate replacement page by invoking the corresponding strategy
 * 				2) Replace that page with the new page.
 * 				3) The newly added page should have the maximum weight. */
RC pinPage(BM_BufferPool * const bm, BM_PageHandle * const page,
		const PageNumber pageNum) {
	int replacementFrameNum, totalPages, i;
	int statusFlag;
	ReplacementStrategy strategy = bm->strategy;
	Buffer_page_Dtl *lowestPossiblePage;
	totalPages = bm->numPages;
	BufferPool_Node *bf_node;
//	pthread_mutex_lock(&work_mutex_pin);//Hold the mutex lock for thread in pin block.
	bf_node = search_data(BP_StNode_ptr, bm);
	Buffer_page_Dtl *pg_dtl;
	pg_dtl = bf_node->buffer_page_dtl;
	RC writeVal=1, readVal=1;
	int emptyFlag = 1;
	if (pg_dtl != NULL) {

		/*This for loop checks if the page is already present in the buffer*/
		for (i = 0; i < totalPages; i++) {
			/*In order to make sure that all the elements of the array are empty, I am not breaking the loop*/
			if ((pg_dtl + i)->pagenums > -1) { //I assume that pagenums will be a mandatory field for any pg_dtl.
				emptyFlag = 0;
				/*To check if the page is already present in buffer.*/
				if ((pg_dtl + i)->pagenums == pageNum) {
                    (pg_dtl + i)->timeStamp=univtime++;//timestamp used in LRU
                    page->pageNum = pageNum;
					page->data = (pg_dtl + i)->pageframes;
					(pg_dtl + i)->fixcounts+=1;
//					pthread_mutex_unlock(&work_mutex_pin);//Unlock the mutex lock for thread in pin block.
					return RC_OK; // If there is a hit, return OK. There is no need to pin it since it is already present.
				}

			}
		} //end of 1st for loop

		/*This loop gets the first lowestPossible page and assigns it.*/
		for (i = 0; i < totalPages; i++) {
			if ((pg_dtl + i)->pagenums == -1){
				lowestPossiblePage = ((pg_dtl + i)); //After the loop, lowestPossiblePage would be last page for which pg_dtl was empty
				emptyFlag = 1;
				break;
			}
		}//end of 2nd for loop

	} else { /*This also means that the page detail has not been initialized at all since the array itself is null. This block might never be reached*/
		lowestPossiblePage = (pg_dtl + 0); // I assign the first frame itself as the lowestPossiblePage which is fit to be replaced.
		lowestPossiblePage->replacementWeight =
				lowestPossiblePage->replacementWeight + 1;

		(pg_dtl + i)->timeStamp=univtime++;
		emptyFlag = 1;
	}

	/*Even if there is one empty frame, emptyFlag would be 1. And we could make use of that page.*/
	if (emptyFlag == 1) {
		page->pageNum = pageNum;
		page->data = lowestPossiblePage->pageframes;
		/*If you find a free frame, just write the contents to that frame*/
		writeVal = RC_OK;
		/*This if condition is not mandatory. Infact this might never become true*/
		if (lowestPossiblePage->isdirty == TRUE) {
			writeVal = writeBlock(pageNum, bm->mgmtData,
					lowestPossiblePage->pageframes);
					bf_node->numwriteIO++;
		}
		if(readBlock(pageNum, bm->mgmtData,lowestPossiblePage->pageframes)==RC_READ_NON_EXISTING_PAGE)
				{
				    readVal=appendEmptyBlock(bm->mgmtData);//If page requested in pin not available in the file , do append it.
				}
				else
                    readVal=RC_OK;
        bf_node->numreadIO++;
		lowestPossiblePage->fixcounts += 1;
		lowestPossiblePage->pagenums = pageNum;

	} else { /*If no frame is free, call the appropriate page replacement algorithm to do the job*/
		if (strategy == RS_FIFO) {
			statusFlag = applyFIFO(bm, page, pageNum);
		} else if (strategy == RS_LRU) {
			statusFlag = applyLRU(bm, page, pageNum);
		} else if (strategy == RS_CLOCK) {
//			statusFlag = applyCLOCK(bm, page, pageNum);
		} else if (strategy == RS_LRU_K) {
//			statusFlag = applyLRU_k(bm, page, pageNum);
		} else {
			return RC_WRITE_FAILED; // should probably return "Invalid strategy"
		}
	} //end of outer else block

	/*Status flag indicates the success of the page replacement algorithm when no frame is free
	 * writeVal indicates the success of writelock call when a frame is dirty*/
//   	 pthread_mutex_unlock(&work_mutex_pin);
	if (statusFlag == 1 || (writeVal == RC_OK && readVal == RC_OK)) {
		return RC_OK;
	} else {
		return RC_WRITE_FAILED;
	}
}
Esempio n. 24
0
int main(int argc, char *argv[])
{
	char str_to_write[1024];
	int i0 = 0;
	int  fd_read;
	int  fd;
	int  ret = 0;

	char sn_header[16];
	char serial_number[SN_MAX_LEN];
	char *str_sn;
	char str_slip[] = "-";
	char arg_val[8][64];
	CARD_INFO *card_data;
	CARD_INFO *card_tmp;
	char *str_read;

	int fd0;
	char buf[sizeof(char)+1];
	char str_storeu[2048];
	int read_flag = 0;
#ifdef DEBUG_IN_LINUX
	char m_data[2048];
#endif

	char cmd_buf[256];
	CARD_INFO *card_store[MAX_CARD_NUMBER];

	memset(str_to_write  , 0x0 , sizeof(str_to_write));
	memset(sn_header     , 0x0 , sizeof(sn_header));
	memset(serial_number , 0x0 , sizeof(serial_number));
	memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
#ifdef DEBUG_IN_LINUX
	memset(m_data        , 0x0 , sizeof(m_data));
#endif
	#ifdef ENABLE_STRUCT
	i0 = 0;
	while(i0 < sizeof(card_store)/sizeof(CARD_INFO))
	{
		memset(card_store,0x0,sizeof(CARD_INFO));
		i0++;
	}
	#endif
	prepare_env();

	//read_file_from_mmc();
	/* go out if argument less than 2 */
	if(argc < 2)
	{
#ifdef DEBUG_IN_LINUX
		//testRSAGen();
		//encrypt_write_data("test data!",0);
		//decrypt_read_data(m_data);
		//JCG("read -->\n%s\n",m_data);
#endif
		JCG("bad args, should be ./q YCT-000000123455; ./q read; ./q write etc.");
		ret = -1;
		goto RET_ERR;
	}
	JCG("argv[0]:%s, argv[1]:%s.\n",argv[0],argv[1]);

	if(strcasecmp(argv[1],"clear") == 0)
	{
		clear_data();
		JCG("clear");
		ret = 0;
		goto RET_SUCC;
	}

	#ifdef MAC_WRITER_SUPPORT
	else if(strncasecmp(argv[1],"mac",sizeof("mac")) == 0)
	{
		ret = main_mac(argc,argv);
		JCG(" MAC Writer!!");
		goto RET_SUCC;
	}
	#endif

	else if(strcasecmp(argv[1],"read") == 0)
	{
#if 0
		char str_store[2048];

		char cmd_buf[256];
		char data_buf[256];

		memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
		memset(data_buf      , 0x0 , sizeof(data_buf));

		/* read data from flash*/
		read_data(NULL, str_store);
		JCG("get read data:%s\n",str_store);
#else
		char get_read_data[2048];
		/* read data from flash*/
		read_file_from_mmc();
		#ifdef ENABLE_STRUCT
		card_data = (CARD_INFO*) malloc(sizeof(CARD_INFO));
		read_data(card_data, NULL);
		card_tmp = card_data->next;
		print_card_info(card_data);
		free(card_data);
		#else	//not ENABLE_STRUCT
		memset(get_read_data,0x0,sizeof(get_read_data));
		read_data(NULL, get_read_data);
		JCG("get data -->\n%s\n",get_read_data);
		#endif
#endif
 		JCG("read");
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"del",3) == 0)
	{
		/* read data from flash*/
		delete_data(argv[1], NULL);
 		JCG("delete");
		ret = 0;
		write_file_to_mmc();
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"search",strlen("search")) == 0)
	{
		search_data(NULL);
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"mmcread",strlen("mmcread")) == 0)
	{
		read_file_from_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"mmcwrite",strlen("mmcwrite")) == 0)
	{
		write_file_to_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"rmda",strlen("rmda")) == 0)
	{
		delete_data_file();
		ret = 0;
		goto RET_SUCC;
	}

	JCG("-------- format: ./mac_writer YHK-000000123455 ---------------------------");
	write_data(argv[1], NULL);
	JCG("-----------------------------------");
	ret = 0;
	write_file_to_mmc();
	goto RET_SUCC;

RET_SUCC:
#ifdef DEBUG_IN_ANDROID
	property_set("persist.sys.mac_writer.proc" ,"done");
#else
#endif
	destroye_env();

	return ret;
RET_ERR:
	destroye_env();
	return ret;

}
Esempio n. 25
0
static RBT_IMEI *_delete(RBT_IMEI *root, long IMEI)
{
	RBT_IMEI *child, *parent, *old, *left, *node;
	Color color;
	if (!(node = search_data(IMEI, root, NULL))) {
		return root;
	}
	old = node;
	if (node->left && node->right) {
		node = node->right;
		while ((left = node->left) != NULL) {
			node = left;
		}
		child = node->right;
		parent = node->parent;
		color = node->color;
		if (child) {
			child->parent = parent;
		}
		if (parent) {
			if (parent->left == node) {
				parent->left = child;
			} else {
				parent->right = child;
			}
		} else {
			root = child;
		}
		if (node->parent == old) {
			parent = node;
		}
		node->parent = old->parent;
		node->color = old->color;
		node->right = old->right;
		node->left = old->left;
		if (old->parent) {
			if (old->parent->left == old) {
				old->parent->left = node;
			} else {
				old->parent->right = node;
			}
		} else {
			root = node;
		}
		old->left->parent = node;
		if(old->right) {
			old->right->parent = node;
		}
	} else {
		if (!node->left) {
			child = node->right;
		}
		else if (!node->right) {
			child = node->left;
		}
		parent = node->parent;
		color = node->color;
		if (child) {
			child->parent = parent;
		}
		if (parent) {
			if (parent->left == node) {
				parent->left = child;
			} else {
				parent->right = child;
			}
		} else {
			root = child;
		}
	}
	road_destory(old->road);
	free(old), old = NULL;
	if (color == BLACK) {
		root = delete_case(child, parent, root);
	}
	return root;
}