Skip to content

Commit 06f2008

Browse files
authored
Rollup merge of rust-lang#101260 - ChrisDenton:attribute-tag, r=thomcc
Use `FILE_ATTRIBUTE_TAG_INFO` to get reparse tag I've been looking at this code recently and it just occurred to me we don't actually use the full reparse data at this point, only the tag. [`GetFileInformationByHandleEx`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex) can do exactly that by filling a [`FILE_ATTRIBUTE_TAG_INFO`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_attribute_tag_info) struct. r? ``````@thomcc`````` since you've made changes here recently (which is why I have this code on my mind atm)
2 parents a1e77ca + 630f831 commit 06f2008

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

library/std/src/sys/windows/c.rs

+6
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ pub enum FILE_INFO_BY_HANDLE_CLASS {
454454
MaximumFileInfoByHandlesClass,
455455
}
456456

457+
#[repr(C)]
458+
pub struct FILE_ATTRIBUTE_TAG_INFO {
459+
pub FileAttributes: DWORD,
460+
pub ReparseTag: DWORD,
461+
}
462+
457463
#[repr(C)]
458464
pub struct FILE_DISPOSITION_INFO {
459465
pub DeleteFile: BOOLEAN,

library/std/src/sys/windows/fs.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,15 @@ impl File {
326326
cvt(c::GetFileInformationByHandle(self.handle.as_raw_handle(), &mut info))?;
327327
let mut reparse_tag = 0;
328328
if info.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
329-
let mut b =
330-
Align8([MaybeUninit::<u8>::uninit(); c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]);
331-
if let Ok((_, buf)) = self.reparse_point(&mut b) {
332-
reparse_tag = (*buf).ReparseTag;
329+
let mut attr_tag: c::FILE_ATTRIBUTE_TAG_INFO = mem::zeroed();
330+
cvt(c::GetFileInformationByHandleEx(
331+
self.handle.as_raw_handle(),
332+
c::FileAttributeTagInfo,
333+
ptr::addr_of_mut!(attr_tag).cast(),
334+
mem::size_of::<c::FILE_ATTRIBUTE_TAG_INFO>().try_into().unwrap(),
335+
))?;
336+
if attr_tag.FileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
337+
reparse_tag = attr_tag.ReparseTag;
333338
}
334339
}
335340
Ok(FileAttr {
@@ -390,10 +395,15 @@ impl File {
390395
attr.file_size = info.AllocationSize as u64;
391396
attr.number_of_links = Some(info.NumberOfLinks);
392397
if attr.file_type().is_reparse_point() {
393-
let mut b =
394-
Align8([MaybeUninit::<u8>::uninit(); c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]);
395-
if let Ok((_, buf)) = self.reparse_point(&mut b) {
396-
attr.reparse_tag = (*buf).ReparseTag;
398+
let mut attr_tag: c::FILE_ATTRIBUTE_TAG_INFO = mem::zeroed();
399+
cvt(c::GetFileInformationByHandleEx(
400+
self.handle.as_raw_handle(),
401+
c::FileAttributeTagInfo,
402+
ptr::addr_of_mut!(attr_tag).cast(),
403+
mem::size_of::<c::FILE_ATTRIBUTE_TAG_INFO>().try_into().unwrap(),
404+
))?;
405+
if attr_tag.FileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
406+
reparse_tag = attr_tag.ReparseTag;
397407
}
398408
}
399409
Ok(attr)

0 commit comments

Comments
 (0)