This file provides guidance to AI coding agents working on this repository.
util-linux is a collection of essential Linux system utilities and libraries (libmount, libblkid, libsmartcols, libfdisk, libuuid). The project follows Linux kernel coding conventions and workflows.
Only human beings can be credited in commit messages. Do not include
Co-Developed-By, Co-Authored-By, or similar attribution for AI models.
Commits should include a Signed-off-by line (git commit -s).
Always consult these files as needed:
Documentation/HOWTO-BUILDING.md— how to compile the project, build system internalsDocumentation/HOWTO-CONTRIBUTING.md— contribution guidelines, patch and PR workflowDocumentation/HOWTO-HACKING.md— coding details: usage functions, man pages, debuggingDocumentation/HOWTO-TESTING.md— regression test framework, environment variables
The coding style is based on the Linux kernel coding style.
- Do NOT use
{ }braces for single-line if/else blocks. - Do not use
elseafter non-returning functions (err(), errx(), exit(), ...). - Avoid
if ((rc = func()) != 0)— split into separate assignment and comparison:rc = func(); if (rc != 0)
- Use
printf()consistently, notfprintf(stdout, ...). - Follow existing naming and coding conventions in each file.
- Use EditorConfig (
.editorconfigin the project root) for whitespace settings.
- Boolean functions return true/false — name with
_is_,_has_,_can_. - Iterator
_next_functions: 0 = success, <0 = error, 1 = end of list. - Error-returning functions: negative errno or NULL.
- Check existing similar functions in libsmartcols, libmount for API consistency.
- For non-library code, use
include/xalloc.hwrappers (xmalloc(),xcalloc(),xstrdup(), etc.) — these always succeed or terminate witherr(). - In libraries, check ownership semantics: does the function take ownership or copy?
- Trace every
malloc/calloc/strdup/asprintfto its correspondingfree(). list_del()must also free the element memory, not just unlink.- Watch for missing
free()on error/early-return paths.
- Use
Fixes:when the commit resolves an issue. - Use
Addresses:when the commit only partly implements requested changes. - Always use complete GitHub URLs, for example:
Fixes: https://github.com/util-linux/util-linux/issues/NNN - Do not commit generated files (po/, po-man/, ./configure, ...).
The project supports two build systems: autotools and meson.
Autotools:
- Build:
./autogen.sh && ./configure && make - Run tests:
make checkorcd tests && ./run.sh - Selective build:
./configure --disable-all-programs --enable-<name>
Meson:
- Build:
meson setup build && meson compile -C build - Run tests:
meson test -C build
Features should include corresponding tests.