#
# Dependencies of this sub-command
#
read_file_depends()
{
	echo ""
}

#
# Sub-command: read file
#
subcmd_read_file()
{
	log_debug "subcmd_read_file"

	check_argc $# 1 +
	check_hostid any $HOSTID
	exec_remote_host_agent $HOSTID - systest::gfarm2fs::read_file "file-path=$1" "checksum=$2"
	[ $? -ne 0 ] && log_error "gfservice systest::gfarm2fs::read_file failed"

	log_debug "end subcmd_read_file"
}

read_file()
{
	FILE_PATH=$1
	CHECKSUM_EXPECTED=$2

	if [ X$CHECKSUM_EXPECTED = X ]; then
		dd if=$FILE_PATH of=/dev/null
		[ $? -ne 0 ] && log_error "failed to read file: $FILE_PATH"
	else
		dd if=$FILE_PATH of=/dev/null
		[ $? -ne 0 ] && log_error "failed to read file: $FILE_PATH"
		CHECKSUM_ACTUAL=`openssl md5 $FILE_PATH | awk '{ print $2 }'`
		if [ X$CHECKSUM_ACTUAL != X$CHECKSUM_EXPECTED ]; then
			log_error "checksum of a file $FILE_PATH is not same." \
				"expected: $CHECKSUM_EXPECTED actual: " \
				"$CHECKSUM_ACTUAL"
		fi
	fi
	log_debug "$PROGHOST read $FILE_PATH done"
}

#
# Dependencies of this sub-command agent
#
read_file_agent_depends()
{
	echo ""
}

#
# Sub-command: systest::gfarm2fs::read_file
# Read given files.
#
subcmd_read_file_agent()
{
	log_debug "subcmd_read_file_agent"

	FILE_PATH=`get_param file-path`
	CHECKSUM=`get_param checksum`

	read_file $FILE_PATH $CHECKSUM

	log_debug "end subcmd_read_file_agent"

	return 0
}
