| 1159 | #endif |
| 1160 | |
| 1161 | static int read_reparse_point(const WCHAR *wpath, BOOL fail_on_unknown_tag, |
| 1162 | char *tmpbuf, int *plen, DWORD *ptag) |
| 1163 | { |
| 1164 | HANDLE handle; |
| 1165 | WCHAR *wbuf; |
| 1166 | REPARSE_DATA_BUFFER *b = alloca(MAXIMUM_REPARSE_DATA_BUFFER_SIZE); |
| 1167 | DWORD dummy; |
| 1168 | |
| 1169 | /* read reparse point data */ |
| 1170 | handle = CreateFileW(wpath, 0, |
| 1171 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
| 1172 | OPEN_EXISTING, |
| 1173 | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); |
| 1174 | if (handle == INVALID_HANDLE_VALUE) { |
| 1175 | errno = err_win_to_posix(GetLastError()); |
| 1176 | return -1; |
| 1177 | } |
| 1178 | if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, b, |
| 1179 | MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &dummy, NULL)) { |
| 1180 | errno = err_win_to_posix(GetLastError()); |
| 1181 | CloseHandle(handle); |
| 1182 | return -1; |
| 1183 | } |
| 1184 | CloseHandle(handle); |
| 1185 | |
| 1186 | /* get target path for symlinks or mount points (aka 'junctions') */ |
| 1187 | switch ((*ptag = b->ReparseTag)) { |
| 1188 | case IO_REPARSE_TAG_SYMLINK: |
| 1189 | wbuf = (WCHAR*) (((char*) b->SymbolicLinkReparseBuffer.PathBuffer) |
| 1190 | + b->SymbolicLinkReparseBuffer.SubstituteNameOffset); |
| 1191 | *(WCHAR*) (((char*) wbuf) |
| 1192 | + b->SymbolicLinkReparseBuffer.SubstituteNameLength) = 0; |
| 1193 | break; |
| 1194 | case IO_REPARSE_TAG_MOUNT_POINT: |
| 1195 | wbuf = (WCHAR*) (((char*) b->MountPointReparseBuffer.PathBuffer) |
| 1196 | + b->MountPointReparseBuffer.SubstituteNameOffset); |
| 1197 | *(WCHAR*) (((char*) wbuf) |
| 1198 | + b->MountPointReparseBuffer.SubstituteNameLength) = 0; |
| 1199 | break; |
| 1200 | default: |
| 1201 | if (fail_on_unknown_tag) { |
| 1202 | errno = EINVAL; |
| 1203 | return -1; |
| 1204 | } else { |
| 1205 | *plen = MAX_PATH; |
| 1206 | return 0; |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | if ((*plen = |
| 1211 | xwcstoutf(tmpbuf, normalize_ntpath(wbuf), MAX_PATH)) < 0) |
| 1212 | return -1; |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | int mingw_lstat(const char *file_name, struct stat *buf) |
| 1217 | { |
no test coverage detected