2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <sys/syscalls.h>
13 #include "file_utils.h"
14 #include "shell_defs.h"
16 struct command cmds
[] = {
19 {"mkdir", &cmd_mkdir
},
27 int cmd_exec(int argc
, char *argv
[])
29 return cmd_create_proc(argc
- 1,argv
+1);
32 int cmd_create_proc(int argc
,char *argv
[])
39 char filename
[SCAN_SIZE
+1];
42 printf("not enough args to exec\n");
48 if( !find_file_in_path(argv
[0],filename
,SCAN_SIZE
)){
49 printf("can't find '%s' \n",argv
[0]);
54 // a hack to support the unix '&'
56 arg_len
= strlen(tmp
);
70 pid
= sys_proc_create_proc(filename
,filename
, argv
, argc
, 5);
75 sys_proc_wait_on_proc(pid
, &retcode
);
78 printf("Error: cannot execute '%s'\n", filename
);
79 return 0; // should be -1, but the shell would exit
85 int cmd_mkdir(int argc
, char *argv
[])
90 printf("not enough arguments to mkdir\n");
94 rc
= sys_create(argv
[1], STREAM_TYPE_DIR
);
96 printf("sys_mkdir() returned error: %s\n", strerror(rc
));
98 printf("%s successfully created.\n", argv
[1]);
104 int cmd_cat(int argc
, char *argv
[])
112 printf("not enough arguments to cat\n");
116 fd
= sys_open(argv
[1], STREAM_TYPE_FILE
, 0);
118 printf("cat: sys_open() returned error: %s!\n", strerror(fd
));
123 rc
= sys_read(fd
, buf
, -1, sizeof(buf
) -1);
135 int cmd_cd(int argc
, char *argv
[])
140 printf("not enough arguments to cd\n");
144 rc
= sys_setcwd(argv
[1]);
146 printf("cd: sys_setcwd() returned error: %s!\n", strerror(rc
));
152 int cmd_pwd(int argc
, char *argv
[])
156 cwd
= getcwd(NULL
, 1024);
158 printf("cd: sys_getcwd() returned error: %s!\n", "xx"); //strerror(rc));
160 printf("pwd: cwd=\'%s\'\n", cwd
);
168 int cmd_stat(int argc
, char *argv
[])
171 struct file_stat stat
;
174 printf("not enough arguments to stat\n");
178 rc
= sys_rstat(argv
[1], &stat
);
180 printf("stat of file '%s': \n", argv
[1]);
181 printf("vnid 0x%x\n", (unsigned int)stat
.vnid
);
182 printf("type %d\n", stat
.type
);
183 printf("size %d\n", (int)stat
.size
);
185 printf("stat failed for file '%s'\n", argv
[1]);
190 int cmd_help(int argc
, char *argv
[])
192 printf("command list:\n\n");
193 printf("exit : quits this copy of the shell\n");
194 printf("exec <file> : load this file as a binary and run it\n");
195 printf("mkdir <path> : makes a directory at <path>\n");
196 printf("cd <path> : sets the current working directory at <path>\n");
197 printf("ls <path> : directory list of <path>. If no path given it lists the current dir\n");
198 printf("stat <file> : gives detailed file statistics of <file>\n");
199 printf("help : this command\n");
200 printf("cat <file> : dumps the file to stdout\n");
201 printf("mount <path> <device> <fsname> : tries to mount <device> at <path>\n");
202 printf("unmount <path> : tries to unmount at <path>\n");