History log of /freebsd-current/sbin/growfs/growfs.c
Revision Date Author Comments
# 26c3d72e 13-Jan-2024 HUANG,YU-JIA <s112062566@m112.nthu.edu.tw>

growfs(8): Fix spelling

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request: https://github.com/freebsd/freebsd-src/pull/1055


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 70a0fb43 05-Oct-2023 Mina Galić <freebsd@igalic.co>

growfs: make exit codes more consistent

We have overused err(1), so it's hard to distinguish when an error is
very, very serious, and when it's just a user-error, or even harmless.

This patch changes the current behaviour to distinguish between the
following three:

1 for usage errors
2 for recoverable errors
3 or higher for unrecoverable errors

Reviewed by: jilles, pauamma_gundo.com, des
Differential Revision: https://reviews.freebsd.org/D27161


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 0a6e34e9 15-May-2023 Kirk McKusick <mckusick@FreeBSD.org>

Fix size differences between architectures of the UFS/FFS CGSIZE macro value.

The cylinder group header structure ended with `u_int8_t cg_space[1]'
representing the beginning of the inode bitmap array. Some architectures
like the i386 rounded this up to a 4-byte boundry while other
architectures like the amd64 rounded it up to an 8-byte boundry.
Thus sizeof(struct cg) was four bytes bigger on an amd64 machine
than on an i386 machine. If a filesystem created on an i386 machine
was moved to an amd64 machine, the size of the cylinder group
calculated by the CGSIZE macro would appear to grow by four bytes.
Filesystems whose cylinder groups were exactly equal to the block
size on an i386 machine would appear to have a cylinder group that
was four bytes too big when moved to an amd64 machine. Note that
although the structure appears to be too big, it in fact is fine.
It is just the calaculation of its size that is in error.

The fix is to remove the cg_space element from the cylinder-group
structure so that the calculated size of the structure is the same
size on all architectures.

Reported by: Tijl Coosemans
Tested by: Tijl Coosemans and Peter Holm
MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# 906c312b 15-Jan-2023 Kirk McKusick <mckusick@FreeBSD.org>

Document the mntopts(3) functions.

The mntopts(3) functions support operations associated with a mount
point. The main purpose of this commit is to document the mntopts(3)
functions that now appear in 18 utilities in the base system. See
mntopts(3) for the documentation details.

The getmntopts() function appeared in 4.4BSD. The build_iovec(),
build_iovec_argf(), free_iovec(), checkpath(), and rmslashes()
functions were added with nmount(8) in FreeBSD 5.0. The getmntpoint()
and chkdoreload() functions are being added in this commit.

These functions should be in a library but for historic reasons are
in a file in the sources for the mount(8) program. Thus, to access
them the following lines need to be added to the Makefile of the
program wanting to use them:

SRCS+= getmntopts.c
MOUNT= ${SRCTOP}/sbin/mount
CFLAGS+= -I${MOUNT}
.PATH: ${MOUNT}

Once these changes have been MFC'ed to 13 they may be made into
a library.

Reviewed by: kib, gbe
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37907


# b21582ee 30-Jul-2022 Kirk McKusick <mckusick@FreeBSD.org>

Add a flags parameter to the ffs_sbget() function that reads UFS superblocks.

Rather than trying to shoehorn flags into the requested superblock
address, create a separate flags parameter to the ffs_sbget()
function in sys/ufs/ffs/ffs_subr.c. The ffs_sbget() function is
used both in the kernel and in user-level utilities through export
to the sbget() function in the libufs(3) library (see sbget(3)
for details). The kernel uses ffs_sbget() when mounting UFS
filesystems, in the glabel(8) and gjournal(8) GEOM utilities,
and in the standalone library used when booting the system
from a UFS root filesystem.

The ffs_sbget() function reads the superblock located at the byte
offset specified by its sblockloc parameter. The value UFS_STDSB
may be specified for sblockloc to request that the standard
location for the superblock be read.

The two existing options are now flags:

UFS_NOHASHFAIL will note if the check hash is wrong but will still
return the superblock. This is used by the bootstrap code to
give the system a chance to come up so that fsck can be run to
correct the problem.

UFS_NOMSG indicates that superblock inconsistency error messages
should not be printed. It is used by programs like fsck that
want to print their own error message and programs like glabel(8)
that just want to know if a UFS filesystem exists on a partition.

One additional flag is added:

UFS_NOCSUM causes only the superblock itself to be returned, but does
not read in any auxiliary data structures like the cylinder group
summary information. It is used by clients like glabel(8) that
just want to check for possible filesystem types. Using UFS_NOCSUM
skips the superblock checks for csum data which allows superblocks
that have corrupted csum data to be read and used.

The validate_sblock() function checks that the superblock has not
been corrupted in a way that can crash or hang the system. Unless
the UFS_NOMSG flag is specified, it will print out any errors that
it finds. Prior to this commit, validate_sblock() returned as soon
as it found an inconsistency so would print at most one message.
It now does all its checks so when UFS_NOMSG has not been specified
will print out everything that it finds inconsistent.

Sponsored by: The FreeBSD Foundation


# 2049cc32 27-Jun-2022 Kirk McKusick <mckusick@FreeBSD.org>

Correctly update fs_dsize in growfs(8)

When growing a UFS/FFS filesystem, the size of the summary information
may expand into additional blocks. These blocks must be removed from
fs_dsize which records the number of blocks in the filesystem that can
be used to hold filesystem data.

While here also update the fs_old_dsize and fs_old_size fields for
compatibility with kernels that were compiled before the addition
of UFS2.

Reported by: Edward Tomasz Napiera
MFC after: 1 week


# 78dfcf25 27-Jun-2022 Kirk McKusick <mckusick@FreeBSD.org>

Eliminate set but not used variable.

No functional change intended.


# 3f9acedb 15-Nov-2021 Ed Maste <emaste@FreeBSD.org>

growfs: do not error if filesystem is already requested size

For some cloud/virtualization use cases it can be convenient to grow the
filesystem on boot any time the disk/partition happens to be larger, but
not fail if it remains the same size.

Continue to emit a message if we have no action to take, but exit with
status 0 if the size remains the same.

Reviewed by: trasz
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32856


# 0dcde5cc 02-Mar-2021 Ed Maste <emaste@FreeBSD.org>

growfs: allow operation on RW-mounted filesystems

growfs supports growing mounted filesystems (writes are temporarily
suspended while the grow happens). Drop the check for fs_clean == 0
to restore this case. Leave fs_flags check for FS_UNCLEAN or
FS_NEEDSFSCK which represent the state of the filesystem when it was
mounted, and fsck should be run first if they are set.

PR: 253754
Reviewed by: mckusick
MFC after: 3 days
Fixes: 6eb925f8450f ("Filesystem utilities that modify the...")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29021


# 6eb925f8 24-Oct-2020 Kirk McKusick <mckusick@FreeBSD.org>

Filesystem utilities that modify the filesystem (growfs(8), tunefs(8),
and fsirand(8)) should check the filesystem status and require that
fsck(8) be run if it is unclean. This requirement is not imposed on
fsdb(8) or clri(8) since they may be used to clean up a filesystem.

MFC after: 2 weeks
Sponsored by: Netflix


# 54fab0fb 21-Sep-2020 Kirk McKusick <mckusick@FreeBSD.org>

Add missing cylinder group check-hash updates when doing large expansions
of filesystems.

Reported by: Colin Percival (cperciva@)
Tested by: Colin Percival (cperciva@)
MFC after: 3 days
Sponsored by: Netflix


# fb14e73c 05-Dec-2018 Kirk McKusick <mckusick@FreeBSD.org>

Normally when an attempt is made to mount a UFS/FFS filesystem whose
superblock has a check-hash error, an error message noting the
superblock check-hash failure is printed and the mount fails. The
administrator then runs fsck to repair the filesystem and when
successful, the filesystem can once again be mounted.

This approach fails if the filesystem in question is a root filesystem
from which you are trying to boot. Here, the loader fails when trying
to access the filesystem to get the kernel to boot. So it is necessary
to allow the loader to ignore the superblock check-hash error and make
a best effort to read the kernel. The filesystem may be suffiently
corrupted that the read attempt fails, but there is no harm in trying
since the loader makes no attempt to write to the filesystem.

Once the kernel is loaded and starts to run, it attempts to mount its
root filesystem. Once again, failure means that it breaks to its prompt
to ask where to get its root filesystem. Unless you have an alternate
root filesystem, you are stuck.

Since the root filesystem is initially mounted read-only, it is
safe to make an attempt to mount the root filesystem with the failed
superblock check-hash. Thus, when asked to mount a root filesystem
with a failed superblock check-hash, the kernel prints a warning
message that the root filesystem superblock check-hash needs repair,
but notes that it is ignoring the error and proceeding. It does
mark the filesystem as needing an fsck which prevents it from being
enabled for writing until fsck has been run on it. The net effect
is that the reboot fails to single user, but at least at that point
the administrator has the tools at hand to fix the problem.

Reported by: Rick Macklem (rmacklem@)
Discussed with: Warner Losh (imp@)
Sponsored by: Netflix


# 9fc5d538 13-Nov-2018 Kirk McKusick <mckusick@FreeBSD.org>

In preparation for adding inode check-hashes, clean up and
document the libufs interface for fetching and storing inodes.
The undocumented getino / putino interface has been replaced
with a new getinode / putinode interface.

Convert the utilities that had been using the undocumented
interface to use the new documented interface.

No functional change (as for now the libufs library does not
do inode check-hashes).

Reviewed by: kib
Tested by: Peter Holm
Sponsored by: Netflix


# dffce215 25-Jan-2018 Kirk McKusick <mckusick@FreeBSD.org>

Refactoring of reading and writing of the UFS/FFS superblock.
Specifically reading is done if ffs_sbget() and writing is done
in ffs_sbput(). These functions are exported to libufs via the
sbget() and sbput() functions which then used in the various
filesystem utilities. This work is in preparation for adding
subperblock check hashes.

No functional change intended.

Reviewed by: kib


# df57947f 18-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

spdx: initial adoption of licensing ID tags.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes: yes
Differential Revision: https://reviews.freebsd.org/D13133


# 4887fa36 10-Oct-2017 Ed Maste <emaste@FreeBSD.org>

growfs: ANSIfy cgckhash()

The build was broken on GCC-using architectures with:

growfs.c: In function 'cgckhash':
growfs.c:1753: warning: old-style function definition

Sponsored by: The FreeBSD Foundation


# 3abf5d76 10-Oct-2017 Kirk McKusick <mckusick@FreeBSD.org>

Growfs got missed in r323923 that added a check hash to cylinder groups.
This makes the needed changes to add/update cylinder group check hashes
when a filesystem is expanded.

Reported by: kib and Warner Losh (imp)
Reviewed by: kib
Tested by: Peter Holm (pho)


# 1dc349ab 15-Feb-2017 Ed Maste <emaste@FreeBSD.org>

prefix UFS symbols with UFS_ to reduce namespace pollution

Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Also prefix ext2's and nandfs's NDADDR and NIADDR with EXT2_ and NANDFS_

Reviewed by: kib, mckusick
Obtained from: NetBSD
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D9536


# b8a1930f 11-May-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Cosmetic fixes for growfs(8) - remove unneeded capitalization and a spurious
newline, clarify a message.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# e921a133 01-May-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use MIN() macro from sys/param.h.

Reviewed by: trasz
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6119


# edf6b683 18-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use NULL instead of 0 for pointers.

strchr(3) will return NULL if the character does not appear in the
string.

MFC after: 2 weeks.


# a44ba043 23-Apr-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix growfs(8) build with debug enabled (make -DGFSDBG).

PR: 199641
Submitted by: Willem Jan Withagen <wjw at digiware dot nl>
MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 295a5bd7 09-Feb-2014 Christian Brueffer <brueffer@FreeBSD.org>

Refer newfs and growfs users to fsck_ffs instead of
fsck, the latter does not accept the referred to "-b" flag.

This change was accidently committed directly to 9-STABLE in
r237505.

PR: 82720
Submitted by: David D.W. Downey
MFC after: 1 week


# 63efd0a1 08-May-2013 Eitan Adler <eadler@FreeBSD.org>

Allow the use of lowercase 'yes'

PR: bin/178422
Submitted by: Garrett Cooper <yaneurabeya@gmail.com>


# 44246b4c 14-Apr-2013 Xin LI <delphij@FreeBSD.org>

Use arc4random() instead of random().

MFC after: 2 weeks


# be1bfa99 16-Dec-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

When growing a filesystem, don't leave unused space at the end
if there is not enough room for a full cylinder group.

Reviewed by: mckusick@


# cd379aaf 15-Dec-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix extending filesystems of weird size by making sure the actual size
is always multiple of fragment size.


# 2ec1a006 18-Nov-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make it possible to resize filesystems mounted read-write, using newly
introduced UFS write suspension mechanism.

Reviewed by: kib, mckusick
Sponsored by: FreeBSD Foundation


# 549f62fa 30-Oct-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix problem with geom_label(4) not recognizing UFS labels on filesystems
extended using growfs(8). The problem here is that geom_label checks if
the filesystem size recorded in UFS superblock is equal to the provider
(i.e. device) size. This check cannot be removed due to backward
compatibility. On the other hand, in most cases growfs(8) cannot set
fs_size in the superblock to match the provider size, because, differently
from newfs(8), it cannot recompute cylinder group sizes.

To fix this problem, add another superblock field, fs_providersize, used
only for this purpose. The geom_label(4) will attach if either fs_size
(filesystem created with newfs(8)) or fs_providersize (filesystem expanded
using growfs(8)) matches the device size.

PR: kern/165962
Reviewed by: mckusick
Sponsored by: FreeBSD Foundation


# e25a029e 27-Sep-2012 Matthew D Fleming <mdf@FreeBSD.org>

Fix sbin/ build with a 64-bit ino_t.

Original code by: Gleb Kurtsou


# 089d61ec 07-Jul-2012 Eitan Adler <eadler@FreeBSD.org>

Remove unneeded variable reported by gcc46 which stopped being used in
r234178.

Approved by: cperciva
MFC after: 3 days


# deb35287 06-May-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix offset calculation to actually rewrite the _last_ block.


# e35497f1 30-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Improve growfs(8) in a few ways; unfortunately, it's somewhat hard to untangle
them and commit separately.

1. Rewrite the way growfs(8) finds the device and mount point. This makes
it possible to use e.g. "growfs /mnt"; it's also used to display more
helpful messages.

2. Be more user-friendly, using descriptive messages, like this:

OK to grow filesystem on /dev/md0, mounted on /mnt, from 9.8GB to 20GB? [Yes/No]"

3. Allow to specify the size (-s option) just like with mdconfig(8), i.e. with
postfixes ("mdconfig -s 10g").

4. Reload read-only filesystem after growing.

Reviewed by: kib, mckusick (earlier version)
Sponsored by: The FreeBSD Foundation


# 91ac1479 18-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Style.


# f979d8ac 15-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Style.


# b408e19c 15-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Remove FSIRAND and FSMAXSWAP ifdefs, removing code unconditionally.

Reviewed by: kib, mckusick
Sponsored by: The FreeBSD Foundation


# 6ad07d53 12-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Style.


# 9f2d8a38 12-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Remove block reallocation used to make room for the cylinder group
summary structure. From now on, when there is no room for it,
we simply allocate new one in a newly added cylinder group.

This patch removes a conditional in updcsloc(), reindents some code
there, and removes unused routines. I decided to do it this way instead
of disabling reallocation when the filesystem is live and leaving it
as it is otherwise, because this allows for removal of lots of complicated
and hard to test code. Also, conditionally disabling it would result
in a different layout in filesystems resized online and offline, which
would look somewhat weird.

Reviewed by: mckusick
No objections from: kib
Sponsored by: The FreeBSD Foundation


# 50c603c4 29-Mar-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Remove disklabel handling code from growfs. This should be done
via geom_part(4), and it doesn't belong in growfs anyway.

Reviewed by: kib, mckusick
Sponsored by: The FreeBSD Foundation


# 8f061f61 12-Mar-2012 Dimitry Andric <dim@FreeBSD.org>

After r232548, clang complains about the apparent '=-' operator (a
left-over from ancient C times, and a frequent typo) in growfs.c:

sbin/growfs/growfs.c:1550:8: error: use of unary operator that may be intended as compound assignment (-=) [-Werror]
blkno =- 1;
^~

Use 'blkno = -1' instead, to silence the error.


# a1da0740 05-Mar-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make growfs(8) mostly style compliant. No functional changes,
verified with MD5.


# 11dc4806 17-Jan-2012 Ed Schouten <ed@FreeBSD.org>

Allow growfs to be built with GCC 4.7 and -Werror.

The dp1 variable is only used when FSIRAND is defined. Just place the
variable behind #ifdefs entirely.


# 1efe3c6b 04-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Add missing static keywords for global variables to tools in sbin/.

These tools declare global variables without using the static keyword,
even though their use is limited to a single C-file, or without placing
an extern declaration of them in the proper header file.


# 8857bdbc 28-Jun-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Revert the mechanical change from 'file system' to 'filesystem', committed
in r223429. As bde@ pointed out, it was mostly backwards.


# b2168df8 22-Jun-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Cosmetic fixes; mostly s/file system/filesystem/g and removing weird indent
from messages.


# 974206cf 23-Feb-2011 Rebecca Cran <brucec@FreeBSD.org>

Fix typos - remove duplicate "is".

PR: docs/154934
Submitted by: Eitan Adler <lists at eitanadler.com>
MFC after: 3 days


# ea6de5ee 22-Jan-2011 Marcel Moolenaar <marcel@FreeBSD.org>

s/utime/modtime/g -- utime shadows utime(3).

Submitted by: Garrett Cooper


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# e29560ac 19-Sep-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Unbreak the build on strong-aligned architectures (arm, ia64).
Casting from (char *) to (struct ufs1_dinode *) changes the
alignment requirement of the pointer and GCC does not know that
the pointer is adequately aligned (due to malloc(3)), and warns
about it. Cast to (void *) first to by-pass the check.


# 1ad5f80f 19-Sep-2010 Brian Somers <brian@FreeBSD.org>

Revise r197763 which fixes filesystem corruption when extending
into un-zeroed storage.

The original patch was questioned by Kirk as it forces the filesystem
to do excessive work initialising inodes on first use, and was never
MFC'd. This change mimics the newfs(8) approach of zeroing two
blocks of inodes for each new cylinder group.

Reviewed by: mckusick
MFC after: 3 weeks


# 40df9792 17-Mar-2010 Gavin Atkinson <gavin@FreeBSD.org>

Merge r203835 from head:

When growing a UFS1 filesystem, we need to initialise all inodes in any new
cylinder groups that are created. When the filesystem is first created,
newfs always initialises the first two blocks of inodes, and then in the
UFS1 case will also initialise the remaining inode blocks. The changes in
growfs.c 1.23 broke the initialisation of all inodes, seemingly based on
this implementation detail in newfs(8). The result was that instead of
initialising all inodes, we would actually end up initialising all but the
first two blocks of inodes. If the filesystem was grown into empty
(all-zeros) space then the resulting filesystem was fine, however when
grown onto non-zeroed space the filesystem produced would appear to have
massive corruption on the first fsck after growing.
A test case for this problem can be found in the PR audit trail.

Fix this by once again initialising all inodes in the UFS1 case.

PR: bin/115174
Submitted by: "Nate Eldredge" <nge cs.hmc.edu>
Reviewed by: mjacob


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 4179ce18 26-Feb-2010 Kirk McKusick <mckusick@FreeBSD.org>

MFC of 203763, 203764, 203768, 203769, 203770, 203782, and 203784.

These fixes correct 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.

These fixes also update newfs to ensure that it will never create a
filesystem with more than 2^32 inodes.

They also update libufs, tunefs, and growfs so that they properly
handle inode numbers as unsigned.

Reported by: Scott Burns, John Kilburg, and Bruce Evans
Followup by: Jeff Roberson
PR: 133980


# 08f353eb 13-Feb-2010 Gavin Atkinson <gavin@FreeBSD.org>

When growing a UFS1 filesystem, we need to initialise all inodes in any new
cylinder groups that are created. When the filesystem is first created,
newfs always initialises the first two blocks of inodes, and then in the
UFS1 case will also initialise the remaining inode blocks. The changes in
growfs.c 1.23 broke the initialisation of all inodes, seemingly based on
this implementation detail in newfs(8). The result was that instead of
initialising all inodes, we would actually end up initialising all but the
first two blocks of inodes. If the filesystem was grown into empty
(all-zeros) space then the resulting filesystem was fine, however when
grown onto non-zeroed space the filesystem produced would appear to have
massive corruption on the first fsck after growing.
A test case for this problem can be found in the PR audit trail.

Fix this by once again initialising all inodes in the UFS1 case.

PR: bin/115174
Submitted by: Nate Eldredgei nge cs.hmc.edu
Reviewed by: mjacob
MFC after: 1 month


# 14a176a0 10-Feb-2010 Kirk McKusick <mckusick@FreeBSD.org>

Quiet spurious warnings.


# 86aedb09 02-Feb-2010 Gavin Atkinson <gavin@FreeBSD.org>

Merge r201401 from head:

Remove dead code. This section of code is only run in the
(sblock.fs_magic == FS_UFS1_MAGIC) case, so the check within the
loop is redundant.

PR: bin/115174 (partly)
Submitted by: Nate Eldredge nge cs.hmc.edu
Reviewed by: mjacob
Approved by: ed (mentor, implicit)


# eb747250 02-Jan-2010 Gavin Atkinson <gavin@FreeBSD.org>

Remove dead code. This section of code is only run in the
(sblock.fs_magic == FS_UFS1_MAGIC) case, so the check within the
loop is redundant.

Submitted by: Nate Eldredge nge cs.hmc.edu
Reviewed by: mjacob
Approved by: ed (mentor)
MFC after: 1 month


# 4bdcc9c7 04-Oct-2009 Matt Jacob <mjacob@FreeBSD.org>

The cylinder group tag cg_initediblk needs to match the number of inodes
actually initialized. In the growfs case for UFS2, no inodes were actually
being initialized and the number of inodes noted as initialized was the
number of inodes per group. This created a filesystem that was deemed
corrupted because the inodes thus added were full of garbage.

MFC after: 1 month


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# baa15be0 17-Dec-2007 David Schultz <das@FreeBSD.org>

Fix an int overflow on very large file systems.

PR: bin/113399
Submitted by: Staffan Ulfberg <staffan@ulfberg.se>


# 42e35587 17-Jul-2006 Stefan Farfeleder <stefanf@FreeBSD.org>

Remove duplicated assignment.


# e3ec673e 16-Jan-2005 Philippe Charnier <charnier@FreeBSD.org>

Remove \n at the end of err(3) strings


# e7c46054 08-Oct-2004 Scott Long <scottl@FreeBSD.org>

3 important fixes for growfs:

1) ginode() is passed a cylinder group number and inode number. The inode
number is relative to the cg. Use this relative number rather than the
absolute inode number when searching the cg inode bitmap to see if the inode
is allocated. Using the absolute number quickly runs the check off the end
of the array and causes invalid inodes to be referenced.

2) ginode() checks the absolute indoe number to make sure that it is greater
than ROOTINO. However, the caller loops through all of the possible inode
numbers and directly passes in values that are < ROOTINO. Instead of halting
the program with an error, just return NULL.

3) When allocating new cylinder groups, growfs was initializing all of the
inodes in the group regardless of this only being required for UFS1. Not
doing this for UFS2 provides a significant performance increase.

These fixes allow growing a filesystem beyond a trivial amount and have
been tested to grow an 8GB filesystem to 1.9TB. Much more testing would
be appreciated.

Obtained from: Sandvine, Inc.


# 691ae404 29-Jul-2004 Lukas Ertl <le@FreeBSD.org>

Catch up with recent gcc changes and introduce a DIP_SET macro
to use when setting values that depend on the UFS version.
Raise WARNS again.


# 35cf80de 03-Apr-2004 Bruce Evans <bde@FreeBSD.org>

Include <time.h> instead of depending on namespace pollution in <sys/stat.h>
for the declaration of time().


# b1fddb23 03-Apr-2004 Maxime Henrion <mux@FreeBSD.org>

Fix the remaining warnings of growfs(8) on my sparc64 box with
WARNS=6. I don't change the WARNS level in the Makefile because I
didn't tested this on other archs.

The fs.h fix was suggested by: marcel
Reviewed by: md5(1)


# 760ea1fa 03-Apr-2004 Maxime Henrion <mux@FreeBSD.org>

- Don't abuse caddr_t when what we really want is a void *.
- Use the %jd format and a cast to intmax_t to print an int64_t.
- The return type of getopt() is an int, not a char.

This fixes some warnings but there's still much more work to do here.


# 75d1ec91 03-Apr-2004 Lukas Ertl <le@FreeBSD.org>

Make growfs WARNS=6 clean.

Approved by: grog (mentor)


# f055f9f2 26-Mar-2004 Lukas Ertl <le@FreeBSD.org>

Don't read an inode which isn't used to avoid problems on UFS2 where not
all inodes are initialized when running newfs.

Approved by: grog (mentor)


# 654c2874 29-Oct-2003 Tom Rhodes <trhodes@FreeBSD.org>

Remove a few unused variables.


# 4b9748d4 11-May-2003 Greg Lehey <grog@FreeBSD.org>

Understand GEOM. This makes growfs work again, but it really needs rewriting.

Submitted by: Lukas Ertl <l.ertl@univie.ac.at>
Approved by: re (scottl)


# 6ded0533 26-Apr-2003 Jens Schweikhardt <schweikh@FreeBSD.org>

Fix typos in comments; some style(9) fixes; no code changes.

PR: misc/50979
Submitted by: Lukas Ertl <l.ertl@univie.ac.at>


# d64ada50 30-Dec-2002 Jens Schweikhardt <schweikh@FreeBSD.org>

Fix typos, mostly s/ an / a / where appropriate and a few s/an/and/
Add FreeBSD Id tag where missing.


# ada981b2 26-Nov-2002 Kirk McKusick <mckusick@FreeBSD.org>

Create a new 32-bit fs_flags word in the superblock. Add code to move
the old 8-bit fs_old_flags to the new location the first time that the
filesystem is mounted by a new kernel. One of the unused flags in
fs_old_flags is used to indicate that the flags have been moved.
Leave the fs_old_flags word intact so that it will work properly if
used on an old kernel.

Change the fs_sblockloc superblock location field to be in units
of bytes instead of in units of filesystem fragments. The old units
did not work properly when the fragment size exceeeded the superblock
size (8192). Update old fs_sblockloc values at the same time that
the flags are moved.

Suggested by: BOUWSMA Barry <freebsd-misuser@netscum.dyndns.dk>
Sponsored by: DARPA & NAI Labs.


# 89fdc4e1 24-Sep-2002 Mike Barcroft <mike@FreeBSD.org>

Use the standardized CHAR_BIT constant instead of NBBY in userland.


# ce66ddb7 21-Aug-2002 Tom Rhodes <trhodes@FreeBSD.org>

s/filesystem/file system/g as discussed on -developers


# 1c85e6a3 21-Jun-2002 Kirk McKusick <mckusick@FreeBSD.org>

This commit adds basic support for the UFS2 filesystem. The UFS2
filesystem expands the inode to 256 bytes to make space for 64-bit
block pointers. It also adds a file-creation time field, an ability
to use jumbo blocks per inode to allow extent like pointer density,
and space for extended attributes (up to twice the filesystem block
size worth of attributes, e.g., on a 16K filesystem, there is space
for 32K of attributes). UFS2 fully supports and runs existing UFS1
filesystems. New filesystems built using newfs can be built in either
UFS1 or UFS2 format using the -O option. In this commit UFS1 is
the default format, so if you want to build UFS2 format filesystems,
you must specify -O 2. This default will be changed to UFS2 when
UFS2 proves itself to be stable. In this commit the boot code for
reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c)
as there is insufficient space in the boot block. Once the size of the
boot block is increased, this code can be defined.

Things to note: the definition of SBSIZE has changed to SBLOCKSIZE.
The header file <ufs/ufs/dinode.h> must be included before
<ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and
ufs_lbn_t.

Still TODO:
Verify that the first level bootstraps work for all the architectures.
Convert the utility ffsinfo to understand UFS2 and test growfs.
Add support for the extended attribute storage. Update soft updates
to ensure integrity of extended attribute storage. Switch the
current extended attribute interfaces to use the extended attribute
storage. Add the extent like functionality (framework is there,
but is currently never used).

Sponsored by: DARPA & NAI Labs.
Reviewed by: Poul-Henning Kamp <phk@freebsd.org>


# 3468b317 15-May-2002 Tom Rhodes <trhodes@FreeBSD.org>

more file system > filesystem


# 3d438ad6 20-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove 'register' keyword.
It does not help modern compilers, and some may take some hit from it.
(I also found several functions that listed *every* of its 10 local vars with
"register" -- just how many free registers do people think machines have?)


# 8af1452c 13-Aug-2001 Ruslan Ermilov <ru@FreeBSD.org>

Removed duplicate VCS ID tags, as per style(9).


# 5455cc1a 08-Aug-2001 Christoph Herrmann <chm@FreeBSD.org>

fixing a bug in test mode (growfs -N)

Submitted by: Chris Boltwood <chris@hiendmedia.com>
Reviewed by: tomsoft
MFC after: 5 days


# adcaff07 07-Jun-2001 Thomas-Henning von Kamptz <tomsoft@FreeBSD.org>

cleanup to get rid of most warnings on alpha
and yes now it also works on alpha

Reviewed by: chm
MFC after: 3 weeks


# 25e34650 05-Jun-2001 Thomas-Henning von Kamptz <tomsoft@FreeBSD.org>

fix a bug of a only partitally initialization which could result
in an unclean filesystem after growing by a large amount of cylinder
groups

Reviewed by: chm


# 4020c5bc 12-Dec-2000 Thomas-Henning von Kamptz <tomsoft@FreeBSD.org>

corrected spelling mistakes in comments
check a couple of mallocs
usage of errx
linebreaks of DBG_ macros,
correcting the usage of nroff macros

Submitted by: grog, charnier
Reviewed by: chm


# 3d500078 09-Dec-2000 Thomas-Henning von Kamptz <tomsoft@FreeBSD.org>

added growfs(8) including ffsinfo(8) to the freebsd base system

Reviewed by: grog