Beispiel #1
0
int ext2::Write(FileDescriptorBase *fileDescriptor, void *buff, uint numBytes)
{
	if(numBytes == 0)
		return(0);
	
	FileDescriptor	*tmpDescriptor = reinterpret_cast<FileDescriptor*>(fileDescriptor);
	uint		bytesWritten = 0;
	int		amt;
	
	while(numBytes > bytesWritten)
	{
		amt = MIN(blockSize - tmpDescriptor->blockPosition, numBytes - bytesWritten);

		// copy in the current block
		MemCopy(tmpDescriptor->blockData + tmpDescriptor->blockPosition, reinterpret_cast<uchar*>(buff) + bytesWritten, amt);
		
		// write this block to the disk
		WriteDataBlock(tmpDescriptor->blockNumber, tmpDescriptor, tmpDescriptor->blockData);
		
		// update the positions
		tmpDescriptor->blockPosition += amt;
		tmpDescriptor->filePosition += amt;
		
		if(tmpDescriptor->filePosition > tmpDescriptor->fileInode.size)
			tmpDescriptor->fileInode.size = tmpDescriptor->filePosition;
		
		// we're done with this block and their's another to read in
		if(tmpDescriptor->blockPosition == blockSize &&
		   tmpDescriptor->filePosition < tmpDescriptor->fileInode.size)
		{
			ReadDataBlock(++tmpDescriptor->blockNumber, tmpDescriptor->fileInode.blockPointers, tmpDescriptor->blockData);
			tmpDescriptor->blockPosition = 0;
		}
		
		// we're at the end of the block and the file
		else if(tmpDescriptor->blockPosition == blockSize &&
			tmpDescriptor->filePosition == tmpDescriptor->fileInode.size)
		{
			MemSet(tmpDescriptor->blockData, 0, blockSize);	// set the block to all zeros
			tmpDescriptor->blockPosition = 0;	// reset the block position
			++tmpDescriptor->blockNumber;		// increase the block number
		}

		bytesWritten += amt;
	}
	
	return bytesWritten;
}
Beispiel #2
0
// Write a RECT to the ini file
BOOL CIni::WriteRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rc) const
{
	return WriteDataBlock(lpSection, lpKey, &rc, sizeof(RECT));
}
Beispiel #3
0
// Write a POINT to the ini file
BOOL CIni::WritePoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT pt) const
{
	return WriteDataBlock(lpSection, lpKey, &pt, sizeof(POINT));
}