Final Year Project:
Using Linux Filesystems Under Windows
Chris Bryden
BEng. Electronics and Software Engineering
School of Computer Science
University of Birmingham
47
false the FILE_EXIST error is returned. If the fOwrite flag is true, the function
proceeds to copy the new file regardless of the destination file already existing,
overwriting the destination file. The destination file is opened for writing using the
standard C fopen function.
The blocks in the block list for the source file are then read using the
ReadBlock function and written to the destination file using the fwrite function. A
variable ulBytesLeft records the number of bytes left to copy, and is
dexcremented by a block size every time a block is copied. If the number of
bytes left to copy is less than a full block, the fwrite function only writes the exact
number of bytes left using the fwrite command. This is to ensure that there is no
garbage copied to the destination file from the slack space on the source file.
This is implemented as shown in the code section shown below:
The function then closes the destination file and returns 0 if the file was
copied correctly. This function forms part of the interface between layers 1 and 2.
while((lpBlocksBuff[iBlk] > 0) && (ulOffset/ulBlkSize < Inode.i_blocks))
{
ReadBlock(bDrive, bPart, lpBlocksBuff[iBlk], lpBuff);
if(ulBytesLeft >= ulBlkSize)
fwrite(lpBuff,ulBlkSize,1,pDest);
else
fwrite(lpBuff,ulBytesLeft,1,pDest);
ulBytesLeft -= ulBlkSize;
++iBlk;
}