[Pkg-privacy-commits] [libgsecuredelete] 117/168: Workaround missing support for filesystem file size limit in `sfill`
Ulrike Uhlig
u-guest at moszumanska.debian.org
Thu Jul 7 20:06:46 UTC 2016
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch master
in repository libgsecuredelete.
commit 57000102649513474fd45cb10c96f8d25118d002
Author: Colomban Wendling <ban at herbesfolles.org>
Date: Wed May 23 22:06:47 2012 +0200
Workaround missing support for filesystem file size limit in `sfill`
Add a wrapper script around `sfill` to support filesystems with a file
size limit, especially FAT.
`sfill` only creates one huge file and guesses that the filesystem is
full when enlarging that file fails. This doesn't work on filesystems
with a smaller file size limit than the maximal filesystem file, since
a write would fail when reaching the file size limit rather than when
the filesystem would actually be full.
To work this around, we add a wrapper script that creates huge files
until no more data can be written to a new empty file. This could
still theoretically not fill the whole empty space if it isn't possible
to allocate all that space without removing or truncating existing
files, e.g. if (max_file_size * free_inodes) < free_space. However
this is really unlikely and can't really be worked around anyway.
---
Makefile.am | 11 +++++
configure.ac | 8 ++--
gsd-sfill-helper.in | 106 ++++++++++++++++++++++++++++++++++++++++++++++
gsecuredelete/Makefile.am | 19 ++++++++-
gsecuredelete/config.vapi | 4 +-
5 files changed, 141 insertions(+), 7 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index aa84014..44e8be1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,3 +13,14 @@ EXTRA_DIST = AUTHORS \
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gsecuredelete.pc
+
+pkglibexec_SCRIPTS = gsd-sfill-helper
+CLEANFILES = $(pkglibexec_SCRIPTS)
+EXTRA_DIST += gsd-sfill-helper.in
+
+compile_script = sed -e 's%[@]SRM_PATH[@]%$(SRM_PATH)%g' \
+ -e 's%[@]SFILL_PATH[@]%$(SFILL_PATH)%g'
+
+gsd-sfill-helper: gsd-sfill-helper.in Makefile
+ $(compile_script) < $(srcdir)/$< > $@
+ chmod +x $@
diff --git a/configure.ac b/configure.ac
index bbbf2ee..aa21c8f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,10 +37,10 @@ GSD_PATH_PROG([SFILL], [sfill], [/usr/bin/sfill])
GSD_PATH_PROG([SMEM], [smem], [/usr/bin/smem])
GSD_PATH_PROG([SSWAP], [sswap], [/usr/bin/sswap])
-AC_DEFINE_UNQUOTED([SRM_PATH], ["$SRM"], [Path to the srm binary])
-AC_DEFINE_UNQUOTED([SFILL_PATH], ["$SFILL"], [Path to the sfill binary])
-AC_DEFINE_UNQUOTED([SMEM_PATH], ["$SMEM"], [Path to the smem binary])
-AC_DEFINE_UNQUOTED([SSWAP_PATH], ["$SSWAP"], [Path to the sswap binary])
+AC_SUBST([SRM_PATH], ["$SRM"])
+AC_SUBST([SFILL_PATH], ["$SFILL"])
+AC_SUBST([SMEM_PATH], ["$SMEM"])
+AC_SUBST([SSWAP_PATH], ["$SSWAP"])
# Checks for libraries.
diff --git a/gsd-sfill-helper.in b/gsd-sfill-helper.in
new file mode 100644
index 0000000..61f674f
--- /dev/null
+++ b/gsd-sfill-helper.in
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 Colomban Wendling <ban at herbesfolles.org>
+#
+# 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# drop-in replacement and wrapper script for sfill to work around its lack of
+# support for file size limits.
+
+
+SRM="@SRM_PATH@"
+SFILL="@SFILL_PATH@"
+
+OPT_f=
+OPT_i=
+OPT_I=
+OPT_l=
+OPT_v=
+OPT_z=
+
+
+# die [MESSAGE]
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+# progress_step
+progress_step_STEP=0
+progress_step() {
+ if [ -n $OPT_v ]; then
+ case "$(echo $OPT_l | wc -w)" in
+ 0)
+ echo '*******************';;
+ 1)
+ echo '*';;
+ *)
+ [ "$progress_step_STEP" -gt 0 ] && echo '*'
+ ;;
+ esac
+ progress_step_STEP=1
+ fi
+}
+
+
+# parse arguments
+while getopts 'fiIlvz' o; do
+ case "$o" in
+ f) OPT_f=-f;;
+ i) OPT_i=-i;;
+ I) OPT_I=-I;;
+ l) OPT_l="$OPT_l -l";;
+ v) OPT_v=-v;;
+ z) OPT_z=-z;;
+ esac
+done
+shift $(expr $OPTIND - 1)
+[ $# -eq 1 ] || die "wrong arguments"
+
+
+
+# wipe inodes, no workaround needed
+if [ -n "$OPT_i" ] || [ -z "$OPT_I" ]; then
+ # don't report progress if we're also gonna wipe disk space
+ inode_v=$OPT_v
+ [ -z $OPT_i ] && inode_v=
+
+ "$SFILL" $OPT_f -i $OPT_l $inode_v $OPT_z "$1"
+fi
+
+# wipe disk space, work around for file size limit
+if [ -z "$OPT_i" ]; then
+ dir=$(mktemp -d --tmpdir="$1") || die "failed to create temp directory"
+ trap "rm -rf '$dir'" INT QUIT TERM EXIT
+
+ input=/dev/urandom
+ [ -r "$input" ] || input=/dev/zero
+
+ while [ 1 ]; do
+ file=$(mktemp --tmpdir="$dir") || die "failed to create temp file"
+
+ dd if="$input" of="$file" bs=8M conv=fdatasync 2>&1
+
+ # if the file we tried to create has size 0, guess there's actually no
+ # space left on device
+ size=$(stat -c '%s' "$file") || die "failed to stat file '$f'"
+ [ "$size" = 0 ] && break
+ done
+ sync
+ progress_step
+
+ "$SRM" -r $OPT_f $OPT_l $OPT_z "$dir"
+ progress_step
+fi
diff --git a/gsecuredelete/Makefile.am b/gsecuredelete/Makefile.am
index 05c1005..47e09a1 100644
--- a/gsecuredelete/Makefile.am
+++ b/gsecuredelete/Makefile.am
@@ -1,7 +1,8 @@
noinst_PROGRAMS = test
lib_LTLIBRARIES = libgsecuredelete.la
-EXTRA_DIST = config.vapi
+EXTRA_DIST = config.vapi
+DISTCLEANFILES = gsd-config.h
AM_VALAFLAGS = $(VALA_PACKAGES:%=--pkg=%)
AM_CFLAGS = $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) -DG_LOG_DOMAIN=\"$(PACKAGE)\"
@@ -31,3 +32,19 @@ test_LDADD = libgsecuredelete.la
gsecuredelete.vapi: libgsecuredelete_la_vala.stamp
test_vala.stamp: gsecuredelete.vapi
+
+$(libgsecuredelete_la_SOURCES): gsd-config.h
+
+gsd-config.h: Makefile
+ $(AM_V_GEN) \
+ echo '#ifndef GSD_CONFIG_H' > $@; \
+ echo '#define GSD_CONFIG_H' >> $@; \
+ echo '' >> $@; \
+ echo '#define PACKAGE "$(PACKAGE)"' >> $@; \
+ echo '#define VERSION "$(VERSION)"' >> $@; \
+ echo '#define SRM_PATH "$(SRM_PATH)"' >> $@; \
+ echo '#define SFILL_PATH "$(pkglibexecdir)/gsd-sfill-helper"' >> $@; \
+ echo '#define SMEM_PATH "$(SMEM_PATH)"' >> $@; \
+ echo '#define SSWAP_PATH "$(SSWAP_PATH)"' >> $@; \
+ echo '' >> $@; \
+ echo '#endif /* guard */' >> $@
diff --git a/gsecuredelete/config.vapi b/gsecuredelete/config.vapi
index 36a0348..528495c 100644
--- a/gsecuredelete/config.vapi
+++ b/gsecuredelete/config.vapi
@@ -1,6 +1,6 @@
-[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
-namespace Config
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "gsd-config.h")]
+namespace Gsd.Config
{
public const string PACKAGE;
public const string VERSION;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libgsecuredelete.git
More information about the Pkg-privacy-commits
mailing list