Skip to contentSkip to conversation

Enable findmnt on kfreebsd

PATCH Jeff Epler 3 participants 5 messages Mar 14, 2013

Subsystems (2)
lore
Share & tools
lore

Jeff Epler

author
#0 lore raw

In a recent discussion on #debian-kbsd, rleigh brought up the fact that findmnt isn't available on kfreebsd; he feels it would be useful in initscripts.

I had a look at what it would take to enable findmnt, which needs libmount. It turns out that not much is required: mostly, make a few bits of code return (-)ENOSYS. There were also a few more bits that needed tweaking before kfreebsd was happy (LIST_HEAD is also in some bsd-origin header, and of course <linux/posix_types.h> was not available).

I'm not sure I correctly intuited where it was proper to return +ENOSYS and where it was proper to return -ENOSYS, so this merits further study.

There's also a bit of debian bookkeeping which is not of interest to util-linux@

Once this is done, findmnt (the only libmount-relying part I tested) seems to work properly, including listing zfs filesystems.

Please copy me on any replies as I am not subscribed to util-linux.

Jeff

configure.ac +1 -6
diff -u util-linux-2.20.1/configure.ac util-linux-2.20.1/configure.ac
@@ -446,12 +446,7 @@
   [], enable_libmount=check
 )
 build_libmount=yes
-if test "x$enable_libmount" = xcheck; then
-  if test "x$linux_os" = xno; then
-    AC_MSG_WARN([non-linux system; do not build libmount])
-    build_libmount=no
-  fi
-elif test "x$enable_libmount" = xno; then
+if test "x$enable_libmount" = xno; then
     build_libmount=no
 fi
 
debian/changelog +7 -0
diff -u util-linux-2.20.1/debian/changelog util-linux-2.20.1/debian/changelog
@@ -1,3 +1,10 @@
+util-linux (2.20.1-5.4) UNRELEASED; urgency=low
+
+  * Non-maintainer upload.
+  * Hack libmount into building (enables findmnt)
+
+ -- Jeff Epler <jepler@localhost>  Wed, 13 Mar 2013 19:04:59 -0500
+
 util-linux (2.20.1-5.3) unstable; urgency=low
 
   * Non-maintainer upload.
debian/control +1 -1
diff -u util-linux-2.20.1/debian/control util-linux-2.20.1/debian/control
@@ -130,7 +130,7 @@
 Priority: required
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Pre-Depends: multiarch-support
-Architecture: linux-any
+Architecture: linux-any kfreebsd-any
 Description: block device id library
  The device mounting library, used by mount and mount helpers.
 

only in patch2:
unchanged:

include/list.h +4 -0
@@ -31,6 +31,10 @@
 
 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 
+#ifdef LIST_HEAD
+#undef LIST_HEAD
+#endif
+
 #define LIST_HEAD(name) \
 	struct list_head name = LIST_HEAD_INIT(name)
 

only in patch2:
unchanged:

libmount/src/context_umount.c +8 -0
@@ -439,6 +439,9 @@
 /* Check whether the kernel supports UMOUNT_NOFOLLOW flag */
 static int umount_nofollow_support(void)
 {
+#ifdef __FreeBSD_kernel__
+	return  0;
+#else
 	int res = umount2("", UMOUNT_UNUSED);
 	if (res != -1 || errno != EINVAL)
 		return 0;
@@ -448,10 +451,14 @@
 		return 0;
 
 	return 1;
+#endif
 }
 
 static int do_umount(struct libmnt_context *cxt)
 {
+#ifdef __FreeBSD_kernel__
+	return -ENOSYS;
+#else
 	int rc = 0, flags = 0;
 	const char *src, *target;
 	char *tgtbuf = NULL;
@@ -541,6 +548,7 @@
 	cxt->syscall_status = 0;
 	DBG(CXT, mnt_debug_h(cxt, "umount(2) success"));
 	return 0;
+#endif
 }
 
 /**

only in patch2:
unchanged:

libmount/src/context_mount.c +4 -0
@@ -385,6 +385,9 @@
  */
 static int do_mount(struct libmnt_context *cxt, const char *try_type)
 {
+#ifdef __FreeBSD_kernel__
+	return ENOSYS;
+#else
 	int rc = 0;
 	const char *src, *target, *type;
 	unsigned long flags;
@@ -444,6 +447,7 @@
 	 */
 
 	return rc;
+#endif
 }
 
 static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)

only in patch2:
unchanged:

lib/loopdev.c +2 -0
@@ -29,7 +29,9 @@
 #include <sys/sysmacros.h>
 #include <inttypes.h>
 #include <dirent.h>
+#ifdef __LINUX__
 #include <linux/posix_types.h>
+#endif
 
 #include "linux_version.h"
 #include "c.h"
#1 lore raw
Quoted 13 lines · Jeff Epler, le Wed 13 Mar 2013 19:39:47 -0500, a écrit :
libmount/src/context_umount.c +3 -0
@@ -439,6 +439,9 @@
 /* Check whether the kernel supports UMOUNT_NOFOLLOW flag */
 static int umount_nofollow_support(void)
 {
+#ifdef __FreeBSD_kernel__
+	return  0;
+#else
 	int res = umount2("", UMOUNT_UNUSED);
 	if (res != -1 || errno != EINVAL)
 		return 0;

libmount/src/context_umount.c line 454

Quoted 4 lines
libmount/src/context_umount.c +1 -0
@@ -448,10 +451,14 @@
 		return 0;
 
 	return 1;
+#endif

Perhaps rather turn all these into
#ifdef __linux__
linux stuff
#else
return 0;
#endif
?

Samuel

author
#2 lore raw
Quoted 5 lines · Samuel Thibault
Quoted 1 line · Jeff Epler, le Wed 13 Mar 2013 19:39:47 -0500, a écrit :

+#ifdef __FreeBSD_kernel__

Perhaps rather turn all these into
#ifdef __linux__

Fine by me, and might make e.g., hurd work too (or at least get closer).

Jeff

#3 lore raw
Quoted 8 lines · Jeff Epler, le Wed 13 Mar 2013 21:02:41 -0500, a écrit :
Quoted 5 lines · Samuel Thibault
Quoted 1 line · Jeff Epler, le Wed 13 Mar 2013 19:39:47 -0500, a écrit :

+#ifdef __FreeBSD_kernel__

Perhaps rather turn all these into
#ifdef __linux__

Fine by me, and might make e.g., hurd work too (or at least get closer).

That was the point, yes :)

Samuel

maintainer
#4 lore raw
In reply to Jeff Epler
Quoted 3 lines · Jeff Epler

In a recent discussion on #debian-kbsd, rleigh brought up the fact that findmnt isn't available on kfreebsd; he feels it would be useful in initscripts.

Do you mean for fstab/mtab parsing? ... because I cannot imagine anything else without Linux kernel.

Quoted 9 lines

I had a look at what it would take to enable findmnt, which needs libmount. It turns out that not much is required: mostly, make a few bits of code return (-)ENOSYS. There were also a few more bits that needed tweaking before kfreebsd was happy (LIST_HEAD is also in some bsd-origin header, and of course <linux/posix_types.h> was not available).

I'm not sure I correctly intuited where it was proper to return +ENOSYS and where it was proper to return -ENOSYS, so this merits further study.

Maybe you can #ifdef whole context{.c,_umount.c,mount.c} API. All you need is probably fs.c tab*.c files. Maybe you can modify libmount/src/Makemodule.am rather than code to create a minimalistic kernel independent libmount :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com