7 win32_error_string(DWORD err)
9 static wchar_t buf[1024];
11 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, 1024, NULL);
16 fail(const char *func)
18 DWORD err = GetLastError();
19 fprintf(stderr, "%s (err 0x%08x: %ls)\n", func,
20 (uint32_t)err, win32_error_string(err));
25 wmain(int argc, wchar_t **argv)
27 uint16_t rpdatalen = 80;
29 if (argc < 2 || argc > 3) {
30 fprintf(stderr, "Usage: %ls FILE [rpdatalen]\n", argv[0]);
35 rpdatalen = wcstol(argv[2], NULL, 10);
37 HANDLE h = CreateFile(argv[1],
39 FILE_SHARE_VALID_FLAGS,
42 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
44 if (h == INVALID_HANDLE_VALUE)
47 uint8_t in[8 + rpdatalen];
49 *(uint32_t *)p = 0x80000000; /* rptag */
51 *(uint16_t *)p = rpdatalen; /* rpdatalen */
53 *(uint16_t *)p = 0x1234; /* rpreserved */
55 memset(p, 0, rpdatalen); /* rpdata */
60 if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT, in, p - in,
61 NULL, 0, &bytes_returned, NULL))
62 fail("DeviceIoControl");