Example #1
0
/*****************************************************************************
  Function:
	BOOL MPFSSeek(MPFS_HANDLE hMPFS, DWORD dwOffset, MPFS_SEEK_MODE tMode)

  Description:
	Moves the current read pointer to a new location.
	
  Precondition:
	The file handle referenced by hMPFS is already open.

  Parameters:
	hMPFS - the file handle to seek with
	dwOffset - offset from the specified position in the specified direction
	tMode - one of the MPFS_SEEK_MODE constants

  Returns:
	TRUE - the seek was successful
	FALSE - either the new location or the handle itself was invalid
  ***************************************************************************/
BOOL MPFSSeek(MPFS_HANDLE hMPFS, DWORD dwOffset, MPFS_SEEK_MODE tMode)
{
	DWORD temp;
	
	// Make sure a valid file is open
	if(hMPFS > MAX_MPFS_HANDLES)
		return FALSE;
	if(MPFSStubs[hMPFS].addr == MPFS_INVALID)
		return FALSE;

	switch(tMode)
	{
		// Seek offset bytes from start
		case MPFS_SEEK_START:
			temp = MPFSGetSize(hMPFS);
			if(dwOffset > temp)
				return FALSE;
			
			MPFSStubs[hMPFS].addr = MPFSGetStartAddr(hMPFS) + dwOffset;
			MPFSStubs[hMPFS].bytesRem = temp - dwOffset;
			return TRUE;
		
		// Seek forwards offset bytes
		case MPFS_SEEK_FORWARD:
			if(dwOffset > MPFSStubs[hMPFS].bytesRem)
				return FALSE;
			
			MPFSStubs[hMPFS].addr += dwOffset;
			MPFSStubs[hMPFS].bytesRem -= dwOffset;
			return TRUE;
		
		// Seek backwards offset bytes
		case MPFS_SEEK_REWIND:
			temp = MPFSGetStartAddr(hMPFS);
			if(MPFSStubs[hMPFS].addr < temp + dwOffset)
				return FALSE;
			
			MPFSStubs[hMPFS].addr -= dwOffset;
			MPFSStubs[hMPFS].bytesRem += dwOffset;
			return TRUE;
		
		// Seek so that offset bytes remain in file
		case MPFS_SEEK_END:
			temp = MPFSGetSize(hMPFS);
			if(dwOffset > temp)
				return FALSE;
			
			MPFSStubs[hMPFS].addr = MPFSGetEndAddr(hMPFS) - dwOffset;
			MPFSStubs[hMPFS].bytesRem = dwOffset;
			return TRUE;
		
		default:
			return FALSE;
	}
}
Example #2
0
/*****************************************************************************
  Function:
    bool MPFS_EOF( uintptr_t handle )

  Description:
    Returns if the present file pointer already reached end of file?

  Precondition:
    None

  Parameters:
    handle - a valie handle to the file

  Returns:
    End of file     - true
    Not end of file - false
*/
bool MPFS_EOF( uintptr_t handle )
{
    MPFS_HANDLE hMPFS = ((MPFS_HANDLE )handle);
    volatile unsigned long len, position;

    len = MPFSGetSize ( hMPFS );
    position = MPFSGetPosition ( hMPFS );

    if(position == len)
        return 1;
    else
        return 0;
//    return (position == len ? 1 : 0);
}
Example #3
0
/*****************************************************************************
  Function:
    uint32_t MPFS_GetSize ( uintptr_t handle )

  Description:
    Obtains the size of the file

  Precondition:
    None

  Parameters:
    handle - a valie handle to the file

  Returns:
    The size of file.
*/
uint32_t MPFS_GetSize ( uintptr_t handle )
{
    MPFS_HANDLE address = ((MPFS_HANDLE )handle);

    return (MPFSGetSize ( address ));
}