]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Ventoy2Disk/Ventoy2Disk/DiskService.c
Add EDK debug info.
[Ventoy.git] / Ventoy2Disk / Ventoy2Disk / DiskService.c
1 /******************************************************************************
2 * DiskService.c
3 *
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <Windows.h>
22 #include <winternl.h>
23 #include <commctrl.h>
24 #include <initguid.h>
25 #include <vds.h>
26 #include "Ventoy2Disk.h"
27 #include "DiskService.h"
28
29 BOOL DISK_CleanDisk(int DriveIndex)
30 {
31 BOOL ret;
32
33 ret = VDS_CleanDisk(DriveIndex);
34 if (!ret)
35 {
36 ret = PSHELL_CleanDisk(DriveIndex);
37 }
38
39 return ret;
40 }
41
42
43 BOOL DISK_DeleteVtoyEFIPartition(int DriveIndex, UINT64 EfiPartOffset)
44 {
45 BOOL ret;
46
47 ret = VDS_DeleteVtoyEFIPartition(DriveIndex, EfiPartOffset);
48 if (!ret)
49 {
50 ret = PSHELL_DeleteVtoyEFIPartition(DriveIndex, EfiPartOffset);
51 }
52
53 return ret;
54 }
55
56 BOOL DISK_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset)
57 {
58 BOOL ret;
59
60 ret = VDS_ChangeVtoyEFI2ESP(DriveIndex, Offset);
61 if (!ret)
62 {
63 ret = PSHELL_ChangeVtoyEFI2ESP(DriveIndex, Offset);
64 }
65
66 return ret;
67 }
68
69
70 BOOL DISK_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset)
71 {
72 BOOL ret;
73
74 ret = VDS_ChangeVtoyEFI2Basic(DriveIndex, Offset);
75 if (!ret)
76 {
77 ret = PSHELL_ChangeVtoyEFI2Basic(DriveIndex, Offset);
78 }
79
80 return ret;
81 }
82
83 BOOL DISK_ChangeVtoyEFIAttr(int DriveIndex, UINT64 Offset, UINT64 Attr)
84 {
85 BOOL ret;
86
87 ret = VDS_ChangeVtoyEFIAttr(DriveIndex, Offset, Attr);
88
89 return ret;
90 }
91
92 BOOL DISK_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes)
93 {
94 BOOL ret;
95
96 ret = VDS_ShrinkVolume(DriveIndex, VolumeGuid, DriveLetter, OldBytes, ReduceBytes);
97 if (!ret)
98 {
99 if (LASTERR == VDS_E_SHRINK_DIRTY_VOLUME)
100 {
101 Log("VDS shrink return dirty, no need to run powershell.");
102 }
103 else
104 {
105 ret = PSHELL_ShrinkVolume(DriveIndex, VolumeGuid, DriveLetter, OldBytes, ReduceBytes);
106 }
107 }
108
109 return ret;
110 }
111