轻量级的内存文件系统,实现基本的文件、目录和设备管理 A lightweight in-memory file system implementing basic file, directory, and device management
More...
#include <ramfs.hpp>
|
| | RamFS (const char *name="ramfs") |
| | 构造函数,初始化内存文件系统的根目录 Constructor that initializes the root directory of the in-memory file system
|
| |
| void | Add (File &file) |
| | 向文件系统的根目录添加文件 Adds a file to the root directory of the file system
|
| |
| void | Add (Dir &dir) |
| | 向文件系统的根目录添加子目录 Adds a subdirectory to the root directory of the file system
|
| |
| void | Add (Device &dev) |
| | 向文件系统的根目录添加设备 Adds a device to the root directory of the file system
|
| |
| File * | FindFile (const char *name) |
| | 在整个文件系统中查找文件 Finds a file in the entire file system
|
| |
| 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 int | CompareStr (const char *const &a, const char *const &b) |
| | 比较两个字符串 Compares two strings
|
| |
| template<typename DataType > |
| static File | CreateFile (const char *name, DataType &raw) |
| | 创建一个新的文件 Creates a new file
|
| |
| template<typename ArgType > |
| static File | CreateFile (const char *name, int(*exec)(ArgType arg, int argc, char **argv), ArgType &&arg) |
| | 创建一个可执行文件 Creates an executable file
|
| |
| static Dir | CreateDir (const char *name) |
| | 创建一个新的目录 Creates a new directory
|
| |
|
| Dir | root_ |
| | 文件系统的根目录 Root directory of the file system
|
| |
| Dir | bin_ |
| | bin 目录,用于存放可执行文件 bin directory for storing executable files
|
| |
| Dir | dev_ |
| | dev 目录,用于存放设备文件 dev directory for storing device files
|
| |
轻量级的内存文件系统,实现基本的文件、目录和设备管理 A lightweight in-memory file system implementing basic file, directory, and device management
Definition at line 19 of file ramfs.hpp.
◆ File
◆ FileType
文件类型 Types of files
| Enumerator |
|---|
| READ_ONLY | 只读 Read-only
|
| READ_WRITE | 读写 Read/Write
|
| EXEC | 可执行 Executable
|
Definition at line 58 of file ramfs.hpp.
59 {
63 };
@ READ_WRITE
读写 Read/Write
◆ FsNodeType
文件系统节点类型 Types of file system nodes
| Enumerator |
|---|
| FILE | 文件 File
|
| DIR | 目录 Directory
|
| DEVICE | 设备 Device
|
| STORAGE | 存储 Storage
|
| UNKNOWN | 未知 Unknown
|
Definition at line 44 of file ramfs.hpp.
◆ RamFS()
| RamFS::RamFS |
( |
const char * | name = "ramfs" | ) |
|
构造函数,初始化内存文件系统的根目录 Constructor that initializes the root directory of the in-memory file system
- Parameters
-
| name | 根目录的名称(默认为 "ramfs") Name of the root directory (default: "ramfs") |
Definition at line 5 of file ramfs.cpp.
7{
10}
void Add(File &file)
添加文件到当前目录 Adds a file to the current directory
static Dir CreateDir(const char *name)
创建一个新的目录 Creates a new directory
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
◆ Add() [1/3]
| void LibXR::RamFS::Add |
( |
Device & | dev | ) |
|
|
inline |
向文件系统的根目录添加设备 Adds a device to the root directory of the file system
- Parameters
-
| dev | 要添加的设备 The device to be added |
Definition at line 435 of file ramfs.hpp.
◆ Add() [2/3]
| void LibXR::RamFS::Add |
( |
Dir & | dir | ) |
|
|
inline |
向文件系统的根目录添加子目录 Adds a subdirectory to the root directory of the file system
- Parameters
-
| dir | 要添加的子目录 The subdirectory to be added |
Definition at line 429 of file ramfs.hpp.
◆ Add() [3/3]
| void LibXR::RamFS::Add |
( |
File & | file | ) |
|
|
inline |
向文件系统的根目录添加文件 Adds a file to the root directory of the file system
- Parameters
-
| file | 要添加的文件 The file to be added |
Definition at line 423 of file ramfs.hpp.
◆ CompareStr()
| int RamFS::CompareStr |
( |
const char *const & | a, |
|
|
const char *const & | b ) |
|
static |
比较两个字符串 Compares two strings
- Parameters
-
- Returns
- int 比较结果 Comparison result
Definition at line 12 of file ramfs.cpp.
12{ return strcmp(a, b); }
◆ CreateDir()
| static Dir LibXR::RamFS::CreateDir |
( |
const char * | name | ) |
|
|
inlinestatic |
创建一个新的目录 Creates a new directory
- Parameters
-
| name | 目录名称 The name of the directory |
- Returns
- Dir 创建的目录对象 The created directory object
- Note
- 包含动态内存分配。 Contains dynamic memory allocation.
Definition at line 406 of file ramfs.hpp.
407 {
408 Dir dir;
409
410 char* name_buff = new char[strlen(name) + 1];
411 strcpy(name_buff, name);
412 dir->name = name_buff;
414
415 return dir;
416 }
◆ CreateFile() [1/2]
template<typename DataType >
| static File LibXR::RamFS::CreateFile |
( |
const char * | name, |
|
|
DataType & | raw ) |
|
inlinestatic |
创建一个新的文件 Creates a new file
- Template Parameters
-
| DataType | 文件存储的数据类型 Data type stored in the file |
- Parameters
-
| name | 文件名 The name of the file |
| raw | 文件存储的数据 Data stored in the file |
- Returns
- File 创建的文件对象 The created file object
- Note
- 包含动态内存分配。 Contains dynamic memory allocation.
Definition at line 329 of file ramfs.hpp.
330 {
331 File file;
332 char* name_buff = new char[strlen(name) + 1];
333 strcpy(name_buff, name);
334 file->name = name_buff;
335
336 if (std::is_const<DataType>())
337 {
339 file->addr_const = &raw;
340 }
341 else
342 {
344 file->addr = &raw;
345 }
346
347 file->size = sizeof(DataType);
348
349 return file;
350 }
◆ CreateFile() [2/2]
template<typename ArgType >
| static File LibXR::RamFS::CreateFile |
( |
const char * | name, |
|
|
int(* | exec )(ArgType arg, int argc, char **argv), |
|
|
ArgType && | arg ) |
|
inlinestatic |
创建一个可执行文件 Creates an executable file
- Template Parameters
-
| ArgType | 可执行文件的参数类型 The argument type for the executable file |
- Parameters
-
| name | 文件名 The name of the file |
| exec | 可执行函数 The executable function |
| arg | 可执行文件的参数 The argument for the executable file |
- Returns
- File 创建的可执行文件对象 The created executable file object
- Note
- 包含动态内存分配。 Contains dynamic memory allocation.
Definition at line 365 of file ramfs.hpp.
367 {
368 typedef struct
369 {
370 ArgType arg;
371 decltype(exec) exec_fun;
372 } FileBlock;
373
374 File file;
375
376 char* name_buff = new char[strlen(name) + 1];
377 strcpy(name_buff, name);
378 file->name = name_buff;
380
381 auto block = new FileBlock;
382 block->arg = std::forward<ArgType>(arg);
383 block->exec_fun = exec;
384 file->arg = block;
385
386 auto fun = [](void* arg, int argc, char** argv)
387 {
388 auto block = reinterpret_cast<FileBlock*>(arg);
389 return block->exec_fun(block->arg, argc, argv);
390 };
391
392 file->exec = fun;
393
394 return file;
395 }
◆ FindDevice()
| Device * LibXR::RamFS::FindDevice |
( |
const char * | name | ) |
|
|
inline |
在整个文件系统中查找设备 Finds a device in the entire file system
- Parameters
-
| name | 设备名 The name of the device |
- Returns
- Device* 指向找到的设备的指针,如果未找到则返回 nullptr Pointer to the found device, or nullptr if not found
Definition at line 460 of file ramfs.hpp.
Device * FindDeviceRev(const char *name)
递归查找设备 Recursively searches for a device
◆ FindDir()
| Dir * LibXR::RamFS::FindDir |
( |
const char * | name | ) |
|
|
inline |
在整个文件系统中查找目录 Finds a directory in the entire file system
- Parameters
-
| name | 目录名 The name of the directory |
- Returns
- Dir* 指向找到的目录的指针,如果未找到则返回 nullptr Pointer to the found directory, or nullptr if not found
Definition at line 452 of file ramfs.hpp.
Dir * FindDirRev(const char *name)
递归查找子目录 Recursively searches for a subdirectory
◆ FindFile()
| File * LibXR::RamFS::FindFile |
( |
const char * | name | ) |
|
|
inline |
在整个文件系统中查找文件 Finds a file in the entire file system
- Parameters
-
| name | 文件名 The name of the file |
- Returns
- File* 指向找到的文件的指针,如果未找到则返回 nullptr Pointer to the found file, or nullptr if not found
Definition at line 444 of file ramfs.hpp.
File * FindFileRev(const char *name)
递归查找文件 Recursively searches for a file
◆ bin_
bin 目录,用于存放可执行文件 bin directory for storing executable files
Definition at line 472 of file ramfs.hpp.
◆ dev_
dev 目录,用于存放设备文件 dev directory for storing device files
Definition at line 478 of file ramfs.hpp.
◆ root_
文件系统的根目录 Root directory of the file system
Definition at line 466 of file ramfs.hpp.
The documentation for this class was generated from the following files: