History log of /freebsd-current/sbin/mdmfs/mdmfs.c
Revision Date Author Comments
# 32e86a82 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# f8526186 31-Oct-2019 Kyle Evans <kevans@FreeBSD.org>

mdmfs(8): add -k skel option to populate fs from a skeleton

mdmfs(8) lacks the ability to populate throwaway memory filesystems from an
existing directory.

This features permits an interesting setup where /var for instance lives on
a device where wear-leveling is something you want to avoid as much as
possible and nonetheless you don't want to lose your logs, ports metadata,
etc. Here are the steps:

1. Copy /var to /var.bak;
2. Mount an mfs into /var using -k /var.bak at startup;
3. Synchronize /var to /var.bak weekly and on shutdown.

Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag.

PR: 146254
Submitted by: jlh (many moons ago)
MFC after: 1 week


# c9b6ff9c 16-Feb-2019 Kyle Evans <kevans@FreeBSD.org>

mdmfs(8): use -o reserve with malloc-backed md(4)

Mentioned in mdconfig(8), malloc-backed md(4) can be unstable unless
required memory is allocated up front with -o reserve. Furthermore, panics
have been observed with md used in fstab on 12.0-RELEASE. Choose the stable
route and pass -o reserve.

Submitted by: Paul Vixie
MFC after: 1 week


# f95509a4 11-Feb-2019 Brooks Davis <brooks@FreeBSD.org>

mdmfs: Fix many bugs in automatic md(4) creation.

This code allocated a correctly sized buffer, read past the end of the
source buffer, writing off the end of the target buffer, and then writing
a '\0' terminator past the end of the target buffer (in the wrong place).
It then leaked the buffer.

Switch to a statically sized buffer on the stack and update the source
pointer and
length before use so the correct things are copied.

Fix a logic error in the checks that the format of the line is as
expected and move on out of an assert.

Remove an unneeded close(). fclose() closes the descriptor.

Found with: CheriABI
Obtained from: CheriBSD
Reviewed by: kib, jhb, markj
Differential Revision: https://reviews.freebsd.org/D19122


# 594fb8f5 20-Oct-2018 Conrad Meyer <cem@FreeBSD.org>

mdmfs(8): Check for other types of helper-program failure

Exiting with a signal should not be treated the same as successful exit with
zero status.

Return signal exit information to the callers via negative integers, to
enable distinction from normal exit statuses. (All consumers that check for
errors don't care what the exact non-zero exit value is -- in such a case
they print a diagnostic message and either continue or bail.)

Additionally, check for unexpected sources of waitpid() wakeup and bail if
we encounter them.

Reported by: lev@
Reviewed by: kib, lev, markj (earlier version)
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D17035


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# f3b5058c 30-Sep-2017 Andreas Tobler <andreast@FreeBSD.org>

Initialize mdsize to make gcc happy again. This fixes buildworld on powerpc.

Reviewed by: ian@


# 50e3590c 29-Sep-2017 Ian Lepore <ian@FreeBSD.org>

Enhance mdmfs(8) to work with tmpfs(5).

Existing scripts and associated config such as rc.initdiskless, rc.d/var,
and others, use mdmfs to create memory filesystems. That program accepts a
size argument which allows SI suffixes and treats an unsuffixed number as a
count of 512 byte sectors. That makes it difficult to convert existing
scripts to use tmpfs instead of mdmfs, because tmpfs treats unsuffixed
numbers as a count of bytes. The script logic to deal with existing user
config that might include suffixed and unsuffixed numbers is... unpleasant.

Also, there is no g'tee that tmpfs will be available. It is sometimes
configured out of small-resource embedded systems to save memory and flash
storage space.

These changes enhance mdmfs(8) so that it accepts two new values for the
'md-device' arg: 'tmpfs' and 'auto'. With tmpfs, the program always uses
tmpfs(5) (and fails if it's not available). With 'auto' the program prefers
tmpfs, but falls back to using md(4) if tmpfs isn't available. It also
handles the -s <size> argument so that the mdconfig interpetation of
unsuffixed numbers applies when tmpfs is used as well, so that existing user
config keeps working after a switch to tmpfs.

A new rc setting, mfs_type, is added to etc/defaults/rc.conf to let users
force the use of tmpfs or md; the default value is "auto".

Differential Revision: https://reviews.freebsd.org/D12301


# 9bb18677 10-Mar-2016 Alex Kozlov <ak@FreeBSD.org>

- Implement -T option to allow to specify a fs type for a vnode-backed memory disk
- Rephrase -t option description (manpage)
- Split long sentences (manpage)

Differential Review: https://reviews.freebsd.org/D4394

Reviewed by: mav, wblock (manpage)
Approved by: mav


# 4b85a12f 07-Jan-2012 Ulrich Spörlein <uqs@FreeBSD.org>

Spelling fixes for sbin/


# e50e74d8 13-Sep-2011 Konstantin Belousov <kib@FreeBSD.org>

Do not try to change the mode or ownership of the root of the mountpoint
when newly established mdmfs mount is readonly.

PR: bin/128427
Tested and reviewed by: jchandra
MFC after: 1 week
Approved by: re (bz)


# bf6619ba 06-Sep-2011 Konstantin Belousov <kib@FreeBSD.org>

dd -t switch for mdmfs to enable TRIM on the configured filesystem.
While there, fix minor style issues.

Submitted by: Alex Kozlov <spam rm-rf kiev ua>
MFC after: 1 week
Approved by: re (bz)


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# c918e9f7 14-May-2007 Remko Lodder <remko@FreeBSD.org>

-n is used by newfs to tell "do not generate a .snap directory" instead of
specifying rotational-positions, reflect that in the command arguments.

PR: bin/110178
Submitted by: Alex Kozlov <spam at rm-rf dot kiev dot ua>
Approved by: imp (mentor)


# 3cb8dc7c 30-Apr-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

Fix a typo: argv -> argvp

Rationale:
We are interested in the current (last) element of the argv array
there, not in its first element. The if construct is there because
we want to avoid adding empty (zero-length) arguments to argv, so
we just don't advance argvp if the current argument is empty, and
it gets overwritten at the next iteration. Note that strsep(3)
doesn't treat consecutive delim characters as a single separator,
it returns empty fields between such characters, and it's up to the
caller to handle them this or that way.

Also add a comment that the argv array ends up null-terminated in
any case (it's due to the design of the for loop) as an answer to
a possible question why the whole argv isn't zero-filled.

Submitted by: yongari
Tested by: yongari
MFC after: 3 days


# 9a7d93d6 07-Mar-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

Don't leave a NULL value in mdsuffix when a particular md
unit w/o suffix is specified. It had better be an empty
string as it will be passed to a printf-like function that
builds the command line to run.

PR: kern/109863
MFC after: 1 week


# c72132f0 15-Feb-2007 Matteo Riondato <matteo@FreeBSD.org>

Correct -c and -d description.

Other requests made in the PR were already solved in the past.

PR: bin/66763
MFC after: 1 week


# 8c6a98de 15-Feb-2007 Matteo Riondato <matteo@FreeBSD.org>

Enhances mdmfs(8) to mount md-based device such as uzip.
Examples of use can be found in the PR text.

PR: 103501
MFC after: 1 week


# 957d7c8f 02-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

Remove the -C option as it does more harm than good. To be fully
compatible, it would have to (at least):

- support the "compat-compat" -T option,
- *not* support the -l, -O, and -v options,
- default to soft updates being disabled.

Worse, the compatibility mode makes it impossible to mount_mfs(8)
a file system from fstab(5) with soft updates disabled (-S). [1]

Now, the only difference when called as "mount_mfs" or "mfs" (as
opposed to "mdmfs") is that the file mode of the mount point is
set by default to 01777. All options available to mdmfs(8) are
also available to mount_mfs(8); the -C option is still recognized
but ignored for backward compatibility.

PR: bin/98860 [1]
MFC after: 2 weeks


# 63f8ddbe 16-Feb-2006 Maxim Sobolev <sobomax@FreeBSD.org>

Add new -E option, which allows to specify location of the mdconfig(8)
utility instead of using default _PATH_MDCONFIG (/sbin/mdconfig).

MFC after: 1 week


# 05b2fd30 01-Jan-2006 Dima Dorfman <dd@FreeBSD.org>

Add a -P option to allow skipping newfs when using a vnode-backed
disk. Apparently some people want to use mdmfs as mount_* as a
shortcut for mounting existing file-based file systems.

Note that unlike in the patches from the submitters, this option is
not available in compat mode. Compat mode was supposed to support only
things that mount_mfs used to support. To use this option from fstab,
mdmfs should be called mount_md, not mount_mfs. This distinction has
not always upkept for new options, and those can't be fixed now
without breaking people's systems, but new options should not usually
be allowed in compat mode. (Not sure why -F is allowed there at all.)

PR: 57641
Submitted by: Ruben de Groot
Submitted independently by: Wojciech A. Koszek, for Urzad Miasta Czestochowa


# 541ce3c1 22-Dec-2005 Dima Dorfman <dd@FreeBSD.org>

If we're operating without running external programs (-N) and
autonumbering is requested, set the unit to 0 instead of -1. This
option is just for output, and "/dev/md-1" looks disconcerting.

Submitted by: Wojciech A. Koszek


# de90a634 14-Oct-2005 Ralf S. Engelschall <rse@FreeBSD.org>

Fix parsing of mdmfs(8) option "-w <user>:<group>" in case <user> or
<group> is a numeric user/group ID instead of a user/group name (as
explicitly intended to be allowed by both the manual page and the
implementation).

Before this fix, mdmfs(8) aborted:

| # mdmfs -s 32m -w 0:0 md /var/tmp/foo
| Assertion failed: (mip->mi_have_uid), function extract_ugid, file /usr/src/sbin/mdmfs/mdmfs.c, line 555.
| Abort trap (core dumped)

The "mi_have_[ug]id" fields were only set in case a name lookup was
successful. Instead they also have to be set in case the string to
integer conversion was successful.

Additionally, as a result of this fix, two assertions at the end of
the function are now always true and hence can be just be removed. It
is guarrantied that both the UID and the GID are set when the function
returns regularily, else it would have been already bailed out with
usage()/exit(3) or errx(3) before.

Spotted by: Christoph Schug <chris@schug.net>
MFC after: 3 days


# 8d646af5 10-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# 47376189 30-Jan-2005 Suleiman Souhlal <ssouhlal@FreeBSD.org>

Remove unsigned casts.

Discussed with: delphij, stefanf
Approved by: grehan (mentor)


# 6449237f 25-Jan-2005 Suleiman Souhlal <ssouhlal@FreeBSD.org>

- Make WARNS?= 6 clean
- Add WARNS?= 6

Approved by: stefanf, grehan (mentor)


# 2921afed 17-May-2004 Ruslan Ermilov <ru@FreeBSD.org>

Added -l to usage().


# 1d3170aa 25-Feb-2004 Robert Watson <rwatson@FreeBSD.org>

Add a "-l" parameter to mdmfs so that memory file systems can be
created with the multilabel flag from inception. This simply
passes the "-l" flag on to newfs(8).

Obtained from: TrustedBSD Project
Sponsored by: DARPA, McAfee Research


# 5cfe0423 22-Jan-2004 Peter Grehan <grehan@FreeBSD.org>

Userland signed char fixes for PPC build. Problems were using a char
return for getopt() and comparing to -1, ditto with fgetc() and EOF,
and using the kg_nice value from <sys/user.h>

Submitted by: Stefan Farfeleder <stefan@fafoe.narf.at>
Reviewed by: obrien, bde (a while back)
Tested lightly on: ppc, i386, make universe


# ce03e3a7 05-Aug-2003 Yaroslav Tykhiy <ytykhiy@gmail.com>

Don't reinvent the wheel: Use setmode(3) to interpret
a file mode specification from the command line. This
approach is more flexible and less error-prone than using
a mere strtoul(3).


# 8a50130b 10-Jul-2003 Alexander Kabaev <kan@FreeBSD.org>

Do not compare unsigned int values with ULONG_MAX. The comparison is
always false on 64bit platforms and GCC 3.3.1 issues warning there.


# 3bb374eb 29-Jun-2003 Gordon Tetlow <gordon@FreeBSD.org>

Remove pathnames.h.

Pointed out by: Mathieu Arnold <mat@mat.cc>


# 1386defa 29-Jun-2003 Gordon Tetlow <gordon@FreeBSD.org>

Move path definitions to include/paths.h. This makes it easier to override
these definitions in the /rescue case.

Submitted by: Tim Kientzle <kientzle@acm.org>


# c69284ca 03-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID() to quiet GCC 3.3 warnings.


# 622448fa 01-Dec-2002 Robert Watson <rwatson@FreeBSD.org>

Teach mdmfs how to pass UFS version numbers through to newfs. Because
of an argument name collision with -O, use -v, and default to whatever
the newfs default is for the platform (generally, UFS1). This is
required to support diskless workstations that use UFS2 for their
mdmfs file systems.

Reviewed by: dd, bmah
Approved by: re (bmah)
Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories


# b7e368f7 22-Sep-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Don't disklabel(8) the md(4) device, it is not needed, and we don't want
to propagete BSD disklabels to architectures not already so polluted.

Sponsored by: DARPA & NAI Labs.


# ce66ddb7 21-Aug-2002 Tom Rhodes <trhodes@FreeBSD.org>

s/filesystem/file system/g as discussed on -developers


# d3974088 22-Apr-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Usage style sweep: spell "usage" with a small 'u'.
Also change one case of blatant __progname abuse (several more remain)
This commit does not touch anything in src/{contrib,crypto,gnu}/.


# 2dc4ac06 30-Sep-2001 Ian Dowse <iedowse@FreeBSD.org>

Enable bug-for-bug compatibility with mount_mfs when the program
name is "mount_mfs" or "mfs". Previously, the condition was that
the program name must start with "mount_", but this both missed
the case where mount(8) invokes mdmfs with argv[0] = "mfs", and it
included cases such as "mount_md" where compatibility is not
required.

Reviewed by: dd


# f7acb7e4 15-Aug-2001 Dima Dorfman <dd@FreeBSD.org>

Implement a better compatibility mode with mount_mfs. It is the
default if the executable is named (called as) "mount_*", or can be
enabled with the -C option. This allows users to leave their old
fstab entires unchanged (modulo symlink'ing mdmfs to mount(md|mfs))
and have things behave the way they should (by emulating mount_mfs
silliness), while still allowing mdmfs to be used as a generic
make-an-md-and-mount-it type thing.

Right now, the only effects of this option is to set the mount-point
mode to 01777 as if "-p 1777" was given, and to complain about getting
command-line options that mount_mfs didn't take (e.g., -X, -L, et al).
The latter is mostly to try to catch operator errors.

Also implement -U, which turns on soft-updates. It's redundant (since
softdep is the default), but implement it anyway for compatibility.


# 94ddc5af 14-Aug-2001 David E. O'Brien <obrien@FreeBSD.org>

style(9) tweak

Approved by: dd


# d69f5dee 30-Jul-2001 Dima Dorfman <dd@FreeBSD.org>

Nuke my e-mail address since it seems out of place here.


# bc56b93a 01-Jul-2001 Kris Kennaway <kris@FreeBSD.org>

Add __printflike() to those static functions which need it.


# 8d3c1246 24-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Use strdup(3) instead of reimplementing it inline.


# 04438a11 21-Jun-2001 Matt Jacob <mjacob@FreeBSD.org>

Fix compilation error on alpha.


# 4d7de91f 18-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Introduce mdmfs(8), a wrapper around mdconfig(8), disklabel(8),
newfs(8), and mount(8) that mimics the command line option set of the
deprecated mount_mfs(8).

Approved by: jkh, phk, -hackers