Skip to content

Commit 7dbe099

Browse files
committed
miscfs/fullfs: add disk-full simulation layerfs based on miscfs/nullfs
1 parent fa6492c commit 7dbe099

28 files changed

Lines changed: 1130 additions & 5 deletions

File tree

distrib/sets/lists/base/mi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420
./sbin/mount_fdesc base-miscfs-root fdescfs
421421
./sbin/mount_ffs base-sysutil-root
422422
./sbin/mount_filecore base-filecorefs-root filecorefs
423+
./sbin/mount_full base-miscfs-root fullfs
423424
./sbin/mount_hfs base-hfs-root hfs
424425
./sbin/mount_hfsp base-obsolete obsolete
425426
./sbin/mount_kernfs base-sysutil-root kernfs

distrib/sets/lists/debug/mi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
./usr/libdata/debug/sbin/mount_fdesc.debug comp-miscfs-debug fdescfs,debug
392392
./usr/libdata/debug/sbin/mount_ffs.debug comp-sysutil-debug debug
393393
./usr/libdata/debug/sbin/mount_filecore.debug comp-filecorefs-debug filecorefs,debug
394+
./usr/libdata/debug/sbin/mount_full.debug comp-miscfs-debug fullfs,debug
394395
./usr/libdata/debug/sbin/mount_hfs.debug comp-hfs-debug hfs,debug
395396
./usr/libdata/debug/sbin/mount_kernfs.debug comp-sysutil-debug kernfs,debug
396397
./usr/libdata/debug/sbin/mount_lfs.debug comp-sysutil-debug lfs,debug

distrib/sets/lists/debug/module.mi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163
./usr/libdata/debug/@MODULEDIR@/flash/flash.kmod.debug modules-base-kernel kmod,debug
164164
./usr/libdata/debug/@MODULEDIR@/fss modules-base-kernel kmod,debug
165165
./usr/libdata/debug/@MODULEDIR@/fss/fss.kmod.debug modules-base-kernel kmod,debug
166+
./usr/libdata/debug/@MODULEDIR@/full modules-base-kernel kmod,debug
167+
./usr/libdata/debug/@MODULEDIR@/full/full.kmod.debug modules-base-kernel kmod,debug
166168
./usr/libdata/debug/@MODULEDIR@/gpio modules-base-kernel kmod,debug
167169
./usr/libdata/debug/@MODULEDIR@/gpio/gpio.kmod.debug modules-base-kernel kmod,debug
168170
./usr/libdata/debug/@MODULEDIR@/gpioiic modules-base-kernel kmod,debug

distrib/sets/lists/man/mi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,7 @@
31003100
./usr/share/man/cat8/mount_fdesc.0 man-miscfs-catman fdescfs,.cat
31013101
./usr/share/man/cat8/mount_ffs.0 man-sysutil-catman .cat
31023102
./usr/share/man/cat8/mount_filecore.0 man-filecorefs-catman filecorefs,.cat
3103+
./usr/share/man/cat8/mount_full.0 man-miscfs-catman fullfs,.cat
31033104
./usr/share/man/cat8/mount_hfs.0 man-hfs-catman hfs,.cat
31043105
./usr/share/man/cat8/mount_hfsp.0 man-obsolete obsolete
31053106
./usr/share/man/cat8/mount_kernfs.0 man-sysutil-catman kernfs,.cat
@@ -6693,6 +6694,7 @@
66936694
./usr/share/man/man8/mount_fdesc.8 man-miscfs-man fdescfs,.man
66946695
./usr/share/man/man8/mount_ffs.8 man-sysutil-man .man
66956696
./usr/share/man/man8/mount_filecore.8 man-filecorefs-man filecorefs,.man
6697+
./usr/share/man/man8/mount_full.8 man-miscfs-man fullfs,.man
66966698
./usr/share/man/man8/mount_hfs.8 man-hfs-man hfs,.man
66976699
./usr/share/man/man8/mount_hfsp.8 man-obsolete obsolete
66986700
./usr/share/man/man8/mount_kernfs.8 man-sysutil-man kernfs,.man

distrib/sets/lists/manhtml/mi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,6 +2776,7 @@
27762776
./usr/share/man/html8/mount_fdesc.html man-miscfs-htmlman fdescfs,html
27772777
./usr/share/man/html8/mount_ffs.html man-sysutil-htmlman html
27782778
./usr/share/man/html8/mount_filecore.html man-filecorefs-htmlman filecorefs,html
2779+
./usr/share/man/html8/mount_full.html man-miscfs-htmlman fullfs,html
27792780
./usr/share/man/html8/mount_hfs.html man-hfs-htmlman hfs,html
27802781
./usr/share/man/html8/mount_kernfs.html man-sysutil-htmlman kernfs,html
27812782
./usr/share/man/html8/mount_lfs.html man-sysutil-htmlman lfs,html

distrib/sets/lists/modules/mi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@
185185
./@MODULEDIR@/flash/flash.kmod modules-base-kernel kmod
186186
./@MODULEDIR@/fss modules-base-kernel kmod
187187
./@MODULEDIR@/fss/fss.kmod modules-base-kernel kmod
188+
./@MODULEDIR@/full modules-base-kernel kmod
189+
./@MODULEDIR@/full/full.kmod modules-base-kernel kmod
188190
./@MODULEDIR@/gpio modules-base-kernel kmod
189191
./@MODULEDIR@/gpio/gpio.kmod modules-base-kernel kmod
190192
./@MODULEDIR@/gpioiic modules-base-kernel kmod

sbin/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ SUBDIR+= mount_ntfs
9292
SUBDIR+= mount_null
9393
.endif
9494

95+
.if (${MKFULLFS} != "no")
96+
SUBDIR+= mount_full
97+
.endif
98+
9599
.if (${MKOVERLAYFS} != "no")
96100
SUBDIR+= mount_overlay
97101
.endif

sbin/mount_full/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# $NetBSD$
2+
3+
.include <bsd.own.mk>
4+
5+
PROG= mount_full
6+
SRCS= mount_full.c pathadj.c
7+
MAN= mount_full.8
8+
9+
MOUNT= ${NETBSDSRCDIR}/sbin/mount
10+
CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT}
11+
.PATH: ${MOUNT}
12+
13+
DPADD+=${LIBUTIL}
14+
LDADD+=-lutil
15+
16+
.include <bsd.prog.mk>

sbin/mount_full/mount_full.8

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
.\" $NetBSD$
2+
.\"
3+
.\" Copyright (c) 1992, 1993, 1994
4+
.\" The Regents of the University of California. All rights reserved.
5+
.\"
6+
.\" This code is derived from software donated to Berkeley by
7+
.\" Jan-Simon Pendry.
8+
.\"
9+
.\" Redistribution and use in source and binary forms, with or without
10+
.\" modification, are permitted provided that the following conditions
11+
.\" are met:
12+
.\" 1. Redistributions of source code must retain the above copyright
13+
.\" notice, this list of conditions and the following disclaimer.
14+
.\" 2. Redistributions in binary form must reproduce the above copyright
15+
.\" notice, this list of conditions and the following disclaimer in the
16+
.\" documentation and/or other materials provided with the distribution.
17+
.\" 3. Neither the name of the University nor the names of its contributors
18+
.\" may be used to endorse or promote products derived from this software
19+
.\" without specific prior written permission.
20+
.\"
21+
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22+
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25+
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27+
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30+
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31+
.\" SUCH DAMAGE.
32+
.\"
33+
.Dd March 6, 2026
34+
.Dt MOUNT_FULL 8
35+
.Os
36+
.Sh NAME
37+
.Nm mount_full
38+
.Nd mount a disk-full simulation filesystem layer
39+
.Sh SYNOPSIS
40+
.Nm
41+
.Op Fl o Ar options
42+
.Ar target
43+
.Ar mount-point
44+
.Sh DESCRIPTION
45+
The
46+
.Nm
47+
command mounts a
48+
.Em fullfs
49+
layer over
50+
.Ar target ,
51+
making it accessible at
52+
.Ar mount-point .
53+
.Pp
54+
.Em fullfs
55+
is a stackable filesystem layer built on the same layerfs infrastructure as
56+
.Xr mount_null 8 .
57+
It presents the contents of
58+
.Ar target
59+
unchanged, but intercepts any vnode operation that would allocate disk space
60+
and returns
61+
.Er ENOSPC
62+
immediately, without touching the underlying filesystem.
63+
.Pp
64+
This makes it possible to test an application's handling of disk-full
65+
conditions without filling an actual disk.
66+
.Pp
67+
Both
68+
.Ar target
69+
and
70+
.Ar mount-point
71+
are converted to absolute paths before use.
72+
.Sh BEHAVIOR
73+
The following operations always fail with
74+
.Er ENOSPC
75+
through a fullfs mount:
76+
.Bl -bullet -compact
77+
.It
78+
.Xr write 2
79+
.It
80+
.Xr open 2
81+
with
82+
.Dv O_CREAT
83+
(new file creation)
84+
.It
85+
.Xr mkdir 2
86+
.It
87+
.Xr mknod 2
88+
.It
89+
.Xr symlink 2
90+
.It
91+
.Xr link 2
92+
.El
93+
.Pp
94+
The following operations pass through to the underlying filesystem unchanged:
95+
.Bl -bullet -compact
96+
.It
97+
.Xr read 2 ,
98+
.Xr readdir 2 ,
99+
.Xr stat 2 ,
100+
and other read-only operations
101+
.It
102+
.Xr unlink 2
103+
and
104+
.Xr rmdir 2
105+
(these free space rather than allocating it)
106+
.It
107+
.Xr rename 2
108+
.El
109+
.Pp
110+
.Xr statvfs 2
111+
reports zero free and available blocks and inodes, regardless of the
112+
actual state of the underlying filesystem.
113+
.Sh OPTIONS
114+
.Bl -tag -width Fl
115+
.It Fl o
116+
Options are specified with a
117+
.Fl o
118+
flag followed by a comma-separated string of options.
119+
See the
120+
.Xr mount 8
121+
man page for possible options and their meanings.
122+
.El
123+
.Sh EXAMPLES
124+
Mount
125+
.Pa /var/db
126+
under
127+
.Pa /mnt/full
128+
to test how a program behaves when the database volume is full:
129+
.Pp
130+
.Dl mount_full /var/db /mnt/full
131+
.Pp
132+
Verify that the layer is working correctly:
133+
.Bd -literal -offset indent
134+
# Existing data is still readable:
135+
ls /mnt/full
136+
137+
# Writes fail immediately:
138+
echo hello >> /mnt/full/somefile
139+
echo $? # non-zero; "No space left on device"
140+
141+
# Free space is reported as zero:
142+
df /mnt/full
143+
.Ed
144+
.Sh SEE ALSO
145+
.Xr mount 8 ,
146+
.Xr mount_null 8
147+
.Sh HISTORY
148+
The
149+
.Nm
150+
utility first appeared in
151+
.Nx 11 .

sbin/mount_full/mount_full.c

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* $NetBSD$ */
2+
3+
/*
4+
* Copyright (c) 1992, 1993, 1994
5+
* The Regents of the University of California. All rights reserved.
6+
*
7+
* This code is derived from software donated to Berkeley by
8+
* Jan-Simon Pendry.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
* 3. Neither the name of the University nor the names of its contributors
19+
* may be used to endorse or promote products derived from this software
20+
* without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32+
* SUCH DAMAGE.
33+
*/
34+
35+
#include <sys/cdefs.h>
36+
#ifndef lint
37+
__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
38+
The Regents of the University of California. All rights reserved.");
39+
#endif /* not lint */
40+
41+
#ifndef lint
42+
#if 0
43+
static char sccsid[] = "@(#)mount_full.c 8.6 (Berkeley) 4/26/95";
44+
#else
45+
__RCSID("$NetBSD$");
46+
#endif
47+
#endif /* not lint */
48+
49+
#include <sys/param.h>
50+
#include <sys/mount.h>
51+
#include <miscfs/fullfs/full.h>
52+
53+
#include <err.h>
54+
#include <stdio.h>
55+
#include <unistd.h>
56+
#include <stdlib.h>
57+
#include <string.h>
58+
59+
#include <mntopts.h>
60+
61+
#include "mountprog.h"
62+
63+
static const struct mntopt mopts[] = {
64+
MOPT_STDOPTS,
65+
MOPT_GETARGS,
66+
MOPT_NULL,
67+
};
68+
69+
int mount_full(int argc, char **argv);
70+
__dead static void usage(void);
71+
72+
#ifndef MOUNT_NOMAIN
73+
int
74+
main(int argc, char **argv)
75+
{
76+
return mount_full(argc, argv);
77+
}
78+
#endif
79+
80+
int
81+
mount_full(int argc, char *argv[])
82+
{
83+
struct full_args args;
84+
int ch, mntflags;
85+
char target[MAXPATHLEN], canon_dir[MAXPATHLEN];
86+
mntoptparse_t mp;
87+
88+
mntflags = 0;
89+
while ((ch = getopt(argc, argv, "o:")) != -1)
90+
switch(ch) {
91+
case 'o':
92+
mp = getmntopts(optarg, mopts, &mntflags, 0);
93+
if (mp == NULL)
94+
err(1, "getmntopts");
95+
freemntopts(mp);
96+
break;
97+
case '?':
98+
default:
99+
usage();
100+
}
101+
argc -= optind;
102+
argv += optind;
103+
104+
if (argc != 2)
105+
usage();
106+
107+
pathadj(argv[0], target);
108+
pathadj(argv[1], canon_dir);
109+
110+
if (strcmp(target, canon_dir) == 0)
111+
errx(1, "%s (%s) and %s (%s) are identical paths",
112+
argv[0], target, argv[1], canon_dir);
113+
114+
args.la.target = target;
115+
116+
if (mount(MOUNT_FULL, canon_dir, mntflags, &args, sizeof args) == -1)
117+
err(1, "%s on %s", target, canon_dir);
118+
exit(0);
119+
}
120+
121+
static void
122+
usage(void)
123+
{
124+
(void)fprintf(stderr,
125+
"usage: mount_full [-o options] target_fs mount_point\n");
126+
exit(1);
127+
}

0 commit comments

Comments
 (0)