#!/bin/bash

#
# script to zero out a file in place.
# It's written to work around the fact that 
# recent (fall 2005) versions of NTFS drivers
# can only write to a file in place, but can't 
# truncate expand or delete.
#  
# This uses DD and the shell '<>'  open in place 
# construct to open a file read/write and write 
# small blocks of data until the end of the file is 
# reahed.

# Note that this will fail if the file is smaller than 
# $Block  .  The default size of Block is 32 bytes.
# You can change that default by setting the shell 
# variable 'Block' to a smaller number (e.g. 8)

#  Block=8  killntfile.sh /mnt/hda1/somefile.exe 


Block=${Block-32}
for file in "$@" ;do 
	size=`wc -c < "$@" ` 
	count=$((  (size+Block-1) / Block ))
	if [ $count -le 1 ] ; then 
		echo "count = $count . filesize = $size blocksize=$Block. The write  may  fail" 1>2
	fi

	if [ -f "$file" ] ; then
		dd if=/dev/zero count=$count bs=$Block  <> "$file"
	fi
done


