轻量级的内存文件系统,实现基本的文件、目录和设备管理 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 66 of file ramfs.hpp.
67 {
71 };
@ READ_WRITE
读写 Read/Write
◆ FsNodeType
文件系统节点类型 Types of file system nodes
Enumerator |
---|
FILE | 文件 File
|
DIR | 目录 Directory
|
DEVICE | 设备 Device
|
STORAGE | 存储 Storage
|
UNKNOW | 未知 Unknown
|
Definition at line 52 of file ramfs.hpp.
◆ RamFS()
LibXR::RamFS::RamFS |
( |
const char * | name = "ramfs" | ) |
|
|
inline |
构造函数,初始化内存文件系统的根目录 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 28 of file ramfs.hpp.
30 {
33 }
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 593 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 587 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 581 of file ramfs.hpp.
◆ CompareStr()
static int LibXR::RamFS::CompareStr |
( |
const char *const & | a, |
|
|
const char *const & | b ) |
|
inlinestatic |
比较两个字符串 Compares two strings
- Parameters
-
- Returns
- int 比较结果 Comparison result
Definition at line 42 of file ramfs.hpp.
43 {
44 return strcmp(a, b);
45 }
◆ 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
Definition at line 564 of file ramfs.hpp.
565 {
566 Dir dir;
567
568 char *name_buff = new char[strlen(name) + 1];
569 strcpy(name_buff, name);
570 dir->name = name_buff;
572
573 return dir;
574 }
◆ 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
Definition at line 493 of file ramfs.hpp.
494 {
495 File file;
496 char *name_buff = new char[strlen(name) + 1];
497 strcpy(name_buff, name);
498 file->name = name_buff;
499
500 if (std::is_const<DataType>())
501 {
503 file->addr_const = &raw;
504 }
505 else
506 {
508 file->addr = &raw;
509 }
510
511 file->size = sizeof(DataType);
512
513 return file;
514 }
◆ 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
Definition at line 526 of file ramfs.hpp.
528 {
529 typedef struct
530 {
531 ArgType arg;
532 decltype(exec) exec_fun;
533 } FileBlock;
534
535 File file;
536
537 char *name_buff = new char[strlen(name) + 1];
538 strcpy(name_buff, name);
539 file->name = name_buff;
541
542 auto block = new FileBlock;
543 block->arg = std::forward<ArgType>(arg);
544 block->exec_fun = exec;
545 file->arg = block;
546
547 auto fun = [](void *arg, int argc, char **argv)
548 {
549 auto block = reinterpret_cast<FileBlock *>(arg);
550 return block->exec_fun(block->arg, argc, argv);
551 };
552
553 file->exec = fun;
554
555 return file;
556 }
◆ 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 618 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 610 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 602 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 630 of file ramfs.hpp.
◆ dev_
dev
目录,用于存放设备文件 dev
directory for storing device files
Definition at line 636 of file ramfs.hpp.
◆ root_
文件系统的根目录 Root directory of the file system
Definition at line 624 of file ramfs.hpp.
The documentation for this class was generated from the following file: