replaced fseek with fseeko, this should enable large file support

This commit is contained in:
Fufu Fang 2019-04-22 09:50:53 +01:00
parent 07b8382022
commit a02072f548
2 changed files with 11 additions and 21 deletions

View File

@ -234,7 +234,7 @@ static int Meta_read(Cache *cf)
}
fread(&(cf->time), sizeof(long), 1, fp);
fread(&(cf->content_length), sizeof(long), 1, fp);
fread(&(cf->content_length), sizeof(off_t), 1, fp);
fread(&(cf->blksz), sizeof(int), 1, fp);
fread(&(cf->segbc), sizeof(long), 1, fp);
@ -282,7 +282,7 @@ static int Meta_write(const Cache *cf)
}
fwrite(&(cf->time), sizeof(long), 1, fp);
fwrite(&(cf->content_length), sizeof(long), 1, fp);
fwrite(&(cf->content_length), sizeof(off_t), 1, fp);
fwrite(&(cf->blksz), sizeof(int), 1, fp);
fwrite(&(cf->segbc), sizeof(long), 1, fp);
fwrite(cf->seg, sizeof(Seg), cf->segbc, fp);
@ -355,9 +355,9 @@ static long Data_read(const Cache *cf, long offset, long len,
return -1;
}
if (fseek(fp, offset, SEEK_SET)) {
/* fseek failed */
fprintf(stderr, "Data_read(): fseek(): %s\n", strerror(errno));
if (fseeko(fp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_read(): fseeko(): %s\n", strerror(errno));
goto cleanup;
}
@ -405,9 +405,9 @@ static long Data_write(const Cache *cf, long offset, long len,
return -1;
}
if (fseek(fp, offset, SEEK_SET)) {
/* fseek failed */
fprintf(stderr, "Data_write(): fseek(): %s\n", strerror(errno));
if (fseeko(fp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_write(): fseeko(): %s\n", strerror(errno));
goto cleanup;
}
@ -556,6 +556,7 @@ static void Cache_delete(const char *fn)
Cache *Cache_open(const char *fn)
{
int res = 0;
/* Check if both metadata and data file exist */
if (Cache_exist(fn)) {
return NULL;

View File

@ -8,19 +8,8 @@
* \file cache.h
* \brief cache related structures and functions
* \details
* Metadata:
* - We store the metadata and the actual data separately in two
* different folders.
* - The metadata file should follow the following format:
* - file length (long)
* - CURLINFO_FILETIME
* - segment count (int)
* - individual segments (array of seg)
* \note
* - We are using 'long' to store file size, because the offset in fseek() is
* in long, because the way we use the cache system, you cannot seek past
* long. So the biggest file size has to be able to be stored in long. This
* makes this program architecturally dependent, i.e. i386 vs amd64
* separate folders.
*/
/**
@ -34,7 +23,7 @@ typedef uint8_t Seg;
typedef struct {
char *p_url; /**< the filename from the http server */
long time; /**<the modified time of the file */
long content_length; /**<the size of the file */
off_t content_length; /**<the size of the file */
int blksz; /**<the block size of the data file */
long segbc; /**<segment array byte count */
Seg *seg; /**< the detail of each segment */