From 17e85f59907aecc0c9e812ee094303f6e1fdd845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Thu, 6 Jun 2024 12:28:02 +0200 Subject: [PATCH] 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 --- sbin/newfs_msdos/mkfs_msdos.c | 9 +-------- sbin/newfs_msdos/newfs_msdos.8 | 20 ++++++++------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/sbin/newfs_msdos/mkfs_msdos.c b/sbin/newfs_msdos/mkfs_msdos.c index 1bca560a59e1..dcc2bb982efc 100644 --- a/sbin/newfs_msdos/mkfs_msdos.c +++ b/sbin/newfs_msdos/mkfs_msdos.c @@ -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) % diff --git a/sbin/newfs_msdos/newfs_msdos.8 b/sbin/newfs_msdos/newfs_msdos.8 index 816b5fc867b4..92e407ab81af 100644 --- a/sbin/newfs_msdos/newfs_msdos.8 +++ b/sbin/newfs_msdos/newfs_msdos.8 @@ -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