diff vdisk.c @ 45:07c84761da6f

dd vrbf asm code
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 19 Jul 2018 16:21:47 +0900
parents b26c23331d02
children ec9f494497e1
line wrap: on
line diff
--- a/vdisk.c	Thu Jul 19 11:31:17 2018 +0900
+++ b/vdisk.c	Thu Jul 19 16:21:47 2018 +0900
@@ -20,7 +20,7 @@
 extern char *prog ;   // for disass
 extern Byte * mem0(Byte *iphymem, Word adr, Byte *immu) ;
 #define pmem(a)  mem0(phymem,a,mmu)
-#define umem(a)  (mem[0x41+IOPAGE]?mem0(phymem,a,&mem[0x21+IOPAGE]):mem0(phymem,a,&mem[0x20+IOPAGE]))
+#define umem(a)  (mem[0x42+IOPAGE]?mem0(phymem,a,&mem[0x21+IOPAGE]):mem0(phymem,a,&mem[0x20+IOPAGE]))
 #else
 #define pmem(a)  (&mem[a])
 #define umem(a)  (&mem[a])
@@ -28,31 +28,42 @@
 
 #define MAXPDV 256
 
+
 typedef struct pathDesc {
     char *name;
     FILE *fp;
     int mode;
     int inode ;  // lower 24 bit of unix inode, os9 lsn
     int num ;
+    int sz ;     // used only for directory
+    char drv ;
     char use ;
     char dir;
     char *fd ;
     char *dirfp;
 } PathDesc, *PathDescPtr;
 
+#define MAXVDRV 4
 
+char drvRoot[] = { '.','.','.','.'};
 PathDesc pdv[MAXPDV];
 
+int setVdisk(int drv,char *name) {
+    if (drv<0 || drv>=MAXVDRV) return -1;
+    drvRoot[drv] = name;
+    return 0;
+}
+
 PathDesc *findPD() {
     for(int i=0;i<MAXPDV;i++) {
         if (!pdv[i].use) {
             pdv[i].use = 1;
             pdv[i].num = i;
-            pd[i].mode = 0;
-            pd[i].fp = 0;
-            pd[i].dirfp = 0;
-            pd[i].name = 0;
-            pd[i].fd = 0;
+            pdv[i].mode = 0;
+            pdv[i].fp = 0;
+            pdv[i].dirfp = 0;
+            pdv[i].name = 0;
+            pdv[i].fd = 0;
             return &pdv[i];
         }
     }
@@ -71,18 +82,17 @@
 
 #define MAXPAHTLEN 256
 
-char *addCurdir(char *name, PathDesc *curdir) {
+char *addCurdir(char *name, PathDesc *pd, PathDesc *curdir) {
     int ns = strlen(name);
     int ps = ns;
-    int ds=0 ;
     if (curdir==0 && name[0]!='/') return 0; // no current directory
-    if (name[0]!='/') ps += (ds=strlen(curdir->name))+1;
+    char *base ; 
+    if (name[0]!='/') { base = curdir->name; ps += strlen(curdir->name)+1; }
+    else { base = drvRoot[pd->drv]; ps += strlen(drvRoot[pd->drv])+1; }
     char *path = (char*)malloc(ps+1);
     int i = 0;
-    if (ds) {
-        for(;i<ds;i++) path[i] = curdir->name[i];
-        path[i++] = '/';
-    }
+    for(;base[i];i++) path[i] = base[i];
+    path[i++] = '/';
     for(int j=0;j<ns;j++,i++) path[i] = name[j];
     path[i++] = 0;
     return path;
@@ -98,13 +108,13 @@
         name = (char *)malloc(p-path+1); 
         strncpy(path,p, MAXPAHTLEN-maxlen);
     }
-    char *name1 = addCurdir(name,curdir);
+    char *name1 = addCurdir(name,pd,curdir);
     if (name1!=name && name1!=path) free(name);
     pd->name = name1;
     return p;
 }
 
-void os9setmode(char &os9mode,int mode) {
+void os9setmode(char *os9mode,int mode) {
     char m = 0;
     if (mode&S_IFDIR) m|=0x80;
     if (mode&S_IRUSR) m|=0x01;
@@ -150,6 +160,15 @@
  * MINSEC         SET       16
  */
 
+#define FD_ATT 0 
+#define FD_OWN 1 
+#define FD_DAT 3 
+#define FD_LNK 8 
+#define FD_SIZ 9 
+#define FD_Creat 13 
+#define FD_SEG 16 
+
+
 /*
  *   os9 directory structure
  *
@@ -158,24 +177,25 @@
  *DIR.FD         RMB       3                   File descriptor physical sector number
  *DIR.SZ         EQU       .                   Directory record size
  */
+#define DIR_SZ 32
+#define DIR_NM 29
 
 
 /* read direcotry entry */
-int os9opendir(PathDesc pd) {
+int os9opendir(PathDesc *pd) {
     DIR *dir;
     struct dirent *dp;
     dir = opendir(pd->name);
-    pd->name=fname;
     int dircount = 0;
-    while ((dp = readdir(dirp)) != NULL) dircout++;   // pass 1 to determine the size
+    while ((dp = readdir(dir)) != NULL) dircount++;   // pass 1 to determine the size
     if (dircount==0) return 0;  // should contains . and .. at least
-    pd->sz = dircount*DIR_SZ
+    pd->sz = dircount*DIR_SZ;
     pd->dirfp = (char *)malloc(dircount*DIR_SZ);
     rewinddir(dir);
     int i = 0;
-    while ((dp = readdir(dirp)) != NULL) {
+    while ((dp = readdir(dir)) != NULL) {
         i += DIR_SZ;
-        if (i>pd->SZ) return 0;
+        if (i>pd->sz) return 0;
         int j = 0;
         for(j = 0; j < DIR_NM ; j++) {
             if (j< dp->d_namlen) 
@@ -183,14 +203,17 @@
             else
                pd->dirfp[j] = 0;
         }
-        pd->dirfp[j] = (d_ino&0xff0000)>>16;
-        pd->dirfp[j+1] = (d_ino&0xff00)>>8;
-        pd->dirfp[j+2] = d_ino&0xff;
+        pd->dirfp[j] = (dp->d_ino&0xff0000)>>16;
+        pd->dirfp[j+1] = (dp->d_ino&0xff00)>>8;
+        pd->dirfp[j+2] = dp->d_ino&0xff;
     }
     pd->fp = fmemopen(pd->dirfp,pd->sz,"r");
     return 0;
 }
 
+void os9setdate(char *d,struct timespec * unixtime) {
+    //   yymmddhhss
+}
 
 /* read file descriptor of Path Desc 
  *    create file descriptor sector if necessary
@@ -200,18 +223,18 @@
     struct stat st;
     if (pd->fd) return 1;
     pd->fd = (char *)malloc(256);
-    stat((pd->name,&st);
-    os9setmode(pd->fd,st.st_mode);
-    pd->fd+FD_OWN=(st.st_uid&0xff00)>>8;
-    pd->fd+FD_OWN+1=st.st_uid&0xff;
-    os9setdate(pd->fd,st.st_mtimespec);
-    pd->fd+FD_LNK+0=(st.st_uid&0xff000000)>>24;
-    pd->fd+FD_LNK+1=(st.st_uid&0xff0000)>>16;
-    pd->fd+FD_LNK+2=(st.st_uid&0xff00)>>8;
-    pd->fd+FD_LNK+3=st.st_nlink&0xff;
-    os9setdate(pd->fd,st.st_ctimespec);
+    stat(pd->name,&st);
+    os9setmode(pd->fd+FD_ATT,st.st_mode);
+    pd->fd[FD_OWN]=(st.st_uid&0xff00)>>8;
+    pd->fd[FD_OWN+1]=st.st_uid&0xff;
+    os9setdate(pd->fd + FD_DAT,&st.st_mtimespec);
+    pd->fd[FD_LNK+0]=(st.st_uid&0xff000000)>>24;
+    pd->fd[FD_LNK+1]=(st.st_uid&0xff0000)>>16;
+    pd->fd[FD_LNK+2]=(st.st_uid&0xff00)>>8;
+    pd->fd[FD_LNK+3]=st.st_nlink&0xff;
+    os9setdate(pd->fd+FD_Creat,&st.st_ctimespec);
     // dummy segment list
-    for(int i=0x10 ; i < 256; i++) pd->fd[i] = 0;
+    for(int i=FD_SEG ; i < 256; i++) pd->fd[i] = 0;
     return 0;
 }
 
@@ -221,7 +244,7 @@
  *     inode==0 should return disk id section
  *     inode==bitmap should return disk sector map for os9 free command
  */
-int fdinfo(Byte *buf,int len, int inode) {
+int fdinfo(Byte *buf,int len, int inode, PathDesc *pd) {
     int i;
     for(i=0;i<MAXPDV;i++) {
         PathDesc *pd = pdv+i;
@@ -231,7 +254,7 @@
         while( dir < dir + pd->sz ) {
             Byte *p = (Byte *)(dir + DIR_NM);
             int dinode = (p[0]<<16)+(p[1]<<8)+p[2];
-            if (inode == dir) {
+            if (inode == dinode) {
                 filedescriptor(buf,len,pd);
                 return 1;
             }
@@ -245,11 +268,13 @@
  *
  *   name or buffer, can be in a user map, pmem check that drive number ( mem[0x41+IOPAGE]  0 sys 1 user )
  *   current directory path number                                        mem[0x42+IOPAGE]  
+ *   yreg has pd number
  */
 void do_vdisk(Byte cmd) {
     int err;
-    PathDesc *pd = pdv + *areg;
-    PathDesc *curdir = pdv+mem[0x42+IOPAGE];
+    PathDesc *pd = pdv + yreg;
+    PathDesc *curdir = pdv+mem[0x43+IOPAGE];
+    pd->drv = mem[0x41+IOPAGE];
     Byte mode,attr ;
     char *path,*next,*buf;
 
@@ -305,7 +330,7 @@
             attr = *breg;
             pd->fp = 0;
             path = (char*)pmem(xreg);
-            next = pd->name = checkFileName(path,pd,curdir);
+            next = checkFileName(path,pd,curdir);
             if (next!=0) {
                 struct stat buf;
                 if (stat(pd->name,&buf)!=0) break;
@@ -313,11 +338,8 @@
                     pd->dir = 1;
                     os9opendir(pd);
                 } else {
-                    char *fname;
                     pd->dir = 0;
-                    if (curdir==0 && name[0]!='/') return 0; // no current directory
-                    pd->fp = fopen( fname=findfile(pd->name,curdir),"r+");
-                    free(fname);
+                    pd->fp = fopen( pd->name,os9toUnixAttr(mode));
                 }
             }
             if (next!=0 && pd->fp !=0) {
@@ -407,7 +429,7 @@
             path = (char*)pmem(xreg);
             next = checkFileName(path,pd,curdir);
             if (next!=0 && stat(pd->name,&st)!=0) break;
-            if (next!=0 && ((st->st_mode&S_IFDIR)?rmdir(pd->name):unlink(pd->name)) == 0) {
+            if (next!=0 && ((st.st_mode&S_IFDIR)?rmdir(pd->name):unlink(pd->name)) == 0) {
                 xreg += ( next - path );
                 *breg = 0;
             }