Home | History | Annotate | Download | only in fsck_lfs
History log of /src/sbin/fsck_lfs/main.c
RevisionDateAuthorComments
 1.58  14-Sep-2025  wiz fsck_lfs: add -i to usage
 1.57  14-Sep-2025  perseant Document the -a and -i flags.
 1.56  14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.55  03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.54  15-Aug-2019  kamil fsck: Stop defining the same variable concurrently in bss and data

returntosingle was defined in multiple places:

- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.53  03-Feb-2019  mrg branches: 1.53.2;
- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.52  28-Jul-2015  dholland branches: 1.52.16;
Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.51  24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.50  24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.49  16-Jun-2015  christos fix error messages containing \n
 1.48  13-Jul-2014  dholland Revert previous; it doesn't work because all the lfs tools
promiscuously .PATH in each other's source files, and I haven't the
time or patience to deal with it tonight.
 1.47  12-Jul-2014  dholland Remove pointless function indirection through panic_func(). It was
initialized to one thing, and then set to another right at the top of
main and never changed again.
 1.46  12-Jul-2014  dholland Revert version 1.111 of sysinst/disks.c, which caused sysinst to
create lfs fstab entries with fsck disabled, and instead patch
fsck_lfs to exit successfully without doing anything when given the -p
(bootup preen) option. If you really want to do fsck_lfs -p, you can
do fsck_lfs -f -p to make it go.

This has been sitting in my todo queue since February 2010 and was
ok'd by the committer at the time. The original commit was based on
this post:
http://mail-index.netbsd.org/tech-kern/2010/02/09/msg007306.html

and I remain unconvinced that it's the right thing, but we can at
least do it properly and not ship a sysinst with -7 that creates
permanently wrong fstab files.

Note that this may cause problems for anyone who's taken -p out of the
bootup fsck flags; but doing that is wrong, so don't.
 1.45  08-Jun-2013  dholland branches: 1.45.4;
Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.44  06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.43  09-Jun-2011  christos branches: 1.43.2; 1.43.8;
share more code.
 1.42  07-Jan-2010  christos branches: 1.42.4;
make this compile again.
 1.41  06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.40  12-Oct-2008  wiz Don't use unicode in usage.
Noted by Anon Ymous.
 1.39  09-Oct-2008  wiz Sync usage with man page.
 1.38  09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.37  23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.36  16-Jul-2007  pooka branches: 1.36.4; 1.36.10; 1.36.12;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.35  14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.34  08-Feb-2007  drochner include <signal.h> where signal(3) is used
 1.33  17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.32  01-Dec-2006  tls branches: 1.32.2;
Prompt before rolling forward, in interactive mode, so it's possible to fix
the filesystem but not roll forward possibly unwanted changes.
 1.31  09-Nov-2006  christos Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.30  01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.29  18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.28  17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.27  23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.26  19-Aug-2005  christos 64 bit inode changes
 1.25  27-Jun-2005  christos constify
 1.24  23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.23  14-Apr-2005  wiz Sync usage with man page.
 1.22  14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.21  06-Apr-2005  perseant Correct phase 0 message
 1.20  19-Jan-2005  xtraeme branches: 1.20.2;
ANSIfy, WARNS=2
 1.19  13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.18  21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.17  05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.16  20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.15  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14  29-Mar-2003  perseant Fix some accounting problems when preening, since preening skips phases
1-4 entirely. Make preen run phase 0, since the Ifile is so important
and the test so quick.
 1.13  28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.12  28-Jan-2003  mrg make this build on alpha after daddr_t->64bit
 1.11  24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.10  18-Aug-2001  ad getopt() returns -1 on error, not EOF.
 1.9  19-Feb-2001  cgd convert to use getprogname()
 1.8  04-Feb-2001  christos fix redundant decls
 1.7  11-Nov-2000  perseant Add "-f" flag to match fsck(8) manual page. This flag currently has no
effect. Fixes PR #11129.
 1.6  14-Jun-2000  perseant branches: 1.6.2;
Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.5  23-May-2000  perseant branches: 1.5.2;
Convert to NetBSD source code style
 1.4  16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.3  14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.2  03-Jul-1999  kleink RCS Id police.
 1.1  18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.5.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.1  03-Feb-2001  he Pull up revision 1.7 (requested by perseant):
Add compatibility option "-f" to fsck_lfs (PR #11129).
 1.20.2.1  07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.32.2.1  24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.36.12.2  17-Jan-2009  mjf Sync with HEAD.
 1.36.12.1  03-Apr-2008  mjf Sync with HEAD.
 1.36.10.1  24-Mar-2008  keiichi sync with head.
 1.36.4.1  23-Mar-2008  matt sync with HEAD
 1.42.4.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.43.8.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.8.1  23-Jun-2013  tls resync from head
 1.43.2.1  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.4.1  10-Aug-2014  tls Rebase.
 1.52.16.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.16.1  10-Jun-2019  christos Sync with HEAD
 1.53.2.1  16-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #73):

sbin/fsck_lfs/main.c: revision 1.54
sbin/fsck_ext2fs/main.c: revision 1.40
sbin/fsck_ffs/main.c: revision 1.86

fsck: Stop defining the same variable concurrently in bss and data
returntosingle was defined in multiple places:
- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).

RSS XML Feed