xref: /reactos/base/setup/lib/utils/filesup.h (revision d6eebaa4)
1 /*
2  * PROJECT:     ReactOS Setup Library
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     File support functions.
5  * COPYRIGHT:   Casper S. Hornstrup (chorns@users.sourceforge.net)
6  *              Copyright 2017-2018 Hermes Belusca-Maito
7  */
8 
9 #pragma once
10 
11 NTSTATUS
12 SetupCreateDirectory(
13     _In_ PCWSTR PathName);
14 
15 NTSTATUS
16 SetupDeleteFile(
17     IN PCWSTR FileName,
18     IN BOOLEAN ForceDelete); // ForceDelete can be used to delete read-only files
19 
20 NTSTATUS
21 SetupCopyFile(
22     IN PCWSTR SourceFileName,
23     IN PCWSTR DestinationFileName,
24     IN BOOLEAN FailIfExists);
25 
26 #ifndef _WINBASE_
27 
28 #define MOVEFILE_REPLACE_EXISTING   1
29 #define MOVEFILE_COPY_ALLOWED       2
30 #define MOVEFILE_WRITE_THROUGH      8
31 
32 #endif
33 
34 NTSTATUS
35 SetupMoveFile(
36     IN PCWSTR ExistingFileName,
37     IN PCWSTR NewFileName,
38     IN ULONG Flags);
39 
40 NTSTATUS
41 ConcatPathsV(
42     IN OUT PWSTR PathBuffer,
43     IN SIZE_T cchPathSize,
44     IN ULONG NumberOfPathComponents,
45     IN va_list PathComponentsList);
46 
47 NTSTATUS
48 CombinePathsV(
49     OUT PWSTR PathBuffer,
50     IN SIZE_T cchPathSize,
51     IN ULONG NumberOfPathComponents,
52     IN va_list PathComponentsList);
53 
54 NTSTATUS
55 ConcatPaths(
56     IN OUT PWSTR PathBuffer,
57     IN SIZE_T cchPathSize,
58     IN ULONG NumberOfPathComponents,
59     IN /* PCWSTR */ ...);
60 
61 NTSTATUS
62 CombinePaths(
63     OUT PWSTR PathBuffer,
64     IN SIZE_T cchPathSize,
65     IN ULONG NumberOfPathComponents,
66     IN /* PCWSTR */ ...);
67 
68 BOOLEAN
69 DoesPathExist_UStr(
70     _In_opt_ HANDLE RootDirectory,
71     _In_ PCUNICODE_STRING PathName,
72     _In_ BOOLEAN IsDirectory);
73 
74 BOOLEAN
75 DoesPathExist(
76     _In_opt_ HANDLE RootDirectory,
77     _In_ PCWSTR PathName,
78     _In_ BOOLEAN IsDirectory);
79 
80 #define DoesDirExist(RootDirectory, DirName)    \
81     DoesPathExist((RootDirectory), (DirName), TRUE)
82 
83 #define DoesFileExist(RootDirectory, FileName)  \
84     DoesPathExist((RootDirectory), (FileName), FALSE)
85 
86 // FIXME: DEPRECATED! HACKish function that needs to be deprecated!
87 BOOLEAN
88 DoesFileExist_2(
89     IN PCWSTR PathName OPTIONAL,
90     IN PCWSTR FileName);
91 
92 BOOLEAN
93 NtPathToDiskPartComponents(
94     IN PCWSTR NtPath,
95     OUT PULONG pDiskNumber,
96     OUT PULONG pPartNumber,
97     OUT PCWSTR* PathComponent OPTIONAL);
98 
99 NTSTATUS
100 OpenAndMapFile(
101     _In_opt_ HANDLE RootDirectory,
102     _In_ PCWSTR PathNameToFile,
103     _Out_opt_ PHANDLE FileHandle,
104     _Out_opt_ PULONG FileSize,
105     _Out_ PHANDLE SectionHandle,
106     _Out_ PVOID* BaseAddress,
107     _In_ BOOLEAN ReadWriteAccess);
108 
109 NTSTATUS
110 MapFile(
111     _In_ HANDLE FileHandle,
112     _Out_ PHANDLE SectionHandle,
113     _Out_ PVOID* BaseAddress,
114     _In_ BOOLEAN ReadWriteAccess);
115 
116 BOOLEAN
117 UnMapFile(
118     _In_ HANDLE SectionHandle,
119     _In_ PVOID BaseAddress);
120 
121 #define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)   \
122 do {    \
123     UnMapFile((SectionHandle), (BaseAddress));  \
124     NtClose(FileHandle);                        \
125 } while (0)
126 
127 /* EOF */
128