MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / pt_junction

Function pt_junction

tests/test_test_impact_tree.c:2216–2250  ·  view source on GitHub ↗

A mount-point reparse fixture uses an owned empty directory and an owned * target. It does not depend on symbolic-link privilege or developer mode. */

Source from the content-addressed store, hash-verified

2214/* A mount-point reparse fixture uses an owned empty directory and an owned
2215 * target. It does not depend on symbolic-link privilege or developer mode. */
2216static bool pt_junction(const char *path, const char *target) {
2217 wchar_t wide[PT_PATH], destination[PT_PATH];
2218 if (!pt_wide(path, wide) || !pt_wide(target, destination))
2219 return false;
2220 for (wchar_t *p = destination; *p; p++)
2221 if (*p == L'/')
2222 *p = L'\\';
2223 if (!destination[0] || destination[1] != L':')
2224 return false;
2225 struct {
2226 DWORD tag;
2227 WORD data_length, reserved, substitute_offset, substitute_length, print_offset,
2228 print_length;
2229 WCHAR path[PT_PATH + 8];
2230 } buffer = {0};
2231 size_t length = wcslen(destination);
2232 if (length + 5 >= sizeof(buffer.path) / sizeof(buffer.path[0]))
2233 return false;
2234 buffer.tag = IO_REPARSE_TAG_MOUNT_POINT;
2235 memcpy(buffer.path, L"\\??\\", 4 * sizeof(WCHAR));
2236 memcpy(buffer.path + 4, destination, (length + 1) * sizeof(WCHAR));
2237 buffer.substitute_length = (WORD)((length + 4) * sizeof(WCHAR));
2238 buffer.print_offset = (WORD)(buffer.substitute_length + sizeof(WCHAR));
2239 buffer.print_length = 0;
2240 buffer.path[length + 5] = 0;
2241 buffer.data_length = (WORD)(8 + buffer.substitute_length + 2 * sizeof(WCHAR));
2242 HANDLE directory = CreateFileW(wide, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
2243 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
2244 if (directory == INVALID_HANDLE_VALUE)
2245 return false;
2246 DWORD returned = 0;
2247 bool ok = DeviceIoControl(directory, FSCTL_SET_REPARSE_POINT, &buffer,
2248 (DWORD)(8 + buffer.data_length), NULL, 0, &returned, NULL) != 0;
2249 return CloseHandle(directory) && ok;
2250}
2251#endif
2252
2253static bool pt_link_case(pt_fixture *fx) {

Callers 1

pt_link_caseFunction · 0.85

Calls 1

pt_wideFunction · 0.85

Tested by

no test coverage detected