Repository navigation
fix: Use extattr API to list extended attributes on FreeBSD - #2926
stanleys12 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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. |
|
Thanks, no rush. |
|
@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. |
|
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:
|
|
@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: 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 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. |
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 fileshows up as- testin the file's provider information?