comparison vdisk.c @ 52:51b437557f42

boot without disk image dir -e on other directory
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 22 Jul 2018 15:52:39 +0900
parents 498b6fcaf270
children 4fa2bdb0c457
comparison
equal deleted inserted replaced
51:498b6fcaf270 52:51b437557f42
114 } 114 }
115 115
116 #define MAXPAHTLEN 256 116 #define MAXPAHTLEN 256
117 117
118 static void 118 static void
119 putOs9str(char *s) { 119 putOs9str(char *s,int max) {
120 if (s==0) { 120 if (s==0) {
121 printf("(null)"); 121 printf("(null)");
122 return; 122 return;
123 } 123 }
124 while(*s && *s>=' ' && ((*s&0x80)==0)) { 124 while(*s && (*s&0x7f)>=' ' && ((*s&0x80)==0) && --max !=0) {
125 putchar(*s); s++; 125 putchar(*s); s++;
126 } 126 }
127 if (*s&0x80) putchar(*s&0x7f); 127 if (*s&0x80) putchar(*s&0x7f);
128 } 128 }
129 129
134 134
135 static char * 135 static char *
136 addCurdir(char *name, PathDesc *pd, int curdir) { 136 addCurdir(char *name, PathDesc *pd, int curdir) {
137 int ns =0 ; 137 int ns =0 ;
138 char *n = name; 138 char *n = name;
139 if(vdiskdebug&0x2) { printf("addcur \""); putOs9str(name); printf("\" cur \""); putOs9str( cdt[curdir]); printf("\"\n"); } 139 if(vdiskdebug&0x2) { printf("addcur \""); putOs9str(name,0); printf("\" cur \""); putOs9str( cdt[curdir],0); printf("\"\n"); }
140 if (name[0]=='/') { 140 if (name[0]=='/') {
141 name++; while(*name !='/' && *name!=0) name ++ ; // skip /d0 141 name++; while(*name !='/' && *name!=0) name ++ ; // skip /d0
142 while(name[ns]!=0) ns++; 142 while(name[ns]!=0) ns++;
143 } else if (!cdt[curdir] ) return 0; // no current directory 143 } else if (!cdt[curdir] ) return 0; // no current directory
144 else ns = strlen(name); 144 else ns = strlen(name);
170 static char * 170 static char *
171 checkFileName(char *path, PathDesc *pd, int curdir) { 171 checkFileName(char *path, PathDesc *pd, int curdir) {
172 char *p = path; 172 char *p = path;
173 char *name = path; 173 char *name = path;
174 int maxlen = MAXPAHTLEN; 174 int maxlen = MAXPAHTLEN;
175 if(vdiskdebug&2) { printf("checkf \""); putOs9str(name); printf("\"\n"); } 175 if(vdiskdebug&2) { printf("checkf \""); putOs9str(name,0); printf("\"\n"); }
176 while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++; 176 while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++;
177 if (maxlen==MAXPAHTLEN) return 0; 177 if (maxlen==MAXPAHTLEN) return 0;
178 if (*p!=0) { 178 if (*p) { // 8th bit termination or non ascii termination
179 name = (char *)malloc(p-path+1); 179 int eighth = ((*p&0x80)!=0);
180 name = (char *)malloc(p-path+1+eighth);
180 int i; 181 int i;
181 for(i=0;i<p-path;i++) { 182 for(i=0;i<p-path;i++) name[i] = path[i];
182 name[i] = path[i]&0x7f; 183 if (eighth) { name[i] = path[i]&0x7f; p++ ; i++; }
183 }
184 name[i] = 0; 184 name[i] = 0;
185 } 185 }
186 char *name1 = addCurdir(name,pd,curdir); 186 char *name1 = addCurdir(name,pd,curdir);
187 if (name1!=name && name1!=path) free(name); 187 if (name1!=name && name1!=path) free(name);
188 if (name1==0) return 0; 188 if (name1==0) return 0;
189 pd->name = name1; 189 pd->name = name1;
190 if(vdiskdebug&2) { 190 if(vdiskdebug&2) {
191 printf(" remain = \""); 191 printf(" remain = \"");
192 char *p1 = p; 192 char *p1 = p; int max=31;
193 while(*p1 && (*p1&0x80)==0 ) { if (*p1<0x20) printf("(0x%02x)",*p1); else putchar(*p1); p1++; } 193 while(*p1 && (*p1&0x80)==0 && max-->0) { if (*p1<0x20) printf("(0x%02x)",*p1); else putchar(*p1); p1++; }
194 if (*p1) { if ((*p1&0x7f)<0x20) printf("(0x%02x)",*p1); else putchar(*p1&0x7f); } 194 if (*p1) { if ((*p1&0x7f)<0x20) printf("(0x%02x)",*p1); else putchar(*p1&0x7f); }
195 printf("\" checkname result \""); putOs9str(pd->name); printf("\"\n"); 195 printf("\" checkname result \""); putOs9str(pd->name,0); printf("\"\n");
196 } 196 }
197 return p; 197 return p;
198 } 198 }
199 199
200 static void 200 static void
201 os9setmode(char *os9mode,int mode) { 201 os9setmode(Byte *os9mode,int mode) {
202 char m = 0; 202 char m = 0;
203 if (mode&S_IFDIR) m|=0x80; 203 if (mode&S_IFDIR) m|=0x80;
204 if (mode&S_IRUSR) m|=0x01; 204 if (mode&S_IRUSR) m|=0x01;
205 if (mode&S_IWUSR) m|=0x02; 205 if (mode&S_IWUSR) m|=0x02;
206 if (mode&S_IXUSR) m|=0x04; 206 if (mode&S_IXUSR) m|=0x04;
301 pd->fp = fmemopen(pd->dirfp,pd->sz,"r"); 301 pd->fp = fmemopen(pd->dirfp,pd->sz,"r");
302 return 0; 302 return 0;
303 } 303 }
304 304
305 static void 305 static void
306 os9setdate(char *d,struct timespec * unixtime) { 306 os9setdate(Byte *d,struct timespec * unixtime) {
307 // yymmddhhss 307 // yymmddhhss
308 struct tm r; 308 struct tm r;
309 localtime_r(&unixtime->tv_sec,&r); 309 localtime_r(&unixtime->tv_sec,&r);
310 d[0] = r.tm_year-2000; 310 d[0] = r.tm_year-2048;
311 d[1] = r.tm_mon; 311 d[1] = r.tm_mon + 1;
312 d[2] = r.tm_mday; 312 d[2] = r.tm_mday;
313 d[3] = r.tm_hour; 313 d[3] = r.tm_hour;
314 d[4] = r.tm_min; 314 d[4] = r.tm_min;
315 d[5] = r.tm_sec; 315 d[5] = r.tm_sec;
316 } 316 }
318 /* read file descriptor of Path Desc 318 /* read file descriptor of Path Desc
319 * create file descriptor sector if necessary 319 * create file descriptor sector if necessary
320 * if buf!=0, copy it 320 * if buf!=0, copy it
321 */ 321 */
322 static int 322 static int
323 filedescriptor(Byte *buf, int len, PathDesc *pd) { 323 filedescriptor(Byte *buf, int len, Byte *name,int curdir) {
324 int err = 0x255;
325 PathDesc pd;
326 if (len<13) return -1;
327 checkFileName((char*)name,&pd,curdir);
324 struct stat st; 328 struct stat st;
325 if (pd->fd) return 1; 329 if (stat(pd.name,&st)!=0) goto err1;
326 pd->fd = (char *)malloc(256); 330 os9setmode(buf+FD_ATT,st.st_mode);
327 stat(pd->name,&st); 331 buf[FD_OWN]=(st.st_uid&0xff00)>>8;
328 os9setmode(pd->fd+FD_ATT,st.st_mode); 332 buf[FD_OWN+1]=st.st_uid&0xff;
329 pd->fd[FD_OWN]=(st.st_uid&0xff00)>>8; 333 os9setdate(buf+ FD_DAT,&st.st_mtimespec);
330 pd->fd[FD_OWN+1]=st.st_uid&0xff; 334 buf[FD_LNK]=st.st_nlink&0xff;
331 os9setdate(pd->fd + FD_DAT,&st.st_mtimespec); 335 buf[FD_SIZ+0]=(st.st_size&0xff000000)>>24;
332 pd->fd[FD_LNK]=st.st_nlink&0xff; 336 buf[FD_SIZ+1]=(st.st_size&0xff0000)>>16;
333 pd->fd[FD_SIZ+0]=(st.st_size&0xff000000)>>24; 337 buf[FD_SIZ+2]=(st.st_size&0xff00)>>8;
334 pd->fd[FD_SIZ+1]=(st.st_size&0xff0000)>>16; 338 buf[FD_SIZ+3]=st.st_size&0xff;
335 pd->fd[FD_SIZ+2]=(st.st_size&0xff00)>>8; 339 os9setdate(buf+FD_Creat,&st.st_ctimespec);
336 pd->fd[FD_SIZ+3]=st.st_size&0xff; 340 err = 0;
337 os9setdate(pd->fd+FD_Creat,&st.st_ctimespec); 341 err1:
338 // dummy segment list 342 free(pd.name);
339 for(int i=FD_SEG ; i < 256; i++) pd->fd[i] = 0; 343 return err;
340 return 0;
341 } 344 }
342 345
343 /* read direcotry entry for any file in the directory 346 /* read direcotry entry for any file in the directory
344 * we only returns a file descriptor only in the current opened directory 347 * we only returns a file descriptor only in the current opened directory
345 * 348 *
346 * inode==0 should return disk id section 349 * inode==0 should return disk id section
347 * inode==bitmap should return disk sector map for os9 free command 350 * inode==bitmap should return disk sector map for os9 free command
348 */ 351 */
349 static int 352 static int
350 fdinfo(Byte *buf,int len, int inode, PathDesc *pd) { 353 fdinfo(Byte *buf,int len, int inode, PathDesc *pd,int curdir) {
351 int i; 354 int i;
352 for(i=0;i<MAXPDV;i++) { 355 for(i=0;i<MAXPDV;i++) {
353 PathDesc *pd = pdv+i; 356 PathDesc *pd = pdv+i;
354 if (!pd->use || !pd->dir) continue; 357 if (!pd->use || !pd->dir) continue;
355 // find inode in directory 358 // find inode in directory
356 char *dir = (char *)pd->dirfp; 359 Byte *dir = (Byte*)pd->dirfp;
357 char *end = (char *)pd->dirfp + pd->sz; 360 Byte *end = (Byte*)pd->dirfp + pd->sz;
358 while( dir < end ) { 361 while( dir < end ) {
359 Byte *p = (Byte *)(dir + DIR_NM); 362 Byte *p = (dir + DIR_NM);
360 int dinode = (p[0]<<16)+(p[1]<<8)+p[2]; 363 int dinode = (p[0]<<16)+(p[1]<<8)+p[2];
361 if (inode == dinode) { 364 if (inode == dinode) {
362 filedescriptor(buf,len,pd); 365 return filedescriptor(buf,len,dir,curdir);
363 return 1;
364 } 366 }
365 dir += 0x20; 367 dir += 0x20;
366 } 368 }
367 } 369 }
368 return 0; 370 return 255;
369 } 371 }
370 372
371 void 373 void
372 getDAT() { 374 getDAT() {
373 Word ps = getword(smem(0x50)); // process structure 375 Word ps = getword(smem(0x50)); // process structure
761 /* SS.FD ($0F) - Returns a file descriptor 763 /* SS.FD ($0F) - Returns a file descriptor
762 * Entry: R$A=Path # 764 * Entry: R$A=Path #
763 * R$B=SS.FD ($0F) 765 * R$B=SS.FD ($0F)
764 * R$X=Pointer to a 256 byte buffer 766 * R$X=Pointer to a 256 byte buffer
765 * R$Y=# bytes of FD required 767 * R$Y=# bytes of FD required
766 * this should be handled in vrbf
767 */ 768 */
768 *breg = 0xff; 769 *breg = 0xff;
769 if (pd==0) break; 770 if (pd==0) break;
770 *breg = filedescriptor(pmem(xreg), yreg,pd) ; 771 *breg = filedescriptor(pmem(xreg), yreg,(Byte*)pd->name,curdir) ;
771 break; 772 break;
772 case 0x20: // Pos.FDInf mandatry for dir command 773 case 0x20: // Pos.FDInf mandatry for dir command
773 /* SS.FDInf ($20) - Directly reads a file descriptor from anywhere 774 /* SS.FDInf ($20) - Directly reads a file descriptor from anywhere
774 * on drive. 775 * on drive.
775 * Entry: R$A=Path # 776 * Entry: R$A=Path #
780 * R$U= LSW of logical sector # 781 * R$U= LSW of logical sector #
781 */ 782 */
782 *breg = 0xff; 783 *breg = 0xff;
783 if (pd==0) break; 784 if (pd==0) break;
784 ureg = getword(smem(u+8)); 785 ureg = getword(smem(u+8));
785 *breg = fdinfo(pmem(xreg),yreg,xreg*0x10000+ureg,pd); 786 *breg = fdinfo(pmem(xreg),(yreg&0xff),((yreg&0xff00)>>8)*0x10000+ureg,pd,curdir);
786 break; 787 break;
787 default: 788 default:
788 *breg = 0xff; 789 *breg = 0xff;
789 } 790 }
790 break; 791 break;
813 default: 814 default:
814 *breg = 0xff; 815 *breg = 0xff;
815 } 816 }
816 break; 817 break;
817 } 818 }
819 if (vdiskdebug && *breg) printf(" vdisk call error %x\n",*breg);
818 // return value 820 // return value
819 mem[0xffc0] = *breg; 821 mem[0xffc0] = *breg;
820 *smem(u+2) = *breg ; 822 *smem(u+2) = *breg ;
821 setword(smem(u+4),xreg); 823 setword(smem(u+4),xreg);
822 } 824 }