UNIX类似文件系统的目录结构
Directory Structure for a unix like file system
我当前在系统软件类中,我们的最终项目是实施具有层次目录结构的简单UNIX,例如Shell环境和文件系统。我们已经完成了向用户询问诸如" CD XXX"或" LS"之类的命令的简单部分。一旦调用了每个命令,它就会转到一个函数。我知道我需要目录和文件的数据结构,但我只是不知道从哪里开始。我知道父母只能是目录。该目录有一个名称,可以获取其他目录和文件。文件只有一个名称。如何实施这种代码?这是我现在所拥有的:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
void makeFS(){
printf("You created and formatted a new filesystem.n");
}
void listDir(){
printf("Listing all entries in current directory...n");
}
void exitShell(){
printf("Adios amigo.n");
exit(0);
}
void makeDir(char name[50]){
printf("Directory [%s] created at !n", name);
}
void remDir(char cmd[50]){
printf("You entered %s n", cmd);
}
void changeDir(char *nextName){
printf("Changed directory path to %sn", nextName);
}
void status(char cmd[50]){
printf("You entered %s n", cmd);
}
void makeFile(char cmd[50]){
printf("You entered %s n", cmd);
}
void remFile(char cmd[50]){
printf("You entered %s n", cmd);
}
int main(int argc, char *argv[]){
char cmd[50];
const char spc[50] = " n";
char *file, *dir;
char *tok, *nextName;
while (1){
printf("Russ_John_Shell> ");
fgets(cmd, 50, stdin);
//Tokenizes string to determine what command was inputed as well as any file/directory name needed
tok = strtok(cmd, spc);
nextName = strtok(NULL, spc);
//Checks to see whether the string has a file/directory name after the command
if (nextName == NULL){
//mkfs command
if (strcmp(cmd, "mkfs") == 0){
makeFS();
}
//exit command
else if (strcmp(cmd, "exit") == 0){
exitShell();
}
//ls command
else if (strcmp(cmd, "ls") == 0){
listDir();
}
//command not recognized at all
else {
printf("Command not recognized.n");
}
}
else {
//mkdir command
if (strcmp(cmd, "mkdir") == 0){
makeDir(nextName);
}
//rmdir command
else if (strcmp(cmd, "rmdir") == 0){
remDir(cmd);
}
//cd command
else if (strcmp(cmd, "cd") == 0){
changeDir(nextName);
}
//stat command
else if (strcmp(cmd, "stat") == 0){
status(cmd);
}
//mkfile command
else if (strcmp(cmd, "mkfile") == 0){
makeFile(cmd);
}
//rmfile command
else if (strcmp(cmd, "rmfile") == 0){
remFile(cmd);
}
//command not recognized at all
else {
printf("Command not recognized.n");
}
}
}
}
为什么不使用boost.filesystem?http://www.boost.org/doc/libs/1_62_0/libs/filesystem/doc/index.htm
相关文章:
- 文件系统:复制功能的速度秘诀是什么
- c++17文件系统::recursive_directory迭代器()在mac上没有给出这样的目录,但在windows上
- 如何传递多个 std::文件系统选项?
- 遍历顺序由 std::文件系统directory_iterator给出
- libstdc++ 文件系统中未初始化的用法?
- boost::文件系统::recursive_directory_iterator多线程安全
- C++17 文件系统::remove_all 带有通配符路径
- 实验性文件系统库不完整C++?
- 使用文件系统时仍然需要链接到带有 C++20 的 stdc++fs?
- 无法链接文件系统库C++
- 无法识别 Mac c++ 文件系统库
- 使用Boost文件系统C++将具有特定扩展名的文件的名称保存在特定文件夹中
- 获取 clang++:错误:在编译文件系统库的代码时
- C++17 文件系统在 Windows 10 上使用 nuwen MinGW
- C++ VS 错误:<实验/文件系统>提供 std::experimental::文件系统的标头已被Microsoft弃用,将被删除
- 如何修复 MinGW 文件系统探针?
- 如何读取/查询文件系统和文件结构
- UNIX类似文件系统的目录结构
- 文件系统中的数据结构存储
- 如何为结构化文件系统编写生成文件