1.\" $NetBSD: fsck_ffs.8,v 1.52 2022/11/17 06:40:38 chs Exp $ 2.\" 3.\" Copyright (c) 1980, 1989, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)fsck.8 8.3 (Berkeley) 11/29/94 31.\" 32.Dd May 4, 2018 33.Dt FSCK_FFS 8 34.Os 35.Sh NAME 36.Nm fsck_ffs 37.Nd Fast File System consistency check and interactive repair 38.Sh SYNOPSIS 39.Nm 40.Op Fl adFfPpqUXz 41.Op Fl B Ar byteorder 42.Op Fl b Ar block 43.Op Fl c Ar level 44.Op Fl m Ar mode 45.Op Fl x Ar snap-backup 46.Op Fl y | n 47.Ar filesystem ... 48.Sh DESCRIPTION 49.Nm 50performs interactive file system consistency checks and repair for each of 51the file systems specified on the command line. 52It is normally invoked from 53.Xr fsck 8 . 54.Pp 55The kernel takes care that only a restricted class of innocuous file system 56inconsistencies can happen unless hardware or software failures intervene. 57These are limited to the following: 58.Pp 59.Bl -item -compact -offset indent 60.It 61Unreferenced inodes 62.It 63Link counts in inodes too large 64.It 65Missing blocks in the free map 66.It 67Blocks in the free map also in files 68.It 69Counts in the super-block wrong 70.El 71.Pp 72These are the only inconsistencies that 73.Nm 74in 75.Dq preen 76mode (with the 77.Fl p 78option) will correct; if it encounters other inconsistencies, it exits 79with an abnormal return status. 80For each corrected inconsistency one or more lines will be printed 81identifying the file system on which the correction will take place, 82and the nature of the correction. 83After successfully correcting a file system, 84.Nm 85will print the number of files on that file system, 86the number of used and free blocks, 87and the percentage of fragmentation. 88.Pp 89If sent a 90.Dv QUIT 91signal, 92.Nm 93will finish the file system checks, then exit with an abnormal return status. 94.Pp 95If 96.Nm 97receives a 98.Dv SIGINFO 99signal 100(see the 101.Sy status 102argument for 103.Xr stty 1 ) , 104a line will be written to the standard error output indicating 105the name of the device currently being checked, the current phase 106number and phase-specific progress information. 107.Pp 108Without the 109.Fl p 110option, 111.Nm 112audits and interactively repairs inconsistent conditions for file systems. 113If the file system is inconsistent the operator is prompted for concurrence 114before each correction is attempted. 115It should be noted that some of the corrective actions which are not 116correctable under the 117.Fl p 118option will result in some loss of data. 119The amount and severity of data lost may be determined from the diagnostic 120output. 121The default action for each consistency correction 122is to wait for the operator to respond 123.Li yes 124or 125.Li no . 126If the operator does not have write permission on the file system 127.Nm 128will default to a 129.Fl n 130action. 131.Pp 132.Nm 133has more consistency checks than 134its predecessors 135.Em check , dcheck , fcheck , 136and 137.Em icheck 138combined. 139.Pp 140The following flags are interpreted by 141.Nm . 142.Bl -tag -width XBXbyteorderXX -offset indent 143.It Fl a 144Interpret the filesystem as an Apple UFS filesystem, even if 145there is no Apple UFS volume label present. 146.It Fl B Ar byteorder 147Convert the file system metadata to 148.Ar byteorder 149byte order if needed. 150Valid byte orders are 151.Dq be 152and 153.Dq le . 154If 155.Nm 156is interrupted while swapping the metadata byte order, the file system cannot 157be recovered. 158.Nm 159will print a message in interactive mode if the file system is not in host 160byte order. 161.It Fl b Ar block 162Use the block number 163.Ar block 164as the super block for the file system. 165Block 32 is usually an alternative super block. 166The 167.Fl b 168option of the 169.Xr scan_ffs 8 170utility can also be used to find the offset of other super block backups 171in a file system. 172.It Fl c Ar level 173Convert the FFSv1 file system to the level 174.Ar level . 175Note that the level of a file system can only be raised. 176There are currently five levels defined: 177.Bl -tag -width 3n -offset indent 178.It 0 179The file system is in the old (static table) format. 180.It 1 181The file system is in the new (dynamic table) format. 182Such file systems are made by using the 183.Fl O Ar 0 184option to 185.Xr newfs 8 . 186.It 2 187The file system supports 32-bit UIDs and GIDs, 188short symbolic links are stored in the inode, 189and directories have an added field showing the file type. 190This format was introduced in 191.Bx 4.4 . 192.It 3 193If maxcontig is greater than one, 194build the free segment maps to aid in finding contiguous sets of blocks. 195If maxcontig is equal to one, delete any existing segment maps. 196This was the default before 197.Nx 2.0 . 198.It 4 199Rearrange the super block to the same layout as FFSv2; 200disable the rotational layout tables and per cylinder group 201block totals. 202Such file systems are made by using the 203.Fl O Ar 1 204option to 205.Xr newfs 8 . 206.El 207.Pp 208Note that FFSv2 file systems always have the features of FFSv1 level 4. 209.Pp 210FFSv2 file systems have separate conversion options: 211.Bl -tag -width 3n -offset indent 212.It ea 213Convert the file system to the format which supports extended attributes 214(and access control lists). 215After this conversion is performed, the file system will no longer be 216recognized at all by releases prior to 217.Nx 10.0 . 218.It no-ea 219Convert the file system to the format which does not support extended attributes 220(or access control lists). 221This will remove any existing extended attributes, and the file system 222will become recognizable to releases prior to 223.Nx 10.0 . 224.El 225.Pp 226In interactive mode, 227.Nm 228will list the conversion to be made 229and ask whether the conversion should be done. 230If a negative answer is given, 231no further operations are done on the file system. 232In preen mode, 233the conversion is listed and done if 234possible without user interaction. 235Conversion in preen mode is best used when all the file systems 236are being converted at once. 237.Pp 238The output of 239.Xr dumpfs 8 240can be examined to determine the format of the file system 241.Dq ( format 242in the second line) 243and the file system level 244.Dq ( fslevel 245in the sixth line). 246.Pp 247.It Fl d 248Print debugging output. 249.It Fl F 250Indicates that 251.Ar filesystem 252is a file system image, rather than a raw character device. 253.Ar filesystem 254will be accessed 255.Sq as-is , 256and no attempts will be made to read a disklabel. 257.It Fl f 258Force checking of file systems. 259Normally, if a file system is cleanly unmounted, the kernel will set a 260.Dq clean flag 261in the file system super block, and 262.Nm 263will not check the file system. 264This option forces 265.Nm 266to check the file system, regardless of the state of the clean flag. 267.It Fl m Ar mode 268Use the octal value 269.Ar mode 270as the permission bits to use when creating the 271.Pa lost+found 272directory rather than the default 1700. 273In particular, systems that do not wish to have lost files accessible 274by all users on the system should use a more restrictive 275set of permissions such as 700. 276.It Fl n 277Assume a no response to all questions asked by 278.Nm 279except for 280.Ql CONTINUE? , 281which is assumed to be affirmative; 282do not open the file system for writing. 283.It Fl P 284Display a progress meter for the file system check. 285A new meter is displayed for each of the 5 file system check passes, unless 286.Fl p 287is specified, in which case only one meter for overall progress is displayed. 288Progress meters are disabled if the 289.Fl d 290option is specified. 291.It Fl p 292Specify 293.Dq preen 294mode, described above. 295.It Fl q 296Quiet mode, do not output any messages for clean filesystems. 297.It Fl U 298Resolve user ids to usernames. 299.It Fl X 300Similar to 301.Fl x 302but uses a file system internal snapshot on the file system to be checked. 303.It Fl x Ar snap-backup 304Use a snapshot with 305.Ar snap-backup 306as backup to check a read-write mounted filesystem. 307Must be used with 308.Fl n . 309See 310.Xr fss 4 311for more details. 312The point is to check an internally-consistent version of the 313filesystem to find out if it is damaged; on failure one should unmount 314the filesystem and repair it. 315.It Fl y 316Assume a yes response to all questions asked by 317.Nm ; 318this should be used with great caution as this is a free license 319to continue after essentially unlimited trouble has been encountered. 320.It Fl z 321Clear unused directory space. 322The cleared space includes deleted file names and name padding. 323.El 324.Pp 325Inconsistencies checked are as follows: 326.Bl -enum -offset indent -compact 327.It 328Blocks claimed by more than one inode or the free map. 329.It 330Blocks claimed by an inode outside the range of the file system. 331.It 332Incorrect link counts. 333.It 334Size checks: 335.Bl -item -offset indent -compact 336.It 337Directory size not a multiple of DIRBLKSIZ. 338.It 339Partially truncated file. 340.El 341.It 342Bad inode format. 343.It 344Blocks not accounted for anywhere. 345.It 346Directory checks: 347.Bl -item -offset indent -compact 348.It 349File pointing to unallocated inode. 350.It 351Inode number out of range. 352.It 353Dot or dot-dot not the first two entries of a directory 354or having the wrong inode number. 355.El 356.It 357Super Block checks: 358.Bl -item -offset indent -compact 359.It 360More blocks for inodes than there are in the file system. 361.It 362Bad free block map format. 363.It 364Total free block and/or free inode count incorrect. 365.El 366.El 367.Pp 368Orphaned files and directories (allocated but unreferenced) are, 369with the operator's concurrence, reconnected by 370placing them in the 371.Pa lost+found 372directory. 373The name assigned is the inode number. 374If the 375.Pa lost+found 376directory does not exist, it is created. 377If there is insufficient space its size is increased. 378.Pp 379Because of inconsistencies between the block device and the buffer cache, 380the raw device should always be used. 381.Sh DIAGNOSTICS 382The diagnostics produced by 383.Nm 384are fully enumerated and explained in Appendix A of 385.Rs 386.%T "Fsck \- The UNIX File System Check Program" 387.Re 388.Sh SEE ALSO 389.Xr fss 4 , 390.Xr fs 5 , 391.Xr fstab 5 , 392.Xr dumpfs 8 , 393.Xr fsck 8 , 394.Xr fsdb 8 , 395.Xr newfs 8 , 396.Xr reboot 8 , 397.Xr scan_ffs 8 398.Sh HISTORY 399A 400.Nm fsck 401utility appeared in 402.Bx 4.0 . 403It was renamed to 404.Nm 405in 406.Nx 1.3 407with the introduction of a filesystem independent wrapper as 408.Nm fsck . 409