]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/lib9p/file.c
lib9p: zero out per connection state in Srv template for listensrv()
[plan9front.git] / sys / src / lib9p / file.c
index 1dc324f630f31684e1927c9e3f9343545a5577b4..b2e726cbfd7a38b407c37a87d86f2e68ca327237 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;
@@ -254,7 +259,8 @@ walkfile1(File *dir, char *elem)
        rlock(dir);
        if(strcmp(elem, "..") == 0){
                fp = dir->parent;
-               incref(fp);
+               if(fp != nil)
+                       incref(fp);
                runlock(dir);
                closefile(dir);
                return fp;
@@ -388,12 +394,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)