31 ASSERT(name !=
nullptr);
37 char* name_buff =
new char[strlen(name) + 1];
38 strcpy(name_buff, name);
55 : name_(other.name_), type_(other.type_), parent_(nullptr), tree_node_(this)
82 ASSERT(exec_ !=
nullptr);
83 return exec_(arg_, argc, argv);
126 ASSERT(node.
name_ !=
nullptr);
127 ASSERT(FindNode(node.
name_) ==
nullptr);
146 auto* node = rbt_.Search<
FsNode*>(name);
147 return node !=
nullptr ? node->data_ :
nullptr;
160 auto* ans = FindNode(name);
161 if (ans ==
nullptr || ans->GetNodeType() != type)
183 auto* ans = FindNodeByType(name, type);
195 ErrorCode operator()(Tree::Node<FsNode*>& item)
197 auto* node = item.data_;
198 if (node->GetNodeType() != FsNodeType::DIR)
200 return ErrorCode::OK;
203 ans_ =
static_cast<Dir*
>(node)->FindNodeRevByType(name_, type_);
204 return ans_ !=
nullptr ? ErrorCode::FAILED : ErrorCode::OK;
208 FindNodeRevFn find{name, type, ans};
209 rbt_.Foreach<
FsNode*>(find);
251 if (name[0] ==
'.' && name[1] ==
'\0')
256 if (name[0] ==
'.' && name[1] ==
'.' && name[2] ==
'\0')
278 if (name[0] ==
'.' && name[1] ==
'\0')
283 if (name[0] ==
'.' && name[1] ==
'.' && name[2] ==
'\0')
自定义节点片段 / Custom-node fragment
void * context_
用户自管上下文指针 / Caller-owned user context pointer.
Custom()
构造一个空自定义节点壳 / Construct one empty custom-node shell
uint32_t kind_
用户定义类型标签 / User-defined kind tag.
目录节点片段 / Directory-node fragment
Dir()
构造一个空目录壳 / Construct one empty directory shell
FsNode * FindNode(const char *name)
查找直属子节点 / Find a direct child node
File * FindFile(const char *name)
查找直属文件 / Find a direct child file
Dir * FindDir(const char *name)
查找直属目录,支持 "." 和 ".." / Find a direct child directory, supporting "." and ".."
File * FindFileRev(const char *name)
递归查找文件 / Find a file recursively
FsNode * FindNodeRevByType(const char *name, FsNodeType type)
递归查找指定类型节点 / Find one node of a given type recursively
void Add(File &file)
添加直属文件节点 / Add a direct child file node
void AddNode(FsNode &node)
把一个节点挂到当前目录下 / Attach one node under the current directory
Custom * FindCustom(const char *name)
查找直属自定义节点 / Find a direct child custom node
Custom * FindCustomRev(const char *name)
递归查找自定义节点 / Find a custom node recursively
FsNode * FindNodeByType(const char *name, FsNodeType type)
在当前目录按类型查找直属节点 / Find one direct child node of a given type
Dir * FindDirRev(const char *name)
递归查找目录,支持 "." 和 ".." / Find a directory recursively, supporting "." and ".."
文件节点片段 / File-node fragment
int Run(int argc, char **argv)
执行可执行文件 / Run an executable file
File()
构造一个空文件壳 / Construct one empty file shell
节点基类片段 / Base-node fragment
FsNode(FsNodeType node_type)
用指定节点类型构造基类部分 / Construct the base node with a given node type
Tree::Node< FsNode * > tree_node_
当前节点挂进目录树时使用的树节点包装 / Tree node wrapper used when inserted into a directory tree.
Dir * parent_
父目录;根目录保持为空 / Parent directory; stays null for the root.
const char * name_
节点名称缓冲区 / Retained node-name buffer.
轻量级内存文件系统 / Lightweight in-memory file system
RamFS(const char *name="ramfs")
构造 RamFS,并创建根目录和 bin 目录 / Construct RamFS with root and bin directories
FsNodeType
文件系统节点类型 / File-system node type
@ CUSTOM
用户自定义节点 / User-defined node
static char * DuplicateName(const char *name)
复制并持有一个节点名称 / Duplicate and retain one node name
static int CompareStr(const char *const &a, const char *const &b)
RamFS 名称比较函数 / Name comparator used by RamFS trees.
@ EXEC
可执行命令入口 / Executable command entry
Dir bin_
预留的可执行文件目录 / Reserved executable-file directory.
Dir root_
根目录;所有外部 Add()/Find*() 默认都从这里进入 / Root directory; all external Add()/Find*() entry through here.