Deleted Added
full compact
3.t (18808) 3.t (66861)
1.\" Copyright (c) 1982, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.

--- 15 unchanged lines hidden (view full) ---

24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
1.\" Copyright (c) 1982, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.

--- 15 unchanged lines hidden (view full) ---

24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" $FreeBSD: head/sbin/fsck_ffs/SMM.doc/3.t 66861 2000-10-09 08:26:35Z adrian $
32.\" @(#)3.t 8.1 (Berkeley) 6/5/93
33.\"
34.ds RH Fixing corrupted file systems
35.NH
36Fixing corrupted file systems
37.PP
38A file system
39can become corrupted in several ways.

--- 21 unchanged lines hidden (view full) ---

61Any piece of hardware can fail at any time.
62Failures
63can be as subtle as a bad block
64on a disk pack, or as blatant as a non-functional disk-controller.
65.NH 2
66Detecting and correcting corruption
67.PP
68Normally
33.\" @(#)3.t 8.1 (Berkeley) 6/5/93
34.\"
35.ds RH Fixing corrupted file systems
36.NH
37Fixing corrupted file systems
38.PP
39A file system
40can become corrupted in several ways.

--- 21 unchanged lines hidden (view full) ---

62Any piece of hardware can fail at any time.
63Failures
64can be as subtle as a bad block
65on a disk pack, or as blatant as a non-functional disk-controller.
66.NH 2
67Detecting and correcting corruption
68.PP
69Normally
69.I fsck
70.I fsck_ffs
70is run non-interactively.
71In this mode it will only fix
72corruptions that are expected to occur from an unclean halt.
73These actions are a proper subset of the actions that
71is run non-interactively.
72In this mode it will only fix
73corruptions that are expected to occur from an unclean halt.
74These actions are a proper subset of the actions that
74.I fsck
75.I fsck_ffs
75will take when it is running interactively.
76Throughout this paper we assume that
76will take when it is running interactively.
77Throughout this paper we assume that
77.I fsck
78.I fsck_ffs
78is being run interactively,
79and all possible errors can be encountered.
80When an inconsistency is discovered in this mode,
79is being run interactively,
80and all possible errors can be encountered.
81When an inconsistency is discovered in this mode,
81.I fsck
82.I fsck_ffs
82reports the inconsistency for the operator to
83chose a corrective action.
84.PP
85A quiescent\(dd
86.FS
87\(dd I.e., unmounted and not being written on.
88.FE
89file system may be checked for structural integrity
90by performing consistency checks on the
91redundant data intrinsic to a file system.
92The redundant data is either read from
93the file system,
94or computed from other known values.
95The file system
96.B must
97be in a quiescent state when
83reports the inconsistency for the operator to
84chose a corrective action.
85.PP
86A quiescent\(dd
87.FS
88\(dd I.e., unmounted and not being written on.
89.FE
90file system may be checked for structural integrity
91by performing consistency checks on the
92redundant data intrinsic to a file system.
93The redundant data is either read from
94the file system,
95or computed from other known values.
96The file system
97.B must
98be in a quiescent state when
98.I fsck
99.I fsck_ffs
99is run,
100since
100is run,
101since
101.I fsck
102.I fsck_ffs
102is a multi-pass program.
103.PP
104In the following sections,
105we discuss methods to discover inconsistencies
106and possible corrective actions
107for the cylinder group blocks, the inodes, the indirect blocks, and
108the data blocks containing directory entries.
109.NH 2

--- 11 unchanged lines hidden (view full) ---

121The super-block is checked for inconsistencies
122involving file-system size, number of inodes,
123free-block count, and the free-inode count.
124The file-system size must be larger than the
125number of blocks used by the super-block
126and the number of blocks used by the list of inodes.
127The file-system size and layout information
128are the most critical pieces of information for
103is a multi-pass program.
104.PP
105In the following sections,
106we discuss methods to discover inconsistencies
107and possible corrective actions
108for the cylinder group blocks, the inodes, the indirect blocks, and
109the data blocks containing directory entries.
110.NH 2

--- 11 unchanged lines hidden (view full) ---

122The super-block is checked for inconsistencies
123involving file-system size, number of inodes,
124free-block count, and the free-inode count.
125The file-system size must be larger than the
126number of blocks used by the super-block
127and the number of blocks used by the list of inodes.
128The file-system size and layout information
129are the most critical pieces of information for
129.I fsck .
130.I fsck_ffs .
130While there is no way to actually check these sizes,
131since they are statically determined by
132.I newfs ,
131While there is no way to actually check these sizes,
132since they are statically determined by
133.I newfs ,
133.I fsck
134.I fsck_ffs
134can check that these sizes are within reasonable bounds.
135All other file system checks require that these sizes be correct.
136If
135can check that these sizes are within reasonable bounds.
136All other file system checks require that these sizes be correct.
137If
137.I fsck
138.I fsck_ffs
138detects corruption in the static parameters of the default super-block,
139detects corruption in the static parameters of the default super-block,
139.I fsck
140.I fsck_ffs
140requests the operator to specify the location of an alternate super-block.
141.NH 2
142Free block checking
143.PP
141requests the operator to specify the location of an alternate super-block.
142.NH 2
143Free block checking
144.PP
144.I Fsck
145.I Fsck_ffs
145checks that all the blocks
146marked as free in the cylinder group block maps
147are not claimed by any files.
148When all the blocks have been initially accounted for,
146checks that all the blocks
147marked as free in the cylinder group block maps
148are not claimed by any files.
149When all the blocks have been initially accounted for,
149.I fsck
150.I fsck_ffs
150checks that
151the number of free blocks
152plus the number of blocks claimed by the inodes
153equals the total number of blocks in the file system.
154.PP
155If anything is wrong with the block allocation maps,
151checks that
152the number of free blocks
153plus the number of blocks claimed by the inodes
154equals the total number of blocks in the file system.
155.PP
156If anything is wrong with the block allocation maps,
156.I fsck
157.I fsck_ffs
157will rebuild them,
158based on the list it has computed of allocated blocks.
159.PP
160The summary information associated with the super-block
161counts the total number of free blocks within the file system.
158will rebuild them,
159based on the list it has computed of allocated blocks.
160.PP
161The summary information associated with the super-block
162counts the total number of free blocks within the file system.
162.I Fsck
163.I Fsck_ffs
163compares this count to the
164number of free blocks it found within the file system.
165If the two counts do not agree, then
164compares this count to the
165number of free blocks it found within the file system.
166If the two counts do not agree, then
166.I fsck
167.I fsck_ffs
167replaces the incorrect count in the summary information
168by the actual free-block count.
169.PP
170The summary information
171counts the total number of free inodes within the file system.
168replaces the incorrect count in the summary information
169by the actual free-block count.
170.PP
171The summary information
172counts the total number of free inodes within the file system.
172.I Fsck
173.I Fsck_ffs
173compares this count to the number
174of free inodes it found within the file system.
175If the two counts do not agree, then
174compares this count to the number
175of free inodes it found within the file system.
176If the two counts do not agree, then
176.I fsck
177.I fsck_ffs
177replaces the incorrect count in the
178summary information by the actual free-inode count.
179.NH 2
180Checking the inode state
181.PP
182An individual inode is not as likely to be corrupted as
183the allocation information.
184However, because of the great number of active inodes,

--- 17 unchanged lines hidden (view full) ---

202regular inode, directory inode, symbolic link inode,
203special block inode, special character inode, or socket inode.
204Inodes may be found in one of three allocation states:
205unallocated, allocated, and neither unallocated nor allocated.
206This last state suggests an incorrectly formated inode.
207An inode can get in this state if
208bad data is written into the inode list.
209The only possible corrective action is for
178replaces the incorrect count in the
179summary information by the actual free-inode count.
180.NH 2
181Checking the inode state
182.PP
183An individual inode is not as likely to be corrupted as
184the allocation information.
185However, because of the great number of active inodes,

--- 17 unchanged lines hidden (view full) ---

203regular inode, directory inode, symbolic link inode,
204special block inode, special character inode, or socket inode.
205Inodes may be found in one of three allocation states:
206unallocated, allocated, and neither unallocated nor allocated.
207This last state suggests an incorrectly formated inode.
208An inode can get in this state if
209bad data is written into the inode list.
210The only possible corrective action is for
210.I fsck
211.I fsck_ffs
211is to clear the inode.
212.NH 2
213Inode links
214.PP
215Each inode counts the
216total number of directory entries
217linked to the inode.
212is to clear the inode.
213.NH 2
214Inode links
215.PP
216Each inode counts the
217total number of directory entries
218linked to the inode.
218.I Fsck
219.I Fsck_ffs
219verifies the link count of each inode
220by starting at the root of the file system,
221and descending through the directory structure.
222The actual link count for each inode
223is calculated during the descent.
224.PP
225If the stored link count is non-zero and the actual
226link count is zero,
227then no directory entry appears for the inode.
228If this happens,
220verifies the link count of each inode
221by starting at the root of the file system,
222and descending through the directory structure.
223The actual link count for each inode
224is calculated during the descent.
225.PP
226If the stored link count is non-zero and the actual
227link count is zero,
228then no directory entry appears for the inode.
229If this happens,
229.I fsck
230.I fsck_ffs
230will place the disconnected file in the
231.I lost+found
232directory.
233If the stored and actual link counts are non-zero and unequal,
234a directory entry may have been added or removed without the inode being
235updated.
236If this happens,
231will place the disconnected file in the
232.I lost+found
233directory.
234If the stored and actual link counts are non-zero and unequal,
235a directory entry may have been added or removed without the inode being
236updated.
237If this happens,
237.I fsck
238.I fsck_ffs
238replaces the incorrect stored link count by the actual link count.
239.PP
240Each inode contains a list,
241or pointers to
242lists (indirect blocks),
243of all the blocks claimed by the inode.
244Since indirect blocks are owned by an inode,
245inconsistencies in indirect blocks directly
246affect the inode that owns it.
247.PP
239replaces the incorrect stored link count by the actual link count.
240.PP
241Each inode contains a list,
242or pointers to
243lists (indirect blocks),
244of all the blocks claimed by the inode.
245Since indirect blocks are owned by an inode,
246inconsistencies in indirect blocks directly
247affect the inode that owns it.
248.PP
248.I Fsck
249.I Fsck_ffs
249compares each block number claimed by an inode
250against a list of already allocated blocks.
251If another inode already claims a block number,
252then the block number is added to a list of
253.I "duplicate blocks" .
254Otherwise, the list of allocated blocks
255is updated to include the block number.
256.PP
257If there are any duplicate blocks,
250compares each block number claimed by an inode
251against a list of already allocated blocks.
252If another inode already claims a block number,
253then the block number is added to a list of
254.I "duplicate blocks" .
255Otherwise, the list of allocated blocks
256is updated to include the block number.
257.PP
258If there are any duplicate blocks,
258.I fsck
259.I fsck_ffs
259will perform a partial second
260pass over the inode list
261to find the inode of the duplicated block.
262The second pass is needed,
263since without examining the files associated with
264these inodes for correct content,
265not enough information is available
266to determine which inode is corrupted and should be cleared.
267If this condition does arise
268(only hardware failure will cause it),
269then the inode with the earliest
270modify time is usually incorrect,
271and should be cleared.
272If this happens,
260will perform a partial second
261pass over the inode list
262to find the inode of the duplicated block.
263The second pass is needed,
264since without examining the files associated with
265these inodes for correct content,
266not enough information is available
267to determine which inode is corrupted and should be cleared.
268If this condition does arise
269(only hardware failure will cause it),
270then the inode with the earliest
271modify time is usually incorrect,
272and should be cleared.
273If this happens,
273.I fsck
274.I fsck_ffs
274prompts the operator to clear both inodes.
275The operator must decide which one should be kept
276and which one should be cleared.
277.PP
275prompts the operator to clear both inodes.
276The operator must decide which one should be kept
277and which one should be cleared.
278.PP
278.I Fsck
279.I Fsck_ffs
279checks the range of each block number claimed by an inode.
280If the block number is
281lower than the first data block in the file system,
282or greater than the last data block,
283then the block number is a
284.I "bad block number" .
285Many bad blocks in an inode are usually caused by
286an indirect block that was not written to the file system,
287a condition which can only occur if there has been a hardware failure.
288If an inode contains bad block numbers,
280checks the range of each block number claimed by an inode.
281If the block number is
282lower than the first data block in the file system,
283or greater than the last data block,
284then the block number is a
285.I "bad block number" .
286Many bad blocks in an inode are usually caused by
287an indirect block that was not written to the file system,
288a condition which can only occur if there has been a hardware failure.
289If an inode contains bad block numbers,
289.I fsck
290.I fsck_ffs
290prompts the operator to clear it.
291.NH 2
292Inode data size
293.PP
294Each inode contains a count of the number of data blocks
295that it contains.
296The number of actual data blocks
297is the sum of the allocated data blocks
298and the indirect blocks.
291prompts the operator to clear it.
292.NH 2
293Inode data size
294.PP
295Each inode contains a count of the number of data blocks
296that it contains.
297The number of actual data blocks
298is the sum of the allocated data blocks
299and the indirect blocks.
299.I Fsck
300.I Fsck_ffs
300computes the actual number of data blocks
301and compares that block count against
302the actual number of blocks the inode claims.
303If an inode contains an incorrect count
301computes the actual number of data blocks
302and compares that block count against
303the actual number of blocks the inode claims.
304If an inode contains an incorrect count
304.I fsck
305.I fsck_ffs
305prompts the operator to fix it.
306.PP
307Each inode contains a thirty-two bit size field.
308The size is the number of data bytes
309in the file associated with the inode.
310The consistency of the byte size field is roughly checked
311by computing from the size field the maximum number of blocks
312that should be associated with the inode,

--- 7 unchanged lines hidden (view full) ---

320All referenced blocks must be the same kind.
321The three types of data blocks are:
322plain data blocks, symbolic link data blocks, and directory data blocks.
323Plain data blocks
324contain the information stored in a file;
325symbolic link data blocks
326contain the path name stored in a link.
327Directory data blocks contain directory entries.
306prompts the operator to fix it.
307.PP
308Each inode contains a thirty-two bit size field.
309The size is the number of data bytes
310in the file associated with the inode.
311The consistency of the byte size field is roughly checked
312by computing from the size field the maximum number of blocks
313that should be associated with the inode,

--- 7 unchanged lines hidden (view full) ---

321All referenced blocks must be the same kind.
322The three types of data blocks are:
323plain data blocks, symbolic link data blocks, and directory data blocks.
324Plain data blocks
325contain the information stored in a file;
326symbolic link data blocks
327contain the path name stored in a link.
328Directory data blocks contain directory entries.
328.I Fsck
329.I Fsck_ffs
329can only check the validity of directory data blocks.
330.PP
331Each directory data block is checked for
332several types of inconsistencies.
333These inconsistencies include
334directory inode numbers pointing to unallocated inodes,
335directory inode numbers that are greater than
336the number of inodes in the file system,
337incorrect directory inode numbers for ``\fB.\fP'' and ``\fB..\fP'',
338and directories that are not attached to the file system.
339If the inode number in a directory data block
340references an unallocated inode,
341then
330can only check the validity of directory data blocks.
331.PP
332Each directory data block is checked for
333several types of inconsistencies.
334These inconsistencies include
335directory inode numbers pointing to unallocated inodes,
336directory inode numbers that are greater than
337the number of inodes in the file system,
338incorrect directory inode numbers for ``\fB.\fP'' and ``\fB..\fP'',
339and directories that are not attached to the file system.
340If the inode number in a directory data block
341references an unallocated inode,
342then
342.I fsck
343.I fsck_ffs
343will remove that directory entry.
344Again,
345this condition can only arise when there has been a hardware failure.
346.PP
344will remove that directory entry.
345Again,
346this condition can only arise when there has been a hardware failure.
347.PP
347.I Fsck
348.I Fsck_ffs
348also checks for directories with unallocated blocks (holes).
349Such directories should never be created.
350When found,
349also checks for directories with unallocated blocks (holes).
350Such directories should never be created.
351When found,
351.I fsck
352.I fsck_ffs
352will prompt the user to adjust the length of the offending directory
353which is done by shortening the size of the directory to the end of the
354last allocated block preceeding the hole.
355Unfortunately, this means that another Phase 1 run has to be done.
353will prompt the user to adjust the length of the offending directory
354which is done by shortening the size of the directory to the end of the
355last allocated block preceeding the hole.
356Unfortunately, this means that another Phase 1 run has to be done.
356.I Fsck
357will remind the user to rerun fsck after repairing a
357.I Fsck_ffs
358will remind the user to rerun fsck_ffs after repairing a
358directory containing an unallocated block.
359.PP
360If a directory entry inode number references
361outside the inode list, then
359directory containing an unallocated block.
360.PP
361If a directory entry inode number references
362outside the inode list, then
362.I fsck
363.I fsck_ffs
363will remove that directory entry.
364This condition occurs if bad data is written into a directory data block.
365.PP
366The directory inode number entry for ``\fB.\fP''
367must be the first entry in the directory data block.
368The inode number for ``\fB.\fP''
369must reference itself;
370e.g., it must equal the inode number
371for the directory data block.
372The directory inode number entry
373for ``\fB..\fP'' must be
374the second entry in the directory data block.
375Its value must equal the inode number for the
376parent of the directory entry
377(or the inode number of the directory
378data block if the directory is the
379root directory).
380If the directory inode numbers are
381incorrect,
364will remove that directory entry.
365This condition occurs if bad data is written into a directory data block.
366.PP
367The directory inode number entry for ``\fB.\fP''
368must be the first entry in the directory data block.
369The inode number for ``\fB.\fP''
370must reference itself;
371e.g., it must equal the inode number
372for the directory data block.
373The directory inode number entry
374for ``\fB..\fP'' must be
375the second entry in the directory data block.
376Its value must equal the inode number for the
377parent of the directory entry
378(or the inode number of the directory
379data block if the directory is the
380root directory).
381If the directory inode numbers are
382incorrect,
382.I fsck
383.I fsck_ffs
383will replace them with the correct values.
384If there are multiple hard links to a directory,
385the first one encountered is considered the real parent
386to which ``\fB..\fP'' should point;
384will replace them with the correct values.
385If there are multiple hard links to a directory,
386the first one encountered is considered the real parent
387to which ``\fB..\fP'' should point;
387\fIfsck\fP recommends deletion for the subsequently discovered names.
388\fIfsck_ffs\fP recommends deletion for the subsequently discovered names.
388.NH 2
389File system connectivity
390.PP
389.NH 2
390File system connectivity
391.PP
391.I Fsck
392.I Fsck_ffs
392checks the general connectivity of the file system.
393If directories are not linked into the file system, then
393checks the general connectivity of the file system.
394If directories are not linked into the file system, then
394.I fsck
395.I fsck_ffs
395links the directory back into the file system in the
396.I lost+found
397directory.
398This condition only occurs when there has been a hardware failure.
399.ds RH "References"
400.SH
401\s+2Acknowledgements\s0
402.PP

--- 4 unchanged lines hidden (view full) ---

407Finally we thank our sponsors,
408the National Science Foundation under grant MCS80-05144,
409and the Defense Advance Research Projects Agency (DoD) under
410Arpa Order No. 4031 monitored by Naval Electronic System Command under
411Contract No. N00039-82-C-0235. (Kirk McKusick, July 1983)
412.PP
413I would like to thank Larry A. Wehr for advice that lead
414to the first version of
396links the directory back into the file system in the
397.I lost+found
398directory.
399This condition only occurs when there has been a hardware failure.
400.ds RH "References"
401.SH
402\s+2Acknowledgements\s0
403.PP

--- 4 unchanged lines hidden (view full) ---

408Finally we thank our sponsors,
409the National Science Foundation under grant MCS80-05144,
410and the Defense Advance Research Projects Agency (DoD) under
411Arpa Order No. 4031 monitored by Naval Electronic System Command under
412Contract No. N00039-82-C-0235. (Kirk McKusick, July 1983)
413.PP
414I would like to thank Larry A. Wehr for advice that lead
415to the first version of
415.I fsck
416.I fsck_ffs
416and Rick B. Brandt for adapting
417and Rick B. Brandt for adapting
417.I fsck
418.I fsck_ffs
418to
419UNIX/TS. (T. Kowalski, July 1979)
420.sp 2
421.SH
422\s+2References\s0
423.LP
424.IP [Dolotta78] 20
425Dolotta, T. A., and Olsson, S. B. eds.,

--- 17 unchanged lines hidden (view full) ---

443.B 57 ,
4446 (July-August 1978, Part 2), pp. 1905-29.
445.IP [Thompson78] 20
446Thompson, K.,
447UNIX Implementation,
448.I "The Bell System Technical Journal\^"
449.B 57 ,
4506 (July-August 1978, Part 2), pp. 1931-46.
419to
420UNIX/TS. (T. Kowalski, July 1979)
421.sp 2
422.SH
423\s+2References\s0
424.LP
425.IP [Dolotta78] 20
426Dolotta, T. A., and Olsson, S. B. eds.,

--- 17 unchanged lines hidden (view full) ---

444.B 57 ,
4456 (July-August 1978, Part 2), pp. 1905-29.
446.IP [Thompson78] 20
447Thompson, K.,
448UNIX Implementation,
449.I "The Bell System Technical Journal\^"
450.B 57 ,
4516 (July-August 1978, Part 2), pp. 1931-46.
451.ds RH Appendix A \- Fsck Error Conditions
452.ds RH Appendix A \- Fsck_ffs Error Conditions
452.bp
453.bp