1 | /* $Id: RTPathSetMode-r3-nt.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTPathSetMode, Native NT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #define LOG_GROUP RTLOGGROUP_FILE
|
---|
32 | #include "internal-r3-nt.h"
|
---|
33 |
|
---|
34 | #include <iprt/path.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 |
|
---|
37 | #include "internal/fs.h"
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | RTDECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode)
|
---|
42 | {
|
---|
43 | fMode = rtFsModeNormalize(fMode, pszPath, 0);
|
---|
44 | AssertReturn(rtFsModeIsValidPermissions(fMode), VERR_INVALID_FMODE);
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Convert and normalize the path.
|
---|
48 | */
|
---|
49 | UNICODE_STRING NtName;
|
---|
50 | HANDLE hRootDir;
|
---|
51 | int rc = RTNtPathFromWinUtf8(&NtName, &hRootDir, pszPath);
|
---|
52 | if (RT_SUCCESS(rc))
|
---|
53 | {
|
---|
54 | HANDLE hPath = RTNT_INVALID_HANDLE_VALUE;
|
---|
55 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
56 | OBJECT_ATTRIBUTES ObjAttr;
|
---|
57 | InitializeObjectAttributes(&ObjAttr, &NtName, 0 /*fAttrib*/, hRootDir, NULL);
|
---|
58 |
|
---|
59 | ULONG fOpenOptions = FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_REPARSE_POINT;
|
---|
60 | //if (fFlags & RTPATH_F_ON_LINK)
|
---|
61 | // fOpenOptions |= FILE_OPEN_REPARSE_POINT;
|
---|
62 | NTSTATUS rcNt = NtCreateFile(&hPath,
|
---|
63 | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
|
---|
64 | &ObjAttr,
|
---|
65 | &Ios,
|
---|
66 | NULL /*AllocationSize*/,
|
---|
67 | FILE_ATTRIBUTE_NORMAL,
|
---|
68 | FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
---|
69 | FILE_OPEN,
|
---|
70 | fOpenOptions,
|
---|
71 | NULL /*EaBuffer*/,
|
---|
72 | 0 /*EaLength*/);
|
---|
73 | if (NT_SUCCESS(rcNt))
|
---|
74 | {
|
---|
75 | rc = rtNtFileSetModeWorker(hPath, fMode);
|
---|
76 |
|
---|
77 | rcNt = NtClose(hPath);
|
---|
78 | if (!NT_SUCCESS(rcNt) && RT_SUCCESS(rc))
|
---|
79 | rc = RTErrConvertFromNtStatus(rcNt);
|
---|
80 | }
|
---|
81 | else
|
---|
82 | rc = RTErrConvertFromNtStatus(rcNt);
|
---|
83 |
|
---|
84 | RTNtPathFree(&NtName, &hRootDir);
|
---|
85 | }
|
---|
86 | return rc;
|
---|
87 | }
|
---|
88 |
|
---|