MCPcopy Create free account
hub / github.com/git/git / read_reparse_point

Function read_reparse_point

compat/mingw.c:1161–1214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1159#endif
1160
1161static 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
1216int mingw_lstat(const char *file_name, struct stat *buf)
1217{

Callers 2

mingw_lstatFunction · 0.85
readlinkFunction · 0.85

Calls 3

err_win_to_posixFunction · 0.85
xwcstoutfFunction · 0.85
normalize_ntpathFunction · 0.85

Tested by

no test coverage detected