开源鸿蒙 Ramfs

  • 2022-08-09
  • 浏览 (581)

Ramfs

Basic Concepts

Ramfs is a RAM-based file system whose size can be dynamically adjusted. Ramfs does not have a backing store. Directory entries and page caches are allocated when files are written into ramfs. However, data is not written back to any other storage medium. This means that data will be lost after a power outage.

Working Principles

Ramfs stores all files in RAM, and read/write operations are performed in RAM. Ramfs is generally used to store temporary data or data that needs to be frequently modified, such as the /tmp and /var directories. Using ramfs reduces the read/write loss of the memory and improves the data read/write speed.

Development Guidelines

Mount:

mount(NULL, "/dev/shm", "ramfs", 0, NULL)

Create a directory:

mkdir(pathname, mode)

Create a file:

open(pathname, O_NONBLOCK | O_CREAT | O_RDWR, mode)

Read a directory:

dir = opendir(pathname) 
ptr = readdir(dir)
closedir(dir)

Delete a file:

unlink(pathname)

Delete a directory:

rmdir(pathname)

Unmount:

umount("/dev/shm")

icon-caution.gif CAUTION
- A ramfs file system can be mounted only once. Once mounted to a directory, it cannot be mounted to other directories.

  • Ramfs is under debugging and disabled by default. Do not use it in formal products.

你可能感兴趣的文章

开源鸿蒙 Kernel

开源鸿蒙 Time Management

开源鸿蒙 Appendix

开源鸿蒙 Kernel Coding Specification

开源鸿蒙 Doubly Linked List

开源鸿蒙 Basic Data Structure

开源鸿蒙 CMSIS Support

开源鸿蒙 POSIX Support

开源鸿蒙 Standard Libraries

开源鸿蒙 Interrupt Management

0  赞