Mercurial > hg > Members > kono > os9 > sbc09
comparison src/vdisk.c @ 59:7c6dc25c2b05
add comment
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Jul 2018 20:17:12 +0900 |
parents | 2088fd998865 |
children | 80f4ec9a3420 |
comparison
equal
deleted
inserted
replaced
58:efbe39fee3ae | 59:7c6dc25c2b05 |
---|---|
34 #define pmem(a) (&mem[a]) | 34 #define pmem(a) (&mem[a]) |
35 #endif | 35 #endif |
36 | 36 |
37 #define MAXPDV 256 | 37 #define MAXPDV 256 |
38 | 38 |
39 /* | |
40 * os9 has one path descriptor for one open file or directory | |
41 * keep coresponding information in vdisk file manager | |
42 */ | |
39 | 43 |
40 typedef struct pathDesc { | 44 typedef struct pathDesc { |
41 char *name; | 45 char *name; // path name relative to drvRoot |
42 FILE *fp; | 46 FILE *fp; // file , memfile for directory |
43 int mode; | 47 int mode; |
44 int inode ; // lower 24 bit of unix inode, os9 lsn | 48 int inode ; // lower 24 bit of unix inode, os9 lsn |
45 int num ; | 49 int num ; |
46 int sz ; // used only for directory | 50 int sz ; // used only for directory |
47 char drv ; | 51 char drv ; |
48 char use ; | 52 char use ; |
49 char dir; | 53 char dir; // is directory? |
50 char *fd ; | 54 char *fd ; // simulated os9 file descriptor ( not used now) |
51 char *dirfp; | 55 char *dirfp; // simulated os9 directory file |
52 } PathDesc, *PathDescPtr; | 56 } PathDesc, *PathDescPtr; |
53 | 57 |
54 static void | 58 static void |
55 vdisklog(Word u,PathDesc *pd, Word pdptr, int curdir,FILE *fp) ; | 59 vdisklog(Word u,PathDesc *pd, Word pdptr, int curdir,FILE *fp) ; |
56 | 60 |
58 | 62 |
59 static char *drvRoot[] = { ".",".",".","."}; | 63 static char *drvRoot[] = { ".",".",".","."}; |
60 static PathDesc pdv[MAXPDV]; | 64 static PathDesc pdv[MAXPDV]; |
61 | 65 |
62 /* | 66 /* |
63 * us 0 system | 67 * byte order staff |
64 * 1 caller | |
65 */ | 68 */ |
66 static inline Word | 69 static inline Word |
67 getword(Byte *adr) { | 70 getword(Byte *adr) { |
68 Word *padr = (Word*)adr; | 71 Word *padr = (Word*)adr; |
69 return ntohs(*padr); | 72 return ntohs(*padr); |
73 setword(Byte *adr,Word value) { | 76 setword(Byte *adr,Word value) { |
74 Word *padr = (Word*)adr; | 77 Word *padr = (Word*)adr; |
75 *padr = htons(value); | 78 *padr = htons(value); |
76 } | 79 } |
77 | 80 |
78 static int | 81 int |
79 setVdisk(int drv,char *name) { | 82 setVdisk(int drv,char *name) { |
80 if (drv<0 || drv>=MAXVDRV) return -1; | 83 if (drv<0 || drv>=MAXVDRV) return -1; |
81 drvRoot[drv] = name; | 84 drvRoot[drv] = name; |
82 return 0; | 85 return 0; |
83 } | 86 } |
94 } | 97 } |
95 | 98 |
96 /* | 99 /* |
97 * keep track current directory ( most recently 256 entry ) | 100 * keep track current directory ( most recently 256 entry ) |
98 * too easy approach | 101 * too easy approach |
102 * | |
103 * dir command keep old directory LSN, so we have to too | |
99 */ | 104 */ |
100 char *cdt[512]; | 105 char *cdt[512]; |
101 static int cdtptr = 0; | 106 static int cdtptr = 0; |
102 | 107 |
103 Byte | 108 Byte |
113 return cdtptr++; | 118 return cdtptr++; |
114 } | 119 } |
115 | 120 |
116 #define MAXPAHTLEN 256 | 121 #define MAXPAHTLEN 256 |
117 | 122 |
123 /* | |
124 * print os9 string for debug | |
125 */ | |
118 static void | 126 static void |
119 putOs9str(char *s,int max) { | 127 putOs9str(char *s,int max) { |
120 if (s==0) { | 128 if (s==0) { |
121 printf("(null)"); | 129 printf("(null)"); |
122 return; | 130 return; |
130 static void | 138 static void |
131 err(int error) { | 139 err(int error) { |
132 printf("err %d\n",error); | 140 printf("err %d\n",error); |
133 } | 141 } |
134 | 142 |
143 /* | |
144 * add current directory name to the path | |
145 * if name starts /v0, drvRoot will be add | |
146 */ | |
135 static char * | 147 static char * |
136 addCurdir(char *name, PathDesc *pd, int curdir) { | 148 addCurdir(char *name, PathDesc *pd, int curdir) { |
137 int ns =0 ; | 149 int ns =0 ; |
138 char *n = name; | 150 char *n = name; |
139 if(vdiskdebug&0x2) { printf("addcur \""); putOs9str(name,0); printf("\" cur \""); putOs9str( cdt[curdir],0); printf("\"\n"); } | 151 if(vdiskdebug&0x2) { printf("addcur \""); putOs9str(name,0); printf("\" cur \""); putOs9str( cdt[curdir],0); printf("\"\n"); } |
165 if (i>ps) | 177 if (i>ps) |
166 printf("overrun i=%d ps=%d\n",i,ps); // err(__LINE__); | 178 printf("overrun i=%d ps=%d\n",i,ps); // err(__LINE__); |
167 return path; | 179 return path; |
168 } | 180 } |
169 | 181 |
182 /* | |
183 * os9 file name may contains garbage such as 8th bit on or traling space | |
184 * fix it. and make the pointer to next path for the return value | |
185 * | |
186 * pd->name will be freed, we have to malloc it | |
187 */ | |
170 static char * | 188 static char * |
171 checkFileName(char *path, PathDesc *pd, int curdir) { | 189 checkFileName(char *path, PathDesc *pd, int curdir) { |
172 char *p = path; | 190 char *p = path; |
173 char *name = path; | 191 char *name = path; |
174 int maxlen = MAXPAHTLEN; | 192 int maxlen = MAXPAHTLEN; |
195 printf("\" checkname result \""); putOs9str(pd->name,0); printf("\"\n"); | 213 printf("\" checkname result \""); putOs9str(pd->name,0); printf("\"\n"); |
196 } | 214 } |
197 return p; | 215 return p; |
198 } | 216 } |
199 | 217 |
218 /* | |
219 * os9 / unix mode conversion | |
220 */ | |
200 static void | 221 static void |
201 os9setmode(Byte *os9mode,int mode) { | 222 os9setmode(Byte *os9mode,int mode) { |
202 char m = 0; | 223 char m = 0; |
203 if (mode&S_IFDIR) m|=0x80; | 224 if (mode&S_IFDIR) m|=0x80; |
204 if (mode&S_IRUSR) m|=0x01; | 225 if (mode&S_IRUSR) m|=0x01; |
264 */ | 285 */ |
265 #define DIR_SZ 32 | 286 #define DIR_SZ 32 |
266 #define DIR_NM 29 | 287 #define DIR_NM 29 |
267 | 288 |
268 | 289 |
269 /* read direcotry entry */ | 290 /* read direcotry entry |
291 * | |
292 * create simulated os9 directory structure for dir command | |
293 * writing to the directory is not allowed | |
294 * */ | |
270 static int | 295 static int |
271 os9opendir(PathDesc *pd) { | 296 os9opendir(PathDesc *pd) { |
272 DIR *dir; | 297 DIR *dir; |
273 struct dirent *dp; | 298 struct dirent *dp; |
274 if (pd->dirfp) return 0; // already opened | 299 if (pd->dirfp) return 0; // already opened |
316 } | 341 } |
317 | 342 |
318 /* read file descriptor of Path Desc | 343 /* read file descriptor of Path Desc |
319 * create file descriptor sector if necessary | 344 * create file descriptor sector if necessary |
320 * if buf!=0, copy it | 345 * if buf!=0, copy it |
346 * | |
347 * only dir command accesses this using undocumented getstat fdinfo command | |
321 */ | 348 */ |
322 static int | 349 static int |
323 filedescriptor(Byte *buf, int len, Byte *name,int curdir) { | 350 filedescriptor(Byte *buf, int len, Byte *name,int curdir) { |
324 int err = 0x255; | 351 int err = 0x255; |
325 PathDesc pd; | 352 PathDesc pd; |
341 err1: | 368 err1: |
342 free(pd.name); | 369 free(pd.name); |
343 return err; | 370 return err; |
344 } | 371 } |
345 | 372 |
346 /* read direcotry entry for any file in the directory | 373 /* |
374 * undocumented getstat command | |
375 * | |
376 * read direcotry entry for *any* file in the directory | |
347 * we only returns a file descriptor only in the current opened directory | 377 * we only returns a file descriptor only in the current opened directory |
348 * | 378 * |
349 * inode==0 should return disk id section | 379 * inode==0 should return disk id section |
350 * inode==bitmap should return disk sector map for os9 free command | 380 * inode==bitmap should return disk sector map for os9 free command |
351 */ | 381 */ |
368 } | 398 } |
369 } | 399 } |
370 return 255; | 400 return 255; |
371 } | 401 } |
372 | 402 |
403 /* | |
404 * on os9 level 2, user process may on different memory map | |
405 * get DAT table on process descriptor on 0x50 in system page | |
406 */ | |
373 void | 407 void |
374 getDAT() { | 408 getDAT() { |
409 #ifdef USE_MMU | |
375 Word ps = getword(smem(0x50)); // process structure | 410 Word ps = getword(smem(0x50)); // process structure |
376 Byte *dat = smem(ps+0x40); // process dat (dynamic address translation) | 411 Byte *dat = smem(ps+0x40); // process dat (dynamic address translation) |
377 for(int i=0; i<8; i++) { | 412 for(int i=0; i<8; i++) { |
378 pmmu[i] = dat[i*2+1]; | 413 pmmu[i] = dat[i*2+1]; |
379 } | 414 } |
380 } | 415 #endif |
381 | 416 } |
382 /* | 417 |
418 /* | |
419 * vdisk command processing | |
420 * | |
421 * vrbf.asm will write a command on 0x40+IOPAGE ( 0xffc0 or 0xe040) | |
422 * | |
423 * U contains caller's stack (call and return value) on 0x45+IOPAGE | |
424 * current directory (cwd or cxd) on 0x44+IOPAGE | |
425 * Path dcriptor number on 0x47+IOPAGE | |
426 * drive number on 0x41+IOPAGE | |
427 * caller's process descriptor on <0x50 | |
428 * | |
383 * each command should have preallocated os9 path descriptor on Y | 429 * each command should have preallocated os9 path descriptor on Y |
384 * | 430 * |
385 * name or buffer, can be in a user map, check that drive number ( mem[0x41+IOPAGE] 0 sys 1 user ) | 431 * name or buffer, can be in a user map, check that drive number ( mem[0x41+IOPAGE] 0 sys 1 user ) |
386 * current directory path number mem[0x42+IOPAGE] | 432 * current directory path number mem[0x42+IOPAGE] |
387 * yreg has pd number | 433 * yreg has pd number |
768 */ | 814 */ |
769 *breg = 0xff; | 815 *breg = 0xff; |
770 if (pd==0) break; | 816 if (pd==0) break; |
771 *breg = filedescriptor(pmem(xreg), yreg,(Byte*)pd->name,curdir) ; | 817 *breg = filedescriptor(pmem(xreg), yreg,(Byte*)pd->name,curdir) ; |
772 break; | 818 break; |
773 case 0x20: // Pos.FDInf mandatry for dir command | 819 case 0x20: // Pos.FDInf mandatry for dir command (undocumented, use the source) |
774 /* SS.FDInf ($20) - Directly reads a file descriptor from anywhere | 820 /* SS.FDInf ($20) - Directly reads a file descriptor from anywhere |
775 * on drive. | 821 * on drive. |
776 * Entry: R$A=Path # | 822 * Entry: R$A=Path # |
777 * R$B=SS.FDInf ($20) | 823 * R$B=SS.FDInf ($20) |
778 * R$X=Pointer to a 256 byte buffer | 824 * R$X=Pointer to a 256 byte buffer |
833 *areg = frame[1]; | 879 *areg = frame[1]; |
834 *breg = frame[2]; | 880 *breg = frame[2]; |
835 xreg = getword(frame+4); | 881 xreg = getword(frame+4); |
836 yreg = getword(frame+6); | 882 yreg = getword(frame+6); |
837 ureg = getword(frame+8); | 883 ureg = getword(frame+8); |
838 pcreg = getword(frame+10)-3; | 884 pcreg = getword(frame+10)-3; // point os9 swi2 |
839 prog = (char*)(pmem(pcreg) - pcreg); | 885 prog = (char*)(pmem(pcreg) - pcreg); |
840 do_trace(fp); | 886 do_trace(fp); |
841 } | 887 } |
842 | 888 |
843 | 889 |