Commit Graph

290 Commits

Author SHA1 Message Date
Simon J. Gerraty
188bf8876f Build host tools on non-FreeBSD host with DIRDEPS_BUILD
Add Makefile.depend.options to libnetbsd, mkimg and makefs
to ensure libegacy is build if needed.

targets/pseudo/stage/Makefile avoid the need for mtree
the staging process creates target dirs as needed anyway.

Reviewed by:	stevek
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D39757
2023-04-22 13:13:22 -07:00
Ed Maste
dd9059b3e9 makefs: set cd9660 Rock Ridge timestamps for . and ..
DOT and DOTDOT entries have special handling, and previously only Rock
Ridge PX (POSIX attributes) entries were attached.  Add TF (timestamp)
entries as well.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39662
2023-04-20 12:20:56 -04:00
Ed Maste
79ead08497 makefs: remove unused variable
Reported by:	Clang
Sponsored by:	The FreeBSD Foundation
2023-04-17 08:22:12 -04:00
Ed Maste
10854bf517 makefs: use unsigned and %u for rock_ridge_move_count
For diff reduction against NetBSD's makefs.  Based on NetBSD git mirror
commit 00991aee8248.

With this change our makefs cd9660 support should be in sync up to
NetBSD commit bdae6c9dc792 ("makefs(8): Nix trailing whitespace.").

Sponsored by:	The FreeBSD Foundation
2023-04-17 08:21:28 -04:00
Ed Maste
e5551216d8 makefs: call brelse from bread
This matches NetBSD and rationalizes makefs with the kernel API.

This reverts commit 370e009188.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
Obtained from:	NetBSD 0a62dad69f62, 0c4125e1a19f, cb6a5a3575fd
Differential Revision:	https://reviews.freebsd.org/D39070
2023-04-16 15:45:17 -04:00
Ed Maste
c753f49f70 makefs: remove unused cd9660 options
Makefs defined "follow-symlinks" and "help" options, but they did
nothing.  Remove them.

Obtained from:	OpenBSD a8f1645688c2
Sponsored by:	The FreeBSD Foundation
2023-04-16 09:38:02 -04:00
Ed Maste
af7624ed31 makefs: use %s and __func__ in printf messages
For diff reduction against NetBSD.

Obtained from:	NetBSD 0c4125e1a19f
Sponsored by:	The FreeBSD Foundation
2023-04-11 11:21:36 -04:00
Ed Maste
22db5e5d03 makefs: set the validation entry system type
Obtained from:	NetBSD c3cb4dcc9c43
Sponsored by:	The FreeBSD Foundation
2023-04-10 19:07:14 -04:00
Ed Maste
1d1ffa2efd makefs: use size_t or ssize_t where appropriate
Obtained from:	NetBSD af7bc97830ac
2023-04-10 18:50:27 -04:00
Ed Maste
c02e6ca7c2 makefs: simplify filename conversion handling
Obtained from:	OpenBSD 4095a2e01d18
Sponsored by:	The FreeBSD Foundation
2023-04-10 12:03:06 -04:00
Ed Maste
d73acb32d3 makefs: remove some unused cd9660 types and defines
Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation
2023-04-10 11:15:34 -04:00
Ed Maste
7bc4ccf3ae makefs: avoid uninitialized memory in root directory date
Move date setting into cd9660_populate_iso_dir_record so there is no
path that leaves it unset.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39258
2023-04-06 13:47:35 -04:00
Christos Margiolis
f21faa67ab makefs(8): do not print comma after the last super-block
Reviewed by:	markj, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39430
2023-04-05 18:25:19 -04:00
Ed Maste
2f11df6337 makefs: remove CD9660MAXPATH #define
It was used only in constructing the host path that contains file
content, which is not related to anything CD9660-specific.  PATH_MAX is
the appropriate limit.  See OpenBSD commit 299d8950f319.

Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation
2023-04-05 14:05:49 -04:00
Ed Maste
c6ed8694ac makefs: improve some cd9660 error messages
Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation
2023-03-31 10:03:05 -04:00
Ed Maste
f0bef3d20e makefs: #define Apple Partition bits
NetBSD defines these in sys/bootblock.h, which we don't have.  Add local
defintions in cd9660_eltorito.c (as OpenBSD did) to reduce diffs between
the three makefs implementations.

Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation
2023-03-30 18:27:30 -04:00
Ed Maste
efe6a1574e makefs: correct "filname" typo
Obtained from:	NetBSD cd9660.c r1.58
2023-03-30 12:21:26 -04:00
Ed Maste
52c68e1625 makefs: Whitespace cleanup to sync with NetBSD 2023-03-30 11:45:13 -04:00
Ed Maste
45e405603b makefs: do not pass mode to open() call lacking O_CREAT
Obtained from:	OpenBSD ffs.c 1.35
2023-03-30 09:20:00 -04:00
Ed Maste
cc4adc4c4e makefs: remove vestigial '?' cases from top-level getopt(3) loop
getopt(3) returns '?' when it encounters a flag not present in the in
the optstring or if a flag is missing its option argument.  We can
handle this case with the "default" failure case with no loss of
legibility.

Obtained from:	OpenBSD makefs.c 1.22
2023-03-30 09:20:00 -04:00
Ed Maste
1fb7d2cf99 makefs: spelling
Obtained from:	OpenBSD msdosfs_fat.c 1.7
2023-03-29 21:48:14 -04:00
Ed Maste
978013a094 makefs: emit NM records for all directory entries
We previously attempted to emit Rock Ridge NM records only when the name
represented by the Rock Ridge extensions would actually differ. We would
omit the record for an all-upper-case directory name, however Linux (and
perhaps other operating systems) map names with no NM record to
lowercase.

This affected only directories, as file names have an implicit ";1"
version number appended and thus always differ.  To solve, just emit NM
records for all entries other than DOT and DOTDOT .

We could continue to omit the NM record for directories that would avoid
mapping (for example, one named 1234.567) but this does not seem worth
the complexity.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net
Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39258
2023-03-25 09:25:18 -04:00
Ed Maste
9f2a525360 makefs: correct El Torito bood record
The boot catalog pointer is a DWord, but we previously populated it via
cd9660_bothendian_dword which overwrote four unused bytes following it.
See El Torito 1.0 (1995) Figure 7 for details.

PR:		203531
Reported by:	Coverity Scan
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	kevans
CID:		977470
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39231
2023-03-23 17:56:33 -04:00
Ed Maste
c3ec19359e makefs: correct iso9660 Rock Ridge NM values
These are not actually used by makefs (yet), but ought to match the
spec.

See RRIP 4.1.4 Description of the "NM" System Use Entry for details.

PR:		203531
Sponsored by:	The FreeBSD Foundation
2023-03-23 08:36:15 -04:00
Ed Maste
c65c969bd5 makefs: correct iso9660 Rock Ridge TF timestamps
The bit definitions for the TF_* timestamp bits (TF_MODIFY, etc.) were
incorrect, and timestamps were written in the wrong order.

See RRIP 4.1.6 Description of the "TF" System Use Entry for details.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	jrtc27, kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39221
2023-03-23 07:11:58 -04:00
Ed Maste
bc33c99234 makefs: do not call brelse if bread returns an error
If bread returns an error there is no bp to brelse.  One of these
changes was taken from NetBSD commit 0a62dad69f62 ("This works well
enough to populate..."), the rest were found by looking for the same
pattern.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39069
2023-03-13 22:39:09 -04:00
Warner Losh
370e009188 makefs: make msdos creation go fast
Add missing brelse(bp). Without it the cache grows and we have a n^2
lookup.  I'm not entirely sure why we read the block before we write it
back out, since the only side effect of that is to allocate memory,
clear the memory, read it in from disk, throw it away with the contents
of the file being written out. We likely should just do a getblk() here
instead, but even with all that, this takes the time it takes to create
a 150MB msdos fs image down from 5 minutes to 30 seconds.

Old: 317.663u 0.685s 5:18.34 100.0%	198+360k 0+19io 1009pf+0w
New: 7.330u 23.841s 0:31.17 100.0%	198+360k 0+250522io 4pf+0w

See code review for how we got this. tl;dr: netbsd move brelse
into bwrite and we picked up msdos code after that, but not the
move. That change should be picked up later.

Sponsored by:		Netflix
Reviewed by:		emaste
MFC After:		1 day (13.2 is coming fast)
Differential Revision:	https://reviews.freebsd.org/D39025
2023-03-13 14:38:36 -06:00
Brooks Davis
6e011d1503 makefs: don't needlessly require directories to exist
If a type=dir entry exists and all contents are directories, files
added with contents=, or symlinks with link= attributes then it doesn't
need to exist.  Just let openat fail in that case.  It's conceivable
this will make debugging some cases weird, but it's sufficent to handle
the way we add /root/.ssh in CheriBSD VM images.

This is a recommit of 794154149f with
bugfixes.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38029
2023-01-12 19:16:14 +00:00
Brooks Davis
5e5baba880 Revert "makefs: don't needlessly require directories to exist"
I pushed prematurely and this version is broken.

This reverts commit 794154149f.
2023-01-12 18:21:27 +00:00
Brooks Davis
794154149f makefs: don't needlessly require directories to exist
If a type=dir entry exists and all contents are directories, files
added with contents=, or symlinks with link= attributes then it doesn't
need to exist.  Just let openat fail in that case.  It's conceivable
this will make debugging some cases weird, but it's sufficent to handle
the way we add /root/.ssh in CheriBSD VM images.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38029
2023-01-12 18:19:14 +00:00
Brooks Davis
b78d5b4241 makefs: handle mtree link= for ZFS
When a link target is specified use it rather than attempting to read
a potentially non-existant file.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38028
2023-01-12 18:18:45 +00:00
Brooks Davis
aac389a347 makefs: handle mtree contents= in zfs
When a source path is provided use it rather than constructing one.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38027
2023-01-12 18:18:24 +00:00
Mark Johnston
a9e7a44c24 makefs: Add some validation of ZFS pool names
Reported by:	imp
2022-12-16 10:30:58 -05:00
John Baldwin
abb9a940bb makefs: Ignore some sign comparison warnings from GCC.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D37470
2022-11-23 10:38:29 -08:00
John Baldwin
82ac811efa makefs zfs: Disable -Wunused-function for GCC as well.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D37469
2022-11-23 10:35:30 -08:00
John Baldwin
9821e24441 makefs zfs: Use signed values for both results of ?:.
Reported by:	GCC -Wsign-compare
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D37468
2022-11-23 10:35:14 -08:00
Mark Johnston
752ba1004a makefs: Fix handling of inherited mountpoints
Commit d7eec79b70 overlooked the fact that
nvlist_find(DATA_TYPE_STRING) does not provide a nul-terminated string.
Fix the leak a different way.

Fixes:	d7eec79b70 ("makefs: Plug a memory leak")
2022-10-28 17:00:22 -04:00
Mark Johnston
cba2fa7c5b makefs: Add a cast to placate static analyzers
"prefixlen" will always be smaller than 32 but adding a cast is
harmless.

Reported by:	Coverity
2022-10-04 13:05:54 -04:00
Mark Johnston
d7eec79b70 makefs: Plug a memory leak
nvlist_find_string() would return a copy of the found value, but callers
assumed they would have to make their own copy.  It's simpler to change
nvlist_find_string() than it is to change callers, so do that.

Reported by:	Coverity
2022-10-04 13:05:54 -04:00
Ed Maste
06a400d76b makefs: whitespace cleanup (remove space before tab)
MFC after:	1 week
2022-09-20 10:26:24 -04:00
Gordon Bergling
5f285d5537 cd9660(5): Correct a typo in a source code comment
- s/byes/bytes/

MFC after:	3 days
2022-09-04 18:20:09 +02:00
Mark Johnston
09a2fce092 makefs tests: Do not run ZFS tests in parallel
makefs-created pools always have the same GUID and thus cannot be
imported simultaneously.

Reported by:	olivier
2022-08-29 12:54:25 -04:00
Mark Johnston
a3b6b3ac4d makefs tests: Do not install ZFS tests if WITHOUT_ZFS is defined 2022-08-29 12:50:51 -04:00
Mark Johnston
575ca2c265 makefs: Remove some redundant initializations
No functional change intended.
2022-08-29 12:50:51 -04:00
Jessica Clarke
c6890399fc makefs: Fix issues building as a cross-tool on non-FreeBSD
This adds missing includes, uses the standard dirent.h rather than the
BSD-specific sys/dirent.h subset (which works on macOS but not Linux)
and works around Linux's lack of st_birthtim.

This allows usr.sbin/makefs to be added to LOCAL_XTOOL_DIRS again on
macOS and Linux so that disk images can be cross-built.

Reviewed by:	markj
Fixes:		240afd8c1f ("makefs: Add ZFS support")
Differential Revision:	https://reviews.freebsd.org/D36135
2022-08-18 02:46:28 +01:00
Jessica Clarke
b0ce7dfc5e makefs: Fix 32-bit issues in ZFS time attributes setting
Currently the code copies a struct timespec's raw bits as a pair of
uint64_t. On 64-bit systems this has the same representation, but on
32-bit issues there are two issues:

1. tv_sec is a time_t which is 32-bit on i386 specifically
2. tv_nsec is a long not a 64-bit integer

On i386, this means the assertion should fire as the size doesn't match.
On other 32-bit systems there are 4 bytes of padding after tv_nsec,
which in practice are probably 0, as this data is ultimately coming from
the kernel, so it's deterministic (though the padding bytes are not
required to be preserved by the compiler, so are strictly unspecified).
However, on 32-bit big-endian systems, the padding bytes are in the
wrong half to be harmless, resulting in the nanoseconds being multiplied
by 2^32.

Fix this all by marshalling via a real uint64_t pair like is done by the
real ZFS_TIME_ENCODE.

Reviewed by:	markj
Fixes:		240afd8c1f ("makefs: Add ZFS support")
Differential Revision:	https://reviews.freebsd.org/D36131
2022-08-18 02:46:27 +01:00
Mark Johnston
8502144d7a makefs tests: Add test cases for handling of multiple staging dirs
Sponsored by:	The FreeBSD Foundation
2022-08-17 17:28:01 -04:00
Mark Johnston
582ce32ff8 makefs tests: Whitespace fixes
Sponsored by:	The FreeBSD Foundation
2022-08-17 17:28:00 -04:00
Mark Johnston
8eca320798 makefs: Handle multiple staging directories when creating ZFS pools
The fsnode tree traversal routines used in ZFS mode assume that all
children of a (directory) fsnode can be accessed using a directory fd
for the parent and the child name.  This is true when populating the
image using an mtree manifest or from a single staging directory, but
doesn't work when multiple staging directories are specified.

Change the traversal routines to use absolute path lookups when an mtree
manifest is not in use.  This isn't ideal, but it's the simplest way to
fix the problem.

Reported by:	imp
Sponsored by:	The FreeBSD Foundation
2022-08-17 17:28:00 -04:00
Mark Johnston
c4d26f027b makefs: Style
Reported by:	rpokala
Fixes:		187084dddd ("makefs: Align the block buffer used in ZFS mode")
Sponsored by:	The FreeBSD Foundation
2022-08-16 14:21:44 -04:00