Upload Tizen:Base source
[framework/base/util-linux-ng.git] / tests / ts / cramfs / mkfs
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
5 #
6 # This file is part of util-linux-ng.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 TS_TOPDIR="$(dirname $0)/../.."
19 TS_DESC="mkfs checksums"
20
21 . $TS_TOPDIR/functions.sh
22 ts_init "$*"
23 ts_skip_nonroot
24
25 set -o pipefail
26
27 ORIGPWD=$(pwd)
28 IMAGE_NAME="${TS_TESTNAME}-loop.img"
29 IMAGE_PATH="$TS_OUTDIR/$IMAGE_NAME"
30 IMAGE_SRC="$TS_OUTDIR/${TS_TESTNAME}-data"
31 LABEL="testCramfs"
32
33 ts_log "create mountpoint dir"
34
35 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
36
37 ts_log "generate data"
38 if [ ! -d "$IMAGE_SRC" ]; then
39         mkdir -p $IMAGE_SRC
40         for d in `seq 0 110`; do
41                 DIRNAME="$IMAGE_SRC/$(printf "dir-%03d" $d)"
42                 mkdir -p $DIRNAME
43                 for f in `seq 0 10`; do
44                         FILENAME="$DIRNAME/$(printf "data.%03d" $f)"
45                         printf "data in %03d-%03d" $d $f >> $FILENAME
46                 done
47         done
48 fi
49
50 cd $IMAGE_SRC
51
52 ts_log "list checksums from original data"
53 find -type f -exec md5sum {} \; | sort >> $TS_OUTPUT
54 echo >> $TS_OUTPUT
55
56 ts_log "create cramfs image"
57 $TS_CMD_MKCRAMFS -n $LABEL $IMAGE_SRC $IMAGE_PATH 2>&1 >> $TS_OUTPUT
58 [ -s "$IMAGE_PATH" ] || ts_die "Cannot create $IMAGE_PATH"
59
60 cd $TS_OUTDIR
61
62 ts_log "count MD5 from the image"
63 md5sum $IMAGE_NAME 2>&1 | sort >> $TS_OUTPUT
64 echo >> $TS_OUTPUT
65
66 ts_log "create loop device from image"
67 DEVICE=$($TS_CMD_LOSETUP -s -f $IMAGE_PATH)
68
69 ts_log "check the image"
70 ts_device_has "TYPE" "cramfs" $DEVICE
71 [  "$?" == "0" ] || ts_die "Cannot found cramfs on $DEVICE" $DEVICE
72
73 ts_udev_dev_support "by-label" $LABEL
74 [ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
75
76 ts_log "mount the image"
77 $TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
78
79 # check it
80 ts_is_mounted $DEVICE || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
81
82 cd $TS_MOUNTPOINT
83
84 ts_log "list the image"
85 ls -laR --time-style=long-iso . >> $TS_OUTPUT
86 echo >> $TS_OUTPUT
87
88 ts_log "list checksums from new data"
89 find . -type f -exec md5sum {} \; | sort >> $TS_OUTPUT
90 echo >> $TS_OUTPUT
91
92 cd $ORIGPWD
93
94 ts_log "umount the image"
95 $TS_CMD_UMOUNT $DEVICE
96 $TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT
97 ts_finalize
98