Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ build/%.o: src/%.cpp | build
.PHONY: clean
clean:
rm -rf build/ bin/

.PHONY: install
install: bin/vramfs
install -d $(DEST)/usr/local/bin/
install bin/vramfs $(DEST)/usr/local/bin/
install fuse3.vramfs $(DEST)/usr/local/bin/

.PHONY: uninstall
uninstall:
$(RM) $(DEST)/usr/local/bin/fuse3.vramfs
$(RM) $(DEST)/usr/local/bin/vramfs
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ OpenCL driver:

* **valgrind:** `make DEBUG=1`

#### Installing

For a recommended way to install see the Makefile’s `install` target. You can
invoke the install target directly be running `sudo make install` after
finishing the build.

#### Mounting

Mount a disk by running `bin/vramfs <mountdir> <size>`. The `mountdir` can be
Expand Down
114 changes: 114 additions & 0 deletions fuse3.vramfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/sh
# POSIX compatible shell script implementing the mount helper calling convention
#
# Place this in the system $PATH (/usr/local/bin) next to the built `vramfs`
# binary to allow usage of vramfs as:
#
# mount -t fuse3.vramfs <device> <mountdir> -o size=<size>
#
# (Including the respective fstab and systemd equivalents.)
set -eu

NAME="${0##*/}"
VRAMFS=vramfs

print_help() {
if [ $# -gt 0 ];
then
echo "${NAME}: ${1}"
echo
fi

echo "usage: ${NAME} <device> <mountdir> -o size=<size>[,…]"
echo
echo " device - device number of target device, starting from 0"
echo " mountdir - directory to mount file system, must be empty"
echo " size - size of the disk in bytes"
echo
"${VRAMFS}" 2>&1 | tail -n +8
}

# Argument list validation
if [ $# -eq 0 ];
then
print_help
exit 0
fi

if [ $# -ne 4 ];
then
print_help "Exactly 4 arguments expected" >&2
exit 1
fi

if [ "$3" != "-o" ];
then
print_help "Argument 3 must be \`-o\`, following the mount helper program convention" >&2
exit 1
fi

# Save position arguments
DEVICE="$1"
MOUNTDIR="$2"

# Use options list (splitted at `,`) as argument list
#
# Source: https://unix.stackexchange.com/a/312284/47938
OLDIFS="${IFS}"
set -f; IFS=","
set -- $4
set +f; IFS="${OLDIFS}"

# Process mount options
SIZE=
for opt in "$@";
do
case "${opt}" in
# Ignore generic mount options that apply by default
rw|suid|dev|exec|noatime|async) ;;

# Print warning for unsupported generic mount options
ro|nosuid|nodev|noexec|atime|sync|dirsync)
echo "${NAME}: Ignoring unsupported generic mount option: ${opt}" >&2
;;

# Store value of required size option
size=*)
SIZE=${opt#*=}
;;

# All other mount options are errors
*)
print_help "Recevied unsupported mount option: ${opt}" >&2
exit 1
;;
esac
done

if [ -z "${SIZE}" ];
then
print_help "Missing required mount option: size=…" >&2
exit 1
fi

# Defer to actual fuse binary, exiting after it started
PARENT=$$
trap "exit 0" HUP # Return success if launch succeeded
{
"${VRAMFS}" "${MOUNTDIR}" "${SIZE}" -d "${DEVICE}" 2>&1 | while read -r line;
do
echo "${line}" >&2

if [ "${line}" = "mounted." ];
then
kill -s HUP ${PARENT}

# Replace sub-shell with `cat` to keep process standard output
# functioning without requiring the shell to remain
exec cat
fi
done
} &
wait $!

exit 4 # Return error if launch failed / no signal was trapped