Skip to content

fix: Use extattr API to list extended attributes on FreeBSD - #2926

Open
stanleys12 wants to merge 1 commit into
WerWolv:masterfrom
stanleys12:osc/fix-freebsd-build-use-extattr-api-instea-01a3
Open

stanleys12 wants to merge 1 commit into
WerWolv:masterfrom
stanleys12:osc/fix-freebsd-build-use-extattr-api-instea-01a3

Conversation

@stanleys12

Copy link
Copy Markdown

Problem description

FreeBSD defines both OS_LINUX and OS_FREEBSD, so the xattr listing in the file provider calls ::listxattr. That doesn't exist there and the build fails. Related to #2776.

Implementation description

On OS_FREEBSD the file provider now calls extattr_list_file with EXTATTR_NAMESPACE_USER. FreeBSD returns each name as a length byte followed by that many characters, with no NUL terminators. I parse that format separately and stop if the buffer is truncated. Linux and macOS paths are unchanged.

Screenshots

None.

Additional things

I couldn't build or run this on FreeBSD. I only checked it by reading extattr(2). @samuelvenable, could you build this branch on FreeBSD and check that an attribute set with setextattr user test v file shows up as - test in the file's provider information?

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@samuelvenable

Copy link
Copy Markdown

I have somewhere I have to be soon, and I'll be gone the rest of the day. It is roughly 3:30PM for me right now in my timezone. Feel free to ping me tomorrow if I haven't done it by then.

@stanleys12

Copy link
Copy Markdown
Author

Thanks, no rush.

@samuelvenable

samuelvenable commented Oct 7, 2026 •

Copy link
Copy Markdown

@stanleys12 building your pr's fork and branch atm will let you know how it goes. in the meantime, i have no idea what this code does or how to confirm or deny it's working beyond whether it builds a binary successfully and runs without a segfault, bus error, or w/e. If I could have some idea of what to look for in knowing what to test in specific and hearing what the expected behavior is, that would be what I'd need to know before this will be ready for review by a comitter.

@samuelvenable

Copy link
Copy Markdown

Ok so apparently @WerWolv or someone else must've added some more Linux-spefic code that doesn't compile on FreeBSD, since the last time I tried compiling on FreeBSD, which wasn't even that long ago:

-- Found Backtrace: /usr/lib/libexecinfo.so
-- Could NOT find elfutils (missing: ELFUTILS_INCLUDE_DIR ELFUTILS_LIB_dw)
-- (set ELFUTILS_INSTALL_DIR, or install libdw-dev on a Debian-like system)
-- Backtrace enabled! Header: execinfo.h Library: /usr/lib/libexecinfo.so
-- Configuring done (5.8s)
-- Generating done (0.3s)
-- Build files have been written to: /home/freebsd/ImHex/build
freebsd@FreeBSD:~/ImHex/build $ ninja install
[79/707] Building C object lib/third_p...lfw/src/CMakeFiles/glfw.dir/wl_init.c.o
FAILED: [code=1] lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_init.c.o
/usr/bin/cc -DHAVE_MEMFD_CREATE -DIMHEX_ENABLE_UPDATER -DNDEBUG -DOS_FREEBSD -DOS_LINUX -DSYSTEM_PLUGINS_LOCATION="/usr/local/lib/imhex" -D_GLFW_WAYLAND -D_GLFW_X11 -I/home/freebsd/ImHex/lib/third_party/glfw/include -I/home/freebsd/ImHex/lib/third_party/glfw/src -I/home/freebsd/ImHex/build/lib/third_party/glfw/src -I/usr/local/include -I/usr/local/include/libepoll-shim -O3 -DNDEBUG -std=c99 -fPIC -Wall -MD -MT lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_init.c.o -MF lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_init.c.o.d -o lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_init.c.o -c /home/freebsd/ImHex/lib/third_party/glfw/src/wl_init.c
/home/freebsd/ImHex/lib/third_party/glfw/src/wl_init.c:33:10: fatal error: 'linux/input.h' file not found
33 | #include <linux/input.h>
| ^~~~~~~~~~~~~~~
1 error generated.
[80/707] Building C object lib/third_p...w/src/CMakeFiles/glfw.dir/wl_window.c.o
FAILED: [code=1] lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_window.c.o
/usr/bin/cc -DHAVE_MEMFD_CREATE -DIMHEX_ENABLE_UPDATER -DNDEBUG -DOS_FREEBSD -DOS_LINUX -DSYSTEM_PLUGINS_LOCATION="/usr/local/lib/imhex" -D_GLFW_WAYLAND -D_GLFW_X11 -I/home/freebsd/ImHex/lib/third_party/glfw/include -I/home/freebsd/ImHex/lib/third_party/glfw/src -I/home/freebsd/ImHex/build/lib/third_party/glfw/src -I/usr/local/include -I/usr/local/include/libepoll-shim -O3 -DNDEBUG -std=c99 -fPIC -Wall -MD -MT lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_window.c.o -MF lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_window.c.o.d -o lib/third_party/glfw/src/CMakeFiles/glfw.dir/wl_window.c.o -c /home/freebsd/ImHex/lib/third_party/glfw/src/wl_window.c
/home/freebsd/ImHex/lib/third_party/glfw/src/wl_window.c:45:10: fatal error: 'linux/input-event-codes.h' file not found
45 | #include <linux/input-event-codes.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[92/707] Building CXX object lib/exter...r/source/math_eval/math_evaluator.cpp.o
ninja: build stopped: subcommand failed.

@stanleys12

Copy link
Copy Markdown
Author

@samuelvenable thanks for taking the time to build it.

What this changes: when you open a file, ImHex lists its extended attributes in the file info. That's in FileProvider::getDataDescription() in plugins/builtin/source/content/providers/file_provider.cpp. FreeBSD builds define both OS_FREEBSD and OS_LINUX (you can see both in your compile line), so that code called listxattr(). FreeBSD doesn't have listxattr, so this file failed to compile there. With this change, FreeBSD calls extattr_list_file() with EXTATTR_NAMESPACE_USER instead. FreeBSD also returns the names in a different format from Linux/macOS: each name is one length byte followed by that many characters, not a NUL-separated list. So the change parses that format separately. Linux and macOS still use the old code.

To test it once you have a binary:

touch ./somefile
setextattr user testattr hello ./somefile
lsextattr user ./somefile

lsextattr should print testattr. Then open ./somefile in ImHex, open the Data Information view and run Analyze. In the "Data Source Information" section there should be an "Attributes (xatts)" row with - testattr. Hovering over the file's tab with Shift held shows the same table. On FreeBSD only the user namespace is read, so system-namespace attributes won't show up. A file with no user attributes just has no xatts row.

The GLFW errors are unrelated to this PR. It only touches file_provider.cpp. Those failures come from the bundled GLFW's Wayland backend (wl_init.c, wl_window.c), which includes Linux-only input headers. Your compile line shows both -D_GLFW_WAYLAND and -D_GLFW_X11, so both backends are being built. If you turn off GLFW's Wayland backend in the cmake configure and build X11 only, those files shouldn't be compiled. I haven't checked the exact option name in the GLFW fork ImHex bundles, so I don't want to guess it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants