Skip to content

Commit 0343561

Browse files
authored
<filesystem>: __std_fs_get_stats should work on FAT32 (#2373)
1 parent 39a0ea7 commit 0343561

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

stl/src/filesystem.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,10 @@ struct alignas(long long) _Aligned_file_attrs {
888888
return _Last_error;
889889
}
890890

891-
constexpr auto _Basic_info_data = __std_fs_stats_flags::_Attributes | __std_fs_stats_flags::_Last_write_time;
892-
constexpr auto _Attribute_tag_info_data = __std_fs_stats_flags::_Attributes | __std_fs_stats_flags::_Reparse_tag;
893-
constexpr auto _Standard_info_data = __std_fs_stats_flags::_File_size | __std_fs_stats_flags::_Link_count;
891+
constexpr auto _Basic_info_data = __std_fs_stats_flags::_Attributes | __std_fs_stats_flags::_Last_write_time;
892+
constexpr auto _Standard_info_data = __std_fs_stats_flags::_File_size | __std_fs_stats_flags::_Link_count;
894893

895-
if (_Flags != _Attribute_tag_info_data && _Bitmask_includes(_Flags, _Basic_info_data)) {
896-
// we have data FileBasicInfo can fill in, that FileAttributeTagInfo wouldn't exactly fill in
894+
if (_Bitmask_includes(_Flags, _Basic_info_data | __std_fs_stats_flags::_Reparse_tag)) {
897895
FILE_BASIC_INFO _Info;
898896
if (!GetFileInformationByHandleEx(_Handle._Get(), FileBasicInfo, &_Info, sizeof(_Info))) {
899897
return __std_win_error{GetLastError()};
@@ -902,17 +900,21 @@ struct alignas(long long) _Aligned_file_attrs {
902900
_Stats->_Attributes = __std_fs_file_attr{_Info.FileAttributes};
903901
_Stats->_Last_write_time = _Info.LastWriteTime.QuadPart;
904902
_Flags &= ~_Basic_info_data;
905-
}
903+
if (_Bitmask_includes(_Flags, __std_fs_stats_flags::_Reparse_tag)) {
904+
// Calling GetFileInformationByHandleEx with FileAttributeTagInfo fails on FAT file system with
905+
// ERROR_INVALID_PARAMETER. We avoid calling this for non-reparse-points.
906+
if (_Info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
907+
FILE_ATTRIBUTE_TAG_INFO _TagInfo;
908+
if (!GetFileInformationByHandleEx(_Handle._Get(), FileAttributeTagInfo, &_TagInfo, sizeof(_TagInfo))) {
909+
return __std_win_error{GetLastError()};
910+
}
906911

907-
if (_Bitmask_includes(_Flags, _Attribute_tag_info_data)) {
908-
FILE_ATTRIBUTE_TAG_INFO _Info;
909-
if (!GetFileInformationByHandleEx(_Handle._Get(), FileAttributeTagInfo, &_Info, sizeof(_Info))) {
910-
return __std_win_error{GetLastError()};
912+
_Stats->_Reparse_point_tag = __std_fs_reparse_tag{_TagInfo.ReparseTag};
913+
} else {
914+
_Stats->_Reparse_point_tag = __std_fs_reparse_tag::_None;
915+
}
916+
_Flags &= ~__std_fs_stats_flags::_Reparse_tag;
911917
}
912-
913-
_Stats->_Attributes = __std_fs_file_attr{_Info.FileAttributes};
914-
_Stats->_Reparse_point_tag = __std_fs_reparse_tag{_Info.ReparseTag};
915-
_Flags &= ~_Attribute_tag_info_data;
916918
}
917919

918920
if (_Bitmask_includes(_Flags, _Standard_info_data)) {

0 commit comments

Comments
 (0)