Ejemplo n.º 1
0
U32 FS__FlusCache(FS_FILE *handle){
   U32 i,tempOffset;
   tempOffset=handle->Offset;
   handle->Offset=(FS__pDevInfo[0].pDevCacheInfo)[handle->CacheId].fileOldOffset;
   i=FS_FWrite((FS__pDevInfo[0].pDevCacheInfo)[handle->CacheId].SecsDatabuff,1,
                            (FS__pDevInfo[0].pDevCacheInfo)[handle->CacheId].CacheOffset,handle);
   handle->Offset=tempOffset;
   handle->dirty=0;
   (FS__pDevInfo[0].pDevCacheInfo)[handle->CacheId].fileOldOffset=handle->Offset;
   (FS__pDevInfo[0].pDevCacheInfo)[handle->CacheId].CacheOffset=0;
   return i;
} 
Ejemplo n.º 2
0
FS_i32 FS_FileCpy(const TCHAR*path1, const TCHAR*path2)		//path1: souce file    path2: destination file
{
	FS_FILE *src;
	FS_FILE * dst;
	FS_i32 read_size,write_size;
	FS_i32 src_size, dst_size;
	struct stat buf;
	_DISK_INFO info;
	FS_i8 *buffer;

	if( !strcmp((const char *)path1, (const char *)path2) )
	{
		FS_Debug("FSW_ERROR:can not copy a file to itself\r\n");
		return 0;
	}
	
	if( -1 == FS_Stat( path1, &buf ) ) return 0;

	src_size = buf.st_size;

	if(GetDiskInfo(path2,&info)==-1)
	{
		FS_Debug("FSW_ERROR:getdiskinfo err\r\n");
		return 0;
	}
		
	if(src_size > info.free_size)
	{
		FS_Debug("there is no enough space on the flash!\n\r");
		return 0;
	}

	src = FS_FOpen(path1, FA_READ|FA_OPEN_EXISTING);
	if(0 == src)
	{
		FS_Debug("FSW_ERROR:cannot open the source file\r\n");
		return 0;
	}

	dst = FS_FOpen(path2, FA_CREATE_ALWAYS|FA_WRITE);
	if(0 == dst)
	{
		FS_Debug("FSW_ERROR:cannot create the distance file\r\n");
		FS_FClose(src);
		return 0;
	}

	buffer=Q_Mallco(COPY_FILE_BUFFER);

	do{		
		read_size = FS_FRead(buffer, COPY_FILE_BUFFER,1,src);
		write_size = FS_FWrite(buffer, read_size,1,dst);

		if(write_size < read_size)
		{
			FS_Debug("FSW_ERROR:file write error\r\n");
			Q_Free(buffer);
			goto CP_FILE_ERROR;
		}
	}while(read_size == COPY_FILE_BUFFER);

	Q_Free(buffer);
	FS_FClose(src);
	FS_FClose(dst);

	if( -1 == FS_Stat( path2, &buf ) ) return 0;

	dst_size = buf.st_size;

	if(dst_size < src_size)
	{
		FS_Debug("there is an unkown flash operation during the copyfile!\n\r");
		FS_Unlink(path2);
		return 0;
	}

	return 1;

CP_FILE_ERROR:
	FS_FClose(src);
	FS_FClose(dst);
	return 0;

}