39.1. file-5.48
Identify a file by its content, and the magic database behind it
| Version | 5.48, release 1 |
| Shelf | base — The minimal userland and system daemons that every KDOS image boots with |
| Phase | 30_foundation (Build Foundation), 8 of 127 in build order |
| Licence | BSD-2-Clause |
| Homepage | https://www.darwinsys.com/file/ |
| Build time | 0.2 SBU |
| Installed size | 10.6 MiB in 11 files |
| Recipe | ports/core/base/file/kpkgbuild |
About
file names what a file is from its contents, using the magic database in /usr/share/misc/magic.mgc; libmagic is the same engine as a library.
It is one of the first ports 30_foundation installs, ahead of every shelf, because builds run it without naming it: on x86-64, libtool’s configure runs file on a test object to learn whether the compiler produces 32-bit or 64-bit code, and picks the linker emulation from the answer. On the finished system it is what the less input filter asks what a file is (file -L -s -b --mime, see Shell environment), and nano, yazi, recoll and e2fsprogs are among the ports that depend on it.
Why it is in KDOS
The comment above the 24 ports from fortify-headers to musl-utils in script/phases/30_foundation/packages.txt is quoted in The build foundation.
Sources
file-5.48.tar.gz(2.6 MiB)
sha256ed14656883b23a364b4057c05595d93252da9bc473d30106519519d0da141283
upstream: https://astron.com/pub/file/file-5.48.tar.gz
archive copy: sources-1/base--file-5.48.tar.gz
Dependencies
Depends on: zlib, bzip2, xz, zstd, libseccomp.
Required by (14): android-file-transfer, e2fsprogs, foomatic-db-engine, imhex, lesspipe, lyx, nano, openjdk, recoll, rizin, sox, viking, yara, yazi.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/30_foundation/phase.env && kpkg install file'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base/file.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/base/file
echo 'ed14656883b23a364b4057c05595d93252da9bc473d30106519519d0da141283 file-5.48.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/file
SRC=$SRC_ROOT/file-5.48
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf file-5.48.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
./configure --prefix=/usr --sysconfdir=/etc --disable-static \
--enable-zlib --enable-bzlib --enable-xzlib --enable-zstdlib \
--enable-libseccomp --enable-landlock \
--disable-lzlib --disable-lrziplib
make
make DESTDIR=$PKG install
The switches, and why each is set:
--enable-zlib,--enable-bzlib,--enable-xzlib,--enable-zstdlib— Letfile -zlook inside gzip, bzip2, xz and zstd compressed files through the libraries, in-process, instead of running an external decompressor. Named, a missing library stops configure rather than dropping the format.--enable-libseccomp— Confinefileto the system calls it needs with a seccomp filter, through libseccomp. The filter is on by default whenfileruns;file -Sturns it off.--enable-landlock— Also confine it with Landlock, the kernel’s file system sandbox, which the KDOS kernel has (CONFIG_SECURITY_LANDLOCK=yinkdos.config).--disable-lzlib,--disable-lrziplib— No lzip or lrzip decompression through a library. Neitherlzlibnorliblrzipis in the tree; the lzip port is the program alone.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/file, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf file-5.48-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/file, and runs the triggers its paths call for.
Contents
Installed programs: file.
Installed libraries: libmagic.so.
Installed directories: /usr/share/licenses/file, /usr/share/misc.
Short descriptions
file |
determine file type |
libmagic.pc |
Magic number recognition library |
Notes
The sandbox and -z meet in one place: with the seccomp filter on, file can decompress only through the linked libraries, because the filter forbids running another program. A compressed format with no library here needs file -S -z to be looked into.