Add support for name_to_handle_at(2), open_by_handle_at(2) on Linux #1517
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for
{name_to,open_by}_handle_at(2)
on Linux.I have a Rust application that wants to use these syscalls and it would be really nice to use a standard library rather than roll my own wrappers.
I would consider this an RFC at this point because I do have a few open questions about the API:
handle_bytes
andhandle_type
fields, even though they are exposed in the C struct definition. (Thehandle_bytes
field does need to be accessed to size the handle correctly, but that is handled by this library, so user apps need not worry about that.) So this API makesstruct FileHandle
entirely opaque. If I'm wrong and there is a valid reason for a user app to access those fields, I think getter/setters could be added in the future without breaking the API...BorrowedFileHandle
type that contains&[u8]
instead ofBox<[u8]>
-- I don't immediately have a use case for it, so I didn't implement it, but putting it out there in case the idea does seem usefulname_to_handle_at(2)
is interesting in that its signature is different depending on the flagAT_HANDLE_MNT_ID_UNIQUE
-- themount_id
parameter is either anint *
, oru64 *
. I thought of two ways to handle this in rust: create a separatename_to_handle_at_unique()
function for theu64
variant, or create an Enum so that one function can return both kinds of mount_id. I went with the latter, but I could see an argument for the former being better. Thoughts?I want to be able to store a filehandle and/or send it over the network, and then use it again when I get it back, so that is the reason for adding public
from_raw()
andinto_raw()
methods ontostruct FileHandle
.Another question is how to test this -- since open_by_handle_at(2) requires CAP_DAC_READ_SEARCH privilege, programs that use it typically run as root. Is there a precedent for how to write unit/integration tests that require root in Rustix? (I have an external test program I ran with sudo to test this, I can share it if that would be helpful.)