Mercurial > hg > Members > kono > os9 > sbc09
annotate src/vdisk.c @ 149:2f71506f980f
fmemopen mess
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 17 Jan 2019 07:51:13 +0900 |
parents | fa0fbcbccbc9 |
children | da020c491fbb |
rev | line source |
---|---|
43 | 1 /******************************************************************** |
2 * Virtual RBF - Random Block File Manager | |
3 * | |
4 * Shinji KONO (kono@ie.u-ryukyu.ac.jp) 2018/7/17 | |
5 * GPL v1 license | |
6 */ | |
7 | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
8 #define engine extern |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
9 #include "v09.h" |
43 | 10 #include <stdio.h> |
11 #include <stdlib.h> | |
12 #include <unistd.h> | |
13 #include <sys/stat.h> | |
14 #include <sys/select.h> | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
15 #include <dirent.h> |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
16 #include <string.h> |
47 | 17 #include <time.h> |
49 | 18 #include <arpa/inet.h> |
61 | 19 #include <fcntl.h> |
43 | 20 |
62 | 21 static int vdiskdebug = 0; // bit 1 trace, bit 2 filename |
43 | 22 |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
23 |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
24 Byte pmmu[8]; // process dat mmu |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
25 |
49 | 26 extern char *prog ; // for disass |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
27 #ifdef USE_MMU |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
28 extern Byte * mem0(Byte *iphymem, Word adr, Byte *immu) ; |
47 | 29 // smem physical address using system mmu |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
30 // pmem physical address using caller's mmu |
46 | 31 #define smem(a) mem0(phymem,a,&mem[0x20+IOPAGE]) |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
32 #define pmem(a) mem0(phymem,a,pmmu) |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
33 #else |
46 | 34 #define smem(a) (&mem[a]) |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
35 #define pmem(a) (&mem[a]) |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
36 #endif |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
37 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
38 #define MAXPDV 256 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
39 |
59 | 40 /* |
41 * os9 has one path descriptor for one open file or directory | |
42 * keep coresponding information in vdisk file manager | |
43 */ | |
45 | 44 |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
45 typedef struct pathDesc { |
59 | 46 char *name; // path name relative to drvRoot |
47 FILE *fp; // file , memfile for directory | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
48 int mode; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
49 int inode ; // lower 24 bit of unix inode, os9 lsn |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
50 int num ; |
45 | 51 int sz ; // used only for directory |
52 char drv ; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
53 char use ; |
59 | 54 char dir; // is directory? |
55 char *fd ; // simulated os9 file descriptor ( not used now) | |
56 char *dirfp; // simulated os9 directory file | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
57 } PathDesc, *PathDescPtr; |
43 | 58 |
49 | 59 static void |
60 vdisklog(Word u,PathDesc *pd, Word pdptr, int curdir,FILE *fp) ; | |
61 | |
45 | 62 #define MAXVDRV 4 |
43 | 63 |
49 | 64 static char *drvRoot[] = { ".",".",".","."}; |
65 static PathDesc pdv[MAXPDV]; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
66 |
49 | 67 /* |
59 | 68 * byte order staff |
49 | 69 */ |
70 static inline Word | |
71 getword(Byte *adr) { | |
72 Word *padr = (Word*)adr; | |
73 return ntohs(*padr); | |
74 } | |
75 | |
76 static inline void | |
77 setword(Byte *adr,Word value) { | |
78 Word *padr = (Word*)adr; | |
79 *padr = htons(value); | |
80 } | |
81 | |
59 | 82 int |
49 | 83 setVdisk(int drv,char *name) { |
45 | 84 if (drv<0 || drv>=MAXVDRV) return -1; |
85 drvRoot[drv] = name; | |
86 return 0; | |
87 } | |
88 | |
49 | 89 static void |
90 closepd(PathDesc *pd) { | |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
91 if(pd->fp) fclose(pd->fp) ; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
92 pd->dir = 0; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
93 pd->use = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
94 pd->fp = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
95 pd->mode = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
96 free(pd->dirfp); pd->dirfp = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
97 free(pd->name); pd->name = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
98 } |
43 | 99 |
49 | 100 /* |
101 * keep track current directory ( most recently 256 entry ) | |
102 * too easy approach | |
59 | 103 * |
104 * dir command keep old directory LSN, so we have to too | |
49 | 105 */ |
106 char *cdt[512]; | |
107 static int cdtptr = 0; | |
108 | |
109 Byte | |
110 setcd(char *name) { | |
111 int len; | |
51 | 112 for(int i=0;i<512;i++) { |
49 | 113 if (cdt[i] && strcmp(name,cdt[i])==0) return i; |
114 } | |
51 | 115 cdtptr &= 0x1ff; |
49 | 116 if (cdt[cdtptr]) free(cdt[cdtptr]); |
117 cdt[cdtptr] = (char*)malloc(len=strlen(name)+1); | |
118 strcpy(cdt[cdtptr],name); | |
119 return cdtptr++; | |
120 } | |
121 | |
43 | 122 #define MAXPAHTLEN 256 |
123 | |
59 | 124 /* |
125 * print os9 string for debug | |
126 */ | |
49 | 127 static void |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
128 putOs9str(char *s,int max) { |
49 | 129 if (s==0) { |
130 printf("(null)"); | |
131 return; | |
132 } | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
133 while(*s && (*s&0x7f)>=' ' && ((*s&0x80)==0) && --max !=0) { |
49 | 134 putchar(*s); s++; |
135 } | |
136 if (*s&0x80) putchar(*s&0x7f); | |
137 } | |
138 | |
51 | 139 static void |
140 err(int error) { | |
141 printf("err %d\n",error); | |
142 } | |
143 | |
59 | 144 /* |
145 * add current directory name to the path | |
146 * if name starts /v0, drvRoot will be add | |
147 */ | |
49 | 148 static char * |
149 addCurdir(char *name, PathDesc *pd, int curdir) { | |
46 | 150 int ns =0 ; |
47 | 151 char *n = name; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
152 if(vdiskdebug&0x2) { printf("addcur \""); putOs9str(name,0); printf("\" cur \""); putOs9str( cdt[curdir],0); printf("\"\n"); } |
46 | 153 if (name[0]=='/') { |
49 | 154 name++; while(*name !='/' && *name!=0) name ++ ; // skip /d0 |
46 | 155 while(name[ns]!=0) ns++; |
49 | 156 } else if (!cdt[curdir] ) return 0; // no current directory |
157 else ns = strlen(name); | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
158 int ps = ns; |
45 | 159 char *base ; |
49 | 160 if (name[0]=='/') { |
161 base = drvRoot[pd->drv]; ps += strlen(drvRoot[pd->drv])+1; name++; | |
47 | 162 } else if (name[0]==0) { |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
163 base = drvRoot[pd->drv]; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
164 char *path = (char*)malloc(strlen(base)+1); // we'll free this, malloc it. |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
165 int i = 0; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
166 for(;base[i];i++) path[i] = base[i]; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
167 path[i]=0; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
168 return path; |
47 | 169 } else { |
49 | 170 base = cdt[curdir]; ps += strlen(cdt[curdir])+2; |
47 | 171 } |
49 | 172 char *path = (char*)malloc(ps); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
173 int i = 0; |
45 | 174 for(;base[i];i++) path[i] = base[i]; |
175 path[i++] = '/'; | |
51 | 176 for(int j=0;i<ps;j++,i++) path[i] = name[j]; |
177 path[i] = 0; | |
178 if (i>ps) | |
179 printf("overrun i=%d ps=%d\n",i,ps); // err(__LINE__); | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
180 return path; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
181 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
182 |
59 | 183 /* |
184 * os9 file name may contains garbage such as 8th bit on or traling space | |
185 * fix it. and make the pointer to next path for the return value | |
186 * | |
187 * pd->name will be freed, we have to malloc it | |
188 */ | |
49 | 189 static char * |
190 checkFileName(char *path, PathDesc *pd, int curdir) { | |
43 | 191 char *p = path; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
192 char *name = path; |
43 | 193 int maxlen = MAXPAHTLEN; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
194 if(vdiskdebug&2) { printf("checkf \""); putOs9str(name,0); printf("\"\n"); } |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
195 while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++; |
43 | 196 if (maxlen==MAXPAHTLEN) return 0; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
197 if (*p) { // 8th bit termination or non ascii termination |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
198 int eighth = ((*p&0x80)!=0); |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
199 name = (char *)malloc(p-path+1+eighth); |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
200 int i; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
201 for(i=0;i<p-path;i++) name[i] = path[i]; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
202 if (eighth) { name[i] = path[i]&0x7f; p++ ; i++; } |
51 | 203 name[i] = 0; |
61 | 204 // skip trailing space |
205 while(*p==' ') p++; | |
43 | 206 } |
45 | 207 char *name1 = addCurdir(name,pd,curdir); |
71 | 208 if (name1!=name && path!=name) free(name); |
47 | 209 if (name1==0) return 0; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
210 pd->name = name1; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
211 if(vdiskdebug&2) { |
49 | 212 printf(" remain = \""); |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
213 char *p1 = p; int max=31; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
214 while(*p1 && (*p1&0x80)==0 && max-->0) { if (*p1<0x20) printf("(0x%02x)",*p1); else putchar(*p1); p1++; } |
49 | 215 if (*p1) { if ((*p1&0x7f)<0x20) printf("(0x%02x)",*p1); else putchar(*p1&0x7f); } |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
216 printf("\" checkname result \""); putOs9str(pd->name,0); printf("\"\n"); |
49 | 217 } |
43 | 218 return p; |
219 } | |
220 | |
59 | 221 /* |
222 * os9 / unix mode conversion | |
223 */ | |
49 | 224 static void |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
225 os9setmode(Byte *os9mode,int mode) { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
226 char m = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
227 if (mode&S_IFDIR) m|=0x80; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
228 if (mode&S_IRUSR) m|=0x01; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
229 if (mode&S_IWUSR) m|=0x02; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
230 if (mode&S_IXUSR) m|=0x04; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
231 if (mode&S_IROTH) m|=0x08; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
232 if (mode&S_IWOTH) m|=0x10; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
233 if (mode&S_IXOTH) m|=0x20; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
234 m|=0x60; // always sharable |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
235 *os9mode = m; |
43 | 236 } |
237 | |
49 | 238 static char * |
61 | 239 os9toUnixAttr(Byte mode) { |
240 if ((mode&0x1) && (mode&0x2)) return "r+"; | |
241 if (!(mode&0x1) && (mode&0x2)) return "w"; | |
242 if ((mode&0x1) && !(mode&0x2)) return "r"; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
243 return "r"; |
43 | 244 } |
245 | |
61 | 246 static int |
247 os9mode(Byte m) { | |
248 int mode = 0; | |
249 if ((m&0x80)) mode|=S_IFDIR ; | |
250 if ((m&0x01)) mode|=S_IRUSR ; | |
251 if ((m&0x02)) mode|=S_IWUSR ; | |
252 if ((m&0x04)) mode|=S_IXUSR ; | |
253 if ((m&0x08)) mode|=S_IROTH ; | |
254 if ((m&0x10)) mode|=S_IWOTH ; | |
255 if ((m&0x20)) mode|=S_IXOTH ; | |
256 return mode; | |
257 } | |
258 | |
149 | 259 #if defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL < 200809L |
148
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
260 |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
261 FILE *fmemopen(char *buf,long sz, const char *mode) { |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
262 static char fname[] = "/tmp/myfileXXXXXX"; |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
263 int fd; |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
264 fd = mkstemp(fname); /* Create and open temp file */ |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
265 write(fd, buf, sz); /* Write something to file */ |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
266 lseek(fd, 0L, SEEK_SET); |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
267 FILE *fp = fdopen(fd,mode); |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
268 unlink(fname); |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
269 return fp; |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
270 } |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
271 |
fa0fbcbccbc9
add easy fmemopen replacement
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
272 #endif |
61 | 273 |
43 | 274 /* |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
275 * os9 file descriptor |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
276 * * File Descriptor Format |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
277 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
278 * The file descriptor is a sector that is present for every file |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
279 * on an RBF device. It contains attributes, modification dates, |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
280 * and segment information on a file. |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
281 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
282 * ORG 0 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
283 *FD.ATT RMB 1 Attributes |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
284 *FD.OWN RMB 2 Owner |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
285 *FD.DAT RMB 5 Date last modified |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
286 *FD.LNK RMB 1 Link count |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
287 *FD.SIZ RMB 4 File size |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
288 *FD.Creat RMB 3 File creation date (YY/MM/DD) |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
289 *FD.SEG EQU . Beginning of segment list |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
290 * Segment List Entry Format |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
291 ORG 0 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
292 * FDSL.A RMB 3 Segment beginning physical sector number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
293 * FDSL.B RMB 2 Segment size |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
294 * FDSL.S EQU . Segment list entry size |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
295 * FD.LS1 EQU FD.SEG+((256-FD.SEG)/FDSL.S-1)*FDSL.S |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
296 * FD.LS2 EQU (256/FDSL.S-1)*FDSL.S |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
297 * MINSEC SET 16 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
298 */ |
43 | 299 |
45 | 300 #define FD_ATT 0 |
301 #define FD_OWN 1 | |
302 #define FD_DAT 3 | |
303 #define FD_LNK 8 | |
304 #define FD_SIZ 9 | |
305 #define FD_Creat 13 | |
306 #define FD_SEG 16 | |
307 | |
308 | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
309 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
310 * os9 directory structure |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
311 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
312 * ORG 0 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
313 *DIR.NM RMB 29 File name |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
314 *DIR.FD RMB 3 File descriptor physical sector number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
315 *DIR.SZ EQU . Directory record size |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
316 */ |
45 | 317 #define DIR_SZ 32 |
318 #define DIR_NM 29 | |
43 | 319 |
320 | |
59 | 321 /* read direcotry entry |
322 * | |
323 * create simulated os9 directory structure for dir command | |
324 * writing to the directory is not allowed | |
325 * */ | |
49 | 326 static int |
327 os9opendir(PathDesc *pd) { | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
328 DIR *dir; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
329 struct dirent *dp; |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
330 if (pd->dirfp) return 0; // already opened |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
331 dir = opendir(pd->name); |
47 | 332 if (dir==0) return -1; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
333 int dircount = 0; |
45 | 334 while ((dp = readdir(dir)) != NULL) dircount++; // pass 1 to determine the size |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
335 if (dircount==0) return 0; // should contains . and .. at least |
45 | 336 pd->sz = dircount*DIR_SZ; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
337 pd->dirfp = (char *)malloc(dircount*DIR_SZ); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
338 rewinddir(dir); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
339 int i = 0; |
51 | 340 while ((dp = readdir(dir)) != NULL && dircount-->=0) { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
341 int j = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
342 for(j = 0; j < DIR_NM ; j++) { |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
343 if (j< dp->d_namlen) { |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
344 pd->dirfp[i+j] = dp->d_name[j]&0x7f; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
345 if (j== dp->d_namlen-1) |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
346 pd->dirfp[i+j] |= 0x80; // os9 EOL |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
347 } else |
47 | 348 pd->dirfp[i+j] = 0; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
349 } |
47 | 350 pd->dirfp[i+j] = (dp->d_ino&0xff0000)>>16; |
351 pd->dirfp[i+j+1] = (dp->d_ino&0xff00)>>8; | |
352 pd->dirfp[i+j+2] = dp->d_ino&0xff; | |
353 i += DIR_SZ; | |
51 | 354 if (i>pd->sz) |
355 return 0; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
356 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
357 pd->fp = fmemopen(pd->dirfp,pd->sz,"r"); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
358 return 0; |
43 | 359 } |
360 | |
49 | 361 static void |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
362 os9setdate(Byte *d,struct timespec * unixtime) { |
45 | 363 // yymmddhhss |
47 | 364 struct tm r; |
365 localtime_r(&unixtime->tv_sec,&r); | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
366 d[0] = r.tm_year-2048; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
367 d[1] = r.tm_mon + 1; |
47 | 368 d[2] = r.tm_mday; |
369 d[3] = r.tm_hour; | |
370 d[4] = r.tm_min; | |
371 d[5] = r.tm_sec; | |
45 | 372 } |
43 | 373 |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
374 /* read file descriptor of Path Desc |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
375 * create file descriptor sector if necessary |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
376 * if buf!=0, copy it |
59 | 377 * |
378 * only dir command accesses this using undocumented getstat fdinfo command | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
379 */ |
49 | 380 static int |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
381 filedescriptor(Byte *buf, int len, Byte *name,int curdir) { |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
382 int err = 0x255; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
383 PathDesc pd; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
384 if (len<13) return -1; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
385 checkFileName((char*)name,&pd,curdir); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
386 struct stat st; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
387 if (stat(pd.name,&st)!=0) goto err1; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
388 os9setmode(buf+FD_ATT,st.st_mode); |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
389 buf[FD_OWN]=(st.st_uid&0xff00)>>8; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
390 buf[FD_OWN+1]=st.st_uid&0xff; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
391 os9setdate(buf+ FD_DAT,&st.st_mtimespec); |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
392 buf[FD_LNK]=st.st_nlink&0xff; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
393 buf[FD_SIZ+0]=(st.st_size&0xff000000)>>24; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
394 buf[FD_SIZ+1]=(st.st_size&0xff0000)>>16; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
395 buf[FD_SIZ+2]=(st.st_size&0xff00)>>8; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
396 buf[FD_SIZ+3]=st.st_size&0xff; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
397 os9setdate(buf+FD_Creat,&st.st_ctimespec); |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
398 err = 0; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
399 err1: |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
400 free(pd.name); |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
401 return err; |
43 | 402 } |
403 | |
59 | 404 /* |
405 * undocumented getstat command | |
406 * | |
407 * read direcotry entry for *any* file in the directory | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
408 * we only returns a file descriptor only in the current opened directory |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
409 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
410 * inode==0 should return disk id section |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
411 * inode==bitmap should return disk sector map for os9 free command |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
412 */ |
49 | 413 static int |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
414 fdinfo(Byte *buf,int len, int inode, PathDesc *pd,int curdir) { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
415 int i; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
416 for(i=0;i<MAXPDV;i++) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
417 PathDesc *pd = pdv+i; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
418 if (!pd->use || !pd->dir) continue; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
419 // find inode in directory |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
420 Byte *dir = (Byte*)pd->dirfp; |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
421 Byte *end = (Byte*)pd->dirfp + pd->sz; |
49 | 422 while( dir < end ) { |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
423 Byte *p = (dir + DIR_NM); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
424 int dinode = (p[0]<<16)+(p[1]<<8)+p[2]; |
45 | 425 if (inode == dinode) { |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
426 return filedescriptor(buf,len,dir,curdir); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
427 } |
49 | 428 dir += 0x20; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
429 } |
43 | 430 } |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
431 return 255; |
43 | 432 } |
433 | |
59 | 434 /* |
435 * on os9 level 2, user process may on different memory map | |
436 * get DAT table on process descriptor on 0x50 in system page | |
437 */ | |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
438 void |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
439 getDAT() { |
59 | 440 #ifdef USE_MMU |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
441 Word ps = getword(smem(0x50)); // process structure |
59 | 442 Byte *dat = smem(ps+0x40); // process dat (dynamic address translation) |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
443 for(int i=0; i<8; i++) { |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
444 pmmu[i] = dat[i*2+1]; |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
445 } |
59 | 446 #endif |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
447 } |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
448 |
43 | 449 /* |
59 | 450 * vdisk command processing |
451 * | |
452 * vrbf.asm will write a command on 0x40+IOPAGE ( 0xffc0 or 0xe040) | |
453 * | |
454 * U contains caller's stack (call and return value) on 0x45+IOPAGE | |
455 * current directory (cwd or cxd) on 0x44+IOPAGE | |
456 * Path dcriptor number on 0x47+IOPAGE | |
457 * drive number on 0x41+IOPAGE | |
458 * caller's process descriptor on <0x50 | |
459 * | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
460 * each command should have preallocated os9 path descriptor on Y |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
461 * |
49 | 462 * name or buffer, can be in a user map, check that drive number ( mem[0x41+IOPAGE] 0 sys 1 user ) |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
463 * current directory path number mem[0x42+IOPAGE] |
45 | 464 * yreg has pd number |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
465 */ |
49 | 466 void |
467 do_vdisk(Byte cmd) { | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
468 int err; |
49 | 469 int curdir = mem[0x44+IOPAGE]; // garbage until set |
46 | 470 Byte attr ; |
49 | 471 Word u = getword(&mem[0x45+IOPAGE]); // caller's stack in system segment |
472 Byte *frame = smem(u); | |
473 xreg = getword(frame+4); | |
474 yreg = getword(frame+6); | |
46 | 475 *areg = *smem(u+1); |
476 *breg = *smem(u+2); | |
49 | 477 Byte mode = 0; |
478 Byte *os9pd = smem(getword(&mem[0x47+IOPAGE])); | |
47 | 479 PathDesc *pd = pdv+*os9pd; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
480 |
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
481 getDAT(); |
47 | 482 pd->num = *os9pd; |
483 pd->drv = mem[0x41+IOPAGE]; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
484 char *path,*next,*buf; |
49 | 485 if (vdiskdebug&1) vdisklog(u,pd,getword(&mem[0x47+IOPAGE]),curdir,stdout); |
43 | 486 |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
487 switch(cmd) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
488 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
489 * I$Create Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
490 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
491 * Entry: A = access mode desired |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
492 * B = file attributes |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
493 * X = address of the pathlist |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
494 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
495 * Exit: A = pathnum |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
496 * X = last byte of pathlist address |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
497 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
498 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
499 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
500 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
501 case 0xd1: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
502 mode = *areg; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
503 attr = *breg; |
61 | 504 pd->fp = 0; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
505 path = (char *)pmem(xreg); |
61 | 506 next = checkFileName(path,pd,curdir); |
507 *breg = 0xff; | |
508 int fd = open(pd->name, O_RDWR+O_CREAT,os9mode(attr) ); | |
509 if (fd>0) | |
510 pd->fp = fdopen(fd, os9toUnixAttr(mode)); | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
511 if (next!=0 && pd->fp ) { |
61 | 512 *breg = 0; |
513 *areg = pd->num; | |
514 *smem(u+1) = *areg ; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
515 xreg += ( next - path ); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
516 pd->use = 1; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
517 } else { |
47 | 518 pd->use = 0; |
43 | 519 } |
520 break; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
521 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
522 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
523 * I$Open Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
524 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
525 * Entry: A = access mode desired |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
526 * X = address of the pathlist |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
527 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
528 * Exit: A = pathnum |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
529 * X = last byte of pathlist address |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
530 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
531 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
532 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
533 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
534 case 0xd2: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
535 mode = *areg; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
536 attr = *breg; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
537 pd->fp = 0; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
538 path = (char*)pmem(xreg); |
45 | 539 next = checkFileName(path,pd,curdir); |
47 | 540 *breg = 0xff; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
541 if (next!=0) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
542 struct stat buf; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
543 if (stat(pd->name,&buf)!=0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
544 if ((buf.st_mode & S_IFMT) == S_IFDIR) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
545 pd->dir = 1; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
546 os9opendir(pd); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
547 } else { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
548 pd->dir = 0; |
45 | 549 pd->fp = fopen( pd->name,os9toUnixAttr(mode)); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
550 } |
47 | 551 pd->use = 1; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
552 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
553 if (next!=0 && pd->fp !=0) { |
47 | 554 *breg = 0; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
555 *areg = pd->num; |
49 | 556 *smem(u+1) = *areg ; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
557 xreg += ( next - path ); |
47 | 558 pd->use = 1; |
559 } else { | |
560 pd->use = 0; | |
561 } | |
43 | 562 break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
563 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
564 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
565 * I$MakDir Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
566 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
567 * Entry: X = address of the pathlist |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
568 * B = directory attributes |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
569 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
570 * Exit: X = last byte of pathlist address |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
571 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
572 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
573 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
574 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
575 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
576 case 0xd3: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
577 *breg = 0xff; |
63 | 578 mode = *areg; |
579 attr = *breg; | |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
580 path = (char*)pmem(xreg); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
581 next = checkFileName(path,pd,curdir); |
63 | 582 if (next!=0 && mkdir(pd->name,os9mode(attr))== 0 ) { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
583 xreg += ( next - path ); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
584 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
585 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
586 closepd(pd); |
43 | 587 break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
588 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
589 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
590 * I$ChgDir Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
591 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
592 * data dir P$DIO 3-5 contains open dir Path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
593 * exec dir P$DIO 9-11 contains open dir Path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
594 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
595 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
596 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
597 * *areg = access mode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
598 * 0 = Use any special device capabilities |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
599 * 1 = Read only |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
600 * 2 = Write only |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
601 * 3 = Update (read and write) |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
602 * Entry: X = address of the pathlist |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
603 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
604 * Exit: X = last byte of pathlist address |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
605 * A = open directory Path Number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
606 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
607 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
608 * B = errcode |
49 | 609 * |
610 * | |
611 * we keep track a cwd and a cxd for a process using 8bit id | |
61 | 612 * don't use path descriptor on y |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
613 */ |
61 | 614 case 0xd4: { |
615 PathDesc dm = *pd; | |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
616 path = (char*)pmem(xreg); |
61 | 617 next = checkFileName(path,&dm,curdir); |
49 | 618 if (next!=0) { |
619 struct stat buf; | |
61 | 620 if (stat(dm.name,&buf)!=0) break; |
49 | 621 if ((buf.st_mode & S_IFMT) != S_IFDIR) break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
622 xreg += ( next - path ); |
61 | 623 *areg = setcd(dm.name); |
49 | 624 *smem(u+1) = *areg ; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
625 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
626 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
627 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
628 *breg = 0xff; |
61 | 629 } |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
630 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
631 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
632 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
633 * I$Delete Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
634 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
635 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
636 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
637 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
638 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
639 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
640 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
641 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
642 case 0xd5: { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
643 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
644 if (pd==0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
645 struct stat st; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
646 path = (char*)pmem(xreg); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
647 next = checkFileName(path,pd,curdir); |
47 | 648 pd->use = 0; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
649 if (next!=0 && stat(pd->name,&st)!=0) break; |
45 | 650 if (next!=0 && ((st.st_mode&S_IFDIR)?rmdir(pd->name):unlink(pd->name)) == 0) { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
651 xreg += ( next - path ); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
652 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
653 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
654 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
655 break; |
43 | 656 |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
657 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
658 * I$Seek Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
659 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
660 * Entry Conditions |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
661 * A path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
662 * X MS 16 bits of the desired file position |
49 | 663 * U LS 16 bits of the desired file position |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
664 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
665 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
666 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
667 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
668 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
669 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
670 case 0xd6: { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
671 *breg = 0xff; |
49 | 672 ureg = (*smem(u+8)<<8)+*smem(u+9); |
673 off_t seek = (xreg<<16)+ureg; | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
674 *breg = fseek(pd->fp,(off_t)seek,SEEK_SET); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
675 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
676 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
677 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
678 * I$ReadLn Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
679 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
680 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
681 * Entry Conditions in correct mmu map |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
682 * A path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
683 * X address at which to store data |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
684 * Y maximum number of bytes to read |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
685 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
686 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
687 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
688 * Y number of bytes read |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
689 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
690 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
691 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
692 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
693 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
694 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
695 case 0xd7: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
696 *breg = 0xff; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
697 buf = (char*)pmem(xreg); |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
698 char *b; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
699 if ((b=fgets(buf,yreg,pd->fp))) { |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
700 if (b==0) { |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
701 *breg = 0xd3; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
702 break; |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
703 } |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
704 int i; |
49 | 705 for(i=0;i<yreg && buf[i];i++); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
706 if (i>0 && buf[i-1]=='\n') { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
707 buf[i-1] = '\r'; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
708 yreg = i; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
709 } |
49 | 710 // set y |
711 setword(smem(u+6),yreg); | |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
712 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
713 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
714 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
715 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
716 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
717 * I$Read Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
718 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
719 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
720 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
721 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
722 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
723 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
724 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
725 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
726 case 0xd8: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
727 *breg = 0xff; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
728 buf = (char*)pmem(xreg); |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
729 int i = fread(buf,1,yreg,pd->fp); |
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
730 // set y |
49 | 731 setword(smem(u+6),i); |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
732 *breg = (i==0?0xd3:0) ; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
733 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
734 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
735 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
736 * I$WritLn Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
737 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
738 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
739 * A path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
740 * X address of the data to write |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
741 * Y maximum number of bytes to read |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
742 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
743 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
744 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
745 * Y number of bytes written |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
746 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
747 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
748 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
749 */ |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
750 case 0xd9: { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
751 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
752 if (pd->dir) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
753 int len = yreg; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
754 int i = 0; |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
755 Byte *buf = pmem(xreg); |
61 | 756 while(len>0 && buf[i] !='\r') { |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
757 fputc(buf[i++],pd->fp); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
758 len--; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
759 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
760 if (buf[i]=='\r') { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
761 fputc('\n',pd->fp); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
762 i++; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
763 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
764 *breg = 0; |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
765 // set y |
49 | 766 setword(smem(u+6),i); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
767 break; |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
768 } |
43 | 769 |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
770 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
771 * I$Write Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
772 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
773 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
774 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
775 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
776 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
777 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
778 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
779 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
780 case 0xda : |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
781 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
782 if (!pd->dir) { |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
783 Byte *buf = pmem(xreg); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
784 int len = yreg; |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
785 int err = fwrite(buf,1,len,pd->fp); |
49 | 786 *breg = err?0:0xff; |
48
ea1b17311bf3
dir /v0 worked but dir /v0/src and chd /v0; dir does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
787 // set y |
49 | 788 setword(smem(u+6),err); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
789 } |
43 | 790 break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
791 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
792 /* I$Close Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
793 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
794 * Entry: A = path number |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
795 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
796 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
797 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
798 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
799 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
800 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
801 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
802 case 0xdb: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
803 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
804 if (pd==0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
805 closepd(pd); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
806 *breg = 0; |
43 | 807 break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
808 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
809 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
810 * I$GetStat Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
811 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
812 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
813 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
814 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
815 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
816 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
817 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
818 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
819 case 0xdc: { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
820 struct stat st; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
821 off_t pos; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
822 switch (*breg) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
823 case 01: // SS.Ready |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
824 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
825 if (pd==0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
826 fstat(fileno(pd->fp),&st); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
827 if ((pos = ftell(pd->fp))) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
828 xreg = st.st_size - pos; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
829 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
830 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
831 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
832 case 02: // SS.SIZ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
833 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
834 if (pd==0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
835 fstat(fileno(pd->fp),&st); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
836 xreg = st.st_size ; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
837 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
838 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
839 case 05: // SS.Pos |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
840 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
841 if (pd==0) break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
842 xreg = ftell(pd->fp); |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
843 *breg = 0; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
844 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
845 case 15: // SS.FD |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
846 /* SS.FD ($0F) - Returns a file descriptor |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
847 * Entry: R$A=Path # |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
848 * R$B=SS.FD ($0F) |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
849 * R$X=Pointer to a 256 byte buffer |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
850 * R$Y=# bytes of FD required |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
851 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
852 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
853 if (pd==0) break; |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
854 *breg = filedescriptor(pmem(xreg), yreg,(Byte*)pd->name,curdir) ; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
855 break; |
59 | 856 case 0x20: // Pos.FDInf mandatry for dir command (undocumented, use the source) |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
857 /* SS.FDInf ($20) - Directly reads a file descriptor from anywhere |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
858 * on drive. |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
859 * Entry: R$A=Path # |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
860 * R$B=SS.FDInf ($20) |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
861 * R$X=Pointer to a 256 byte buffer |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
862 * R$Y= MSB - Length of read |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
863 * LSB - MSB of logical sector # |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
864 * R$U= LSW of logical sector # |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
865 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
866 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
867 if (pd==0) break; |
49 | 868 ureg = getword(smem(u+8)); |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
869 *breg = fdinfo(pmem(xreg),(yreg&0xff),((yreg&0xff00)>>8)*0x10000+ureg,pd,curdir); |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
870 break; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
871 default: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
872 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
873 } |
43 | 874 break; |
44
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
875 } |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
876 |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
877 /* |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
878 * I$SetStat Entry Point |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
879 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
880 * Entry: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
881 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
882 * Exit: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
883 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
884 * |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
885 * Error: CC Carry set |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
886 * B = errcode |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
887 */ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
888 case 0xdd: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
889 switch (*breg) { |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
890 case 0: // SS.Opt |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
891 case 02: // SS.SIZ |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
892 case 15: // SS.FD |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
893 case 0x11: // SS.Lock |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
894 case 0x10: // SS.Ticks |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
895 case 0x20: // SS.RsBit |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
896 case 0x1c: // SS.Attr |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
897 default: |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
898 *breg = 0xff; |
b26c23331d02
add more function on vdisk
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
43
diff
changeset
|
899 } |
43 | 900 break; |
901 } | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
902 if (vdiskdebug && *breg) printf(" vdisk call error %x\n",*breg); |
46 | 903 // return value |
56 | 904 mem[0x40+IOPAGE] = *breg; |
46 | 905 *smem(u+2) = *breg ; |
49 | 906 setword(smem(u+4),xreg); |
907 } | |
46 | 908 |
49 | 909 static void |
910 vdisklog(Word u,PathDesc *pd, Word pdptr, int curdir, FILE *fp) { | |
911 char *cd = cdt[curdir]?cdt[curdir]:"(null)"; | |
912 fprintf(fp,"pd %d 0x%x cd[%d]=%s ",pd->num, pdptr, curdir,cd); | |
913 Byte *frame = smem(u); | |
914 sreg = u; | |
915 ccreg = frame[0]; | |
916 *areg = frame[1]; | |
917 *breg = frame[2]; | |
918 xreg = getword(frame+4); | |
919 yreg = getword(frame+6); | |
920 ureg = getword(frame+8); | |
59 | 921 pcreg = getword(frame+10)-3; // point os9 swi2 |
50
1430678cd4fb
use process structure's mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
922 prog = (char*)(pmem(pcreg) - pcreg); |
61 | 923 if (*pmem(pcreg)==0 && *pmem(pcreg+1)==0) { |
924 // may be we are called from system state | |
925 // of coursel, this may wrong. but in system state, <$50 process has wrong DAT for pc | |
926 // and we can't know wether we are called from system or user | |
927 prog = (char*)(smem(pcreg) - pcreg); | |
928 } | |
49 | 929 do_trace(fp); |
43 | 930 } |
931 | |
932 | |
49 | 933 /* end */ |