2 * SetupAPI DiskSpace functions
4 * Copyright 2004 CodeWeavers (Aric Stewart)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
37 LONGLONG dwWantedSpace
;
38 } DRIVE_ENTRY
, *LPDRIVE_ENTRY
;
42 DRIVE_ENTRY Drives
[26];
43 } DISKSPACELIST
, *LPDISKSPACELIST
;
46 /***********************************************************************
47 * SetupCreateDiskSpaceListW (SETUPAPI.@)
49 HDSKSPC WINAPI
SetupCreateDiskSpaceListW(PVOID Reserved1
, DWORD Reserved2
, UINT Flags
)
54 LPDISKSPACELIST list
=NULL
;
56 TRACE("(%p, %u, 0x%08x)\n", Reserved1
, Reserved2
, Flags
);
58 if (Reserved1
|| Reserved2
|| Flags
& ~SPDSL_IGNORE_DISK
)
60 SetLastError(ERROR_INVALID_PARAMETER
);
64 rc
= GetLogicalDriveStringsW(255,drives
);
69 list
= HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST
));
71 list
->dwDriveCount
= 0;
77 DWORD type
= GetDriveTypeW(ptr
);
78 if (type
== DRIVE_FIXED
)
84 lstrcpyW(list
->Drives
[list
->dwDriveCount
].lpzName
,ptr
);
85 GetDiskFreeSpaceW(ptr
,§ors
,&bytes
,&clusters
,&total
);
86 list
->Drives
[list
->dwDriveCount
].dwFreeSpace
= clusters
* sectors
*
88 list
->Drives
[list
->dwDriveCount
].dwWantedSpace
= 0;
91 ptr
+= lstrlenW(ptr
) + 1;
97 /***********************************************************************
98 * SetupCreateDiskSpaceListA (SETUPAPI.@)
100 HDSKSPC WINAPI
SetupCreateDiskSpaceListA(PVOID Reserved1
, DWORD Reserved2
, UINT Flags
)
102 return SetupCreateDiskSpaceListW( Reserved1
, Reserved2
, Flags
);
105 /***********************************************************************
106 * SetupDuplicateDiskSpaceListW (SETUPAPI.@)
108 HDSKSPC WINAPI
SetupDuplicateDiskSpaceListW(HDSKSPC DiskSpace
, PVOID Reserved1
, DWORD Reserved2
, UINT Flags
)
110 DISKSPACELIST
*list_copy
, *list_original
= DiskSpace
;
112 if (Reserved1
|| Reserved2
|| Flags
)
114 SetLastError(ERROR_INVALID_PARAMETER
);
120 SetLastError(ERROR_INVALID_HANDLE
);
124 list_copy
= HeapAlloc(GetProcessHeap(), 0, sizeof(DISKSPACELIST
));
127 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
131 *list_copy
= *list_original
;
136 /***********************************************************************
137 * SetupDuplicateDiskSpaceListA (SETUPAPI.@)
139 HDSKSPC WINAPI
SetupDuplicateDiskSpaceListA(HDSKSPC DiskSpace
, PVOID Reserved1
, DWORD Reserved2
, UINT Flags
)
141 return SetupDuplicateDiskSpaceListW(DiskSpace
, Reserved1
, Reserved2
, Flags
);
144 /***********************************************************************
145 * SetupAddInstallSectionToDiskSpaceListA (SETUPAPI.@)
147 BOOL WINAPI
SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace
,
148 HINF InfHandle
, HINF LayoutInfHandle
,
149 LPCSTR SectionName
, PVOID Reserved1
, UINT Reserved2
)
155 /***********************************************************************
156 * SetupQuerySpaceRequiredOnDriveW (SETUPAPI.@)
158 BOOL WINAPI
SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace
,
159 LPCWSTR DriveSpec
, LONGLONG
*SpaceRequired
,
160 PVOID Reserved1
, UINT Reserved2
)
164 LPDISKSPACELIST list
= DiskSpace
;
166 static const WCHAR bkslsh
[]= {'\\',0};
170 SetLastError(ERROR_INVALID_HANDLE
);
176 SetLastError(ERROR_INVALID_PARAMETER
);
180 driveW
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(DriveSpec
) + 2) * sizeof(WCHAR
));
183 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
187 lstrcpyW(driveW
,DriveSpec
);
188 lstrcatW(driveW
,bkslsh
);
190 TRACE("Looking for drive %s\n",debugstr_w(driveW
));
192 for (i
= 0; i
< list
->dwDriveCount
; i
++)
194 TRACE("checking drive %s\n",debugstr_w(list
->Drives
[i
].lpzName
));
195 if (lstrcmpW(driveW
,list
->Drives
[i
].lpzName
)==0)
198 *SpaceRequired
= list
->Drives
[i
].dwWantedSpace
;
203 HeapFree(GetProcessHeap(), 0, driveW
);
205 if (!rc
) SetLastError(ERROR_INVALID_DRIVE
);
209 /***********************************************************************
210 * SetupQuerySpaceRequiredOnDriveA (SETUPAPI.@)
212 BOOL WINAPI
SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace
,
213 LPCSTR DriveSpec
, LONGLONG
*SpaceRequired
,
214 PVOID Reserved1
, UINT Reserved2
)
220 /* The parameter validation checks are in a different order from the
221 * Unicode variant of SetupQuerySpaceRequiredOnDrive. */
224 SetLastError(ERROR_INVALID_PARAMETER
);
230 SetLastError(ERROR_INVALID_HANDLE
);
234 len
= MultiByteToWideChar(CP_ACP
, 0, DriveSpec
, -1, NULL
, 0);
236 DriveSpecW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
239 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
243 MultiByteToWideChar(CP_ACP
, 0, DriveSpec
, -1, DriveSpecW
, len
);
245 ret
= SetupQuerySpaceRequiredOnDriveW(DiskSpace
, DriveSpecW
, SpaceRequired
,
246 Reserved1
, Reserved2
);
248 HeapFree(GetProcessHeap(), 0, DriveSpecW
);
253 /***********************************************************************
254 * SetupDestroyDiskSpaceList (SETUPAPI.@)
256 BOOL WINAPI
SetupDestroyDiskSpaceList(HDSKSPC DiskSpace
)
258 LPDISKSPACELIST list
= DiskSpace
;
259 HeapFree(GetProcessHeap(),0,list
);