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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? tfsclean.c

?? 可移到ucos上的文件系統(tǒng)
?? C
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
/* tfsclean.c:
 *	This portion of the tfs code supports the file system cleanup or
 *	defragmentation.  If INCLUDE_TFSCLEAN is set, then the power-safe
 *	cleanup is in place; otherwise, a much simpler and much less robust
 *	cleanup is used.
 *
 *	General notice:
 *	This code is part of a boot-monitor package developed as a generic base
 *	platform for embedded system designs.  As such, it is likely to be
 *	distributed to various projects beyond the control of the original
 *	author.  Please notify the author of any enhancements made or bugs found
 *	so that all may benefit from the changes.  In addition, notification back
 *	to the author will allow the new user to pick up changes that may have
 *	been made by other users after this version of the code was distributed.
 *
 *	Author:	Ed Sutter
 *	email:	esutter@lucent.com		(home: lesutter@worldnet.att.net)
 *	phone:	908-582-2351			(home: 908-889-5161)
 */
#include "config.h"
#include "cpu.h"
#include "stddefs.h"
#include "genlib.h"
#include "tfs.h"
#include "flash.h"
#include "monflags.h"
#if INCLUDE_TFSCLEAN

static ulong	*DefragStateTbl;

static struct tfsdfg tfsdfgmsgtbl[] = {
	{ SECTOR_DEFRAG_INACTIVE,		"DefragInactive" }, 
	{ BUILDING_HEADER_TABLE,		"BuildingHeaderTable" },
	{ HEADER_TABLE_READY,			"HeaderTblReady" },
	{ SECTOR_COPIED_TO_SPARE,		"SectorCopiedToSpare" },
	{ SECTOR_UPDATE_STARTED,		"SectorUpdateStarted" },
	{ SECTOR_UPDATE_COMPLETE,		"SectorUpdateComplete" },
	{ SECTOR_DEFRAG_COMPLETE,		"SectorDefragComplete" },
	{ ERASING_LAST_SECTOR,			"ErasingLastSector" },
	{ TOTAL_DEFRAG_COMPLETE,		"TotalDefragComplete" },
	{ COPY_HDRS_TO_SPARE,			"CopyingHdrsToSpare" },
	{ HDRS_IN_SPARE,				"HeadersInSpare" },
	{ ERASING_DEAD_SECTOR,			"ErasingDeadSector" },
	{ LASTSECTOR_IN_SPARE,			"LastSectorInSpare" },
	{ 0,0 }
};

/* tfsdefragmsg():
 *	Return the  message string that corresponds to the incoming
 *	tfs defragmentation state number.
 */
static char *
tfsdefragmsg(int state)
{
	struct tfsdfg *tdp;

	tdp = tfsdfgmsgtbl;
	while(tdp->msg) {
		if (tdp->state == state)
			return(tdp->msg);
		tdp++;
	}
	return("unknown tfs defrag state");
}

/* getndaoffset():
 *	This function is used by tfsclean when a file that is being defragmented
 *	spans across multiple sectors.  Since the defrag header only contains
 *	the sector number of the starting and ending sectors that the file spans
 *	across, this is used to retrieve the total offset from the start of
 *	the new file (new_destination_address) as each additional sector is
 *	defragmented.
 */
static int
getndaoffset(struct defraghdr *dp,int sec,int *retoffset)
{
	int		i, ssize, offset;
	uchar	*nextbase, *base;

	offset = 0;
	sectortoaddr(dp->bsn,0,&nextbase);
	for(i=dp->bsn;i<sec;i++) {
		if (addrtosector(nextbase,0,&ssize,&base) < 0) {
			printf("getndaoffset (dp=0x%lx,sector=%d) failed\n",(ulong)dp,sec);
			return(TFSERR_MEMFAIL);
		}
		if (i == dp->bsn)
			offset = ssize - dp->bso;
		else if (i == dp->esn)
			offset += (ssize - dp->eso);
		else
			offset += ssize;
		nextbase = base+ssize;
	}
	
	*retoffset = offset;
	return(TFS_OKAY);
}

/* setdefragstate():
 *	The state of the defragmentation process is maintained by a table of
 *	longs that is located at the end of the last sector of TFS space.
 *	Each long represents the state of a TFS sector.  This function simply
 *	modifies the bits in one of the longs to maintain the state of a
 *	particular sector.
 *	Note that the incoming sector number is relative to TFS space, so
 *	tfssector=0 does not represent the first sector of flash, it represents
 *	the first sector of TFS flash.
 */
static int
setdefragstate(tfssector,state,verbose)
int		tfssector, verbose;
ulong	state;
{
	if (verbose > 2)
		printf("  DefragState: %s\n",tfsdefragmsg(state));
	if (tfsflashwrite((ulong *)(&DefragStateTbl[tfssector]),
		(ulong *)&state,sizeof(state)) < 0) {
		printf("setdefragstate(tfssec=%d,state=0x%lx) failed\n",	
			tfssector,state);
		return(TFSERR_FLASHFAILURE);
	}
	return(TFS_OKAY);
}

/* tfsclean():
 *	Defragment the file system. During defragmentation, continually save
 *	enough state so that this function may be interrupted by a reset or
 *	power hit and can recover from it.
 *	Requires that one of the largest sectors of the flash device be designated
 *	as a SPARE sector, to be used only by defragmentation.
 *	Defragmentation state is stored at the end of the last TFS sector, so
 *	it is maintained across reset/powerhit also.
 *	Use of the SPARE sector and flash-based defragmentation state eliminates
 *	the vulnerability of the TFS being corrupted if the system is reset during
 *	defragmentation.  It also eliminates the need for a large amount of RAM
 *	space (as was needed in earlier versions of tfsclean()).
 *
 *	The function is designed to be entered at various points of the 
 *	defragmentation process.  If defragmentation is starting from scratch,
 *	then all arguments (except verbose) will be zero.  If filtot is non-zero
 *	on entry, then this means that tfsclean() must pick up from a previously
 *	started defragmentation and cannot assume that a sane file system
 *	currently exists.
 *
 *	Defragmentation success depends on some coordination with tfsadd()...
 *	Whenever a file is added to TFS, tfsadd() must verify that the space
 *	needed for defrag overhead (defrag state & header tables) will be
 *	available.  Also, tfsadd() must make sure that the defrag overhead will
 *	always fit into one sector (the sector just prior to the spare).
 *	
 */

#if DEFRAG_TEST_ENABLED
int ExitPoint, ExitSector;

#define TEST_EXIT_POINT(pt,sno)	\
	if (ExitPoint == pt) { \
		if ((ExitSector == sno) || (sno == -1)) { \
			printf("!!!!!!!!!!!!! TestExit at point %d, sector %d\n",pt,sno); \
			return(TFS_OKAY); \
		} \
	}
#else
#define TEST_EXIT_POINT(pt,sno)
#endif


static int
_tfsclean(int filtot,ulong *tbl1,struct defraghdr *tbl2,int snum,
	TDEV *tdp,int resetwhendone,int verbose)
{
	int		ftot, fcnt, fsize, dtot, sparesnum, ssize;
	int		firsttfssector, lasttfssector, sectorcheck;
	int		tfssector, sidx, chkstat;
	char	*newaddress, *sbase, *firstdeadfile;
	TFILE	*tfp;
	TINFO	tinfo;
	struct	defraghdr	*defraghdrtbl, *dp, defrag;
	ulong	*lp;
	
	/* If incoming TFS device pointer is NULL, error... */
	if (!tdp)
		return(TFSERR_BADARG);

	if ((verbose > 1) || (tfsTrace > 0)) {
		printf("tfsclean(%d,0x%lx,0x%lx,%x,%s,%d,%d)\n",
			filtot,(ulong)tbl1,(ulong)tbl2,snum,
			tdp->prefix,resetwhendone,verbose);
	}
	else if (verbose)
		printf("TFS cleanup: %s\n",tdp->prefix);

	/* Do some initial configuration retrieval... */
	/* Determine the first and last sector within TFS... */
	if (addrtosector((char *)tdp->start,&firsttfssector,&ssize,
		(uchar **)&sbase) < 0)
		return(TFSERR_MEMFAIL);
	lasttfssector = firsttfssector + tdp->sectorcount - 1;
	if (addrtosector((char *)tdp->end,&sectorcheck,0,0) < 0)
		return(TFSERR_MEMFAIL);
	if (lasttfssector != sectorcheck) {
		printf("%s: TFS SECTORCOUNT does not match TFSSTART <-> TFSEND\n",
			tdp->prefix);
		printf("First TFS sector = %d\n",firsttfssector);
		printf("Last TFS sector  = %d\n",sectorcheck);
		return(TFSERR_MEMFAIL);
	}

	/* Store away information about spare sector... */
	if (addrtosector((char *)tdp->spare,&sparesnum,0,0) < 0)
		return(TFSERR_MEMFAIL);

	if (filtot) {
		sidx = snum;
		ftot = filtot;
		defraghdrtbl = tbl2;
		DefragStateTbl = tbl1;
		tfssector = firsttfssector+snum;
		printf("Continuing defragmentation at sector %3d ",tfssector);
		printf("(state=%s)...\n",tfsdefragmsg(DefragStateTbl[snum]));

		if (sectortoaddr(tfssector,&ssize,(uchar **)&sbase) == -1)
			return(TFSERR_MEMFAIL);

		switch(DefragStateTbl[snum]) {
			case BUILDING_HEADER_TABLE:
				goto building_hdr;
			case HEADER_TABLE_READY:
				goto hdr_table_ready;
			case COPY_HDRS_TO_SPARE:
				goto copy_hdrs_to_spare;
			case HDRS_IN_SPARE:
				goto hdrs_in_spare;
			case LASTSECTOR_IN_SPARE:
				goto lastsector_in_spare;
			case SECTOR_COPIED_TO_SPARE:
				goto sector_copied_to_spare;
			case SECTOR_UPDATE_STARTED:
				goto sector_update_started;
			case SECTOR_UPDATE_COMPLETE:
				goto sector_update_complete;
			case SECTOR_DEFRAG_COMPLETE:
				goto sector_defrag_complete;
			case ERASING_DEAD_SECTOR:
				goto erasing_dead_sector;
			case ERASING_LAST_SECTOR:
				goto erasing_last_sector;
			default:
				return(TFSERR_BADARG);
		}
	}

	/* Determine how many "live" files exist so that we can determine
	 * where to start building the defragstate[] and defraghdrtbl[] tables.
	 */
	tfp = (TFILE *)tdp->start;
	ftot = dtot = 0;
	while(validtfshdr(tfp)) {
		if (TFS_FILEEXISTS(tfp))
			ftot++;
		else 
			dtot++;
		tfp = nextfp(tfp,tdp);
	}

	/* If dtot is 0, then all TFS file headers indicate that there is no
	 * need to clean up the flash.  There is still a chance that the flash
	 * (after the end of the last file in TFS) may not be erased, so check
	 * for that also...
	 */
	if (dtot == 0) {
		printf("No dead files in %s.\n",tdp->prefix);
		if (tfsflasherased(tdp,verbose))
			return(0);
		else
			printf("Running defrag to cleanup...\n");
	}

	/* If ftot is 0, then there are no valid files in the flash, so simply
	 * erase all TFS flash space and return...
	 */
	if (ftot == 0) {
		if (verbose)
			printf("No active files detected, erasing all %s flash...\n",
				tdp->prefix);
		_tfsinit(tdp);
		return(0);
	}

	tfsmemuse(tdp,&tinfo,0);
	if ((verbose) || (!MFLAGS_NODEFRAGPRN())) {
		printf("%s with %d dead file%s (%d bytes) removed.\n",
		    "Defragmenting file system",dtot,dtot>1 ? "s":"",
			tinfo.deadovrhd+tinfo.deaddata);
	}

	DefragStateTbl = (ulong *)(tdp->end+1);
	DefragStateTbl -= tdp->sectorcount;
	defraghdrtbl = (struct defraghdr *)(DefragStateTbl) - ftot;

	/* Verify that the space to be written to for the
	 * defrag stuff is erased...
	 */
	lp = (ulong *)defraghdrtbl;
	while(lp < (ulong *)tdp->end) {
		if (*lp++ != (ulong)ERASED32) {
			printf("Defragmentation table space (0x%lx-0x%lx) not erased.\n",
				(ulong)defraghdrtbl,(ulong)(tdp->end));
			return(TFSERR_FLASHFAILURE);
		}
	}

	TEST_EXIT_POINT(1,-1);

	/* Erase SPARE sector. */
	if (tfsflasherase(sparesnum) < 0) {
		printf("Flash SPARE sector erase failed\n");
		return(TFSERR_FLASHFAILURE);
	}

	TEST_EXIT_POINT(2,-1);

	if (verbose > 2) {
		printf("Building defrag header for %d files...\n",ftot);
		printf("DefragStateTbl=0x%lx\n",(ulong)DefragStateTbl);
		printf("defraghdrtbl=0x%lx\n",(ulong)defraghdrtbl);
	}

	/* Mark the defragmentation state table to indicate that we are */
	/* about to begin defragmentation. */
	if (setdefragstate(0,BUILDING_HEADER_TABLE,verbose) != TFS_OKAY)
		return(TFSERR_FLASHFAILURE);

building_hdr:
	firstdeadfile = (char *)0;
	tfp = (TFILE *)tdp->start;
	while(validtfshdr(tfp)) {
		if (TFS_DELETED(tfp)) {
			firstdeadfile = (char *)tfp;
			break;
		}
		tfp = nextfp(tfp,tdp);
	}
	
	tfp = (TFILE *)tdp->start;
	newaddress = (char *)tdp->start;
	fcnt = 0;
	if (verbose > 2)
		printf("\nDEFRAGMETATION HEADER DATA:\n");
	while(validtfshdr(tfp)) {
		if (TFS_FILEEXISTS(tfp)) {
			uchar	*base, *eof;
			int		size, slot;
			struct	tfsdat *slotptr;

			defrag.fhdr = *tfp;
			if (addrtosector((char *)tfp,&defrag.bsn,0,&base) < 0)
				return(TFSERR_MEMFAIL);
			defrag.bso = (uchar *)tfp - base;
			eof = (uchar *)(tfp+1)+TFS_SIZE(tfp)-1;
			if (addrtosector((char *)eof,&defrag.esn,0,&base) < 0)
				return(TFSERR_MEMFAIL);
			defrag.fdf = firstdeadfile;
			defrag.eso = eof - base + 1;
			defrag.nda = newaddress;
			defrag.phc = ERASED32;

			/* If the file is currently opened, adjust the base address. */
			slotptr = tfsSlots;
			for (slot=0;slot<TFS_MAXOPEN;slot++,slotptr++) {
				if (slotptr->offset != -1) {
					if (slotptr->base == (uchar *)(TFS_BASE(tfp))) {
						slotptr->base = (uchar *)(newaddress+TFSHDRSIZ);
						if (verbose)
							printf("Base of opened file '%s' shifted from 0x%lx to 0x%lx\n",
								TFS_NAME(tfp),(ulong)(TFS_BASE(tfp)),
								(ulong)(slotptr->base));
					}
				}
			}
			if (verbose > 2) {
				printf(" File %s:\n",TFS_NAME(tfp));
				printf(" bsn=%3d,bso=0x%08x,",defrag.bsn,defrag.bso);
				printf("esn=%3d,eso=0x%08x,",defrag.esn,defrag.eso);
				printf("nda=0x%08lx,fdf=0x%08lx\n",

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人午夜电影小说| 欧美一卡二卡在线| 成人深夜在线观看| 激情深爱一区二区| 蜜臀av一区二区三区| 欧美亚一区二区| 色88888久久久久久影院野外| 99免费精品视频| 91免费版在线看| 91蜜桃视频在线| 欧美丝袜自拍制服另类| 欧洲色大大久久| 欧美日韩视频在线观看一区二区三区| 精品视频123区在线观看| 欧美亚洲图片小说| 欧美日韩性生活| 日韩一区二区在线播放| 日韩午夜激情免费电影| 精品国产一区二区三区久久影院| 日韩欧美国产午夜精品| 欧美精品一区二区在线观看| 国产午夜精品一区二区 | 在线成人午夜影院| 91精品国产色综合久久不卡蜜臀| 日韩三级精品电影久久久| 欧美精品一区二区蜜臀亚洲| 国产喷白浆一区二区三区| 国产精品三级av| 一区二区免费视频| 日韩国产欧美在线播放| 国内成人免费视频| 成人免费看黄yyy456| 在线视频国内一区二区| 91精品国产91热久久久做人人| 精品精品国产高清一毛片一天堂| 国产亚洲女人久久久久毛片| 中文字幕五月欧美| 性欧美疯狂xxxxbbbb| 极品少妇xxxx精品少妇| 波多野结衣的一区二区三区| 欧美日韩亚洲综合一区| 精品av综合导航| 亚洲视频网在线直播| 亚洲综合视频在线| 丝袜亚洲另类欧美| 激情综合网最新| 91免费视频网| 日韩欧美另类在线| 成人欧美一区二区三区小说| 午夜精品久久久| 国产成人一区二区精品非洲| 色哟哟在线观看一区二区三区| 欧美一区二区视频免费观看| 国产精品丝袜黑色高跟| 午夜精品一区二区三区三上悠亚| 国产精品中文字幕欧美| 欧美日韩在线电影| 国产欧美一区二区精品性色| 午夜精品一区在线观看| 成人视屏免费看| 欧美一区二区三区啪啪| 中文字幕一区二区视频| 麻豆久久久久久久| 一本色道久久综合精品竹菊| 欧美成人三级在线| 一区二区三区**美女毛片| 国产精品99久久久久久似苏梦涵 | 亚洲精品大片www| 国产伦精一区二区三区| 欧美视频一二三区| 中文字幕精品三区| 久久电影国产免费久久电影| 在线精品视频免费播放| 国产亚洲精品免费| 日本美女一区二区三区视频| 色综合久久天天综合网| 国产欧美日韩激情| 免费成人在线视频观看| 欧美色男人天堂| 亚洲天天做日日做天天谢日日欢 | 4438成人网| 尤物在线观看一区| 成人午夜视频在线| 精品久久久久久亚洲综合网 | 一本大道av一区二区在线播放 | 精品在线观看视频| 欧美日韩国产免费一区二区| 亚洲男同性视频| 国产91丝袜在线播放| 精品日韩欧美一区二区| 青青草原综合久久大伊人精品| 欧洲av在线精品| 亚洲欧美欧美一区二区三区| av综合在线播放| 国产精品久久久久影院| 国产成人综合亚洲网站| 久久久久久久性| 国产麻豆午夜三级精品| 26uuu色噜噜精品一区二区| 日韩不卡一区二区三区| 欧美狂野另类xxxxoooo| 午夜伦理一区二区| 欧美色倩网站大全免费| 亚洲18女电影在线观看| 欧美日韩一级视频| 亚洲成人黄色小说| 欧美日本高清视频在线观看| 亚洲va国产天堂va久久en| 欧美网站大全在线观看| 亚洲狠狠爱一区二区三区| 欧美亚洲愉拍一区二区| 亚洲一区二区在线播放相泽| 欧美日韩视频专区在线播放| 午夜不卡av免费| 欧美一级淫片007| 裸体在线国模精品偷拍| 2020国产精品| 国产高清亚洲一区| 国产精品美女一区二区| 91女神在线视频| 亚洲专区一二三| 91精品国模一区二区三区| 美脚の诱脚舐め脚责91| 2欧美一区二区三区在线观看视频| 国产美女久久久久| 一区二区中文视频| 在线视频国产一区| 日韩电影一二三区| 精品国产sm最大网站免费看| 成人夜色视频网站在线观看| 亚洲日本一区二区三区| 欧美日韩精品二区第二页| 久久国产尿小便嘘嘘| 国产欧美日韩三级| 色狠狠色狠狠综合| 日韩av一区二区在线影视| 欧美精品一区二区三区高清aⅴ| 丁香婷婷综合色啪| 亚洲一区二区三区在线播放| 欧美一级艳片视频免费观看| 国产成人av影院| 亚洲综合一区二区精品导航| 91精品国产福利在线观看| 国产麻豆一精品一av一免费| 亚洲啪啪综合av一区二区三区| 欧美日韩久久不卡| 国产一区二区三区国产| 亚洲另类春色国产| 欧美不卡视频一区| 99国产精品久| 美女爽到高潮91| 亚洲欧洲日韩综合一区二区| 欧美精品九九99久久| 国产精品一线二线三线精华| 一区二区三区高清在线| 精品久久五月天| 91麻豆国产精品久久| 免费成人在线观看视频| 中文字幕人成不卡一区| 欧美一级夜夜爽| 色婷婷精品久久二区二区蜜臂av| 免费欧美在线视频| 亚洲欧美福利一区二区| 欧美tk丨vk视频| 欧美在线观看视频在线| 国产精品亚洲一区二区三区在线 | 国产一区福利在线| 亚洲国产成人精品视频| 国产欧美一区二区精品忘忧草| 欧美欧美欧美欧美首页| 成人av在线资源网站| 蜜臀av国产精品久久久久| 亚洲免费视频成人| 久久一区二区视频| 777xxx欧美| 色综合天天视频在线观看| 国产精品一区二区免费不卡| 五月激情丁香一区二区三区| 亚洲欧洲色图综合| 久久你懂得1024| 欧美一级二级三级蜜桃| 91麻豆国产精品久久| 懂色av中文一区二区三区| 老汉av免费一区二区三区| 亚洲成av人片| 一区二区欧美国产| **欧美大码日韩| 亚洲国产精品传媒在线观看| 日韩欧美激情一区| 欧美精品高清视频| 日本精品一级二级| 97aⅴ精品视频一二三区| 国产精选一区二区三区| 美女视频黄 久久| 青青草国产成人99久久| 首页亚洲欧美制服丝腿| 亚洲亚洲精品在线观看| 亚洲精品精品亚洲| 亚洲美女区一区| 亚洲三级理论片|