VirtualBox

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

Last change on this file since 91575 was 82968, checked in by vboxsync, 5 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.4 KB
Line 
1/* $Id: RTPathSetMode-r3-nt.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - RTPathSetMode, Native NT.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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
41RTDECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode)
42{
43 fMode = rtFsModeNormalize(fMode, pszPath, 0, 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
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