diff vdisk.c @ 51:498b6fcaf270

vdisk worked
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 22 Jul 2018 05:48:04 +0900
parents 1430678cd4fb
children 51b437557f42
line wrap: on
line diff
--- a/vdisk.c	Sat Jul 21 22:44:02 2018 +0900
+++ b/vdisk.c	Sun Jul 22 05:48:04 2018 +0900
@@ -17,7 +17,7 @@
 #include <time.h>
 #include <arpa/inet.h>
 
-static int vdiskdebug = 1;  //   1 trace, 2 filename
+static int vdiskdebug = 0;  //   1 trace, 2 filename
 
 
 Byte pmmu[8];  // process dat mmu
@@ -103,10 +103,10 @@
 Byte
 setcd(char *name) {
     int len;
-    for(int i=0;i<256;i++) {
+    for(int i=0;i<512;i++) {
         if (cdt[i] && strcmp(name,cdt[i])==0) return i;
     }
-    cdtptr &= 0xff;
+    cdtptr &= 0x1ff;
     if (cdt[cdtptr]) free(cdt[cdtptr]);
     cdt[cdtptr] = (char*)malloc(len=strlen(name)+1);
     strcpy(cdt[cdtptr],name);
@@ -127,6 +127,11 @@
     if (*s&0x80) putchar(*s&0x7f);
 }
 
+static void
+err(int error) {
+    printf("err %d\n",error);
+}
+
 static char *
 addCurdir(char *name, PathDesc *pd, int curdir) {
     int ns =0 ;
@@ -155,8 +160,10 @@
     int i = 0;
     for(;base[i];i++) path[i] = base[i];
     path[i++] = '/';
-    for(int j=0;j<ps;j++,i++) path[i] = name[j];
-    path[i++] = 0;
+    for(int j=0;i<ps;j++,i++) path[i] = name[j];
+    path[i] = 0;
+    if (i>ps)
+        printf("overrun i=%d ps=%d\n",i,ps); // err(__LINE__);
     return path;
 }
 
@@ -171,10 +178,10 @@
     if (*p!=0) {
         name = (char *)malloc(p-path+1); 
         int i;
-        for(int i=0;i<MAXPAHTLEN;i++) {
+        for(i=0;i<p-path;i++) {
             name[i] = path[i]&0x7f;
         }
-        name[MAXPAHTLEN-maxlen] = 0;
+        name[i] = 0;
     }
     char *name1 = addCurdir(name,pd,curdir);
     if (name1!=name && name1!=path) free(name);
@@ -274,7 +281,7 @@
     pd->dirfp = (char *)malloc(dircount*DIR_SZ);
     rewinddir(dir);
     int i = 0;
-    while ((dp = readdir(dir)) != NULL) {
+    while ((dp = readdir(dir)) != NULL && dircount-->=0) {
         int j = 0;
         for(j = 0; j < DIR_NM ; j++) {
             if (j< dp->d_namlen)  {
@@ -288,7 +295,8 @@
         pd->dirfp[i+j+1] = (dp->d_ino&0xff00)>>8;
         pd->dirfp[i+j+2] = dp->d_ino&0xff;
         i += DIR_SZ;
-        if (i>pd->sz) return 0;
+        if (i>pd->sz) 
+            return 0;
     }
     pd->fp = fmemopen(pd->dirfp,pd->sz,"r");
     return 0;