Re: zic: fix PostgreSQL build failure on filesystems without hard link support

Поиск
Список
Период
Сортировка
Искать

Re: zic: fix PostgreSQL build failure on filesystems without hard link support

От:
Vladlen Popolitov <v.popolitov@postgrespro.ru>
Дата:
Tom Lane писал(а) 2026-07-31 02:57:
> Vladlen Popolitov  writes:
>> PostgreSQL fails to build on filesystems that do not support hard 
>> links
>> (e.g., exFAT, FAT32, some network filesystems). The build process 
>> stops
>> with the following error during timezone data generation:
>>    Can't link  to : Invalid argument
> 
> A question from the tzdb guys:
> 
> * Does the 'symlink' system call have the same problem on this 
> MS-Windows platform? Should zic worry about them as well? (But if so, 
> why didn't zic complain to your users about symlink?)
> 
> Also, it occurs to me to wonder if we're doing this to ourselves.
> Specifically, it looks like src/port/win32error.c's _dosmaperr
> will map ERROR_NOT_SUPPORTED to EINVAL, due to the lack of any
> table entry for ERROR_NOT_SUPPORTED.  Can you confirm which
> underlying Windows error code is being returned?
> 
> 			regards, tom lane

I have confirmed that the Windows error code returned by
CreateHardLinkA() on exFAT is ERROR_INVALID_FUNCTION (numeric value 1).
This code has no mapping in PostgreSQL's _dosmaperr(), which
falls back to returning EINVAL (errno == 22). This is why zic
receives EINVAL instead of ENOTSUP.

One more observation: Microsoft's documentation for CreateHardLinkA() 
does
not list possible error codes. For most Windows API functions, the
documentation explicitly lists all error codes that the function can 
return.
But for CreateHardLinkA(), this information is missing. Therefore, it is
unclear whether different error codes are returned for different failure
scenarios on Windows. This is different from the POSIX link() function,
which has a clearly defined set of error codes for each specific failure
case.
Also I see in man: Linux returns EPERM for unsupported filesystems,
FreeBSD returns EOPNOTSUPP. Neither returns ENOTSUP.

Regarding symlink(): PostgreSQL maps symlink to pgsymlink(), which is
implemented using NTFS junction points on Windows. Junction points work
only with directories, not files. Since zic needs to create symbolic
references to timezone data files, this mechanism is unsuitable, and
zic correctly excludes symlink support using #ifdef HAVE_SYMLINK.

-- 
Best regards,

Vladlen Popolitov.


Re: zic: fix PostgreSQL build failure on filesystems without hard link support

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Вложения:
Vladlen Popolitov  writes:
> Tom Lane писал(а) 2026-07-31 02:57:
>> Also, it occurs to me to wonder if we're doing this to ourselves.
>> Specifically, it looks like src/port/win32error.c's _dosmaperr
>> will map ERROR_NOT_SUPPORTED to EINVAL, due to the lack of any
>> table entry for ERROR_NOT_SUPPORTED.  Can you confirm which
>> underlying Windows error code is being returned?

> I have confirmed that the Windows error code returned by
> CreateHardLinkA() on exFAT is ERROR_INVALID_FUNCTION (numeric value 1).
> This code has no mapping in PostgreSQL's _dosmaperr(), which
> falls back to returning EINVAL (errno == 22). This is why zic
> receives EINVAL instead of ENOTSUP.

Interesting.  I wonder if it'd be sane to put in an explicit mapping
for ERROR_INVALID_FUNCTION, although I'm not quite sure whether to
prefer ENOTSUP or EOPNOTSUPP.  (If so, I'd be inclined to also add a
mapping for ERROR_NOT_SUPPORTED, but apparently that's not relevant to
the immediate problem.)

> Also I see in man: Linux returns EPERM for unsupported filesystems,
> FreeBSD returns EOPNOTSUPP. Neither returns ENOTSUP.

Oooh.  I didn't experiment on either, but I concur with your reading
of their man pages.  Also, NetBSD's man page says the same as FreeBSD,
and I quickly verified on NetBSD 10 that EOPNOTSUPP (45) is different
from ENOTSUP (86), unlike the situation on Linux.  So tzcode's
expectation of ENOTSUP is pretty widely broken already.

> Regarding symlink(): PostgreSQL maps symlink to pgsymlink(), which is
> implemented using NTFS junction points on Windows. Junction points work
> only with directories, not files. Since zic needs to create symbolic
> references to timezone data files, this mechanism is unsuitable, and
> zic correctly excludes symlink support using #ifdef HAVE_SYMLINK.

Right, so that part of it is not a problem.

But this is a mess :-(.  We're not doing the best possible job in
_dosmaperr, but it seems tzcode's expectations need some adjustment
anyway, and that side should probably get sorted before we decide
what to do in _dosmaperr.  I'll go consult further with them.

			regards, tom lane


Re: zic: fix PostgreSQL build failure on filesystems without hard link support

От:
Vladlen Popolitov <v.popolitov@postgrespro.ru>
Дата:
Tom Lane писал(а) 2026-07-31 22:03:
> Vladlen Popolitov  writes:
>> Tom Lane писал(а) 2026-07-31 20:07:
>>> Yeah, that sounds like the solution with the smallest blast radius.
>>> I'll go make it so in a bit.  Thanks for the report!
> 
>> I have already created and tested a new patch based on this idea.
> 
> Oh, I'd already pushed an equivalent fix in win32link.c before
> seeing this message.
> 
>> It fixes the link() error handling. The patch also fixes dolink()
>> on Linux and FreeBSD, since these platforms are affected as well.
>> I hope this can be fixed in upstream tzcode.
> 
> Eggert already committed something, as per the tz@iana.org thread.
> I don't want to take a local patch that doesn't match his, and I'm
> not really in a big hurry to worry about this on Linux/*BSD anyway.
> I think there are few people installing zoneinfo trees on
> non-hard-link filesystems on those platforms, else he'd have gotten
> pushback sooner.  (I didn't research their git history, but I'm
> thinking this error behavior has probably been in tzcode for awhile.)
> There are even fewer people doing so with Postgres' copy of zic,
> because I imagine just about everyone on those platforms uses
> --with-system-tzdata instead of a private, often out-of-date zoneinfo
> tree.  So I'm content to let this go for non-Windows until the next
> time we sync our copy of tzcode.

Tom,

Thank you for the quick fix. I'm glad this is resolved.

This issue came up unexpectedly while I was working with other
patches on Windows. I was using an exFAT drive for the build,
and the build stopped with the link() error. The previous
version of zic handled this correctly because it had slightly
different logic for fallback.

By the way, I am also working on another patch related to link
on Windows (pgsymlink() which uses junction points). In
the PostgreSQL code, there is an incorrect constant used
for buffer length (to short). This can cause failures not
only on servers but also during builds and tests, because
Meson tends to create very long directory names. As a result,
one of the build tests starts failing.

There is a discussion about this issue in the hackers list,
and another participant has confirmed the failure:
https://www.postgresql.org/message-id/flat/ac3f262fdc3613acfb88176972938fd1%40postgrespro.ru

Best regards,
Vladlen


FAQ