"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.4/scripts/wipe-free.in" (28 Mar 2021, 2501 Bytes) of package /linux/privat/littleutils-1.2.4.tar.lz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "wipe-free.in": 1.2.3_vs_1.2.4.

    1 #! PROGBASH
    2 # vim: set filetype=bash:
    3 
    4 # wipe-free: overwrite all free space in a filesystem with zeros
    5 
    6 # Copyright (C) 2011-2021 by Brian Lindholm.  This file is part of the
    7 # littleutils utility set.
    8 #
    9 # The wipe-free utility is free software; you can redistribute it and/or modify
   10 # it under the terms of the GNU General Public License as published by the Free
   11 # Software Foundation; either version 3, or (at your option) any later version.
   12 #
   13 # The wipe-free utility is distributed in the hope that it will be useful, but
   14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   16 # more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # the littleutils.  If not, see <https://www.gnu.org/licenses/>.
   20 
   21 # get command-line options
   22 declare -i MAXCHUNKS=4096
   23 declare -i BS=4096
   24 declare -i COUNT=262144
   25 while getopts b:c:hm: opts
   26 do
   27   case $opts in
   28     b) BS=$OPTARG ;;
   29     c) COUNT=$OPTARG ;;
   30     h) echo 'wipe-free LU_VERSION'
   31        echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp)]'
   32        echo '  default: wipe-free -b 4096 -c 262144 -m 4096'
   33        exit 0 ;;
   34     m) MAXCHUNKS=$OPTARG ;;
   35     *) echo 'wipe-free LU_VERSION'
   36        echo 'usage: wipe-free [-b block_size] [-c count] [-m max_chunks] [-h(elp)]'
   37        echo '  default: wipe-free -b 4096 -c 262144 -m 4096'
   38        exit 1 ;;
   39   esac
   40 done
   41 shift $((${OPTIND}-1))
   42 declare -i SIZE TARGET=$(($BS*$COUNT))
   43 
   44 # set up traps
   45 trap 'rm -f zero*_$$_*.dat ; exit 1' 1 2 3 13 15
   46 
   47 # write files until max_chunk files are written or space is filled
   48 DONE='n'
   49 echo 'wipe-free message: beginning zero-file writes...'
   50 for IDX in $(seq -w 0001 $MAXCHUNKS) ; do
   51   if [ "$DONE" = 'n' ]; then
   52     TMPNAME=$(tempname -d . -s .dat zero${IDX}_$$) || exit 99
   53     TIME0="$EPOCHREALTIME"
   54     dd bs=$BS count=$COUNT if=/dev/zero of=$TMPNAME >& /dev/null
   55     sync
   56     TIME1="$EPOCHREALTIME"
   57     ELAPSED=$(echo $TIME0 $TIME1 | awk '{printf "%.3f\n", $2 - $1}')
   58     SIZE=$(filesize $TMPNAME)
   59     echo "  file $IDX: $SIZE bytes in $ELAPSED seconds as $TMPNAME"
   60     if [ $SIZE -lt $TARGET ]; then
   61       echo 'wipe-free message: free space filled with zeros'
   62       DONE='y'
   63     fi
   64   fi
   65 done
   66 
   67 # report on final results and remove space-filling zero files
   68 if [ "$DONE" = 'n' ]; then
   69   echo 'wipe-free warning: free space possibly not filled'
   70 fi
   71 echo 'wipe-free message: deleting zero files'
   72 rm -f zero*_$$_*.dat