Advertisement
Guest User

Cygwin + OS X SMB reparse point test 2

a guest
Oct 22nd, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. void scream_and_die(const char* complaint, ...)
  5. {
  6.     va_list args = NULL;
  7.  
  8.     char format[80];
  9.     snprintf(format, sizeof(format), "%s: %%s (0x%x)\n",
  10.             complaint, GetLastError());
  11.  
  12.     LPTSTR syserr = 0;
  13.     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
  14.             FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, GetLastError(),
  15.             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  16.             (LPTSTR)&syserr, 0, 0);
  17.  
  18.     fprintf(stderr, format, syserr);
  19.     exit(1);
  20. }
  21.  
  22. int main()
  23. {
  24.     const char* path = "P:\\";
  25.     HANDLE handle = CreateFile (path, GENERIC_READ, 0, 0,
  26.             OPEN_EXISTING,
  27.             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
  28.             0);
  29.     if (handle == INVALID_HANDLE_VALUE) {
  30.         scream_and_die("Bad handle");
  31.     }
  32.     DWORD attributes = GetFileAttributes (path);
  33.     if (attributes != (DWORD) -1
  34.             && (attributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
  35.         char buf[32000];
  36.         DWORD len;
  37.  
  38.         if (!DeviceIoControl(handle,
  39.                 FSCTL_GET_REPARSE_POINT, NULL, 0,
  40.                 buf, 32000, &len, NULL)) {
  41.             scream_and_die("Failed to get reparse point");
  42.         }
  43.         else {
  44.             printf("No error\n");
  45.         }
  46.     }
  47.     else {
  48.         printf("Reparse flag not set\n");
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement