]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Ventoy2Disk/Ventoy2Disk/DiskService_diskpart.c
6d02e90517e45dd1725c1fe94955797b038f061e
1 /******************************************************************************
2 * DiskService_diskpart.c
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
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.
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.
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/>.
26 #include "Ventoy2Disk.h"
27 #include "DiskService.h"
29 STATIC BOOL
IsDiskpartExist(void)
33 ret
= IsFileExist("C:\\Windows\\system32\\diskpart.exe");
36 Log("diskpart.exe not exist");
42 STATIC BOOL
DSPT_CommProc(const char *Cmd
)
44 CHAR CmdBuf
[MAX_PATH
];
45 CHAR CmdFile
[MAX_PATH
];
47 PROCESS_INFORMATION Pi
;
49 GetCurrentDirectoryA(sizeof(CmdBuf
), CmdBuf
);
50 sprintf_s(CmdFile
, sizeof(CmdFile
), "%s\\ventoy\\diskpart_%u.txt", CmdBuf
, GetCurrentProcessId());
52 SaveBufToFile(CmdFile
, Cmd
, (int)strlen(Cmd
));
55 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
56 Si
.wShowWindow
= SW_HIDE
;
58 sprintf_s(CmdBuf
, sizeof(CmdBuf
), "C:\\Windows\\system32\\diskpart.exe /s \"%s\"", CmdFile
);
60 Log("CreateProcess <%s>", CmdBuf
);
61 CreateProcessA(NULL
, CmdBuf
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
63 Log("Wair process ...");
64 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
65 Log("Process finished...");
67 CHECK_CLOSE_HANDLE(Pi
.hProcess
);
68 CHECK_CLOSE_HANDLE(Pi
.hThread
);
74 BOOL
DSPT_CleanDisk(int DriveIndex
)
78 Log("CleanDiskByDiskpart <%d>", DriveIndex
);
80 if (!IsDiskpartExist())
85 sprintf_s(CmdBuf
, sizeof(CmdBuf
), "select disk %d\r\nclean\r\n", DriveIndex
);
86 return DSPT_CommProc(CmdBuf
);
89 BOOL
DSPT_FormatVolume(char DriveLetter
, int fs
)
91 const char* fsname
= NULL
;
94 Log("FormatVolumeByDiskpart <%C:>", DriveLetter
);
96 if (!IsDiskpartExist())
110 sprintf_s(CmdBuf
, sizeof(CmdBuf
), "select volume %C:\r\nformat FS=%s LABEL=Ventoy QUICK OVERRIDE\r\n", DriveLetter
, fsname
);
111 return DSPT_CommProc(CmdBuf
);