nilfs2: add helper to get if volume is in a valid state
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / Documentation / filesystems / nilfs2.txt
CommitLineData
962281a7
RK
1NILFS2
2------
3
4NILFS2 is a log-structured file system (LFS) supporting continuous
5snapshotting. In addition to versioning capability of the entire file
6system, users can even restore files mistakenly overwritten or
7destroyed just a few seconds ago. Since NILFS2 can keep consistency
8like conventional LFS, it achieves quick recovery after system
9crashes.
10
11NILFS2 creates a number of checkpoints every few seconds or per
12synchronous write basis (unless there is no change). Users can select
13significant versions among continuously created checkpoints, and can
14change them into snapshots which will be preserved until they are
15changed back to checkpoints.
16
17There is no limit on the number of snapshots until the volume gets
18full. Each snapshot is mountable as a read-only file system
19concurrently with its writable mount, and this feature is convenient
20for online backup.
21
22The userland tools are included in nilfs-utils package, which is
23available from the following download page. At least "mkfs.nilfs2",
24"mount.nilfs2", "umount.nilfs2", and "nilfs_cleanerd" (so called
25cleaner or garbage collector) are required. Details on the tools are
26described in the man pages included in the package.
27
28Project web page: http://www.nilfs.org/en/
29Download page: http://www.nilfs.org/en/download.html
30Git tree web page: http://www.nilfs.org/git/
31NILFS mailing lists: http://www.nilfs.org/mailman/listinfo/users
32
33Caveats
34=======
35
36Features which NILFS2 does not support yet:
37
38 - atime
39 - extended attributes
40 - POSIX ACLs
41 - quotas
fb6e7113
RK
42 - fsck
43 - resize
962281a7
RK
44 - defragmentation
45
46Mount options
47=============
48
49NILFS2 supports the following mount options:
50(*) == default
51
91f1953b 52nobarrier Disables barriers.
962281a7
RK
53errors=continue(*) Keep going on a filesystem error.
54errors=remount-ro Remount the filesystem read-only on an error.
55errors=panic Panic and halt the machine if an error occurs.
56cp=n Specify the checkpoint-number of the snapshot to be
57 mounted. Checkpoints and snapshots are listed by lscp
58 user command. Only the checkpoints marked as snapshot
59 are mountable with this option. Snapshot is read-only,
60 so a read-only mount option must be specified together.
61order=relaxed(*) Apply relaxed order semantics that allows modified data
62 blocks to be written to disk without making a
63 checkpoint if no metadata update is going. This mode
64 is equivalent to the ordered data mode of the ext3
65 filesystem except for the updates on data blocks still
66 conserve atomicity. This will improve synchronous
67 write performance for overwriting.
68order=strict Apply strict in-order semantics that preserves sequence
69 of all file operations including overwriting of data
70 blocks. That means, it is guaranteed that no
71 overtaking of events occurs in the recovered file
72 system after a crash.
73
74NILFS2 usage
75============
76
77To use nilfs2 as a local file system, simply:
78
79 # mkfs -t nilfs2 /dev/block_device
80 # mount -t nilfs2 /dev/block_device /dir
81
82This will also invoke the cleaner through the mount helper program
83(mount.nilfs2).
84
85Checkpoints and snapshots are managed by the following commands.
86Their manpages are included in the nilfs-utils package above.
87
88 lscp list checkpoints or snapshots.
89 mkcp make a checkpoint or a snapshot.
90 chcp change an existing checkpoint to a snapshot or vice versa.
91 rmcp invalidate specified checkpoint(s).
92
93To mount a snapshot,
94
95 # mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir
96
97where <cno> is the checkpoint number of the snapshot.
98
99To unmount the NILFS2 mount point or snapshot, simply:
100
101 # umount /dir
102
103Then, the cleaner daemon is automatically shut down by the umount
104helper program (umount.nilfs2).
105
106Disk format
107===========
108
109A nilfs2 volume is equally divided into a number of segments except
110for the super block (SB) and segment #0. A segment is the container
111of logs. Each log is composed of summary information blocks, payload
112blocks, and an optional super root block (SR):
113
114 ______________________________________________________
115 | |SB| | Segment | Segment | Segment | ... | Segment | |
116 |_|__|_|____0____|____1____|____2____|_____|____N____|_|
117 0 +1K +4K +8M +16M +24M +(8MB x N)
118 . . (Typical offsets for 4KB-block)
119 . .
120 .______________________.
121 | log | log |... | log |
122 |__1__|__2__|____|__m__|
123 . .
124 . .
125 . .
126 .______________________________.
127 | Summary | Payload blocks |SR|
128 |_blocks__|_________________|__|
129
130The payload blocks are organized per file, and each file consists of
131data blocks and B-tree node blocks:
132
133 |<--- File-A --->|<--- File-B --->|
134 _______________________________________________________________
135 | Data blocks | B-tree blocks | Data blocks | B-tree blocks | ...
136 _|_____________|_______________|_____________|_______________|_
137
138
139Since only the modified blocks are written in the log, it may have
140files without data blocks or B-tree node blocks.
141
142The organization of the blocks is recorded in the summary information
143blocks, which contains a header structure (nilfs_segment_summary), per
144file structures (nilfs_finfo), and per block structures (nilfs_binfo):
145
146 _________________________________________________________________________
147 | Summary | finfo | binfo | ... | binfo | finfo | binfo | ... | binfo |...
148 |_blocks__|___A___|_(A,1)_|_____|(A,Na)_|___B___|_(B,1)_|_____|(B,Nb)_|___
149
150
151The logs include regular files, directory files, symbolic link files
152and several meta data files. The mata data files are the files used
153to maintain file system meta data. The current version of NILFS2 uses
154the following meta data files:
155
156 1) Inode file (ifile) -- Stores on-disk inodes
157 2) Checkpoint file (cpfile) -- Stores checkpoints
158 3) Segment usage file (sufile) -- Stores allocation state of segments
159 4) Data address translation file -- Maps virtual block numbers to usual
160 (DAT) block numbers. This file serves to
161 make on-disk blocks relocatable.
962281a7
RK
162
163The following figure shows a typical organization of the logs:
164
165 _________________________________________________________________________
166 | Summary | regular file | file | ... | ifile | cpfile | sufile | DAT |SR|
167 |_blocks__|_or_directory_|_______|_____|_______|________|________|_____|__|
168
169
170To stride over segment boundaries, this sequence of files may be split
171into multiple logs. The sequence of logs that should be treated as
172logically one log, is delimited with flags marked in the segment
173summary. The recovery code of nilfs2 looks this boundary information
174to ensure atomicity of updates.
175
176The super root block is inserted for every checkpoints. It includes
177three special inodes, inodes for the DAT, cpfile, and sufile. Inodes
178of regular files, directories, symlinks and other special files, are
179included in the ifile. The inode of ifile itself is included in the
180corresponding checkpoint entry in the cpfile. Thus, the hierarchy
181among NILFS2 files can be depicted as follows:
182
183 Super block (SB)
184 |
185 v
186 Super root block (the latest cno=xx)
187 |-- DAT
188 |-- sufile
189 `-- cpfile
190 |-- ifile (cno=c1)
191 |-- ifile (cno=c2) ---- file (ino=i1)
192 : : |-- file (ino=i2)
193 `-- ifile (cno=xx) |-- file (ino=i3)
194 : :
195 `-- file (ino=yy)
196 ( regular file, directory, or symlink )
197
198For detail on the format of each file, please see include/linux/nilfs2_fs.h.