Ejemplo n.º 1
0
int preProc(PicNodeList* pPicNodeList, char* path){
    
	int iResult = -1;
	int num;
    
	//test if the path is a directory
	if(access(path,F_OK) != 0 || testdir(path) == 0)
	{
		printf("[%s] is not a valid directory\n", path);
		return -1;
	}
    
	if(getFileNum(path, &num) != 0){
		printf("Error in getFileNum()\n");
		return -1;
	}
    
	pPicNodeList->numOfImgs = num;
    
	pPicNodeList->picNode = (PicNode *)malloc(num*sizeof(PicNode));
    
	memset(pPicNodeList->picNode, 0, num*sizeof(PicNode));
    
	if(setPicNodeList(path, pPicNodeList) != 0){
		printf("Error in pPicNodeList()\n");
		free(pPicNodeList->picNode);
		return -1;
	}
    
    return 0;
}
Ejemplo n.º 2
0
/****************************************************************************
Desc:	This is a private method that will truncate the spill file back to
		the specified size.
****************************************************************************/
RCODE F_MultiFileHdl::truncateFile(
	FLMUINT64		ui64NewSize)
{
	RCODE				rc = NE_FLM_OK;
	FLMUINT			uiFileNum = getFileNum( ui64NewSize);
	IF_FileHdl *	pFileHdl;

	if( RC_BAD( rc = getFileHdl( uiFileNum, TRUE, &pFileHdl)))
	{
		goto Exit;
	}

	if (RC_BAD( rc = pFileHdl->truncateFile( getFileOffset( ui64NewSize))))
	{
		goto Exit;
	}

Exit:

	return( rc);
}
Ejemplo n.º 3
0
/****************************************************************************
Desc: Writes data to the file
****************************************************************************/
RCODE F_MultiFileHdl::write(
	FLMUINT64	ui64Offset,				// Offset
	FLMUINT		uiLength,				// Number of bytes to write.
	void *		pvBuffer,				// Buffer that contains bytes to be written
	FLMUINT *	puiBytesWritten)		// Number of bytes written.
{
	RCODE				rc = NE_FLM_OK;
	FLMUINT			uiFileNum = getFileNum( ui64Offset);
	FLMUINT			uiFileOffset = getFileOffset( ui64Offset);
	FLMUINT			uiTmp;
	FLMUINT			uiTotalBytesWritten = 0;
	FLMUINT			uiBytesToWrite;
	FLMUINT			uiMaxWriteLen;
	IF_FileHdl *	pFileHdl;

	// Don't allow zero-length writes

	f_assert( uiLength);

	// Write to the data file(s), moving to new files as needed.

	for( ;;)
	{
		if( RC_BAD( rc = getFileHdl( uiFileNum, TRUE, &pFileHdl)))
		{
			goto Exit;
		}

		uiMaxWriteLen = m_uiMaxFileSize - uiFileOffset;
		f_assert( uiMaxWriteLen != 0);
		uiBytesToWrite = uiLength >= uiMaxWriteLen ? uiMaxWriteLen : uiLength;

		uiTmp = 0;
		rc = pFileHdl->write( uiFileOffset, uiBytesToWrite, pvBuffer, &uiTmp);

		uiTotalBytesWritten += uiTmp;
		uiLength -= uiTmp;
		ui64Offset += uiTmp;

		if( RC_BAD( rc))
		{
			goto Exit;
		}

		if( !uiLength)
		{
			break;
		}

		// Set up for next write

		pvBuffer = ((FLMBYTE *)pvBuffer) + uiTmp;
		uiFileNum = getFileNum( ui64Offset);
		uiFileOffset = getFileOffset( ui64Offset);
	}

Exit:

	if( ui64Offset > m_ui64EOF)
	{
		m_ui64EOF = ui64Offset;
	}

	*puiBytesWritten = uiTotalBytesWritten;
	return( rc);
}
Ejemplo n.º 4
0
/****************************************************************************
Desc: Reads data from the file
****************************************************************************/
RCODE F_MultiFileHdl::read(
	FLMUINT64	ui64Offset,				// Offset to begin reading
	FLMUINT		uiLength,				// Number of bytes to read
	void *		pvBuffer,				// Buffer
	FLMUINT *	puiBytesRead)			// [out] Number of bytes read
{
	RCODE				rc = NE_FLM_OK;
	FLMUINT			uiFileNum = getFileNum( ui64Offset);
	FLMUINT			uiFileOffset = getFileOffset( ui64Offset);
	FLMUINT			uiTmp;
	FLMUINT			uiTotalBytesRead = 0;
	FLMUINT			uiBytesToRead;
	FLMUINT			uiMaxReadLen;
	IF_FileHdl *	pFileHdl;

	// Handle the case of a 0-byte read

	if( !uiLength)
	{
		if( ui64Offset >= m_ui64EOF)
		{
			rc = RC_SET( NE_FLM_IO_END_OF_FILE);
		}
		goto Exit;
	}

	// Read the data file(s), moving to new files as needed.

	for( ;;)
	{
		if( ui64Offset >= m_ui64EOF)
		{
			rc = RC_SET( NE_FLM_IO_END_OF_FILE);
			goto Exit;
		}

		uiMaxReadLen = m_uiMaxFileSize - uiFileOffset;
		f_assert( uiMaxReadLen != 0);
		uiTmp = (uiLength >= uiMaxReadLen ? uiMaxReadLen : uiLength);
		uiBytesToRead = (((FLMUINT64)uiTmp > (FLMUINT64)(m_ui64EOF - ui64Offset))
								? (FLMUINT)(m_ui64EOF - ui64Offset)
								: uiTmp);

		if( RC_BAD( rc = getFileHdl( uiFileNum, FALSE, &pFileHdl)))
		{
			if( rc == NE_FLM_IO_PATH_NOT_FOUND)
			{
				// Handle the case of a sparse file by filling the unread
				// portion of the buffer with zeros.

				f_memset( pvBuffer, 0, uiBytesToRead);
				uiTmp = uiBytesToRead;
				rc = NE_FLM_OK;
			}
			else
			{
				goto Exit;
			}
		}
		else
		{
			if( RC_BAD( rc = pFileHdl->read( uiFileOffset, uiBytesToRead,
				pvBuffer, &uiTmp)))
			{
				if( rc == NE_FLM_IO_END_OF_FILE)
				{
					// Handle the case of a sparse file by filling the unread
					// portion of the buffer with zeros.

					f_memset( &(((FLMBYTE *)(pvBuffer))[ uiTmp]),
						0, (FLMUINT)(uiBytesToRead - uiTmp));
					uiTmp = uiBytesToRead;
					rc = NE_FLM_OK;
				}
				else
				{
					goto Exit;
				}
			}
		}

		uiTotalBytesRead += uiTmp;
		uiLength -= uiTmp;
		if( !uiLength)
		{
			break;
		}

		// Set up for next read

		pvBuffer = ((FLMBYTE *)pvBuffer) + uiTmp;
		ui64Offset += uiTmp;
		uiFileNum = getFileNum( ui64Offset);
		uiFileOffset = getFileOffset( ui64Offset);
	}

Exit:

	*puiBytesRead = uiTotalBytesRead;
	return( rc);
}
Ejemplo n.º 5
0
/****************************************************************************
Desc: Opens an existing 64-bit file
****************************************************************************/
RCODE F_MultiFileHdl::openFile(
	const char *	pszPath)
{
	RCODE					rc = NE_FLM_OK;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();
	IF_DirHdl *			pDir = NULL;
	FLMUINT				uiTmp;
	FLMUINT				uiHighFileNum = 0;
	FLMUINT64			ui64HighOffset = 0;

	if( m_bOpen)
	{
		rc = RC_SET_AND_ASSERT( NE_FLM_FAILURE);
		goto Exit;
	}

	if( RC_BAD( pFileSystem->doesFileExist( pszPath)) ||
		!pFileSystem->isDir( pszPath))
	{
		rc = RC_SET( NE_FLM_IO_PATH_NOT_FOUND);
		goto Exit;
	}

	f_strcpy( m_szPath, pszPath);

	// Create the lock file

	if( RC_BAD( rc = createLockFile( m_szPath)))
	{
		goto Exit;
	}

	// Need to determine the current EOF

	if( RC_BAD( rc = pFileSystem->openDir( m_szPath, (char *)"*.64", &pDir)))
	{
		goto Exit;
	}

	// Find all data files to determine the EOF

	for( rc = pDir->next(); !RC_BAD( rc); rc = pDir->next())
	{
		if( RC_OK( getFileNum( pDir->currentItemName(), &uiTmp)))
		{
			if( uiTmp >= uiHighFileNum)
			{
				uiHighFileNum = uiTmp;
				ui64HighOffset = pDir->currentItemSize();
			}
		}
	}
	rc = NE_FLM_OK;

	m_ui64EOF = (((FLMUINT64)uiHighFileNum) * m_uiMaxFileSize) + ui64HighOffset;
	m_bOpen = TRUE;

Exit:

	if( pDir)
	{
		pDir->Release();
	}

	// Release the lock file

	if( RC_BAD( rc))
	{
		releaseLockFile( m_szPath, FALSE);
	}

	return( rc);
}