Debian Codegraph @

tests/ts/fdisk/mbr-nondos-mode

raw
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="${0%/*}/../.."
18 TS_DESC="MBR - non-dos mode"
19
20 . "$TS_TOPDIR"/functions.sh
21 ts_init "$*"
22
23 ts_check_test_command "$TS_CMD_FDISK"
24 ts_check_test_command "$TS_HELPER_MD5"
25
26 # cmd to changes system id to 0x1
27 FDISK_CMD_INIT="x\ni\n0x1\nr\n"
28 FDISK_CMD_WRITE_CLOSE="w\nq\n"
29 FDISK_CMD_CREATE_DOSLABEL="o\n" #create dos label
30 FDISK_CMD_CREATE_1PRIMARY="n\np\n\n\n+3M\n" # create primary partition of size 3MiB
31 FDISK_CMD_CREATE_2PRIMARY="n\np\n\n\n+2M\n" # create primary partition of size 2MiB
32 FDISK_CMD_SET_ACTIVE="a\n1\n" # set first partition active
33 FDISK_CMD_CREATE_EXTENDED="n\ne\n\n\n\n" # create extended partition
34 FDISK_CMD_CREATE_LOGICAL="n\nl\n\n+2M\n" # create next logical partition of size 10 sectors
35 FDISK_CMD_DELETE_LOGICALS="d\n6\nd\n5\nd\n6\n" # delete middle, head, tail, last partitions
36 FDISK_CMD_DELETE_1PRIMARY="d\n1\n" # delete first primary
37 FDISK_CMD_DELETE_2PRIMARY="d\n2\n" # delete first primary
38 FDISK_CMD_DELETE_EXTENDED="d\n3\n" # delete second primary
39
40 # ignore architectures where MBR is not a default
41 ARCH=$(uname -m)
42 case $ARCH in
43 *sparc* )
44 ts_skip "unsupported"
45 ;;
46 *)
47 ;;
48 esac
49
50 function print_layout {
51 echo -ne "\n---layout----------\n" >> $TS_OUTPUT
52 $TS_CMD_FDISK -x ${TEST_IMAGE_NAME} >> $TS_OUTPUT
53 echo -ne "-------------------\n\n" >> $TS_OUTPUT
54
55 ts_fdisk_clean ${TEST_IMAGE_NAME}
56 }
57
58 #set -x
59
60 ts_init_subtest "empty-pt"
61 ts_log "Initialize empty image"
62 TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB
63 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
64
65 # need to run init twice, to change system ID after new label, otherwise system
66 # ID will be random and will screw up md5's
67 ts_log "Create new DOS partition table"
68 echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
69 | $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null
70 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
71 print_layout
72 ts_finalize_subtest
73
74
75 ts_init_subtest "1st-primary"
76 ts_log "Create 1st primary partition"
77 echo -e "${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
78 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
79 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
80 print_layout
81 ts_finalize_subtest
82
83
84 ts_init_subtest "1st-active"
85 ts_log "Set primary partition active"
86 echo -e "${FDISK_CMD_SET_ACTIVE}${FDISK_CMD_WRITE_CLOSE}" | \
87 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
88 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
89 print_layout
90 ts_finalize_subtest
91
92
93 ts_init_subtest "1st-primary-recreate"
94 ts_log "Re-create 1st primary partition"
95 echo -e "d\n${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
96 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
97 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
98 print_layout
99 ts_finalize_subtest
100
101
102 ts_init_subtest "2nd-primary"
103 ts_log "Create 2nd primary partition"
104 echo -e "${FDISK_CMD_CREATE_2PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
105 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
106 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
107 print_layout
108 ts_finalize_subtest
109
110
111 ts_init_subtest "extended"
112 ts_log "Create extended partition"
113 echo -e "${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" | \
114 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
115 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
116 print_layout
117 ts_finalize_subtest
118
119
120 ts_init_subtest "logical"
121 ts_log "Create logical partitions"
122 echo -e "${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
123 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
124 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
125 print_layout
126 ts_finalize_subtest
127
128
129 ts_init_subtest "logical-delete"
130 ts_log "Delete logical partitions"
131 echo -e "${FDISK_CMD_DELETE_LOGICALS}${FDISK_CMD_WRITE_CLOSE}" \
132 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
133 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
134 print_layout
135 ts_finalize_subtest
136
137
138 ts_init_subtest "logical-recreate"
139 ts_log "Create another logical partition"
140 echo -e "${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
141 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
142 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
143 print_layout
144 ts_finalize_subtest
145
146
147 ts_init_subtest "1st-primary-delete"
148 ts_log "Delete primary partition"
149 echo -e "${FDISK_CMD_DELETE_1PRIMARY}${FDISK_CMD_WRITE_CLOSE}" \
150 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
151 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
152 print_layout
153 ts_finalize_subtest
154
155
156 ts_init_subtest "1nd-primary-delete"
157 ts_log "Delete primary partition"
158 echo -e "${FDISK_CMD_DELETE_2PRIMARY}${FDISK_CMD_WRITE_CLOSE}" \
159 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
160 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
161 print_layout
162 ts_finalize_subtest
163
164
165 ts_init_subtest "extended-delete"
166 ts_log "Delete extended partition"
167 echo -e "${FDISK_CMD_DELETE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \
168 | $TS_CMD_FDISK -c=dos -u=cylinders ${TEST_IMAGE_NAME} &> /dev/null
169 ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG
170 print_layout
171 ts_finalize_subtest
172
173
174 ts_init_subtest "first-sector-at-end"
175 ts_log "Create new DOS partition table (again)"
176 echo -e "${FDISK_CMD_INIT}${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
177 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
178 ts_log "Create 1st primary at the end of device"
179 echo -e "n\np\n1\n20000\n\n${FDISK_CMD_WRITE_CLOSE}" | \
180 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
181 print_layout
182
183 ts_log "Create 2nd primary at the begin of device"
184 echo -e "n\np\n2\n\n\n${FDISK_CMD_WRITE_CLOSE}" | \
185 $TS_CMD_FDISK ${TEST_IMAGE_NAME} >> $TS_OUTPUT
186 print_layout
187 ts_finalize_subtest
188
189
190 ts_finalize