From 378c18e5f024ac5a8aef4cb40d7c9aa9633d144c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 16:30:35 +0200 Subject: Adding upstream version 2.38.1. Signed-off-by: Daniel Baumann --- tests/ts/fdisk/align-512-4K | 79 ++++++++++++++ tests/ts/fdisk/align-512-4K-63 | 80 ++++++++++++++ tests/ts/fdisk/align-512-4K-md | 104 +++++++++++++++++++ tests/ts/fdisk/align-512-512 | 73 +++++++++++++ tests/ts/fdisk/align-512-512-topology | 79 ++++++++++++++ tests/ts/fdisk/bsd | 141 +++++++++++++++++++++++++ tests/ts/fdisk/gpt | 107 +++++++++++++++++++ tests/ts/fdisk/gpt-resize | 63 +++++++++++ tests/ts/fdisk/id | 56 ++++++++++ tests/ts/fdisk/mbr-dos-mode | 145 ++++++++++++++++++++++++++ tests/ts/fdisk/mbr-nondos-mode | 190 ++++++++++++++++++++++++++++++++++ tests/ts/fdisk/mbr-sort | 83 +++++++++++++++ tests/ts/fdisk/oddinput | 53 ++++++++++ tests/ts/fdisk/sunlabel | 104 +++++++++++++++++++ 14 files changed, 1357 insertions(+) create mode 100755 tests/ts/fdisk/align-512-4K create mode 100755 tests/ts/fdisk/align-512-4K-63 create mode 100755 tests/ts/fdisk/align-512-4K-md create mode 100755 tests/ts/fdisk/align-512-512 create mode 100755 tests/ts/fdisk/align-512-512-topology create mode 100755 tests/ts/fdisk/bsd create mode 100755 tests/ts/fdisk/gpt create mode 100755 tests/ts/fdisk/gpt-resize create mode 100755 tests/ts/fdisk/id create mode 100755 tests/ts/fdisk/mbr-dos-mode create mode 100755 tests/ts/fdisk/mbr-nondos-mode create mode 100755 tests/ts/fdisk/mbr-sort create mode 100755 tests/ts/fdisk/oddinput create mode 100755 tests/ts/fdisk/sunlabel (limited to 'tests/ts/fdisk') diff --git a/tests/ts/fdisk/align-512-4K b/tests/ts/fdisk/align-512-4K new file mode 100755 index 0000000..88e99cb --- /dev/null +++ b/tests/ts/fdisk/align-512-4K @@ -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" + +. $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 --noauto-pt ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG + +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..325a5d4 --- /dev/null +++ b/tests/ts/fdisk/align-512-4K-63 @@ -0,0 +1,80 @@ +#!/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 --noauto-pt ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG + + +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..0f40405 --- /dev/null +++ b/tests/ts/fdisk/align-512-4K-md @@ -0,0 +1,104 @@ +#!/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" + +# rhbz#182625: It can't create new raid0 with metadata 0.90 from mdadm-4.1 +TS_KNOWN_FAIL="yes" + +# 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 --noauto-pt ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG + +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>> $TS_ERRLOG +udevadm settle + +ts_log "Create partitions (MD)" +$TS_CMD_FDISK ${MD_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG + +mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG + +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..cda1321 --- /dev/null +++ b/tests/ts/fdisk/align-512-512 @@ -0,0 +1,73 @@ +#!/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 --noauto-pt ${DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG <> $TS_OUTPUT 2>> $TS_ERRLOG + +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..9ce2723 --- /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 +# +# 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 diff --git a/tests/ts/fdisk/gpt b/tests/ts/fdisk/gpt new file mode 100755 index 0000000..18e4fab --- /dev/null +++ b/tests/ts/fdisk/gpt @@ -0,0 +1,107 @@ +#!/bin/bash +# +# This file is part of util-linux. +# +# Copyright (C) 2013 Karel Zak +# +# 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>> $TS_ERRLOG + echo -ne "-------------------\n\n" >> $TS_OUTPUT + + ts_fdisk_clean ${TEST_IMAGE_NAME} +} + + +ts_init_subtest "empty-pt" +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 --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null + +print_layout +ts_finalize_subtest + +ts_init_subtest "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_finalize_subtest + +ts_init_subtest "change-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_finalize_subtest + +ts_init_subtest "change-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_finalize_subtest + +ts_init_subtest "delete-partition" +echo -e "${FDISK_CMD_DELETE_PART}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout +ts_finalize_subtest + +ts_init_subtest "create-again-partition" +echo -e "${FDISK_CMD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout +ts_finalize_subtest + +ts_init_subtest "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_finalize_subtest + +ts_init_subtest "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_finalize_subtest + +ts_finalize diff --git a/tests/ts/fdisk/gpt-resize b/tests/ts/fdisk/gpt-resize new file mode 100755 index 0000000..a5d248a --- /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>> $TS_ERRLOG +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 + +ts_log_both "----- fixing after resize: -----" + +# 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>> $TS_ERRLOG +udevadm settle + + +ts_log "----- list result: -----" + +$TS_CMD_FDISK --list $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG + +ts_fdisk_clean $DEVICE +ts_finalize diff --git a/tests/ts/fdisk/id b/tests/ts/fdisk/id new file mode 100755 index 0000000..c52e44b --- /dev/null +++ b/tests/ts/fdisk/id @@ -0,0 +1,56 @@ +#!/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_init_subtest "create-mbr-with-id-0x1" +TS_EXPECTED+="${ARCH_EXT}" +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_finalize_subtest + +ts_init_subtest "create-mbr-with-id-0x2" +TS_EXPECTED+="${ARCH_EXT}" +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_subtest + +ts_finalize diff --git a/tests/ts/fdisk/mbr-dos-mode b/tests/ts/fdisk/mbr-dos-mode new file mode 100755 index 0000000..cc27429 --- /dev/null +++ b/tests/ts/fdisk/mbr-dos-mode @@ -0,0 +1,145 @@ +#!/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} -x ${TEST_IMAGE_NAME} >> $TS_OUTPUT + echo -ne "-------------------\n\n" >> $TS_OUTPUT + + ts_fdisk_clean ${TEST_IMAGE_NAME} +} + +# +# Note that fdisk will enlarge the disk image (to 57MB) because the logical +# partitions are out of the original range (10MB). +# +ts_init_subtest "empty-pt" +TEST_IMAGE_NAME=$(ts_image_init 10) +ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG + +echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_INIT}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK --noauto-pt ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null +ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "set-primary-par-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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "re-create-primary-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "create-extended-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "create-logical-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "delete-logical-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "create-another-log-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "delete-primary-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "delete-extended-par" +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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_finalize diff --git a/tests/ts/fdisk/mbr-nondos-mode b/tests/ts/fdisk/mbr-nondos-mode new file mode 100755 index 0000000..d366f28 --- /dev/null +++ b/tests/ts/fdisk/mbr-nondos-mode @@ -0,0 +1,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 diff --git a/tests/ts/fdisk/mbr-sort b/tests/ts/fdisk/mbr-sort new file mode 100755 index 0000000..6a6d3b8 --- /dev/null +++ b/tests/ts/fdisk/mbr-sort @@ -0,0 +1,83 @@ +#!/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 -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" +TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB + +echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null + +print_layout +ts_finalize_subtest + +ts_init_subtest "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_finalize_subtest + + +ts_init_subtest "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_finalize_subtest + + +ts_init_subtest "fix-order" +echo -e "${FDISK_CMD_EXPERT_SORT}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout +ts_finalize_subtest + +ts_finalize diff --git a/tests/ts/fdisk/oddinput b/tests/ts/fdisk/oddinput new file mode 100755 index 0000000..8c23abb --- /dev/null +++ b/tests/ts/fdisk/oddinput @@ -0,0 +1,53 @@ +#!/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>> $TS_ERRLOG + +# +# 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 -x ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG +sed -i -e "s/${TEST_IMAGE_NAME//\//\\/}/testimage/" $TS_OUTPUT $TS_ERRLOG + +# +# Errors +# +ts_logerr "---Nonexistent file" +$TS_CMD_FDISK -c=dos -u=cylinders -x _a_file_that_does_not_exist_ >> $TS_OUTPUT 2>> $TS_ERRLOG +sed -i -e "s@$($TS_HELPER_STRERROR ENOENT)@ENOENT@" $TS_OUTPUT $TS_ERRLOG + +ts_logerr "---Too small file" +echo "This file is too small" >> oddinput.toosmall +$TS_CMD_FDISK -c=dos -u=cylinders -x oddinput.toosmall >> $TS_OUTPUT 2>> $TS_ERRLOG +sed -i -e "s@$($TS_HELPER_STRERROR EINVAL)@EINVAL@" $TS_OUTPUT $TS_ERRLOG +rm oddinput.toosmall +ts_finalize diff --git a/tests/ts/fdisk/sunlabel b/tests/ts/fdisk/sunlabel new file mode 100755 index 0000000..4c0d375 --- /dev/null +++ b/tests/ts/fdisk/sunlabel @@ -0,0 +1,104 @@ +#!/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" + +function print_layout { + $TS_CMD_FDISK ${FDISK_OPTIONS} -x ${TEST_IMAGE_NAME} >> $TS_OUTPUT + ts_fdisk_clean ${TEST_IMAGE_NAME} +} + +#set -x + +ts_init_subtest "empty-sun-pt" +TEST_IMAGE_NAME=$(ts_image_init 10) +ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG + +echo -e "${FDISK_CMD_INIT}${FDISK_CMD_DELETEALL}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK --noauto-pt ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} &> /dev/null +ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + + +ts_init_subtest "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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "set-first-par-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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "set-first-par-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>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "create-second-partition" +echo -e "${FDISK_CMD_CREATE_SECONDARY}${FDISK_CMD_WRITE_CLOSE}" | \ + $TS_CMD_FDISK ${FDISK_OPTIONS} ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_image_md5sum >> $TS_OUTPUT 2>> $TS_ERRLOG + +print_layout +ts_finalize_subtest + +ts_init_subtest "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>> $TS_ERRLOG +ts_finalize_subtest + + +ts_finalize -- cgit v1.2.3