@@ -290,10 +290,11 @@ test_sync(int writes_per_op)
290290for (ops = 0 ;alarm_triggered == false;ops ++ )
291291{
292292for (writes = 0 ;writes < writes_per_op ;writes ++ )
293- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
293+ if (pg_pwrite (tmpfile ,
294+ buf ,
295+ XLOG_BLCKSZ ,
296+ writes * XLOG_BLCKSZ )!= XLOG_BLCKSZ )
294297die ("write failed" );
295- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
296- die ("seek failed" );
297298}
298299STOP_TIMER ;
299300close (tmpfile );
@@ -315,11 +316,12 @@ test_sync(int writes_per_op)
315316for (ops = 0 ;alarm_triggered == false;ops ++ )
316317{
317318for (writes = 0 ;writes < writes_per_op ;writes ++ )
318- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
319+ if (pg_pwrite (tmpfile ,
320+ buf ,
321+ XLOG_BLCKSZ ,
322+ writes * XLOG_BLCKSZ )!= XLOG_BLCKSZ )
319323die ("write failed" );
320324fdatasync (tmpfile );
321- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
322- die ("seek failed" );
323325}
324326STOP_TIMER ;
325327close (tmpfile );
@@ -339,12 +341,13 @@ test_sync(int writes_per_op)
339341for (ops = 0 ;alarm_triggered == false;ops ++ )
340342{
341343for (writes = 0 ;writes < writes_per_op ;writes ++ )
342- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
344+ if (pg_pwrite (tmpfile ,
345+ buf ,
346+ XLOG_BLCKSZ ,
347+ writes * XLOG_BLCKSZ )!= XLOG_BLCKSZ )
343348die ("write failed" );
344349if (fsync (tmpfile )!= 0 )
345350die ("fsync failed" );
346- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
347- die ("seek failed" );
348351}
349352STOP_TIMER ;
350353close (tmpfile );
@@ -362,12 +365,13 @@ test_sync(int writes_per_op)
362365for (ops = 0 ;alarm_triggered == false;ops ++ )
363366{
364367for (writes = 0 ;writes < writes_per_op ;writes ++ )
365- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
368+ if (pg_pwrite (tmpfile ,
369+ buf ,
370+ XLOG_BLCKSZ ,
371+ writes * XLOG_BLCKSZ )!= XLOG_BLCKSZ )
366372die ("write failed" );
367373if (pg_fsync_writethrough (tmpfile )!= 0 )
368374die ("fsync failed" );
369- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
370- die ("seek failed" );
371375}
372376STOP_TIMER ;
373377close (tmpfile );
@@ -393,17 +397,17 @@ test_sync(int writes_per_op)
393397for (ops = 0 ;alarm_triggered == false;ops ++ )
394398{
395399for (writes = 0 ;writes < writes_per_op ;writes ++ )
396- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
397-
400+ if (pg_pwrite (tmpfile ,
401+ buf ,
402+ XLOG_BLCKSZ ,
403+ writes * XLOG_BLCKSZ )!= XLOG_BLCKSZ )
398404/*
399405 * This can generate write failures if the filesystem has
400406 * a large block size, e.g. 4k, and there is no support
401407 * for O_DIRECT writes smaller than the file system block
402408 * size, e.g. XFS.
403409 */
404410die ("write failed" );
405- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
406- die ("seek failed" );
407411}
408412STOP_TIMER ;
409413close (tmpfile );
@@ -457,11 +461,12 @@ test_open_sync(const char *msg, int writes_size)
457461for (ops = 0 ;alarm_triggered == false;ops ++ )
458462{
459463for (writes = 0 ;writes < 16 /writes_size ;writes ++ )
460- if (write (tmpfile ,buf ,writes_size * 1024 )!=
464+ if (pg_pwrite (tmpfile ,
465+ buf ,
466+ writes_size * 1024 ,
467+ writes * writes_size * 1024 )!=
461468writes_size * 1024 )
462469die ("write failed" );
463- if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
464- die ("seek failed" );
465470}
466471STOP_TIMER ;
467472close (tmpfile );
@@ -553,16 +558,16 @@ test_non_sync(void)
553558printf (LABEL_FORMAT ,"write" );
554559fflush (stdout );
555560
561+ if ((tmpfile = open (filename ,O_RDWR |PG_BINARY ,0 ))== -1 )
562+ die ("could not open output file" );
556563START_TIMER ;
557564for (ops = 0 ;alarm_triggered == false;ops ++ )
558565{
559- if ((tmpfile = open (filename ,O_RDWR |PG_BINARY ,0 ))== -1 )
560- die ("could not open output file" );
561- if (write (tmpfile ,buf ,XLOG_BLCKSZ )!= XLOG_BLCKSZ )
566+ if (pg_pwrite (tmpfile ,buf ,XLOG_BLCKSZ ,0 )!= XLOG_BLCKSZ )
562567die ("write failed" );
563- close (tmpfile );
564568}
565569STOP_TIMER ;
570+ close (tmpfile );
566571}
567572
568573static void