feat(metadata): implement Windows xattrs via NTFS Alternate Data Streams (#1867)#3536
Merged
Conversation
af09a8d to
c8b5bcf
Compare
…ams (#1867) Add a Windows backend for the cross-platform xattr layer that maps each named extended attribute onto an NTFS Alternate Data Stream using the `path:streamname:$DATA` syntax. The four POSIX primitives are now backed by `FindFirstStreamW`/`FindNextStreamW` for listing, `CreateFileW` + `ReadFile`/`WriteFile` for read and write, and `DeleteFileW` for removal. Stream-name parsing strips the `:` prefix and `:$DATA` suffix returned by NTFS so the wire-format names match the Unix xattr names exposed by the existing `xattr` crate backend. Refactor the per-attribute primitives in `crates/metadata/src/xattr.rs` to take raw `&[u8]` names and dispatch to a platform backend module (`xattr_unix` or `xattr_windows`). The Unix backend continues to wrap the `xattr` crate; the new Windows backend lives in a separate file under the same `feature = "xattr"` gate so the cross-platform layer remains backend-agnostic. The public API (`read_xattrs_for_wire`, `sync_xattrs`, `apply_xattrs_from_list`) is unchanged and the upstream rsync namespace-filtering policy still applies on Linux. Unsafe FFI is contained in `xattr_windows.rs` with `#![allow(unsafe_code)]` matching the existing convention for platform wrappers in the metadata crate (alongside `acl_windows`, `ownership`, `id_lookup`). Resource management uses RAII wrappers around `FindClose` and `CloseHandle` so handles are released on every error path. Tests cover the stream-name parser, input validation in `stream_path_wide`, and a write/read/list/remove round-trip that gracefully skips when the test volume does not support ADS (e.g. FAT32 runners). Refs #1867
The Windows ADS xattr backend used `windows::Win32::Storage::FileSystem::{
ReadFile, WriteFile}`, which are gated behind the `Win32_System_IO`
feature in `windows = "0.62"`. Cross-compiling to
`x86_64-pc-windows-gnu` therefore failed with `no `ReadFile` /
`WriteFile` in `Win32::Storage::FileSystem``. `FindFirstStreamW`'s
`dwflags` argument also takes `Option<u32>`, but the call site passed a
bare `0`.
Replace the raw `ReadFile`/`WriteFile` calls with `std::fs::File`
constructed from the Win32 `HANDLE` via `FromRawHandle`, so the read
and write paths use stdlib I/O instead of FFI bindings that depend on
an additional `windows` crate feature. The `File` takes ownership of
the handle and closes it on drop, replacing the now-unused
`OwnedHandle` wrapper. Wrap the reserved-must-be-zero `dwflags`
argument in `Some(0)` to match the binding signature.
No new Cargo features and no changes outside `crates/metadata/`.
c8b5bcf to
72a0c68
Compare
oferchen
added a commit
that referenced
this pull request
May 5, 2026
…ams (#1867) (#3536) * feat(metadata): implement Windows xattrs via NTFS Alternate Data Streams (#1867) Add a Windows backend for the cross-platform xattr layer that maps each named extended attribute onto an NTFS Alternate Data Stream using the `path:streamname:$DATA` syntax. The four POSIX primitives are now backed by `FindFirstStreamW`/`FindNextStreamW` for listing, `CreateFileW` + `ReadFile`/`WriteFile` for read and write, and `DeleteFileW` for removal. Stream-name parsing strips the `:` prefix and `:$DATA` suffix returned by NTFS so the wire-format names match the Unix xattr names exposed by the existing `xattr` crate backend. Refactor the per-attribute primitives in `crates/metadata/src/xattr.rs` to take raw `&[u8]` names and dispatch to a platform backend module (`xattr_unix` or `xattr_windows`). The Unix backend continues to wrap the `xattr` crate; the new Windows backend lives in a separate file under the same `feature = "xattr"` gate so the cross-platform layer remains backend-agnostic. The public API (`read_xattrs_for_wire`, `sync_xattrs`, `apply_xattrs_from_list`) is unchanged and the upstream rsync namespace-filtering policy still applies on Linux. Unsafe FFI is contained in `xattr_windows.rs` with `#![allow(unsafe_code)]` matching the existing convention for platform wrappers in the metadata crate (alongside `acl_windows`, `ownership`, `id_lookup`). Resource management uses RAII wrappers around `FindClose` and `CloseHandle` so handles are released on every error path. Tests cover the stream-name parser, input validation in `stream_path_wide`, and a write/read/list/remove round-trip that gracefully skips when the test volume does not support ADS (e.g. FAT32 runners). Refs #1867 * style(metadata): cargo fmt * fix(metadata): make ADS xattr impl cross-compile for windows-gnu The Windows ADS xattr backend used `windows::Win32::Storage::FileSystem::{ ReadFile, WriteFile}`, which are gated behind the `Win32_System_IO` feature in `windows = "0.62"`. Cross-compiling to `x86_64-pc-windows-gnu` therefore failed with `no `ReadFile` / `WriteFile` in `Win32::Storage::FileSystem``. `FindFirstStreamW`'s `dwflags` argument also takes `Option<u32>`, but the call site passed a bare `0`. Replace the raw `ReadFile`/`WriteFile` calls with `std::fs::File` constructed from the Win32 `HANDLE` via `FromRawHandle`, so the read and write paths use stdlib I/O instead of FFI bindings that depend on an additional `windows` crate feature. The `File` takes ownership of the handle and closes it on drop, replacing the now-unused `OwnedHandle` wrapper. Wrap the reserved-must-be-zero `dwflags` argument in `Some(0)` to match the binding signature. No new Cargo features and no changes outside `crates/metadata/`. * style(metadata): cargo fmt xattr_windows imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
path:streamname:$DATAsyntax.FindFirstStreamW/FindNextStreamWfor listing,CreateFileW+ReadFile/WriteFilefor read/write, andDeleteFileWfor removal. Stream-name parsing strips the:prefix and:$DATAsuffix so wire-format names match the existing Unix xattr names.crates/metadata/src/xattr.rsto dispatch through a platform backend module (xattr_unixorxattr_windows) while keeping the public API (read_xattrs_for_wire,sync_xattrs,apply_xattrs_from_list) and Linux namespace policy unchanged.xattr_windows.rs(#![allow(unsafe_code)]) and uses RAII wrappers aroundFindCloseandCloseHandlefor handle cleanup. Matches the convention used byacl_windows,ownership, andid_lookupin the same crate.Refs #1867
Test plan
xattr_windows::tests, gracefully skips on FAT32)::$DATAskip, non-data-stream rejection)stream_path_wideinput validation (empty, embedded:, non-UTF-8)xattr.rscross-platform tests on Linux (existing tests still green viaxattr_unixbackend)