dedup

data deduplication program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit d44390527612ca94178f33bd6ce15d999c7cd220
parent 705d45cf7f4bf7006081d44dc0a6439ec90dcede
Author: sin <sin@2f30.org>
Date:   Wed, 21 Mar 2018 17:33:20 +0000

Use fstat to get the size of the file

Diffstat:
dedup.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -232,13 +232,21 @@ grow_ent(struct ent *ent, uint64_t nblks) uint64_t storefile_nblks(void) { - return lseek(sfd, 0, SEEK_END) / sizeof(struct blk); + struct stat sb; + + if (fstat(sfd, &sb) == -1) + err(1, "fstat"); + return sb.st_size / sizeof(struct blk); } uint64_t cachefile_nblks(void) { - return lseek(cfd, 0, SEEK_END) / sizeof(struct cache_data); + struct stat sb; + + if (fstat(cfd, &sb) == -1) + err(1, "fstat"); + return sb.st_size / sizeof(struct cache_data); } void @@ -495,7 +503,7 @@ init(void) err(1, "open %s", CACHEF); if (fstat(ifd, &sb) == -1) - err(1, "stat %s", INDEXF); + err(1, "fstat %s", INDEXF); if (sb.st_size != 0) xread(ifd, &enthdr, sizeof(enthdr));