1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/******************************* LICENCE **************************************
* Any code in this file may be redistributed or modified under the terms of
* the GNU General Public Licence as published by the Free Software
* Foundation; version 2 of the licence.
****************************** END LICENCE ***********************************/
/******************************************************************************
* Author:
* Andrew Smith, http://littlesvr.ca/misc/contactandrew.php
*
* Contributors:
*
******************************************************************************/
/******************************************************************************
* 31 dec 2006: these functions turned out to be so heavy on cpu usage that
* performance went down significantly for writing to anything, including
* the local filesystem. So now they don't do anything.
* 07 Jan 2007: deleted the said caching functions
******************************************************************************/
#include <string.h>
#include <stdio.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "bkInternal.h"
#include "bkCache.h"
#include "bkIoWrappers.h"
int wcSeekForward(VolInfo* volInfo, bk_off_t numBytes)
{
bkSeekSet(volInfo->imageForWriting, numBytes, SEEK_CUR);
return 1;
}
int wcSeekSet(VolInfo* volInfo, bk_off_t position)
{
bkSeekSet(volInfo->imageForWriting, position, SEEK_SET);
return 1;
}
bk_off_t wcSeekTell(VolInfo* volInfo)
{
return bkSeekTell(volInfo->imageForWriting);
}
int wcWrite(VolInfo* volInfo, const char* block, size_t numBytes)
{
ssize_t rc;
rc = bkWrite(volInfo->imageForWriting, block, numBytes);
if(rc == -1)
return BKERROR_WRITE_GENERIC;
if(volInfo->writeProgressFunction != NULL)
{
struct timeb timeNow;
ftime(&timeNow);
if(timeNow.time - volInfo->lastTimeCalledProgress.time >= 1 ||
timeNow.millitm - volInfo->lastTimeCalledProgress.millitm >= 100)
{
BkStatStruct statStruct;
double percentComplete;
bkFstat(volInfo->imageForWriting, &statStruct);
percentComplete = (double)statStruct.st_size * 100 /
volInfo->estimatedIsoSize + 1;
/* estimate isn't perfect */
if(percentComplete > 100)
percentComplete = 100;
else if (percentComplete < 0)
percentComplete = 0;
volInfo->writeProgressFunction(volInfo, percentComplete);
volInfo->lastTimeCalledProgress = timeNow;
}
}
return 1;
}
|