/*
* Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved.
*
+ * Copyright (c) 2012, Intel Corporation.
+ *
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* Sundry porting patches from Guy Harris 12/2001
* $FreeBSD: src/tools/regression/fsx/fsx.c,v 1.1 2001/12/20 04:15:57 jkh Exp $
*/
-
#include <sys/types.h>
#include <sys/stat.h>
#if defined(_UWIN) || defined(__linux__)
char *good_buf; /* a pointer to the correct data */
char *temp_buf; /* a pointer to the current data */
char *fname; /* name of our test file */
-char logfile[1024]; /* name of our log file */
-char goodfile[1024]; /* name of our test file */
+char logfile[PATH_MAX]; /* name of our log file */
+char goodfile[PATH_MAX]; /* name of our test file */
off_t file_size = 0;
off_t biggest = 0;
char state[256];
unsigned long testcalls = 0; /* calls to function "test" */
-unsigned long simulatedopcount = 0; /* -b flag */
+long simulatedopcount = 0; /* -b flag */
int closeprob = 0; /* -c flag */
int debug = 0; /* -d flag */
-unsigned long debugstart = 0; /* -D flag */
-unsigned long maxfilelen = 256 * 1024; /* -l flag */
+long debugstart = 0; /* -D flag */
+long maxfilelen = 256 * 1024; /* -l flag */
int sizechecks = 1; /* -n flag disables them */
int maxoplen = 64 * 1024; /* -o flag */
int quiet = 0; /* -q flag */
-unsigned long progressinterval = 0; /* -p flag */
+long progressinterval = 0; /* -p flag */
int readbdy = 1; /* -r flag */
int style = 0; /* -s flag */
int truncbdy = 1; /* -t flag */
int randomoplen = 1; /* -O flag disables it */
int seed = 1; /* -S flag */
int mapped_writes = 1; /* -W flag disables */
-int mapped_reads = 1; /* -R flag disables it */
+int mapped_reads = 1; /* -R flag disables it */
int fsxgoodfd = 0;
+int o_direct; /* -Z */
FILE * fsxlogf = NULL;
int badoff = -1;
-
void
vwarnc(code, fmt, ap)
int code;
for (i = 0, tf = test_files; i < num_test_files; i++, tf++) {
tf->path = argv[i];
- tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC),
- 0666);
+ tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|
+ o_direct, 0666);
if (tf->fd < 0) {
prterr(tf->path);
exit(91);
int fd = tf->fd;
offset -= offset % readbdy;
+ if (o_direct)
+ size -= size % readbdy;
gettimeofday(&t, NULL);
if (size == 0) {
- if (!quiet && testcalls > simulatedopcount)
+ if (!quiet && testcalls > simulatedopcount && !o_direct)
prt("skipping zero size read\n");
log4(OP_SKIPPED, OP_READ, offset, size, &t, tf);
return;
int fd = tf->fd;
offset -= offset % writebdy;
+ if (o_direct)
+ size -= size % writebdy;
gettimeofday(&t, NULL);
if (size == 0) {
- if (!quiet && testcalls > simulatedopcount)
+ if (!quiet && testcalls > simulatedopcount && !o_direct)
prt("skipping zero size write\n");
log4(OP_SKIPPED, OP_WRITE, offset, size, &t, tf);
return;
gettimeofday(&t, NULL);
prt(" %lu.%06lu close done\n", t.tv_sec, t.tv_usec);
}
- tf->fd = open(tf->path, O_RDWR, 0);
+ tf->fd = open(tf->path, O_RDWR|o_direct, 0);
if (tf->fd < 0) {
prterr("docloseopen: open");
report_failure(181);
" -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n"
" -S seed: for random # generator (default 1) 0 gets timestamp\n"
" -W: mapped write operations DISabled\n"
-" -R: read() system calls only (mapped reads disabled)\n"
-" -I: When multiple paths to the file are given each operation uses"
-" a different path. Iterate through them in order with 'rotate'"
-" or chose then at 'random'. (defaults to random)\n"
+" -R: read() system calls only (mapped reads disabled)\n"
+" -Z: O_DIRECT (use -R, -W, -r and -w too)\n"
+" -I: When multiple paths to the file are given each operation uses\n"
+" a different path. Iterate through them in order with 'rotate'\n"
+" or chose then at 'random'. (defaults to random)\n"
" fname: this filename is REQUIRED (no default)\n");
exit(90);
}
setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
while ((ch = getopt(argc, argv,
- "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:W"))
+ "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:WZ"))
!= EOF)
switch (ch) {
case 'b':
randomoplen = 0;
break;
case 'P':
- strncpy(goodfile, optarg, sizeof(goodfile));
+ strncpy(goodfile, optarg, sizeof(goodfile) - 1);
strcat(goodfile, "/");
- strncpy(logfile, optarg, sizeof(logfile));
+ strncpy(logfile, optarg, sizeof(logfile) - 1);
strcat(logfile, "/");
dirpath = 1;
break;
if (!quiet)
fprintf(stdout, "mapped writes DISABLED\n");
break;
+ case 'Z':
+ o_direct = O_DIRECT;
+ break;
default:
usage();
original_buf = (char *) malloc(maxfilelen);
for (i = 0; i < maxfilelen; i++)
original_buf[i] = random() % 256;
- good_buf = (char *) malloc(maxfilelen);
- memset(good_buf, '\0', maxfilelen);
- temp_buf = (char *) malloc(maxoplen);
- memset(temp_buf, '\0', maxoplen);
+ if (o_direct) {
+ int ret;
+
+ ret = posix_memalign((void **)&good_buf, writebdy, maxfilelen);
+ if (ret) {
+ prt("main: posix_memalign failed: %s\n", strerror(ret));
+ exit(96);
+ }
+
+ ret = posix_memalign((void **)&temp_buf, readbdy, maxoplen);
+ if (ret) {
+ prt("main: posix_memalign failed: %s\n", strerror(ret));
+ exit(97);
+ }
+ } else {
+ good_buf = malloc(maxfilelen);
+ if (!good_buf) {
+ prt("malloc failed.\n");
+ exit(98);
+ }
+
+ temp_buf = malloc(maxoplen);
+ if (!temp_buf) {
+ prt("malloc failed.\n");
+ exit(99);
+ }
+ }
+ memset(good_buf, 0, maxfilelen);
+ memset(temp_buf, 0, maxoplen);
+
if (lite) { /* zero entire existing file */
ssize_t written;
int fd = get_fd();