Home | History | Annotate | Download | only in fsck_ffs
History log of /src/sbin/fsck_ffs/pass2.c
RevisionDateAuthorComments
 1.53  04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.52  27-Mar-2023  chs Apply this commit from FreeBSD:

commit 6bae6625e0e06816c80ac4971dfccf0643abe3f0
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Aug 17 14:19:59 2022 -0700

Improve handling of missing '.' and '..' in UFS directories.

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
 1.51  08-Feb-2017  rin branches: 1.51.22;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.50  09-Jun-2013  dholland branches: 1.50.10; 1.50.14;
Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.49  22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.48  14-Aug-2011  christos branches: 1.48.2; 1.48.8;
WARNS=4
 1.47  09-Jun-2011  christos share more code.
 1.46  06-Mar-2011  bouyer branches: 1.46.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.45  23-Feb-2008  christos branches: 1.45.20;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.44  14-Nov-2006  apb branches: 1.44.8; 1.44.16; 1.44.18;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.43  21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.42  27-Jun-2005  christos sprinkle const.
 1.41  20-Jan-2005  xtraeme branches: 1.41.2;
whitespace (pointed out by wiz@)
 1.40  19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.39  13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.38  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.37  20-Jul-2004  mycroft Reduce memory usage slightly.
 1.36  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.35  13-Jul-2003  itojun use bounded string op
 1.34  09-Apr-2003  fvdl Correctly deal with directories that need indirect blocks by adding
some code I missed in the UFS2 commit. Should fix false positives
seen by fsck_ffs on clean filesystems.

Thanks to Takahiro Kambe for debugging help.
 1.33  02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.32  28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.31  06-May-2002  agc Make this compile on some of the more esoteric architectures.
 1.30  06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.29  09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.28  05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.27  17-Nov-1999  mrg branches: 1.27.4;
fix lp64 lossage.
 1.26  15-Nov-1999  fvdl Changes for softdep code.
 1.25  23-Oct-1998  thorpej branches: 1.25.4; 1.25.8;
Use DINODE_SIZE rather than sizeof(struct dinode) and/or pointer arithmetic.
 1.24  18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.23  21-Sep-1997  lukem reintroduce clarity changes made in rev1.14 that were lost in the lite2 merge
 1.22  21-Sep-1997  lukem remove some code that was obsoleted by mycroft's changes to
propagate() in dir.c rev 1.14.

this was accidentally re-introduced in the lite-2 merge, and could
cause filesystem corruption.
 1.21  20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.20  16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.19  16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.18  14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.17  27-Sep-1996  christos - util.h -> fsutil.h
 1.16  23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.15  11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.14  21-May-1996  mycroft branches: 1.14.2;
Remove previous (incorrect) change, and tidy up a bit to make it
clearer what's going on.
 1.13  21-May-1996  mrg initalise dino to zero. pr#2098
 1.12  18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11  28-Dec-1994  mycroft Change some spacing to match Kirk's view of the world.
 1.10  28-Dec-1994  mycroft Mostly sync with CSRG.
 1.9  05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.8  28-Oct-1994  mycroft Get the byte order right when creating `.' and `..' entries.
 1.7  23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6  08-Jun-1994  mycroft branches: 1.6.2;
Update from 4.4-Lite, with local changes.
 1.5  25-Apr-1994  cgd need <sys/time.h>
 1.4  01-Aug-1993  mycroft Add RCS identifiers.
 1.3  23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2  22-Mar-1993  cgd added rcs ids to all files
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  16-Sep-1997  lukem imported from lite-2
 1.1.1.2  13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.1  07-Nov-1994  cgd for patch #2
 1.14.2.1  10-Dec-1996  mycroft From trunk:
* Redo the tree-walking algorithm to make it O(n) rather than O(n^2).
* Fix some minor type size problems.
 1.25.8.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.4.1  19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.27.4.1  24-Nov-2001  he Pull up revision 1.29 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.41.2.1  20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.44.18.1  03-Apr-2008  mjf Sync with HEAD.
 1.44.16.1  24-Mar-2008  keiichi sync with head.
 1.44.8.1  23-Mar-2008  matt sync with HEAD
 1.45.20.1  20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.46.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.48.8.2  23-Jun-2013  tls resync from head
 1.48.8.1  25-Feb-2013  tls resync with head
 1.48.2.2  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.48.2.1  23-Jan-2013  yamt sync with head
 1.50.14.1  21-Apr-2017  bouyer Sync with HEAD
 1.50.10.1  20-Mar-2017  pgoyette Sync with HEAD
 1.51.22.1  13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #164):

sbin/fsck_ffs/pass2.c: revision 1.52

Apply this commit from FreeBSD:
commit 6bae6625e0e06816c80ac4971dfccf0643abe3f0
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Aug 17 14:19:59 2022 -0700
Improve handling of missing '.' and '..' in UFS directories.
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

RSS XML Feed