Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FPT next free block
Message
From
19/07/2003 06:38:49
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00811749
Message ID:
00811757
Views:
13
>Hi All,
>
>We occasionally encounter a problem with an FPT file which will cause an error when the relevant table is opened from the EXE but when opened from the command window appears OK. Oddly, just the act of opening in the command window automatically means that subsequent access from the EXE is OK.
>
>I've discovered that opening such a damaged table from the command window changes the value of the third byte of the FPT header (part of the 'Location of next free block') - so it appears there is some sort of automatic correction going on.
>
>I figure if VFP can work out what the next free block value should be then I should be able to do the same but can't find any info on this (except what VFP help says on 'Memo file structure'). Anyone know how it's done ?
>
>Regards,
>Viv

Viv,

Have a look at this http://www.e-bachmann.dk/computing/databases/xbase/fpt.html#FPT_STRUCT

As to the program below, I just did minor testing. Haven't actually fixed anything

Maybe you can do a test on your file and confirm that it works ? I'm just lazy ;-)
*---------------------------------------------------------------------------
&& see http://www.e-bachmann.dk/computing/databases/xbase/fpt.html#FPT_STRUCT
function FPT_Fix(FileName)
	
	local fd, FileSize, BlockLen, NextBlock, hdrOnDisk, hdr
	
	fd = fopen(FileName, F_READWRITE_UNBUFF)
	
	do case
	case fd < 0
		wait window 'cannot open ' + FileName
                return FALSE
	
	otherwise
		FileSize = fseek(fd, 0, 2)
		=fseek(fd, 6, 0)
		BlockLen = fread(fd,2)
		BlockLen = CharToBinBE(BlockLen)
		=fseek(fd, 0, 0)
		hdrOnDisk = fread(fd, 4)
	
		NextBlock = ceiling(FileSize / BlockLen)
		hdr = BinToCharBE(NextBlock)
		
		do case
		case hdrOnDisk == hdr
			&& all ok
		
		otherwise
			assert FALSE message 'about to repair'
		 	=fseek(fd, 0, 0)
		 	=fwrite(fd, hdr)
		 endcase
	
		=fclose(fd)
	endcase
	
endfunc
*---------------------------------------------------------------------------
function CharToBinBE(s)	&& BigEndian
	local n
	n = ctobin(s)
	
	return n + iif(n<=0, 256^len(s)/2, -(256^len(s)/2))
endfunc
*---------------------------------------------------------------------------
function BinToCharBE(n, nBytes)	&& BigEndian

	nBytes = iif(empty(nBytes), 4, nBytes)
	
	return bintoc(n + iif(n<=0, 256^nBytes/2, -(256^nBytes/2)), nBytes)
	
endfunc
*---------------------------------------------------------------------------	
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform