From 5ade8fea0d30e88931f0d64927afd4a5034e8cee Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 11 Jul 1999 01:51:30 +0000 Subject: 1999-07-10 Roland McGrath * Makefile (special-targets): Add losetup. (SCRIPTS): Add losetup.sh. * losetup.sh: New file. --- sutils/Makefile | 12 +++++----- sutils/losetup.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 sutils/losetup.sh (limited to 'sutils') diff --git a/sutils/Makefile b/sutils/Makefile index 6542166c..dcb6604b 100644 --- a/sutils/Makefile +++ b/sutils/Makefile @@ -1,6 +1,6 @@ -# Makefile for sutils -# -# Copyright (C) 1996, 1997 Free Software Foundation +# Makefile for sutils +# +# Copyright (C) 1996,97,99 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -20,10 +20,10 @@ dir := sutils makemode := utilities -targets = reboot halt fsck e2os MAKEDEV swapon swapoff -special-targets = e2os MAKEDEV +targets = $(special-targets) reboot halt fsck swapon swapoff +special-targets = e2os MAKEDEV losetup installationdir = $(sbindir) -SCRIPTS = e2os.sh MAKEDEV.sh +SCRIPTS = e2os.sh MAKEDEV.sh losetup.sh SRCS = reboot.c halt.c fsck.c fstab.c clookup.c swapon.c swapoff.c $(SCRIPTS) LCLHDRS = fstab.h diff --git a/sutils/losetup.sh b/sutils/losetup.sh new file mode 100644 index 00000000..85734571 --- /dev/null +++ b/sutils/losetup.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# This script is roughly compatible with the Linux `losetup' utility. +# The Hurd's `storeio' translator provides the equivalent functionality +# (and a whole lot more), and of course works on any old file you want +# to translate, not just magical "/dev/loopN" device files. +# + +PATH=/bin + +usage() { + echo >&2 ... + exit 1 +} + +offset=0 +while [ $# -gt 0 ]; do + case "$arg" in + -d) + [ $# -eq 2 ] || usage + exec settrans -g -- "$2" /hurd/null + ;; + -e) + echo >&2 "$0: encryption not supported" + exit 3 + ;; + -o) + [ $# -gt 1 ] || usage + offset="$1" + shift + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac +done + +[ $# -eq 2 ] || usage +device="$1" +file="$2" + +# If the device name is "/dev/loopN", then create it if necessary. (?) +create= +case "$device" in +'/dev/loop[0-9]*') ;; # smarty pants +/dev/loop[0-9]*) create=--create ;; +esac + +type='-Tfile ' +if [ "$offset" != 0 ]; then + blksz=`storeinfo -B -- "$file"` + if [ $[ $offset % $blksz ] -ne 0 ]; then + echo >&2 "$0: offset $offset is not a multiple of device block size $blksz" + exit 1 + fi + type="-Tremap $[ $offset / $blksz ]+:file:" +fi + +exec settrans $create -gap -- "${device}" /hurd/storeio ${type}"${file}" -- cgit v1.2.3