|
|
|
@ -1,6 +1,26 @@
|
|
|
|
|
diff -up scrub-2.6.1/libscrub/Makefile.am.extent-only scrub-2.6.1/libscrub/Makefile.am
|
|
|
|
|
--- scrub-2.6.1/libscrub/Makefile.am.extent-only 2014-08-20 17:33:43.000000000 -0400
|
|
|
|
|
+++ scrub-2.6.1/libscrub/Makefile.am 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
From 1dd2a8b9226594ae834e639e00abdf2f47ac4acc Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Daniel Kopecek <dkopecek@redhat.com>
|
|
|
|
|
Date: Tue, 16 Jul 2019 13:21:06 +0200
|
|
|
|
|
Subject: [PATCH] scrub allocated extent only
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
libscrub/Makefile.am | 1 +
|
|
|
|
|
man/scrub.1.in | 7 ++
|
|
|
|
|
src/Makefile.am | 2 +
|
|
|
|
|
src/fextent_apply.c | 142 ++++++++++++++++++++++++++
|
|
|
|
|
src/fextent_apply.h | 30 ++++++
|
|
|
|
|
src/fillfile.c | 231 +++++++++++++++++++++++++++++++++----------
|
|
|
|
|
src/fillfile.h | 4 +-
|
|
|
|
|
src/genrand.c | 2 +-
|
|
|
|
|
src/scrub.c | 36 ++++---
|
|
|
|
|
9 files changed, 383 insertions(+), 72 deletions(-)
|
|
|
|
|
create mode 100644 src/fextent_apply.c
|
|
|
|
|
create mode 100644 src/fextent_apply.h
|
|
|
|
|
|
|
|
|
|
diff --git a/libscrub/Makefile.am b/libscrub/Makefile.am
|
|
|
|
|
index 477c866..d88cd48 100644
|
|
|
|
|
--- a/libscrub/Makefile.am
|
|
|
|
|
+++ b/libscrub/Makefile.am
|
|
|
|
|
@@ -13,6 +13,7 @@ libscrub_la_SOURCES = \
|
|
|
|
|
libscrub.c \
|
|
|
|
|
scrub.h \
|
|
|
|
@ -9,10 +29,11 @@ diff -up scrub-2.6.1/libscrub/Makefile.am.extent-only scrub-2.6.1/libscrub/Makef
|
|
|
|
|
../src/filldentry.c \
|
|
|
|
|
../src/fillfile.c \
|
|
|
|
|
../src/genrand.c \
|
|
|
|
|
diff -up scrub-2.6.1/man/scrub.1.in.extent-only scrub-2.6.1/man/scrub.1.in
|
|
|
|
|
--- scrub-2.6.1/man/scrub.1.in.extent-only 2014-08-20 17:33:43.000000000 -0400
|
|
|
|
|
+++ scrub-2.6.1/man/scrub.1.in 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
@@ -110,6 +110,13 @@ Do everything but write to targets.
|
|
|
|
|
diff --git a/man/scrub.1.in b/man/scrub.1.in
|
|
|
|
|
index a1c260a..72b114f 100644
|
|
|
|
|
--- a/man/scrub.1.in
|
|
|
|
|
+++ b/man/scrub.1.in
|
|
|
|
|
@@ -106,6 +106,13 @@ Don't generate random data in parallel with I/O.
|
|
|
|
|
.TP
|
|
|
|
|
\fI-h\fR, \fI--help\fR
|
|
|
|
|
Print a summary of command line options on stderr.
|
|
|
|
@ -26,27 +47,42 @@ diff -up scrub-2.6.1/man/scrub.1.in.extent-only scrub-2.6.1/man/scrub.1.in
|
|
|
|
|
.SH SCRUB METHODS
|
|
|
|
|
.TP
|
|
|
|
|
.I "nnsa"
|
|
|
|
|
diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_apply.c
|
|
|
|
|
--- scrub-2.6.1/src/fextent_apply.c.extent-only 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
+++ scrub-2.6.1/src/fextent_apply.c 2021-02-22 14:25:20.590843156 -0500
|
|
|
|
|
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
|
|
|
index 0cbd8f7..5de0b68 100644
|
|
|
|
|
--- a/src/Makefile.am
|
|
|
|
|
+++ b/src/Makefile.am
|
|
|
|
|
@@ -3,6 +3,8 @@ bin_PROGRAMS = scrub
|
|
|
|
|
scrub_SOURCES = \
|
|
|
|
|
aes.c \
|
|
|
|
|
aes.h \
|
|
|
|
|
+ fextent_apply.c \
|
|
|
|
|
+ fextent_apply.h \
|
|
|
|
|
filldentry.c \
|
|
|
|
|
filldentry.h \
|
|
|
|
|
fillfile.c \
|
|
|
|
|
diff --git a/src/fextent_apply.c b/src/fextent_apply.c
|
|
|
|
|
new file mode 100644
|
|
|
|
|
index 0000000..31d3210
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/src/fextent_apply.c
|
|
|
|
|
@@ -0,0 +1,142 @@
|
|
|
|
|
+/*
|
|
|
|
|
+ * Copyright 2021 Red Hat, Inc.
|
|
|
|
|
+ * Copyright 2012 Red Hat Inc., Durham, North Carolina.
|
|
|
|
|
+ * All Rights Reserved.
|
|
|
|
|
+ *
|
|
|
|
|
+ * This program is free software; you can redistribute it and/or
|
|
|
|
|
+ * modify it under the terms of the GNU General Public License
|
|
|
|
|
+ * as published by the Free Software Foundation; either version
|
|
|
|
|
+ * 2 of the License, or (at your option) any later version.
|
|
|
|
|
+ * This library is free software; you can redistribute it and/or
|
|
|
|
|
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
+ * License as published by the Free Software Foundation; either
|
|
|
|
|
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
+ *
|
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
|
+ * This library is distributed in the hope that it will be useful,
|
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
+ * General Public License for more details.
|
|
|
|
|
+ * Lesser General Public License for more details.
|
|
|
|
|
+ *
|
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
|
+ * along with this program. If not, see:
|
|
|
|
|
+ * <https://www.gnu.org/licenses/>.
|
|
|
|
|
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
+ * License along with this library; if not, write to the Free Software
|
|
|
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
+ *
|
|
|
|
|
+ * Authors:
|
|
|
|
|
+ * Daniel Kopecek <dkopecek@redhat.com>
|
|
|
|
@ -67,10 +103,10 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+#include <linux/fiemap.h>
|
|
|
|
|
+
|
|
|
|
|
+#ifndef NDEBUG
|
|
|
|
|
+# define dP(...) \
|
|
|
|
|
+ do { int __tmp_errno = errno; \
|
|
|
|
|
+ fprintf(stderr, "DEBUG: "__VA_ARGS__); \
|
|
|
|
|
+ errno = __tmp_errno; \
|
|
|
|
|
+# define dP(...) \
|
|
|
|
|
+ do { int __tmp_errno = errno; \
|
|
|
|
|
+ fprintf(stderr, "DEBUG: "__VA_ARGS__); \
|
|
|
|
|
+ errno = __tmp_errno; \
|
|
|
|
|
+ } while(0)
|
|
|
|
|
+#else
|
|
|
|
|
+# define dP(...) while(0)
|
|
|
|
@ -85,26 +121,26 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+
|
|
|
|
|
+ // lock, sync, stat
|
|
|
|
|
+ if (flock(fd, LOCK_EX) != 0) {
|
|
|
|
|
+ dP("flock(%d, LOCK_EX) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ dP("flock(%d, LOCK_EX) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fsync(fd) != 0) {
|
|
|
|
|
+ dP("fsync(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ dP("fsync(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fstat(fd, &st) != 0) {
|
|
|
|
|
+ dP("fstat(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ dP("fstat(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * fiemap => get extent count
|
|
|
|
|
+ */
|
|
|
|
|
+ em = malloc(sizeof(struct fiemap));
|
|
|
|
|
+
|
|
|
|
|
+ if (em == NULL) {
|
|
|
|
|
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap));
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap));
|
|
|
|
|
+ goto exit_1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ memset(em, 0, sizeof(struct fiemap));
|
|
|
|
@ -116,8 +152,8 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+ em->fm_flags = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (ioctl(fd, FS_IOC_FIEMAP, em) != 0) {
|
|
|
|
|
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ extent_count = em->fm_mapped_extents;
|
|
|
|
@ -127,16 +163,16 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+ * fiemap => get extents
|
|
|
|
|
+ */
|
|
|
|
|
+ em = malloc (sizeof(struct fiemap)
|
|
|
|
|
+ + (sizeof(struct fiemap_extent) * extent_count));
|
|
|
|
|
+ + (sizeof(struct fiemap_extent) * extent_count));
|
|
|
|
|
+
|
|
|
|
|
+ if (em == NULL) {
|
|
|
|
|
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap)
|
|
|
|
|
+ + (sizeof (struct fiemap_extent) * extent_count));
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap)
|
|
|
|
|
+ + (sizeof (struct fiemap_extent) * extent_count));
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ memset(em, 0, sizeof(struct fiemap)
|
|
|
|
|
+ + (sizeof(struct fiemap_extent) * extent_count));
|
|
|
|
|
+ + (sizeof(struct fiemap_extent) * extent_count));
|
|
|
|
|
+
|
|
|
|
|
+ em[0].fm_start = 0;
|
|
|
|
|
+ em[0].fm_length = st.st_size;
|
|
|
|
@ -144,21 +180,21 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+ em[0].fm_flags = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (ioctl(fd, FS_IOC_FIEMAP, em) != 0) {
|
|
|
|
|
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < extent_count; ++i) {
|
|
|
|
|
+ // seek to extent start
|
|
|
|
|
+ if (lseek(fd, em->fm_extents[i].fe_logical, SEEK_SET) == (off_t)-1) {
|
|
|
|
|
+ dP("lseek(%d, %llu, SET) failed: %s, %d.\n",
|
|
|
|
|
+ fd, em->fm_extents[i].fe_logical, strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = function(fd, em->fm_extents + i, arg);
|
|
|
|
|
+ if (ret != 0)
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ // seek to extent start
|
|
|
|
|
+ if (lseek(fd, em->fm_extents[i].fe_logical, SEEK_SET) == (off_t)-1) {
|
|
|
|
|
+ dP("lseek(%d, %llu, SET) failed: %s, %d.\n",
|
|
|
|
|
+ fd, em->fm_extents[i].fe_logical, strerror(errno), errno);
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = function(fd, em->fm_extents + i, arg);
|
|
|
|
|
+ if (ret != 0)
|
|
|
|
|
+ goto exit_0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = 0;
|
|
|
|
@ -168,31 +204,33 @@ diff -up scrub-2.6.1/src/fextent_apply.c.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+ exit_1:
|
|
|
|
|
+ // unlock
|
|
|
|
|
+ if (flock(fd, LOCK_UN) != 0)
|
|
|
|
|
+ ret = -1;
|
|
|
|
|
+ ret = -1;
|
|
|
|
|
+
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
diff -up scrub-2.6.1/src/fextent_apply.h.extent-only scrub-2.6.1/src/fextent_apply.h
|
|
|
|
|
--- scrub-2.6.1/src/fextent_apply.h.extent-only 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
+++ scrub-2.6.1/src/fextent_apply.h 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
diff --git a/src/fextent_apply.h b/src/fextent_apply.h
|
|
|
|
|
new file mode 100644
|
|
|
|
|
index 0000000..40a54ec
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/src/fextent_apply.h
|
|
|
|
|
@@ -0,0 +1,30 @@
|
|
|
|
|
+/*
|
|
|
|
|
+ * Copyright 2021 Red Hat, Inc.
|
|
|
|
|
+ * Copyright 2012 Red Hat Inc., Durham, North Carolina.
|
|
|
|
|
+ * All Rights Reserved.
|
|
|
|
|
+ *
|
|
|
|
|
+ * This program is free software; you can redistribute it and/or
|
|
|
|
|
+ * modify it under the terms of the GNU General Public License
|
|
|
|
|
+ * as published by the Free Software Foundation; either version
|
|
|
|
|
+ * 2 of the License, or (at your option) any later version.
|
|
|
|
|
+ * This library is free software; you can redistribute it and/or
|
|
|
|
|
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
+ * License as published by the Free Software Foundation; either
|
|
|
|
|
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
+ *
|
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
|
+ * This library is distributed in the hope that it will be useful,
|
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
+ * General Public License for more details.
|
|
|
|
|
+ * Lesser General Public License for more details.
|
|
|
|
|
+ *
|
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
|
+ * along with this program. If not, see:
|
|
|
|
|
+ * <https://www.gnu.org/licenses/>.
|
|
|
|
|
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
+ * License along with this library; if not, write to the Free Software
|
|
|
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
+ *
|
|
|
|
|
+ * Authors:
|
|
|
|
|
+ * Daniel Kopecek <dkopecek@redhat.com>
|
|
|
|
@ -206,10 +244,11 @@ diff -up scrub-2.6.1/src/fextent_apply.h.extent-only scrub-2.6.1/src/fextent_app
|
|
|
|
|
+int fextent_apply(int fd, int (*function)(int, struct fiemap_extent *, void *), void *arg);
|
|
|
|
|
+
|
|
|
|
|
+#endif /* FEXTENT_APPLY_H */
|
|
|
|
|
diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
--- scrub-2.6.1/src/fillfile.c.extent-only 2014-08-20 17:33:43.000000000 -0400
|
|
|
|
|
+++ scrub-2.6.1/src/fillfile.c 2021-02-22 14:24:32.439635010 -0500
|
|
|
|
|
@@ -41,6 +41,7 @@
|
|
|
|
|
diff --git a/src/fillfile.c b/src/fillfile.c
|
|
|
|
|
index e0f67b6..a77367f 100644
|
|
|
|
|
--- a/src/fillfile.c
|
|
|
|
|
+++ b/src/fillfile.c
|
|
|
|
|
@@ -42,6 +42,7 @@
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "fillfile.h"
|
|
|
|
@ -217,7 +256,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
|
|
|
|
|
static int no_threads = 0;
|
|
|
|
|
|
|
|
|
|
@@ -56,6 +57,20 @@ struct memstruct {
|
|
|
|
|
@@ -57,6 +58,20 @@ struct memstruct {
|
|
|
|
|
|
|
|
|
|
extern char *prog;
|
|
|
|
|
|
|
|
|
@ -238,11 +277,11 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
#if defined(O_DIRECT) && (defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_MEMALIGN))
|
|
|
|
|
# define MY_O_DIRECT O_DIRECT
|
|
|
|
|
#else
|
|
|
|
|
@@ -154,11 +169,12 @@ refill_fini(struct memstruct *mp)
|
|
|
|
|
@@ -155,11 +170,12 @@ refill_fini(struct memstruct *mp)
|
|
|
|
|
* If 'sparse' is true, only scrub first and last blocks (for testing).
|
|
|
|
|
* The number of bytes written is returned.
|
|
|
|
|
* If 'creat' is true, open with O_CREAT and allow ENOSPC to be non-fatal.
|
|
|
|
|
+ * If 'extentonly' is true, fill only file extents with the given pattern.
|
|
|
|
|
+ * IF 'extentonly' is true, fill only file extents with the given pattern
|
|
|
|
|
*/
|
|
|
|
|
off_t
|
|
|
|
|
fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
@ -252,7 +291,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
{
|
|
|
|
|
int fd = -1;
|
|
|
|
|
off_t n;
|
|
|
|
|
@@ -178,34 +194,52 @@ fillfile(char *path, off_t filesize, uns
|
|
|
|
|
@@ -179,34 +195,58 @@ fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
|
}
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
goto error;
|
|
|
|
@ -303,25 +342,31 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
+ if (written + memsize > filesize)
|
|
|
|
|
+ memsize = filesize - written;
|
|
|
|
|
+ if (refill && !sparse) {
|
|
|
|
|
+ if (!mp)
|
|
|
|
|
+ if (refill_init(&mp, refill, memsize) < 0)
|
|
|
|
|
+ if (!mp) {
|
|
|
|
|
+ if (refill_init(&mp, refill, memsize) < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ if (refill_memcpy(mp, mem, memsize, filesize, written) < 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (refill_memcpy(mp, mem, memsize, filesize, written) < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sparse && !(written == 0) && !(written + memsize == filesize)) {
|
|
|
|
|
+ if (lseek(fd, memsize, SEEK_CUR) < 0)
|
|
|
|
|
+ if (lseek(fd, memsize, SEEK_CUR) < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ written += memsize;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ n = write_all(fd, mem, memsize);
|
|
|
|
|
+ if (creat && n < 0 && errno == ENOSPC)
|
|
|
|
|
+ break;
|
|
|
|
|
+ if (n == 0) {
|
|
|
|
|
+ errno = EINVAL; /* write past end of device? */
|
|
|
|
|
+ errno = EINVAL;
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ } else if (n < 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (n < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ written += n;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (progress)
|
|
|
|
@ -329,10 +374,10 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
+ } while (written < filesize);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
if (fsync(fd) < 0) {
|
|
|
|
|
if (errno != EINVAL)
|
|
|
|
|
goto error;
|
|
|
|
|
@@ -232,7 +266,7 @@ error:
|
|
|
|
|
if (fsync(fd) < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
|
|
|
|
|
@@ -230,7 +270,7 @@ error:
|
|
|
|
|
*/
|
|
|
|
|
off_t
|
|
|
|
|
checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
@ -341,7 +386,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
{
|
|
|
|
|
int fd = -1;
|
|
|
|
|
off_t n;
|
|
|
|
|
@@ -240,8 +274,6 @@ checkfile(char *path, off_t filesize, un
|
|
|
|
|
@@ -238,8 +278,6 @@ checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
|
unsigned char *buf = NULL;
|
|
|
|
|
int openflags = O_RDONLY;
|
|
|
|
|
|
|
|
|
@ -350,7 +395,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
if (filetype(path) != FILE_CHAR)
|
|
|
|
|
openflags |= MY_O_DIRECT;
|
|
|
|
|
fd = open(path, openflags);
|
|
|
|
|
@@ -252,32 +284,58 @@ checkfile(char *path, off_t filesize, un
|
|
|
|
|
@@ -250,32 +288,60 @@ checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
|
}
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
goto error;
|
|
|
|
@ -402,19 +447,21 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
+ if (verified + memsize > filesize)
|
|
|
|
|
+ memsize = filesize - verified;
|
|
|
|
|
+ if (sparse && !(verified == 0) && !(verified + memsize == filesize)) {
|
|
|
|
|
+ if (lseek(fd, memsize, SEEK_CUR) < 0)
|
|
|
|
|
+ if (lseek(fd, memsize, SEEK_CUR) < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ verified += memsize;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ n = read_all(fd, buf, memsize);
|
|
|
|
|
+ if (n < 0)
|
|
|
|
|
+ if (n < 0) {
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (n == 0) {
|
|
|
|
|
+ errno = EINVAL; /* early EOF */
|
|
|
|
|
+ goto error;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (memcmp(mem, buf, memsize) != 0) {
|
|
|
|
|
+ break; /* return < filesize means verification failure */
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ verified += n;
|
|
|
|
|
+ }
|
|
|
|
@ -422,7 +469,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
+ progress(arg, (double)verified/filesize);
|
|
|
|
|
+ } while (verified < filesize);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
if (close(fd) < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
- free(buf);
|
|
|
|
@ -432,7 +479,7 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
return verified;
|
|
|
|
|
nomem:
|
|
|
|
|
errno = ENOMEM;
|
|
|
|
|
@@ -295,6 +353,63 @@ disable_threads(void)
|
|
|
|
|
@@ -293,6 +359,63 @@ disable_threads(void)
|
|
|
|
|
no_threads = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -496,10 +543,11 @@ diff -up scrub-2.6.1/src/fillfile.c.extent-only scrub-2.6.1/src/fillfile.c
|
|
|
|
|
/*
|
|
|
|
|
* vi:tabstop=4 shiftwidth=4 expandtab
|
|
|
|
|
*/
|
|
|
|
|
diff -up scrub-2.6.1/src/fillfile.h.extent-only scrub-2.6.1/src/fillfile.h
|
|
|
|
|
--- scrub-2.6.1/src/fillfile.h.extent-only 2014-08-20 17:33:43.000000000 -0400
|
|
|
|
|
+++ scrub-2.6.1/src/fillfile.h 2021-02-22 14:24:32.440635014 -0500
|
|
|
|
|
@@ -3,9 +3,9 @@ typedef void (*refill_t) (unsigned char
|
|
|
|
|
diff --git a/src/fillfile.h b/src/fillfile.h
|
|
|
|
|
index b9ef951..2fc917d 100644
|
|
|
|
|
--- a/src/fillfile.h
|
|
|
|
|
+++ b/src/fillfile.h
|
|
|
|
|
@@ -29,7 +29,7 @@ typedef void (*refill_t) (unsigned char *mem, int memsize);
|
|
|
|
|
|
|
|
|
|
off_t fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
|
|
|
|
|
progress_t progress, void *arg, refill_t refill,
|
|
|
|
@ -509,46 +557,48 @@ diff -up scrub-2.6.1/src/fillfile.h.extent-only scrub-2.6.1/src/fillfile.h
|
|
|
|
|
- progress_t progress, void *arg, bool sparse);
|
|
|
|
|
+ progress_t progress, void *arg, bool sparse, bool extentonly);
|
|
|
|
|
void disable_threads(void);
|
|
|
|
|
diff --git a/src/genrand.c b/src/genrand.c
|
|
|
|
|
index 820c898..ecfd382 100644
|
|
|
|
|
--- a/src/genrand.c
|
|
|
|
|
+++ b/src/genrand.c
|
|
|
|
|
@@ -106,7 +106,7 @@ genrandraw(unsigned char *buf, int buflen)
|
|
|
|
|
buf[n] = result;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
- return;
|
|
|
|
|
+ return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
diff -up scrub-2.6.1/src/Makefile.am.extent-only scrub-2.6.1/src/Makefile.am
|
|
|
|
|
--- scrub-2.6.1/src/Makefile.am.extent-only 2021-02-22 14:24:32.438635006 -0500
|
|
|
|
|
+++ scrub-2.6.1/src/Makefile.am 2021-02-22 14:24:32.440635014 -0500
|
|
|
|
|
@@ -1,6 +1,8 @@
|
|
|
|
|
bin_PROGRAMS = scrub
|
|
|
|
|
|
|
|
|
|
scrub_SOURCES = \
|
|
|
|
|
+ fextent_apply.c \
|
|
|
|
|
+ fextent_apply.h \
|
|
|
|
|
filldentry.c \
|
|
|
|
|
filldentry.h \
|
|
|
|
|
fillfile.c \
|
|
|
|
|
diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
--- scrub-2.6.1/src/scrub.c.extent-only 2021-02-22 14:24:32.438635006 -0500
|
|
|
|
|
+++ scrub-2.6.1/src/scrub.c 2021-02-22 14:24:32.440635014 -0500
|
|
|
|
|
@@ -68,10 +68,11 @@ struct opt_struct {
|
|
|
|
|
bool nofollow;
|
|
|
|
|
bool nohwrand;
|
|
|
|
|
bool nothreads;
|
|
|
|
|
+ bool extentonly;
|
|
|
|
|
};
|
|
|
|
|
diff --git a/src/scrub.c b/src/scrub.c
|
|
|
|
|
index dec71f3..b0eb1f7 100644
|
|
|
|
|
--- a/src/scrub.c
|
|
|
|
|
+++ b/src/scrub.c
|
|
|
|
|
@@ -58,12 +58,12 @@
|
|
|
|
|
#define BUFSIZE (4*1024*1024) /* default blocksize */
|
|
|
|
|
|
|
|
|
|
static bool scrub(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
- int bufsize, bool nosig, bool sparse, bool enospc);
|
|
|
|
|
+ int bufsize, bool nosig, bool sparse, bool enospc, bool extentonly);
|
|
|
|
|
static void scrub_free(char *path, const struct opt_struct *opt);
|
|
|
|
|
static void scrub_dirent(char *path, const struct opt_struct *opt);
|
|
|
|
|
static void scrub_file(char *path, const struct opt_struct *opt);
|
|
|
|
|
@@ -82,7 +83,7 @@ static void scrub_disk(char *path,
|
|
|
|
|
static int scrub_object(char *path, const struct opt_struct *opt,
|
|
|
|
|
bool noexec, bool dryrun);
|
|
|
|
|
- int bufsize, bool Sopt, bool sparse, bool enospc);
|
|
|
|
|
+ int bufsize, bool Sopt, bool sparse, bool enospc, bool extentonly);
|
|
|
|
|
static void scrub_free(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
int bufsize, bool Sopt);
|
|
|
|
|
static void scrub_dirent(char *path, char *newpath);
|
|
|
|
|
static void scrub_file(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
- int bufsize, bool Sopt, bool sparse);
|
|
|
|
|
+ int bufsize, bool Sopt, bool sparse, bool extentonly);
|
|
|
|
|
#if __APPLE__
|
|
|
|
|
static void scrub_resfork(char *path, const sequence_t *seq,
|
|
|
|
|
int bufsize);
|
|
|
|
|
@@ -71,7 +71,7 @@ static void scrub_resfork(char *path, const sequence_t *seq,
|
|
|
|
|
static void scrub_disk(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
int bufsize, bool Sopt, bool sparse);
|
|
|
|
|
|
|
|
|
|
-#define OPTIONS "p:D:Xb:s:fSrvTLRthn"
|
|
|
|
|
+#define OPTIONS "p:D:Xb:s:fSrvTELRthn"
|
|
|
|
|
-#define OPTIONS "p:D:Xb:s:fSrvTLRth"
|
|
|
|
|
+#define OPTIONS "p:D:Xb:s:fSrvTELRth"
|
|
|
|
|
#if HAVE_GETOPT_LONG
|
|
|
|
|
#define GETOPT(ac,av,opt,lopt) getopt_long(ac,av,opt,lopt,NULL)
|
|
|
|
|
static struct option longopts[] = {
|
|
|
|
|
@@ -96,6 +97,7 @@ static struct option longopts[] = {
|
|
|
|
|
@@ -85,6 +85,7 @@ static struct option longopts[] = {
|
|
|
|
|
{"remove", no_argument, 0, 'r'},
|
|
|
|
|
{"version", no_argument, 0, 'v'},
|
|
|
|
|
{"test-sparse", no_argument, 0, 'T'},
|
|
|
|
@ -556,7 +606,7 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
{"no-link", no_argument, 0, 'L'},
|
|
|
|
|
{"no-hwrand", no_argument, 0, 'R'},
|
|
|
|
|
{"no-threads", no_argument, 0, 't'},
|
|
|
|
|
@@ -123,6 +125,7 @@ usage(void)
|
|
|
|
|
@@ -111,6 +112,7 @@ usage(void)
|
|
|
|
|
" -f, --force scrub despite signature from previous scrub\n"
|
|
|
|
|
" -S, --no-signature do not write scrub signature after scrub\n"
|
|
|
|
|
" -r, --remove remove file after scrub\n"
|
|
|
|
@ -564,22 +614,39 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
" -L, --no-link do not scrub link target\n"
|
|
|
|
|
" -R, --no-hwrand do not use a hardware random number generator\n"
|
|
|
|
|
" -t, --no-threads do not compute random data in a parallel thread\n"
|
|
|
|
|
@@ -212,6 +215,9 @@ main(int argc, char *argv[])
|
|
|
|
|
@@ -139,6 +141,7 @@ main(int argc, char *argv[])
|
|
|
|
|
bool Lopt = false;
|
|
|
|
|
bool Ropt = false;
|
|
|
|
|
bool topt = false;
|
|
|
|
|
+ bool Eopt = false;
|
|
|
|
|
extern int optind;
|
|
|
|
|
extern char *optarg;
|
|
|
|
|
int c;
|
|
|
|
|
@@ -207,6 +210,9 @@ main(int argc, char *argv[])
|
|
|
|
|
case 'T': /* --test-sparse */
|
|
|
|
|
opt.sparse = true;
|
|
|
|
|
Topt = true;
|
|
|
|
|
break;
|
|
|
|
|
+ case 'E': /* --extent-only */
|
|
|
|
|
+ opt.extentonly = true;
|
|
|
|
|
+ Eopt = true;
|
|
|
|
|
+ break;
|
|
|
|
|
case 'L': /* --no-link */
|
|
|
|
|
opt.nofollow = true;
|
|
|
|
|
Lopt = true;
|
|
|
|
|
break;
|
|
|
|
|
@@ -430,14 +436,14 @@ static int progress_col (const sequence_
|
|
|
|
|
@@ -315,7 +321,7 @@ main(int argc, char *argv[])
|
|
|
|
|
prog, Dopt, filename);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
- scrub_file(filename, sopt, seq, bopt, Sopt, Topt);
|
|
|
|
|
+ scrub_file(filename, sopt, seq, bopt, Sopt, Topt, Eopt);
|
|
|
|
|
#if __APPLE__
|
|
|
|
|
scrub_resfork(filename, seq, bopt);
|
|
|
|
|
#endif
|
|
|
|
|
@@ -346,14 +352,14 @@ done:
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
- bool nosig, bool sparse, bool enospc)
|
|
|
|
|
+ bool nosig, bool sparse, bool enospc, bool extentonly)
|
|
|
|
|
- bool Sopt, bool sparse, bool enospc)
|
|
|
|
|
+ bool Sopt, bool sparse, bool enospc, bool extentonly)
|
|
|
|
|
{
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
int i;
|
|
|
|
@ -588,11 +655,11 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
bool isfull = false;
|
|
|
|
|
- off_t written, checked;
|
|
|
|
|
+ off_t written = (off_t)-1, checked = (off_t)-1;
|
|
|
|
|
int pcol = progress_col(seq);
|
|
|
|
|
|
|
|
|
|
if (!(buf = alloc_buffer(bufsize))) {
|
|
|
|
|
@@ -468,7 +474,7 @@ scrub(char *path, off_t size, const sequ
|
|
|
|
|
#endif /* HAVE_LIBGCRYPT. */
|
|
|
|
|
fprintf(stderr, "%s: out of memory\n", prog);
|
|
|
|
|
@@ -381,7 +387,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
}
|
|
|
|
|
written = fillfile(path, size, buf, bufsize,
|
|
|
|
|
(progress_t)progress_update, p,
|
|
|
|
|
- (refill_t)genrand, sparse, enospc);
|
|
|
|
@ -600,7 +667,7 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
if (written == (off_t)-1) {
|
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog, path,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
@@ -482,7 +488,7 @@ scrub(char *path, off_t size, const sequ
|
|
|
|
|
@@ -395,7 +401,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
memset_pat(buf, seq->pat[i], bufsize);
|
|
|
|
|
written = fillfile(path, size, buf, bufsize,
|
|
|
|
|
(progress_t)progress_update, p,
|
|
|
|
@ -609,7 +676,7 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
if (written == (off_t)-1) {
|
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog, path,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
@@ -496,7 +502,7 @@ scrub(char *path, off_t size, const sequ
|
|
|
|
|
@@ -409,7 +415,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
memset_pat(buf, seq->pat[i], bufsize);
|
|
|
|
|
written = fillfile(path, size, buf, bufsize,
|
|
|
|
|
(progress_t)progress_update, p,
|
|
|
|
@ -618,48 +685,60 @@ diff -up scrub-2.6.1/src/scrub.c.extent-only scrub-2.6.1/src/scrub.c
|
|
|
|
|
if (written == (off_t)-1) {
|
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog, path,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
@@ -506,7 +512,7 @@ scrub(char *path, off_t size, const sequ
|
|
|
|
|
@@ -419,7 +425,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
printf("%s: %-8s", prog, "verify");
|
|
|
|
|
progress_create(&p, pcol);
|
|
|
|
|
progress_create(&p, 50);
|
|
|
|
|
checked = checkfile(path, written, buf, bufsize,
|
|
|
|
|
- (progress_t)progress_update, p, sparse);
|
|
|
|
|
+ (progress_t)progress_update, p, sparse, extentonly);
|
|
|
|
|
if (checked == (off_t)-1) {
|
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog, path,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
@@ -600,7 +606,7 @@ scrub_free(char *dirpath, const struct o
|
|
|
|
|
@@ -513,7 +519,7 @@ scrub_free(char *dirpath, off_t size, const sequence_t *seq,
|
|
|
|
|
size = blkalign(size, sb.st_blksize, DOWN);
|
|
|
|
|
do {
|
|
|
|
|
snprintf(path, sizeof(path), "%s/scrub.%.3d", dirpath, fileno++);
|
|
|
|
|
isfull = scrub(path, size, opt->seq, opt->blocksize, opt->nosig,
|
|
|
|
|
- false, true);
|
|
|
|
|
+ false, true, false);
|
|
|
|
|
- isfull = scrub(path, size, seq, bufsize, Sopt, false, true);
|
|
|
|
|
+ isfull = scrub(path, size, seq, bufsize, Sopt, false, true, false);
|
|
|
|
|
} while (!isfull);
|
|
|
|
|
while (--fileno >= 0) {
|
|
|
|
|
snprintf(path, sizeof(path), "%s/scrub.%.3d", dirpath, fileno);
|
|
|
|
|
@@ -678,7 +684,7 @@ scrub_file(char *path, const struct opt_
|
|
|
|
|
@@ -565,7 +571,7 @@ scrub_dirent(char *path, char *newpath)
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
scrub_file(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
- int bufsize, bool Sopt, bool sparse)
|
|
|
|
|
+ int bufsize, bool Sopt, bool sparse, bool extentonly)
|
|
|
|
|
{
|
|
|
|
|
struct stat sb;
|
|
|
|
|
filetype_t ftype = filetype(path);
|
|
|
|
|
@@ -590,7 +596,7 @@ scrub_file(char *path, off_t size, const sequence_t *seq,
|
|
|
|
|
prog, path, (int)(size - sb.st_size));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
- scrub(path, size, opt->seq, opt->blocksize, opt->nosig, opt->sparse, false);
|
|
|
|
|
+ scrub(path, size, opt->seq, opt->blocksize, opt->nosig, opt->sparse, false, opt->extentonly);
|
|
|
|
|
- scrub(path, size, seq, bufsize, Sopt, sparse, false);
|
|
|
|
|
+ scrub(path, size, seq, bufsize, Sopt, sparse, false, extentonly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Scrub apple resource fork component of file.
|
|
|
|
|
@@ -706,7 +712,7 @@ scrub_resfork(char *path, const struct o
|
|
|
|
|
@@ -618,7 +624,7 @@ scrub_resfork(char *path, const sequence_t *seq, int bufsize)
|
|
|
|
|
printf("%s: padding %s with %d bytes to fill last fs block\n",
|
|
|
|
|
prog, rpath, (int)(rsize - rsb.st_size));
|
|
|
|
|
}
|
|
|
|
|
- scrub(rpath, rsize, opt->seq, opt->blocksize, false, false, false);
|
|
|
|
|
+ scrub(rpath, rsize, opt->seq, opt->blocksize, false, false, false, false);
|
|
|
|
|
- scrub(rpath, rsize, seq, bufsize, false, false, false);
|
|
|
|
|
+ scrub(rpath, rsize, seq, bufsize, false, false, false, false);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@@ -728,7 +734,7 @@ scrub_disk(char *path, const struct opt_
|
|
|
|
|
@@ -639,7 +645,7 @@ scrub_disk(char *path, off_t size, const sequence_t *seq, int bufsize,
|
|
|
|
|
}
|
|
|
|
|
printf("%s: please verify that device size below is correct!\n", prog);
|
|
|
|
|
}
|
|
|
|
|
scrub(path, devsize, opt->seq, opt->blocksize, opt->nosig, opt->sparse,
|
|
|
|
|
- false);
|
|
|
|
|
+ false, false);
|
|
|
|
|
- scrub(path, size, seq, bufsize, Sopt, sparse, false);
|
|
|
|
|
+ scrub(path, size, seq, bufsize, Sopt, sparse, false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
--
|
|
|
|
|
2.20.1
|
|
|
|
|
|