#!/bin/sh
#
# Description:
#
#	clear SNIA Common raid Disk Data Format.
#
# Authors:
#	Haruo Tomita <haruo.tomita@toshiba.co.jp>
#
# (C) Copyright TOSHIBA Corp. 2010
#
# 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 2 of the License, or
# (at your option) any later version.
#
export LANG=C
OPTIONS=$#
DEV=$1
#
# SNIA Common raid Disk Data Format v2.0 size is 32Mbyte.
#
# http://www.snia.org/tech_activities/standards/curr_standards/ddf
#
DDF_SIZE=65536

if [ $OPTIONS -ne 1 ]; then
	echo "No DEVICE argument given."
	echo "Usage clear_ddf DEVICE"
	exit 1
fi

if [ ! -d /sys/block/$DEV ]; then
	echo "No such device."
	exit 1
fi

SIZE=`cat /sys/block/$DEV/size`
if [ $SIZE -gt $DDF_SIZE ] ; then
	SEEK=`expr $SIZE - $DDF_SIZE`
else
	echo "Unknown device data size."
	exit 1
fi

echo "Do you want to clear SNIA Common raid Disk Data Format v2.0?"
echo -n "Press Enter to continue or ctrl-c to abort."
read

echo "Clear SNIA Common raid Disk Data Format v2.0."
dd if=/dev/zero of=/dev/$DEV seek=$SEEK count=$DDF_SIZE