VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/nt/RTPathSetMode-r3-nt.cpp@ 103795

Last change on this file since 103795 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: RTPathSetMode-r3-nt.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - RTPathSetMode, Native NT.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP RTLOGGROUP_FILE
42#include "internal-r3-nt.h"
43
44#include <iprt/path.h>
45#include <iprt/err.h>
46
47#include "internal/fs.h"
48
49
50
51RTDECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode)
52{
53 fMode = rtFsModeNormalize(fMode, pszPath, 0, 0);
54 AssertReturn(rtFsModeIsValidPermissions(fMode), VERR_INVALID_FMODE);
55
56 /*
57 * Convert and normalize the path.
58 */
59 UNICODE_STRING NtName;
60 HANDLE hRootDir;
61 int rc = RTNtPathFromWinUtf8(&NtName, &hRootDir, pszPath);
62 if (RT_SUCCESS(rc))
63 {
64 HANDLE hPath = RTNT_INVALID_HANDLE_VALUE;
65 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
66 OBJECT_ATTRIBUTES ObjAttr;
67 InitializeObjectAttributes(&ObjAttr, &NtName, 0 /*fAttrib*/, hRootDir, NULL);
68
69 ULONG fOpenOptions = FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_REPARSE_POINT;
70 //if (fFlags & RTPATH_F_ON_LINK)
71 // fOpenOptions |= FILE_OPEN_REPARSE_POINT;
72 NTSTATUS rcNt = NtCreateFile(&hPath,
73 FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
74 &ObjAttr,
75 &Ios,
76 NULL /*AllocationSize*/,
77 FILE_ATTRIBUTE_NORMAL,
78 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
79 FILE_OPEN,
80 fOpenOptions,
81 NULL /*EaBuffer*/,
82 0 /*EaLength*/);
83 if (NT_SUCCESS(rcNt))
84 {
85 rc = rtNtFileSetModeWorker(hPath, fMode);
86
87 rcNt = NtClose(hPath);
88 if (!NT_SUCCESS(rcNt) && RT_SUCCESS(rc))
89 rc = RTErrConvertFromNtStatus(rcNt);
90 }
91 else
92 rc = RTErrConvertFromNtStatus(rcNt);
93
94 RTNtPathFree(&NtName, &hRootDir);
95 }
96 return rc;
97}
98
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette