Home | History | Annotate | Download | only in fsck_ffs
History log of /src/sbin/fsck_ffs/pass1.c
RevisionDateAuthorComments
 1.64  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.63  07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.62  18-Nov-2022  martin branches: 1.62.2;
Fix clearing of permissions when finding unexpected extended attributs
for swapped endian file systems. Ok: chs
 1.61  17-Nov-2022  martin Make the "non-zero exattr fields" message show the inode number.
 1.60  17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.59  19-Apr-2020  christos Enable the code to clean the extattr blocks
 1.58  13-Feb-2018  hannken branches: 1.58.4;
Treat an inode with "mode == 0" and "blocks != 0" as partially allocated
and clear it as ffs_newvnode() tests for "blocks == 0".
 1.57  08-Feb-2017  rin branches: 1.57.4;
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.56  19-Oct-2013  christos branches: 1.56.8; 1.56.12;
fix unused variable warnings.
 1.55  23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.54  23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.53  19-Jun-2013  dholland blkoff() -> ffs_blkoff() stragglers
 1.52  19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.51  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.50  06-Jan-2013  riastradh Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49  14-Aug-2011  christos branches: 1.49.2; 1.49.4; 1.49.8; 1.49.10;
WARNS=4
 1.48  09-Jun-2011  christos share more code.
 1.47  06-Mar-2011  bouyer branches: 1.47.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.46  12-Oct-2008  christos branches: 1.46.2; 1.46.6; 1.46.10; 1.46.14; 1.46.16;
reallocate the correct amount. From Anon Ymous
 1.45  09-Oct-2008  christos Avoid allocating 2 x inospace and use realloc instead. This also saves a
large memcpy.
 1.44  23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.43  14-Nov-2006  apb branches: 1.43.8; 1.43.16; 1.43.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.42  16-Oct-2006  christos comment out impossible code.
 1.41  21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.40  05-Dec-2005  christos ndb is daddr_t which is 64 bits, by truncating it to j which is an int, it
can get negative causing segmentation faults. Check against this.
 1.39  19-Aug-2005  christos 64 bit inode changes
 1.38  08-Jun-2005  dbj add code to handle inodes with extended attribute blocks
this is currently turned off with "#ifdef notyet" since the
kernel will not correctly clean up extended attribute blocks on truncation

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.37  30-Apr-2005  christos Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.36  20-Jan-2005  xtraeme branches: 1.36.2;
whitespace (pointed out by wiz@)
 1.35  19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.34  13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.33  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.32  25-May-2004  hannken Add ffs internal snapshots. Written by Marshall Kirk McKusick for FreeBSD.

- Not enabled by default. Needs kernel option FFS_SNAPSHOT.
- Change parameters of ffs_blkfree.
- Let the copy-on-write functions return an error so spec_strategy
may fail if the copy-on-write fails.
- Change genfs_*lock*() to use vp->v_vnlock instead of &vp->v_lock.
- Add flag B_METAONLY to VOP_BALLOC to return indirect block buffer.
- Add a function ffs_checkfreefile needed for snapshot creation.
- Add special handling of snapshot files:
Snapshots may not be opened for writing and the attributes are read-only.
Use the mtime as the time this snapshot was taken.
Deny mtime updates for snapshot files.
- Add function transferlockers to transfer any waiting processes from
one lock to another.
- Add vfsop VFS_SNAPSHOT to take a snapshot and make it accessible through
a vnode.
- Add snapshot support to ls, fsck_ffs and dump.

Welcome to 2.0F.

Approved by: Jason R. Thorpe <thorpej@netbsd.org>
 1.31  03-Jan-2004  dbj branches: 1.31.4;
fix bugs with unsigned comparison ofs fs_maxsymlinklen
 1.30  03-Jan-2004  dbj increase size of buffer used for updating symlinks with -c 1
otherwise, the block read will blow the stack
 1.29  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.28  02-Apr-2003  he On LP64 hosts, iswap64() result is "long int", so cast result to (long long)
before printing with %lld.
 1.27  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.26  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.25  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.24  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.23  05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.22  15-Nov-1999  fvdl Changes for softdep code.
 1.21  18-Mar-1998  bouyer branches: 1.21.4; 1.21.8;
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.20  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.19  16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.18  16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.17  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.16  27-Sep-1996  christos - util.h -> fsutil.h
 1.15  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.14  18-Jan-1996  mycroft Use fs_csaddr to find the cg summary area. From der Mouse, PR 1366.
 1.13  18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12  05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.11  23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.10  23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9  29-Jun-1994  ws Reads on raw disks are only guarranteed in multiples of the block size
 1.8  14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.7  08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6  25-Apr-1994  cgd need <sys/time.h>
 1.5  01-Aug-1993  mycroft Add RCS identifiers.
 1.4  13-Jun-1993  mycroft Add support for fast symlinks.
 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.21.8.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.4.1  19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.31.4.1  01-May-2005  tron Pull up revision 1.37 (requested by christos in ticket #1493):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.36.2.3  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.36.2.2  07-Dec-2005  riz Pull up following revision(s) (requested by christos in ticket #1037):
sbin/fsck_ffs/pass1.c: revision 1.40
ndb is daddr_t which is 64 bits, by truncating it to j which is an int, it
can get negative causing segmentation faults. Check against this.
 1.36.2.1  01-May-2005  tron Pull up revision 1.37 (requested by christos in ticket #228):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.43.18.2  17-Jan-2009  mjf Sync with HEAD.
 1.43.18.1  03-Apr-2008  mjf Sync with HEAD.
 1.43.16.1  24-Mar-2008  keiichi sync with head.
 1.43.8.1  23-Mar-2008  matt sync with HEAD
 1.46.16.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.14.3  12-Feb-2011  bouyer Skip snapshot inodes for both block and inode quotas.
 1.46.14.2  12-Feb-2011  bouyer Snapshot inode doesn't count for block quotas.
 1.46.14.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.10.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.6.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.2.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.47.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.49.10.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #779):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49.8.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.49.8.2  23-Jun-2013  tls resync from head
 1.49.8.1  25-Feb-2013  tls resync with head
 1.49.4.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #779):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49.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.49.2.1  23-Jan-2013  yamt sync with head
 1.56.12.1  21-Apr-2017  bouyer Sync with HEAD
 1.56.8.1  20-Mar-2017  pgoyette Sync with HEAD
 1.57.4.1  15-Feb-2018  martin Pull up following revision(s) (requested by hannken in ticket #550):
sbin/fsck_ffs/pass1.c: revision 1.58
Treat an inode with "mode == 0" and "blocks != 0" as partially allocated
and clear it as ffs_newvnode() tests for "blocks == 0".
 1.58.4.1  21-Apr-2020  martin Sync with HEAD
 1.62.2.1  13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.

RSS XML Feed