From 9c7d08773fcd398b50b484c5965438116cdb85e7 Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 4 Jun 2014 13:34:13 +0100 Subject: [PATCH] Fallback to pagesize transfers in dd(1) --- dd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dd.c b/dd.c index 994f712..79a3d08 100644 --- a/dd.c +++ b/dd.c @@ -41,6 +41,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd) struct stat st; int fli = O_RDONLY|O_LARGEFILE|O_NOCTTY, flo = O_WRONLY|O_LARGEFILE|O_NOATIME|O_NOCTTY; uid_t euid = 0; + long pagesize; if (ddc->direct) { fli |= O_DIRECT; @@ -68,14 +69,17 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd) if (!ddc->bs) { struct statfs fst; memset(&fst, 0, sizeof(fst)); + pagesize = sysconf(_SC_PAGESIZE); + if (pagesize <= 0) + pagesize = 0x1000; if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0) - fst.f_bsize = 0x1000; + fst.f_bsize = pagesize; if ((unsigned long)fst.f_bsize > (unsigned long)st.st_blksize) ddc->bs = fst.f_bsize; else ddc->bs = st.st_blksize; if (ddc->bs == 0) - ddc->bs = 0x1000; + ddc->bs = pagesize; } /* check if device or regular file */