comparison src/vdisk.c @ 61:80f4ec9a3420

fix writeln chdir don't touch the path descriptor contents
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 25 Jul 2018 20:05:06 +0900
parents 7c6dc25c2b05
children 5b3871f8bdaa
comparison
equal deleted inserted replaced
60:84d2d5a54ed0 61:80f4ec9a3420
14 #include <sys/select.h> 14 #include <sys/select.h>
15 #include <dirent.h> 15 #include <dirent.h>
16 #include <string.h> 16 #include <string.h>
17 #include <time.h> 17 #include <time.h>
18 #include <arpa/inet.h> 18 #include <arpa/inet.h>
19 19 #include <fcntl.h>
20 static int vdiskdebug = 0; // bit 1 trace, bit 2 filename 20
21 static int vdiskdebug = 1; // bit 1 trace, bit 2 filename
21 22
22 23
23 Byte pmmu[8]; // process dat mmu 24 Byte pmmu[8]; // process dat mmu
24 25
25 extern char *prog ; // for disass 26 extern char *prog ; // for disass
198 name = (char *)malloc(p-path+1+eighth); 199 name = (char *)malloc(p-path+1+eighth);
199 int i; 200 int i;
200 for(i=0;i<p-path;i++) name[i] = path[i]; 201 for(i=0;i<p-path;i++) name[i] = path[i];
201 if (eighth) { name[i] = path[i]&0x7f; p++ ; i++; } 202 if (eighth) { name[i] = path[i]&0x7f; p++ ; i++; }
202 name[i] = 0; 203 name[i] = 0;
204 // skip trailing space
205 while(*p==' ') p++;
203 } 206 }
204 char *name1 = addCurdir(name,pd,curdir); 207 char *name1 = addCurdir(name,pd,curdir);
205 if (name1!=name && name1!=path) free(name); 208 if (name1!=name && name1!=path) free(name);
206 if (name1==0) return 0; 209 if (name1==0) return 0;
207 pd->name = name1; 210 pd->name = name1;
231 m|=0x60; // always sharable 234 m|=0x60; // always sharable
232 *os9mode = m; 235 *os9mode = m;
233 } 236 }
234 237
235 static char * 238 static char *
236 os9toUnixAttr(Byte attr) { 239 os9toUnixAttr(Byte mode) {
237 if ((attr&0x1) && (attr&0x2)) return "r+"; 240 if ((mode&0x1) && (mode&0x2)) return "r+";
238 if (!(attr&0x1) && (attr&0x2)) return "w"; 241 if (!(mode&0x1) && (mode&0x2)) return "w";
239 if ((attr&0x1) && !(attr&0x2)) return "r"; 242 if ((mode&0x1) && !(mode&0x2)) return "r";
240 return "r"; 243 return "r";
241 } 244 }
245
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
242 259
243 /* 260 /*
244 * os9 file descriptor 261 * os9 file descriptor
245 * * File Descriptor Format 262 * * File Descriptor Format
246 * 263 *
468 * B = errcode 485 * B = errcode
469 */ 486 */
470 case 0xd1: 487 case 0xd1:
471 mode = *areg; 488 mode = *areg;
472 attr = *breg; 489 attr = *breg;
490 pd->fp = 0;
473 path = (char *)pmem(xreg); 491 path = (char *)pmem(xreg);
474 next = pd->name = checkFileName(path,pd,curdir); 492 next = checkFileName(path,pd,curdir);
475 pd->dir = 0; 493 *breg = 0xff;
476 pd->fp = fopen(pd->name, os9toUnixAttr(attr)); 494 int fd = open(pd->name, O_RDWR+O_CREAT,os9mode(attr) );
495 if (fd>0)
496 pd->fp = fdopen(fd, os9toUnixAttr(mode));
477 if (next!=0 && pd->fp ) { 497 if (next!=0 && pd->fp ) {
498 *breg = 0;
499 *areg = pd->num;
500 *smem(u+1) = *areg ;
478 xreg += ( next - path ); 501 xreg += ( next - path );
479 pd->use = 1; 502 pd->use = 1;
480 } else { 503 } else {
481 *breg = 0xff;
482 free(pd->name);
483 pd->use = 0; 504 pd->use = 0;
484 } 505 }
485 break; 506 break;
486 507
487 /* 508 /*
495 * 516 *
496 * Error: CC Carry set 517 * Error: CC Carry set
497 * B = errcode 518 * B = errcode
498 */ 519 */
499 case 0xd2: 520 case 0xd2:
500 *breg = 0xff;
501 mode = *areg; 521 mode = *areg;
502 attr = *breg; 522 attr = *breg;
503 pd->fp = 0; 523 pd->fp = 0;
504 path = (char*)pmem(xreg); 524 path = (char*)pmem(xreg);
505 next = checkFileName(path,pd,curdir); 525 next = checkFileName(path,pd,curdir);
571 * Error: CC Carry set 591 * Error: CC Carry set
572 * B = errcode 592 * B = errcode
573 * 593 *
574 * 594 *
575 * we keep track a cwd and a cxd for a process using 8bit id 595 * we keep track a cwd and a cxd for a process using 8bit id
576 */ 596 * don't use path descriptor on y
577 case 0xd4: 597 */
598 case 0xd4: {
599 PathDesc dm = *pd;
578 path = (char*)pmem(xreg); 600 path = (char*)pmem(xreg);
579 next = checkFileName(path,pd,curdir); 601 next = checkFileName(path,&dm,curdir);
580 if (next!=0) { 602 if (next!=0) {
581 struct stat buf; 603 struct stat buf;
582 if (stat(pd->name,&buf)!=0) break; 604 if (stat(dm.name,&buf)!=0) break;
583 if ((buf.st_mode & S_IFMT) != S_IFDIR) break; 605 if ((buf.st_mode & S_IFMT) != S_IFDIR) break;
584 xreg += ( next - path ); 606 xreg += ( next - path );
585 *areg = setcd(pd->name); 607 *areg = setcd(dm.name);
586 *smem(u+1) = *areg ; 608 *smem(u+1) = *areg ;
587 pd->use = 1;
588 pd->dir = 1;
589 *breg = 0; 609 *breg = 0;
590 break; 610 break;
591 } 611 }
592 *breg = 0xff; 612 *breg = 0xff;
613 }
593 break; 614 break;
594 615
595 /* 616 /*
596 * I$Delete Entry Point 617 * I$Delete Entry Point
597 * 618 *
714 *breg = 0xff; 735 *breg = 0xff;
715 if (pd->dir) break; 736 if (pd->dir) break;
716 int len = yreg; 737 int len = yreg;
717 int i = 0; 738 int i = 0;
718 Byte *buf = pmem(xreg); 739 Byte *buf = pmem(xreg);
719 while(len>0 && *buf !='\r') { 740 while(len>0 && buf[i] !='\r') {
720 fputc(buf[i++],pd->fp); 741 fputc(buf[i++],pd->fp);
721 len--; 742 len--;
722 } 743 }
723 if (buf[i]=='\r') { 744 if (buf[i]=='\r') {
724 fputc('\n',pd->fp); 745 fputc('\n',pd->fp);
881 xreg = getword(frame+4); 902 xreg = getword(frame+4);
882 yreg = getword(frame+6); 903 yreg = getword(frame+6);
883 ureg = getword(frame+8); 904 ureg = getword(frame+8);
884 pcreg = getword(frame+10)-3; // point os9 swi2 905 pcreg = getword(frame+10)-3; // point os9 swi2
885 prog = (char*)(pmem(pcreg) - pcreg); 906 prog = (char*)(pmem(pcreg) - pcreg);
907 if (*pmem(pcreg)==0 && *pmem(pcreg+1)==0) {
908 // may be we are called from system state
909 // of coursel, this may wrong. but in system state, <$50 process has wrong DAT for pc
910 // and we can't know wether we are called from system or user
911 prog = (char*)(smem(pcreg) - pcreg);
912 }
886 do_trace(fp); 913 do_trace(fp);
887 } 914 }
888 915
889 916
890 /* end */ 917 /* end */