6 : root_(CreateDir(name)), bin_(CreateDir(
"bin")), dev_(CreateDir(
"dev"))
23 char *name_buff =
new char[strlen(name) + 1];
24 strcpy(name_buff, name);
25 data_.name = name_buff;
34 auto ans = (*this)->rbt.Search<
FsNode>(name);
37 return reinterpret_cast<File *
>(ans);
56 Dir *dir =
reinterpret_cast<Dir *
>(&item);
61 return ErrorCode::FAILED;
65 {
return fun(child); });
67 return ans ? ErrorCode::FAILED : ErrorCode::OK;
75 {
return fun(item); });
83 if (name[0] ==
'.' && name[1] ==
'\0')
88 if (name[0] ==
'.' && name[1] ==
'.' && name[2] ==
'\0')
90 return reinterpret_cast<Dir *
>(data_.parent);
97 return reinterpret_cast<Dir *
>(ans);
116 Dir *dir =
reinterpret_cast<Dir *
>(&item);
117 if (strcmp(dir->
data_.name, name) == 0)
120 return ErrorCode::OK;
125 {
return fun(child); });
127 return ans ? ErrorCode::FAILED : ErrorCode::OK;
130 return ErrorCode::OK;
136 {
return fun(item); });
153 Dir *dir =
reinterpret_cast<Dir *
>(&item);
158 return ErrorCode::FAILED;
162 {
return fun(child); });
164 return ans ? ErrorCode::FAILED : ErrorCode::OK;
166 return ErrorCode::OK;
172 {
return fun(item); });
186 auto ans = (*this)->rbt.Search<
FsNode>(name);
189 return reinterpret_cast<Device *
>(ans);
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
Data data_
存储的数据 (Stored data).
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
ErrorCode Foreach(Func func)
遍历红黑树并执行用户提供的操作 (Traverse the Red-Black Tree and apply a user-defined function).
设备类,继承自红黑树节点 DeviceNode Device class inheriting from Red-Black tree node DeviceNode
Device(const char *name, const ReadPort &read_port=ReadPort(), const WritePort &write_port=WritePort())
设备构造函数 Device constructor
目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files...
Device * FindDeviceRev(const char *name)
递归查找设备 Recursively searches for a device
File * FindFile(const char *name)
查找当前目录中的文件 Finds a file in the current directory
Dir * FindDir(const char *name)
查找当前目录中的子目录 Finds a subdirectory in the current directory
Device * FindDevice(const char *name)
在当前目录中查找设备 Finds a device in the current directory
File * FindFileRev(const char *name)
递归查找文件 Recursively searches for a file
void Add(File &file)
添加文件到当前目录 Adds a file to the current directory
Dir * FindDirRev(const char *name)
递归查找子目录 Recursively searches for a subdirectory
RBTree< const char * > rbt
目录中的文件树 File tree in the directory
int(* exec)(void *raw, int argc, char **argv)
可执行文件指针 Executable function pointer
FileType type
文件类型 File type
void * arg
可执行文件参数 Executable file argument
int Run(int argc, char **argv)
运行可执行文件 Runs an executable file
文件系统节点基类,所有文件和目录均继承自该类 Base class for file system nodes; all files and directories inherit from this
Dir * FindDir(const char *name)
在整个文件系统中查找目录 Finds a directory in the entire file system
Device * FindDevice(const char *name)
在整个文件系统中查找设备 Finds a device in the entire file system
RamFS(const char *name="ramfs")
构造函数,初始化内存文件系统的根目录 Constructor that initializes the root directory of the in-memory file system
static int CompareStr(const char *const &a, const char *const &b)
比较两个字符串 Compares two strings
Dir dev_
dev 目录,用于存放设备文件 dev directory for storing device files
Dir bin_
bin 目录,用于存放可执行文件 bin directory for storing executable files
Dir root_
文件系统的根目录 Root directory of the file system
File * FindFile(const char *name)
在整个文件系统中查找文件 Finds a file in the entire file system
ReadPort class for handling read operations.
WritePort class for handling write operations.