OK, it's an incompatibility between Posix world and Plan 9 world. It's
because mkdir doesn't open the directory, and
create on Plan 9 does.

Here is what I think is the relevant code from applylog.


                        if(rd.mode&DMDIR){
                                fd = create(local, OREAD, DMDIR); <========= 
creates d--------- --
but it's open.
                                if(fd < 0 && isdir(local))
                                        fd = open(local, OREAD);
                                if(fd  < 0){
                                        error("mkdir %q: %r", name);
                                        skip = 1;
                                        continue;
                                }

This sequence works fine on Plan 9.

In devfs-posix.c we have this:

                if(mkdir(path, perm & 0777) < 0)
                        oserror();
                if((fd = open(path, 0)) < 0)
                        oserror();

Which fails very badly on linux if perm is 0, as it is from replica.

This works on Plan 9 because create is one operation, even for
directories. Chalk it up to another Posix botch. I can't recall how
many times this one has bitten me.

I can special-case the code in devfs-posix.c:

if (perm&0400 == 0) then do a mkdir, an open, and an fchmod. Tomorrow,
that is. I think the work-around is pretty easy.
I figure the 0400 might work because mode has to be OREAD at this point anyway.

or, simpler: take this code:
                // Be like Plan 9 file servers: inherit mode bits
                // and group from parent.
                fchmod(fd, perm & st.st_mode & 0777);

which happens AFTER the mkdir, and instead compute the perms first and
do the mkdir with those perms.

Russ, any reason to make the d--------- perm directory and then change
it with the fchmod later? Can we just do the mkdir with the final
permissions? Or is this d--------- guarding against some race
condition in the linux vfs?

ron

Reply via email to