Diff markup
001 !! 001
002 002
003 003
004 004
005 005
006 006
007 007
008 008
009 009
010 010
011 011
012 012
013 013
014 014
015 015
016 016
017 017
018 018
019 #include <crt.h> 019 #include <crt.h>
020 #include <libc.h> 020 #include <libc.h>
021 #include <stdarg.h> 021 #include <stdarg.h>
022 #include <string.h> 022 #include <string.h>
023 #include <debug.h> 023 #include <debug.h>
024 #include <drivers/devices.h> 024 #include <drivers/devices.h>
025 025
026 #include "fstest_utils.h" 026 #include "fstest_utils.h"
027 027
028 028
029 029
030 030
031 031
032 032
033 033
034 static int shell_uname (int argc, char *argv[] 034 static int shell_uname (int argc, char *argv[])
035 { 035 {
036 printf ("SOS article 9.5\n"); !! 036 printf ("SOS article 9\n");
037 return 0; 037 return 0;
038 } 038 }
039 039
040 static void shell_ls_internal(int detailed, in 040 static void shell_ls_internal(int detailed, int recursive, int reclevel)
041 { 041 {
042 char tab[256], *c; 042 char tab[256], *c;
043 int i; 043 int i;
044 struct dirent * dirent; 044 struct dirent * dirent;
045 DIR * here; 045 DIR * here;
046 046
047 here = opendir("."); 047 here = opendir(".");
048 if (! here) 048 if (! here)
049 return; 049 return;
050 050
051 051
052 if (recursive) 052 if (recursive)
053 { 053 {
054 for (c = tab, i = 0 ; (i < reclevel) && 054 for (c = tab, i = 0 ; (i < reclevel) && (i < sizeof(tab)/2) ; i++)
055 { 055 {
056 *c++ = ' '; 056 *c++ = ' ';
057 *c++ = ' '; 057 *c++ = ' ';
058 } 058 }
059 *c++ = '\0'; 059 *c++ = '\0';
060 } 060 }
061 else 061 else
062 *tab = '\0'; 062 *tab = '\0';
063 063
064 while ((dirent = readdir(here)) != NULL) 064 while ((dirent = readdir(here)) != NULL)
065 { 065 {
066 char entrychar; 066 char entrychar;
067 char * entrysuffix; 067 char * entrysuffix;
068 068
069 switch(dirent->type) 069 switch(dirent->type)
070 { 070 {
071 case S_IFREG: entrychar='-'; entrysuff 071 case S_IFREG: entrychar='-'; entrysuffix=""; break;
072 case S_IFDIR: entrychar='d'; entrysuff 072 case S_IFDIR: entrychar='d'; entrysuffix="/"; break;
073 case S_IFLNK: entrychar='l'; entrysuff 073 case S_IFLNK: entrychar='l'; entrysuffix="@"; break;
074 case S_IFCHR: entrychar='c'; entrysuff 074 case S_IFCHR: entrychar='c'; entrysuffix=NULL; break;
075 case S_IFBLK: entrychar='b'; entrysuff <<
076 default: entrychar='?'; entrysuffix="? 075 default: entrychar='?'; entrysuffix="?!?"; break;
077 } 076 }
078 077
079 if (detailed) 078 if (detailed)
080 { 079 {
081 struct stat stat; 080 struct stat stat;
082 char target_name[SOS_FS_DIRENT_NAME_ 081 char target_name[SOS_FS_DIRENT_NAME_MAXLEN];
083 char majorminor[24]; 082 char majorminor[24];
084 083
085 if (lstat(dirent->name, & stat)) 084 if (lstat(dirent->name, & stat))
086 continue; 085 continue;
087 086
088 *target_name = '\0'; 087 *target_name = '\0';
089 if (stat.st_type == S_IFLNK) 088 if (stat.st_type == S_IFLNK)
090 { 089 {
091 int fd = open(dirent->name, O_RD 090 int fd = open(dirent->name, O_RDONLY | O_NOFOLLOW);
092 if (fd >= 0) 091 if (fd >= 0)
093 { 092 {
094 int len = read(fd, target_na 093 int len = read(fd, target_name, sizeof(target_name) - 1);
095 if (len < 0) 094 if (len < 0)
096 *target_name='\0'; 095 *target_name='\0';
097 else 096 else
098 target_name[len] = '\0'; 097 target_name[len] = '\0';
099 close(fd); 098 close(fd);
100 } 099 }
101 } 100 }
102 else if ( (stat.st_type == S_IFCHR) !! 101 else if (stat.st_type == S_IFCHR)
103 { 102 {
104 snprintf(majorminor, sizeof(majo 103 snprintf(majorminor, sizeof(majorminor), " %d,%d",
105 stat.st_rdev_major, sta 104 stat.st_rdev_major, stat.st_rdev_minor);
106 entrysuffix = majorminor; 105 entrysuffix = majorminor;
107 } 106 }
108 107
109 printf("%s%c%c%c%c %lld %s%s%s%s (lo 108 printf("%s%c%c%c%c %lld %s%s%s%s (location=0x%llx)\n",
110 tab, entrychar, 109 tab, entrychar,
111 (stat.st_access_rights&S_IRUS 110 (stat.st_access_rights&S_IRUSR)?'r':'-',
112 (stat.st_access_rights&S_IWUS 111 (stat.st_access_rights&S_IWUSR)?'w':'-',
113 (stat.st_access_rights&S_IXUS 112 (stat.st_access_rights&S_IXUSR)?'x':'-',
114 stat.st_size, 113 stat.st_size,
115 dirent->name, 114 dirent->name,
116 entrysuffix, 115 entrysuffix,
117 (stat.st_type==S_IFLNK)?" -> 116 (stat.st_type==S_IFLNK)?" -> ":"",
118 target_name, 117 target_name,
119 stat.st_storage_location); 118 stat.st_storage_location);
120 } 119 }
121 else 120 else
122 printf("%s%s%s\n", 121 printf("%s%s%s\n",
123 tab, dirent->name, entrysuffi 122 tab, dirent->name, entrysuffix);
124 123
125 124
126 if (recursive) 125 if (recursive)
127 { 126 {
128 int fd_here = dirfd(here); 127 int fd_here = dirfd(here);
129 if (chdir(dirent->name)) 128 if (chdir(dirent->name))
130 continue; 129 continue;
131 shell_ls_internal(detailed, recursiv 130 shell_ls_internal(detailed, recursive, reclevel+1);
132 if(fchdir(fd_here)) 131 if(fchdir(fd_here))
133 { 132 {
134 closedir(here); 133 closedir(here);
135 return; 134 return;
136 } 135 }
137 } 136 }
138 } 137 }
139 closedir(here); 138 closedir(here);
140 } 139 }
141 140
142 static void shell_ls(const char * path, int de 141 static void shell_ls(const char * path, int detailed, int recursive)
143 { 142 {
144 int fd_here = open(".", O_RDONLY | O_DIRECTO 143 int fd_here = open(".", O_RDONLY | O_DIRECTORY);
145 if (fd_here < 0) 144 if (fd_here < 0)
146 return; 145 return;
147 146
148 if (chdir(path)) 147 if (chdir(path))
149 { 148 {
150 close(fd_here); 149 close(fd_here);
151 return; 150 return;
152 } 151 }
153 152
154 shell_ls_internal(detailed, recursive, 1); 153 shell_ls_internal(detailed, recursive, 1);
155 154
156 fchdir(fd_here); 155 fchdir(fd_here);
157 close(fd_here); 156 close(fd_here);
158 } 157 }
159 158
160 static int shell_touch (int argc, char *argv[] 159 static int shell_touch (int argc, char *argv[])
161 { 160 {
162 return creat (argv[1], S_IRUSR | S_IWUSR); 161 return creat (argv[1], S_IRUSR | S_IWUSR);
163 } 162 }
164 163
165 static int shell_mkdir (int argc, char *argv[] 164 static int shell_mkdir (int argc, char *argv[])
166 { 165 {
167 return mkdir (argv[1], S_IRUSR | S_IWUSR | S 166 return mkdir (argv[1], S_IRUSR | S_IWUSR | S_IXUSR);
168 } 167 }
169 168
170 static int shell_cat (int argc, char *argv[]) 169 static int shell_cat (int argc, char *argv[])
171 { 170 {
172 int fd; 171 int fd;
173 char buf[4096]; 172 char buf[4096];
174 int len; 173 int len;
175 174
176 fd = open (argv[1], O_RDONLY); 175 fd = open (argv[1], O_RDONLY);
177 if (fd < 0) { 176 if (fd < 0) {
178 printf ("Cannot open '%s'\n", argv[1]); 177 printf ("Cannot open '%s'\n", argv[1]);
179 return -1; 178 return -1;
180 } 179 }
181 180
182 while (1) 181 while (1)
183 { 182 {
184 len = read (fd, buf, sizeof(buf)-1); 183 len = read (fd, buf, sizeof(buf)-1);
185 if (len <= 0) 184 if (len <= 0)
186 break; 185 break;
187 buf[len] = '\0'; 186 buf[len] = '\0';
188 187
189 printf ("%s", buf); 188 printf ("%s", buf);
190 } 189 }
191 190
192 close (fd); 191 close (fd);
193 return 0; 192 return 0;
194 } 193 }
195 194
196 static int shell_edit (int argc, char *argv[]) 195 static int shell_edit (int argc, char *argv[])
197 { 196 {
198 int fd; 197 int fd;
199 char buf[16]; 198 char buf[16];
200 int len; 199 int len;
201 200
202 fd = open (argv[1], O_WRONLY | O_CREAT | O_T 201 fd = open (argv[1], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
203 if (fd < 0) { 202 if (fd < 0) {
204 printf ("Cannot create '%s': %d\n", argv[1 203 printf ("Cannot create '%s': %d\n", argv[1], fd);
205 return -1; 204 return -1;
206 } 205 }
207 206
208 207
209 ioctl (0, SOS_IOCTL_TTY_SETPARAM, SOS_IOCTLP 208 ioctl (0, SOS_IOCTL_TTY_SETPARAM, SOS_IOCTLPARAM_TTY_ECHO);
210 ioctl (0, SOS_IOCTL_TTY_SETPARAM, SOS_IOCTLP 209 ioctl (0, SOS_IOCTL_TTY_SETPARAM, SOS_IOCTLPARAM_TTY_CANON);
211 210
212 while (1) 211 while (1)
213 { 212 {
214 len = read (0, buf, sizeof(buf)); 213 len = read (0, buf, sizeof(buf));
215 if (len <= 1) 214 if (len <= 1)
216 break; 215 break;
217 216
218 bochs_printf ("Writing %d bytes\n", len) 217 bochs_printf ("Writing %d bytes\n", len);
219 len = write (fd, buf, len); 218 len = write (fd, buf, len);
220 if (len <= 0) { 219 if (len <= 0) {
221 printf ("Cannot write to '%s': %d\n", 220 printf ("Cannot write to '%s': %d\n", argv[1], len);
222 break; 221 break;
223 } 222 }
224 } 223 }
225 224
226 225
227 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCT 226 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCTLPARAM_TTY_ECHO);
228 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCT 227 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCTLPARAM_TTY_CANON);
229 228
230 close (fd); 229 close (fd);
231 return 0; 230 return 0;
232 } 231 }
233 232
234 static int shell_hexdump (int argc, char *argv 233 static int shell_hexdump (int argc, char *argv[])
235 { 234 {
236 int fd; 235 int fd;
237 char buf[16]; 236 char buf[16];
238 int count = 0; 237 int count = 0;
239 int len; 238 int len;
240 239
241 fd = open (argv[1], O_RDONLY); 240 fd = open (argv[1], O_RDONLY);
242 if (fd < 0) { 241 if (fd < 0) {
243 printf ("Cannot open '%s': %d\n", argv[1], 242 printf ("Cannot open '%s': %d\n", argv[1], fd);
244 return -1; 243 return -1;
245 } 244 }
246 245
247 while (1) 246 while (1)
248 { 247 {
249 int i; 248 int i;
250 249
251 len = read (fd, buf, sizeof(buf)); 250 len = read (fd, buf, sizeof(buf));
252 if (len <= 0) 251 if (len <= 0)
253 break; 252 break;
254 253
255 if (count < 0x10) 254 if (count < 0x10)
256 printf ("00%x ", count); 255 printf ("00%x ", count);
257 else if (count < 0x100) 256 else if (count < 0x100)
258 printf ("0%x ", count); 257 printf ("0%x ", count);
259 else if (count < 0x1000) 258 else if (count < 0x1000)
260 printf ("%x ", count); 259 printf ("%x ", count);
261 260
262 for (i = 0; i < len; i++) 261 for (i = 0; i < len; i++)
263 { 262 {
264 if (buf[i] < 0x10) 263 if (buf[i] < 0x10)
265 printf ("0%x ", buf[i]); 264 printf ("0%x ", buf[i]);
266 else 265 else
267 printf ("%x ", buf[i]); 266 printf ("%x ", buf[i]);
268 } 267 }
269 268
270 printf ("\n"); 269 printf ("\n");
271 270
272 count += len; 271 count += len;
273 } 272 }
274 273
275 close (fd); 274 close (fd);
276 return 0; 275 return 0;
277 } 276 }
278 277
279 static int shell_test (int argc, char *argv[]) 278 static int shell_test (int argc, char *argv[])
280 { 279 {
281 int i; 280 int i;
282 for (i = 0; i < argc; i++) 281 for (i = 0; i < argc; i++)
283 { 282 {
284 printf ("argv[%d] = %s\n", i, argv[i]); 283 printf ("argv[%d] = %s\n", i, argv[i]);
285 } 284 }
286 return 0; 285 return 0;
287 } 286 }
288 287
289 288
290 static int shell_spawn (int argc, char *argv[] !! 289 static int shell_devtest (int argc, char *argv[])
291 { 290 {
292 int retval; !! 291 bochs_printf("WARNING: This test will eventually write 0 on kernel code !\n");
293 if (argc < 2) !! 292 bochs_printf("This WILL crash the kernel (as expected...) !\n");
294 { !! 293 printf("WARNING: This test will eventually write 0 on kernel code !\n");
295 printf("Usage: spawn prog_name\n"); !! 294 printf("This WILL crash the kernel (as expected...) !\n");
296 return -1; !! 295 if (fork() == 0)
297 } !! 296 exec("devtest");
298 retval = fork(); <<
299 if (retval > 0) <<
300 return 0; <<
301 if (retval < 0) <<
302 { <<
303 printf("Could not fork (%d)\n", retval); <<
304 return -1; <<
305 } <<
306 retval = exec(argv[1]); <<
307 printf("Could not exec %s: error %d\n", argv <<
308 return 0; 297 return 0;
309 } 298 }
310 299
311 300
312 static int shell_rm (int argc, char *argv[]) !! 301 static int shell_fstest (int argc, char *argv[])
313 { 302 {
314 int i; !! 303 if (fork() == 0)
315 !! 304 exec("fstest");
316 for (i = 1; i < argc; i++) <<
317 { <<
318 int ret; <<
319 <<
320 ret = unlink (argv[i]); <<
321 if (ret < 0) <<
322 printf ("Cannot remove '%s', %d\n", ar <<
323 } <<
324 <<
325 return 0; 305 return 0;
326 } 306 }
327 307
328 <<
329 static int shell_dd (int argc, char *argv[]) <<
330 { <<
331 char *infile = NULL; <<
332 char *outfile = NULL; <<
333 long bs = 1; <<
334 long count = -1; <<
335 int i; <<
336 int infd, outfd; <<
337 char *buffer; <<
338 int ret; <<
339 <<
340 for (i = 1; i < argc; i++) <<
341 { <<
342 if (strncmp (argv[i], "if=", 3) == 0) <<
343 infile = argv[i] + 3; <<
344 else if (strncmp (argv[i], "of=", 3) == <<
345 outfile = argv[i] + 3; <<
346 else if (strncmp (argv[i], "bs=", 3) == <<
347 { <<
348 char *tmp = argv[i] + 3; <<
349 char *multiplier_char; <<
350 int multiplier = 1; <<
351 int j; <<
352 <<
353 multiplier_char = & tmp[strlen(tmp)- <<
354 if (*multiplier_char == 'k' || <<
355 *multiplier_char == 'K') <<
356 { <<
357 multiplier = 1024; <<
358 *multiplier_char = '\0'; <<
359 } <<
360 else if (*multiplier_char == 'm' || <<
361 *multiplier_char == 'M') <<
362 { <<
363 multiplier = 1024 * 1024; <<
364 *multiplier_char = '\0'; <<
365 } <<
366 <<
367 for (j = 0; j < strlen(tmp); j++) <<
368 if (! isdigit(tmp[j])) <<
369 { <<
370 printf ("Syntax error in block <<
371 return -1; <<
372 } <<
373 <<
374 bs = atol(tmp) * multiplier; <<
375 } <<
376 else if (strncmp (argv[i], "count=", 6) <<
377 { <<
378 char *tmp = argv[i] + 6; <<
379 int j; <<
380 <<
381 for (j = 0; j < strlen(tmp); j++) <<
382 if (! isdigit(tmp[j])) <<
383 { <<
384 printf ("Syntax error in block <<
385 return -1; <<
386 } <<
387 <<
388 count = atol(tmp); <<
389 } <<
390 else <<
391 { <<
392 printf ("Syntax error\n"); <<
393 return -1; <<
394 } <<
395 } <<
396 <<
397 infd = open(infile, O_RDONLY); <<
398 if (infd < 0) <<
399 { <<
400 printf ("Cannot open '%s', %d\n", infile <<
401 return infd; <<
402 } <<
403 <<
404 outfd = open(outfile, O_RDWR | O_CREAT | O_T <<
405 if (outfd < 0) <<
406 { <<
407 printf ("Cannot open '%s', %d\n", outfil <<
408 return outfd; <<
409 } <<
410 <<
411 buffer = malloc (bs); <<
412 if (! buffer) <<
413 return -1; <<
414 <<
415 for (i = 0; (count < 0) || (i < count) ; i++ <<
416 { <<
417 int len; <<
418 <<
419 ret = read (infd, buffer, bs); <<
420 if (ret < 0) <<
421 { <<
422 printf ("Input error from '%s' at %d <<
423 return -1; <<
424 } <<
425 if (ret == 0) <<
426 break; <<
427 <<
428 len = ret; <<
429 <<
430 ret = write (outfd, buffer, len); <<
431 if (ret != len) <<
432 { <<
433 printf ("Output error to '%s' at %d <<
434 return -1; <<
435 } <<
436 } <<
437 <<
438 return 0; <<
439 } <<
440 <<
441 <<
442 static int shell_partdump (int argc, char *arg <<
443 { <<
444 <<
445 <<
446 <<
447 <<
448 struct partition_entry <<
449 { <<
450 unsigned char active; <<
451 unsigned char start_dl; <<
452 unsigned short start_cylinder; <<
453 unsigned char type; <<
454 unsigned char end_dl; <<
455 unsigned short end_cylinder; <<
456 unsigned long lba; <<
457 unsigned long size; <<
458 }; <<
459 <<
460 <<
461 <<
462 <<
463 #define PART_TABLE_OFFSET 446 <<
464 <<
465 <<
466 <<
467 <<
468 <<
469 <<
470 #define PART_TYPE_EXTENDED 0x5 <<
471 #define PART_TYPE_FAT16_1 0xe <<
472 #define PART_TYPE_FAT16_2 0x6 <<
473 #define PART_TYPE_FAT32_1 0xb <<
474 #define PART_TYPE_FAT32_2 0xc <<
475 #define PART_TYPE_LINUX_SWAP 0x82 <<
476 #define PART_TYPE_LINUX 0x83 <<
477 <<
478 <<
479 <<
480 <<
481 const char * <<
482 sos_part_type_str (unsigned int type) <<
483 { <<
484 switch (type) <<
485 { <<
486 case PART_TYPE_EXTENDED: <<
487 return "Extended"; <<
488 case PART_TYPE_FAT16_1: <<
489 case PART_TYPE_FAT16_2: <<
490 return "FAT16"; <<
491 case PART_TYPE_FAT32_1: <<
492 case PART_TYPE_FAT32_2: <<
493 return "FAT32"; <<
494 case PART_TYPE_LINUX_SWAP: <<
495 return "Linux Swap"; <<
496 case PART_TYPE_LINUX: <<
497 return "Linux"; <<
498 default: <<
499 return "Unknown"; <<
500 } <<
501 } <<
502 <<
503 int fd; <<
504 <<
505 <<
506 #define BLKSIZE 512 <<
507 char buffer[BLKSIZE]; <<
508 int ret; <<
509 struct partition_entry *part_entry; <<
510 int partnum; <<
511 unsigned int extstart = 0, extsup = 0; <<
512 <<
513 if (argc != 2) <<
514 { <<
515 printf ("Usage: partdump /dev/device\n") <<
516 return -1; <<
517 } <<
518 <<
519 fd = open (argv[1], O_RDONLY); <<
520 if (fd < 0) <<
521 { <<
522 printf ("Cannot open '%s', %d\n", argv[1 <<
523 return -1; <<
524 } <<
525 <<
526 ret = read (fd, buffer, sizeof(buffer)); <<
527 if (ret != sizeof(buffer)) <<
528 { <<
529 printf ("Read error in '%s', %d\n", argv <<
530 return -1; <<
531 } <<
532 <<
533 part_entry = (struct partition_entry *) (buf <<
534 <<
535 printf ("Partitions in %s:\n", argv[1]); <<
536 <<
537 <<
538 for (partnum = 0; partnum < 4; partnum++) <<
539 { <<
540 if (part_entry [partnum].size == 0) <<
541 continue; <<
542 <<
543 if (part_entry [partnum].type == PART_TY <<
544 { <<
545 if (extstart != 0) <<
546 printf ("Warning: two extended par <<
547 extstart = part_entry [partnum].lba; <<
548 continue; <<
549 } <<
550 <<
551 <<
552 <<
553 if (part_entry[partnum].size * BLKSIZE > <<
554 printf (" - %s%d (primary, %lu Mb, %s) <<
555 (part_entry[partnum].size * BL <<
556 sos_part_type_str(part_entry[p <<
557 else <<
558 printf (" - %s%d (primary, %lu Kb, %s) <<
559 (part_entry[partnum].size * BL <<
560 sos_part_type_str(part_entry[p <<
561 } <<
562 <<
563 while (extstart != 0) <<
564 { <<
565 ret = lseek (fd, (extstart + extsup) * B <<
566 if (ret != (extstart + extsup) * BLKSIZE <<
567 { <<
568 printf ("Cannot seek at position %d <<
569 (extstart + extsup) * BLKSIZ <<
570 return -1; <<
571 } <<
572 <<
573 ret = read (fd, buffer, BLKSIZE); <<
574 if (ret != BLKSIZE) <<
575 { <<
576 printf ("Read error in '%s', %d\n", <<
577 break; <<
578 } <<
579 <<
580 <<
581 <<
582 if (part_entry[0].size * BLKSIZE >= (102 <<
583 printf (" - %s%d (logical volume, %lu <<
584 (part_entry[0].size * BLKSIZE <<
585 sos_part_type_str(part_entry[0 <<
586 else <<
587 printf (" - %s%d (logical volume, %lu <<
588 (part_entry[0].size * BLKSIZE <<
589 sos_part_type_str(part_entry[0 <<
590 <<
591 extsup = part_entry[1].lba; <<
592 partnum ++; <<
593 if (extsup == 0) <<
594 break; <<
595 } <<
596 <<
597 return 0; <<
598 } <<
599 <<
600 <<
601 void command_exec (char * cmd) 308 void command_exec (char * cmd)
602 { 309 {
603 char *c; 310 char *c;
604 int argc = 1, i; 311 int argc = 1, i;
605 char **argv; 312 char **argv;
606 313
607 for (c = cmd; *c != '\0'; c++) 314 for (c = cmd; *c != '\0'; c++)
608 if (*c == ' ') 315 if (*c == ' ')
609 argc++; 316 argc++;
610 317
611 argv = malloc (argc * sizeof(char*)); 318 argv = malloc (argc * sizeof(char*));
612 if (argv == NULL) 319 if (argv == NULL)
613 return; 320 return;
614 321
615 for (i = 0, c = cmd; i < argc; i++) 322 for (i = 0, c = cmd; i < argc; i++)
616 { 323 {
617 argv[i] = c; 324 argv[i] = c;
618 while (*c != ' ' && *c != '\0') 325 while (*c != ' ' && *c != '\0')
619 c++; 326 c++;
620 *c = '\0'; 327 *c = '\0';
621 c++; 328 c++;
622 } 329 }
623 330
624 if (! strcmp (argv[0], "uname")) 331 if (! strcmp (argv[0], "uname"))
625 shell_uname(argc, argv); 332 shell_uname(argc, argv);
626 333
627 else if (! strcmp (argv[0], "ls")) 334 else if (! strcmp (argv[0], "ls"))
628 { 335 {
629 if (argv[1]) 336 if (argv[1])
630 shell_ls (argv[1], 1, 0); 337 shell_ls (argv[1], 1, 0);
631 else 338 else
632 shell_ls (".", 1, 0); 339 shell_ls (".", 1, 0);
633 } 340 }
634 341
635 else if (! strcmp (argv[0], "touch")) 342 else if (! strcmp (argv[0], "touch"))
636 { 343 {
637 shell_touch (argc, argv); 344 shell_touch (argc, argv);
638 } 345 }
639 346
640 else if (! strcmp (argv[0], "mkdir")) 347 else if (! strcmp (argv[0], "mkdir"))
641 { 348 {
642 shell_mkdir (argc, argv); 349 shell_mkdir (argc, argv);
643 } 350 }
644 351
645 else if (! strcmp (argv[0], "cat")) 352 else if (! strcmp (argv[0], "cat"))
646 { 353 {
647 shell_cat (argc, argv); 354 shell_cat (argc, argv);
648 } 355 }
649 356
650 else if (! strcmp (argv[0], "edit")) 357 else if (! strcmp (argv[0], "edit"))
651 { 358 {
652 shell_edit (argc, argv); 359 shell_edit (argc, argv);
653 } 360 }
654 361
655 else if (! strcmp (argv[0], "hexdump")) 362 else if (! strcmp (argv[0], "hexdump"))
656 { 363 {
657 shell_hexdump (argc, argv); 364 shell_hexdump (argc, argv);
658 } 365 }
659 else if (! strcmp (argv[0], "test")) 366 else if (! strcmp (argv[0], "test"))
660 { 367 {
661 shell_test (argc, argv); 368 shell_test (argc, argv);
662 } 369 }
663 else if (! strcmp (argv[0], "spawn")) !! 370 else if (! strcmp (argv[0], "devtest"))
664 { <<
665 shell_spawn (argc, argv); <<
666 } <<
667 else if (! strcmp (argv[0], "dd")) <<
668 { 371 {
669 shell_dd (argc, argv); !! 372 shell_devtest (argc, argv);
670 } 373 }
671 else if (! strcmp (argv[0], "rm")) !! 374 else if (! strcmp (argv[0], "fstest"))
672 { 375 {
673 shell_rm (argc, argv); !! 376 shell_fstest (argc, argv);
674 } <<
675 else if (! strcmp (argv[0], "partdump")) <<
676 { <<
677 shell_partdump (argc, argv); <<
678 } 377 }
679 378
>> 379
680 else 380 else
681 printf ("Command not found\n"); 381 printf ("Command not found\n");
682 382
683 free (argv); 383 free (argv);
684 } 384 }
685 385
686 int main(void) !! 386 int main()
687 { 387 {
688 char buffer[256]; 388 char buffer[256];
689 int i; 389 int i;
690 char chr; 390 char chr;
691 391
692 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCT 392 ioctl (0, SOS_IOCTL_TTY_RESETPARAM, SOS_IOCTLPARAM_TTY_CANON);
693 393
694 while (1) 394 while (1)
695 { 395 {
696 memset (buffer, 0, sizeof(buffer)); 396 memset (buffer, 0, sizeof(buffer));
697 i = 0; 397 i = 0;
698 printf ("$ "); 398 printf ("$ ");
699 399
700 while (1) 400 while (1)
701 { 401 {
702 read (0, & chr, 1); 402 read (0, & chr, 1);
703 if (chr == '\n') 403 if (chr == '\n')
704 { 404 {
705 buffer[i] = '\0'; 405 buffer[i] = '\0';
706 printf ("\n"); 406 printf ("\n");
707 if (i != 0) 407 if (i != 0)
708 command_exec (buffer); 408 command_exec (buffer);
709 break; 409 break;
710 } 410 }
711 else if (chr == '\b') 411 else if (chr == '\b')
712 { 412 {
713 if (i > 0) 413 if (i > 0)
714 { 414 {
715 i--; 415 i--;
716 printf ("\b"); 416 printf ("\b");
717 } 417 }
718 } 418 }
719 419
720 else if (i < 256) 420 else if (i < 256)
721 { 421 {
722 buffer[i++] = chr; 422 buffer[i++] = chr;
723 printf ("%c", chr); 423 printf ("%c", chr);
724 } 424 }
725 else 425 else
726 printf ("%c", chr); 426 printf ("%c", chr);
727 } 427 }
728 } 428 }
729 429
730 return 0; 430 return 0;
731 } 431 }