Advertisement
Guest User

Cygwin + OS X SMB reparse point test 3

a guest
Oct 23rd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 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.             FILE_FLAG_OPEN_REPARSE_POINT,
  29.             0);
  30.     if (handle == INVALID_HANDLE_VALUE) {
  31.         scream_and_die("Bad handle");
  32.     }
  33.     else {
  34.         BY_HANDLE_FILE_INFORMATION fi;
  35.         if (GetFileInformationByHandle(handle, &fi) &&
  36.                 (fi.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
  37.             char buf[32000];
  38.             DWORD len;
  39.  
  40.             if (!DeviceIoControl(handle,
  41.                     FSCTL_GET_REPARSE_POINT, NULL, 0,
  42.                     buf, 32000, &len, NULL)) {
  43.                 scream_and_die("Failed to get reparse point");
  44.             }
  45.             else {
  46.                 printf("No error\n");
  47.             }
  48.         }
  49.         else {
  50.             printf("Reparse flag not set\n");
  51.         }
  52.  
  53.         return 0;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement