Compare commits
No commits in common. "1ca6f8dfdf0f62051839ee46d28038570212352e" and "8601db8811a54717719702effe3bed94bc2ce86f" have entirely different histories.
1ca6f8dfdf
...
8601db8811
2 changed files with 15 additions and 26 deletions
37
test.sh
37
test.sh
|
|
@ -4,17 +4,13 @@ set -e
|
||||||
# set -x # For debugging
|
# set -x # For debugging
|
||||||
|
|
||||||
# If you ever mess this up:
|
# If you ever mess this up:
|
||||||
# $ mknod /dev/loop-control c 10 237
|
# $ sudo mknod /dev/loop-control c 10 237
|
||||||
# $ chmod 600 /dev/loop-control
|
# $ sudo chmod 600 /dev/loop-control
|
||||||
# $ chown root:root /dev/loop-control
|
# $ sudo chown root:root /dev/loop-control
|
||||||
#
|
#
|
||||||
# For cleanup:
|
# For cleanup:
|
||||||
# $ find /dev -maxdepth 1 -type b -name 'loop[0-9]*' -exec rm -f {} \;
|
# $ sudo 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"
|
DISKFILE="/tmp/disk.img"
|
||||||
BINFILE="/tmp/file.bin"
|
BINFILE="/tmp/file.bin"
|
||||||
|
|
@ -26,9 +22,9 @@ echo "Using device: ${LOOPDEV}"
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
set +e -x
|
set +e -x
|
||||||
losetup -d ${LOOPDEV}
|
sudo losetup -d ${LOOPDEV}
|
||||||
rm ${LOOPDEV}
|
sudo rm ${LOOPDEV}
|
||||||
rm ${BINFILE} ${DISKFILE}
|
sudo rm ${BINFILE} ${DISKFILE}
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT INT TERM
|
trap cleanup EXIT INT TERM
|
||||||
|
|
@ -40,31 +36,28 @@ if losetup ${LOOPDEV} >/dev/null 2>&1; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f ${DISKFILE} ]; then
|
if [ ! -f ${DISKFILE} ]; then
|
||||||
echo "Creating ${DISKFILE}"
|
|
||||||
dd if=/dev/zero of=${DISKFILE} bs=1M count=256
|
dd if=/dev/zero of=${DISKFILE} bs=1M count=256
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f ${BINFILE} ]; then
|
if [ ! -f ${BINFILE} ]; then
|
||||||
echo "Creating ${BINFILE}"
|
|
||||||
dd if=/dev/urandom of=${BINFILE} bs=1M count=64
|
dd if=/dev/urandom of=${BINFILE} bs=1M count=64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e ${LOOPDEV} ]; then
|
if [ ! -e ${LOOPDEV} ]; then
|
||||||
mknod ${LOOPDEV} b 7 ${LOOPNUM} # busybox needs this
|
sudo losetup ${LOOPDEV} ${DISKFILE}
|
||||||
losetup ${LOOPDEV} ${DISKFILE}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./writeimg -nd ${LOOPDEV} ${BINFILE}
|
sudo ./writeimg -nd ${LOOPDEV} ${BINFILE}
|
||||||
./writeimg -vnd ${LOOPDEV} ${BINFILE}
|
sudo ./writeimg -vnd ${LOOPDEV} ${BINFILE}
|
||||||
|
|
||||||
./writeimg -nd ${LOOPDEV} ./writeimg
|
sudo ./writeimg -nd ${LOOPDEV} ./writeimg
|
||||||
./writeimg -vnd ${LOOPDEV} ./writeimg
|
sudo ./writeimg -vnd ${LOOPDEV} ./writeimg
|
||||||
|
|
||||||
./writeimg -nd ${LOOPDEV} ./LICENSE
|
sudo ./writeimg -nd ${LOOPDEV} ./LICENSE
|
||||||
./writeimg -vnd ${LOOPDEV} ./LICENSE
|
sudo ./writeimg -vnd ${LOOPDEV} ./LICENSE
|
||||||
|
|
||||||
# Redirect this to avoid confusion
|
# Redirect this to avoid confusion
|
||||||
! ./writeimg -vnd ${LOOPDEV} ./crc32.h 2>/dev/null
|
! sudo ./writeimg -vnd ${LOOPDEV} ./crc32.h 2>/dev/null
|
||||||
|
|
||||||
GREEN="\e[32m"
|
GREEN="\e[32m"
|
||||||
RESET="\e[0m"
|
RESET="\e[0m"
|
||||||
|
|
|
||||||
|
|
@ -278,11 +278,7 @@ int main(int argc, char *argv[]) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
|
||||||
if (ioctl(fd, BLKGETSIZE64, &device_size) < 0) {
|
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");
|
perror("ioctl");
|
||||||
close(fd);
|
close(fd);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue