master
hpp 119 lines 3.38 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 svccomm.hpp
8
9 Abstract:
10
11 This file contains function declarations for the SvcComm helper class.
12
13 --*/
14
15 #pragma once
16
17 #include <vector>
18 #include <memory>
19 #include "helpers.hpp"
20 #include "SocketChannel.h"
21
22 namespace wsl::windows::common {
23
24 class SvcComm
25 {
26 public:
27 struct MountResult
28 {
29 int Result = -1;
30 int Step = 0;
31 wil::unique_cotaskmem_string MountName;
32 };
33
34 SvcComm();
35 ~SvcComm();
36
37 void ConfigureDistribution(_In_opt_ LPCGUID DistroGuid, _In_ ULONG DefaultUid, _In_ ULONG Flags) const;
38
39 void CreateInstance(_In_opt_ LPCGUID DistroGuid = nullptr, _In_ ULONG Flags = LXSS_CREATE_INSTANCE_FLAGS_ALLOW_FS_UPGRADE);
40
41 HRESULT
42 CreateInstanceNoThrow(_In_opt_ LPCGUID DistroGuid = nullptr, _In_ ULONG Flags = LXSS_CREATE_INSTANCE_FLAGS_ALLOW_FS_UPGRADE, LXSS_ERROR_INFO* Error = nullptr) const;
43
44 std::vector<LXSS_ENUMERATE_INFO> EnumerateDistributions() const;
45
46 HRESULT
47 ExportDistribution(_In_opt_ LPCGUID DistroGuid, _In_ HANDLE FileHandle, _In_ ULONG Flags = 0) const;
48
49 void GetDistributionConfiguration(
50 _In_opt_ LPCGUID DistroGuid,
51 _Out_ LPWSTR* Name,
52 _Out_ ULONG* Version,
53 _Out_ ULONG* DefaultUid,
54 _Out_ ULONG* DefaultEnvironmentCount,
55 _Out_ LPSTR** DefaultEnvironment,
56 _Out_ ULONG* Flags) const;
57
58 DWORD
59 LaunchProcess(
60 _In_opt_ LPCGUID DistroGuid,
61 _In_opt_ LPCWSTR Filename,
62 _In_ int Argc,
63 _In_reads_(Argc) LPCWSTR Argv[],
64 _In_ ULONG LaunchFlags = 0,
65 _In_opt_ PCWSTR Username = nullptr,
66 _In_opt_ PCWSTR CurrentWorkingDirectory = nullptr,
67 _In_ DWORD Timeout = INFINITE) const;
68
69 GUID GetDefaultDistribution() const;
70
71 ULONG
72 GetDistributionFlags(_In_opt_ LPCGUID DistroGuid = nullptr) const;
73
74 GUID GetDistributionId(_In_ LPCWSTR Name, _In_ ULONG Flags = 0) const;
75
76 GUID ImportDistributionInplace(_In_ LPCWSTR Name, _In_ LPCWSTR VhdPath) const;
77
78 MountResult MountDisk(_In_ LPCWSTR Disk, _In_ ULONG Flags, _In_ ULONG PartitionIndex, _In_opt_ LPCWSTR Name, _In_opt_ LPCWSTR Type, _In_opt_ LPCWSTR Options) const;
79
80 std::pair<GUID, wil::unique_cotaskmem_string> RegisterDistribution(
81 _In_ LPCWSTR Name,
82 _In_ ULONG Version,
83 _In_ HANDLE FileHandle,
84 _In_ LPCWSTR TargetDirectory,
85 _In_ ULONG Flags,
86 _In_ std::optional<uint64_t> VhdSize = std::nullopt,
87 _In_opt_ LPCWSTR PackageFamilyName = nullptr) const;
88
89 HRESULT
90 ResizeDistribution(_In_ LPCGUID DistroGuid, _In_ ULONG64 NewSize) const;
91
92 HRESULT
93 CompactDistribution(_In_ LPCGUID DistroGuid) const;
94
95 void SetDefaultDistribution(_In_ LPCGUID DistroGuid) const;
96
97 HRESULT
98 SetSparse(_In_ LPCGUID DistroGuid, _In_ BOOL Sparse, _In_ BOOL AllowUnsafe) const;
99
100 HRESULT
101 SetVersion(_In_ LPCGUID DistroGuid, _In_ ULONG Version) const;
102
103 HRESULT
104 AttachDisk(_In_ LPCWSTR Disk, _In_ ULONG Flags) const;
105
106 std::pair<int, int> DetachDisk(_In_opt_ LPCWSTR Disk) const;
107
108 void Shutdown(_In_ bool Force) const;
109
110 void TerminateInstance(_In_opt_ LPCGUID DistroGuid = nullptr) const;
111
112 void UnregisterDistribution(_In_ LPCGUID DistroGuid) const;
113
114 void MoveDistribution(_In_ const GUID& DistroGuid, _In_ LPCWSTR Location) const;
115
116 private:
117 wil::com_ptr<ILxssUserSession> m_userSession;
118 };
119 } // namespace wsl::windows::common