From 8207ad1c81cea80cb6e5f686c6a2f323a1e7fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erin=E2=80=84Yuki=E2=80=89Schlarb?= Date: Fri, 20 Dec 2024 16:48:52 +0100 Subject: [PATCH 1/2] Add wrapper shell script exposing the mount helper interface for vramfs --- fuse3.vramfs | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 fuse3.vramfs diff --git a/fuse3.vramfs b/fuse3.vramfs new file mode 100755 index 0000000..fc95d03 --- /dev/null +++ b/fuse3.vramfs @@ -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 -o 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} -o 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 \ No newline at end of file From aa884193eb29cb240d76a592ccb8591e4738596e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erin=E2=80=84Yuki=E2=80=89Schlarb?= Date: Fri, 20 Dec 2024 16:54:01 +0100 Subject: [PATCH 2/2] Add `install` and `uninstall` Makefile targets to show suggested installation --- Makefile | 11 +++++++++++ README.md | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Makefile b/Makefile index e6e45e2..60ab1bf 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 4dad506..85f3e36 100644 --- a/README.md +++ b/README.md @@ -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 `. The `mountdir` can be