History log of /freebsd-current/sbin/newfs_msdos/mkfs_msdos.c
Revision Date Author Comments
# 41ee91c6 04-Jun-2024 Stefan Eßer <se@FreeBSD.org>

newfs_msdos: fix build on non-FreeBSD systems

Disable data area alignment if the build environment does not define
PAGE_SIZE (e.g., when building on Linux or macOS).

Reported by: jrtc27
MFC after: 1 week


# 077f757d 02-Jun-2024 Stefan Eßer <se@FreeBSD.org>

newfs_msdos: align data area to VM page boundary by default

Without alignment, the data area will not be aligned with the buffer
cache, leading to overhead, higher write multiplication on SSD devices
and issues with very large cluster sizes (see PR 277414).

The -A option used to align the start of the root directory to a
multiple of the cluster size, which happens to align the start of the
data area with a buffer page boundary in case of large clusters and
the default number of directory entries (512 entries requiring 16 KB
for FAT12 or FAT16, FAT32 puts the root directory into the data area).

This commit aligns the start of the data area with the page size, if
neither -A nor -r is used. It changes -A to align the start of the
data area (end of the root directory) to a multiple of the cluster
size, since this is the alignment that prevents write multiplication
due to clusters crossing erase block boundaries of a SSD device.
The -r option is unchanged and will prevent any automatic alignment
from occuring.

Approved by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D45436


# eba230af 25-Sep-2023 John Baldwin <jhb@FreeBSD.org>

Purge more stray embedded $FreeBSD$ strings

These do not use __FBSDID but instead use bare char arrays.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D41957


# f775c417 29-Apr-2022 Mark Johnston <markj@FreeBSD.org>

newfs_msdos: Fix warnings that arise when compiled for makefs

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# 9990450e 31-Jan-2022 Eric van Gyzen <vangyzen@FreeBSD.org>

newfs_msdos: fix type of kern.maxphys

The type of the kern.maxphys sysctl OID is now ulong. Change the
local variable type to match.

Reviewed by: delphij, emaste
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34116


# 1cbad9d7 04-Jul-2020 Xin LI <delphij@FreeBSD.org>

Use KERN_MAXPHYS.

Suggested by: imp
Reviewed by: imp, cem (earlier version), emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D25563


# 33c2d974 04-Jul-2020 Xin LI <delphij@FreeBSD.org>

Gather writes to larger chunks (MAXPHYS) instead of issuing them in
sectors.

On my SanDisk Cruzer Blade 16GB USB stick this made formatting much faster:

x before
+ after
+--------------------------------------------------------------------------+
|+ |
|+ x |
|+ x x|
|A MA||
+--------------------------------------------------------------------------+
N Min Max Median Avg Stddev
x 3 15.89 16.38 16 16.09 0.2570992
+ 3 0.32 0.37 0.35 0.34666667 0.025166115
Difference at 95.0% confidence
-15.7433 +/- 0.414029
-97.8455% +/- 0.25668%
(Student's t, pooled s = 0.182665)

Reviewed by: emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D24508


# 162ae9c8 26-Jan-2020 Alex Richardson <arichardson@FreeBSD.org>

Allow bootstrapping makefs on older FreeBSD hosts and Linux/macOS

In order to do so we need to install the msdosfs headers to the bootstrap
sysroot and avoid includes of kernel headers that may not exist on every
host (e.g. sys/lockmgr.h). This change should allow bootstrapping of makefs
on FreeBSD 11+ as well as Linux and macOS.

We also have to avoid using the IO_SYNC macro since that may not be
available. In makefs it is only used to switch between calling
bwrite() and bdwrite() which both call the same function. Therefore we
can simply always call bwrite().

For our CheriBSD builds we always bootstrap makefs by setting
LOCAL_XTOOL_DIRS='lib/libnetbsd usr.sbin/makefs' and use the makefs binary
from the build tree to create a bootable disk image.

Reviewed By: brooks
Differential Revision: https://reviews.freebsd.org/D23201


# 2780a26b 07-Dec-2019 Xin LI <delphij@FreeBSD.org>

Fix a couple of minor issues with newfs_msdos:

- Do not unnecessarily strdup().
- Check return value of getdiskinfo(), if it failed, bail out.

Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D22729


# d9aee13f 08-Nov-2019 Ed Maste <emaste@FreeBSD.org>

makefs: avoid warning when creating FAT filesystem on existing file

Previously the mkfs_msdos function (from newfs_msdos) emitted warnings
in the case that an image size is specified and the target is not a
file, or no size is specified and the target is not a character device.
The latter warning (not a character device) doesn't make sense when this
code is used in makefs, regardless of whether an image size is specified
or not.

Sponsored by: The FreeBSD Foundation


# aa9cb40e 22-Aug-2019 Xin LI <delphij@FreeBSD.org>

When creating a new FAT32 filesystem, use "unknown" (0xFFFFFFFF) for
FSI_Nxt_Free instead of providing a wrong value.

With this change, fsck_msdosfs would no longer complain about invalid
FSInfo information.

MFC after: 2 weeks


# 0531ab72 15-Jun-2018 Xin LI <delphij@FreeBSD.org>

Added option to cluster-align the start of the root directory.

Obtained from: Android
Obtained from: https://android.googlesource.com/platform/system/core/+/052f27562154d175267999106bd6bf18fc8c363e
Obtained from: https://android.googlesource.com/platform/system/core/+/8218b6aae9cd4a19fa074a8a8203fe9275b35447
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D15672


# 783d8ed0 04-Jan-2018 Warner Losh <imp@FreeBSD.org>

Only call close if fd and fd1 are not -1.

CID: 1384018, 1384017


# cd446151 27-Dec-2017 Warner Losh <imp@FreeBSD.org>

Close fd and fd1 before returning now that we're done with them.

CID: 978234, 978236


# 28ef05f7 16-May-2017 Ed Maste <emaste@FreeBSD.org>

newfs_msdos: add -T (timestamp) option for reproducible builds

This includes some whitespace and minor bug fixes relative to NetBSD,
which will be submitted upstream at the conclusion of the makefs
msdos update.

NetBSD revs:
mkfs_msdos.c 1.11
mkfs_msdos.h 1.4
newfs_msdos.8 1.22
newfs_msdos.c 1.44

Submitted by: Siva Mahadevan <smahadevan@freebsdfoundation.org>
Reviewed by: emaste
Obtained from: NetBSD
Sponsored by: The FreeBSD Foundation


# bf0d940a 30-Aug-2016 Warner Losh <imp@FreeBSD.org>

The code only converts from bpbHugeSectors to bpbSectors if the sum of
the hidden and huge sectors is less than or equal MAXU16. When
formatting in Windows bpbSectors is still used for 63488 sectors and
2048 hidden (sum > MAXU16). The hidden sectors count is the number of
sectors before the FAT16 Boot Record so it shouldn't affect the sector
count. Attached patch (huge_sec_conversion.patch) to only check for
bpb.bpbHugeSectors <= MAXU16 when converting to bpbSectors.

Submitted by: Guy Yur
PR: 183234


# 4a9fb9fb 30-Aug-2016 Warner Losh <imp@FreeBSD.org>

Remove CHS alignment. It's not needed and causes problems for the BBB
boot partition. NetBSD removed it in 1.10 in their repo some time ago.

Submitted by: Guy Yur
PR: 183234


# 564500de 18-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use nitems() from sys/param.h.

MFC after: 2 weeks.


# 170b1dd5 06-Dec-2015 Enji Cooper <ngie@FreeBSD.org>

Fix leak in mkfs_msdos(..) by initializing img to NULL and free'ing at the end
of the function

Differential Revision: https://reviews.freebsd.org/D4405
MFC after: 1 week
PR: 204943
Reviewed by: emaste, jilles
Reported by: David Binderman <dcb314@hotmail.com>
Sponsored by: EMC / Isilon Storage Division


# 937744df 27-Nov-2015 Ed Maste <emaste@FreeBSD.org>

mkfs_msdos: sync with NetBSD

Add a sanity test and clean up whitespace.

Obtained from: NetBSD


# 99f4158c 23-Nov-2015 Ed Maste <emaste@FreeBSD.org>

newfs_msdos: rework error handling for eventual use in makefs

Return -1 on errors from mkfs_msdos() instead of err()/errx(), to
allow different consumers to handle errors as appropriate.

Obtained from: NetBSD
Sponsored by: The FreeBSD Foundation


# 59faa1e9 16-Oct-2015 Ed Maste <emaste@FreeBSD.org>

newfs_msdos: prefer snprintf to sprintf

Obtained from: NetBSD
Sponsored by: The FreeBSD Foundation


# 041b03da 15-Oct-2015 Ed Maste <emaste@FreeBSD.org>

newfs_msdos: move mkfs_msdos to separate file for later use in makefs

Sponsored by: The FreeBSD Foundation