contrib/file: Fix the DragonFly ABI note version decoding
The ABI note stores __DragonFly_version, which is encoded as
major * 100000 + minor * 100 + rev. file(1) decoded the minor and bump
fields as major * 100000 + minor * 10000 + bump, so a 6.5.22 binary was
reported as "for DragonFly 6.0.522".
Fix the version decoding, similar to my previous patch to readelf(1) in
commit c0de80f6b41e2add4684d84fa92d7abb0fc9b656.
Before:
% file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libexec/ld-elf.so.2, for DragonFly 6.0.522, stripped
After:
% file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libexec/ld-elf.so.2, for DragonFly 6.5.22, stripped
testcases: Add regression tests for open() and openat()
With the previous open(2) fixes, all the tests pass:
vfs/dotdot testcase:
```
--- open() of dot/dotdot ---
ok: open(.) O_WRONLY|O_CREAT Is a directory (21)
ok: open(.) O_RDWR|O_CREAT Is a directory (21)
ok: open(.) O_RDONLY|O_CREAT Is a directory (21)
ok: open(.) O_WRONLY Is a directory (21)
ok: open(.) O_RDONLY OK
ok: open(.) O_WRONLY|O_TRUNC|O_CREAT Is a directory (21)
ok: open(.) O_WRONLY|O_CREAT|O_EXCL File exists (17)
ok: open(.) O_RDONLY|O_CREAT|O_EXCL File exists (17)
ok: open(.) O_RDONLY|O_CREAT|O_DIRECTORY Is a directory (21)
ok: open(..) O_WRONLY|O_CREAT Is a directory (21)
ok: open(..) O_RDONLY|O_CREAT Is a directory (21)
ok: open(..) O_WRONLY|O_CREAT|O_EXCL File exists (17)
[54 lines not shown]
open(2): Fix open(O_CREAT) to correctly return EISDIR
* Skip "." and ".." terminating paths in nlookup() for NLC_OPEN, so
they'll be handled in vn_open() to correctly return EISDIR instead of
EEXIST.
* Let open("/", O_CREAT) through in nlookup(), so this case can be
handled in vn_open() to return EISDIR.
* Fix vn_open() to return EISDIR if the target is a directory and is
opened with O_CREAT or O_RDWR/O_TRUNC.
* Fix vn_open() to handle the mount-point target normally when the
target already exists, instead of simply return EINVAL.
Bug: https://bugs.dragonflybsd.org/issues/3282
Tested-by: pjdfstest (https://github.com/pjd/pjdfstest)
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
rename(2): Fix permission check on cross-parent directory rename
Cross-parent directory rename did not require write permission on the
source directory, although its ".." entry is modified. POSIX requires
EACCES there. UFS already performs this check, but HAMMER2 and tmpfs
don't. Fix the bug by adding a generic check in kern_rename().
To reproduce the bug:
```
$ d=$(mktemp -d)
$ mkdir -p ${d}/p1/dir1 ${d}/p2
$ touch ${d}/p1/dir1/file1
$ chmod 0444 ${d}/p1/dir1
$ mv ${d}/p1/dir1 ${d}/p2
```
Before the fix, the last "mv" command succeeded; after the fix, it would
fail with "Permission denied" (EACCES).
[2 lines not shown]
stat(2): Fix 'st_rdev' to report correct (major, minor) numbers
* Fix vn_stat() to fill 'st_rdev' with makeudev() for character and
block devices that have a valid device number.
* In addition, fix devfs_vop_getattr() to fill 'va_rmajor' in addition to
'va_rminor', and fix hammer2_vop_getattr() to fill 'va_rmajor' and
'va_rminor'.
Before the fix, a manually mknod()-created device would have a 'st_rdev'
of NODEV (i.e., -1), for example:
```
$ ~/mknod /tmp/dev-1-2 1 2
dev: 0x102 (major=1, minor=2)
$ ls -l /tmp/dev-1-2
crw------- 1 root wheel 255, 0xffff00ff Nov 7 18:34 dev-1-2
$ stat -f '%Z' /tmp/dev-1-2
255,4294902015
```
[12 lines not shown]
unlink(2): Fail with EPERM when trying to unlink a directory
As specified by POSIX and documented in the unlink(2) man page,
unlinking a directory fails with EPERM instead of EISDIR. Fix
kern_unlink() to return EPERM when trying to unlink a directory.
Found-by: pjdfstest (https://github.com/pjd/pjdfstest)
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
pc64: Fix std_copyinstr() to correctly return ENAMETOOLONG
The too-long branch previously compared the destination pointer (%rsi)
against VM_MAX_USER_ADDRESS instead of the source pointer (%rdi). The
destination is kernel memory, so it would always take the EFAULT path
instead of returning the correct ENAMETOOLONG.
Found-by: pjdfstest (https://github.com/pjd/pjdfstest)
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
cc120: Use FLAGS.gcc.o to clean up drivers' Makefiles
The macros defined in CFLAGS are only required by gcc.cc, so define them
in CFLAGS.gcc.o and move to drivers/Makefile.inc, and thus clean up the
makefiles of each driver.
While there, remove the unused "Makefile.cco" include from c++/Makefile.
cc120: Fix -Wmissing-include-dirs warnings in cc_tools
cc_tools is built *before* support-libs, so some of include dirs for
support-libs can be missing, causing the following warnings:
```
cc1plus: warning: /usr/obj/usr/src/gnu/usr.bin/cc120/cc_tools/libcpp/../../support-libs/libdecnumber: No such file or directory [-Wmissing-include-dirs]
```
Fix the warnings by introducing GCC_NO_INCS to not include all the -I
directories.
cc120: Extract {PREPROCESSOR,DRIVER}_DEFINES from dragonfly-native.h
Refactor dragonfly-native.h to create {PREPROCESSOR,DRIVER}_DEFINES
make variables for use in libbackend and drivers. These two variables
are also defined in GCC's own makefile.
PREPROCESSOR_DEFINES is only used by cppdefault.cc, and DRIVER_DEFINES
is used by gcc.cc and gcc-ar.cc (so applies to gcc-ar, gcc-nm and
gcc-ranlib LTO wrappers).
The intention is to make some defines in DRIVER_DEFINES available to
gcc-ar.cc, which doesn't include "tm.h" to obtain "dragonfly-native.h".
So this is a required change for the upcoming gcc-{ar,nm,ranlib} LTO
wrappers.
cc120: Clean up dragonfly-native.h
* Add file-level description.
* Remove unnecessary MD_EXEC_PREFIX and MD_EXEC_PREFIX*, which are
defaulted to be empty strings by gcc.cc.
* Add comment for STARTFILE_PREFIX_SPEC.
* Set a dummy value for STANDARD_STARTFILE_PREFIX and remove
STANDARD_STARTFILE_PREFIX_{1,2}, which are unused when
STARTFILE_PREFIX_SPEC is defined.
vendor/GCC120: Backport one lto-dump fix
lto-dump: Do not print output file
Right now the following is printed:
lto-dump
.file "<artificial>"
.ident "GCC: (GNU) 13.0.0 20220707 (experimental)"
.section .note.GNU-stack,"",@progbits
After the patch we print -help and do not emit any assembly output:
lto-dump
Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...
LTO dump tool command line options.
-list [options] Dump the symbol list.
[5 lines not shown]
contrib/gcc-12: Patch gcc-ar.cc to find the liblto_plugin.so
We place all the tools and the LTO plugin in a common location:
/usr/libexec/gcc120, so need to patch gcc-ar.cc to search this location,
similar to the patch to gcc.cc.
vendor/GCC120: Add back gcc-ar.cc and lto-dump.1
* gcc-ar.cc is required to build gcc-{ar,nm,ranlib} wrappers for LTO
function.
* lto-dump.1 is the man page for the lto-dump utility to be installed.
terminfo: Remove unused terminfo.tmp and run_tic.sed from Makefile
* The generated run_tic.sed is empty, so the modified terminfo.tmp is
identical to the original terminfo.src.
* The generated terminfo.tmp is not actually used by run_tic.sh to build
the entries.
So remove both to clean up. while there, also remove the unnecessary
NOMAN.
terminfo: Improve the Makefile for entries installation
* Use FILESGROUPS and related macros from <bsd.files.mk> to install the
entries, replacing the manual explicit "install" target.
* Use the default SHAREMODE (i.e., 444) instead of the custom 644 mode
for installed entries.
* Use the more conventional <bsd.prog.mk> instead of <bsd.lib.mk>, as
used by share/termcap, share/tabset, etc.
terminfo: Fix entries compilation to output to ${.OBJDIR}
Fix the ${ticdir} and @TERMINFO@ to point to paths in ${.OBJDIR}, so
that the intermediate outputs and compiled entries are all located in
${.OBJDIR}.
In addition, ignore ${DESTDIR} for `run_tic.sh` so the entries output
directory is unaffected during the buildworld, which sets a DESTDIR.
While there, clean up the `run_tic.sh` target to specify the prereq and
to remove the unnecessary `cat` command.
terminfo: Auto generate entries list from the source terminfo.src
Replace the hand-crafted entries list in Makefile.entries with an
auto-generated one by an awk script, so that it becomes future-proof.
The auto-generated list contains 2780 entries, adding 160 new entries
over the previous stale list, which contained 2620 entries. In
particular, the new entries include alacritty, kitty, dvtm, etc.
libc: Move thread symbols from gen/Symbol.map to thread/Symbol.map
Commit 28e770f9356419201058747986287acae231f334 merged libthread_xu into
libc, and commit aaef2979773f2bfc0f661b17be90d5e5b82b505b moved the
libthread_xu source to libc/thread. This commit completes the merge by
moving the thread symbols that implemented in libc/thread from
libc/gen/Symbol.map to libc/thread/Symbol.map, so that the Symbol.map
keeps in sync with the source.
kernel - Fix in6_pcbsetlport() panic
* An assertion is issued after lport is modulo-incremented but
before checking to see if the loop has exhausted.
This can result in a field overflow causing the assertion to
fail.
* Fix by moving the assertion to the correct place.