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.
5 #include "sandbox/win/tests/common/test_utils.h"
9 typedef struct _REPARSE_DATA_BUFFER
{
11 USHORT ReparseDataLength
;
15 USHORT SubstituteNameOffset
;
16 USHORT SubstituteNameLength
;
17 USHORT PrintNameOffset
;
18 USHORT PrintNameLength
;
21 } SymbolicLinkReparseBuffer
;
23 USHORT SubstituteNameOffset
;
24 USHORT SubstituteNameLength
;
25 USHORT PrintNameOffset
;
26 USHORT PrintNameLength
;
28 } MountPointReparseBuffer
;
31 } GenericReparseBuffer
;
33 } REPARSE_DATA_BUFFER
, *PREPARSE_DATA_BUFFER
;
35 // Sets a reparse point. |source| will now point to |target|. Returns true if
36 // the call succeeds, false otherwise.
37 bool SetReparsePoint(HANDLE source
, const wchar_t* target
) {
38 USHORT size_target
= static_cast<USHORT
>(wcslen(target
)) * sizeof(target
[0]);
40 char buffer
[2000] = {0};
43 REPARSE_DATA_BUFFER
* data
= reinterpret_cast<REPARSE_DATA_BUFFER
*>(buffer
);
45 data
->ReparseTag
= 0xa0000003;
46 memcpy(data
->MountPointReparseBuffer
.PathBuffer
, target
, size_target
+ 2);
47 data
->MountPointReparseBuffer
.SubstituteNameLength
= size_target
;
48 data
->MountPointReparseBuffer
.PrintNameOffset
= size_target
+ 2;
49 data
->ReparseDataLength
= size_target
+ 4 + 8;
51 int data_size
= data
->ReparseDataLength
+ 8;
53 if (!DeviceIoControl(source
, FSCTL_SET_REPARSE_POINT
, &buffer
, data_size
,
54 NULL
, 0, &returned
, NULL
)) {
60 // Delete the reparse point referenced by |source|. Returns true if the call
61 // succeeds, false otherwise.
62 bool DeleteReparsePoint(HANDLE source
) {
64 REPARSE_DATA_BUFFER data
= {0};
65 data
.ReparseTag
= 0xa0000003;
66 if (!DeviceIoControl(source
, FSCTL_DELETE_REPARSE_POINT
, &data
, 8, NULL
, 0,