| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sandbox/win/tests/common/test_utils.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <winioctl.h> | |
| 9 | |
| 10 typedef struct _REPARSE_DATA_BUFFER { | |
| 11 ULONG ReparseTag; | |
| 12 USHORT ReparseDataLength; | |
| 13 USHORT Reserved; | |
| 14 union { | |
| 15 struct { | |
| 16 USHORT SubstituteNameOffset; | |
| 17 USHORT SubstituteNameLength; | |
| 18 USHORT PrintNameOffset; | |
| 19 USHORT PrintNameLength; | |
| 20 ULONG Flags; | |
| 21 WCHAR PathBuffer[1]; | |
| 22 } SymbolicLinkReparseBuffer; | |
| 23 struct { | |
| 24 USHORT SubstituteNameOffset; | |
| 25 USHORT SubstituteNameLength; | |
| 26 USHORT PrintNameOffset; | |
| 27 USHORT PrintNameLength; | |
| 28 WCHAR PathBuffer[1]; | |
| 29 } MountPointReparseBuffer; | |
| 30 struct { | |
| 31 UCHAR DataBuffer[1]; | |
| 32 } GenericReparseBuffer; | |
| 33 }; | |
| 34 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; | |
| 35 | |
| 36 // Sets a reparse point. |source| will now point to |target|. Returns true if | |
| 37 // the call succeeds, false otherwise. | |
| 38 bool SetReparsePoint(HANDLE source, const wchar_t* target) { | |
| 39 USHORT size_target = static_cast<USHORT>(wcslen(target)) * sizeof(target[0]); | |
| 40 | |
| 41 char buffer[2000] = {0}; | |
| 42 DWORD returned; | |
| 43 | |
| 44 REPARSE_DATA_BUFFER* data = reinterpret_cast<REPARSE_DATA_BUFFER*>(buffer); | |
| 45 | |
| 46 data->ReparseTag = 0xa0000003; | |
| 47 memcpy(data->MountPointReparseBuffer.PathBuffer, target, size_target + 2); | |
| 48 data->MountPointReparseBuffer.SubstituteNameLength = size_target; | |
| 49 data->MountPointReparseBuffer.PrintNameOffset = size_target + 2; | |
| 50 data->ReparseDataLength = size_target + 4 + 8; | |
| 51 | |
| 52 int data_size = data->ReparseDataLength + 8; | |
| 53 | |
| 54 if (!DeviceIoControl(source, FSCTL_SET_REPARSE_POINT, &buffer, data_size, | |
| 55 NULL, 0, &returned, NULL)) { | |
| 56 return false; | |
| 57 } | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 // Delete the reparse point referenced by |source|. Returns true if the call | |
| 62 // succeeds, false otherwise. | |
| 63 bool DeleteReparsePoint(HANDLE source) { | |
| 64 DWORD returned; | |
| 65 REPARSE_DATA_BUFFER data = {0}; | |
| 66 data.ReparseTag = 0xa0000003; | |
| 67 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, | |
| 68 &returned, NULL)) { | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 return true; | |
| 73 } | |
| OLD | NEW |