summaryrefslogtreecommitdiff
path: root/src/shred.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-04-15 10:50:07 +0000
committerJim Meyering <jim@meyering.net>2004-04-15 10:50:07 +0000
commit0adee504ff956edb14905374208e722ca93ecd38 (patch)
tree7e2f294c77453bdabfcade56feaff362a94c1d3f /src/shred.c
parente28e19cbba0ba34df95914f0a656b07b28785ab5 (diff)
downloadcoreutils-0adee504ff956edb14905374208e722ca93ecd38.tar.xz
Include getpagesize.h.
(dopass): Align I/O buffers to page boundaries.
Diffstat (limited to 'src/shred.c')
-rw-r--r--src/shred.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/shred.c b/src/shred.c
index bb7b9c9d6..42276771a 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -105,6 +105,7 @@
#include "system.h"
#include "xstrtol.h"
#include "error.h"
+#include "getpagesize.h"
#include "human.h"
#include "inttostr.h"
#include "quotearg.h" /* For quotearg_colon */
@@ -787,11 +788,9 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
size_t lim; /* Amount of data to try writing */
size_t soff; /* Offset into buffer for next write */
ssize_t ssize; /* Return value from write */
-#if ISAAC_WORDS > 1024
- word32 r[ISAAC_WORDS * 3]; /* Multiple of 4K and of pattern size */
-#else
- word32 r[1024 * 3]; /* Multiple of 4K and of pattern size */
-#endif
+ word32 *r; /* Fill pattern. */
+ size_t rsize = 3 * MAX (ISAAC_WORDS, 1024) * sizeof *r; /* Fill size. */
+ size_t ralign = lcm (getpagesize (), sizeof *r); /* Fill alignment. */
char pass_string[PASS_NAME_SIZE]; /* Name of current pass */
/* Printable previous offset into the file */
@@ -804,10 +803,13 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
return -1;
}
+ r = alloca (rsize + ralign - 1);
+ r = ptr_align (r, ralign);
+
/* Constant fill patterns need only be set up once. */
if (type >= 0)
{
- lim = sizeof r;
+ lim = rsize;
if ((off_t) lim > size && size != -1)
{
lim = (size_t) size;
@@ -832,7 +834,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
for (;;)
{
/* How much to write this time? */
- lim = sizeof r;
+ lim = rsize;
if ((off_t) lim > size - offset && size != -1)
{
if (size < offset)
@@ -842,7 +844,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
break;
}
if (type < 0)
- fillrand (s, r, sizeof r, lim);
+ fillrand (s, r, rsize, lim);
/* Loop to retry partial writes. */
for (soff = 0; soff < lim; soff += ssize)
{