ReactOS  0.4.13-dev-257-gfabbd7c
diskspace.c
Go to the documentation of this file.
1 /*
2  * SetupAPI DiskSpace functions
3  *
4  * Copyright 2004 CodeWeavers (Aric Stewart)
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "setupapi_private.h"
22 
23 typedef struct {
24  WCHAR lpzName[20];
28 
29 typedef struct {
31  DRIVE_ENTRY Drives[26];
33 
34 
35 /***********************************************************************
36  * SetupCreateDiskSpaceListW (SETUPAPI.@)
37  */
39 {
40  WCHAR drives[255];
41  DWORD rc;
42  WCHAR *ptr;
44 
45  TRACE("(%p, %u, 0x%08x)\n", Reserved1, Reserved2, Flags);
46 
48  {
50  return NULL;
51  }
52 
53  rc = GetLogicalDriveStringsW(255,drives);
54 
55  if (rc == 0)
56  return NULL;
57 
59 
60  list->dwDriveCount = 0;
61 
62  ptr = drives;
63 
64  while (*ptr)
65  {
67  if (type == DRIVE_FIXED)
68  {
69  DWORD clusters;
70  DWORD sectors;
71  DWORD bytes;
72  DWORD total;
73  lstrcpyW(list->Drives[list->dwDriveCount].lpzName,ptr);
74  GetDiskFreeSpaceW(ptr,&sectors,&bytes,&clusters,&total);
75  list->Drives[list->dwDriveCount].dwFreeSpace = clusters * sectors *
76  bytes;
77  list->Drives[list->dwDriveCount].dwWantedSpace = 0;
78  list->dwDriveCount++;
79  }
80  ptr += lstrlenW(ptr) + 1;
81  }
82  return list;
83 }
84 
85 
86 /***********************************************************************
87  * SetupCreateDiskSpaceListA (SETUPAPI.@)
88  */
90 {
92 }
93 
94 /***********************************************************************
95  * SetupDuplicateDiskSpaceListW (SETUPAPI.@)
96  */
98 {
99  DISKSPACELIST *list_copy, *list_original = DiskSpace;
100 
101  if (Reserved1 || Reserved2 || Flags)
102  {
104  return NULL;
105  }
106 
107  if (!DiskSpace)
108  {
110  return NULL;
111  }
112 
113  list_copy = HeapAlloc(GetProcessHeap(), 0, sizeof(DISKSPACELIST));
114  if (!list_copy)
115  {
117  return NULL;
118  }
119 
120  *list_copy = *list_original;
121 
122  return list_copy;
123 }
124 
125 /***********************************************************************
126  * SetupDuplicateDiskSpaceListA (SETUPAPI.@)
127  */
129 {
131 }
132 
133 /***********************************************************************
134  * SetupAddInstallSectionToDiskSpaceListA (SETUPAPI.@)
135  */
137  HINF InfHandle, HINF LayoutInfHandle,
138  LPCSTR SectionName, PVOID Reserved1, UINT Reserved2)
139 {
140  FIXME ("Stub\n");
141  return TRUE;
142 }
143 
144 /***********************************************************************
145 * SetupQuerySpaceRequiredOnDriveW (SETUPAPI.@)
146 */
148  LPCWSTR DriveSpec, LONGLONG *SpaceRequired,
150 {
151  WCHAR *driveW;
152  unsigned int i;
153  LPDISKSPACELIST list = DiskSpace;
154  BOOL rc = FALSE;
155  static const WCHAR bkslsh[]= {'\\',0};
156 
157  if (!DiskSpace)
158  {
160  return FALSE;
161  }
162 
163  if (!DriveSpec)
164  {
166  return FALSE;
167  }
168 
169  driveW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(DriveSpec) + 2) * sizeof(WCHAR));
170  if (!driveW)
171  {
173  return FALSE;
174  }
175 
176  lstrcpyW(driveW,DriveSpec);
177  lstrcatW(driveW,bkslsh);
178 
179  TRACE("Looking for drive %s\n",debugstr_w(driveW));
180 
181  for (i = 0; i < list->dwDriveCount; i++)
182  {
183  TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName));
184  if (lstrcmpW(driveW,list->Drives[i].lpzName)==0)
185  {
186  rc = TRUE;
187  *SpaceRequired = list->Drives[i].dwWantedSpace;
188  break;
189  }
190  }
191 
192  HeapFree(GetProcessHeap(), 0, driveW);
193 
195  return rc;
196 }
197 
198 /***********************************************************************
199 * SetupQuerySpaceRequiredOnDriveA (SETUPAPI.@)
200 */
202  LPCSTR DriveSpec, LONGLONG *SpaceRequired,
204 {
205  DWORD len;
206  LPWSTR DriveSpecW;
207  BOOL ret;
208 
209  /* The parameter validation checks are in a different order from the
210  * Unicode variant of SetupQuerySpaceRequiredOnDrive. */
211  if (!DriveSpec)
212  {
214  return FALSE;
215  }
216 
217  if (!DiskSpace)
218  {
220  return FALSE;
221  }
222 
223  len = MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, NULL, 0);
224 
225  DriveSpecW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
226  if (!DriveSpecW)
227  {
229  return FALSE;
230  }
231 
232  MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, DriveSpecW, len);
233 
234  ret = SetupQuerySpaceRequiredOnDriveW(DiskSpace, DriveSpecW, SpaceRequired,
236 
237  HeapFree(GetProcessHeap(), 0, DriveSpecW);
238 
239  return ret;
240 }
241 
242 /***********************************************************************
243 * SetupDestroyDiskSpaceList (SETUPAPI.@)
244 */
246 {
247  LPDISKSPACELIST list = (LPDISKSPACELIST)DiskSpace;
249  return TRUE;
250 }
251 
252 /***********************************************************************
253 * SetupAddToDiskSpaceListA (SETUPAPI.@)
254 */
256  LONGLONG filesize, UINT operation,
257  PVOID reserved1, UINT reserved2)
258 {
259  FIXME(": stub\n");
261  return FALSE;
262 }
263 
264 /***********************************************************************
265 * SetupAddToDiskSpaceListW (SETUPAPI.@)
266 */
268  LONGLONG filesize, UINT operation,
269  PVOID reserved1, UINT reserved2)
270 {
271  FIXME(": stub\n");
273  return FALSE;
274 }
BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile, LONGLONG filesize, UINT operation, PVOID reserved1, UINT reserved2)
Definition: diskspace.c:267
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define SPDSL_IGNORE_DISK
Definition: setupapi.h:538
const uint16_t * PCWSTR
Definition: typedefs.h:55
BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace, LPCSTR DriveSpec, LONGLONG *SpaceRequired, PVOID Reserved1, UINT Reserved2)
Definition: diskspace.c:201
#define TRUE
Definition: types.h:120
HDSKSPC WINAPI SetupCreateDiskSpaceListA(PVOID Reserved1, DWORD Reserved2, UINT Flags)
Definition: diskspace.c:89
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
Definition: diskspace.c:245
BOOL WINAPI SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace, HINF InfHandle, HINF LayoutInfHandle, LPCSTR SectionName, PVOID Reserved1, UINT Reserved2)
Definition: diskspace.c:136
#define CP_ACP
Definition: compat.h:99
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define lstrlenW
Definition: compat.h:407
HDSKSPC WINAPI SetupDuplicateDiskSpaceListW(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
Definition: diskspace.c:97
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
struct DRIVE_ENTRY * LPDRIVE_ENTRY
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetupAddToDiskSpaceListA(HDSKSPC diskspace, PCSTR targetfile, LONGLONG filesize, UINT operation, PVOID reserved1, UINT reserved2)
Definition: diskspace.c:255
BOOL WINAPI SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace, LPCWSTR DriveSpec, LONGLONG *SpaceRequired, PVOID Reserved1, UINT Reserved2)
Definition: diskspace.c:147
const char * LPCSTR
Definition: xmlstorage.h:183
HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT Flags)
Definition: diskspace.c:38
Definition: bcd.h:202
int64_t LONGLONG
Definition: typedefs.h:66
BOOL WINAPI GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:173
#define TRACE(s)
Definition: solgame.cpp:4
uint8_t reserved2[12]
Definition: fsck.fat.h:58
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
HDSKSPC WINAPI SetupDuplicateDiskSpaceListA(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
Definition: diskspace.c:128
int ret
#define ERROR_INVALID_DRIVE
Definition: winerror.h:118
GLenum GLsizei len
Definition: glext.h:6722
Definition: _list.h:228
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define DRIVE_FIXED
Definition: winbase.h:249
DWORD dwDriveCount
Definition: diskspace.c:30
struct DISKSPACELIST * LPDISKSPACELIST
#define lstrcpyW
Definition: compat.h:406
LONGLONG dwWantedSpace
Definition: diskspace.c:26
LONGLONG dwFreeSpace
Definition: diskspace.c:25
#define list
Definition: rosglue.h:35
unsigned int UINT
Definition: ndis.h:50
__u8 sectors[2]
Definition: mkdosfs.c:366
Definition: bcd.h:201
#define MultiByteToWideChar
Definition: compat.h:100
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
Definition: diskspace.c:23
const char * PCSTR
Definition: typedefs.h:51
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
DWORD WINAPI GetLogicalDriveStringsW(IN DWORD nBufferLength, IN LPWSTR lpBuffer)
Definition: disk.c:73