Update to upstream util-linux 2.20.1
[framework/base/util-linux-ng.git] / tests / ts / fdisk / sunlabel
1 #!/bin/bash
2
3 #
4 # This file is part of util-linux.
5 #
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16
17 TS_TOPDIR="$(dirname $0)/../.."
18 TS_DESC="sunlabel tests"
19
20 . $TS_TOPDIR/functions.sh
21 ts_init "$*"
22
23 FDISK_CMD_INIT="s\n1\n1\n1024\n" # create new sunlabel
24 FDISK_CMD_WRITE_CLOSE="w\nq\n"
25 FDISK_CMD_DELETEALL="d\n1\nd\n2\nd\n3\nd\n4\nd\n5\nd\n6\nd\n7\nd\n8\n" # delete all partitions
26
27 FDISK_CMD_CREATE_PRIMARY="n\n1\n0\n128\n" # create first partition, cylinders 0 through 128
28 FDISK_CMD_TOGGLE_READONLY="a\n1\n" # sets first partition as read-only
29 FDISK_CMD_TOGGLE_MOUNTABLE="c\n1\n" # sets first partition as mountable
30 FDISK_CMD_CHANGE_SYSID="t\n1\n4\n" # changes sysid to 4 (SunOS usr)
31 FDISK_CMD_CREATE_SECONDARY="n\n2\n128\n\n" # create secondary partition cylinders 128 to the end of disk
32
33 #set -x
34
35 ts_log "Initialize empty image"
36 TEST_IMAGE_NAME=$(ts_image_init 10)
37 ts_image_md5sum >> $TS_OUTPUT 2>&1
38
39 ts_log "Create new SUN partition table"
40 echo -e "${FDISK_CMD_INIT}${FDISK_CMD_DELETEALL}${FDISK_CMD_WRITE_CLOSE}" \
41          | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
42 ts_image_md5sum >> $TS_OUTPUT 2>&1
43
44 ts_log "Create first partition"
45 echo -e "${FDISK_CMD_CREATE_PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
46         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
47 ts_image_md5sum >> $TS_OUTPUT 2>&1
48
49 ts_log "Set partition sysid"
50 echo -e "${FDISK_CMD_CHANGE_SYSID}${FDISK_CMD_WRITE_CLOSE}" | \
51         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
52 ts_image_md5sum >> $TS_OUTPUT 2>&1
53
54 ts_log "Set first partition readonly"
55 echo -e "${FDISK_CMD_TOGGLE_READONLY}${FDISK_CMD_WRITE_CLOSE}" | \
56         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
57 ts_image_md5sum >> $TS_OUTPUT 2>&1
58
59 ts_log "Set first partition mountable"
60 echo -e "${FDISK_CMD_TOGGLE_MOUNTABLE}${FDISK_CMD_WRITE_CLOSE}" | \
61         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
62 ts_image_md5sum >> $TS_OUTPUT 2>&1
63
64 ts_log "Create second partition"
65 echo -e "${FDISK_CMD_CREATE_SECONDARY}${FDISK_CMD_WRITE_CLOSE}" | \
66         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
67 ts_image_md5sum >> $TS_OUTPUT 2>&1
68
69 ts_log "Delete all partitions"
70 echo -e "${FDISK_CMD_DELETEALL}${FDISK_CMD_WRITE_CLOSE}" | \
71         $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
72 ts_image_md5sum >> $TS_OUTPUT 2>&1
73
74 ts_finalize