Cleans up kdirent hack, removes MIN_M_BUF_SZ
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 8 Jul 2014 01:23:44 +0000 (18:23 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 8 Jul 2014 01:23:44 +0000 (18:23 -0700)
kern/include/ns.h
kern/src/ns/dev.c
kern/src/ns/sysfile.c

index e32c7d1..36dec8f 100644 (file)
@@ -121,9 +121,6 @@ struct dir {
        char *muid;                                     /* last modifier name */
 };
 
-/* Part of the dirty kdirent hack in sysread.  Used to be 59... */
-#define MIN_M_BUF_SZ 52                        /* TODO: 53 is the smallest i've seen */
-
 struct waitmsg {
        int pid;                                        /* of loved one */
        uint32_t time[3];                       /* of loved one and descendants */
index b49625d..7fb59d0 100644 (file)
@@ -314,7 +314,6 @@ devdirread(struct chan *c, char *d, long n,
                                                error(Eshort);
                                        return m;
                                }
-                               assert(dsz >= MIN_M_BUF_SZ);
                                m += dsz;
                                d += dsz;
                                break;
index 10500b6..cdce469 100644 (file)
@@ -754,23 +754,17 @@ static long rread(int fd, void *va, long n, int64_t * offp)
         * new stuff later. Allocate 2048 bytes for that purpose. 
         */
        if (dir) {
+               /* expecting only one dirent at a time, o/w we're busted */
                assert(n >= sizeof(struct kdirent));
-       /* We need to read exactly one dirent and avoid reading too much from the
-        * underlying dev, so that subsequent reads don't miss any dirents. 
-        * Buffer 2*MAXPATH, to be safe. Read off what you can. Return one
-        * kdirent at a time. If you don't have enough, read more. If you run out,
-        * you're done.
-        */
-       if (!c->buf){
-               c->buf=kmalloc(2048, KMALLOC_WAIT);
-               c->bufused = 0;
-       }
-       }
-       while (waserror()) {
-               printk("Well, sysread of a dir sucks.%s \n", current_errstr());
-               nexterror();
-       }
-       if (dir) {
+               if (!c->buf) {
+                       c->buf=kmalloc(2048, KMALLOC_WAIT);
+                       c->bufused = 0;
+               }
+               /* debugging */
+               if (waserror()) {
+                       printk("Well, sysread of a dir sucks.%s \n", current_errstr());
+                       nexterror();
+               }
                va = c->buf + c->bufused;
                n = 2048 - c->bufused;
        }
@@ -810,8 +804,8 @@ static long rread(int fd, void *va, long n, int64_t * offp)
                c->bufused -= amt;
                memmove(c->buf, c->buf + amt, c->bufused);
                n = amt;
+               poperror();     /* matching our debugging waserror */
        }
-       poperror();     /* matching our while(waserror) */
 
        poperror();
        cclose(c);