Home | History | Annotate | Download | only in fsck_ffs
History log of /src/sbin/fsck_ffs/utilities.c
RevisionDateAuthorComments
 1.71  05-Jul-2023  riastradh Revert "fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.70  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.69  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.68  14-Jan-2023  christos catch up with sign changes in the fs.h
 1.67  17-Nov-2022  chs branches: 1.67.2;
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.66  17-Apr-2020  jdolecek align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device
 1.65  08-Feb-2017  rin branches: 1.65.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.64  19-Oct-2013  christos branches: 1.64.8; 1.64.12;
fix unused variable warnings.
 1.63  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.62  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.61  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.60  09-Jun-2011  christos branches: 1.60.2; 1.60.8;
share more code.
 1.59  06-Mar-2011  bouyer branches: 1.59.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.58  07-Jan-2010  christos branches: 1.58.2;
make this compile again.
 1.57  06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.56  31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.55  23-Feb-2008  christos branches: 1.55.4; 1.55.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.54  08-Feb-2007  drochner branches: 1.54.4; 1.54.10; 1.54.12;
include <signal.h> where signal(3) is used
 1.53  20-Mar-2006  christos Coverity CID 2074: Fix memory leak.
 1.52  23-Aug-2005  tron Use FFS_MAXNAMLEN instead of MAXNAMLEN.
 1.51  19-Aug-2005  christos 64 bit inode changes
 1.50  27-Jun-2005  christos sprinkle const.
 1.49  20-Jan-2005  xtraeme whitespace (pointed out by wiz@)
 1.48  19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.47  12-Jun-2004  mycroft Use pread()/pwrite().
 1.46  13-Apr-2004  dbj fix range error when swapping postbl for compatibility
 1.45  15-Jan-2004  dbj branches: 1.45.2;
terminate preen message from previous with \n
 1.44  15-Jan-2004  dbj if the user specifies both -b and -p, then just go ahead and update
the primary superblock.
 1.43  09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.42  29-Dec-2003  dbj fix minor bug in buf cache statistic collecting
 1.41  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.40  13-Jul-2003  itojun use bounded string op
 1.39  14-Apr-2003  fvdl If an alternate superblock is used, update the standard one correctly.
 1.38  13-Apr-2003  yamt save and restore errno in signal handlers.
 1.37  06-Apr-2003  fvdl Write update some old fields when writing the superblock, similar to
ffs_oldfscompat_write() in the kernel. Use the old totals when
time < old_time (i.e. an old kernel or fsck wrote the filesystem last).
When setting the date back on a new kernel, that works out ok, since
new kernels always update both fields.
 1.36  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.35  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.34  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.33  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.32  02-Sep-2001  lukem Incorporate fix by iedowse @ FreeBSD to allow disks with large numbers of
cylinder groups to work correctly, with minor modifications by me to work
with our FFS_EI code. From the FreeBSD commit message:

The ffs superblock includes a 128-byte region for use by temporary
in-core pointers to summary information. An array in this region
(fs_csp) could overflow on filesystems with a very large number of
cylinder groups (~16000 on i386 with 8k blocks). When this happens,
other fields in the superblock get corrupted, and fsck refuses to
check the filesystem.

Solve this problem by replacing the fs_csp array in 'struct fs'
with a single pointer, and add padding to keep the length of the
128-byte region fixed. Update the kernel and userland utilities
to use just this single pointer.

With this change, the kernel no longer makes use of the superblock
fields 'fs_csshift' and 'fs_csmask'. Add a comment to newfs/mkfs.c
to indicate that these fields must be calculated for compatibility
with older kernels.

Reviewed by: mckusick
 1.31  15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.30  04-Feb-2001  christos remove redundant declarations
 1.29  09-Jan-2001  mycroft A minor tweak.
 1.28  09-Jan-2001  enami Don't swap cg_clustersum(cg)[0]. It doesn't actually exists and it's
actually tail of free block bitmap.

XXX swap_cg() should be shared with newfs.
 1.27  10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.26  15-Nov-1999  fvdl branches: 1.26.4;
Changes for softdep code.
 1.25  06-May-1998  mycroft branches: 1.25.2; 1.25.4; 1.25.8;
copyback_cg() tried to copy too much if the cylinder group info was smaller
than 8k. From PR 5404.
 1.24  30-Mar-1998  mrg use extern int over extern
 1.23  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.22  24-Sep-1997  lukem for now, #ifdef out a couple of chunks that were added in the lite2 merge
 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  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.18  27-Sep-1996  christos - util.h -> fsutil.h
 1.17  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.16  05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.15  23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.14  12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.13  18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12  10-Feb-1995  cgd functions which are 'fake-varaargs' should be passed longs, not ints.
 1.11  05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.10  23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 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  09-Apr-1994  deraadt if user does ie, "fsck /etc/group", then types ^C to the CONTINUE
prompt do not dump core. fix from <dean@fsa.ca> (who i will stop
hounding about bug fixes for an hour or two)
 1.5  28-Mar-1994  cgd kill extern'd lseek()
 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.25.8.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.4.2  26-Oct-1999  fvdl Fix some merge mistakes.
 1.25.4.1  19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.25.2.1  10-Oct-2000  he Pull up revision 1.27 (requested by is):
Format string cleanup.
 1.26.4.3  25-Nov-2001  he Pull up revision 1.32 (requested by lukem):
Change fs_csp[] from being a fixed size to being an array sized
as required. This allows file systems with more than about 15500
cylinder groups (on 32-bit systems) to be used.
 1.26.4.2  24-Nov-2001  he Pull up revisions 1.28-1.30 (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.26.4.1  18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.45.2.1  27-Apr-2004  jdc Pull up revision 1.46 (requested by dbj in ticket #185)

Fix problems related to superblock upgrade issues which may be
experienced by -current users from 2003.
 1.54.12.2  28-Sep-2008  mjf Sync with HEAD.
 1.54.12.1  03-Apr-2008  mjf Sync with HEAD.
 1.54.10.1  24-Mar-2008  keiichi sync with head.
 1.54.4.1  23-Mar-2008  matt sync with HEAD
 1.55.6.1  10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.55.4.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.58.2.2  30-Jan-2011  bouyer Fix cut-n-paste: compare gid against gid, not uid.
 1.58.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.59.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.60.8.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.60.8.1  25-Feb-2013  tls resync with head
 1.60.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.60.2.1  23-Jan-2013  yamt sync with head
 1.64.12.1  21-Apr-2017  bouyer Sync with HEAD
 1.64.8.1  20-Mar-2017  pgoyette Sync with HEAD
 1.65.12.1  21-Apr-2020  martin Sync with HEAD
 1.67.2.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