Home | History | Annotate | Download | only in fsck_ffs
History log of /src/sbin/fsck_ffs/inode.c
RevisionDateAuthorComments
 1.79  25-Feb-2025  andvar Fix a few typos in the word 'offset' in comments and error message.
 1.78  05-Jul-2023  riastradh Revert "fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.77  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.76  04-Jul-2023  riastradh fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.75  14-Jan-2023  kre Use %zu rather than %lu to print a size_t (should fix i386 build).

But, philosophical question, shouldn't the product of two size_t
variables really be an area_t, or something like that?
 1.74  14-Jan-2023  christos catch up with sign changes in the fs.h
 1.73  17-Apr-2020  jdolecek branches: 1.73.6;
align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device
 1.72  08-Feb-2017  rin branches: 1.72.12;
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.71  05-Apr-2014  justin branches: 1.71.8; 1.71.12;
Iterate over fields of struct seperately to avoid warnings from pedantic compilers
 1.70  02-Dec-2013  bouyer Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.69  23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.68  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.67  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.66  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.65  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.64  06-Mar-2011  bouyer branches: 1.64.4; 1.64.6; 1.64.10; 1.64.12; 1.64.14;
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.63  04-Feb-2010  christos branches: 1.63.2;
Centralize time printing and deal with ctime possibly returning NULL.
 1.62  11-Apr-2009  lukem fix sign-compare issues
 1.61  09-Oct-2008  christos branches: 1.61.4;
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.60  08-Jul-2008  simonb Fix funny whitespace in a variable assignment.
 1.59  23-Feb-2008  christos branches: 1.59.4; 1.59.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.58  12-Apr-2007  chs branches: 1.58.4; 1.58.10; 1.58.12;
apply revision 1.31 yet again:
"make sure that we don't try to allocate negative memory when blks == 0."
or on amd64, "make sure that we don't allocate 32 GB when blks == 0."
 1.57  21-Apr-2006  skrll branches: 1.57.4;
Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.56  19-Aug-2005  christos 64 bit inode changes
 1.55  27-Jun-2005  christos sprinkle const.
 1.54  02-Jun-2005  lukem appease gcc -Wuninitialized
 1.53  30-Apr-2005  christos Remove stray " I" from message.
 1.52  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.51  20-Jan-2005  xtraeme branches: 1.51.2;
whitespace (pointed out by wiz@)
 1.50  19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.49  08-Oct-2004  dbj when allocating inodes, such as for the lost+found directory,
extend the inostat array if needed. Otherwise, inoinfo() will
return the static "unallocated" inode template, which was
getting improperly modified.
Before this fix, any time the lost+found directory got created,
fsck would set all of the inode/directory counts wrong since
suddenly unallocated inodes would turn into directory inodes
 1.48  20-Jul-2004  mycroft Reduce memory usage slightly.
 1.47  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.46  26-Apr-2004  dbj fix 64bit bug in chkrange()
problem noticed by nathanw
fix from freebsd
 1.45  03-Jan-2004  dbj branches: 1.45.2;
fix logic for handling symlinks in inodes when isappleufs
 1.44  03-Jan-2004  dbj when doing both -c 2 and -B, swap the blocks listed in the inode
of symlinks, since the swapping happens before the symlinks
are moved into the inode.
 1.43  03-Jan-2004  dbj fix paste-o in previous commit
 1.42  03-Jan-2004  dbj fix bugs with unsigned comparison ofs fs_maxsymlinklen
 1.41  19-Sep-2003  itojun realloc pedant
 1.40  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.39  13-Jul-2003  itojun use bounded string op
 1.38  08-Apr-2003  fvdl Swap the right blocks in an inode in the byteswapping case.
 1.37  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.36  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.35  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.34  05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.33  12-Dec-1999  christos - ARGH /brick fvdl
- Put back the change from revision 1.31
 1.32  15-Nov-1999  fvdl Changes for softdep code.
 1.31  06-Sep-1999  christos branches: 1.31.4;
make sure that we don't try to allocate negative memory when blks == 0.
 1.30  23-Oct-1998  thorpej branches: 1.30.4;
Use DINODE_SIZE rather than sizeof(struct dinode) and/or pointer arithmetic.
 1.29  28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.28  01-Apr-1998  kleink Need <time.h> for ctime() and time() prototypes.
 1.27  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.26  16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.25  16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.24  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.23  11-Oct-1996  thorpej Bug fix from Kirk McKusick <mckusick@McKusick.COM>:

Fix a bug in fsck_ffs where if a directory somehow develops a hole
(that is a block pointer that has a value of zero), fsck would give the
filesystem a clean bill of health, but the kernel would panic when
accessing the directory with the hole. Fsck now checks for holes
in directories. If found in preen mode, fsck fails. In manual
mode, it can be directed to shorten the directory to the beginning of
the hole. A more complete solution would be to allocate a block to fill
the hole. However, this is a lot more work for a `cannot happen' error,
so the extra effort seems unwarranted.
 1.22  27-Sep-1996  christos - util.h -> fsutil.h
 1.21  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.20  11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.19  25-May-1996  mycroft File sizes in FFS are u_int64_t.
 1.18  21-May-1996  mycroft branches: 1.18.2;
Adjust the logic a bit so we `nif' can't overflow.
 1.17  17-Dec-1995  thorpej Squish some type bugs pointed out by Jonathan Stone.
 1.16  14-Dec-1995  thorpej Make this compile with -Werror.
 1.15  07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.14  20-Mar-1995  mycroft Make sure to recreate the `..' entry in the root directory if missing.
 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 Eliminate uses of some obsolete functions.
 1.10  14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.9  08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8  02-May-1994  pk Prototype some things.
 1.7  25-Apr-1994  cgd need <sys/time.h>
 1.6  18-Apr-1994  cgd kill some code if SMALL is defined...
 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.18.2.2  02-Mar-1997  mycroft Pull up changes from Kirk McKusick to check for holes in directories.
 1.18.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.30.4.2  26-Oct-1999  fvdl Fix some merge mistakes.
 1.30.4.1  19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.31.4.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.45.2.1  28-Apr-2004  jmc branches: 1.45.2.1.2;
Pullup rev 1.46 (requested by dbj in ticket #202)

Fix 64bit bug in chkrange().
 1.45.2.1.2.1  01-May-2005  tron Pull up revision 1.52 (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.51.2.1  01-May-2005  tron Pull up revision 1.52 (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.57.4.2  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.57.4.1  12-Apr-2007  bouyer Pull up following revision(s) (requested by chs in ticket #568):
sbin/fsck_ffs/inode.c: revision 1.58
apply revision 1.31 yet again:
"make sure that we don't try to allocate negative memory when blks == 0."
or on amd64, "make sure that we don't allocate 32 GB when blks == 0."
 1.58.12.3  17-Jan-2009  mjf Sync with HEAD.
 1.58.12.2  28-Sep-2008  mjf Sync with HEAD.
 1.58.12.1  03-Apr-2008  mjf Sync with HEAD.
 1.58.10.1  24-Mar-2008  keiichi sync with head.
 1.58.4.1  23-Mar-2008  matt sync with HEAD
 1.59.6.1  18-Jul-2008  simonb Sync with head.
 1.59.4.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.61.4.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.63.2.3  12-Feb-2011  bouyer Skip snapshot inodes for both block and inode quotas.
 1.63.2.2  12-Feb-2011  bouyer Snapshot inode doesn't count for block quotas.
 1.63.2.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.64.14.1  17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.12.1  17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.10.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.64.10.2  23-Jun-2013  tls resync from head
 1.64.10.1  25-Feb-2013  tls resync with head
 1.64.6.1  17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.4.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.64.4.1  23-Jan-2013  yamt sync with head
 1.71.12.1  21-Apr-2017  bouyer Sync with HEAD
 1.71.8.1  20-Mar-2017  pgoyette Sync with HEAD
 1.72.12.1  21-Apr-2020  martin Sync with HEAD
 1.73.6.2  13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #163):

sbin/fsck_ffs/inode.c: revision 1.75

Use %zu rather than %lu to print a size_t (should fix i386 build).
 1.73.6.1  13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #162):

sbin/fsck_ffs/inode.c: revision 1.74
sbin/fsck_ffs/utilities.c: revision 1.68
sbin/fsck_ffs/fsck.h: revision 1.57
sbin/fsck_ffs/pass4.c: revision 1.30

catch up with sign changes in the fs.h

RSS XML Feed