tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mtree weirdness

On Fri, 27 Feb 2009, Luke Mewburn wrote:

> On Wed, Feb 25, 2009 at 07:09:24PM +0000, Iain Hibbert wrote:
>   | I found a weird thing where /usr/tools/bin/nbmtree fails to work (means
>   | sourcesets creates empty sets), whereas /usr/sbin/mtree works
>   | fine yet they are built from the same sources..

[when the current directory is in a unionfs mount]

> It may be some weirdness in tools/compat and its dirfd() macro,
> or associated code.
> I'd look further into tools/compat/compat_defs.h and friends.

Ok I found the root cause, the fix might need consideration :)

The problem is in libc/gen/opendir.c - fts(3) uses the internal
__opendir2() entry point and always passes the DTF_REWIND flag which
causes a pause/rewind halfway through a unionfs scan because there is some
special handling for cases when a fchdir() is to be made according to the

Because fts(3) is not always available, it is added to the tools build but
lacking the NETBSD_SOURCE definition causing the __opendir2() call to be
translated into the standard opendir() expected in the host libc.

Our libc opendir (dating from CSRG sync in 94) is a stub call, comprising:

        return (__opendir2(name, DTF_HIDEW|DTF_NODUP));

and so the essential difference is the lack of the DTF_REWIND flag. If I
add DTF_REWIND to that (as below) and rebuild libc, then
"/usr/tools/bin/nbmtree -c" works fine in a unionfs directory.

Now, DTF_REWIND is only required in a unionfs mount situtation (I think)
but it is present for the nfs case also and so adding it to default
opendir() call might not be correct (but fts always uses it anyway)



--- /usr/src/lib/libc/gen/opendir.c     2008-01-10 09:49:04.000000000 +0000
+++ src/lib/libc/gen/opendir.c  2009-03-02 10:54:30.000000000 +0000
@@ -66,7 +66,7 @@ opendir(const char *name)

        _DIAGASSERT(name != NULL);

-       return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
+       return (__opendir2(name, DTF_HIDEW|DTF_NODUP|DTF_REWIND));

 DIR *

Home | Main Index | Thread Index | Old Index