newfs_msdos: align to multiple of cluster size by default

A previous commit aligned the start of the data area to a multiple of
the VM page size, in order to prevent extra buffers to be allocated
(which failed for 64 KB cluster size without this alignment).

Since a dependency on PAGE_SIZE caused compatibility issues, the
alignment was made conditional on this macro being defined, in the
previous commit. This lead to different behavior of this program
when built on FreeBSD vs. Linux (which does not define PAGE_SIZE).

This commit removes any use of PAGE_SIZE and instead always aligns
the start of the data area to a multiple of the cluster size.

The -A option is now implied, unless overridden by a specific number
of reserved sectors with the -r option.

Approved by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45436
This commit is contained in:
Stefan Eßer 2024-06-06 12:28:02 +02:00
parent ec69d23093
commit 17e85f5990
2 changed files with 9 additions and 20 deletions

View File

@ -568,14 +568,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs;
}
if (set_res) {
if (o.align)
alignto = bpb.bpbSecPerClust;
else
#ifdef PAGE_SIZE
alignto = PAGE_SIZE / bpb.bpbBytesPerSec;
#else
alignto = 1;
#endif
alignto = bpb.bpbSecPerClust;
if (alignto > 1) {
/* align data clusters */
alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs + rds) %

View File

@ -23,7 +23,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 2, 2024
.Dd June 6, 2024
.Dt NEWFS_MSDOS 8
.Os
.Sh NAME
@ -91,13 +91,11 @@ A suffix s, k, m, g (lower or upper case)
appended to the offset specifies that the
number is in sectors, kilobytes, megabytes or gigabytes, respectively.
.It Fl A
Attempt to cluster align the data area, useful for SD card.
If neither the
.Fl A
nor
Attempt to cluster align the data area, useful for flash based storage.
This option is enabled by default, unless a number of reserved sectors
is specified using the
.Fl r
option is used, the number of reserved sectors is set to a value that aligns
the start of the data area to a multiple of the page size of the host.
option.
.It Fl B Ar boot
Get bootstrap from file.
.It Fl C Ar create-size
@ -173,12 +171,10 @@ is 2.
Number of hidden sectors.
.It Fl r Ar reserved
Number of reserved sectors.
If neither the
.Fl A
nor
If the
.Fl r
option is used, the number of reserved sectors is set to a value that aligns
the start of the data area to a multiple of the page size of the host.
option is not used, the number of reserved sectors is set to a value that
aligns the start of the data area to a multiple of the cluster size.
.It Fl s Ar total
File system size.
.It Fl u Ar track-size