diff --git a/lib/Makefile b/lib/Makefile --- a/lib/Makefile +++ b/lib/Makefile @@ -74,6 +74,7 @@ libmemstat \ libmd \ libmixer \ + libmount \ libmt \ lib80211 \ libnetbsd \ diff --git a/lib/libmount/Makefile b/lib/libmount/Makefile new file mode 100644 --- /dev/null +++ b/lib/libmount/Makefile @@ -0,0 +1,20 @@ +PACKAGE= runtime + +LIB= mount +INTERNALLIB= + +SRCS+= getmntopts.c +SRCS+= mounttab.c +SRCS+= vfslist.c + +MAN+= mntopts.3 +MLINKS+= mntopts.3 getmntopts.3 +MLINKS+= mntopts.3 getmntpoint.3 +MLINKS+= mntopts.3 chkdoreload.3 +MLINKS+= mntopts.3 build_iovec.3 +MLINKS+= mntopts.3 build_iovec_argf.3 +MLINKS+= mntopts.3 free_iovec.3 +MLINKS+= mntopts.3 checkpath.3 +MLINKS+= mntopts.3 rmslashes.3 + +.include diff --git a/sbin/mount/getmntopts.c b/lib/libmount/getmntopts.c rename from sbin/mount/getmntopts.c rename to lib/libmount/getmntopts.c diff --git a/sbin/mount/mntopts.h b/lib/libmount/mntopts.h rename from sbin/mount/mntopts.h rename to lib/libmount/mntopts.h --- a/sbin/mount/mntopts.h +++ b/lib/libmount/mntopts.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef _MNTOPTS_H_ +#define _MNTOPTS_H_ + struct mntopt { const char *m_option; /* option name */ int m_inverse; /* if a negative option, e.g. "atime" */ @@ -107,3 +110,5 @@ void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); void free_iovec(struct iovec **iovec, int *iovlen); + +#endif /* !_MNTOPTS_H_ */ diff --git a/sbin/mount/mntopts.3 b/lib/libmount/mntopts.3 rename from sbin/mount/mntopts.3 rename to lib/libmount/mntopts.3 diff --git a/usr.sbin/rpc.umntall/mounttab.h b/lib/libmount/mounttab.h rename from usr.sbin/rpc.umntall/mounttab.h rename to lib/libmount/mounttab.h --- a/usr.sbin/rpc.umntall/mounttab.h +++ b/lib/libmount/mounttab.h @@ -26,6 +26,9 @@ * SUCH DAMAGE. */ +#ifndef _MOUNTTAB_H +#define _MOUNTTAB_H + #define STRSIZ (MNTNAMLEN+MNTPATHLEN+100) #define PATH_MOUNTTAB "/var/db/mounttab" @@ -44,3 +47,5 @@ int read_mtab(void); int write_mtab(int); void free_mtab(void); + +#endif /* !_MOUNTTAB_H */ diff --git a/usr.sbin/rpc.umntall/mounttab.c b/lib/libmount/mounttab.c rename from usr.sbin/rpc.umntall/mounttab.c rename to lib/libmount/mounttab.c diff --git a/sbin/mount/extern.h b/lib/libmount/vfslist.h copy from sbin/mount/extern.h copy to lib/libmount/vfslist.h --- a/sbin/mount/extern.h +++ b/lib/libmount/vfslist.h @@ -1,8 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 1997 FreeBSD Inc. - * All rights reserved. + * Copyright (c) 2025 Dimitry Andric * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +25,10 @@ * SUCH DAMAGE. */ -/* vfslist.c */ +#ifndef _VFSLIST_H_ +#define _VFSLIST_H_ + int checkvfsname(const char *, const char **); const char **makevfslist(char *); -int mount_fs(const char *, int, char *[]); +#endif /* !_VFSLIST_H_ */ diff --git a/sbin/mount/vfslist.c b/lib/libmount/vfslist.c rename from sbin/mount/vfslist.c rename to lib/libmount/vfslist.c --- a/sbin/mount/vfslist.c +++ b/lib/libmount/vfslist.c @@ -33,7 +33,7 @@ #include #include -#include "extern.h" +#include "vfslist.h" static int skipvfs; diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile --- a/rescue/rescue/Makefile +++ b/rescue/rescue/Makefile @@ -143,6 +143,7 @@ # CRUNCH_PROGS+= devd CRUNCH_LIBS+= -l80211 -lalias -lcam -lncursesw -ldevstat -lipsec -llzma +CRUNCH_LIBS+= ${LIBMOUNT} CRUNCH_LIBS_camcontrol+= ${LIBNVMF} ${LIBNV} .if ${MK_ZFS} != "no" CRUNCH_LIBS+= -lavl -lpthread -luutil -lumem -ltpool -lspl -lrt diff --git a/sbin/fsck/Makefile b/sbin/fsck/Makefile --- a/sbin/fsck/Makefile +++ b/sbin/fsck/Makefile @@ -3,10 +3,8 @@ PACKAGE=runtime PROG= fsck SRCS= fsck.c fsutil.c preen.c -SRCS+= getmntopts.c MAN= fsck.8 -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+= -I${MOUNT} -.PATH: ${MOUNT} +CFLAGS+=-I${SRCTOP}/lib/libmount +LIBADD+=mount .include diff --git a/sbin/fsck_ffs/Makefile b/sbin/fsck_ffs/Makefile --- a/sbin/fsck_ffs/Makefile +++ b/sbin/fsck_ffs/Makefile @@ -5,12 +5,11 @@ MAN= fsck_ffs.8 MLINKS= fsck_ffs.8 fsck_ufs.8 fsck_ffs.8 fsck_4.2bsd.8 SRCS= dir.c ea.c fsutil.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c \ - pass4.c pass5.c setup.c suj.c utilities.c gjournal.c getmntopts.c \ - globs.c -LIBADD= ufs + pass4.c pass5.c setup.c suj.c utilities.c gjournal.c globs.c +LIBADD= mount ufs WARNS?= 2 -CFLAGS+= -I${.CURDIR} -I${.CURDIR:H}/mount +CFLAGS+= -I${.CURDIR} -I${SRCTOP}/lib/libmount -.PATH: ${SRCTOP}/sys/ufs/ffs ${.CURDIR:H}/mount +.PATH: ${SRCTOP}/sys/ufs/ffs .include diff --git a/sbin/growfs/Makefile b/sbin/growfs/Makefile --- a/sbin/growfs/Makefile +++ b/sbin/growfs/Makefile @@ -3,13 +3,11 @@ .include -.PATH: ${.CURDIR:H}/mount - PACKAGE=ufs PROG= growfs -SRCS= growfs.c getmntopts.c +SRCS= growfs.c MAN= growfs.8 -CFLAGS+=-I${.CURDIR:H}/mount +CFLAGS+=-I${SRCTOP}/lib/libmount .if defined(GFSDBG) SRCS+= debug.c @@ -17,7 +15,7 @@ NO_WCAST_ALIGN= yes .endif -LIBADD= ufs util +LIBADD= mount ufs util HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/sbin/init/Makefile b/sbin/init/Makefile --- a/sbin/init/Makefile +++ b/sbin/init/Makefile @@ -1,7 +1,7 @@ CONFGROUPS= CONFTTYS PACKAGE=runtime PROG= init -SRCS= init.c getmntopts.c +SRCS= init.c MAN= init.8 PRECIOUSPROG= INSTALLFLAGS=-b -B.bak @@ -11,10 +11,8 @@ CONFTTYSNAME= ttys CONFTTYS+= ttys -# Needed for getmntopts.c -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+=-I${MOUNT} -.PATH: ${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount NO_SHARED?= YES diff --git a/sbin/mksnap_ffs/Makefile b/sbin/mksnap_ffs/Makefile --- a/sbin/mksnap_ffs/Makefile +++ b/sbin/mksnap_ffs/Makefile @@ -1,12 +1,11 @@ -.PATH: ${.CURDIR:H}/mount - PACKAGE=ufs PROG= mksnap_ffs -SRCS= mksnap_ffs.c getmntopts.c +SRCS= mksnap_ffs.c MAN= mksnap_ffs.8 WARNS?= 2 -CFLAGS+=-I${.CURDIR:H}/mount +CFLAGS+=-I${SRCTOP}/lib/libmount +LIBADD+=mount .if defined(NOSUID) BINMODE=554 diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile --- a/sbin/mount/Makefile +++ b/sbin/mount/Makefile @@ -1,16 +1,9 @@ PACKAGE=runtime PROG= mount -SRCS= mount.c mount_fs.c getmntopts.c vfslist.c -MAN= mntopts.3 mount.8 -MLINKS+= mntopts.3 getmntopts.3 -MLINKS+= mntopts.3 getmntpoint.3 -MLINKS+= mntopts.3 chkdoreload.3 -MLINKS+= mntopts.3 build_iovec.3 -MLINKS+= mntopts.3 build_iovec_argf.3 -MLINKS+= mntopts.3 free_iovec.3 -MLINKS+= mntopts.3 checkpath.3 -MLINKS+= mntopts.3 rmslashes.3 +SRCS= mount.c mount_fs.c +MAN= mount.8 -LIBADD= util xo +CFLAGS+=-I${SRCTOP}/lib/libmount +LIBADD= mount util xo .include diff --git a/sbin/mount/extern.h b/sbin/mount/extern.h --- a/sbin/mount/extern.h +++ b/sbin/mount/extern.h @@ -26,8 +26,4 @@ * SUCH DAMAGE. */ -/* vfslist.c */ -int checkvfsname(const char *, const char **); -const char **makevfslist(char *); - int mount_fs(const char *, int, char *[]); diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -53,6 +53,7 @@ #include "extern.h" #include "mntopts.h" #include "pathnames.h" +#include "vfslist.h" #define EXIT(a) { \ xo_close_container("mount"); \ diff --git a/sbin/mount_cd9660/Makefile b/sbin/mount_cd9660/Makefile --- a/sbin/mount_cd9660/Makefile +++ b/sbin/mount_cd9660/Makefile @@ -1,16 +1,14 @@ PACKAGE=runtime PROG= mount_cd9660 -SRCS= mount_cd9660.c getmntopts.c +SRCS= mount_cd9660.c MAN= mount_cd9660.8 LIBADD= kiconv -MOUNT= ${.CURDIR:H}/mount -CFLAGS+= -I${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount # Needs to be dynamically linked for optional dlopen() access to # userland libiconv NO_SHARED?= NO -.PATH: ${MOUNT} - .include diff --git a/sbin/mount_fusefs/Makefile b/sbin/mount_fusefs/Makefile --- a/sbin/mount_fusefs/Makefile +++ b/sbin/mount_fusefs/Makefile @@ -20,12 +20,10 @@ PACKAGE=runtime PROG= mount_fusefs -SRCS= mount_fusefs.c getmntopts.c +SRCS= mount_fusefs.c MAN8= mount_fusefs.8 -MOUNT= ${.CURDIR:H}/mount -CFLAGS+= -I${MOUNT} - -.PATH: ${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount .include diff --git a/sbin/mount_msdosfs/Makefile b/sbin/mount_msdosfs/Makefile --- a/sbin/mount_msdosfs/Makefile +++ b/sbin/mount_msdosfs/Makefile @@ -1,19 +1,14 @@ -# -# - PACKAGE=runtime PROG= mount_msdosfs -SRCS= mount_msdosfs.c getmntopts.c +SRCS= mount_msdosfs.c MAN= mount_msdosfs.8 LIBADD= kiconv -MOUNT= ${.CURDIR:H}/mount -CFLAGS+= -I${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount # Needs to be dynamically linked for optional dlopen() access to # userland libiconv NO_SHARED?= NO -.PATH: ${MOUNT} - .include diff --git a/sbin/mount_nfs/Makefile b/sbin/mount_nfs/Makefile --- a/sbin/mount_nfs/Makefile +++ b/sbin/mount_nfs/Makefile @@ -1,12 +1,9 @@ PACKAGE=nfs PROG= mount_nfs -SRCS= mount_nfs.c getmntopts.c mounttab.c +SRCS= mount_nfs.c MAN= mount_nfs.8 -MOUNT= ${.CURDIR:H}/mount -UMNTALL= ${SRCTOP}/usr.sbin/rpc.umntall -CFLAGS+= -DNFS -I${MOUNT} -I${UMNTALL} - -.PATH: ${MOUNT} ${UMNTALL} +CFLAGS+= -DNFS -I${SRCTOP}/lib/libmount +LIBADD+= mount .include diff --git a/sbin/mount_nullfs/Makefile b/sbin/mount_nullfs/Makefile --- a/sbin/mount_nullfs/Makefile +++ b/sbin/mount_nullfs/Makefile @@ -1,11 +1,9 @@ PACKAGE=runtime PROG= mount_nullfs -SRCS= mount_nullfs.c getmntopts.c +SRCS= mount_nullfs.c MAN= mount_nullfs.8 -MOUNT= ${.CURDIR:H}/mount -CFLAGS+=-I${MOUNT} - -.PATH: ${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount .include diff --git a/sbin/mount_udf/Makefile b/sbin/mount_udf/Makefile --- a/sbin/mount_udf/Makefile +++ b/sbin/mount_udf/Makefile @@ -1,12 +1,11 @@ PACKAGE=runtime PROG= mount_udf -SRCS= mount_udf.c getmntopts.c +SRCS= mount_udf.c MAN= mount_udf.8 LIBADD= kiconv -MOUNT= ${.CURDIR:H}/mount -CFLAGS+= -I${MOUNT} -I${SRCTOP}/sys -.PATH: ${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount -I${SRCTOP}/sys +LIBADD+= mount # Needs to be dynamically linked for optional dlopen() access to # userland libiconv diff --git a/sbin/mount_unionfs/Makefile b/sbin/mount_unionfs/Makefile --- a/sbin/mount_unionfs/Makefile +++ b/sbin/mount_unionfs/Makefile @@ -1,11 +1,9 @@ PACKAGE=runtime PROG= mount_unionfs -SRCS= mount_unionfs.c getmntopts.c +SRCS= mount_unionfs.c MAN= mount_unionfs.8 -MOUNT= ${.CURDIR:H}/mount -CFLAGS+=-I${MOUNT} - -.PATH: ${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount .include diff --git a/sbin/tunefs/Makefile b/sbin/tunefs/Makefile --- a/sbin/tunefs/Makefile +++ b/sbin/tunefs/Makefile @@ -1,12 +1,10 @@ PACKAGE=ufs PROG= tunefs -SRCS= tunefs.c getmntopts.c -LIBADD= ufs +SRCS= tunefs.c +LIBADD= mount ufs MAN= tunefs.8 -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+= -I${MOUNT} -.PATH: ${MOUNT} +CFLAGS+=-I${SRCTOP}/lib/libmount WARNS?= 3 diff --git a/sbin/umount/Makefile b/sbin/umount/Makefile --- a/sbin/umount/Makefile +++ b/sbin/umount/Makefile @@ -1,12 +1,9 @@ PACKAGE=runtime PROG= umount -SRCS= umount.c vfslist.c mounttab.c +SRCS= umount.c MAN= umount.8 -MOUNT= ${.CURDIR:H}/mount -UMNTALL= ${SRCTOP}/usr.sbin/rpc.umntall -CFLAGS+= -I${MOUNT} -I${UMNTALL} - -.PATH: ${MOUNT} ${UMNTALL} +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount .include diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk --- a/share/mk/src.libnames.mk +++ b/share/mk/src.libnames.mk @@ -55,6 +55,7 @@ lpr \ lua \ lutok \ + mount \ netbsd \ ntp \ ntpevent \ @@ -699,6 +700,9 @@ LIBWPAWPSDIR= ${_LIB_OBJTOP}/usr.sbin/wpa/src/wps LIBWPAWPS?= ${LIBWPAWPSDIR}/libwpawps${PIE_SUFFIX}.a +LIBMOUNTDIR?= ${_LIB_OBJTOP}/lib/libmount +LIBMOUNT?= ${LIBMOUNTDIR}/libmount${PIE_SUFFIX}.a + LIBC_NOSSP_PICDIR= ${_LIB_OBJTOP}/lib/libc LIBC_NOSSP_PIC?= ${LIBC_NOSSP_PICDIR}/libc_nossp_pic.a diff --git a/tests/sys/fs/fusefs/Makefile b/tests/sys/fs/fusefs/Makefile --- a/tests/sys/fs/fusefs/Makefile +++ b/tests/sys/fs/fusefs/Makefile @@ -55,7 +55,6 @@ .for p in ${GTESTS} SRCS.$p+= ${p}.cc -SRCS.$p+= getmntopts.c SRCS.$p+= mockfs.cc SRCS.$p+= utils.cc .endfor @@ -68,7 +67,7 @@ TEST_METADATA+= timeout=10 FUSEFS= ${SRCTOP}/sys/fs/fuse -MOUNT= ${SRCTOP}/sbin/mount +MOUNT= ${SRCTOP}/lib/libmount # Suppress warnings that GCC generates for the libc++ and gtest headers. CXXWARNFLAGS.gcc+= -Wno-placement-new -Wno-attributes # Suppress Wcast-align for readdir.cc, because it is unavoidable when using @@ -88,8 +87,8 @@ CXXFLAGS+= -I${SRCTOP}/tests CXXFLAGS+= -I${FUSEFS} CXXFLAGS+= -I${MOUNT} -.PATH: ${MOUNT} +LIBADD+= mount LIBADD+= pthread LIBADD+= gmock gtest LIBADD+= util diff --git a/usr.sbin/autofs/Makefile b/usr.sbin/autofs/Makefile --- a/usr.sbin/autofs/Makefile +++ b/usr.sbin/autofs/Makefile @@ -6,27 +6,21 @@ SRCS+= autounmountd.c SRCS+= common.c SRCS+= defined.c -SRCS+= getmntopts.c SRCS+= log.c SRCS+= popen.c SRCS+= token.l CFLAGS+=-I${.CURDIR} CFLAGS+=-I${SRCTOP}/sys/fs/autofs +CFLAGS+=-I${SRCTOP}/lib/libmount MAN= automount.8 automountd.8 autounmountd.8 auto_master.5 -LIBADD= util - -# Needed for getmntopts.c -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+=-I${MOUNT} +LIBADD= mount util LINKS= ${BINDIR}/automountd ${BINDIR}/automount LINKS+= ${BINDIR}/automountd ${BINDIR}/autounmountd -.PATH: ${MOUNT} - SUBDIR= autofs .include diff --git a/usr.sbin/mount_smbfs/Makefile b/usr.sbin/mount_smbfs/Makefile --- a/usr.sbin/mount_smbfs/Makefile +++ b/usr.sbin/mount_smbfs/Makefile @@ -1,15 +1,15 @@ PROG= mount_smbfs PACKAGE= smbutils -SRCS= mount_smbfs.c getmntopts.c +SRCS= mount_smbfs.c MAN= mount_smbfs.8 -MOUNTDIR= ${SRCTOP}/sbin/mount +MOUNTDIR= ${SRCTOP}/lib/libmount CONTRIBDIR= ${SRCTOP}/contrib/smbfs CFLAGS+= -DSMBFS -I${MOUNTDIR} -I${CONTRIBDIR}/include -LIBADD= smb +LIBADD+= mount +LIBADD+= smb .PATH: ${CONTRIBDIR}/mount_smbfs -.PATH: ${MOUNTDIR} .include diff --git a/usr.sbin/mountd/Makefile b/usr.sbin/mountd/Makefile --- a/usr.sbin/mountd/Makefile +++ b/usr.sbin/mountd/Makefile @@ -1,13 +1,10 @@ PROG= mountd -SRCS= mountd.c getmntopts.c +SRCS= mountd.c MAN= exports.5 netgroup.5 mountd.8 -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+= -I${MOUNT} +CFLAGS+= -I${SRCTOP}/lib/libmount WARNS?= 2 -.PATH: ${MOUNT} - -LIBADD= util +LIBADD= mount util .include diff --git a/usr.sbin/rpc.umntall/Makefile b/usr.sbin/rpc.umntall/Makefile --- a/usr.sbin/rpc.umntall/Makefile +++ b/usr.sbin/rpc.umntall/Makefile @@ -2,7 +2,10 @@ PROG= rpc.umntall MAN= rpc.umntall.8 -SRCS= rpc.umntall.c mounttab.c +SRCS= rpc.umntall.c + +CFLAGS+= -I${SRCTOP}/lib/libmount +LIBADD+= mount WARNS?= 3