summaryrefslogtreecommitdiffstats
path: root/tests/ts/fdisk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtests/ts/fdisk/align-512-4K78
-rwxr-xr-xtests/ts/fdisk/align-512-4K-6379
-rwxr-xr-xtests/ts/fdisk/align-512-4K-md100
-rwxr-xr-xtests/ts/fdisk/align-512-51272
-rwxr-xr-xtests/ts/fdisk/align-512-512-topology78
-rwxr-xr-xtests/ts/fdisk/bsd141
-rwxr-xr-xtests/ts/fdisk/gpt96
-rwxr-xr-xtests/ts/fdisk/gpt-resize63
-rwxr-xr-xtests/ts/fdisk/id52
-rwxr-xr-xtests/ts/fdisk/mbr-dos-mode134
-rwxr-xr-xtests/ts/fdisk/mbr-nondos-mode154
-rwxr-xr-xtests/ts/fdisk/mbr-sort79
-rwxr-xr-xtests/ts/fdisk/oddinput47
-rwxr-xr-xtests/ts/fdisk/sunlabel92
14 files changed, 1265 insertions, 0 deletions
diff --git a/tests/ts/fdisk/align-512-4K b/tests/ts/fdisk/align-512-4K
new file mode 100755
index 0000000..c312e34
--- /dev/null
+++ b/tests/ts/fdisk/align-512-4K
@@ -0,0 +1,78 @@
+#!/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.
+#
+
+
+#
+# Test alignment for 512/512 disk *with* topology -- aligned to optimal
+# I/O size (32KiB)
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="align 512/4K"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+ts_skip_nonroot
+
+# set global variable TS_DEVICE
+ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3
+DEVNAME=$(basename $TS_DEVICE)
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${TS_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+n
+p
+3
+
++10M
+n
+e
+
+
+n
+
++5M
+n
+
++5M
+n
+
+
+p
+w
+q
+EOF
+
+udevadm settle
+ts_log "Alignment offsets:"
+cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1
+
+ts_fdisk_clean $TS_DEVICE
+
+ts_finalize
diff --git a/tests/ts/fdisk/align-512-4K-63 b/tests/ts/fdisk/align-512-4K-63
new file mode 100755
index 0000000..b84780b
--- /dev/null
+++ b/tests/ts/fdisk/align-512-4K-63
@@ -0,0 +1,79 @@
+#!/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.
+#
+
+
+#
+# Test alignment for 512/512 disk *with* topology -- aligned to optimal
+# I/O size (32KiB)
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="align 512/4K +alignment_offset"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+ts_skip_nonroot
+
+# set global variable TS_DEVICE
+ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7
+DEVNAME=$(basename $TS_DEVICE)
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${TS_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+n
+p
+3
+
++10M
+n
+e
+
+
+n
+
++5M
+n
+
++5M
+n
+
+
+p
+w
+q
+EOF
+
+udevadm settle
+ts_log "Alignment offsets:"
+cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1
+
+
+ts_fdisk_clean $TS_DEVICE
+
+ts_finalize
diff --git a/tests/ts/fdisk/align-512-4K-md b/tests/ts/fdisk/align-512-4K-md
new file mode 100755
index 0000000..7f60a65
--- /dev/null
+++ b/tests/ts/fdisk/align-512-4K-md
@@ -0,0 +1,100 @@
+#!/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.
+#
+
+
+#
+# Test alignment for 512/512 disk *with* topology -- aligned to optimal
+# I/O size (32KiB)
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="align 512/4K +MD"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+ts_skip_nonroot
+ts_check_prog "mdadm"
+
+# set global variable TS_DEVICE
+ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3
+DEVNAME=$(basename $TS_DEVICE)
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${TS_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++20M
+n
+p
+2
+
+
+p
+w
+q
+EOF
+
+udevadm settle
+ts_log "Alignment offsets:"
+cat /sys/block/${DEVNAME}/${DEVNAME}{1,2}/alignment_offset >> $TS_OUTPUT 2>&1
+
+ts_lock "md"
+
+MD_DEVNAME=md8
+MD_DEVICE=/dev/${MD_DEVNAME}
+
+mdadm -q -S ${MD_DEVICE} &> /dev/null
+udevadm settle
+
+mdadm -q --create ${MD_DEVICE} --metadata=0.90 --chunk=64 \
+ --level=0 --raid-devices=2 ${TS_DEVICE}1 ${TS_DEVICE}2 >> $TS_OUTPUT 2>&1
+udevadm settle
+
+ts_log "Create partitions (MD)"
+$TS_CMD_FDISK ${MD_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+p
+w
+q
+EOF
+
+udevadm settle
+ts_log "Alignment offsets (MD):"
+cat /sys/block/${MD_DEVNAME}/${MD_DEVNAME}p{1,2}/alignment_offset >> $TS_OUTPUT 2>&1
+
+mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1
+
+udevadm settle
+ts_unlock "md"
+
+ts_fdisk_clean $TS_DEVICE
+ts_fdisk_clean $MD_DEVICE
+
+ts_finalize
diff --git a/tests/ts/fdisk/align-512-512 b/tests/ts/fdisk/align-512-512
new file mode 100755
index 0000000..19506ea
--- /dev/null
+++ b/tests/ts/fdisk/align-512-512
@@ -0,0 +1,72 @@
+#!/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.
+#
+
+#
+# Test default 1MiB (2048 sectors) alignment for 512/512 disk *without*
+# topology.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="align 512/512"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+ts_skip_nonroot
+ts_check_losetup
+
+ts_device_init 50
+DEVICE=$TS_LODEV
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+n
+p
+3
+
++10M
+n
+e
+
+
+n
+
++5M
+n
+
++5M
+n
+
+
+p
+q
+EOF
+
+ts_fdisk_clean $DEVICE
+
+ts_finalize
diff --git a/tests/ts/fdisk/align-512-512-topology b/tests/ts/fdisk/align-512-512-topology
new file mode 100755
index 0000000..802ea61
--- /dev/null
+++ b/tests/ts/fdisk/align-512-512-topology
@@ -0,0 +1,78 @@
+#!/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.
+#
+
+
+#
+# Test alignment for 512/512 disk *with* topology -- aligned to optimal
+# I/O size (32KiB)
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="align 512/512 +topology"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+ts_skip_nonroot
+
+# set global variable TS_DEVICE
+ts_scsi_debug_init dev_size_mb=50 sector_size=512
+DEVNAME=$(basename $TS_DEVICE)
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${TS_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+n
+p
+3
+
++10M
+n
+e
+
+
+n
+
++5M
+n
+
++5M
+n
+
+
+p
+w
+q
+EOF
+
+udevadm settle
+ts_log "Alignment offsets:"
+cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1
+
+ts_fdisk_clean $TS_DEVICE
+
+ts_finalize
diff --git a/tests/ts/fdisk/bsd b/tests/ts/fdisk/bsd
new file mode 100755
index 0000000..953b087
--- /dev/null
+++ b/tests/ts/fdisk/bsd
@@ -0,0 +1,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 -l ${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>&1
+
+ts_log "Create new DOS partition table"
+echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_SETID}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+$TS_CMD_HEXDUMP -C ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>&1
+
+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>&1
+
+print_layout
+
+ts_log "Create 2st 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>&1
+
+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>&1
+
+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>&1
+
+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>&1
+
+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>&1
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+ts_finalize
diff --git a/tests/ts/fdisk/gpt b/tests/ts/fdisk/gpt
new file mode 100755
index 0000000..62dce6d
--- /dev/null
+++ b/tests/ts/fdisk/gpt
@@ -0,0 +1,96 @@
+#!/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="GPT"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+FDISK_CMD_CREATE_GPTLABEL="g\n" # create GPT label
+FDISK_CMD_WRITE_CLOSE="w\nq\n" # write to image
+
+FDISK_CMD_CHANGE_TYPE_BY_NUM="t\n1\n1\n" # set 1st partition to EFI System
+ # set 5th partition to Linux swap
+FDISK_CMD_CHANGE_TYPE_BY_UUID="t\n5\n0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n"
+
+FDISK_CMD_DELETE_PART="d\n2\n" # delete 2nd partition
+FDISK_CMD_CREATE_PART="n\n2\n\n\n" # create 2nd partition
+
+function print_layout {
+ echo -ne "\n---layout----------\n" >> $TS_OUTPUT
+ $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>&1
+ echo -ne "-------------------\n\n" >> $TS_OUTPUT
+}
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 10)
+
+ts_log "Create new GPT partition table"
+echo -e "${FDISK_CMD_CREATE_GPTLABEL}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Create partitions"
+for i in {1..8}; do
+ echo -e "n\n${i}\n\n+1M\n${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+done
+
+ts_log "Change partition type by number"
+echo -e "${FDISK_CMD_CHANGE_TYPE_BY_NUM}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Change partition type by UUID"
+echo -e "${FDISK_CMD_CHANGE_TYPE_BY_UUID}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Delete partition"
+echo -e "${FDISK_CMD_DELETE_PART}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Create again partition"
+echo -e "${FDISK_CMD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Corrupt primary table"
+dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 seek=1 conv=notrunc &> /dev/null
+echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Corrupt backup table"
+dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 \
+ seek=$(( 1024 * 1024 * 10 / 512 - 1)) conv=notrunc &> /dev/null
+echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+ts_finalize
diff --git a/tests/ts/fdisk/gpt-resize b/tests/ts/fdisk/gpt-resize
new file mode 100755
index 0000000..b831981
--- /dev/null
+++ b/tests/ts/fdisk/gpt-resize
@@ -0,0 +1,63 @@
+#!/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.
+#
+
+#
+# Test GPT Alternative-LBA and backup header update after device resize.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="gpt-resize"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_skip_nonroot
+
+ts_check_test_command "$TS_CMD_FDISK"
+ts_check_test_command "$TS_CMD_SFDISK"
+ts_check_prog "dd"
+
+ts_check_losetup
+
+ts_device_init 10
+DEVICE=$TS_LODEV
+
+# create GPT with one partition
+echo ",," | $TS_CMD_SFDISK --no-reread --no-tell-kernel --label gpt $DEVICE >> $TS_OUTPUT 2>&1
+udevadm settle
+
+# enlarge the image
+IMAGE=$($TS_CMD_LOSETUP --output BACK-FILE --noheadings $DEVICE)
+dd if=/dev/zero of=${IMAGE} bs=1MiB count=10 conv=notrunc oflag=append &> /dev/null
+udevadm settle
+
+# update device size
+$TS_CMD_LOSETUP --set-capacity $DEVICE
+udevadm settle
+
+echo -e "\n\n----- fixing after resize: -----\n\n" >> $TS_OUTPUT
+
+# create another GPT partition on new free space (all default)
+echo -e 'n\n\n\n\nw\n' | $TS_CMD_FDISK $DEVICE >> $TS_OUTPUT 2>&1
+udevadm settle
+
+
+echo -e "\n\n----- list result: -----\n\n" >> $TS_OUTPUT
+
+$TS_CMD_FDISK --list $DEVICE 2>&1 >> $TS_OUTPUT
+
+ts_fdisk_clean $DEVICE
+ts_finalize
diff --git a/tests/ts/fdisk/id b/tests/ts/fdisk/id
new file mode 100755
index 0000000..85b87d6
--- /dev/null
+++ b/tests/ts/fdisk/id
@@ -0,0 +1,52 @@
+#!/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 - id"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+FDISK_CMD_ID1="x\ni\n0x1\nr\nw\n"
+FDISK_CMD_ID2="x\ni\n0x2\nr\nw\n"
+
+# Sparc uses SUN disk labels by default and thus has a different output
+ARCH=$(uname -m)
+case $ARCH in
+ *sparc* )
+ ARCH_EXT=".sparc"
+ ;;
+ *)
+ ARCH_EXT=""
+ ;;
+esac
+
+TS_EXPECTED+="${ARCH_EXT}"
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 10)
+
+ts_log "Create MBR with ID=0x1"
+echo -e "${FDISK_CMD_ID1}" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+$TS_CMD_FDISK -l ${TEST_IMAGE_NAME} | grep identifier >> $TS_OUTPUT
+
+ts_log "Create MBR with ID=0x2"
+echo -e "${FDISK_CMD_ID2}" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+$TS_CMD_FDISK -l ${TEST_IMAGE_NAME} | grep identifier >> $TS_OUTPUT
+
+ts_finalize
diff --git a/tests/ts/fdisk/mbr-dos-mode b/tests/ts/fdisk/mbr-dos-mode
new file mode 100755
index 0000000..219df2f
--- /dev/null
+++ b/tests/ts/fdisk/mbr-dos-mode
@@ -0,0 +1,134 @@
+#!/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 - dos mode"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+ts_check_test_command "$TS_HELPER_MD5"
+
+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_PRIMARY="n\np\n1\n\n+1M\n" # create primary partition 1 of size 1MB
+FDISK_CMD_CHANGE_PARTTYPE="t\nbf\n" # change partition type to "bf - solaris", this requires that there is only one partition to change
+FDISK_CMD_SET_ACTIVE="a\n1\n" # set first partition active
+FDISK_CMD_CREATE_EXTENDED="n\ne\n2\n\n+10\n" # create extended partition 2 of size 11 cylinders
+FDISK_CMD_CREATE_LOGICAL="n\nl\n\n+1\n" # create next logical partition of size 2 cyl
+FDISK_CMD_DELETE_LOGICALS="d\n6\nd\n5\nd\n6\n" # delete middle, head, tail, last partitions
+FDISK_CMD_DELETE_PRIMARY="d\n1\n" # delete first primary
+FDISK_CMD_DELETE_EXTENDED="d\n2\n" # delete second primary
+
+FDISK_OPTIONS="-C 1024 -c=dos -u=cylinders"
+
+function print_layout {
+ echo -ne "\n---layout----------\n" >> $TS_OUTPUT
+ $TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+ echo -ne "-------------------\n\n" >> $TS_OUTPUT
+}
+
+#
+# Note that fdisk will enlarge the disk image (to 57MB) because the logical
+# partitions are out of the original range (10MB).
+#
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 10)
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+ts_log "Create new DOS partition table"
+echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Create primary partition"
+echo -e "${FDISK_CMD_CREATE_PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Set partition type"
+echo -e "${FDISK_CMD_CHANGE_PARTTYPE}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Set primary partition active"
+echo -e "${FDISK_CMD_SET_ACTIVE}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Re-create primary partition"
+echo -e "d\n${FDISK_CMD_CREATE_PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Create extended partition"
+echo -e "${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+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 ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Delete logical partitions"
+echo -e "${FDISK_CMD_DELETE_LOGICALS}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Create another logical partition"
+echo -e "${FDISK_CMD_CREATE_LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Delete primary partition"
+echo -e "${FDISK_CMD_DELETE_PRIMARY}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_log "Delete extended partition"
+echo -e "${FDISK_CMD_DELETE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+ts_finalize
diff --git a/tests/ts/fdisk/mbr-nondos-mode b/tests/ts/fdisk/mbr-nondos-mode
new file mode 100755
index 0000000..7ac5dae
--- /dev/null
+++ b/tests/ts/fdisk/mbr-nondos-mode
@@ -0,0 +1,154 @@
+#!/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
+
+# Sparc uses SUN disk labels by default and thus has a different output
+ARCH=$(uname -m)
+case $ARCH in
+ *sparc* )
+ ARCH_EXT=".sparc"
+ ;;
+ *)
+ ARCH_EXT=""
+ ;;
+esac
+
+TS_EXPECTED+="${ARCH_EXT}"
+
+function print_layout {
+ echo -ne "\n---layout----------\n" >> $TS_OUTPUT
+ $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+ echo -ne "-------------------\n\n" >> $TS_OUTPUT
+}
+
+#set -x
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+# 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_INIT}${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+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>&1
+
+print_layout
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+
+ts_finalize
diff --git a/tests/ts/fdisk/mbr-sort b/tests/ts/fdisk/mbr-sort
new file mode 100755
index 0000000..2cdb115
--- /dev/null
+++ b/tests/ts/fdisk/mbr-sort
@@ -0,0 +1,79 @@
+#!/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 - sort"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+
+# cmd to changes system id to 0x1
+FDISK_CMD_WRITE_CLOSE="w\nq\n"
+FDISK_CMD_CREATE_DOSLABEL="o\n" #create dos label
+
+FDISK_CMD_CREATE_1PRIMARY="n\np\n1\n4096\n6143\n"
+FDISK_CMD_CREATE_2PRIMARY="n\np\n2\n2048\n4095\n"
+FDISK_CMD_CREATE_3PRIMARY="n\np\n3\n6144\n8191\n"
+FDISK_CMD_CREATE_EXTENDED="n\ne\n\n\n"
+
+FDISK_CMD_CREATE_1LOGICAL="n\n14336\n16383\n"
+FDISK_CMD_CREATE_2LOGICAL="n\n22528\n24575\n"
+FDISK_CMD_CREATE_3LOGICAL="n\n18432\n20479\n"
+FDISK_CMD_CREATE_4LOGICAL="n\n10240\n12287\n"
+
+FDISK_CMD_EXPERT_SORT="x\nf\nr\n"
+
+function print_layout {
+ echo -ne "\n---layout----------\n" >> $TS_OUTPUT
+ $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+ echo -ne "-------------------\n\n" >> $TS_OUTPUT
+}
+
+#set -x
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB
+
+ts_log "Create new DOS partition table"
+echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_log "Create primary partitions"
+echo -e "${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_CREATE_2PRIMARY}${FDISK_CMD_CREATE_3PRIMARY}${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+
+ts_log "Create logical partitions"
+echo -e "${FDISK_CMD_CREATE_1LOGICAL}${FDISK_CMD_CREATE_2LOGICAL}${FDISK_CMD_CREATE_3LOGICAL}${FDISK_CMD_CREATE_4LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+
+ts_log "Fix order."
+echo -e "${FDISK_CMD_EXPERT_SORT}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
+
+print_layout
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+ts_finalize
diff --git a/tests/ts/fdisk/oddinput b/tests/ts/fdisk/oddinput
new file mode 100755
index 0000000..0679242
--- /dev/null
+++ b/tests/ts/fdisk/oddinput
@@ -0,0 +1,47 @@
+#!/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="invalid input tests"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+ts_check_test_command "$TS_HELPER_MD5"
+
+#set -x
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 10)
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+#
+# Note that since 2.23 the DOS-mode has effect only if there is a MBR on the device.
+#
+
+ts_log "Empty image listing" # this should report empty partition table
+# TEST_IMAGE_NAME has absolute path, and is by definition different on each computer, we need to sed it away
+$TS_CMD_FDISK -c=dos -u=cylinders -l ${TEST_IMAGE_NAME} 2>&1 | sed -e "s/${TEST_IMAGE_NAME//\//\\/}/testimage/" >> $TS_OUTPUT
+
+ts_log "Nonexistent file" # this originally does absolutely nothing
+$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ >> $TS_OUTPUT 2>&1
+
+ts_log "Too small file" # same here
+echo "This file is too small" >> oddinput.toosmall
+$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall >> $TS_OUTPUT 2>&1
+rm oddinput.toosmall
+ts_finalize
diff --git a/tests/ts/fdisk/sunlabel b/tests/ts/fdisk/sunlabel
new file mode 100755
index 0000000..d6b1033
--- /dev/null
+++ b/tests/ts/fdisk/sunlabel
@@ -0,0 +1,92 @@
+#!/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="sunlabel tests"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_FDISK"
+ts_check_test_command "$TS_HELPER_MD5"
+
+FDISK_CMD_INIT="s\n" # create new sunlabel
+FDISK_CMD_WRITE_CLOSE="w\nq\n"
+FDISK_CMD_DELETEALL="d\n1\nd\n2\nd\n3\nd\n4\nd\n5\nd\n6\nd\n7\nd\n8\n" # delete all partitions
+
+FDISK_CMD_CREATE_PRIMARY="n\n\n\n128\n" # create first partition
+FDISK_CMD_TOGGLE_READONLY="a\n1\n" # sets first partition as read-only
+FDISK_CMD_TOGGLE_MOUNTABLE="c\n1\n" # sets first partition as mountable
+FDISK_CMD_CHANGE_SYSID="t\n4\n" # changes sysid to 4 (SunOS usr)
+FDISK_CMD_CREATE_SECONDARY="n\n2\n128\n\n" # create secondary partition to the end of disk
+
+FDISK_OPTIONS="-H 1 -S 63 -u=cylinders"
+
+#set -x
+
+ts_log "Initialize empty image"
+TEST_IMAGE_NAME=$(ts_image_init 10)
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+ts_log "Create new SUN partition table"
+echo -e "${FDISK_CMD_INIT}${FDISK_CMD_DELETEALL}${FDISK_CMD_WRITE_CLOSE}" \
+ | $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Create first partition"
+echo -e "${FDISK_CMD_CREATE_PRIMARY}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Set partition sysid"
+echo -e "${FDISK_CMD_CHANGE_SYSID}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Set first partition readonly"
+echo -e "${FDISK_CMD_TOGGLE_READONLY}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Set first partition mountable"
+echo -e "${FDISK_CMD_TOGGLE_MOUNTABLE}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Create second partition"
+echo -e "${FDISK_CMD_CREATE_SECONDARY}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>&1
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+$TS_CMD_FDISK ${FDISK_OPTIONS} -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT
+
+ts_log "Delete all partitions"
+echo -e "${FDISK_CMD_DELETEALL}${FDISK_CMD_WRITE_CLOSE}" | \
+ $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null
+ts_image_md5sum >> $TS_OUTPUT 2>&1
+
+ts_fdisk_clean ${TEST_IMAGE_NAME}
+ts_finalize