"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/wipe-free.in" between
littleutils-1.2.3.tar.lz and littleutils-1.2.4.tar.lz

About: littleutils are a collection of small and simple utilities (rename files, search for duplicate files, ...).

wipe-free.in  (littleutils-1.2.3.tar.lz):wipe-free.in  (littleutils-1.2.4.tar.lz)
#! PROGBASH #! PROGBASH
# vim: set filetype=bash: # vim: set filetype=bash:
# wipe-free: overwrite all free space in a filesystem with zeros # wipe-free: overwrite all free space in a filesystem with zeros
# Copyright (C) 2011-2012 by Brian Lindholm. This file is part of the # Copyright (C) 2011-2021 by Brian Lindholm. This file is part of the
# littleutils utility set. # littleutils utility set.
# #
# The wipe-free utility is free software; you can redistribute it and/or modify # The wipe-free utility 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 # it under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later version. # Software Foundation; either version 3, or (at your option) any later version.
# #
# The wipe-free utility is distributed in the hope that it will be useful, but # The wipe-free utility is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# the littleutils. If not, see <https://www.gnu.org/licenses/>. # the littleutils. If not, see <https://www.gnu.org/licenses/>.
# set up traps
trap 'rm -f zero*_$$_*.dat ; exit 1' 1 2 3 13 15
trap 'rm -f zero*_$$_*.dat ; exit 0' 0
# get command-line options # get command-line options
MAXCHUNKS=4096 declare -i MAXCHUNKS=4096
BS=4096 declare -i BS=4096
COUNT=262144 declare -i COUNT=262144
while getopts b:c:hm: opts while getopts b:c:hm: opts
do do
case $opts in case $opts in
b) BS=${OPTARG} ;; b) BS=$OPTARG ;;
c) COUNT=${OPTARG} ;; c) COUNT=$OPTARG ;;
h) echo 'wipe-free LU_VERSION' h) echo 'wipe-free LU_VERSION'
echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp )]' echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp )]'
echo ' default: wipe-free -b 4096 -c 262144 -m 4096' echo ' default: wipe-free -b 4096 -c 262144 -m 4096'
exit 0 ;; exit 0 ;;
m) MAXCHUNKS=${OPTARG} ;; m) MAXCHUNKS=$OPTARG ;;
*) echo 'wipe-free LU_VERSION' *) echo 'wipe-free LU_VERSION'
echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp )]' echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp )]'
echo ' default: wipe-free -b 4096 -c 262144 -m 4096' echo ' default: wipe-free -b 4096 -c 262144 -m 4096'
exit 1 ;; exit 1 ;;
esac esac
done done
shift `expr ${OPTIND} - 1` shift $((${OPTIND}-1))
TARGET=$(($BS*$COUNT)) declare -i SIZE TARGET=$(($BS*$COUNT))
# set up traps
trap 'rm -f zero*_$$_*.dat ; exit 1' 1 2 3 13 15
# write files until max_chunk files are written or space is filled # write files until max_chunk files are written or space is filled
DONE='no' DONE='n'
echo 'wipe-free message: beginning zero-file writes...' echo 'wipe-free message: beginning zero-file writes...'
for IDX in `seq -w 0001 ${MAXCHUNKS}` ; do for IDX in $(seq -w 0001 $MAXCHUNKS) ; do
if [ "$DONE" = 'no' ]; then if [ "$DONE" = 'n' ]; then
TMPNAME=`tempname -d . -s .dat zero${IDX}_$$` || exit 99 TMPNAME=$(tempname -d . -s .dat zero${IDX}_$$) || exit 99
TIME0=`date +%s.%N` TIME0="$EPOCHREALTIME"
dd bs=${BS} count=${COUNT} if=/dev/zero of=${TMPNAME} >& /dev/null dd bs=$BS count=$COUNT if=/dev/zero of=$TMPNAME >& /dev/null
sync sync
TIME1=`date +%s.%N` TIME1="$EPOCHREALTIME"
ELAPSED=`echo $TIME0 $TIME1 | awk '{printf "%.3f\n", $2 - $1}'` ELAPSED=$(echo $TIME0 $TIME1 | awk '{printf "%.3f\n", $2 - $1}')
SIZE=`filesize "$TMPNAME"` SIZE=$(filesize $TMPNAME)
echo " file $IDX: $SIZE bytes in $ELAPSED seconds as $TMPNAME" echo " file $IDX: $SIZE bytes in $ELAPSED seconds as $TMPNAME"
if [ "$SIZE" -lt "$TARGET" ]; then if [ $SIZE -lt $TARGET ]; then
echo 'wipe-free message: free space filled with zeros' echo 'wipe-free message: free space filled with zeros'
DONE='yes' DONE='y'
fi fi
fi fi
done done
# report on final results and remove space-filling zero files # report on final results and remove space-filling zero files
if [ "$DONE" = 'no' ]; then if [ "$DONE" = 'n' ]; then
echo 'wipe-free warning: free space possibly not filled' echo 'wipe-free warning: free space possibly not filled'
fi fi
echo 'wipe-free message: deleting zero files' echo 'wipe-free message: deleting zero files'
rm -f zero*_$$_*.dat rm -f zero*_$$_*.dat
 End of changes. 12 change blocks. 
25 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)