()
| 151 | |
| 152 | #[no_mangle] |
| 153 | fn main() { |
| 154 | println!("Type help [Enter] to see the shell help page."); |
| 155 | |
| 156 | let stdin = io::stdin(); |
| 157 | let mut line_buffer = String::new(); |
| 158 | |
| 159 | // Current Working Directory |
| 160 | let mut current_directory = PathBuf::from("/ramdisk"); |
| 161 | |
| 162 | loop { |
| 163 | // prompt |
| 164 | print!("$ "); |
| 165 | |
| 166 | // Read a line of input |
| 167 | stdin.read_line(&mut line_buffer); |
| 168 | |
| 169 | let args: Vec<_> = line_buffer.split_whitespace().collect(); |
| 170 | if let Some(command) = args.first() { |
| 171 | match *command { |
| 172 | // Built-in shell commands |
| 173 | // |
| 174 | // Help |
| 175 | "help" | "?" => help(), |
| 176 | // List directory |
| 177 | "ls" => ls(¤t_directory, &args[1..]), |
| 178 | // Print working directory |
| 179 | "pwd" => println!("{:?}", current_directory), |
| 180 | // Change directory |
| 181 | "cd" => { |
| 182 | if args.len() != 2 { |
| 183 | println!("Usage: cd <directory>"); |
| 184 | continue; |
| 185 | } |
| 186 | current_directory.push(args[1]); |
| 187 | current_directory = fs::canonicalize(current_directory).unwrap(); |
| 188 | }, |
| 189 | "mount" => { |
| 190 | match syscalls::list_mounts() { |
| 191 | Ok((handle, len)) => { |
| 192 | let u8_slice = handle.as_slice::<u8>(len as usize); |
| 193 | if let Ok(s) = str::from_utf8(u8_slice) { |
| 194 | println!("{}", s); |
| 195 | } else { |
| 196 | println!("mount: syscall utf8 error"); |
| 197 | } |
| 198 | } |
| 199 | Err(err) => { |
| 200 | println!("mount: error {}", err); |
| 201 | } |
| 202 | } |
| 203 | }, |
| 204 | "umount" => umount(&args[1..]), |
| 205 | "rm" => rm(¤t_directory, &args[1..]), |
| 206 | "mkdir" => mkdir(¤t_directory, &args[1..]), |
| 207 | "exit" => return, |
| 208 | cmd => { |
| 209 | let path = fs::canonicalize(current_directory.join(cmd)).unwrap(); |
| 210 |
nothing calls this directly
no test coverage detected