Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH mtd-utils RFC] Add an ubifs mount helper
@ 2020-10-06  9:19 Uwe Kleine-König
  2020-11-16  9:39 ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2020-10-06  9:19 UTC (permalink / raw)
  To: David Oberhollenzer; +Cc: Richard Weinberger, linux-mtd, entwicklung

This abstracts away attaching of the right ubi and then selecting the right
ubi device and volume to mount.

As described in the comment at the top this allows to mount ubifs volumes
directly from /etc/fstab without having to use hardcoded numbers (which
depend on mount order and so are unreliable) and extra magic to care for
attaching.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

this is a nice script that helps attaching ubis and mounting ubifs'. I
already discussed this a bit with Richard on irc and the idea was
welcome in principle.

A concern was that the entry in /etc/fstab is too magic and there should
be an indication that this relies on the mount helper. Something like
using ubifs.autoattach as file system type (fs_vfstype) or requiring
"autoattach" in the fourth field (fs_mntops).

Having thought a bit I'm not convinced we need this indication. Yes
there is magic but nothing out of the ordinary as mount helpers are a
known concept and the fs_spec already looks interesting enough to make
it obvious there is something going on. And once people are used to the
magic it is annoying to have to always write this indication in your
fstab. Additionally it complicates the implementation. 

Also "autoattach" doesn't completely cover the script as it does a
translation from mtd name to mtd number, too. "autoattach,mtdtranslate"
seems a bit excessive.

Best regards
Uwe

 ubifs-utils/Makemodule.am |   2 +
 ubifs-utils/mount.ubifs   | 101 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100755 ubifs-utils/mount.ubifs

diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am
index 59109ccd613c..5c5d99f7572b 100644
--- a/ubifs-utils/Makemodule.am
+++ b/ubifs-utils/Makemodule.am
@@ -47,4 +47,6 @@ UBIFS_EXTRA = \
 
 EXTRA_DIST += $(UBIFS_HEADER) $(UBIFS_EXTRA)
 
+dist_sbin_SCRIPTS = ubifs-utils/mount.ubifs
+
 sbin_PROGRAMS += $(UBIFS_BINS)
diff --git a/ubifs-utils/mount.ubifs b/ubifs-utils/mount.ubifs
new file mode 100755
index 000000000000..b94ddc5649f4
--- /dev/null
+++ b/ubifs-utils/mount.ubifs
@@ -0,0 +1,101 @@
+#!/bin/sh
+
+# This script should be installed as /sbin/mount.ubifs. The benefit is that an
+# fstab entry like:
+#
+# 	mtd=mtddev:home     /home        ubifs   defaults 0 0
+#
+# results in the ubi contained in the mtd named "mtddev" to be attached (if not
+# already done) and then the volume named "home" being mounted to /home.
+
+# This is called by mount with the following options:
+# /sbin/mount.ubifs spec dir [-sfnv] [-N namespace] [-o options] [-t type.subtype]
+
+spec="$1"
+shift
+
+mtdname2num() {
+	local name
+
+	name="$1"
+
+	for d in $(find /sys/class/mtd/ -regex '.*/mtd[0-9]*'); do
+		case "$d" in
+			*ro)
+				continue
+				;;
+		esac
+
+		if test "$name" = "$(cat "$d/name")"; then
+			local dev mtdnum
+
+			dev="$(basename "$d")"
+			mtdnum="${dev#mtd}"
+			echo "$mtdnum"
+			return
+		fi
+	done
+
+	return 1
+}
+
+mtdnum2ubi() {
+	local mtdnum
+
+	mtdnum="$1"
+
+	for d in $(find /sys/class/ubi/ -regex '.*/ubi[0-9]*'); do
+		case "$d" in
+			*_[0-9]*)
+				continue
+				;;
+		esac
+
+		if test "$mtdnum" = "$(cat "$d/mtd_num")"; then
+			local ubi
+
+			ubi="$(basename "$d")"
+			echo "$ubi"
+			return;
+		fi
+	done
+
+	return 1
+}
+
+mtdnum2ubi_autoattach() {
+	local mtdnum ubi
+
+	mtdnum="$1"
+
+	ubi="$(mtdnum2ubi "$mtdnum")" && { echo "$ubi"; return; }
+
+	# ubiattach might fail with "mtdX is already attached to ubiY" if there
+	# is more than one mount to do in the same mtd partition. So ignore errors.
+	ubiattach -m "$mtdnum" >&2 || true
+
+	mtdnum2ubi "$mtdnum"
+}
+
+case "$spec" in
+	mtd=*:*)
+		spec="${spec#mtd=}"
+		mtd="${spec%:*}"
+		rspec="${spec#*:}"
+
+		mtdnum="$(mtdname2num "$mtd")" || {
+			echo "Failed to find mtdnum for mtd \"$mtd\""
+			exit 1
+		}
+
+		ubi="$(mtdnum2ubi_autoattach "$mtdnum")" || {
+			echo "Failed to find ubi for mtd \"$mtd\""
+			exit 1
+		}
+
+		spec="$ubi:$rspec"
+
+		;;
+esac
+
+/bin/mount -i -t ubifs "$spec" "$@"
-- 
2.28.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH mtd-utils RFC] Add an ubifs mount helper
  2020-10-06  9:19 [PATCH mtd-utils RFC] Add an ubifs mount helper Uwe Kleine-König
@ 2020-11-16  9:39 ` Uwe Kleine-König
  2020-11-18 14:43   ` David Oberhollenzer
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2020-11-16  9:39 UTC (permalink / raw)
  To: David Oberhollenzer; +Cc: Richard Weinberger, linux-mtd, entwicklung

[-- Attachment #1.1: Type: text/plain, Size: 1847 bytes --]

Hello,

On Tue, Oct 06, 2020 at 11:19:13AM +0200, Uwe Kleine-König wrote:
> This abstracts away attaching of the right ubi and then selecting the right
> ubi device and volume to mount.
> 
> As described in the comment at the top this allows to mount ubifs volumes
> directly from /etc/fstab without having to use hardcoded numbers (which
> depend on mount order and so are unreliable) and extra magic to care for
> attaching.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> this is a nice script that helps attaching ubis and mounting ubifs'. I
> already discussed this a bit with Richard on irc and the idea was
> welcome in principle.
> 
> A concern was that the entry in /etc/fstab is too magic and there should
> be an indication that this relies on the mount helper. Something like
> using ubifs.autoattach as file system type (fs_vfstype) or requiring
> "autoattach" in the fourth field (fs_mntops).
> 
> Having thought a bit I'm not convinced we need this indication. Yes
> there is magic but nothing out of the ordinary as mount helpers are a
> known concept and the fs_spec already looks interesting enough to make
> it obvious there is something going on. And once people are used to the
> magic it is annoying to have to always write this indication in your
> fstab. Additionally it complicates the implementation. 
> 
> Also "autoattach" doesn't completely cover the script as it does a
> translation from mtd name to mtd number, too. "autoattach,mtdtranslate"
> seems a bit excessive.

I didn't hear any feedback here. Is reviewing this patch still on
somebody's todo list?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 144 bytes --]

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH mtd-utils RFC] Add an ubifs mount helper
  2020-11-16  9:39 ` Uwe Kleine-König
@ 2020-11-18 14:43   ` David Oberhollenzer
  0 siblings, 0 replies; 3+ messages in thread
From: David Oberhollenzer @ 2020-11-18 14:43 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Richard Weinberger, linux-mtd, entwicklung

On 11/16/20 10:39 AM, Uwe Kleine-König wrote:
> 
> I didn't hear any feedback here. Is reviewing this patch still on
> somebody's todo list?
> 

I compared this version against the one you linked to on IRC earlier, where
the idea itself seemed to be approved quite well.

I don't see any issue with this patch, but I was still waiting out for
maybe *somebody* else posting some kind comment or remark, if not outright
spotting an issue we missed when discussing it on IRC.

As there seem to be no objects, I applied it to mtd-utils.git master.

Greetings,

David

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06  9:19 [PATCH mtd-utils RFC] Add an ubifs mount helper Uwe Kleine-König
2020-11-16  9:39 ` Uwe Kleine-König
2020-11-18 14:43   ` David Oberhollenzer

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git