summaryrefslogtreecommitdiffstats
path: root/tests/scripts/mkdup
blob: c48a9f05a062247ef31d745eb8b32f855515758c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
OPTS="-O bigalloc -C 8192"
SIZE=4096
IMG=/tmp/foo.img
TMP=$(mktemp)
SIZE_A=15000
SIZE_B=5000
SIZE_C=20000

DEBUGFS=./debugfs/debugfs
MKE2FS=./misc/mke2fs
FSCK=./e2fsck/e2fsck

dd if=/dev/zero of=$IMG bs=1k count=$SIZE
echo $MKE2FS -F -t ext4 -L test $OPTS test.img $SIZE
$MKE2FS -F -t ext4 -L test $OPTS $IMG $SIZE
dd if=/dev/zero of=$TMP bs=$SIZE_A count=1 >& /dev/null
echo Writing $SIZE_A bytes to a
$DEBUGFS -w -R "write $TMP a" $IMG
BLKS=$(./debugfs/debugfs -R "blocks a" $IMG)
cp /dev/null $TMP
echo "Releasing blocks $BLKS"
for i in $BLKS ; do echo "freeb $i" >> $TMP; done
$DEBUGFS -w $IMG < $TMP >& /dev/null

echo Writing $SIZE_B bytes to b
dd if=/dev/zero of=$TMP bs=$SIZE_B count=1 >& /dev/null
$DEBUGFS -w -R "write $TMP b" $IMG
if [ -n "$SIZE_C" ]; then
    BLKS=$(./debugfs/debugfs -R "blocks b" $IMG)
    cp /dev/null $TMP
    echo "Releasing blocks $BLKS"
    for i in $BLKS ; do echo "freeb $i" >> $TMP; done
    $DEBUGFS -w $IMG < $TMP >& /dev/null

    echo Writing $SIZE_C bytes to c
    dd if=/dev/zero of=$TMP bs=$SIZE_C count=1 >& /dev/null
    $DEBUGFS -w -R "write $TMP c" $IMG
fi
echo "set_inode_field a mtime 201107040000" > $TMP
echo "set_inode_field b mtime 201107050000" >> $TMP
if [ -n "$SIZE_C" ]; then
    echo "set_inode_field c mtime 201107060000" >> $TMP
fi
$DEBUGFS -w $IMG < $TMP >& /dev/null

$FSCK -fy $IMG
rm $TMP