5#include "libxr_assert.hpp"
6#include "libxr_def.hpp"
8#include "libxr_type.hpp"
28 RamFS(
const char *name =
"ramfs")
132 template <
typename DataType, SizeLimitMode LimitMode = SizeLimitMode::MORE>
135 LibXR::Assert::SizeLimitCheck<LimitMode>(
sizeof(
DataType),
size);
147 const void *
addr =
nullptr;
201 template <
typename ReadOperation>
204 return data_.read_port(data, std::forward<ReadOperation>(op));
215 template <
typename WriteOperation>
218 return data_.write_port(data, std::forward<WriteOperation>(op));
259 (*this)->rbt.Insert(file, file->name);
269 (*this)->rbt.Insert(
dir,
dir->name);
279 (*this)->rbt.Insert(
dev,
dev->name);
292 auto ans = (*this)->rbt.Search<
FsNode>(name);
295 return reinterpret_cast<File *
>(
ans);
326 return ErrorCode::FAILED;
330 {
return fun(child); });
332 return ans ? ErrorCode::FAILED : ErrorCode::OK;
334 return ErrorCode::OK;
340 {
return fun(
item); });
355 if (name[0] ==
'.' && name[1] ==
'\0')
360 if (name[0] ==
'.' && name[1] ==
'.' && name[2] ==
'\0')
362 return reinterpret_cast<Dir *
>(
data_.parent);
369 return reinterpret_cast<Dir *
>(
ans);
399 return ErrorCode::OK;
404 {
return fun(child); });
406 return ans ? ErrorCode::FAILED : ErrorCode::OK;
409 return ErrorCode::OK;
415 {
return fun(
item); });
444 return ErrorCode::FAILED;
448 {
return fun(child); });
450 return ans ? ErrorCode::FAILED : ErrorCode::OK;
452 return ErrorCode::OK;
458 {
return fun(
item); });
472 auto ans = (*this)->rbt.Search<
FsNode>(name);
492 template <
typename DataType>
500 if (std::is_const<DataType>())
503 file->addr_const = &
raw;
525 template <
typename ArgType>
543 block->arg = std::forward<ArgType>(arg);
544 block->exec_fun = exec;
547 auto fun = [](
void *arg,
int argc,
char **
argv)
常量原始数据封装类。 A class for encapsulating constant raw data.
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
DeviceNode data_
存储的数据 (Stored data).
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
设备类,继承自红黑树节点 DeviceNode Device class inheriting from Red-Black tree node DeviceNode
uint32_t device_type
设备类型 Device type
ErrorCode Write(WriteOperation &&op, ConstRawData data)
向设备写入数据 Writes data to the device
ErrorCode Read(ReadOperation &&op, RawData data)
读取设备数据 Reads data from the device
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...
Dir * FindDirRev(const char *name)
递归查找子目录 Recursively searches for a subdirectory
void Add(Dir &dir)
添加子目录到当前目录 Adds a subdirectory to the current directory
Dir * FindDir(const char *name)
查找当前目录中的子目录 Finds a subdirectory in the current directory
void Add(Device &dev)
添加设备到当前目录 Adds a device to the current directory
Device * FindDeviceRev(const char *name)
递归查找设备 Recursively searches for a device
void Add(File &file)
添加文件到当前目录 Adds a file to 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
File * FindFile(const char *name)
查找当前目录中的文件 Finds a file in the current directory
目录节点,继承自 FsNode Directory node, inheriting from FsNode
RBTree< const char * > rbt
目录中的文件树 File tree in the directory
文件节点类,继承自 FsNode,表示文件 File node class, inheriting from FsNode, representing a file
int(* exec)(void *raw, int argc, char **argv)
可执行文件指针 Executable function pointer
void * addr
读写地址 Read/Write address
FileType type
文件类型 File type
void * arg
可执行文件参数 Executable file argument
const DataType & GetData()
获取文件数据 Retrieves file data
const void * addr_const
只读地址 Read-only address
size_t size
文件大小 File size
int Run(int argc, char **argv)
运行可执行文件 Runs an executable file
文件系统节点基类,所有文件和目录均继承自该类 Base class for file system nodes; all files and directories inherit from this
轻量级的内存文件系统,实现基本的文件、目录和设备管理 A lightweight in-memory file system implementing basic file,...
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
static File CreateFile(const char *name, DataType &raw)
创建一个新的文件 Creates a new file
void Add(Dir &dir)
向文件系统的根目录添加子目录 Adds a subdirectory to the root directory of the file system
FsNodeType
文件系统节点类型 Types of file system nodes
static Dir CreateDir(const char *name)
创建一个新的目录 Creates a new directory
static int CompareStr(const char *const &a, const char *const &b)
比较两个字符串 Compares two strings
void Add(Device &dev)
向文件系统的根目录添加设备 Adds a device to the root directory of the file system
Dir dev_
dev 目录,用于存放设备文件 dev directory for storing device files
FileType
文件类型 Types of files
@ READ_WRITE
读写 Read/Write
Dir bin_
bin 目录,用于存放可执行文件 bin directory for storing executable files
static File CreateFile(const char *name, int(*exec)(ArgType arg, int argc, char **argv), ArgType &&arg)
创建一个可执行文件 Creates an executable file
void Add(File &file)
向文件系统的根目录添加文件 Adds a file to the root directory of the file system
Dir root_
文件系统的根目录 Root directory of the file system
File * FindFile(const char *name)
在整个文件系统中查找文件 Finds a file in the entire file system
RamFS(const char *name="ramfs")
构造函数,初始化内存文件系统的根目录 Constructor that initializes the root directory of the in-memory file system
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
WritePort class for handling write operations.
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
设备节点,继承自 FsNode Device node, inheriting from FsNode
ReadPort read_port
读端口 Read port
WritePort write_port
写端口 Write port