summaryrefslogtreecommitdiffstats
path: root/tests/ts/fdisk/mbr-nondos-mode
blob: 4db206415b4654a522a01c1df76c1a7d7dc4d26b (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash

#
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

TS_TOPDIR="${0%/*}/../.."
TS_DESC="MBR - non-dos mode"

. "$TS_TOPDIR"/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_FDISK"
ts_check_test_command "$TS_HELPER_MD5"

# cmd to changes system id to 0x1
FDISK_CMD_INIT="x\ni\n0x1\nr\n"
FDISK_CMD_WRITE_CLOSE="w\nq\n"
FDISK_CMD_CREATE_DOSLABEL="o\n" #create dos label
FDISK_CMD_CREATE_1PRIMARY="n\np\n\n\n+3M\n" # create primary partition of size 3MiB
FDISK_CMD_CREATE_2PRIMARY="n\np\n\n\n+2M\n" # create primary partition of size 2MiB
FDISK_CMD_SET_ACTIVE="a\n1\n" # set first partition active
FDISK_CMD_CREATE_EXTENDED="n\ne\n\n\n\n" # create extended partition
FDISK_CMD_CREATE_LOGICAL="n\nl\n\n+2M\n" # create next logical partition of size 10 sectors
FDISK_CMD_DELETE_LOGICALS="d\n6\nd\n5\nd\n6\n" # delete middle, head, tail, last partitions
FDISK_CMD_DELETE_1PRIMARY="d\n1\n" # delete first primary
FDISK_CMD_DELETE_2PRIMARY="d\n2\n" # delete first primary
FDISK_CMD_DELETE_EXTENDED="d\n3\n" # delete second primary

# ignore architectures where MBR is not a default
ARCH=$(uname -m)
case $ARCH in
	*sparc* )
		ts_skip "unsupported"
		;;
	*)
		;;
esac

function print_layout {
	echo -ne "\n---layout----------\n" >> $TS_OUTPUT
	$TS_CMD_FDISK -x ${TEST_IMAGE_NAME} >> $TS_OUTPUT
	echo -ne   "-------------------\n\n" >> $TS_OUTPUT

	ts_fdisk_clean ${TEST_IMAGE_NAME}
}

#set -x

ts_init_subtest "empty-pt"
ts_log "Initialize empty image"
TEST_IMAGE_NAME=$(ts_image_init 20)	# 20 MiB
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG

# need to run init twice, to change system ID after new label, otherwise system
# ID will be random and will screw up md5's
ts_log "Create new DOS partition table"
echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
	 | $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "1st-primary"
ts_log "Create 1st primary partition"
echo -e "${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "1st-active"
ts_log "Set primary partition active"
echo -e "${FDISK_CMD_SET_ACTIVE}${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "1st-primary-recreate"
ts_log "Re-create 1st primary partition"
echo -e "d\n${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "2nd-primary"
ts_log "Create 2nd primary partition"
echo -e "${FDISK_CMD_CREATE_2PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "extended"
ts_log "Create extended partition"
echo -e "${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK  ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "logical"
ts_log "Create logical partitions"
echo -e "${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "logical-delete"
ts_log "Delete logical partitions"
echo -e "${FDISK_CMD_DELETE_LOGICALS}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "logical-recreate"
ts_log "Create another logical partition"
echo -e "${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "1st-primary-delete"
ts_log "Delete primary partition"
echo -e "${FDISK_CMD_DELETE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "1nd-primary-delete"
ts_log "Delete primary partition"
echo -e "${FDISK_CMD_DELETE_2PRIMARY}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "extended-delete"
ts_log "Delete extended partition"
echo -e "${FDISK_CMD_DELETE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \
	| $TS_CMD_FDISK -c=dos -u=cylinders ${TEST_IMAGE_NAME} &> /dev/null
ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_finalize_subtest


ts_init_subtest "first-sector-at-end"
ts_log "Create new DOS partition table (again)"
echo -e "${FDISK_CMD_INIT}${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
	 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
ts_log "Create 1st primary at the end of device"
echo -e "n\np\n1\n20000\n\n${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
print_layout

ts_log "Create 2nd primary at the begin of device"
echo -e "n\np\n2\n\n\n${FDISK_CMD_WRITE_CLOSE}" | \
	$TS_CMD_FDISK ${TEST_IMAGE_NAME} >> $TS_OUTPUT
print_layout
ts_finalize_subtest


ts_finalize