#!/bin/sh

set -e

if [ $# -ne 2 ]; then
	echo "Usage: $0 FILE BLOCK_SIZE" >&2
	exit 1
fi

FILE="$1"
BLOCK_SIZE="$2"

NDIR=12
ADDRS=$(($BLOCK_SIZE / 4))

# Fill up the direct blocks and indirect block, plus two indirect blocks in the
# first doubly-indirect block.
dd if=/dev/zero of="$FILE" bs="$BLOCK_SIZE" count=$(($NDIR + 3 * $ADDRS))

# Punch a hole from the middle of the first indirect block in the
# doubly-indirect block to the beginning of the second indirect block.
fallocate -p -o $(($BLOCK_SIZE * ($NDIR + $ADDRS + $ADDRS / 2))) -l $((BLOCK_SIZE * ($ADDRS / 2))) "$FILE"
