xref: /reactos/base/setup/lib/utils/filesup.h (revision cadfdc55)
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 DirectoryName);
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(
70     IN HANDLE RootDirectory OPTIONAL,
71     IN PCWSTR PathName,
72     IN BOOLEAN IsDirectory);
73 
74 #define DoesDirExist(RootDirectory, DirName)    \
75     DoesPathExist((RootDirectory), (DirName), TRUE)
76 
77 #define DoesFileExist(RootDirectory, FileName)  \
78     DoesPathExist((RootDirectory), (FileName), FALSE)
79 
80 // FIXME: DEPRECATED! HACKish function that needs to be deprecated!
81 BOOLEAN
82 DoesFileExist_2(
83     IN PCWSTR PathName OPTIONAL,
84     IN PCWSTR FileName);
85 
86 BOOLEAN
87 NtPathToDiskPartComponents(
88     IN PCWSTR NtPath,
89     OUT PULONG pDiskNumber,
90     OUT PULONG pPartNumber,
91     OUT PCWSTR* PathComponent OPTIONAL);
92 
93 NTSTATUS
94 OpenAndMapFile(
95     _In_opt_ HANDLE RootDirectory,
96     _In_ PCWSTR PathNameToFile,
97     _Out_opt_ PHANDLE FileHandle,
98     _Out_opt_ PULONG FileSize,
99     _Out_ PHANDLE SectionHandle,
100     _Out_ PVOID* BaseAddress,
101     _In_ BOOLEAN ReadWriteAccess);
102 
103 NTSTATUS
104 MapFile(
105     _In_ HANDLE FileHandle,
106     _Out_ PHANDLE SectionHandle,
107     _Out_ PVOID* BaseAddress,
108     _In_ BOOLEAN ReadWriteAccess);
109 
110 BOOLEAN
111 UnMapFile(
112     _In_ HANDLE SectionHandle,
113     _In_ PVOID BaseAddress);
114 
115 #define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)   \
116 do {    \
117     UnMapFile((SectionHandle), (BaseAddress));  \
118     NtClose(FileHandle);                        \
119 } while (0)
120 
121 /* EOF */
122