5#include "libxr_assert.hpp"
6#include "libxr_def.hpp"
8#include "libxr_type.hpp"
28 RamFS(
const char *name =
"ramfs");
37 static int CompareStr(
const char *
const &a,
const char *
const &b);
92 int (*
exec)(
void *raw,
int argc,
111 int Run(
int argc,
char **argv);
120 template <
typename DataType, SizeLimitMode LimitMode = SizeLimitMode::MORE>
126 return *
reinterpret_cast<DataType *
>(
addr);
130 return *
reinterpret_cast<const DataType *
>(
addr_const);
135 const void *
addr =
nullptr;
136 return *
reinterpret_cast<const DataType *
>(
addr);
180 template <
typename ReadOperation>
183 return data_.read_port(data, std::forward<ReadOperation>(op));
194 template <
typename WriteOperation>
197 return data_.write_port(data, std::forward<WriteOperation>(op));
238 (*this)->rbt.Insert(file, file->name);
248 (*this)->rbt.Insert(dir, dir->name);
258 (*this)->rbt.Insert(dev, dev->name);
325 template <
typename DataType>
329 char *name_buff =
new char[strlen(name) + 1];
330 strcpy(name_buff, name);
331 file->name = name_buff;
333 if (std::is_const<DataType>())
336 file->addr_const = &raw;
344 file->
size =
sizeof(DataType);
358 template <
typename ArgType>
360 int (*exec)(ArgType arg,
int argc,
char **argv), ArgType &&arg)
365 decltype(exec) exec_fun;
370 char *name_buff =
new char[strlen(name) + 1];
371 strcpy(name_buff, name);
372 file->name = name_buff;
375 auto block =
new FileBlock;
376 block->arg = std::forward<ArgType>(arg);
377 block->exec_fun = exec;
380 auto fun = [](
void *arg,
int argc,
char **argv)
382 auto block =
reinterpret_cast<FileBlock *
>(arg);
383 return block->exec_fun(block->arg, argc, argv);
401 char *name_buff =
new char[strlen(name) + 1];
402 strcpy(name_buff, name);
403 dir->name = name_buff;
static void SizeLimitCheck(size_t limit, size_t size)
在非调试模式下的占位大小检查函数(无实际作用)。 Dummy size limit check for non-debug builds.
常量原始数据封装类。 A class for encapsulating constant raw data.
size_t size
节点大小 (Size of the node).
BaseNode * parent
父节点 (Parent node).
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
设备类,继承自红黑树节点 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
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
目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files...
Device * FindDeviceRev(const char *name)
递归查找设备 Recursively searches for a device
void Add(Dir &dir)
添加子目录到当前目录 Adds a subdirectory to the current directory
void Add(Device &dev)
添加设备到当前目录 Adds a device to the current directory
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
目录节点,继承自 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
int Run(int argc, char **argv)
运行可执行文件 Runs an executable file
const void * addr_const
只读地址 Read-only address
size_t size
文件大小 File size
文件系统节点基类,所有文件和目录均继承自该类 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
RamFS(const char *name="ramfs")
构造函数,初始化内存文件系统的根目录 Constructor that initializes the root directory of the in-memory file system
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
void Add(Device &dev)
向文件系统的根目录添加设备 Adds a device to the root directory of the 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
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
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
WritePort class for handling write operations.
设备节点,继承自 FsNode Device node, inheriting from FsNode
ReadPort read_port
读端口 Read port
WritePort write_port
写端口 Write port