Mercurial > hg > Members > kono > os9 > sbc09
comparison vdisk.c @ 51:498b6fcaf270
vdisk worked
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 22 Jul 2018 05:48:04 +0900 |
parents | 1430678cd4fb |
children | 51b437557f42 |
comparison
equal
deleted
inserted
replaced
50:1430678cd4fb | 51:498b6fcaf270 |
---|---|
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 |
20 static int vdiskdebug = 1; // 1 trace, 2 filename | 20 static int vdiskdebug = 0; // 1 trace, 2 filename |
21 | 21 |
22 | 22 |
23 Byte pmmu[8]; // process dat mmu | 23 Byte pmmu[8]; // process dat mmu |
24 | 24 |
25 extern char *prog ; // for disass | 25 extern char *prog ; // for disass |
101 static int cdtptr = 0; | 101 static int cdtptr = 0; |
102 | 102 |
103 Byte | 103 Byte |
104 setcd(char *name) { | 104 setcd(char *name) { |
105 int len; | 105 int len; |
106 for(int i=0;i<256;i++) { | 106 for(int i=0;i<512;i++) { |
107 if (cdt[i] && strcmp(name,cdt[i])==0) return i; | 107 if (cdt[i] && strcmp(name,cdt[i])==0) return i; |
108 } | 108 } |
109 cdtptr &= 0xff; | 109 cdtptr &= 0x1ff; |
110 if (cdt[cdtptr]) free(cdt[cdtptr]); | 110 if (cdt[cdtptr]) free(cdt[cdtptr]); |
111 cdt[cdtptr] = (char*)malloc(len=strlen(name)+1); | 111 cdt[cdtptr] = (char*)malloc(len=strlen(name)+1); |
112 strcpy(cdt[cdtptr],name); | 112 strcpy(cdt[cdtptr],name); |
113 return cdtptr++; | 113 return cdtptr++; |
114 } | 114 } |
123 } | 123 } |
124 while(*s && *s>=' ' && ((*s&0x80)==0)) { | 124 while(*s && *s>=' ' && ((*s&0x80)==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 } | |
129 | |
130 static void | |
131 err(int error) { | |
132 printf("err %d\n",error); | |
128 } | 133 } |
129 | 134 |
130 static char * | 135 static char * |
131 addCurdir(char *name, PathDesc *pd, int curdir) { | 136 addCurdir(char *name, PathDesc *pd, int curdir) { |
132 int ns =0 ; | 137 int ns =0 ; |
153 } | 158 } |
154 char *path = (char*)malloc(ps); | 159 char *path = (char*)malloc(ps); |
155 int i = 0; | 160 int i = 0; |
156 for(;base[i];i++) path[i] = base[i]; | 161 for(;base[i];i++) path[i] = base[i]; |
157 path[i++] = '/'; | 162 path[i++] = '/'; |
158 for(int j=0;j<ps;j++,i++) path[i] = name[j]; | 163 for(int j=0;i<ps;j++,i++) path[i] = name[j]; |
159 path[i++] = 0; | 164 path[i] = 0; |
165 if (i>ps) | |
166 printf("overrun i=%d ps=%d\n",i,ps); // err(__LINE__); | |
160 return path; | 167 return path; |
161 } | 168 } |
162 | 169 |
163 static char * | 170 static char * |
164 checkFileName(char *path, PathDesc *pd, int curdir) { | 171 checkFileName(char *path, PathDesc *pd, int curdir) { |
169 while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++; | 176 while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++; |
170 if (maxlen==MAXPAHTLEN) return 0; | 177 if (maxlen==MAXPAHTLEN) return 0; |
171 if (*p!=0) { | 178 if (*p!=0) { |
172 name = (char *)malloc(p-path+1); | 179 name = (char *)malloc(p-path+1); |
173 int i; | 180 int i; |
174 for(int i=0;i<MAXPAHTLEN;i++) { | 181 for(i=0;i<p-path;i++) { |
175 name[i] = path[i]&0x7f; | 182 name[i] = path[i]&0x7f; |
176 } | 183 } |
177 name[MAXPAHTLEN-maxlen] = 0; | 184 name[i] = 0; |
178 } | 185 } |
179 char *name1 = addCurdir(name,pd,curdir); | 186 char *name1 = addCurdir(name,pd,curdir); |
180 if (name1!=name && name1!=path) free(name); | 187 if (name1!=name && name1!=path) free(name); |
181 if (name1==0) return 0; | 188 if (name1==0) return 0; |
182 pd->name = name1; | 189 pd->name = name1; |
272 if (dircount==0) return 0; // should contains . and .. at least | 279 if (dircount==0) return 0; // should contains . and .. at least |
273 pd->sz = dircount*DIR_SZ; | 280 pd->sz = dircount*DIR_SZ; |
274 pd->dirfp = (char *)malloc(dircount*DIR_SZ); | 281 pd->dirfp = (char *)malloc(dircount*DIR_SZ); |
275 rewinddir(dir); | 282 rewinddir(dir); |
276 int i = 0; | 283 int i = 0; |
277 while ((dp = readdir(dir)) != NULL) { | 284 while ((dp = readdir(dir)) != NULL && dircount-->=0) { |
278 int j = 0; | 285 int j = 0; |
279 for(j = 0; j < DIR_NM ; j++) { | 286 for(j = 0; j < DIR_NM ; j++) { |
280 if (j< dp->d_namlen) { | 287 if (j< dp->d_namlen) { |
281 pd->dirfp[i+j] = dp->d_name[j]&0x7f; | 288 pd->dirfp[i+j] = dp->d_name[j]&0x7f; |
282 if (j== dp->d_namlen-1) | 289 if (j== dp->d_namlen-1) |
286 } | 293 } |
287 pd->dirfp[i+j] = (dp->d_ino&0xff0000)>>16; | 294 pd->dirfp[i+j] = (dp->d_ino&0xff0000)>>16; |
288 pd->dirfp[i+j+1] = (dp->d_ino&0xff00)>>8; | 295 pd->dirfp[i+j+1] = (dp->d_ino&0xff00)>>8; |
289 pd->dirfp[i+j+2] = dp->d_ino&0xff; | 296 pd->dirfp[i+j+2] = dp->d_ino&0xff; |
290 i += DIR_SZ; | 297 i += DIR_SZ; |
291 if (i>pd->sz) return 0; | 298 if (i>pd->sz) |
299 return 0; | |
292 } | 300 } |
293 pd->fp = fmemopen(pd->dirfp,pd->sz,"r"); | 301 pd->fp = fmemopen(pd->dirfp,pd->sz,"r"); |
294 return 0; | 302 return 0; |
295 } | 303 } |
296 | 304 |