diff --git a/distrib/sets/lists/base/mi b/distrib/sets/lists/base/mi index 45f64fdcc2bc0..968d2ff92965b 100644 --- a/distrib/sets/lists/base/mi +++ b/distrib/sets/lists/base/mi @@ -420,6 +420,7 @@ ./sbin/mount_fdesc base-miscfs-root fdescfs ./sbin/mount_ffs base-sysutil-root ./sbin/mount_filecore base-filecorefs-root filecorefs +./sbin/mount_full base-miscfs-root fullfs ./sbin/mount_hfs base-hfs-root hfs ./sbin/mount_hfsp base-obsolete obsolete ./sbin/mount_kernfs base-sysutil-root kernfs @@ -1128,6 +1129,7 @@ ./usr/include/miscfs base-c-usr ./usr/include/miscfs/fdesc base-c-usr ./usr/include/miscfs/fifofs base-c-usr +./usr/include/miscfs/fullfs base-c-usr ./usr/include/miscfs/genfs base-c-usr ./usr/include/miscfs/kernfs base-c-usr ./usr/include/miscfs/nullfs base-c-usr diff --git a/distrib/sets/lists/base/shl.mi b/distrib/sets/lists/base/shl.mi index c3f762f6b7fa3..38b3f0463ec7a 100644 --- a/distrib/sets/lists/base/shl.mi +++ b/distrib/sets/lists/base/shl.mi @@ -677,6 +677,9 @@ ./usr/lib/librumpfs_ffs.so base-rump-shlib rump ./usr/lib/librumpfs_ffs.so.0 base-rump-shlib rump ./usr/lib/librumpfs_ffs.so.0.0 base-rump-shlib rump +./usr/lib/librumpfs_full.so base-rump-shlib rump +./usr/lib/librumpfs_full.so.0 base-rump-shlib rump +./usr/lib/librumpfs_full.so.0.0 base-rump-shlib rump ./usr/lib/librumpfs_hfs.so base-rump-shlib rump ./usr/lib/librumpfs_hfs.so.0 base-rump-shlib rump ./usr/lib/librumpfs_hfs.so.0.0 base-rump-shlib rump diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index 9ac7023f20746..7fd0f413f2572 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -2786,6 +2786,7 @@ ./usr/include/milter/mfdef.h comp-obsolete obsolete ./usr/include/miscfs/fdesc/fdesc.h comp-c-include ./usr/include/miscfs/fifofs/fifo.h comp-c-include +./usr/include/miscfs/fullfs/full.h comp-c-include ./usr/include/miscfs/genfs/genfs.h comp-c-include ./usr/include/miscfs/genfs/genfs_node.h comp-c-include ./usr/include/miscfs/genfs/layer.h comp-c-include @@ -4338,6 +4339,8 @@ ./usr/lib/librumpfs_fdesc_p.a comp-c-proflib rump,profile ./usr/lib/librumpfs_ffs.a comp-c-lib rump ./usr/lib/librumpfs_ffs_p.a comp-c-proflib rump,profile +./usr/lib/librumpfs_full.a comp-c-lib rump,fullfs +./usr/lib/librumpfs_full_p.a comp-c-proflib rump,fullfs,profile ./usr/lib/librumpfs_hfs.a comp-c-lib rump ./usr/lib/librumpfs_hfs_p.a comp-c-proflib rump,profile ./usr/lib/librumpfs_kernfs.a comp-c-lib rump diff --git a/distrib/sets/lists/debug/mi b/distrib/sets/lists/debug/mi index 4f4a5d45c89e3..69b49c5df5c23 100644 --- a/distrib/sets/lists/debug/mi +++ b/distrib/sets/lists/debug/mi @@ -391,6 +391,7 @@ ./usr/libdata/debug/sbin/mount_fdesc.debug comp-miscfs-debug fdescfs,debug ./usr/libdata/debug/sbin/mount_ffs.debug comp-sysutil-debug debug ./usr/libdata/debug/sbin/mount_filecore.debug comp-filecorefs-debug filecorefs,debug +./usr/libdata/debug/sbin/mount_full.debug comp-miscfs-debug fullfs,debug ./usr/libdata/debug/sbin/mount_hfs.debug comp-hfs-debug hfs,debug ./usr/libdata/debug/sbin/mount_kernfs.debug comp-sysutil-debug kernfs,debug ./usr/libdata/debug/sbin/mount_lfs.debug comp-sysutil-debug lfs,debug @@ -1714,6 +1715,7 @@ ./usr/libdata/debug/usr/tests/fs/ffs/t_snapshot_v2.debug tests-fs-debug debug,atf,rump ./usr/libdata/debug/usr/tests/fs/ffs/t_update_log.debug tests-fs-debug debug,atf,rump ./usr/libdata/debug/usr/tests/fs/fifofs/t_fifo.debug tests-fs-debug debug,atf,rump +./usr/libdata/debug/usr/tests/fs/fullfs/t_basic.debug tests-fs-debug fullfs,debug,atf,rump ./usr/libdata/debug/usr/tests/fs/hfs/t_pathconvert.debug tests-fs-debug hfs,debug,atf,rump ./usr/libdata/debug/usr/tests/fs/kernfs/t_basic.debug tests-fs-debug kernfs,debug,atf,rump ./usr/libdata/debug/usr/tests/fs/lfs/t_basic.debug tests-fs-debug lfs,debug,atf,rump diff --git a/distrib/sets/lists/debug/module.mi b/distrib/sets/lists/debug/module.mi index 7669d22f21403..d87d2bf13eaa5 100644 --- a/distrib/sets/lists/debug/module.mi +++ b/distrib/sets/lists/debug/module.mi @@ -163,6 +163,8 @@ ./usr/libdata/debug/@MODULEDIR@/flash/flash.kmod.debug modules-base-kernel kmod,debug ./usr/libdata/debug/@MODULEDIR@/fss modules-base-kernel kmod,debug ./usr/libdata/debug/@MODULEDIR@/fss/fss.kmod.debug modules-base-kernel kmod,debug +./usr/libdata/debug/@MODULEDIR@/full modules-base-kernel kmod,debug +./usr/libdata/debug/@MODULEDIR@/full/full.kmod.debug modules-base-kernel kmod,debug ./usr/libdata/debug/@MODULEDIR@/gpio modules-base-kernel kmod,debug ./usr/libdata/debug/@MODULEDIR@/gpio/gpio.kmod.debug modules-base-kernel kmod,debug ./usr/libdata/debug/@MODULEDIR@/gpioiic modules-base-kernel kmod,debug diff --git a/distrib/sets/lists/man/mi b/distrib/sets/lists/man/mi index 593bd2130c8b9..70e39302435fe 100644 --- a/distrib/sets/lists/man/mi +++ b/distrib/sets/lists/man/mi @@ -3100,6 +3100,7 @@ ./usr/share/man/cat8/mount_fdesc.0 man-miscfs-catman fdescfs,.cat ./usr/share/man/cat8/mount_ffs.0 man-sysutil-catman .cat ./usr/share/man/cat8/mount_filecore.0 man-filecorefs-catman filecorefs,.cat +./usr/share/man/cat8/mount_full.0 man-miscfs-catman fullfs,.cat ./usr/share/man/cat8/mount_hfs.0 man-hfs-catman hfs,.cat ./usr/share/man/cat8/mount_hfsp.0 man-obsolete obsolete ./usr/share/man/cat8/mount_kernfs.0 man-sysutil-catman kernfs,.cat @@ -6693,6 +6694,7 @@ ./usr/share/man/man8/mount_fdesc.8 man-miscfs-man fdescfs,.man ./usr/share/man/man8/mount_ffs.8 man-sysutil-man .man ./usr/share/man/man8/mount_filecore.8 man-filecorefs-man filecorefs,.man +./usr/share/man/man8/mount_full.8 man-miscfs-man fullfs,.man ./usr/share/man/man8/mount_hfs.8 man-hfs-man hfs,.man ./usr/share/man/man8/mount_hfsp.8 man-obsolete obsolete ./usr/share/man/man8/mount_kernfs.8 man-sysutil-man kernfs,.man diff --git a/distrib/sets/lists/manhtml/mi b/distrib/sets/lists/manhtml/mi index 03ab42791f01a..4c30d403c0c69 100644 --- a/distrib/sets/lists/manhtml/mi +++ b/distrib/sets/lists/manhtml/mi @@ -2776,6 +2776,7 @@ ./usr/share/man/html8/mount_fdesc.html man-miscfs-htmlman fdescfs,html ./usr/share/man/html8/mount_ffs.html man-sysutil-htmlman html ./usr/share/man/html8/mount_filecore.html man-filecorefs-htmlman filecorefs,html +./usr/share/man/html8/mount_full.html man-miscfs-htmlman fullfs,html ./usr/share/man/html8/mount_hfs.html man-hfs-htmlman hfs,html ./usr/share/man/html8/mount_kernfs.html man-sysutil-htmlman kernfs,html ./usr/share/man/html8/mount_lfs.html man-sysutil-htmlman lfs,html diff --git a/distrib/sets/lists/modules/mi b/distrib/sets/lists/modules/mi index 115be941ef341..086662f215413 100644 --- a/distrib/sets/lists/modules/mi +++ b/distrib/sets/lists/modules/mi @@ -185,6 +185,8 @@ ./@MODULEDIR@/flash/flash.kmod modules-base-kernel kmod ./@MODULEDIR@/fss modules-base-kernel kmod ./@MODULEDIR@/fss/fss.kmod modules-base-kernel kmod +./@MODULEDIR@/full modules-base-kernel kmod +./@MODULEDIR@/full/full.kmod modules-base-kernel kmod ./@MODULEDIR@/gpio modules-base-kernel kmod ./@MODULEDIR@/gpio/gpio.kmod modules-base-kernel kmod ./@MODULEDIR@/gpioiic modules-base-kernel kmod diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 2a1330673182f..16d98817700a5 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -37,6 +37,7 @@ ./usr/libdata/debug/usr/tests/fs/cd9660 tests-fs-debug compattestfile,atf ./usr/libdata/debug/usr/tests/fs/ffs tests-fs-debug compattestfile,atf ./usr/libdata/debug/usr/tests/fs/fifofs tests-fs-debug compattestfile,atf +./usr/libdata/debug/usr/tests/fs/fullfs tests-fs-debug compattestfile,atf ./usr/libdata/debug/usr/tests/fs/hfs tests-fs-debug compattestfile,atf ./usr/libdata/debug/usr/tests/fs/kernfs tests-fs-debug compattestfile,atf ./usr/libdata/debug/usr/tests/fs/lfs tests-fs-debug compattestfile,atf @@ -1682,6 +1683,10 @@ ./usr/tests/fs/fifofs/Atffile tests-fs-tests atf,rump ./usr/tests/fs/fifofs/Kyuafile tests-fs-tests atf,rump,kyua ./usr/tests/fs/fifofs/t_fifo tests-fs-tests atf,rump +./usr/tests/fs/fullfs tests-fs-tests compattestfile,atf +./usr/tests/fs/fullfs/Atffile tests-fs-tests atf,rump +./usr/tests/fs/fullfs/Kyuafile tests-fs-tests atf,rump,kyua +./usr/tests/fs/fullfs/t_basic tests-fs-tests atf,rump ./usr/tests/fs/h_funcs.subr tests-fs-tests atf,rump ./usr/tests/fs/hfs tests-fs-tests compattestfile,atf ./usr/tests/fs/hfs/Atffile tests-fs-tests atf,rump diff --git a/etc/mtree/NetBSD.dist.tests b/etc/mtree/NetBSD.dist.tests index 919e17cb978b3..40f7c826fd4ea 100644 --- a/etc/mtree/NetBSD.dist.tests +++ b/etc/mtree/NetBSD.dist.tests @@ -29,6 +29,7 @@ ./usr/libdata/debug/usr/tests/fs/cd9660 ./usr/libdata/debug/usr/tests/fs/ffs ./usr/libdata/debug/usr/tests/fs/fifofs +./usr/libdata/debug/usr/tests/fs/fullfs ./usr/libdata/debug/usr/tests/fs/hfs ./usr/libdata/debug/usr/tests/fs/kernfs ./usr/libdata/debug/usr/tests/fs/lfs @@ -235,6 +236,7 @@ ./usr/tests/fs/cd9660 ./usr/tests/fs/ffs ./usr/tests/fs/fifofs +./usr/tests/fs/fullfs ./usr/tests/fs/hfs ./usr/tests/fs/kernfs ./usr/tests/fs/lfs diff --git a/sbin/Makefile b/sbin/Makefile index 7a5c776841e06..8ad2bbb96ee27 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -92,6 +92,10 @@ SUBDIR+= mount_ntfs SUBDIR+= mount_null .endif +.if (${MKFULLFS} != "no") +SUBDIR+= mount_full +.endif + .if (${MKOVERLAYFS} != "no") SUBDIR+= mount_overlay .endif diff --git a/sbin/mount_full/Makefile b/sbin/mount_full/Makefile new file mode 100644 index 0000000000000..978e0ddf6999d --- /dev/null +++ b/sbin/mount_full/Makefile @@ -0,0 +1,16 @@ +# $NetBSD$ + +.include + +PROG= mount_full +SRCS= mount_full.c pathadj.c +MAN= mount_full.8 + +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + +DPADD+=${LIBUTIL} +LDADD+=-lutil + +.include diff --git a/sbin/mount_full/mount_full.8 b/sbin/mount_full/mount_full.8 new file mode 100644 index 0000000000000..81f29b86b2305 --- /dev/null +++ b/sbin/mount_full/mount_full.8 @@ -0,0 +1,151 @@ +.\" $NetBSD$ +.\" +.\" Copyright (c) 1992, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software donated to Berkeley by +.\" Jan-Simon Pendry. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd March 6, 2026 +.Dt MOUNT_FULL 8 +.Os +.Sh NAME +.Nm mount_full +.Nd mount a disk-full simulation filesystem layer +.Sh SYNOPSIS +.Nm +.Op Fl o Ar options +.Ar target +.Ar mount-point +.Sh DESCRIPTION +The +.Nm +command mounts a +.Em fullfs +layer over +.Ar target , +making it accessible at +.Ar mount-point . +.Pp +.Em fullfs +is a stackable filesystem layer built on the same layerfs infrastructure as +.Xr mount_null 8 . +It presents the contents of +.Ar target +unchanged, but intercepts any vnode operation that would allocate disk space +and returns +.Er ENOSPC +immediately, without touching the underlying filesystem. +.Pp +This makes it possible to test an application's handling of disk-full +conditions without filling an actual disk. +.Pp +Both +.Ar target +and +.Ar mount-point +are converted to absolute paths before use. +.Sh BEHAVIOR +The following operations always fail with +.Er ENOSPC +through a fullfs mount: +.Bl -bullet -compact +.It +.Xr write 2 +.It +.Xr open 2 +with +.Dv O_CREAT +(new file creation) +.It +.Xr mkdir 2 +.It +.Xr mknod 2 +.It +.Xr symlink 2 +.It +.Xr link 2 +.El +.Pp +The following operations pass through to the underlying filesystem unchanged: +.Bl -bullet -compact +.It +.Xr read 2 , +.Xr readdir 2 , +.Xr stat 2 , +and other read-only operations +.It +.Xr unlink 2 +and +.Xr rmdir 2 +(these free space rather than allocating it) +.It +.Xr rename 2 +.El +.Pp +.Xr statvfs 2 +reports zero free and available blocks and inodes, regardless of the +actual state of the underlying filesystem. +.Sh OPTIONS +.Bl -tag -width Fl +.It Fl o +Options are specified with a +.Fl o +flag followed by a comma-separated string of options. +See the +.Xr mount 8 +man page for possible options and their meanings. +.El +.Sh EXAMPLES +Mount +.Pa /var/db +under +.Pa /mnt/full +to test how a program behaves when the database volume is full: +.Pp +.Dl mount_full /var/db /mnt/full +.Pp +Verify that the layer is working correctly: +.Bd -literal -offset indent +# Existing data is still readable: +ls /mnt/full + +# Writes fail immediately: +echo hello >> /mnt/full/somefile +echo $? # non-zero; "No space left on device" + +# Free space is reported as zero: +df /mnt/full +.Ed +.Sh SEE ALSO +.Xr mount 8 , +.Xr mount_null 8 +.Sh HISTORY +The +.Nm +utility first appeared in +.Nx 11 . diff --git a/sbin/mount_full/mount_full.c b/sbin/mount_full/mount_full.c new file mode 100644 index 0000000000000..a3a851a28c2e8 --- /dev/null +++ b/sbin/mount_full/mount_full.c @@ -0,0 +1,127 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1992, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software donated to Berkeley by + * Jan-Simon Pendry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ + The Regents of the University of California. All rights reserved."); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)mount_full.c 8.6 (Berkeley) 4/26/95"; +#else +__RCSID("$NetBSD$"); +#endif +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "mountprog.h" + +static const struct mntopt mopts[] = { + MOPT_STDOPTS, + MOPT_GETARGS, + MOPT_NULL, +}; + +int mount_full(int argc, char **argv); +__dead static void usage(void); + +#ifndef MOUNT_NOMAIN +int +main(int argc, char **argv) +{ + return mount_full(argc, argv); +} +#endif + +int +mount_full(int argc, char *argv[]) +{ + struct full_args args; + int ch, mntflags; + char target[MAXPATHLEN], canon_dir[MAXPATHLEN]; + mntoptparse_t mp; + + mntflags = 0; + while ((ch = getopt(argc, argv, "o:")) != -1) + switch(ch) { + case 'o': + mp = getmntopts(optarg, mopts, &mntflags, 0); + if (mp == NULL) + err(1, "getmntopts"); + freemntopts(mp); + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 2) + usage(); + + pathadj(argv[0], target); + pathadj(argv[1], canon_dir); + + if (strcmp(target, canon_dir) == 0) + errx(1, "%s (%s) and %s (%s) are identical paths", + argv[0], target, argv[1], canon_dir); + + args.la.target = target; + + if (mount(MOUNT_FULL, canon_dir, mntflags, &args, sizeof args) == -1) + err(1, "%s on %s", target, canon_dir); + exit(0); +} + +static void +usage(void) +{ + (void)fprintf(stderr, + "usage: mount_full [-o options] target_fs mount_point\n"); + exit(1); +} diff --git a/share/man/man5/mk.conf.5 b/share/man/man5/mk.conf.5 index a58b9435f0a4d..07d7439197c5c 100644 --- a/share/man/man5/mk.conf.5 +++ b/share/man/man5/mk.conf.5 @@ -1024,6 +1024,17 @@ and .Dq no on other platforms. . +.It Sy MKFULLFS +.YorN +Indicates whether support for the FULLFS disk-full +simulation file system will be built and installed. +.DFLT +.Dq no +on +.Sy m68000 ; +.Dq yes +on other platforms. +. .It Sy MKGCC .YorN Indicates whether diff --git a/share/mk/bsd.README b/share/mk/bsd.README index d30029a26d1af..dcc074de99fb3 100644 --- a/share/mk/bsd.README +++ b/share/mk/bsd.README @@ -117,7 +117,7 @@ The supported mk.conf(5) make variables are: MKCOMPATMODULES, MKCOMPATTESTS, MKCOMPATX11, MKCOMPLEX, MKCROSSGDB, MKCTF, MKCVS, MKCXX, MKDEBUG, MKDEBUGKERNEL, MKDEBUGLIB, MKDEBUGTOOLS, MKDEPINCLUDES, MKDOC, MKDTB, MKDTC, MKDTRACE, MKDYNAMICROOT, MKEFS, - MKEXT2FS, MKFDESCFS, MKFIDO2, MKFILECOREFS, MKFIRMWARE, MKGCC, + MKEXT2FS, MKFDESCFS, MKFIDO2, MKFILECOREFS, MKFIRMWARE, MKFULLFS, MKGCC, MKGCCCMDS, MKGDB, MKGROFF, MKGROFFHTMLDOC, MKHESIOD, MKHFS, MKKERNFS, MKHOSTOBJ, MKHTML, MKIEEEFP, MKINET6, MKINFO, MKIPFILTER, MKIPSEC, MKISCSI, MKKERBEROS, MKKMOD, MKKYUA, MKLDAP, MKLFS, MKLIBCSANITIZER, diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index a0c243e4cd62a..27e2fb676dd69 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -1305,6 +1305,7 @@ _MKVARS.yes= \ MKFDESCFS \ MKFIDO2 \ MKFILECOREFS \ + MKFULLFS \ MKGCC \ MKGDB \ MKGROFF \ @@ -1383,6 +1384,7 @@ MKEXT2FS.m68000?= no MKFDESCFS.m68000?= no MKFIDO2.m68000?= no MKFILECOREFS.m68000?= no +MKFULLFS.m68000?= no MKGROFF.m68000?= no MKHESIOD.m68000?= no MKHFS.m68000?= no diff --git a/sys/conf/files b/sys/conf/files index 9e8bd63e28efd..d0712df3b37b7 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1586,6 +1586,7 @@ include "fs/autofs/files.autofs" include "miscfs/fdesc/files.fdesc" include "miscfs/kernfs/files.kernfs" include "miscfs/nullfs/files.nullfs" +include "miscfs/fullfs/files.fullfs" include "miscfs/overlay/files.overlay" include "miscfs/procfs/files.procfs" include "miscfs/umapfs/files.umapfs" diff --git a/sys/miscfs/Makefile b/sys/miscfs/Makefile index 9ba12575c96c2..61f6c9ff3f084 100644 --- a/sys/miscfs/Makefile +++ b/sys/miscfs/Makefile @@ -1,6 +1,6 @@ # $NetBSD: Makefile,v 1.10 2015/05/06 15:57:08 hannken Exp $ -SUBDIR= fdesc fifofs genfs kernfs nullfs overlay procfs specfs umapfs +SUBDIR= fdesc fifofs fullfs genfs kernfs nullfs overlay procfs specfs umapfs INCSDIR= /usr/include/miscfs diff --git a/sys/miscfs/fullfs/Makefile b/sys/miscfs/fullfs/Makefile new file mode 100644 index 0000000000000..f2f65ec0b3e2b --- /dev/null +++ b/sys/miscfs/fullfs/Makefile @@ -0,0 +1,7 @@ +# $NetBSD$ + +INCSDIR= /usr/include/miscfs/fullfs + +INCS= full.h + +.include diff --git a/sys/miscfs/fullfs/files.fullfs b/sys/miscfs/fullfs/files.fullfs new file mode 100644 index 0000000000000..68c2036fb7310 --- /dev/null +++ b/sys/miscfs/fullfs/files.fullfs @@ -0,0 +1,7 @@ +# $NetBSD$ + +deffs FULLFS + +define fullfs: vfs, layerfs +file miscfs/fullfs/full_vfsops.c fullfs +file miscfs/fullfs/full_vnops.c fullfs diff --git a/sys/miscfs/fullfs/full.h b/sys/miscfs/fullfs/full.h new file mode 100644 index 0000000000000..99a7019cf2407 --- /dev/null +++ b/sys/miscfs/fullfs/full.h @@ -0,0 +1,115 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1999 National Aeronautics & Space Administration + * All rights reserved. + * + * This software was written by William Studenmund of the + * Numerical Aerospace Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the National Aeronautics & Space Administration + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- + * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software donated to Berkeley by + * Jan-Simon Pendry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Id: lofs.h,v 1.8 1992/05/30 10:05:43 jsp Exp + * @(#)null.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _MISCFS_FULLFS_H_ +#define _MISCFS_FULLFS_H_ + +#include + +struct full_args { + struct layer_args la; /* generic layerfs args */ +}; +#define fulla_target la.target +#define fulla_export la.export + +#ifdef _KERNEL +struct full_mount { + struct layer_mount lm; /* generic layerfs mount stuff */ +}; +#define fullm_rootvp lm.layerm_rootvp +#define fullm_export lm.layerm_export +#define fullm_flags lm.layerm_flags +#define fullm_size lm.layerm_size +#define fullm_tag lm.layerm_tag +#define fullm_bypass lm.layerm_bypass +#define fullm_alloc lm.layerm_alloc +#define fullm_vnodeop_p lm.layerm_vnodeop_p +#define fullm_node_hashtbl lm.layerm_node_hashtbl +#define fullm_node_hash lm.layerm_node_hash +#define fullm_hashlock lm.layerm_hashlock + +/* + * A cache of vnode references + */ +struct full_node { + struct layer_node ln; +}; +#define full_hash ln.layer_hash +#define full_lowervp ln.layer_lowervp +#define full_vnode ln.layer_vnode +#define full_flags ln.layer_flags + +#define MOUNTTOFULLMOUNT(mp) ((struct full_mount *)((mp)->mnt_data)) + +extern int (**full_vnodeop_p)(void *); +extern struct vfsops fullfs_vfsops; + +#endif /* _KERNEL */ +#endif /* _MISCFS_FULLFS_H_ */ diff --git a/sys/miscfs/fullfs/full_vfsops.c b/sys/miscfs/fullfs/full_vfsops.c new file mode 100644 index 0000000000000..153565ff7bda1 --- /dev/null +++ b/sys/miscfs/fullfs/full_vfsops.c @@ -0,0 +1,285 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1999 National Aeronautics & Space Administration + * All rights reserved. + * + * This software was written by William Studenmund of the + * Numerical Aerospace Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the National Aeronautics & Space Administration + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- + * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993, 1995 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software donated to Berkeley by + * Jan-Simon Pendry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp + * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92 + * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95 + */ + +/* + * Full file-system: VFS operations. + * + * See full_vnops.c for a description. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include + +MODULE(MODULE_CLASS_VFS, full, "layerfs"); + +VFS_PROTOS(fullfs); + +int +fullfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) +{ + struct vnode *lowerrootvp, *vp; + struct full_args *args = data; + struct full_mount *nmp; + struct layer_mount *lmp; + struct pathbuf *pb; + struct nameidata nd; + int error; + + if (args == NULL) + return EINVAL; + if (*data_len < sizeof(*args)) + return EINVAL; + + if (mp->mnt_flag & MNT_GETARGS) { + lmp = MOUNTTOLAYERMOUNT(mp); + if (lmp == NULL) + return EIO; + args->la.target = NULL; + *data_len = sizeof(*args); + return 0; + } + + /* Update is not supported. */ + if (mp->mnt_flag & MNT_UPDATE) + return EOPNOTSUPP; + + /* Find the lower vnode and lock it. */ + error = pathbuf_copyin(args->la.target, &pb); + if (error) { + return error; + } + NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb); + if ((error = namei(&nd)) != 0) { + pathbuf_destroy(pb); + return error; + } + lowerrootvp = nd.ni_vp; + pathbuf_destroy(pb); + + /* Create the mount point. */ + nmp = kmem_zalloc(sizeof(struct full_mount), KM_SLEEP); + mp->mnt_data = nmp; + mp->mnt_iflag |= lowerrootvp->v_mount->mnt_iflag & IMNT_MPSAFE; + mp->mnt_iflag |= lowerrootvp->v_mount->mnt_iflag & IMNT_SHRLOOKUP; + + /* + * Make sure that the mount point is sufficiently initialized + * that the node create call will work. + */ + vfs_getnewfsid(mp); + error = vfs_set_lowermount(mp, lowerrootvp->v_mount); + if (error) { + vput(lowerrootvp); + kmem_free(nmp, sizeof(struct full_mount)); + return error; + } + + nmp->fullm_size = sizeof(struct full_node); + nmp->fullm_tag = VT_FULL; + nmp->fullm_bypass = layer_bypass; + nmp->fullm_vnodeop_p = full_vnodeop_p; + + /* Setup a full node for root vnode. */ + VOP_UNLOCK(lowerrootvp); + error = layer_node_create(mp, lowerrootvp, &vp); + if (error) { + vrele(lowerrootvp); + kmem_free(nmp, sizeof(struct full_mount)); + return error; + } + /* + * Keep a held reference to the root vnode. It will be released on + * umount. Note: fullfs is MP-safe. + */ + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + vp->v_vflag |= VV_ROOT; + nmp->fullm_rootvp = vp; + VOP_UNLOCK(vp); + + error = set_statvfs_info(path, UIO_USERSPACE, args->la.target, + UIO_USERSPACE, mp->mnt_op->vfs_name, mp, curlwp); + if (error) + return error; + + if (mp->mnt_lower->mnt_flag & MNT_LOCAL) + mp->mnt_flag |= MNT_LOCAL; + return 0; +} + +int +fullfs_unmount(struct mount *mp, int mntflags) +{ + struct full_mount *nmp = MOUNTTOFULLMOUNT(mp); + struct vnode *full_rootvp = nmp->fullm_rootvp; + int error, flags = 0; + + if (mntflags & MNT_FORCE) + flags |= FORCECLOSE; + + if (vrefcnt(full_rootvp) > 1 && (mntflags & MNT_FORCE) == 0) + return EBUSY; + + if ((error = vflush(mp, full_rootvp, flags)) != 0) + return error; + + /* Eliminate all activity and release the vnode. */ + vgone(full_rootvp); + + /* Finally, destroy the mount point structures. */ + kmem_free(mp->mnt_data, sizeof(struct full_mount)); + mp->mnt_data = NULL; + return 0; +} + +int +fullfs_statvfs(struct mount *mp, struct statvfs *sbp) +{ + int error; + + error = layerfs_statvfs(mp, sbp); + if (error) + return error; + + /* A full filesystem has no free space. */ + sbp->f_bfree = 0; + sbp->f_bavail = 0; + sbp->f_bresvd = 0; + sbp->f_ffree = 0; + sbp->f_favail = 0; + sbp->f_fresvd = 0; + + return 0; +} + +extern const struct vnodeopv_desc full_vnodeop_opv_desc; + +const struct vnodeopv_desc * const fullfs_vnodeopv_descs[] = { + &full_vnodeop_opv_desc, + NULL, +}; + +struct vfsops fullfs_vfsops = { + .vfs_name = MOUNT_FULL, + .vfs_min_mount_data = sizeof (struct full_args), + .vfs_mount = fullfs_mount, + .vfs_start = layerfs_start, + .vfs_unmount = fullfs_unmount, + .vfs_root = layerfs_root, + .vfs_quotactl = layerfs_quotactl, + .vfs_statvfs = fullfs_statvfs, + .vfs_sync = layerfs_sync, + .vfs_loadvnode = layerfs_loadvnode, + .vfs_vget = layerfs_vget, + .vfs_fhtovp = layerfs_fhtovp, + .vfs_vptofh = layerfs_vptofh, + .vfs_init = layerfs_init, + .vfs_done = layerfs_done, + .vfs_snapshot = layerfs_snapshot, + .vfs_extattrctl = vfs_stdextattrctl, + .vfs_suspendctl = layerfs_suspendctl, + .vfs_renamelock_enter = layerfs_renamelock_enter, + .vfs_renamelock_exit = layerfs_renamelock_exit, + .vfs_fsync = (void *)eopnotsupp, + .vfs_opv_descs = fullfs_vnodeopv_descs +}; + +static int +full_modcmd(modcmd_t cmd, void *arg) +{ + int error; + + switch (cmd) { + case MODULE_CMD_INIT: + error = vfs_attach(&fullfs_vfsops); + if (error != 0) + break; + break; + case MODULE_CMD_FINI: + error = vfs_detach(&fullfs_vfsops); + if (error != 0) + break; + break; + default: + error = ENOTTY; + break; + } + return error; +} diff --git a/sys/miscfs/fullfs/full_vnops.c b/sys/miscfs/fullfs/full_vnops.c new file mode 100644 index 0000000000000..494f004cf8aa5 --- /dev/null +++ b/sys/miscfs/fullfs/full_vnops.c @@ -0,0 +1,143 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1999 National Aeronautics & Space Administration + * All rights reserved. + * + * This software was written by William Studenmund of the + * Numerical Aerospace Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the National Aeronautics & Space Administration + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- + * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * John Heidemann of the UCLA Ficus project. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)null_vnops.c 8.6 (Berkeley) 5/27/95 + * + * Ancestors: + * @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92 + * Id: lofs_vnops.c,v 1.11 1992/05/30 10:05:43 jsp Exp jsp + * ...and... + * @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project + */ + +/* + * Full file-system. + * + * Implemented using layerfs, see layer_vnops.c for a description. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include +#include +#include + +#include +#include +#include + +static int +fullfs_enospc(void *v __unused) +{ + return ENOSPC; +} + +/* + * Global VFS data structures. + */ + +int (**full_vnodeop_p)(void *); + +const struct vnodeopv_entry_desc full_vnodeop_entries[] = { + /* same as nullfs */ + { &vop_default_desc, layer_bypass }, + + { &vop_lookup_desc, layer_lookup }, + { &vop_setattr_desc, layer_setattr }, + { &vop_getattr_desc, layer_getattr }, + { &vop_access_desc, layer_access }, + { &vop_accessx_desc, genfs_accessx }, + { &vop_fsync_desc, layer_fsync }, + { &vop_inactive_desc, layer_inactive }, + { &vop_reclaim_desc, layer_reclaim }, + { &vop_print_desc, layer_print }, + { &vop_remove_desc, layer_remove }, + { &vop_rename_desc, layer_rename }, + { &vop_revoke_desc, layer_revoke }, + { &vop_rmdir_desc, layer_rmdir }, + + { &vop_open_desc, layer_open }, + { &vop_close_desc, layer_close }, + + { &vop_bmap_desc, layer_bmap }, + { &vop_getpages_desc, layer_getpages }, + { &vop_putpages_desc, layer_putpages }, + + /* fails with ENOSPC */ + { &vop_write_desc, fullfs_enospc }, + { &vop_create_desc, fullfs_enospc }, + { &vop_mkdir_desc, fullfs_enospc }, + { &vop_mknod_desc, fullfs_enospc }, + { &vop_symlink_desc, fullfs_enospc }, + { &vop_link_desc, fullfs_enospc }, + + { NULL, NULL } +}; + +const struct vnodeopv_desc full_vnodeop_opv_desc = { + &full_vnodeop_p, full_vnodeop_entries +}; diff --git a/sys/modules/Makefile b/sys/modules/Makefile index e6ae6c48c97e8..c746d5d2e8114 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -71,6 +71,7 @@ SUBDIR+= ffs SUBDIR+= filecore SUBDIR+= flash SUBDIR+= fss +SUBDIR+= full SUBDIR+= gpio SUBDIR+= gpioiic SUBDIR+= gpioow diff --git a/sys/modules/full/Makefile b/sys/modules/full/Makefile new file mode 100644 index 0000000000000..77abfcf9ab4fd --- /dev/null +++ b/sys/modules/full/Makefile @@ -0,0 +1,12 @@ +# $NetBSD$ + +.include "../Makefile.inc" + +.PATH: ${S}/miscfs/fullfs ${S}/miscfs/genfs + +KMOD= full +SRCS= full_vfsops.c full_vnops.c + +CWARNFLAGS.clang= -Wno-conversion + +.include diff --git a/sys/rump/fs/Makefile.rumpfscomp b/sys/rump/fs/Makefile.rumpfscomp index a455c533a10f1..9370420087461 100644 --- a/sys/rump/fs/Makefile.rumpfscomp +++ b/sys/rump/fs/Makefile.rumpfscomp @@ -3,8 +3,8 @@ .include -RUMPFSCOMP= cd9660 efs ext2fs fdesc ffs hfs kernfs lfs mfs msdos \ - nfs nilfs ntfs null ptyfs syspuffs sysvbfs \ +RUMPFSCOMP= cd9660 efs ext2fs fdesc ffs full hfs kernfs lfs mfs \ + msdos nfs nilfs ntfs null ptyfs syspuffs sysvbfs \ tmpfs udf umap union v7fs .if ${MKZFS} != "no" || make(rumpdescribe) diff --git a/sys/rump/fs/lib/libfull/Makefile b/sys/rump/fs/lib/libfull/Makefile new file mode 100644 index 0000000000000..b4971f224799e --- /dev/null +++ b/sys/rump/fs/lib/libfull/Makefile @@ -0,0 +1,13 @@ +# $NetBSD$ + +.PATH: ${.CURDIR}/../../../../miscfs/fullfs + +LIB= rumpfs_full +COMMENT=Disk-full simulation file system + +SRCS= full_vfsops.c full_vnops.c + +CWARNFLAGS.clang+= -Wno-conversion + +.include +.include diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 1903fcd3c6979..caacc8cc882db 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -73,6 +73,7 @@ #define MOUNT_LFS "lfs" /* Log-based Filesystem */ #define MOUNT_FDESC "fdesc" /* File Descriptor Filesystem */ #define MOUNT_NULL "null" /* Minimal Filesystem Layer */ +#define MOUNT_FULL "full" /* Full Filesystem Layer */ #define MOUNT_OVERLAY "overlay" /* Minimal Overlay Filesystem Layer */ #define MOUNT_UMAP "umap" /* User/Group Identifier Remapping Filesystem */ #define MOUNT_KERNFS "kernfs" /* Kernel Information Filesystem */ diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index e0796d2cf6d07..1b046ce53d068 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -103,7 +103,7 @@ enum vtagtype { VT_AFS, VT_ISOFS, VT_UNION, VT_ADOSFS, VT_EXT2FS, VT_CODA, VT_FILECORE, VT_NTFS, VT_VFS, VT_OVERLAY, VT_SMBFS, VT_PTYFS, VT_TMPFS, VT_UDF, VT_SYSVBFS, VT_PUFFS, VT_HFS, VT_EFS, VT_ZFS, - VT_RUMP, VT_NILFS, VT_V7FS, VT_CHFS, VT_AUTOFS + VT_RUMP, VT_NILFS, VT_V7FS, VT_CHFS, VT_AUTOFS, VT_FULL }; #define VNODE_TAGS \ @@ -112,7 +112,7 @@ enum vtagtype { "VT_AFS", "VT_ISOFS", "VT_UNION", "VT_ADOSFS", "VT_EXT2FS", "VT_CODA", \ "VT_FILECORE", "VT_NTFS", "VT_VFS", "VT_OVERLAY", "VT_SMBFS", "VT_PTYFS", \ "VT_TMPFS", "VT_UDF", "VT_SYSVBFS", "VT_PUFFS", "VT_HFS", "VT_EFS", \ - "VT_ZFS", "VT_RUMP", "VT_NILFS", "VT_V7FS", "VT_CHFS", "VT_AUTOFS" + "VT_ZFS", "VT_RUMP", "VT_NILFS", "VT_V7FS", "VT_CHFS", "VT_AUTOFS", "VT_FULL" #if defined(_KERNEL) || defined(_KMEMUSER) struct vnode; diff --git a/tests/fs/Makefile b/tests/fs/Makefile index bb13b3496fc22..3cf0cc34d4549 100644 --- a/tests/fs/Makefile +++ b/tests/fs/Makefile @@ -13,6 +13,10 @@ TESTS_SUBDIRS+= vfs TESTS_SUBDIRS+= cd9660 .endif +.if ${MKFULLFS} != "no" +TESTS_SUBDIRS+= fullfs +.endif + .if ${MKHFS} != "no" TESTS_SUBDIRS+= hfs .endif diff --git a/tests/fs/fullfs/Makefile b/tests/fs/fullfs/Makefile new file mode 100644 index 0000000000000..91a76580ad32e --- /dev/null +++ b/tests/fs/fullfs/Makefile @@ -0,0 +1,13 @@ +# $NetBSD$ + +.include + +TESTSDIR= ${TESTSBASE}/fs/fullfs +WARNS= 4 + +TESTS_C= t_basic + +LDADD+= -lrumpfs_tmpfs -lrumpfs_full -lrumpvfs_layerfs # fs drivers +LDADD+= ${LIBRUMPBASE} # base + +.include diff --git a/tests/fs/fullfs/t_basic.c b/tests/fs/fullfs/t_basic.c new file mode 100644 index 0000000000000..7b1402175b78f --- /dev/null +++ b/tests/fs/fullfs/t_basic.c @@ -0,0 +1,203 @@ +/* $NetBSD$ */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "h_macros.h" + +#define MSTR "magic bus" + +static void +xput_tfile(const char *path, const char *mstr, size_t len) +{ + int fd; + + RL(fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777)); + ATF_REQUIRE_EQ_MSG((ssize_t)len, rump_sys_write(fd, mstr, len), + "write to testfile: %s", strerror(errno)); + RL(rump_sys_close(fd)); +} + +static int +xread_tfile(const char *path, const char *mstr, size_t len) +{ + char buf[128]; + int fd; + + fd = rump_sys_open(path, O_RDONLY); + if (fd == -1) + return errno; + RL(rump_sys_read(fd, buf, sizeof(buf))); + RL(rump_sys_close(fd)); + if (strncmp(buf, mstr, len) == 0) + return 0; + return EPROGMISMATCH; +} + +static void +mountfull(const char *what, const char *mp, int flags) +{ + struct full_args fargs; + + memset(&fargs, 0, sizeof(fargs)); + fargs.fulla_target = __UNCONST(what); + RL(rump_sys_mount(MOUNT_FULL, mp, flags, &fargs, sizeof(fargs))); +} + +static void +mounttmpfs(const char *mp) +{ + struct tmpfs_args targs; + + memset(&targs, 0, sizeof(targs)); + targs.ta_version = TMPFS_ARGS_VERSION; + targs.ta_root_mode = 0777; + RL(rump_sys_mount(MOUNT_TMPFS, mp, 0, &targs, sizeof(targs))); +} + +static void +setup_fullfs(void) +{ + rump_init(); + RL(rump_sys_mkdir("/td1", 0777)); + RL(rump_sys_mkdir("/td2", 0777)); + mounttmpfs("/td1"); + mountfull("/td1", "/td2", 0); +} + + +ATF_TC(read_succeeds); +ATF_TC_HEAD(read_succeeds, tc) +{ + atf_tc_set_md_var(tc, "descr", "read through fullfs succeeds"); +} +ATF_TC_BODY(read_succeeds, tc) +{ + setup_fullfs(); + + xput_tfile("/td1/testfile", MSTR, sizeof(MSTR)); + + ATF_REQUIRE_EQ(0, xread_tfile("/td2/testfile", MSTR, sizeof(MSTR))); +} + + +ATF_TC(write_fails); +ATF_TC_HEAD(write_fails, tc) +{ + atf_tc_set_md_var(tc, "descr", "write through fullfs fails with ENOSPC"); +} +ATF_TC_BODY(write_fails, tc) +{ + int fd; + + setup_fullfs(); + + xput_tfile("/td1/testfile", MSTR, sizeof(MSTR)); + + RL(fd = rump_sys_open("/td2/testfile", O_WRONLY)); + ATF_REQUIRE_EQ(-1, rump_sys_write(fd, MSTR, sizeof(MSTR))); + ATF_REQUIRE_EQ(ENOSPC, errno); +} + + +ATF_TC(create_fails); +ATF_TC_HEAD(create_fails, tc) +{ + atf_tc_set_md_var(tc, "descr", "create through fullfs fails with ENOSPC"); +} +ATF_TC_BODY(create_fails, tc) +{ + setup_fullfs(); + + ATF_REQUIRE_EQ(-1, rump_sys_open("/td2/testfile", O_CREAT | O_WRONLY, 0600)); + ATF_REQUIRE_EQ(ENOSPC, errno); +} + + +ATF_TC(mkdir_fails); +ATF_TC_HEAD(mkdir_fails, tc) +{ + atf_tc_set_md_var(tc, "descr", "mkdir through fullfs fails with ENOSPC"); +} +ATF_TC_BODY(mkdir_fails, tc) +{ + setup_fullfs(); + + ATF_REQUIRE_EQ(-1, rump_sys_mkdir("/td2/testdir", 0777)); + ATF_REQUIRE_EQ(ENOSPC, errno); +} + + +ATF_TC(symlink_fails); +ATF_TC_HEAD(symlink_fails, tc) +{ + atf_tc_set_md_var(tc, "descr", "symlink through fullfs fails with ENOSPC"); +} +ATF_TC_BODY(symlink_fails, tc) +{ + setup_fullfs(); + + ATF_REQUIRE_EQ(-1, rump_sys_symlink("anything", "/td2/link")); + ATF_REQUIRE_EQ(ENOSPC, errno); +} + + +ATF_TC(remove_succeeds); +ATF_TC_HEAD(remove_succeeds, tc) +{ + atf_tc_set_md_var(tc, "descr", "remove through fullfs succeeds"); +} +ATF_TC_BODY(remove_succeeds, tc) +{ + setup_fullfs(); + + xput_tfile("/td1/testfile", MSTR, sizeof(MSTR)); + ATF_REQUIRE_EQ(0, rump_sys_unlink("/td2/testfile")); + + ATF_REQUIRE_EQ(ENOENT, xread_tfile("/td1/testfile", NULL, 0)); +} + + +ATF_TC(statvfs_shows_full); +ATF_TC_HEAD(statvfs_shows_full, tc) +{ + atf_tc_set_md_var(tc, "descr", "statvfs through fullfs shows full"); +} +ATF_TC_BODY(statvfs_shows_full, tc) +{ + struct statvfs sb; + + setup_fullfs(); + + RL(rump_sys_statvfs1("/td2", &sb, ST_WAIT)); + ATF_REQUIRE_EQ(0, sb.f_bfree); + ATF_REQUIRE_EQ(0, sb.f_bavail); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, read_succeeds); + ATF_TP_ADD_TC(tp, write_fails); + ATF_TP_ADD_TC(tp, create_fails); + ATF_TP_ADD_TC(tp, mkdir_fails); + ATF_TP_ADD_TC(tp, symlink_fails); + ATF_TP_ADD_TC(tp, remove_succeeds); + ATF_TP_ADD_TC(tp, statvfs_shows_full); + return atf_no_error(); +}