aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsck_ffs/pass2.c
Commit message (Collapse)AuthorAgeFilesLines
* sbin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-3/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* sbin: Remove ancient SCCS tags.Warner Losh2023-11-271-3/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Fix a bug in fsck_ffs(8) triggered by corrupted filesystems.Kirk McKusick2023-05-271-2/+2
| | | | | | | | | | The last valid inode in the filesystem is maxino - 1, not maxino. Thus validity checks should ino < maxino, not ino <= maxino. Reported-by: Robert Morris PR: 271312 MFC-after: 1 week Sponsored-by: The FreeBSD Foundation
* Improvement in UFS/FFS directory placement when doing mkdir(2).Kirk McKusick2023-03-301-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The algorithm for laying out new directories was devised in the 1980s and markedly improved the performance of the filesystem. In those days large disks had at most 100 cylinder groups and often as few as 10-20. Modern multi-terrabyte disks have thousands of cylinder groups. The original algorithm does not handle these large sizes well. This change attempts to expand the scope of the original algorithm to work well with these much larger disks while still retaining the properties of the original algorithm for small disks. The filesystem implementation is divided into policy routines and implementation routines. The policy routines can be changed in any way desired without risk of corrupting the filesystem. The policy requests are handled by the implementation layer. If the policy asks for an available resource, it is granted. But if it asks for an already in-use resource, then the implementation will provide an available one nearby the request. Thus it is impossible for a policy to double allocate. This change is limited to the policy implementation. This change updates the ffs_dirpref() routine which is responsible for selecting the cylinder group into which a new directory should be placed. If we are near the root of the filesystem we aim to spread them out as much as possible. As we descend deeper from the root we cluster them closer together around their parent as we expect them to be more closely interactive. Higher-level directories like usr/src/sys and usr/src/bin should be separated while the directories in these areas are more likely to be accessed together so should be closer. And directories within commands or kernel subsystems should be closer still. We pick a range of cylinder groups around the cylinder group of the directory in which we are being created. The size of the range for our search is based on our depth from the root of our filesystem. We then probe that range based on how many directories are already present. The first new directory is at 1/2 (middle) of the range; the second is in the first 1/4 of the range, then at 3/4, 1/8, 3/8, 5/8, 7/8, 1/16, 3/16, 5/16, etc. It is desirable to store the depth of a directory in its on-disk inode so that it is available when we need it. We add a new field di_dirdepth to track the depth of each directory. Because there are few spare fields left in the inode, we choose to share an existing field in the inode rather than having one of our own. Specifically we create a union with the di_freelink field. The di_freelink field is used to track inodes that have been unlinked but remain referenced. It is not needed until a rmdir(2) operation has been done on a directory. At that point, the directory has no contents and even if it is kept active as a current directory is no longer able to have any new directories or files created in it. Thus the use of di_dirdepth and di_freelink will never coincide. Reported by: Timo Voelker Reviewed by: kib Tested by: Peter Holm MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39246
* Rewrite function definitions with identifier lists.Kirk McKusick2023-03-221-0/+1
| | | | | | | | A few functions snuck in with K&R style definitions. Also add some missing memory frees. MFC after: 1 week
* Correct several bugs in fsck_ffs(8) triggered by corrupted filesystems.Kirk McKusick2023-03-071-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a directory entry has an illegal inode number (less than zero or greater than the last inode in the filesystem) the entry is removed. If a directory '.' or '..' entry had an illegal inode number they were being removed. Since fsck_ffs knows what the correct value is for these two entries fix them rather deleting them. Add much more extensive cylinder group checks and use them to be more careful about rebuilding a cylinder group. Check for out-of-range block numbers before trying to free them. When a directory is deleted also remove its cache entry created in pass1 so that later passes do not try to operate on a deleted directory. Check for ctime(3) returning NULL before trying to use its return. When freeing a directory inode, do not try to interpret it as a directory. Reserve space in the inostatlist to have room to allocate a lost+found directory. If an invalid block number is found past the end of an inode simply remove it rather than clearing and removing the inode. Modernize the inoinfo structure to use queue(3) LIST rather than a handrolled linked list implementation. Reported by: Bob Prohaska, John-Mark Gurney, and Mark Millard Tested by: Peter Holm Reviewed by: Peter Holm MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38668
* Improve handling of missing '.' and '..' in UFS directories.Kirk McKusick2022-08-171-45/+82
| | | | | | | | | | | | | | | | | | | | | The UFS filesystem expects to find '.' and '..' as the first two entries in a directory. The kernel's UFS name cache can become quite confused when these two entries are not present as the first two entries. Prior to this change, when the fsck_ffs(8) utility detected that '.' and/or '..' were missing, it would report them, but only offered to replace them if the space at the beginning of the directory was available. Otherwise it was left to the system administrator to move the offending file(s) out of the way and then rerun fsck_ffs(8) to create the '.' and '..' entries. With this change, fsck_ffs(8) will always be able to create the '.' and/or '..' entries. It moves any files in the way elsewhere in the directory block. If there is no room in the directory block to which to move them, they are placed in the lost+found directory. Reported by: Peter Holm Sponsored by: The FreeBSD Foundation
* Rewrite the disk I/O management system in fsck_ffs(8). Other thanKirk McKusick2021-01-071-11/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | making fsck_ffs(8) run faster, there should be no functional change. The original fsck_ffs(8) had its own disk I/O management system. When gjournal(8) was added to FreeBSD 7, code was added to fsck_ffs(8) to do the necessary gjournal rollback. Rather than use the existing fsck_ffs(8) disk I/O system, it wrote its own from scratch. Similarly when journalled soft updates were added in FreeBSD 9, code was added to fsck_ffs(8) to do the necessary journal rollback. And once again, rather than using either of the existing fsck_ffs(8) disk I/O systems, it wrote its own from scratch. Lastly the fsdb(8) utility uses the fsck_ffs(8) disk I/O management system. In preparation for making the changes necessary to enable snapshots to be taken when using journalled soft updates, it was necessary to have a single disk I/O system used by all the various subsystems in fsck_ffs(8). This commit merges the functionality required by all the different subsystems into a single disk I/O system that supports all of their needs. In so doing it picks up optimizations from each of them with the results that each of the subsystems does fewer reads and writes than it did with its own customized I/O system. It also greatly simplifies making changes to fsck_ffs(8) since everything goes through a single place. For example the ginode() function fetches an inode from the disk. When inode check hashes were added, they previously had to be checked in the code implementing inode fetch in each of the three different disk I/O systems. Now they need only be checked in ginode(). Tested by: Peter Holm Sponsored by: Netflix
* In preparation for adding inode check-hashes, change the fsck_ffsKirk McKusick2018-10-311-3/+3
| | | | | | | | | | inodirty() function to have a pointer to the inode being dirtied. No functional change (as for now the parameter is ununsed). Sponsored by: Netflix Notes: svn path=/head/; revision=339941
* Revert r313780 (UFS_ prefix)Ed Maste2018-03-171-5/+4
| | | | Notes: svn path=/head/; revision=331095
* Prefix UFS symbols with UFS_ to reduce namespace pollutionEd Maste2018-03-171-4/+5
| | | | | | | | | | | | | Followup to r313780. Also prefix ext2's and nandfs's versions with EXT2_ and NANDFS_. Reported by: kib Reviewed by: kib, mckusick Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D9623 Notes: svn path=/head/; revision=331083
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-1/+3
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* prefix UFS symbols with UFS_ to reduce namespace pollutionEd Maste2017-02-151-18/+21
| | | | | | | | | | | | | | | | | | | | | Specifically: ROOTINO -> UFS_ROOTINO WINO -> UFS_WINO NXADDR -> UFS_NXADDR NDADDR -> UFS_NDADDR NIADDR -> UFS_NIADDR MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency) Also prefix ext2's and nandfs's NDADDR and NIADDR with EXT2_ and NANDFS_ Reviewed by: kib, mckusick Obtained from: NetBSD MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D9536 Notes: svn path=/head/; revision=313780
* Use MIN/MAX macros from sys/param.h.Marcelo Araujo2016-05-021-3/+1
| | | | | | | MFC after: 2 weeks. Notes: svn path=/head/; revision=298907
* Fix fsck_ffs build with a 64-bit ino_t.Matthew D Fleming2012-09-271-9/+11
| | | | | | | Original code by: Gleb Kurtsou Notes: svn path=/head/; revision=241012
* Replace index() and rindex() calls with strchr() and strrchr().Ed Schouten2012-01-031-1/+1
| | | | | | | | | | | | | The index() and rindex() functions were marked LEGACY in the 2001 revision of POSIX and were subsequently removed from the 2008 revision. The strchr() and strrchr() functions are part of the C standard. This makes the source code a lot more consistent, as most of these C files also call into other str*() routines. In fact, about a dozen already perform strchr() calls. Notes: svn path=/head/; revision=229403
* Mechanical whitespace cleanup.Dag-Erling Smørgrav2011-04-271-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=221110
* Add support to background fsck to delete zero-length directories.Kirk McKusick2010-05-201-1/+30
| | | | Notes: svn path=/head/; revision=208330
* Cast 64-bit quantity to intptr_t rather than int so as to work properlyKirk McKusick2010-01-111-2/+2
| | | | | | | | | with 64-bit architectures (such as amd64). Reported by: Xin LI and Josh Paetzel Notes: svn path=/head/; revision=202131
* This update utilizes new fsck sysctl commands that allow fsck runningKirk McKusick2010-01-111-7/+82
| | | | | | | | | | | | | in background mode to correct expected inconsistencies that arise during directory rename (see immediately previous update to this file for details). If run on a kernel without the new functionality, background fsck will simply ignore these inconsistencies rather than fail. Reported by: jeff Notes: svn path=/head/; revision=202109
* When renaming a directory it passes through several intermediateKirk McKusick2010-01-111-21/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | | states. First its new name will be created causing it to have two names (from possibly different parents). Next, if it has different parents, its value of ".." will be changed from pointing to the old parent to pointing to the new parent. Concurrently, its old name will be removed bringing it back into a consistent state. When fsck encounters an extra name for a directory, it offers to remove the "extraneous hard link"; when it finds that the names have been changed but the update to ".." has not happened, it offers to rewrite ".." to point at the correct parent. Both of these changes were considered unexpected so would cause fsck in preen mode or fsck in background mode to fail with the need to run fsck manually to fix these problems. This update changes these errors to be expected so that in preen mode fsck will simply fix these transitional errors. For now, background fsck will note these errors, but will need additional kernel support to fix them, so will simply ignore them rather than fail. A future update will allow background fsck to fix these problems. Reported by: jeff Notes: svn path=/head/; revision=202107
* In pass2check(): Be more strict with the inode information before furtherXin LI2008-02-261-0/+2
| | | | | | | | | processing the information. chk1 is more prone to crash when insane information is provided by the on-disk inode, and does not even work if the inode is being smarshed badly. Notes: svn path=/head/; revision=176574
* Eliminate linked list used to track inodes with an initial linkDon Lewis2004-10-081-1/+5
| | | | | | | | | | | | count of zero and instead encode this information in the inode state. Pass 4 performed a linear search of this list for each inode in the file system, which performs poorly if the list is long. Reviewed by: sam & keramida (an earlier version of the patch), mckusick MFC after: 1 month Notes: svn path=/head/; revision=136281
* Create DIP_SET() and IBLK_SET() macros to fix lvalue warnings.Scott Long2004-09-011-9/+9
| | | | | | | Inspired by: kan Notes: svn path=/head/; revision=134589
* Remove advertising clause from University of California Regent's license,Mark Murray2004-04-091-4/+0
| | | | | | | | | per letter dated July 22, 1999. Approved by: core, imp Notes: svn path=/head/; revision=128073
* In the case of a background fsck, periodically update the process titleScott Long2004-02-281-0/+5
| | | | | | | with a progress update. Notes: svn path=/head/; revision=126345
* Use __FBSDID() to quiet GCC 3.3 warnings.David E. O'Brien2003-05-031-1/+0
| | | | Notes: svn path=/head/; revision=114589
* Replace various spelling with FALLTHROUGH which is lint()ablePhilippe Charnier2002-08-251-6/+7
| | | | Notes: svn path=/head/; revision=102411
* Fix a bunch of format string warnings which brokeMaxime Henrion2002-07-311-7/+8
| | | | | | | | | the sparc64 build. Tested on: sparc64, i386 Notes: svn path=/head/; revision=101037
* Warning cleanup.Poul-Henning Kamp2002-07-301-3/+3
| | | | | | | Format changes by peter Notes: svn path=/head/; revision=100935
* This commit adds basic support for the UFS2 filesystem. The UFS2Kirk McKusick2002-06-211-16/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | filesystem expands the inode to 256 bytes to make space for 64-bit block pointers. It also adds a file-creation time field, an ability to use jumbo blocks per inode to allow extent like pointer density, and space for extended attributes (up to twice the filesystem block size worth of attributes, e.g., on a 16K filesystem, there is space for 32K of attributes). UFS2 fully supports and runs existing UFS1 filesystems. New filesystems built using newfs can be built in either UFS1 or UFS2 format using the -O option. In this commit UFS1 is the default format, so if you want to build UFS2 format filesystems, you must specify -O 2. This default will be changed to UFS2 when UFS2 proves itself to be stable. In this commit the boot code for reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c) as there is insufficient space in the boot block. Once the size of the boot block is increased, this code can be defined. Things to note: the definition of SBSIZE has changed to SBLOCKSIZE. The header file <ufs/ufs/dinode.h> must be included before <ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and ufs_lbn_t. Still TODO: Verify that the first level bootstraps work for all the architectures. Convert the utility ffsinfo to understand UFS2 and test growfs. Add support for the extended attribute storage. Update soft updates to ensure integrity of extended attribute storage. Switch the current extended attribute interfaces to use the extended attribute storage. Add the extent like functionality (framework is there, but is currently never used). Sponsored by: DARPA & NAI Labs. Reviewed by: Poul-Henning Kamp <phk@freebsd.org> Notes: svn path=/head/; revision=98542
* UFS2 preparation commit:Poul-Henning Kamp2002-05-121-43/+8
| | | | | | | | | | Remove support for converting old FFS formats to newer. Submitted by: mckusick Sponspored by: DARPA & NAI Labs. Notes: svn path=/head/; revision=96483
* o __P removedWarner Losh2002-03-201-7/+5
| | | | | | | | | | o ansi function prototypes o unifdef -D__STDC__ o __dead2 on usage prototype o remove now-bogus main prototype Notes: svn path=/head/; revision=92839
* Remove 'register' keyword.David E. O'Brien2002-03-201-4/+4
| | | | | | | | | It does not help modern compilers, and some may take some hit from it. (I also found several functions that listed *every* of its 10 local vars with "register" -- just how many free registers do people think machines have?) Notes: svn path=/head/; revision=92806
* Fix a large number of -Wall, -Wformat and -W compiler warnings.Ian Dowse2001-11-171-2/+2
| | | | | | | | | | | | These were mainly missing casts or wrong format strings in printf statements, but there were also missing includes, unused variables, functions and arguments. The choice of `long' vs `int' still seems almost random in a lot of places though. Notes: svn path=/head/; revision=86514
* Give a more useful diagnostic when an extraneous hard link to aIan Dowse2001-11-171-1/+3
| | | | | | | | | | | | | directory is encountered. This includes the full path of the directory that will be removed if the user answers "y" to the "REMOVE?" question. PR: bin/226851 Submitted by: KOIE Hide <hide@koie.org> MFC after: 1 week Notes: svn path=/head/; revision=86512
* Additions to run checks on live filesystems. This change will notKirk McKusick2001-03-211-0/+3
| | | | | | | | | | | | affect current systems until fsck is modified to use these new facilities. To try out this change, set the fsck passno to zero in /etc/fstab to cause the filesystem to be mounted without running fsck, then run `fsck_ffs -p -B <filesystem>' after the system has been brought up multiuser to run a background cleanup on <filesystem>. Note that the <filesystem> in question must have soft updates enabled. Notes: svn path=/head/; revision=74556
* Add a simple SIGINFO handler to fsck_ffs. Shortly after receipt ofIan Dowse2000-12-151-0/+6
| | | | | | | | | | | a SIGINFO (normally via Ctrl-T), a line will be output indicating the current phase number and progress information relevant to the current phase. Approved by: mckusick Notes: svn path=/head/; revision=70050
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* Cosmetic and documentation changes brought from earlier FreeBSD versions.Julian Elischer1998-12-031-2/+4
| | | | | | | (e.g. RCS Id:) Notes: svn path=/head/; revision=41477
* Reviewed by: Don Lewis <Don.Lewis@tsc.tdk.com>Julian Elischer1998-12-031-32/+32
| | | | | | | | | | | | | | | Submitted by: Kirk McKusick <mckusick@McKusick.COM> Obtained from: Mckusick, BSDI and a host of others This exactly matches Kirks sources imported under the Tag MCKUSICK2. These are as supplied by kirk with one small change needed to compile under freeBSD. Some FreeBSD patches will be added back, though many have been added to Kirk's sources already. Notes: svn path=/head/; revision=41474
* Correct use of .Nm. Add rcsid. Remove unused #includes. Use err(3).Philippe Charnier1998-06-151-2/+4
| | | | Notes: svn path=/head/; revision=37000
* Reviewed by: dyson@freebsd.org (john Dyson), dg@root.com (david greenman)Julian Elischer1998-03-081-8/+23
| | | | | | | | Submitted by: Kirk McKusick (mcKusick@mckusick.com) Obtained from: WHistle development tree Notes: svn path=/head/; revision=34266
* Finished (?) merging with Lite2: cleaned up #include mess.Bruce Evans1997-03-121-2/+1
| | | | Notes: svn path=/head/; revision=23799
* Merge from Lite2. Note that Lite2 has it's own filesystem clean checkPeter Wemm1997-03-111-24/+58
| | | | | | | | skipping code that overrides ours sooner. One should be eliminated, but for now it works. Notes: svn path=/head/; revision=23675
* Remove trailing whitespace.Rodney W. Grimes1995-05-301-1/+1
| | | | Notes: svn path=/head/; revision=8871
* Submitted by: phk, added to by bdeBruce Evans1995-04-021-1/+5
| | | | | | | Fix all the warnings from `gcc -Wall'. Notes: svn path=/head/; revision=7585
* BSD 4.4 Lite sbin SourcesRodney W. Grimes1994-05-261-0/+430
Note: XNSrouted and routed NOT imported here, they shall be imported with usr.sbin. Notes: svn path=/head/; revision=1558