tests: add blkid --offset test

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2022-12-01 15:08:19 +01:00
parent 22147e08c9
commit db0f70fd47
2 changed files with 99 additions and 0 deletions

View file

@ -0,0 +1,41 @@
Checking that no-one is using this disk right now ... OK
Disk <removed>: 50 MiB, 52428800 bytes, 102400 sectors
Disk model: scsi_debug
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / <removed> bytes
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new disklabel.
<removed>1: Created a new partition <removed>.
<removed>2: Created a new partition <removed>.
<removed>3: Created a new partition <removed>.
<removed>4: Created a new partition <removed>.
<removed>5: Done.
New situation:
Disklabel type: gpt
Disk identifier: <removed>
Device Start End Sectors Size Type
<removed>1 2048 12287 10240 5M Linux filesystem
<removed>2 12288 22527 10240 5M Linux filesystem
<removed>3 22528 32767 10240 5M Linux filesystem
<removed>4 32768 100351 67584 33M Linux filesystem
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
ID_FS_LABEL=FOO
ID_FS_LABEL_ENC=FOO
ID_FS_UUID=ccf3dc28-f697-4577-971b-0bc79300a700
ID_FS_UUID_ENC=ccf3dc28-f697-4577-971b-0bc79300a700
ID_FS_VERSION=1.0
ID_FS_FSBLOCKSIZE=1024
ID_FS_BLOCK_SIZE=1024
ID_FS_FSLASTBLOCK=5120
ID_FS_FSSIZE=5242880
ID_FS_TYPE=ext2
ID_FS_USAGE=filesystem

58
tests/ts/blkid/offset Executable file
View file

@ -0,0 +1,58 @@
#!/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="offset"
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_SFDISK"
ts_check_test_command "$TS_CMD_BLKID"
ts_check_test_command "$TS_CMD_PARTX"
ts_check_prog "mkfs.ext2"
ts_skip_nonroot
# set global variable TS_DEVICE
ts_scsi_debug_init dev_size_mb=50 sector_size=512
$TS_CMD_SFDISK ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <<EOF
label: gpt
label-id: b181c399-4711-4c52-8b65-9e764541218d
,5M,L
,5M,L
,5M,L
, ,
EOF
ts_fdisk_clean $TS_DEVICE
udevadm settle
mkfs.ext2 -L FOO -U ccf3dc28-f697-4577-971b-0bc79300a700 ${TS_DEVICE}2 &> /dev/null
udevadm settle
ts_device_has "TYPE" "ext2" ${TS_DEVICE}2 ||
ts_die "Cannot find ext2 on ${TS_DEVICE}2"
DEVNAME=$(basename $TS_DEVICE)
offset=$(( $(cat /sys/block/${DEVNAME}/${DEVNAME}2/start) * 512))
size=$(( $(cat /sys/block/${DEVNAME}/${DEVNAME}2/size) * 512))
$TS_CMD_PARTX --delete ${TS_DEVICE} &> /dev/null
$TS_CMD_BLKID -p -o udev --offset=${offset} --size=${size} $TS_DEVICE \
>> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize