ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

diskspace.c
Go to the documentation of this file.
00001 /*
00002  * SetupAPI DiskSpace functions
00003  *
00004  * Copyright 2004 CodeWeavers (Aric Stewart)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "setupapi_private.h"
00022 
00023 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
00024 
00025 typedef struct {
00026     WCHAR   lpzName[20];
00027     LONGLONG dwFreeSpace;
00028     LONGLONG dwWantedSpace;
00029 } DRIVE_ENTRY, *LPDRIVE_ENTRY;
00030 
00031 typedef struct {
00032     DWORD   dwDriveCount;
00033     DRIVE_ENTRY Drives[26];
00034 } DISKSPACELIST, *LPDISKSPACELIST;
00035 
00036 
00037 /***********************************************************************
00038  *      SetupCreateDiskSpaceListW  (SETUPAPI.@)
00039  */
00040 HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT Flags)
00041 {
00042     WCHAR drives[255];
00043     DWORD rc;
00044     WCHAR *ptr;
00045     LPDISKSPACELIST list=NULL;
00046 
00047     TRACE("(%p, %u, 0x%08x)\n", Reserved1, Reserved2, Flags);
00048 
00049     if (Reserved1 || Reserved2 || Flags & ~SPDSL_IGNORE_DISK)
00050     {
00051         SetLastError(ERROR_INVALID_PARAMETER);
00052         return NULL;
00053     }
00054 
00055     rc = GetLogicalDriveStringsW(255,drives);
00056 
00057     if (rc == 0)
00058         return NULL;
00059 
00060     list = HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST));
00061 
00062     list->dwDriveCount = 0;
00063 
00064     ptr = drives;
00065 
00066     while (*ptr)
00067     {
00068         DWORD type = GetDriveTypeW(ptr);
00069         if (type == DRIVE_FIXED)
00070         {
00071             DWORD clusters;
00072             DWORD sectors;
00073             DWORD bytes;
00074             DWORD total;
00075             lstrcpyW(list->Drives[list->dwDriveCount].lpzName,ptr);
00076             GetDiskFreeSpaceW(ptr,&sectors,&bytes,&clusters,&total);
00077             list->Drives[list->dwDriveCount].dwFreeSpace = clusters * sectors *
00078                                                            bytes;
00079             list->Drives[list->dwDriveCount].dwWantedSpace = 0;
00080             list->dwDriveCount++;
00081         }
00082        ptr += lstrlenW(ptr) + 1;
00083     }
00084     return list;
00085 }
00086 
00087 
00088 /***********************************************************************
00089  *      SetupCreateDiskSpaceListA  (SETUPAPI.@)
00090  */
00091 HDSKSPC WINAPI SetupCreateDiskSpaceListA(PVOID Reserved1, DWORD Reserved2, UINT Flags)
00092 {
00093     return SetupCreateDiskSpaceListW( Reserved1, Reserved2, Flags );
00094 }
00095 
00096 /***********************************************************************
00097  *      SetupDuplicateDiskSpaceListW  (SETUPAPI.@)
00098  */
00099 HDSKSPC WINAPI SetupDuplicateDiskSpaceListW(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
00100 {
00101     DISKSPACELIST *list_copy, *list_original = DiskSpace;
00102 
00103     if (Reserved1 || Reserved2 || Flags)
00104     {
00105         SetLastError(ERROR_INVALID_PARAMETER);
00106         return NULL;
00107     }
00108 
00109     if (!DiskSpace)
00110     {
00111         SetLastError(ERROR_INVALID_HANDLE);
00112         return NULL;
00113     }
00114 
00115     list_copy = HeapAlloc(GetProcessHeap(), 0, sizeof(DISKSPACELIST));
00116     if (!list_copy)
00117     {
00118         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00119         return NULL;
00120     }
00121 
00122     *list_copy = *list_original;
00123 
00124     return list_copy;
00125 }
00126 
00127 /***********************************************************************
00128  *      SetupDuplicateDiskSpaceListA  (SETUPAPI.@)
00129  */
00130 HDSKSPC WINAPI SetupDuplicateDiskSpaceListA(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
00131 {
00132     return SetupDuplicateDiskSpaceListW(DiskSpace, Reserved1, Reserved2, Flags);
00133 }
00134 
00135 /***********************************************************************
00136  *      SetupAddInstallSectionToDiskSpaceListA  (SETUPAPI.@)
00137  */
00138 BOOL WINAPI SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace,
00139                         HINF InfHandle, HINF LayoutInfHandle,
00140                         LPCSTR SectionName, PVOID Reserved1, UINT Reserved2)
00141 {
00142     FIXME ("Stub\n");
00143     return TRUE;
00144 }
00145 
00146 /***********************************************************************
00147 *       SetupQuerySpaceRequiredOnDriveW  (SETUPAPI.@)
00148 */
00149 BOOL WINAPI SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace,
00150                         LPCWSTR DriveSpec, LONGLONG *SpaceRequired,
00151                         PVOID Reserved1, UINT Reserved2)
00152 {
00153     WCHAR *driveW;
00154     unsigned int i;
00155     LPDISKSPACELIST list = DiskSpace;
00156     BOOL rc = FALSE;
00157     static const WCHAR bkslsh[]= {'\\',0};
00158 
00159     if (!DiskSpace)
00160     {
00161         SetLastError(ERROR_INVALID_HANDLE);
00162         return FALSE;
00163     }
00164 
00165     if (!DriveSpec)
00166     {
00167         SetLastError(ERROR_INVALID_PARAMETER);
00168         return FALSE;
00169     }
00170 
00171     driveW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(DriveSpec) + 2) * sizeof(WCHAR));
00172     if (!driveW)
00173     {
00174         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00175         return FALSE;
00176     }
00177 
00178     lstrcpyW(driveW,DriveSpec);
00179     lstrcatW(driveW,bkslsh);
00180 
00181     TRACE("Looking for drive %s\n",debugstr_w(driveW));
00182  
00183     for (i = 0; i < list->dwDriveCount; i++)
00184     {
00185         TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName));
00186         if (lstrcmpW(driveW,list->Drives[i].lpzName)==0)
00187         {
00188             rc = TRUE;
00189             *SpaceRequired = list->Drives[i].dwWantedSpace;
00190             break;
00191         }
00192     }
00193 
00194     HeapFree(GetProcessHeap(), 0, driveW);
00195 
00196     if (!rc) SetLastError(ERROR_INVALID_DRIVE);
00197     return rc;
00198 }
00199 
00200 /***********************************************************************
00201 *       SetupQuerySpaceRequiredOnDriveA  (SETUPAPI.@)
00202 */
00203 BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
00204                         LPCSTR DriveSpec, LONGLONG *SpaceRequired,
00205                         PVOID Reserved1, UINT Reserved2)
00206 {
00207     DWORD len;
00208     LPWSTR DriveSpecW;
00209     BOOL ret;
00210 
00211     /* The parameter validation checks are in a different order from the
00212      * Unicode variant of SetupQuerySpaceRequiredOnDrive. */
00213     if (!DriveSpec)
00214     {
00215         SetLastError(ERROR_INVALID_PARAMETER);
00216         return FALSE;
00217     }
00218 
00219     if (!DiskSpace)
00220     {
00221         SetLastError(ERROR_INVALID_HANDLE);
00222         return FALSE;
00223     }
00224 
00225     len = MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, NULL, 0);
00226 
00227     DriveSpecW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
00228     if (!DriveSpecW)
00229     {
00230         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00231         return FALSE;
00232     }
00233 
00234     MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, DriveSpecW, len);
00235 
00236     ret = SetupQuerySpaceRequiredOnDriveW(DiskSpace, DriveSpecW, SpaceRequired,
00237                                           Reserved1, Reserved2);
00238 
00239     HeapFree(GetProcessHeap(), 0, DriveSpecW);
00240 
00241     return ret;
00242 }
00243 
00244 /***********************************************************************
00245 *       SetupDestroyDiskSpaceList  (SETUPAPI.@)
00246 */
00247 BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
00248 {
00249     LPDISKSPACELIST list = (LPDISKSPACELIST)DiskSpace;
00250     HeapFree(GetProcessHeap(),0,list);
00251     return TRUE;
00252 }

Generated on Sun May 27 2012 04:26:12 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.