Debian Codegraph @

tests/ts/fdisk/mbr-sort

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 - sort"
19
20 . "$TS_TOPDIR"/functions.sh
21 ts_init "$*"
22
23 ts_check_test_command "$TS_CMD_FDISK"
24
25 # cmd to changes system id to 0x1
26 FDISK_CMD_WRITE_CLOSE="w\nq\n"
27 FDISK_CMD_CREATE_DOSLABEL="o\n" #create dos label
28
29 FDISK_CMD_CREATE_1PRIMARY="n\np\n1\n4096\n6143\n"
30 FDISK_CMD_CREATE_2PRIMARY="n\np\n2\n2048\n4095\n"
31 FDISK_CMD_CREATE_3PRIMARY="n\np\n3\n6144\n8191\n"
32 FDISK_CMD_CREATE_EXTENDED="n\ne\n\n\n"
33
34 FDISK_CMD_CREATE_1LOGICAL="n\n14336\n16383\n"
35 FDISK_CMD_CREATE_2LOGICAL="n\n22528\n24575\n"
36 FDISK_CMD_CREATE_3LOGICAL="n\n18432\n20479\n"
37 FDISK_CMD_CREATE_4LOGICAL="n\n10240\n12287\n"
38
39 FDISK_CMD_EXPERT_SORT="x\nf\nr\n"
40
41 function print_layout {
42 echo -ne "\n---layout----------\n" >> $TS_OUTPUT
43 $TS_CMD_FDISK --list-details ${TEST_IMAGE_NAME} >> $TS_OUTPUT
44 echo -ne "-------------------\n\n" >> $TS_OUTPUT
45
46 ts_fdisk_clean ${TEST_IMAGE_NAME}
47 }
48
49 #set -x
50
51 ts_init_subtest "empty-pt"
52 TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB
53
54 echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_WRITE_CLOSE}" \
55 | $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null
56
57 print_layout
58 ts_finalize_subtest
59
60 ts_init_subtest "create-primary-partitions"
61 echo -e "${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_CREATE_2PRIMARY}${FDISK_CMD_CREATE_3PRIMARY}${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \
62 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
63
64 print_layout
65 ts_finalize_subtest
66
67
68 ts_init_subtest "create-logical-partitions"
69 echo -e "${FDISK_CMD_CREATE_1LOGICAL}${FDISK_CMD_CREATE_2LOGICAL}${FDISK_CMD_CREATE_3LOGICAL}${FDISK_CMD_CREATE_4LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
70 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
71
72 print_layout
73 ts_finalize_subtest
74
75
76 ts_init_subtest "fix-order"
77 echo -e "${FDISK_CMD_EXPERT_SORT}${FDISK_CMD_WRITE_CLOSE}" \
78 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
79
80 print_layout
81 ts_finalize_subtest
82
83 ts_finalize