From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <13426df10910042142p1392b6b8m8b05ece8c9b05353@mail.gmail.com> References: <13426df10910040930i48221de1mc9c5cced7d87fcc5@mail.gmail.com> <13426df10910041415w5968c210ue0b80c3273c1c8dd@mail.gmail.com> <1d5d51400910041755x54322df8i4e4bce1b3c290eb@mail.gmail.com> <13426df10910042142p1392b6b8m8b05ece8c9b05353@mail.gmail.com> Date: Sun, 4 Oct 2009 23:39:58 -0700 Message-ID: <13426df10910042339j2e1889em728f6f103a535529@mail.gmail.com> From: ron minnich To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [9fans] replica under 9vx Topicbox-Message-UUID: 7e577aa4-ead5-11e9-9d60-3106f5b1d025 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