]> wimlib.net Git - wimlib/commitdiff
Add additional reparse point tests to win32-test-imagex-capture_and_apply.bat
authorEric Biggers <ebiggers3@gmail.com>
Sun, 22 Mar 2015 20:44:31 +0000 (15:44 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 22 Mar 2015 21:36:10 +0000 (16:36 -0500)
tests/set_reparse_point.c [new file with mode: 0644]
tests/win32-test-imagex-capture_and_apply.bat

diff --git a/tests/set_reparse_point.c b/tests/set_reparse_point.c
new file mode 100644 (file)
index 0000000..73428f0
--- /dev/null
@@ -0,0 +1,61 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include <windows.h>
+
+static wchar_t *
+win32_error_string(DWORD err_code)
+{
+       static wchar_t buf[1024];
+       buf[0] = L'\0';
+       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err_code, 0,
+                     buf, 1024, NULL);
+       return buf;
+}
+
+static void
+fail(const char *func, DWORD code)
+{
+       fprintf(stderr, "%s (err 0x%08x: %ls)\n", func,
+               (unsigned int)code, win32_error_string(code));
+       exit(1);
+}
+
+int
+wmain(int argc, wchar_t **argv)
+{
+       if (argc != 2) {
+               fprintf(stderr, "Usage: %ls FILE\n", argv[0]);
+               return 2;
+       }
+
+       HANDLE h = CreateFile(argv[1],
+                             GENERIC_WRITE,
+                             FILE_SHARE_VALID_FLAGS,
+                             NULL,
+                             OPEN_EXISTING,
+                             FILE_FLAG_BACKUP_SEMANTICS,
+                             NULL);
+       if (h == INVALID_HANDLE_VALUE)
+               fail("CreateFile", GetLastError());
+
+       uint8_t in[128];
+       uint8_t *p = in;
+       *(uint32_t *)p = 0x80000000; /* rptag */
+       p += 4;
+       *(uint16_t *)p = 80; /* rpdatalen */
+       p += 2;
+       *(uint16_t *)p = 0; /* rpreserved */
+       p += 2;
+       memset(p, 0, 80); /* rpdata */
+       p += 80;
+
+       DWORD bytes_returned;
+
+       if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT, in, p - in,
+                            NULL, 0, &bytes_returned, NULL))
+               fail("DeviceIoControl", GetLastError());
+
+       CloseHandle(h);
+
+       return 0;
+}
index 98064adedea7a92658593a7e5601740f2749c8ee..8283ddd44a40b5fe3f71dc4dd3820962675b8c1c 100644 (file)
@@ -10,8 +10,9 @@ REM Administrator privileges.  wimlib-imagex and win32-tree-cmp must be
 REM executable using the paths set below.\r
 \r
 setlocal EnableDelayedExpansion\r
 REM executable using the paths set below.\r
 \r
 setlocal EnableDelayedExpansion\r
-set WIN32_TREE_CMP=win32-tree-cmp\r
 set WIMLIB_IMAGEX=wimlib-imagex\r
 set WIMLIB_IMAGEX=wimlib-imagex\r
+set WIN32_TREE_CMP=win32-tree-cmp\r
+set SET_REPARSE_POINT=set_reparse_point\r
 \r
 if exist in.dir rd /S /Q in.dir\r
 if exist out.dir rd /S /Q out.dir\r
 \r
 if exist in.dir rd /S /Q in.dir\r
 if exist out.dir rd /S /Q out.dir\r
@@ -178,6 +179,48 @@ echo "hello world!!!!" > subdir2\otherfile
 call :do_test\r
 if %errorlevel% neq 0 goto :fail\r
 \r
 call :do_test\r
 if %errorlevel% neq 0 goto :fail\r
 \r
+call :msg "reparse point that is neither a symlink nor a junction"\r
+type nul > file\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with named data streams"\r
+type nul > file\r
+echo 11 > file:a\r
+echo 1 > file:aa\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with unnamed data stream"\r
+echo "test" > file\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with unnamed data stream and named data streams"\r
+echo "test" > file\r
+echo 11 > file:a\r
+echo 1 > file:aa\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory reparse point that is neither a symlink nor a junction"\r
+md subdir\r
+%SET_REPARSE_POINT% subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory reparse point with named data streams"\r
+md subdir\r
+echo 11 > subdir:a\r
+echo 1 > subdir:aa\r
+%SET_REPARSE_POINT% subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
 call :msg "compressed file"\r
 echo "test" > test\r
 compact /C test > nul\r
 call :msg "compressed file"\r
 echo "test" > test\r
 compact /C test > nul\r