diff --git a/README b/README index c8afd69..7a95fd2 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -### Compile +### Compile on Linux gcc -Wall -c utils.c gcc -Wall -c f3write.c @@ -6,11 +6,20 @@ gcc -Wall -c f3read.c gcc -o f3write utils.o f3write.o -lm gcc -o f3read utils.o f3read.o +### Compile on Mac + +gcc -Wall -DAPPLE_MAC -c utils.c +gcc -Wall -DAPPLE_MAC -c f3write.c +gcc -Wall -DAPPLE_MAC -c f3read.c +gcc -o f3write utils.o f3write.o -lm +gcc -o f3read utils.o f3read.o + ### Use example ./f3write /media/5EBD-5C80/ ./f3read /media/5EBD-5C80/ -Please replace "/media/5EBD-5C80/" with appropriate path. +Please replace "/media/5EBD-5C80/" with the appropriate path. +USB devices are mounted in "/Volumes" on Macs. ### For more information see http://oss.digirati.com.br/f3/ diff --git a/f3write.c b/f3write.c index 6bbbd87..05d2283 100644 --- a/f3write.c +++ b/f3write.c @@ -218,13 +218,19 @@ static void measure(int fd, struct flow *fw) } if (fw->progress) { - double percent = (double)fw->total_written * 100 / - fw->total_size; /* Instantaneous speed. */ double inst_speed = (double)fw->blocks_per_delay * fw->block_size * 1000 / fw->delay_ms; const char *unit = adjust_unit(&inst_speed); + double percent; + /* The following shouldn't be necessary, but sometimes + * the initial free space isn't exactly reported + * by the kernel; this issue has been seen on Macs. + */ + if (fw->total_size < fw->total_written) + fw->total_size = fw->total_written; + percent = (double)fw->total_written * 100 / fw->total_size; erase(fw->erase); fw->erase = printf("%.2f%% -- %.2f %s/s", percent, inst_speed, unit); @@ -330,21 +336,19 @@ static int fill_fs(const char *path, int progress) int i, fine; free_space = get_freespace(path); + pr_freespace(free_space); if (free_space <= 0) { printf("No space!\n"); return 1; } - pr_freespace(free_space); init_flow(&fw, free_space, progress); i = 0; fine = 1; - while (fine && free_space > 0) { - size_t size = free_space >= GIGABYTES ? GIGABYTES : free_space; - fine = create_and_fill_file(path, i, size, &fw); - free_space -= size; + do { + fine = create_and_fill_file(path, i, GIGABYTES, &fw); i++; - } + } while (fine); /* Final report. */ pr_freespace(get_freespace(path)); diff --git a/utils.c b/utils.c index 526f538..1a6ab18 100644 --- a/utils.c +++ b/utils.c @@ -14,7 +14,7 @@ const char *adjust_unit(double *ptr_bytes) return units[i]; } -#ifndef __GLIBC__ +#ifndef APPLE_MAC #include #include @@ -89,4 +89,4 @@ int lrand48_r(struct drand48_data *buffer, long int *result) return __nrand48_r(buffer->__x, buffer, result); } -#endif /* __GLIBC__ */ +#endif /* APPLE_MAC */ diff --git a/utils.h b/utils.h index b28220d..eae9e43 100644 --- a/utils.h +++ b/utils.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -52,7 +51,22 @@ static inline long delay_ms(const struct timeval *t1, const struct timeval *t2) (t2->tv_usec - t1->tv_usec) / 1000; } -#ifndef __GLIBC__ +#ifdef APPLE_MAC + +/* For PATH_MAX. */ +#include + +#include +static inline int fdatasync(int fd) +{ + /* It isn't exactly the same thing, but it's the best available on + * Macs, and it's enough to work. + */ + return fcntl(fd, F_FULLFSYNC); +} + +/* Mac's kernel doesn't take advices from applications. */ +#define posix_fadvise(fd, offset, len, advice) 0 /* * The following functions were copied from GNU Library C to make F3 @@ -79,6 +93,6 @@ extern int srand48_r(long int __seedval, struct drand48_data *__buffer) extern int lrand48_r(struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((nonnull(1, 2))); -#endif /* __GLIBC__ */ +#endif /* APPLE_MAC */ #endif /* HEADER_UTILS_H */