From d90c05ca77f4ddea252cbb0b899098b97747ed81 Mon Sep 17 00:00:00 2001 From: Imbus Date: Sat, 21 Feb 2026 08:05:09 +0100 Subject: [PATCH 1/2] Tests: test.sh does not use sudo internally, now runs under alpine with musl --- test.sh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/test.sh b/test.sh index 70cfae9..1eb6280 100644 --- a/test.sh +++ b/test.sh @@ -4,13 +4,17 @@ set -e # set -x # For debugging # If you ever mess this up: -# $ sudo mknod /dev/loop-control c 10 237 -# $ sudo chmod 600 /dev/loop-control -# $ sudo chown root:root /dev/loop-control +# $ mknod /dev/loop-control c 10 237 +# $ chmod 600 /dev/loop-control +# $ chown root:root /dev/loop-control # # For cleanup: -# $ sudo find /dev -maxdepth 1 -type b -name 'loop[0-9]*' -exec rm -f {} \; +# $ find /dev -maxdepth 1 -type b -name 'loop[0-9]*' -exec rm -f {} \; +if [ "$(id -u)" -ne 0 ]; then + echo "Run as root. We need permissions to write and setup a loop device." + exit 1 +fi DISKFILE="/tmp/disk.img" BINFILE="/tmp/file.bin" @@ -22,9 +26,9 @@ echo "Using device: ${LOOPDEV}" cleanup() { echo "Cleaning up..." set +e -x - sudo losetup -d ${LOOPDEV} - sudo rm ${LOOPDEV} - sudo rm ${BINFILE} ${DISKFILE} + losetup -d ${LOOPDEV} + rm ${LOOPDEV} + rm ${BINFILE} ${DISKFILE} } trap cleanup EXIT INT TERM @@ -36,28 +40,31 @@ if losetup ${LOOPDEV} >/dev/null 2>&1; then fi if [ ! -f ${DISKFILE} ]; then + echo "Creating ${DISKFILE}" dd if=/dev/zero of=${DISKFILE} bs=1M count=256 fi if [ ! -f ${BINFILE} ]; then + echo "Creating ${BINFILE}" dd if=/dev/urandom of=${BINFILE} bs=1M count=64 fi if [ ! -e ${LOOPDEV} ]; then - sudo losetup ${LOOPDEV} ${DISKFILE} + mknod ${LOOPDEV} b 7 ${LOOPNUM} # busybox needs this + losetup ${LOOPDEV} ${DISKFILE} fi -sudo ./writeimg -nd ${LOOPDEV} ${BINFILE} -sudo ./writeimg -vnd ${LOOPDEV} ${BINFILE} +./writeimg -nd ${LOOPDEV} ${BINFILE} +./writeimg -vnd ${LOOPDEV} ${BINFILE} -sudo ./writeimg -nd ${LOOPDEV} ./writeimg -sudo ./writeimg -vnd ${LOOPDEV} ./writeimg +./writeimg -nd ${LOOPDEV} ./writeimg +./writeimg -vnd ${LOOPDEV} ./writeimg -sudo ./writeimg -nd ${LOOPDEV} ./LICENSE -sudo ./writeimg -vnd ${LOOPDEV} ./LICENSE +./writeimg -nd ${LOOPDEV} ./LICENSE +./writeimg -vnd ${LOOPDEV} ./LICENSE # Redirect this to avoid confusion -! sudo ./writeimg -vnd ${LOOPDEV} ./crc32.h 2>/dev/null +! ./writeimg -vnd ${LOOPDEV} ./crc32.h 2>/dev/null GREEN="\e[32m" RESET="\e[0m" From 1ca6f8dfdf0f62051839ee46d28038570212352e Mon Sep 17 00:00:00 2001 From: Imbus Date: Sat, 21 Feb 2026 08:06:37 +0100 Subject: [PATCH 2/2] Fix warning in musl related to ioctl Ioctl's in musl take ints, while glibc take unsigned longs. When not using glibc, default to casting the ioctl number to an int. Tests passing. --- writeimg.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/writeimg.c b/writeimg.c index f0139ad..2219acb 100644 --- a/writeimg.c +++ b/writeimg.c @@ -278,7 +278,11 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } +#ifdef __GLIBC__ if (ioctl(fd, BLKGETSIZE64, &device_size) < 0) { +#else /* With musl, ioctl's take ints, kheaders provide unsigned longs. Passes tests. */ + if (ioctl(fd, (int)BLKGETSIZE64, &device_size) < 0) { +#endif perror("ioctl"); close(fd); exit(EXIT_FAILURE);