wip/mount

This commit is contained in:
Marc Beninca 2024-11-16 04:23:54 +01:00
parent 36aaa275a7
commit 58ca9eb86f
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -1,52 +1,75 @@
mo() {
local root="${1}"
if [ -z "${root}" ]; then
log_error "No root"
log_error "No root target directory"
return 1
fi
root="$(realpath "${root}")"
if ! mkdir "overlay"; then
log_error "Unable to make mount directory"
log_error "Unable to make overlay directory"
return 2
fi
{
(
if ! cd "overlay"; then
log_error "Unable to move into mount directory"
log_error "Unable to move into overlay directory"
return 3
fi
local directory
for directory in "lower" "upper" "work" "mount"; do
if ! mkdir --parents "${directory}"; then
log_error "Unable to move into: ${directory}"
log_error "Unable to make directory: ${directory}"
return 4
fi
done
local file="${root}/filesystem.squashfs"
if ! mount "${file}" "lower"; then
log_error "Unable to mount: ${file}"
log_error "Unable to lower mount: ${file}"
return 5
fi
if ! mount \
-o "lowerdir=lower,upperdir=upper,workdir=work" \
-t "overlay" \
"overlay" "mount"; then
log_error "Unable to mount: ${file}"
log_error "Unable to overlay mount"
return 6
fi
}
)
}
uo() {
cd "overlay"
if umount "mount"; then
rmdir "mount"
rm --recursive "upper" "work"
if umount "lower"; then
rmdir "lower"
(
if ! cd "overlay"; then
log_error "Unable to move into overlay directory"
return 1
fi
if ! umount "mount"; then
log_error "Unable to unmount mount directory"
return 2
fi
if ! rmdir "mount"; then
log_error "Unable to remove mount directory"
return 3
fi
local directory
for directory in "upper" "work"; do
if ! rm --force --recursive "${directory}"; then
log_error "Unable to remove directory: ${directory}"
return 4
fi
done
if ! umount "lower"; then
log_error "Unable to unmount lower directory"
return 5
fi
if ! rmdir "lower"; then
log_error "Unable to remove lower directory"
return 6
fi
)
if ! rmdir "overlay"; then
log_error "Unable to remove overlay directory"
return 7
fi
cd ..
rmdir "overlay"
}
mr() {