blob: 8477f929e9ca7695132c5ae66493dd908f81b9e6 (
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
|
#!/bin/bash
#
# This file is part of util-linux.
#
# Copyright (C) 2013 Karel Zak <kzak@redhat.com>
#
# 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="nested BSD"
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_FDISK"
ts_check_test_command "$TS_CMD_HEXDUMP"
ts_check_test_command "$TS_HELPER_SYSINFO"
FDISK_CMD_CREATE_DOSLABEL="o\n" # create dos label
FDISK_CMD_SETID="x\ni\n0x1\nr\n" # set non-random ID
FDISK_CMD_WRITE_CLOSE="w\nq\n" # write to image
FDISK_CMD_CREATE_PRIMARY1="n\np\n1\n\n+1M\n" # 1st primary partition of size 1MiB
FDISK_CMD_CREATE_PRIMARY2="n\np\n2\n\n\n" # 2nd primary partition for whole of the disk
FDISK_CMD_CHANGE_PART2TYPE="t\n2\na5\n" # change partition type FreeBSD
FDISK_CMD_BSD_CREATE="b\ny\n" # create nested BSD PT
FDISK_CMD_BSD_LIST="b\np\nr\nq\n" # list nested BSD PT and quit
FDISK_CMD_BSD_CREATE_PART="b\nn\na\n\n+1M\n" # add BSD partition 'a', size 1MiB
FDISK_CMD_BSD_PARTTYPE="b\nt\na\n7\n" # set partition 'a' to type 4.2BSD
FDISK_CMD_BSD_LIST_TYPES="b\nl\nq\n" # list supported PT types and quit
#set -x
# BSD disklabel depends on endianness
BYTE_ORDER=$($TS_HELPER_SYSINFO byte-order)
# and also on arch-specific offset (see include/pt-bsd.h)
ARCH=$(uname -m)
case $ARCH in
# see include/pt-bsd.h
*alpha* | *ppc* | *ia64* | *hppa* | *parisc* )
BSD_LABELSECTOR=0
BSD_LABELOFFSET=64
;;
*)
BSD_LABELSECTOR=1
BSD_LABELOFFSET=0
;;
esac
# and contains extra options for alpha
BSD_EXTRA=""
case $ARCH in
*alpha*)
BSD_EXTRA="_alpha"
;;
esac
echo "BSD_LABELSECTOR=$BSD_LABELSECTOR" >> $TS_OUTPUT
echo "BSD_LABELOFFSET=$BSD_LABELOFFSET" >> $TS_OUTPUT
echo "BSD_EXTRA=$BSD_EXTRA" >> $TS_OUTPUT
echo "BYTE_ORDER=$BYTE_ORDER" >> $TS_OUTPUT
echo >> $TS_OUTPUT
TS_EXPECTED+="_${BSD_LABELSECTOR}_${BSD_LABELOFFSET}${BSD_EXTRA}.${BYTE_ORDER}"
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
}
function print_bsd_layout {
echo -ne "\n---layout----------\n" >> $TS_OUTPUT
echo -e "${FDISK_CMD_BSD_LIST}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} >> $TS_OUTPUT
echo -ne "-------------------\n\n" >> $TS_OUTPUT
}
ts_log "Initialize empty image"
TEST_IMAGE_NAME=$(ts_image_init 10)
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_log "Create new DOS partition table"
echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_SETID}${FDISK_CMD_WRITE_CLOSE}" \
| $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_log "Create 1st primary partition"
echo -e "${FDISK_CMD_CREATE_PRIMARY1}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_log "Create 2nd primary partition"
echo -e "${FDISK_CMD_CREATE_PRIMARY2}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_log "Set 2nd partition type"
echo -e "${FDISK_CMD_CHANGE_PART2TYPE}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
print_layout
ts_log "Create default BSD"
echo -e "${FDISK_CMD_BSD_CREATE}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
print_bsd_layout
echo -e "${FDISK_CMD_BSD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
echo -e "${FDISK_CMD_BSD_PARTTYPE}${FDISK_CMD_WRITE_CLOSE}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG
print_bsd_layout
echo -e "${FDISK_CMD_BSD_LIST_TYPES}" | \
$TS_CMD_FDISK ${TEST_IMAGE_NAME} | \
sed 's/Reading .*//g; s/Welcome to fdisk .*//' >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_fdisk_clean ${TEST_IMAGE_NAME}
ts_finalize
|