Re: git: 41ee91c64f47 - main - newfs_msdos: fix build on non-FreeBSD systems

From: Enji Cooper <yaneurabeya_at_gmail.com>
Date: Wed, 05 Jun 2024 23:47:06 UTC
> On Jun 5, 2024, at 4:42 PM, Enji Cooper <yaneurabeya@gmail.com> wrote:
> 
>> On Jun 3, 2024, at 11:28 PM, Stefan Eßer <se@freebsd.org> wrote:
>> 
>> The branch main has been updated by se:
>> 
>> URL: https://cgit.FreeBSD.org/src/commit/?id=41ee91c64f47faaa8131df3cd8a63bdb60fa486a
>> 
>> commit 41ee91c64f47faaa8131df3cd8a63bdb60fa486a
>> Author:     Stefan Eßer <se@FreeBSD.org>
>> AuthorDate: 2024-06-04 06:26:09 +0000
>> Commit:     Stefan Eßer <se@FreeBSD.org>
>> CommitDate: 2024-06-04 06:26:09 +0000
>> 
>>    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
>> ---
>> sbin/newfs_msdos/mkfs_msdos.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>> 
>> diff --git a/sbin/newfs_msdos/mkfs_msdos.c b/sbin/newfs_msdos/mkfs_msdos.c
>> index 423fbbcadcc5..1bca560a59e1 100644
>> --- a/sbin/newfs_msdos/mkfs_msdos.c
>> +++ b/sbin/newfs_msdos/mkfs_msdos.c
>> @@ -571,7 +571,11 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
>> 	    if (o.align)
>> 		alignto = bpb.bpbSecPerClust;
>> 	    else
>> +#ifdef	PAGE_SIZE
>> 		alignto = PAGE_SIZE / bpb.bpbBytesPerSec;
>> +#else
>> +	        alignto = 1;
>> +#endif
>> 	    if (alignto > 1) {
>> 		/* align data clusters */
>> 		alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs + rds) %
> 
> 	I realize this might seem silly, but what about sysconf(_SC_PAGE_SIZE) ( https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html ) with platforms that don’t have direct access to PAGE_SIZE? It’s supported on Linux and MacOS at least.

Also, POSIX says it could be defined by limits.h: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html . It might just be that an extra header is required to make the tool compile with the proper PAGE_SIZE prior to this change.
-Enji