kernel-small-bundles-fs-support-ramfs.md 1.6 KB
Newer Older
D
duangavin123 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
# Ramfs<a name="EN-US_TOPIC_0000001078864272"></a>

-   [Basic Concepts](#section9507151014420)
-   [Working Principles](#section1859711263447)
-   [Development Guidelines](#section163554380448)

## Basic Concepts<a name="section9507151014420"></a>

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, and data is lost after a power outage.

## Working Principles<a name="section1859711263447"></a>

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<a name="section163554380448"></a>

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)
```

Deletes a directory:

```
rmdir(pathname)
```

Unmount:

```
umount("/dev/shm")
```

>![](../public_sys-resources/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.