Re: A micro-optimisation for walkdir() - Mailing list pgsql-hackers

From Magnus Hagander
Subject Re: A micro-optimisation for walkdir()
Date
Msg-id CABUevEzURN=wC95JHvTKFJtEy0eY9rWO42yU=59-q8xSwm-Dug@mail.gmail.com
Whole thread Raw
In response to Re: A micro-optimisation for walkdir()  (Thomas Munro <thomas.munro@gmail.com>)
Responses Re: A micro-optimisation for walkdir()
List pgsql-hackers


On Mon, Sep 7, 2020 at 12:27 AM Thomas Munro <thomas.munro@gmail.com> wrote:
On Sun, Sep 6, 2020 at 5:23 AM Juan José Santamaría Flecha
<juanjo.santamaria@gmail.com> wrote:
> On Sat, Sep 5, 2020 at 2:13 AM Andres Freund <andres@anarazel.de> wrote:
>> > However, it looks like we might be missing a further opportunity
>> > here...  Doesn't Windows already give us the flags we need in the
>> > dwFileAttributes member of the WIN32_FIND_DATA object that the
>> > Find{First,Next}File() functions populate?
>>
>> That'd be better...
>
>
> At first I did not see how to get DT_LNK directly, but it is possible without additional calls, so please find attached a version with that logic.
>
> This version also drops the enum, defining just the macros.

Excellent.  I'd like to commit these soon, unless someone has a better
idea for how to name file_utils_febe.c.

I think the following is a little mysterious, but it does seem to be
what people do for this in other projects.  It is the documented way
to detect mount points, and I guess IO_REPARSE_TAG_MOUNT_POINT is
either overloaded also for junctions, or junctions are the same thing
as mount points.  It would be nice to see a Win32 documentation page
that explicitly said that.

The wikipedia page on it is actually fairly decent: https://en.wikipedia.org/wiki/NTFS_reparse_point. It's not the documentation of course, but it's easier to read :) The core difference is whether you mount a whole filesystem (mount point) or just a directory off something mounted elsehwere (junction).

And yes, the wikipedia page confirms that junctions also use IO_REPARSE_TAG_MOUNT_POINT.


+    /* For reparse points dwReserved0 field will contain the ReparseTag */
+    else if ((fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0
+             && (fd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT))
+        d->ret.d_type = DT_LNK;

Hmm, it's interesting that our existing test for a junction in
pgwin32_is_junction() only looks for FILE_ATTRIBUTE_REPARSE_POINT and
doesn't care what kind of reparse point it is.

I think that's mostly historical. When that code was written, the only two types of reparse points that existed were junctions and mount points -- which are as already noted, the same. Symbolic links, unix sockets and such things came later.

 
--

pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: v13: CLUSTER segv with wal_level=minimal and parallel index creation
Next
From: Heikki Linnakangas
Date:
Subject: Re: Yet another fast GiST build