]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/lib9p/file.c
make bind(2) error handling consistent
[plan9front.git] / sys / src / lib9p / file.c
index 54e09d278179fa0d023dce3ddcbfa76d109a58a9..eddef7e4c6c92a46180f7c1c13f4cdeb91601ac8 100644 (file)
@@ -191,6 +191,12 @@ createfile(File *fp, char *name, char *uid, ulong perm, void *aux)
        }
 
        wlock(fp);
+       if(fp->parent == nil){
+               wunlock(fp);
+               werrstr("create in deleted directory");
+               return nil;
+       }
+
        /*
         * We might encounter blank spots along the
         * way due to deleted files that have not yet
@@ -229,7 +235,6 @@ createfile(File *fp, char *name, char *uid, ulong perm, void *aux)
        if(perm & DMEXCL)
                f->qid.type |= QTEXCL;
 
-       f->mode = perm;
        f->atime = f->mtime = time(0);
        f->length = 0;
        f->parent = fp;
@@ -332,8 +337,9 @@ alloctree(char *uid, char *gid, ulong mode, void (*destroy)(File*))
 
        incref(f);
        t->root = f;
-       t->qidgen = 0;
-       t->dirqidgen = 1;
+
+       /* t->qidgen starts at 1 because root Qid.path is 0 */
+       t->qidgen = 1;
        if(destroy == nil)
                destroy = nop;
        t->destroy = destroy;
@@ -389,12 +395,16 @@ opendirfile(File *dir)
 }
 
 long
-readdirfile(Readdir *r, uchar *buf, long n)
+readdirfile(Readdir *r, uchar *buf, long n, long o)
 {
        long x, m;
        Filelist *fl;
 
-       for(fl=r->fl, m=0; fl && m+2<=n; fl=fl->link, m+=x){
+       if(o == 0)
+               fl = r->dir->filelist;
+       else
+               fl = r->fl;
+       for(m=0; fl && m+2<=n; fl=fl->link, m+=x){
                if(fl->f == nil)
                        x = 0;
                else if((x=convD2M(fl->f, buf+m, n-m)) <= BIT16SZ)