亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bfh.c

?? btree的實現源代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *                Larry A. Walker & Co. B+Tree R2        Corp. 1991,1995 Larry A. Walker (Larry A. Walker & Co.)                        All rights reserved.* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */#include "bfh.h"#include "debug.h"extern void free(void*);#define RELEASECODE	"CFW01.01"/*//// NAME:	BfhOpen////// RETURN:	NULL on error, or a pointer to the open descriptor (BFH *)//// DESCRIPTION:	Build a Block File//             	Open routine for the block file handler.  This routine requires//		a character pointer to the file name, a pointer to a descriptive//		structure that the user programs maintain concerning the //		contents of the file, the size of this structure, a key //		indicating if the file is to be created, and the block size of//		the file, including a one byte overhead.//*/BFH * BfhOpen(	char * file_name, /* pointer to block file name */			void * vptr, /* pointer to user description data */			int vptr_size, /* size of the user description */			int create , /* true or false create file switch */			int size /* single block size */){	int open_fd;	BFH * bfh;	char empty_block[BFHBLOCK];	char * ptr;	if(file_name == NULL){		Debug("Must have a file name\n");		return NULL;	}	Trace("BfhOpen(%s, %x, %d, %d, %d )\n", file_name, (unsigned)vptr, 		vptr_size, create, size);	if(vptr_size != 0){		if(vptr_size > BFHBLOCK){			Debug( "Invalid user data size. Quitting.\n");			return NULL;		}	}	/*		--- Create a handle -- descriptor	*/	bfh = (BFH *)calloc(1,sizeof(struct BfhInfo));	if(bfh == NULL){		Debug( "Memory allocation failed. Quitting.\n");		return NULL;	}		/*		--- Initialize it	*/	bfh->file_fd = -1;	bfh->file_ptr = NULL;	bfh->file_name[0] = 0;	/* the size of the block requested must be atleast this large*/	if(size < sizeof (struct free_block_id) ) {		size = sizeof(struct free_block_id) ;		Debug("Force adjust blocksize\n");	}	++size;	/* the size must be adjusted to accommodate the switch */	memset(empty_block, 0, BFHBLOCK);	/*		-- Create an empty file as necessary	*/	if(create == CREATE){		char Nil = 0;		if((sizeof(BFH) > BFHBLOCK) || ( vptr_size > BFHBLOCK))		{			Debug("Header contents too big to fit into block.  Block = %d, bfh block = %d, user block = %d\n", BFHBLOCK, sizeof(BFH), vptr_size);		}		open_fd = open(file_name,			O_RDWR|O_CREAT|O_EXCL,0666);		if(open_fd != -1){			strcpy(bfh->version, RELEASECODE);			bfh->magic = 7321L;			bfh->date_created = time(NULL);			bfh->date_opened = time(NULL);			bfh->date_updated = time(NULL);			bfh->block_size = size; /* Remember, the 				requested size plus one */			bfh->first_free_block_addr = -1L;			bfh->last_free_block_addr = -1L;			bfh->add_block_addr = 2*BFHBLOCK;			bfh->mask = 0;			/* write the bfh info block */			memmove(empty_block,bfh,sizeof(struct BfhInfo));			if(write(open_fd,empty_block,BFHBLOCK) 				!= BFHBLOCK){				Debug("bfh write failure\n");				free((void *)bfh);				return NULL;			}			memset(empty_block, 0, BFHBLOCK);			/* write the user program block */			if( (vptr_size > 0) && (vptr != NULL)){				memmove(empty_block,vptr,vptr_size);			}			if(write(open_fd,empty_block,BFHBLOCK) != BFHBLOCK){				Debug("bfh_data write failure\n");				free((void*)bfh);				return NULL;			}			/* write a single character position for seeks to land on */			if(write(open_fd,&Nil,1) != 1){				Debug("bfh_data write failure\n");				free((void*)bfh);				return NULL;			}			close(open_fd);		} else{			Debug("Failed to create file \"%s\"\n", file_name);			free((void*)bfh);			return NULL;		}	}	/* Save the file name and put a pointer in the descriptor to the addr */	ptr = strrchr(file_name,FILESEP);	if(ptr != NULL){		strncpy(bfh->file_name, ptr, 99);	}else{		strncpy(bfh->file_name, file_name, 99);	}/*	bfh->file_ptr = (char *)malloc( strlen(file_name) + 1);	if(bfh->file_ptr == NULL){		Debug( "Memory allocation failed. Quitting.\n");		free((void*)bfh);		return NULL;	}	strcpy(bfh->file_ptr, file_name);*/	open_fd = open(file_name, O_RDWR);	if(open_fd != -1){		/* Lock the file until the close */		if(lockf(open_fd, F_LOCK, 0) == -1){			Debug("Failed to lock file \"%s\"\n", file_name);			free((void*)bfh);			return NULL;		}		/* Read the bfh info block */		if(read(open_fd,empty_block,BFHBLOCK) != BFHBLOCK){			Debug("bfh_data read failure\n");			free((void*)bfh);			return NULL;		}		memmove(bfh,empty_block,sizeof(struct BfhInfo));		if(bfh->magic != 7321L){			Debug("Not a known B+Tree\n");			return NULL;		}		/* 			This code will only understand CFW index versions. 			( C freeware )		*/		if(strncmp(bfh->version, "CFW", 3) != 0){			Debug("Unknown release %s\n", bfh->version);			return NULL;		}		if(bfh->magic != 7321L){			Debug("Not a BFH file\n");		}		/* Read the user info block */			if(read(open_fd,empty_block,BFHBLOCK) != BFHBLOCK){			Debug("user data read failure\n");			free((void*)bfh);			return NULL;		}		/* Give the user a copy of the user data */		if( (vptr_size > 0) && (vptr != NULL)){			memmove((char *)vptr,(char *)empty_block,vptr_size);		}	} else{		Debug("Failed to create file \"%s\"\n", file_name);		free((void*)bfh);		return NULL;	}	bfh->empty_rec = (char *)malloc(bfh->block_size);	if(bfh->empty_rec == NULL ) {		return NULL;	}	memset(bfh->empty_rec, 0, bfh->block_size);	/* Save a copy of the fd in the descriptor */	bfh->file_fd = open_fd;		/* Update the last open date */	bfh->date_opened = time(NULL);/*	if(bfh->file_ptr != NULL){		free(bfh->file_ptr);		bfh->file_ptr = NULL;	}*/	return bfh;}/*//// NAME:	BfhClose//// DESCRIPTION:	Close the file and truncate the file of all free blocks which //		are at the end of the file//// RETURN:	SUCCESS or FAILED//*/int BfhClose(	BFH * bfh, /* pointer to the descriptor */		void * userdata, /* pointer to the updated user data */		int userdatasize /* size of the user data */){	long new_end;	int truncate, endfound;	struct free_block_id fbi;	struct free_block_id newfbi;	char cswitch;	long present_position;	Trace("BfhClose(%x, %x, %d)\n", (unsigned)bfh, (unsigned)userdata, 		userdatasize);	new_end = -1L;	if(bfh == NULL){		Debug("NULL descriptor\n");		return FAILED;	}		/* write out the headers*/	truncate = 0;	endfound = 0;	new_end = bfh->add_block_addr;	if(new_end > (long)(2*BFHBLOCK)){ /* if we have added blocks */		do{			if(new_end <= (long)(2*BFHBLOCK)){				/* there are no longer any blocks */				break;			}			/* find the last block in the file */			if(lseek(bfh->file_fd,new_end - bfh->block_size,0) == -1L) {				Debug( "Failed to seek\n");				return FAILED;			}			present_position = lseek(bfh->file_fd,0L,1);			/* get the switch for the last block */			if(read(bfh->file_fd,&cswitch,1) != 1 ) {				Debug( "Failed to read swithc\n");				return FAILED;			}			if(cswitch & BFHBLOCKINUSE){ /* a full block */				endfound++;				break;			}			/* otherwise the block can be truncacted */			if(read(bfh->file_fd,&fbi,sizeof(struct free_block_id)) != sizeof(struct free_block_id) ) {				Debug( "Failed to read");				return FAILED;			}			/* release a free block from the list*/			new_end = present_position;			/*free up this block from the list*/			/*				--- The previous free block in the list can't be pointing 				    forward to the one we are releasing			*/                        if (fbi.previous_block != -1L){				/* go to the previous block */				if(lseek(bfh->file_fd,fbi.previous_block+1,0) == -1L) {					Debug( "Failed to seek\n");					return FAILED;				}				/* get its free block identification */				if(read(bfh->file_fd,&newfbi,sizeof(struct free_block_id)) != sizeof(struct free_block_id) ) {					Debug( "Failed to read\n");					return FAILED;				}				/* update its info to bypass the block at the end of the file */				newfbi.next_block = fbi.next_block;				/* reposition */				if(lseek(bfh->file_fd,fbi.previous_block+1,0) == -1L) {					Debug( "Failed to seek\n");					return FAILED;				}				/* write the updated information */				if(write(bfh->file_fd,&newfbi,sizeof(struct free_block_id)) != sizeof(struct free_block_id) ) {					Debug( "Failed to read\n");					return FAILED;				}				truncate = 1;                        }else {				/* there was no previous block, which means this was the				   first free block available, and now it is gone */				bfh->first_free_block_addr = fbi.next_block;			}			/*				--- The next free block in the list can't be pointing 				    backward to the one we are releasing			*/                        if (fbi.next_block != -1L){				if(lseek(bfh->file_fd,fbi.next_block+1,0) == -1L) {					Debug( "Failed to seek\n");					return FAILED;				}				/* get its free block identification */				if(read(bfh->file_fd,&newfbi,sizeof(struct free_block_id)) != sizeof(struct free_block_id) ) {					Debug( "Failed to read\n");					return FAILED;				}				/* update its info to bypass the block at the end of the file */				newfbi.previous_block = fbi.previous_block;				/* reposition */				if(lseek(bfh->file_fd,fbi.next_block+1,0) == -1L) {					Debug( "Failed to seek\n");					return FAILED;				}				if(write(bfh->file_fd,&newfbi,sizeof(struct free_block_id)) != sizeof(struct free_block_id) ) {					Debug( "Failed to read\n");					return FAILED;				}				truncate = 1;                         }else{				/* there was no next block, which means this was the				   last free block available, and now it is gone */					bfh->last_free_block_addr = fbi.previous_block;   				}		}while(endfound == 0);	}	if(truncate)		if(new_end >= (2*BFHBLOCK) )			bfh->add_block_addr = new_end;	/* save the descriptor in the file */	if(lseek(bfh->file_fd,0L,0) == -1L){		Debug( "Failed to seek\n");		return FAILED;	}	if(write(bfh->file_fd,bfh,sizeof(struct BfhInfo)) != sizeof(struct BfhInfo)){		Debug( "close write failure\n");		return FAILED;	}	/* save the user information into the file */	if(userdata != NULL){		if(lseek(bfh->file_fd,(long)BFHBLOCK,0) == -1L){			Debug( "Failed to seek\n");			return FAILED;		}		if(write(bfh->file_fd,userdata,userdatasize) != userdatasize){			Debug( "close write failure\n");			return FAILED;		}	}	/* if the file was shortened, fix it in the file system */	if(truncate){		ftruncate(bfh->file_fd,new_end+1L);	}	if(lockf(bfh->file_fd, F_ULOCK, 0) == -1){		Debug("Failed to unlock file \"%s\"\n", bfh->file_name);		free((void*)bfh);		return FAILED;	}	close(bfh->file_fd);	bfh->file_fd = -1;	if(bfh->empty_rec != NULL){		free(bfh->empty_rec);		bfh->empty_rec = NULL;	}	free((void*)bfh);	return SUCCESS;}/* NAME:	WriteBlock DESCRIPTION: 	Write the block at the char pointer to the indicated position		in the file RETURN:	SUCCESS or FAIL*/int BfhWriteBlock(	BFH * bfh, /* pointer to bfh descriptor */			char *ptr, /* pointer to outgoing data */			long block_addr /* outgoing data block id */){ 	char key_out;	char inuse;	Trace("BfhWriteBlock(%x, %x, %ld)\n", 		(unsigned)bfh, (unsigned)ptr, block_addr);	key_out = BFHBLOCKINUSE; 	/* Used bit set*/	key_out = key_out | bfh->mask;  /* And any other switches being used */	/* Is the request beyond the last block in the file? */	if( block_addr > ((bfh->add_block_addr - bfh->block_size) + 1)){		Debug( "Cant write beyond end of file\n");		return FAILED;	}	/* Is the request below the first block in the file? */	if(block_addr < ((2*BFHBLOCK) + 1) ){		Debug( "Invalid block address\n");

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产欧美日韩另类视频免费观看| 麻豆91小视频| 日韩电影一二三区| 粉嫩蜜臀av国产精品网站| 欧美三级欧美一级| 国产精品少妇自拍| 久久精品国产亚洲高清剧情介绍| a亚洲天堂av| 337p粉嫩大胆色噜噜噜噜亚洲 | 中文在线一区二区| 日韩中文字幕区一区有砖一区 | 免费视频最近日韩| 色老综合老女人久久久| 久久久久国产一区二区三区四区 | 久久久噜噜噜久噜久久综合| 五月综合激情日本mⅴ| 色av一区二区| 国产精品污网站| 国产一区二区三区精品欧美日韩一区二区三区 | 色老综合老女人久久久| 国产女人18毛片水真多成人如厕 | 福利一区在线观看| 日韩精品专区在线影院重磅| 亚洲激情图片qvod| 91视频在线观看| 国产精品美女久久久久久| 狠狠v欧美v日韩v亚洲ⅴ| 在线播放欧美女士性生活| 亚洲综合一区二区三区| 色又黄又爽网站www久久| 国产精品天天摸av网| 国产精品一区不卡| 久久久久99精品一区| 久久99热99| www国产精品av| 国产伦精品一区二区三区免费 | 日韩欧美成人一区| 免费成人性网站| 精品美女被调教视频大全网站| 日本免费新一区视频| 制服.丝袜.亚洲.另类.中文| 日韩成人dvd| 欧美一区二区三区白人| 毛片av中文字幕一区二区| 91精品国产入口| 韩国午夜理伦三级不卡影院| 久久一区二区三区四区| 成人午夜视频免费看| 亚洲欧美综合网| 欧美性受xxxx黑人xyx性爽| 香蕉加勒比综合久久| 日韩午夜激情视频| 粉嫩13p一区二区三区| 亚洲美女少妇撒尿| 91精品国产免费| 国产一区 二区 三区一级| 亚洲国产经典视频| 欧美日韩精品一区二区三区四区| 蜜桃久久久久久久| 久久久久久久久久看片| va亚洲va日韩不卡在线观看| 亚洲一卡二卡三卡四卡五卡| 日韩欧美高清在线| 99久久婷婷国产| 三级在线观看一区二区| 久久久国产精品麻豆| 99精品一区二区| 日韩精品电影在线| 国产精品入口麻豆九色| 欧美日韩在线三级| 激情都市一区二区| 一区二区三区美女视频| 精品久久久久av影院| 91麻豆文化传媒在线观看| 日韩精品国产欧美| 亚洲欧美日韩国产成人精品影院| 日韩女优视频免费观看| 色噜噜狠狠成人网p站| 国产精品911| 免费看欧美美女黄的网站| 中文字幕制服丝袜成人av| 91精品免费在线观看| 91最新地址在线播放| 精品系列免费在线观看| 亚洲午夜精品网| 国产精品久久三区| 久久综合给合久久狠狠狠97色69| 欧美亚洲综合在线| jlzzjlzz欧美大全| 精品中文av资源站在线观看| 亚洲在线观看免费视频| 日本一区二区三区国色天香 | 日韩成人一级片| 亚洲婷婷国产精品电影人久久| 精品国产青草久久久久福利| 欧美体内she精视频| 91蜜桃免费观看视频| 国产精品资源在线观看| 美女视频免费一区| 三级在线观看一区二区| 亚洲福利视频一区二区| 亚洲精品成a人| 一区在线播放视频| 国产日韩欧美高清在线| 久久综合九色综合欧美亚洲| 制服丝袜亚洲网站| 欧美日韩aaa| 欧美日韩的一区二区| 欧美日韩精品专区| 欧美午夜一区二区| 欧美日韩在线电影| 欧美亚洲丝袜传媒另类| 91国产福利在线| 91极品美女在线| 色吧成人激情小说| 欧美日韩在线播| 欧美性生交片4| 欧美日韩视频在线第一区 | 一区二区三区 在线观看视频| 国产欧美日韩在线| 国产日产欧美一区| 国产亚洲欧洲一区高清在线观看| 精品国产乱码久久久久久蜜臀| 精品欧美一区二区三区精品久久| 日韩三级视频在线观看| 日韩免费观看高清完整版在线观看| 欧美一级片在线看| 精品国产欧美一区二区| 中文字幕精品一区| 亚洲综合色噜噜狠狠| 水野朝阳av一区二区三区| 日本aⅴ亚洲精品中文乱码| 九色综合狠狠综合久久| 国产成人精品免费| 99国内精品久久| 一本久道中文字幕精品亚洲嫩| 欧洲人成人精品| 制服丝袜av成人在线看| 精品国产污污免费网站入口| 欧美激情一区二区三区在线| 亚洲啪啪综合av一区二区三区| 亚洲一区视频在线| 激情五月婷婷综合| www.亚洲在线| 欧美丰满嫩嫩电影| 久久亚洲综合色| 亚洲日本青草视频在线怡红院| 亚洲成人资源在线| 国产一区二区精品久久91| 色国产精品一区在线观看| 在线成人免费观看| 国产精品久久夜| 久久黄色级2电影| 一本高清dvd不卡在线观看| 欧美一区二区视频观看视频 | www日韩大片| 一区二区三区91| 国产精品伊人色| 欧美精品18+| 国产精品私人自拍| 日本成人在线网站| 91美女片黄在线观看91美女| 精品久久久久久久一区二区蜜臀| 亚洲欧美国产三级| 国内一区二区视频| 欧美一三区三区四区免费在线看| 亚洲欧美日韩一区二区| 日韩精品五月天| 色悠久久久久综合欧美99| 久久久国际精品| 日韩激情视频在线观看| proumb性欧美在线观看| 午夜精品久久久| 91麻豆精品视频| 精品毛片乱码1区2区3区| 一区二区在线观看免费| 粉嫩aⅴ一区二区三区四区 | 男人操女人的视频在线观看欧美| 波多野结衣的一区二区三区| 日韩欧美在线不卡| 日韩精品成人一区二区三区| 色婷婷国产精品| 中文字幕一区二区三区色视频| 国模套图日韩精品一区二区| 欧美一区二区三区公司| 日日夜夜免费精品视频| 欧美视频在线一区| 亚洲精品va在线观看| 91在线porny国产在线看| 国产精品初高中害羞小美女文| 国产精品综合久久| 久久久久久久久岛国免费| 精品一区免费av| 精品捆绑美女sm三区| 男女性色大片免费观看一区二区| 337p亚洲精品色噜噜| 日本成人超碰在线观看| 日韩欧美黄色影院| 久久精品国产免费| 久久中文字幕电影|