aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsdb
Commit message (Collapse)AuthorAgeFilesLines
* sbin: Remove ancient SCCS tags.Warner Losh2023-11-271-1/+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
* Purge more stray embedded $FreeBSD$ stringsJohn Baldwin2023-09-252-10/+0
| | | | | | | These do not use __FBSDID but instead use bare char arrays. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41957
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* Add quitclean command to fsdb(8) to request a filesystem not be marked dirty.Kirk McKusick2023-07-261-0/+12
| | | | | | | | | | A new command, quitclean, is added to fsdb(8) to request that the filesystem not be marked as needing a full fsck(8). This is useful when creating deliberately bad filesystem images to be used to check that fsck is properly able to clean them up. MFC-after: 1 week Sponsored-by: The FreeBSD Foundation
* Have fsdb(8) only mark a filesystem dirty when it is modified.Kirk McKusick2023-07-262-56/+56
| | | | | | | | | | | | | | | | | | | | | | | | Until this update, the fsdb(8) command always marked a filesystem as needing a full fsck unless it was run with the -n flag which allowed no changes to be made. This change tracks modifications to the filesystem. Two types of changes are tracked. The first type of changes are those that are not critical to the integrity of the filesystem such as changes to owner, group, time stamps, access mode, and generation number. The second type of changes are those that do affect the integrity of the filesystem including zeroing inodes, changing block pointers, directory entries, link counts, file lengths, file types, and file flags. When quitting having made no changes or only changes to data that is not critical to filesystem integrity, the clean state of the filesystem is left unchanged. But if filesystem critical data are changed then fsdb will set the unclean flag which will require a full fsck to be run before the filesystem can be mounted. MFC-after: 1 week Sponsored-by: The FreeBSD Foundation
* Update/fix Makefile.depend for userlandSimon J. Gerraty2023-04-191-2/+0
|
* Add `chdb' command to fsdb(8) to set direct block numbers.Kirk McKusick2023-04-181-0/+32
| | | | | | | | | Add the ability to set direct blocks numbers in inodes so that manual corrections can be made. No checking of the values is attempted so accidental or deliberate bad values can be set. Submitted by: Chuck Silvers MFC after: 1 week
* Improvement in UFS/FFS directory placement when doing mkdir(2).Kirk McKusick2023-03-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* pkgbase: Put ufs related tools and lib in their own packageEmmanuel Vadot2022-10-261-1/+1
| | | | | | | | It's not really useful in a jail or in a mdroot or even if a users wants to do a full zfs machine. Reviewed by: mckusick Differential Revision: https://reviews.freebsd.org/D36227
* Move the ability to search for alternate UFS superblocks from fsck_ffs(8)Kirk McKusick2022-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | into ffs_sbsearch() to allow use by other parts of the system. Historically only fsck_ffs(8), the UFS filesystem checker, had code to track down and use alternate UFS superblocks. Since fsdb(8) used much of the fsck_ffs(8) implementation it had some ability to track down alternate superblocks. This change extracts the code to track down alternate superblocks from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found in ffs_subr.c, these functions can be used directly by the kernel subsystems. Additionally they are exported to the UFS library, libufs(8) so that they can be used by user-level programs. The new functions added to libufs(8) are sbfind(3) that is an alternative to sbread(3) and sbsearch(3) that is an alternative to sbget(3). See their manual pages for further details. The utilities that have been changed to search for superblocks are dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8) tool found in tools/diag/prtblknos searches for superblocks. The UFS specific mount code uses the superblock search interface when mounting the root filesystem and when the administrator doing a mount(8) command specifies the force flag (-f). The standalone UFS boot code (found in stand/libsa/ufs.c) uses the superblock search code in the hope of being able to get the system up and running so that fsck_ffs(8) can be used to get the filesystem cleaned up. The following utilities have not been changed to search for superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8), dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and glabel(8). When these utilities fail, they do report the cause of the failure. The one exception is the tasting code used to try and figure what a given disk contains. The tasting code will remain silent so as not to put out a slew of messages as it trying to taste every new mass storage device that shows up. Reviewed by: kib Reviewed by: Warner Losh Tested by: Peter Holm Differential Revision: https://reviews.freebsd.org/D36053 Sponsored by: The FreeBSD Foundation
* Update fsdb(8) to reflect new structure of fsck_ffs(8).Kirk McKusick2022-02-231-1/+1
| | | | | | | | | | The cleanup of fsck_ffs(8) in commit c0bfa109b942659f6 broke fsdb(8). This commit adds the one-line update needed in fsdb(8) to make it work with the new fsck_ffs(8) structure. Reported by: Chuck Silvers Tested by: Chuck Silvers MFC after: 3 days
* ufs: Rework shortlink handling to avoid subobject overflowsJessica Clarke2022-01-021-5/+2
| | | | | | | | | | | | | | | | | | | | Shortlinks occupy the space of both di_db and di_ib when used. However, everywhere that wants to read or write a shortlink takes a pointer do di_db and promptly runs off the end of it into di_ib. This is fine on most architectures, if a little dodgy. However, on CHERI, the compiler can optionally restrict the bounds on pointers to subobjects to just that subobject, in order to mitigate intra-object buffer overflows, and this is enabled in CheriBSD's pure-capability kernels. Instead, clean this up by inserting a union such that a new di_shortlink can be added with the right size and element type, avoiding the need to cast and allowing the use of the DIP macro to access the field. This also mirrors how the ext2fs code implements extents support, with the exact same structure other than having a uint32_t i_data[] instead of a char di_shortlink[]. Reviewed by: mckusick, jhb Differential Revision: https://reviews.freebsd.org/D33650
* Revert "fsdb: add missing bufinit() call"Robert Wing2021-05-291-1/+0
| | | | This reverts commit 84768d114951e88288024f09d4beae0956c3cf21.
* fsdb: add missing bufinit() callChuck Silvers2021-05-251-0/+1
| | | | | | | | | The bufinit() call in fsck_ffs was moved in commit f190f9193bc10 from a function that is shared with fsdb to one that is private to fsck_ffs, so add a bufinit() call in fsdb to compensate for that. Reviewed by: mckusick Sponsored by: Netflix
* Rewrite the disk I/O management system in fsck_ffs(8). Other thanKirk McKusick2021-01-072-43/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* fsdb(8): Fix an issue reported by mandocGordon Bergling2020-10-031-1/+1
| | | | | | | | | - whitespace at end of input line MFC after: 1 week Notes: svn path=/head/; revision=366408
* The fsdb(8) utility uses the fsck_ffs(8) disk I/O interfaces, soKirk McKusick2020-09-192-2/+4
| | | | | | | | | | switch from using libufs's bread() to using fsck_ffs's getdatablk() when importing tools/diag/prtblnos's prtblknos(). Sponsored by: Netflix Notes: svn path=/head/; revision=365912
* fsck_ffs/fsdb: fix -fno-common buildKyle Evans2020-03-291-3/+0
| | | | | | | | | | | | | | This one is also a small list: - 3x duplicate definition (ufs2_zino, returntosingle, nflag) - 5x 'needs extern', 3/5 of which are referenced in fsdb -fno-common will become the default in GCC10/LLVM11. MFC after: 1 week Notes: svn path=/head/; revision=359427
* After a crash, a file that extends into indirect blocks may end upKirk McKusick2019-02-251-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | shorter than its size resulting in a hole as its final block (which is a violation of the invarients of the UFS filesystem). Soft updates will always ensure that the file size is correct when writing inodes to disk for files that contain only direct block pointers. However soft updates does not roll back sizes for files with indirect blocks that it has set to unallocated because their contents have not yet been written to disk. Hence, the file can appear to have a hole at its end because the block pointer has been rolled back to zero when its inode was written to disk. Thus, fsck_ffs calculates the last allocated block in the file. For files that extend into indirect blocks, fsck_ffs checks for a size past the 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. Submitted by: Chuck Silvers <chs@netflix.com> Tested by: Chuck Silvers <chs@netflix.com> MFC after: 1 week Sponsored by: Netflix Notes: svn path=/head/; revision=344552
* In preparation for adding inode check-hashes, change the fsck_ffsKirk McKusick2018-10-311-15/+15
| | | | | | | | | | 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
* When using the fsdb `blocks' command, replace the long and ugly list ofKirk McKusick2018-04-082-127/+5
| | | | | | | | blocks with the much more concise and readable block list shown by the prtblknos() function imported from tools/diag/prtblknos. Notes: svn path=/head/; revision=332267
* Revert r313780 (UFS_ prefix)Ed Maste2018-03-172-29/+29
| | | | Notes: svn path=/head/; revision=331095
* Prefix UFS symbols with UFS_ to reduce namespace pollutionEd Maste2018-03-172-29/+29
| | | | | | | | | | | | | 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 buildworld after r328075, by also renaming cgget to cglookup inDimitry Andric2018-01-171-1/+1
| | | | | | | | | | fsdb. Reported by: ohartmann@walstatt.org,david@catwhisker.org Pointy hat to: mckusick Notes: svn path=/head/; revision=328084
* The fix in r327273 turns a memory leak into freeing wild pointer.Xin LI2017-12-291-2/+4
| | | | | | | Fix this by freeing only the initialized pointer. Notes: svn path=/head/; revision=327335
* Plug memory leak by freeing wantedblk{32,64}.Warner Losh2017-12-281-0/+2
| | | | | | | CID: 273655, 273656 Notes: svn path=/head/; revision=327273
* various: general adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-273-3/+9
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. 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. No functional change intended. Notes: svn path=/head/; revision=326276
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* Continuing efforts to provide hardening of FFS, this change adds aKirk McKusick2017-09-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | check hash to cylinder groups. If a check hash fails when a cylinder group is read, no further allocations are attempted in that cylinder group until it has been fixed by fsck. This avoids a class of filesystem panics related to corrupted cylinder group maps. The hash is done using crc32c. Check hases 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. Specifics of the changes: sys/sys/buf.h: Add BX_FSPRIV to reserve a set of eight b_xflags that may be used by individual filesystems for their own purpose. Their specific definitions are found in the header files for each filesystem that uses them. Also add fields to struct buf as noted below. sys/kern/vfs_bio.c: It is only necessary to compute a check hash for a cylinder group when it is actually read from disk. When calling bread, you do not know whether the buffer was found in the cache or read. So a new flag (GB_CKHASH) and a pointer to a function to perform the hash has been added to breadn_flags to say that the function should be called to calculate a hash if the data has been read. The check hash is placed in b_ckhash and the B_CKHASH flag is set to indicate that a read was done and a check hash calculated. Though a rather elaborate mechanism, it should also work for check hashing other metadata in the future. A kernel internal API change was to change breada into a static fucntion and add flags and a function pointer to a check-hash function. sys/ufs/ffs/fs.h: Add flags for types of check hashes; stored in a new word in the superblock. Define corresponding BX_ flags for the different types of check hashes. Add a check hash word in the cylinder group. sys/ufs/ffs/ffs_alloc.c: In ffs_getcg do the dance with breadn_flags to get a check hash and if one is provided, check it. sys/ufs/ffs/ffs_vfsops.c: Copy across the BX_FFSTYPES flags in background writes. Update the check hash when writing out buffers that need them. sys/ufs/ffs/ffs_snapshot.c: Recompute check hash when updating snapshot cylinder groups. sys/libkern/crc32.c: lib/libufs/Makefile: lib/libufs/libufs.h: lib/libufs/cgroup.c: Include libkern/crc32.c in libufs and use it to compute check hashes when updating cylinder groups. Four utilities are affected: sbin/newfs/mkfs.c: Add the check hashes when building the cylinder groups. sbin/fsck_ffs/fsck.h: sbin/fsck_ffs/fsutil.c: Verify and update check hashes when checking and writing cylinder groups. sbin/fsck_ffs/pass5.c: Offer to add check hashes to existing filesystems. Precompute check hashes when rebuilding cylinder group (although this will be done when it is written in fsutil.c it is necessary to do it early before comparing with the old cylinder group) sbin/dumpfs/dumpfs.c Print out the new check hash flag(s) sbin/fsdb/Makefile: Needs to add libufs now used by pass5.c imported from fsck_ffs. Reviewed by: kib Tested by: Peter Holm (pho) Notes: svn path=/head/; revision=323923
* sbin: normalize paths using SRCTOP-relative paths or :H when possibleEnji Cooper2017-03-041-2/+2
| | | | | | | | | | This simplifies make logic/output MFC after: 1 month Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=314656
* prefix UFS symbols with UFS_ to reduce namespace pollutionEd Maste2017-02-152-16/+16
| | | | | | | | | | | | | | | | | | | | | 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
* Document which version of BSD first showed up in and add the version infoSevan Janiyan2016-10-021-8/+9
| | | | | | | | | | | | for NetBSD & FreeBSD. PR: 212477 Approved by: bcr (mentor) MFC after: 4 days Differential Revision: https://reviews.freebsd.org/D8105 Notes: svn path=/head/; revision=306603
* Use nitems() from sys/param.h.Marcelo Araujo2016-07-301-2/+2
| | | | | | | Sponsored by: gandi.net (BSD Day Taiwan) Notes: svn path=/head/; revision=303539
* Use NULL instead of 0 for pointers.Marcelo Araujo2016-04-181-1/+1
| | | | | | | | | malloc will return NULL if it cannot allocate memory. MFC after: 2 weeks. Notes: svn path=/head/; revision=298195
* Explicitly add more files to the 'runtime' package.Glen Barber2016-02-091-0/+1
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295450
* Add META_MODE support.Simon J. Gerraty2015-06-131-0/+21
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | Off by default, build behaves normally. WITH_META_MODE we get auto objdir creation, the ability to start build from anywhere in the tree. Still need to add real targets under targets/ to build packages. Differential Revision: D2796 Reviewed by: brooks imp Notes: svn path=/head/; revision=284345
| * dirdeps.mk now sets DEP_RELDIRSimon J. Gerraty2015-06-081-2/+0
| | | | | | | | Notes: svn path=/projects/bmake/; revision=284172
| * Merge sync of headSimon J. Gerraty2015-05-271-2/+1
| |\ | |/ |/| | | Notes: svn path=/projects/bmake/; revision=283595
| * Merge head from 7/28Simon J. Gerraty2014-08-192-3/+3
| |\ | | | | | | | | | Notes: svn path=/projects/bmake/; revision=270164
| * | Updated dependenciesSimon J. Gerraty2014-05-161-1/+0
| | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=266219
| * | Updated dependenciesSimon J. Gerraty2014-05-101-0/+2
| | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=265802
| * | Merge headSimon J. Gerraty2014-04-281-1/+1
| |\ \ | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=265044
| * \ \ sync from headSimon J. Gerraty2013-04-122-6/+6
| |\ \ \ | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=249429
| * | | | Updated dependenciesSimon J. Gerraty2013-03-111-0/+1
| | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=248169
| * | | | Updated dependenciesSimon J. Gerraty2013-02-161-2/+0
| | | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=246868
| * | | | Sync from headSimon J. Gerraty2012-11-042-17/+22
| |\ \ \ \ | | | | | | | | | | | | | | | | | | Notes: svn path=/projects/bmake/; revision=242545
| * | | | | Sync FreeBSD's bmake branch with Juniper's internal bmake branch.Marcel Moolenaar2012-08-221-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Requested by: Simon Gerraty <sjg@juniper.net> Notes: svn path=/projects/bmake/; revision=239572
* | | | | | Convert sbin/ to LIBADDBaptiste Daroussin2014-11-251-2/+1
| |_|_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reduce overlinking Notes: svn path=/head/; revision=275030