Skip to main content

File System Module

The file system module is one of the core components of ElenixOS, providing file and directory operation functions, including file reading and writing, directory management, path operations, etc. This module provides a unified file system access interface for applications and system components, simplifying file operations.

Directory Structure

├── src/core/system/file_system/
│ ├── eos_dfw.c # File system distributed firmware update
│ ├── eos_dfw.h # File system distributed firmware update interface
│ ├── eos_fs.c # File system core implementation
│ └── eos_fs.h # File system interface definition

Core Features

File Operations

The file system module provides file reading, writing, creation, deletion and other operations, supporting the processing of text files and binary files.

Directory Management

Directory management functions include directory creation, deletion, judgment and other operations, supporting recursive creation and deletion of directories.

Path Operations

Path operations include path concatenation, parsing, judgment and other operations, supporting relative paths and absolute paths.

Firmware Update

The file system module also supports distributed firmware update functionality for system firmware update and management.

Key Interfaces

File Operation Interfaces

int eos_fs_puts(const char *s, eos_file_t fp);
char *eos_fs_read_file(const char *path);
int eos_fs_write_file(const char *path, const void *data, size_t data_size);
  • eos_fs_puts:Write string to file
  • eos_fs_read_file:Read entire file content to dynamically allocated buffer
  • eos_fs_write_file:Write file

Directory Operation Interfaces

bool eos_is_dir(const char *path);
bool eos_is_file(const char *path);
int eos_fs_mkdir_if_not_exist(const char *path);
int eos_fs_mkdir_recursive(const char *path);
int eos_fs_rm_recursive(const char *path);
  • eos_is_dir:Check if path is a directory
  • eos_is_file:Check if path is a file
  • eos_fs_mkdir_if_not_exist:Create directory if it doesn't exist
  • eos_fs_mkdir_recursive:Recursively create directory tree
  • eos_fs_rm_recursive:Recursively delete directory and its contents

File Creation Interface

int eos_create_file_if_not_exist(const char *path, const char *default_content);
  • If the file doesn't exist, create it and write default content

Implementation Details

The core implementation of the file system module includes:

  1. File operation encapsulation:Encapsulate underlying file system operations to provide a unified interface
  2. Path processing:Handle file path concatenation, parsing and other operations
  3. Error handling:Provide a unified error handling mechanism
  4. Memory management:Manage memory allocation and release during file operations

This module works closely with the underlying file system to provide a unified file system access interface for upper-level applications.

Usage Examples

Read File

char *content = eos_fs_read_file("/path/to/file.txt");
if (content) {
// Process file content
eos_free(content);
}

Write File

const char *data = "Hello, ElenixOS!";
eos_fs_write_file("/path/to/file.txt", data, strlen(data));

Create Directory

eos_fs_mkdir_recursive("/path/to/directory");

Recursively Delete Directory

eos_fs_rm_recursive("/path/to/directory");

File System Architecture

The file system module adopts a layered architecture:

  1. Interface layer:Provide a unified file system access interface
  2. Implementation layer:Implement specific file system operations
  3. Porting layer:Adapt to different platform file system implementations

This architectural design allows the file system module to maintain a consistent interface across different platforms while providing optimized implementations for specific platforms.