"Fossies" - the Fresh Open Source Software Archive

Member "tc-play-3.3/test/reduce_test_vol.sh" (2 Mar 2020, 1327 Bytes) of package /linux/misc/tc-play-3.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 #############################################################
    4 # This script takes a volume file and reduces its effective
    5 # compressed size by creating a new zero-filled volume
    6 # and only copying over the header, hidden header and the
    7 # respective backup headers into the new volume.
    8 #
    9 # Since the new file consists mostly of zeros, it compresses
   10 # rather well.
   11 #############################################################
   12 
   13 if [ $# -lt 2 ]; then
   14   echo "Usage: $0 <src volume> <dst volume>"
   15   exit 1
   16 fi
   17 
   18 SRC_VOL=$1
   19 DST_VOL=$2
   20 
   21 # Find the total size of the source volume, in bytes.
   22 SZ=`stat -c "%s" $SRC_VOL`
   23 
   24 # Find the total size of the source volume, in blocks.
   25 SZ_BLOCKS=`echo $SZ / 512 | bc`
   26 
   27 # Find the block at which the backup header area starts.
   28 BCK_HDR_START=`echo $SZ_BLOCKS - 256 | bc`
   29 
   30 # Define the sizes of the header and backup header areas,
   31 # in blocks.
   32 HDR_AREA_BLOCKS=256
   33 BCK_HDR_AREA_BLOCKS=256
   34 
   35 
   36 # Create new zero-filled volume with the same size as the
   37 # source volume.
   38 dd if=/dev/zero of=$DST_VOL bs=512 count=$SZ_BLOCKS
   39 
   40 # Copy over the header area.
   41 dd if=$SRC_VOL  of=$DST_VOL bs=512 count=$HDR_AREA_BLOCKS       \
   42     conv=notrunc
   43 
   44 # Copy over the backup header area.
   45 dd if=$SRC_VOL  of=$DST_VOL bs=512 count=$BCK_HDR_AREA_BLOCKS   \
   46    conv=notrunc seek=$BCK_HDR_START skip=$BCK_HDR_START
   47