aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsck_ffs/inode.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix fsck_ffs incorrectly reporting "CANNOT READ BLK: NNNN" errors.Kirk McKusick2021-01-261-2/+3
| | | | | | | | | | | | | | | | A long-standing bug in Pass 1 of fsck_ffs in which it is reading in blocks of inodes to check their block pointers. It failed to round up the size of the read to a disk block size. When disks would accept 512-byte aligned reads, the bug rarely manifested itself. But many recent disks will no longer accept 512-byte aligned reads but require 4096-byte aligned reads, so the failure to properly round-up read sizes to multiples of 4096 bytes makes the error much more likely to occur. Reported by: Peter Holm and others Tested by: Peter Holm and Rozhuk Ivan MFC after: 3 days Sponsored by: Netflix
* Rewrite the disk I/O management system in fsck_ffs(8). Other thanKirk McKusick2021-01-071-99/+269
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Rename pass4check() to freeblock() and move from pass4.c to inode.c.Kirk McKusick2020-12-181-1/+32
| | | | | | | | | | | | The new name more accurately describes what it does and the file move puts it with other similar functions. Done in preparation for future cleanups. No functional differences intended. Sponsored by: Netflix Historic Footnote: my last FreeBSD svn commit Notes: svn path=/head/; revision=368773
* Followup to -r344552 in which fsck_ffs checks for a size past theKirk McKusick2019-04-131-10/+15
| | | | | | | | | | | | | | | | | last allocated block of the file and if that is found, shortens the file to reference the last allocated block thus avoiding having it reference a hole at its end. This update corrects an error where fsck_ffs miscalculated the last logical block of the file when the file contained a large hole. Reported by: Jamie Landeg-Jones Tested by: Peter Holm MFC after: 2 weeks Sponsored by: Netflix Notes: svn path=/head/; revision=346185
* Properly calculate the last used logical block of a file when checkingKirk McKusick2019-03-021-2/+2
| | | | | | | | | | | | inodes that reference directories. While here tighten the check for comparing the last logical block with the end of the file. Reported by: Peter Holm Tested by: Peter Holm Sponsored by: Netflix Notes: svn path=/head/; revision=344732
* Ensure that inode updates are properly flushed out during the firstKirk McKusick2019-02-191-0/+6
| | | | | | | | | | | | pass of fsck_ffs. Some changes, such as check-hash corrections were being lost. Reported by: Michael Tuexen (tuexen@) Tested by: Michael Tuexen (tuexen@) MFC after: 3 days Notes: svn path=/head/; revision=344302
* Fsck would find, report, and offer to fix inode check-hash failures.Kirk McKusick2018-12-151-0/+2
| | | | | | | | | | | | | | | | | | | | | If requested to fix the inode check-hash it would confirm having done it, but then fail to make the fix. The same code is used in fsdb which, unlike fsck, would actually fix the inode check-hash. The discrepancy occurred because fsck has two ways to fetch inodes. The inode by number function ginode() and the streaming inode function getnextinode() used during pass1. Fsdb uses the ginode() function which correctly does the fix, while fsck first encounters the bad inode check-hash in pass1 where it is using the getnextinode() function that failed to make the correction. This patch corrects the getnextinode() function so that fsck now correctly fixes inodes with incorrect inode check-hashs. Reported by: Gary Jennejohn <gljennjohn@gmail.com> Sponsored by: Netflix Notes: svn path=/head/; revision=342128
* Continuing efforts to provide hardening of FFS. This change adds aKirk McKusick2018-12-111-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | check hash to the filesystem inodes. Access attempts to files associated with an inode with an invalid check hash will fail with EINVAL (Invalid argument). Access is reestablished after an fsck is run to find and validate the inodes with invalid check-hashes. This check avoids a class of filesystem panics related to corrupted inodes. The hash is done using crc32c. Note this check-hash is for the inode itself and not any of its indirect blocks. Check-hash validation may be extended to also cover indirect block pointers, but that will be a separate (and more costly) feature. Check hashes are added only to UFS2 and not to UFS1 as UFS1 is primarily used in embedded systems with small memories and low-powered processors which need as light-weight a filesystem as possible. Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix Notes: svn path=/head/; revision=341836
* Ensure that cylinder-group check-hashes are properly updated when firstKirk McKusick2018-12-051-1/+1
| | | | | | | | | | creating them and when correcting them when they are found to be corrupted. Reported by: Don Lewis (truckman@) Sponsored by: Netflix Notes: svn path=/head/; revision=341510
* In preparation for adding inode check-hashes, clean up andKirk McKusick2018-11-131-11/+10
| | | | | | | | | | | | | | | | | | | document the libufs interface for fetching and storing inodes. The undocumented getino / putino interface has been replaced with a new getinode / putinode interface. Convert the utilities that had been using the undocumented interface to use the new documented interface. No functional change (as for now the libufs library does not do inode check-hashes). Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix Notes: svn path=/head/; revision=340411
* In preparation for adding inode check-hashes, change the fsck_ffsKirk McKusick2018-10-311-7/+7
| | | | | | | | | | 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-10/+10
| | | | Notes: svn path=/head/; revision=331095
* Prefix UFS symbols with UFS_ to reduce namespace pollutionEd Maste2018-03-171-10/+10
| | | | | | | | | | | | | 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
* Fix a read past the end of a buffer in fsck.Kirk McKusick2018-02-211-1/+3
| | | | | | | | | | | | | | | | | | To minimize the time spent scanning all of the directories in pass 2 (Check Pathnames), fsck uses a search order based on the location of their first block. Zero length directories have no first block, so the array being used to hold the block numbers of directory inodes was of zero length. Thus a lookup was done past the end of the array getting at best a random value and at worst a segment fault. For zero length directories, this change allocates a one element block array and initializes it to zero. The effect is that all zero length directories are handled first in pass 2. Reviewed by: brooks Differential Revision: https://reviews.freebsd.org/D14163 Notes: svn path=/head/; revision=329749
* Rename cgget => cglookup to clear name space for new libufs function cgget.Kirk McKusick2018-01-171-1/+1
| | | | | | | No functional change. Notes: svn path=/head/; revision=328075
* 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
* fsck_ffs: Unsign some variables and make use of reallocarray(3).Pedro F. Giffuni2017-04-221-2/+2
| | | | | | | | | | | | | Instead of casting listmax and numdirs to unsigned values just define them as unsigned and avoid the casts. Use reallocarray(3). While here, fs_ncg is already unsigned so the cast is unnecessary. Reviewed by: mckusick MFC after: 2 weeks Notes: svn path=/head/; revision=317283
* 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-22/+22
| | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | MFC after: 2 weeks. Notes: svn path=/head/; revision=298907
* sbin: ake use of our rounddown() macro when sys/param.h is available.Pedro F. Giffuni2016-05-011-1/+1
| | | | | | | No functional change. Notes: svn path=/head/; revision=298872
* fsck_ffs for pointers replace 0 with NULL.Pedro F. Giffuni2016-04-121-2/+2
| | | | | | | | | Found with devel/coccinelle. Reviewed by: mckusick Notes: svn path=/head/; revision=297886
* Revert 248634 and 248643 (e.g., restoring 248625 and 248639).Kirk McKusick2013-03-231-6/+8
| | | | | | | Build verified by: Glen Barber (gjb@) Notes: svn path=/head/; revision=248658
* Revert svn r248625Sean Bruno2013-03-231-8/+6
| | | | | | | | | | | Clang errors around printf could be trivially fixed, but the breakage in sbin/fsdb were to significant for this type of change. Submitter of this changeset has been notified and hopefully this can be restored soon. Notes: svn path=/head/; revision=248634
* Speed up fsck by caching the cylinder group maps in pass1 soKirk McKusick2013-03-221-6/+8
| | | | | | | | | | | | | | | | | | | | | | | that they do not need to be read again in pass5. As this nearly doubles the memory requirement for fsck, the cache is thrown away if other memory needs in fsck would otherwise fail. Thus, the memory footprint of fsck remains unchanged in memory constrained environments. This work was inspired by a paper presented at Usenix's FAST '13: www.usenix.org/conference/fast13/ffsck-fast-file-system-checker Details of this implementation appears in the April 2013 of ;login: www.usenix.org/publications/login/april-2013-volume-38-number-2. A copy of the April 2013 ;login: paper can also be downloaded from: www.mckusick.com/publications/faster_fsck.pdf. Reviewed by: kib Tested by: Peter Holm MFC after: 4 weeks Notes: svn path=/head/; revision=248625
* When running with the -d option, instrument fsck_ffs to track the number,Kirk McKusick2013-02-241-22/+23
| | | | | | | | | data type, and running time of its I/O operations. No functional changes. Notes: svn path=/head/; revision=247212
* Fix fsck_ffs build with a 64-bit ino_t.Matthew D Fleming2012-09-271-4/+7
| | | | | | | Original code by: Gleb Kurtsou Notes: svn path=/head/; revision=241012
* Mechanical whitespace cleanup.Dag-Erling Smørgrav2011-04-271-16/+16
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=221110
* The dump, fsck_ffs, fsdb, fsirand, newfs, makefs, and quot utilitiesKirk McKusick2011-01-241-1/+1
| | | | | | | | | | | | | | | | | include sys/time.h instead of time.h. This include is incorrect as per the manpages for the APIs and the POSIX definitions. This commit replaces sys/time.h where necessary with time.h. The commit also includes some minor style(9) header fixup in newfs. This commit is part of a larger effort by Garrett Cooper started in //depot/user/gcooper/posix-conformance-work/ -- to make FreeBSD more POSIX compliant. Submitted by: Garrett Cooper yanegomi at gmail dot com Notes: svn path=/head/; revision=217769
* Update the actions previously attempted by the -D option to make themKirk McKusick2009-02-041-3/+54
| | | | | | | | | | | | | | | | | | | | | robust. With these changes fsck is now able to detect and reliably rebuild corrupted cylinder group maps. The -D option is no longer necessary as it has been replaced by a prompt asking whether the corrupted cylinder group should be rebuilt and doing so when requested. These actions are only offered and taken when running fsck in manual mode. Corrupted cylinder groups found during preen mode cause the fsck to fail. Add the -r option to free up excess unused inodes. Decreasing the number of preallocated inodes reduces the running time of future runs of fsck and frees up space that can allocated to files. The -r option is ignored when running in preen mode. Reviewed by: Xin LI <delphij@> Sponsored by: Rsync.net Notes: svn path=/head/; revision=188110
* Add a new flag, '-C' which enables a special mode that is intended forXin LI2008-04-101-2/+1
| | | | | | | | | | | | | catastrophic recovery. Currently, this mode only validates whether a cylindergroup has good signature data, and prompts the user to decide whether to clear it as a whole. This mode is useful when there is data damage on a disk and you are working on copy of the original disk, as fsck_ffs(8) tends to abnormally exit in such case, as a last resort to recover data from the disk. Notes: svn path=/head/; revision=178088
* Implements gjournal support. If file system has gjournal support enabledPawel Jakub Dawidek2006-10-311-2/+2
| | | | | | | | | | | | | and -p flag was given perform fast file system checking (bascially only garbage collecting of orphaned objects). Rename bread() to blread() and bwrite() to blwrite() as we now link to the libufs library, which also implement functions with that names. Sponsored by: home.pl Notes: svn path=/head/; revision=163845
* Eliminate linked list used to track inodes with an initial linkDon Lewis2004-10-081-0/+2
| | | | | | | | | | | | 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-14/+18
| | | | | | | 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
* Use __FBSDID() to quiet GCC 3.3 warnings.David E. O'Brien2003-05-031-4/+4
| | | | Notes: svn path=/head/; revision=114589
* Fix a bunch of format string warnings which brokeMaxime Henrion2002-07-311-2/+2
| | | | | | | | | the sparc64 build. Tested on: sparc64, i386 Notes: svn path=/head/; revision=101037
* Warning cleanup.Poul-Henning Kamp2002-07-301-5/+5
| | | | | | | Format changes by peter Notes: svn path=/head/; revision=100935
* This commit adds basic support for the UFS2 filesystem. The UFS2Kirk McKusick2002-06-211-86/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2/+1
| | | | | | | | | | 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-46/+20
| | | | | | | | | | 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-15/+15
| | | | | | | | | 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
* declare locally used globals as static.Alfred Perlstein2001-12-221-3/+3
| | | | Notes: svn path=/head/; revision=88413
* Fix a large number of -Wall, -Wformat and -W compiler warnings.Ian Dowse2001-11-171-4/+4
| | | | | | | | | | | | 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
* Silence non-constant format string warnings by marking functionsKris Kennaway2001-08-191-1/+1
| | | | | | | | | | as __printflike()/__printf0like(), adding const, or adding missing "%s" format strings, as appropriate. MFC after: 2 weeks Notes: svn path=/head/; revision=81911
* Just notify us once when encountering a partially allocated inode.Kirk McKusick2001-05-081-1/+1
| | | | Notes: svn path=/head/; revision=76352
* Additions to run checks on live filesystems. This change will notKirk McKusick2001-03-211-5/+19
| | | | | | | | | | | | 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
* Make a tighter test for valid inode numbers in getnextinode().Kirk McKusick2000-07-151-2/+3
| | | | Notes: svn path=/head/; revision=63231
* Teach fsck about snapshot files. These changes should have noKirk McKusick2000-07-061-3/+8
| | | | | | | | | | effect on operation of fsck on filesystems without snapshots. If you get compilation errors, be sure that you have copies of /usr/include/sys/mount.h (1.94), /usr/include/sys/stat.h (1.21), and /usr/include/ufs/ffs/fs.h (1.16) as of July 4, 2000 or later. Notes: svn path=/head/; revision=62668
* Yesterday I had to fix a badly broken disk, and found that fsck kept dying:Kirk McKusick2000-02-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DIR I=64512 CONNECTED. PARENT WAS I=4032 fsck: cannot find inode 995904 fsdb found the inodes with no problem: fsdb (inum: 64512)> inode 995904 current inode: directory I=995904 MODE=40777 SIZE=512 MTIME=Feb 14 15:27:07 2000 [0 nsec] CTIME=Feb 14 15:27:07 2000 [0 nsec] ATIME=Feb 24 10:31:58 2000 [0 nsec] OWNER=nobody GRP=nobody LINKCNT=4 FLAGS=0 BLKCNT=2 GEN=38a41386 Direct blocks: 8094568 0 0 0 0 0 0 0 0 0 0 0 Indirect blocks: 0 0 0 The problem turns out to be a program logic error in fsck. It stores directory inodes internally in hash lists, using the number of directories to form the hash key: inpp = &inphead[inumber % numdirs]; Elsewhere, however, it increments numdirs when it finds unattached directories. I've made the following fix, which solved the problem in the case in hand. Submitted by: Greg Lehey <grog@lemis.com> Reviewed by: Matthew Dillon <dillon@apollo.backplane.com> Approved by: Kirk McKusick <mckusick@mckusick.com> Notes: svn path=/head/; revision=57573