#include "global.h"
#define power_of_2(x) ((x) && !((x) & ((x) - 1)))
-#define DEFAULT_FILESIZE ((__uint64_t) (256 * 1024 * 1024))
+#define DEFAULT_FILESIZE ((uint64_t) (256 * 1024 * 1024))
#define DEFAULT_BLOCKSIZE 512
#define SETBIT(ARRAY, N) ((ARRAY)[(N)/8] |= (1 << ((N)%8)))
/* Bit-vector array showing which blocks have been written */
static unsigned char *valid;
-static __uint64_t filesize;
-static __uint64_t fileoffset;
+static uint64_t filesize;
+static uint64_t fileoffset;
static unsigned int blocksize;
static int count;
* F_FSGETXATTR (Irix).
*
*/
-#ifdef __sgi__ /* Irix */
-# define xfscntl(filename, fd, cmd, arg) \
- fcntl((fd), F_ ## cmd, (arg))
-#else /* ! __sgi__ */
# define xfscntl(filename, fd, cmd, arg) \
xfsctl((filename), (fd), XFS_IOC_ ## cmd, (arg))
-#endif /* ! __sgi__ */
static void
usage(char *progname)
fprintf(stderr, "\tdefault count is %d block-sized writes\n",
(int) (DEFAULT_FILESIZE / DEFAULT_BLOCKSIZE));
fprintf(stderr, "\tdefault write_offset is %" PRIu64 " bytes\n",
- (__uint64_t) 0);
+ (uint64_t) 0);
exit(1);
}
}
static void
-dumpblock(int *buffer, __uint64_t offset, int blocksize)
+dumpblock(int *buffer, uint64_t offset, int blocksize)
{
int i;
static void
writeblks(char *fname, int fd, size_t alignment)
{
- __uint64_t offset;
+ uint64_t offset;
char *buffer = NULL;
int block;
+ int ret;
struct flock64 fl;
if (!test) {
- if (posix_memalign((void **) &buffer, alignment, blocksize)) {
- perror("malloc");
+ ret = posix_memalign((void **) &buffer, alignment, blocksize);
+ if (ret) {
+ fprintf(stderr, "posix_memalign: %s\n", strerror(ret));
exit(1);
}
memset(buffer, 0, blocksize);
}
+ /*
+ * Avoid allocation patterns being perturbed by different speculative
+ * preallocation beyond EOF configurations by first truncating the file
+ * to the expected maximum file size.
+ */
+ if (ftruncate(fd, filesize) < 0) {
+ perror("ftruncate");
+ exit(EXIT_FAILURE);
+ }
+
do {
if (verbose && ((count % 100) == 0)) {
printf(".");
exit(1);
}
- offset = (__uint64_t) block * blocksize;
+ offset = (uint64_t) block * blocksize;
if (alloconly) {
if (test) continue;
* into it. We'll verify this when we read
* it back in again.
*/
- *(__uint64_t *) buffer = fileoffset + offset;
- *(__uint64_t *) (buffer + 256) = fileoffset + offset;
+ *(uint64_t *) buffer = fileoffset + offset;
+ *(uint64_t *) (buffer + 256) = fileoffset + offset;
if (write(fd, buffer, blocksize) < blocksize) {
perror("write");
static int
readblks(int fd, size_t alignment)
{
- __uint64_t offset;
+ uint64_t offset;
char *buffer, *tmp;
unsigned int xfer, block, i;
int err=0;
if (alloconly)
return 0;
xfer = READ_XFER*blocksize;
- if (posix_memalign((void **) &buffer, alignment, xfer)) {
- perror("malloc");
+ err = posix_memalign((void **) &buffer, alignment, xfer);
+ if (err) {
+ fprintf(stderr, "posix_memalign: %s\n", strerror(err));
exit(1);
}
memset(buffer, 0, xfer);
}
tmp = buffer;
for (i = 0; i < READ_XFER; i++) {
- __uint64_t want;
- __uint64_t first;
- __uint64_t second;
+ uint64_t want;
+ uint64_t first;
+ uint64_t second;
if (verbose && ((block % 100) == 0)) {
printf("+");
}
want = BITVAL(valid, block) ? offset : 0;
- first = *(__uint64_t *) tmp;
- second = *(__uint64_t *) (tmp + 256);
+ first = *(uint64_t *) tmp;
+ second = *(uint64_t *) (tmp + 256);
if (first != want || second != want) {
printf("mismatched data at offset=0x%" PRIx64
", expected 0x%" PRIx64
perror("malloc");
return 1;
}
+ memset(valid, 0, size);
/* Lots of arguments affect how we open the file */
oflags = test ? O_RDONLY : O_RDWR|O_CREAT;