本文整理汇总了C++中GetDiskFreeSpace函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDiskFreeSpace函数的具体用法?C++ GetDiskFreeSpace怎么用?C++ GetDiskFreeSpace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDiskFreeSpace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zpc
DWORD ZipPlatform::GetDeviceFreeSpace(LPCTSTR lpszPath)
{
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
CZipPathComponent zpc (lpszPath);
CZipString szDrive = zpc.GetFileDrive();
if (!GetDiskFreeSpace(
szDrive,
&SectorsPerCluster,
&BytesPerSector,
&NumberOfFreeClusters,
&TotalNumberOfClusters))
{
CZipPathComponent::AppendSeparator(szDrive); // in spite of what is written in MSDN it is sometimes needed (on fixed disks)
if (!GetDiskFreeSpace(
szDrive,
&SectorsPerCluster,
&BytesPerSector,
&NumberOfFreeClusters,
&TotalNumberOfClusters))
return 0;
}
__int64 total = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters;
return (DWORD)total;
}
示例2: WOSD_FreeSpaceForDriveLetter
/**
* Returns the free disk space for a drive letter, where nDrive is the drive number
* 1 = 'A', 2 = 'B', etc.
*
* @param nDrive The drive number to get the free disk space for.
*/
double WOSD_FreeSpaceForDriveLetter(int nDrive)
{
unsigned __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
P_GDFSE pGetDiskFreeSpaceEx = NULL;
BOOL fResult = FALSE;
pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress ( GetModuleHandle ( "kernel32.dll" ), "GetDiskFreeSpaceExA" );
char s[] = "X:\\";
s[0] = ( char ) 'A' + nDrive - 1;
char *pszDrive = ( nDrive ) ? s : NULL;
if ( pGetDiskFreeSpaceEx )
{
// win95 osr2+ allows the GetDiskFreeSpaceEx call
fResult = pGetDiskFreeSpaceEx ( pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes );
if ( !fResult )
{
fResult = pGetDiskFreeSpaceEx ( NULL,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes );
}
if ( fResult )
{
return ( double ) ( __int64 ) ( i64FreeBytesToCaller / 1024 );
}
}
else
{
// this one will artificially cap free space at 2 gigs
fResult = GetDiskFreeSpace( pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
if ( !fResult )
{
fResult = GetDiskFreeSpace( NULL,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
}
if ( fResult )
{
return ((double)(dwTotalClusters * dwSectPerClust * dwBytesPerSect))/ 1024.0;
}
}
// Nothing worked, just give up.
return -1.0;
}
示例3: BOOL
BOOL CDownloads::IsSpaceAvailable(QWORD nVolume, int nPath)
{
QWORD nMargin = 10485760;
if ( HINSTANCE hKernel = GetModuleHandle( _T("KERNEL32.DLL") ) )
{
BOOL (WINAPI *pfnGetDiskFreeSpaceEx)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
#ifdef UNICODE
(FARPROC&)pfnGetDiskFreeSpaceEx = GetProcAddress( hKernel, "GetDiskFreeSpaceExW" );
#else
(FARPROC&)pfnGetDiskFreeSpaceEx = GetProcAddress( hKernel, "GetDiskFreeSpaceExA" );
#endif
if ( pfnGetDiskFreeSpaceEx != NULL )
{
ULARGE_INTEGER nFree, nNull;
if ( ( ! nPath || nPath == dlPathIncomplete ) && (*pfnGetDiskFreeSpaceEx)( Settings.Downloads.IncompletePath, &nFree, &nNull, &nNull ) )
{
if ( nFree.QuadPart < nVolume + nMargin ) return FALSE;
}
if ( ( ! nPath || nPath == dlPathComplete ) && (*pfnGetDiskFreeSpaceEx)( Settings.Downloads.CompletePath, &nFree, &nNull, &nNull ) )
{
if ( nFree.QuadPart < nVolume + nMargin ) return FALSE;
}
return TRUE;
}
}
DWORD nSPC, nBPS, nFree, nTotal;
if ( ! nPath || nPath == dlPathIncomplete )
{
CString str = Settings.Downloads.IncompletePath.SpanExcluding( _T("\\") ) + '\\';
if ( GetDiskFreeSpace( str, &nSPC, &nBPS, &nFree, &nTotal ) )
{
QWORD nBytes = (QWORD)nSPC * (QWORD)nBPS * (QWORD)nFree;
if ( nBytes < nVolume + nMargin ) return FALSE;
}
}
if ( ! nPath || nPath == dlPathComplete )
{
CString str = Settings.Downloads.CompletePath.SpanExcluding( _T("\\") ) + '\\';
if ( GetDiskFreeSpace( str, &nSPC, &nBPS, &nFree, &nTotal ) )
{
QWORD nBytes = (QWORD)nSPC * (QWORD)nBPS * (QWORD)nFree;
if ( nBytes < nVolume + nMargin ) return FALSE;
}
}
return TRUE;
}
示例4: volume_open
Bool volume_open (char letter, volh *handle) {
char openpath[64];
HANDLE rc;
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters,
TotalNumberOfClusters, Count;
voldata *vh;
sprintf(openpath,"%c:\\",letter);
if (!GetDiskFreeSpace(openpath,&SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters)) BytesPerSector = 512;
sprintf(openpath,"\\\\.\\%c:",letter);
rc = CreateFile(openpath, FILE_WRITE_DATA|FILE_READ_DATA,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
*handle = 0;
if (rc==INVALID_HANDLE_VALUE) return False;
/** dismount is not required for FAT32 driver, but exFAT switches volume
to r/o after writing below, FSCTL_LOCK_VOLUME can`t help too.
GetLogicalDrives() after close should mount it back as MSDN says - and
it works ;) */
if (!DeviceIoControl(rc, FSCTL_DISMOUNT_VOLUME, 0, 0, 0, 0, &Count, 0))
return False;
vh = (voldata*)malloc(sizeof(voldata));
vh->dh = rc;
vh->pos = 0;
vh->ssize = BytesPerSector;
vh->volsize = 0;
vh->volsize = volume_size(vh,0);
strcpy(vh->path, openpath);
*handle = vh;
return True;
}
示例5: get_fs_usage
int get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
{
char buf2[MAX_DPATH];
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
GetFullPathName (path, sizeof buf2, buf2, NULL);
buf2[3] = 0;
if (!GetDiskFreeSpace (buf2, &SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters)) {
/* lasterror = GetLastError ();*/
return -1;
}
/* HACK ALERT! WinNT returns 0 in TotalNumberOfClusters for an audio-CD, which calls the GURU! */
if ((TotalNumberOfClusters == 0) && (GetDriveType (buf2) == DRIVE_CDROM))
TotalNumberOfClusters = 327680;
BytesPerSector *= SectorsPerCluster;
fsp->fsu_blocks = adjust_blocks (TotalNumberOfClusters, BytesPerSector, 512);
fsp->fsu_bavail = adjust_blocks (NumberOfFreeClusters, BytesPerSector, 512);
return 0;
}
示例6: WaveInfo
StreamingWave::StreamingWave(const StreamingWave& c) : WaveInfo(c)
{
file = c.file;
currentReadPass = c.currentReadPass;
currentReadBuffer = c.currentReadBuffer;
isPrepared = c.isPrepared;
dataBuffer = NULL;
sectorAlignment = c.sectorAlignment;
bufferBeginOffset = c.bufferBeginOffset;
if(sectorAlignment == 0)
{
//figure the sector alignment
DWORD dw1, dw2, dw3; //we don't care about these, they die at the end of this block
GetDiskFreeSpace( NULL, &dw1, §orAlignment, &dw2, &dw3 );
}
//allocate the buffers
dataBuffer = (BYTE*)_aligned_malloc(STREAMINGWAVE_BUFFER_COUNT * STREAMINGWAVE_BUFFER_SIZE + sectorAlignment, sectorAlignment);
memset(dataBuffer, 0, STREAMINGWAVE_BUFFER_COUNT * STREAMINGWAVE_BUFFER_SIZE + sectorAlignment);
memcpy(dataBuffer, c.dataBuffer, STREAMINGWAVE_BUFFER_COUNT * STREAMINGWAVE_BUFFER_SIZE + sectorAlignment);
memcpy(xaBuffer, c.xaBuffer, sizeof(xaBuffer));
for(int i = 0; i < STREAMINGWAVE_BUFFER_COUNT; ++i)
xaBuffer[i].pAudioData = dataBuffer + bufferBeginOffset + i * STREAMINGWAVE_BUFFER_SIZE;
}
示例7: statfs
int
statfs(const char *path, struct statfs *sfs)
{
char drive[4];
DWORD spc, bps, freec, totalc;
DWORD vsn, maxlen, flags;
if (!sfs) {
errno = EINVAL;
return -1;
}
strncpy(drive, path, 2);
drive[2] = '\0';
strcat(drive, "\\");
if (!GetDiskFreeSpace(drive, &spc, &bps, &freec, &totalc)) {
errno = ENOENT;
return -1;
}
if (!GetVolumeInformation(drive, NULL, 0, &vsn, &maxlen, &flags, NULL, 0)) {
errno = ENOENT;
return -1;
}
sfs->f_type = flags;
sfs->f_bsize = spc * bps;
sfs->f_blocks = totalc;
sfs->f_bfree = sfs->f_bavail = freec;
sfs->f_files = -1;
sfs->f_ffree = -1;
sfs->f_fsid = vsn;
sfs->f_namelen = maxlen;
return 0;
}
示例8: fat_size
void fat_size(unsigned int* size, unsigned int* free)
{
#ifdef WIN32
long secperclus, bytespersec, free_clusters, num_clusters;
if (GetDiskFreeSpace(NULL, &secperclus, &bytespersec, &free_clusters,
&num_clusters)) {
if (size)
*size = num_clusters * secperclus / 2 * (bytespersec / 512);
if (free)
*free = free_clusters * secperclus / 2 * (bytespersec / 512);
}
#else
struct statfs fs;
if (!statfs(".", &fs)) {
DEBUGF("statfs: bsize=%d blocks=%d free=%d\n",
fs.f_bsize, fs.f_blocks, fs.f_bfree);
if (size)
*size = fs.f_blocks * (fs.f_bsize / 1024);
if (free)
*free = fs.f_bfree * (fs.f_bsize / 1024);
}
#endif
else {
if (size)
*size = 0;
if (free)
*free = 0;
}
}
示例9: statfs
PUBLIC int
statfs (const char *path, struct statfs *bufp)
{
int retval;
DWORD sectors_per_cluster;
DWORD bytes_per_sector;
DWORD free_clusters;
DWORD clusters;
BOOL success;
success = GetDiskFreeSpace (path, §ors_per_cluster, &bytes_per_sector,
&free_clusters, &clusters);
if (success)
{
bufp->f_bsize = bytes_per_sector;
bufp->f_blocks = clusters * sectors_per_cluster;
bufp->f_bfree = free_clusters * sectors_per_cluster;
bufp->f_bavail = bufp->f_bfree;
bufp->f_files = 10;
#warning f_files made up
retval = 0;
}
else
{
warning_trace_info ("path = '%s'", path);
bufp->f_bsize = 512;
bufp->f_blocks = 512 * 1024 * 1024 / bufp->f_bsize;
bufp->f_bavail = 256 * 1024 * 1024 / bufp->f_bsize;
bufp->f_bfree = 256 * 1024 * 1024 / bufp->f_bsize;
bufp->f_files = 10;
retval = -1;
}
return retval;
}
示例10: SetUpDriveAccessVariables
/*
** This function sets up variables for the drive access and disk topography
** values. It also determines the device format type: NTFS or FAT32
*/
void SetUpDriveAccessVariables(char *carrierFile)
{
// Get drive letter and file format.
mountedDrive = toupper(carrierFile[0]);
// Get drive parameters such as sectors per cluster and bytes per sector.
GetDiskFreeSpace(driveRootPath,
§PerClust,
&bytesPerSect,
&freeClusters,
&totalClusters);
// We use this string to tell the Windows API which drive we are interested in
driveRootPath[0] = mountedDrive;
openDrivePath[4] = mountedDrive;
/* We need the file format so we know if it is FAT32 or NTFS. */
int errorCode = GetFileSystemFormatOf(mountedDrive, fileFormatName);
if (errorCode != 0)
{
showErrorMessage(errorCode);
exit(3);
}
}
示例11: sys_getdiskinfo
int
sys_getdiskinfo(const char *path, unsigned long *total, unsigned long *available, unsigned short *block_size)
{
ULARGE_INTEGER free, size;
DWORD bytes_per_sector, d1, d2, d3;
// Fetch the block size from the old interface as this information
// is not provided by the new one anymore.
if (GetDiskFreeSpace(path, &d1, &bytes_per_sector, &d2, &d3))
{
*block_size = bytes_per_sector;
}
else
{
*block_size = 0;
}
// The disk size is queried via the new interface that supports
// drives with more than 2GB (although we currently only support
// return values of 4GB!
if (!GetDiskFreeSpaceExA(path, &free, &size, NULL))
{
*total = 0;
*available = 0;
*block_size = 0;
return -1;
}
*available = free.QuadPart > 0xffffffffUL ? 0xffffffffUL : free.QuadPart;
*total = size.QuadPart > 0xffffffffUL ? 0xffffffffUL : size.QuadPart;
return 0;
}
示例12: file_des_
WfsFileBase::WfsFileBase(const std::string& filename, int mode)
: file_des_(INVALID_HANDLE_VALUE), mode_(mode),
filename(filename), locked(false) {
file_des_ = open_file_impl(filename, mode);
need_alignment_ = (mode& FileBase::DIRECT) != 0;
if (!(mode & NO_LOCK))
{
lock();
}
if (!(mode_ & RDONLY) && (mode & DIRECT))
{
char buf[32768], * part;
if (!GetFullPathName(filename.c_str(), sizeof(buf), buf, &part))
{
LOG1 << "wfs_file_base::wfs_file_base(): GetFullPathName() error for file " << filename;
bytes_per_sector = 512;
}
else
{
part[0] = char();
DWORD bytes_per_sector_;
if (!GetDiskFreeSpace(buf, nullptr, &bytes_per_sector_, nullptr, nullptr))
{
LOG1 << "wfs_file_base::wfs_file_base(): GetDiskFreeSpace() error for path " << buf;
bytes_per_sector = 512;
}
else
bytes_per_sector = bytes_per_sector_;
}
}
}
示例13: statvfs
int statvfs(const char *path, struct statvfs *buf)
{
BOOL res;
int len;
LPWSTR unicodestr;
DWORD lpSectorsPerCluster;
DWORD lpBytesPerSector;
DWORD lpNumberOfFreeClusters;
DWORD lpTotalNumberOfClusters;
len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
unicodestr = (LPWSTR) malloc(len);
MultiByteToWideChar(CP_ACP, 0, path, -1, unicodestr, len);
res = GetDiskFreeSpace(unicodestr, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters);
buf->f_bsize = lpBytesPerSector; /* file system block size */
buf->f_frsize = 0; /* fragment size */
buf->f_blocks = lpTotalNumberOfClusters; /* size of fs in f_frsize units */
buf->f_bfree = lpNumberOfFreeClusters; /* # free blocks */
buf->f_bavail = lpNumberOfFreeClusters; /* # free blocks for unprivileged users */
buf->f_files = 0; /* # inodes */
buf->f_ffree = 0; /* # free inodes */
buf->f_favail = 0; /* # free inodes for unprivileged users */
buf->f_fsid = lpNumberOfFreeClusters & 0xffff; /* file system ID */
buf->f_flag = 0; /* mount flags */
buf->f_namemax = 250; /* maximum filename length */
return res;
}
示例14: CopySelect
//------------------------------------------------------------------------------
static int CopySelect(void) //Копирование выбранных файлов
{
char Name_Dir[260];
if(Get_Name_Dir((Lan+94)->msg, Name_Dir, 0) < 0) return -1;//Запрос имени папки // if(Get_Name_Dir("Укажите диск или папку для записи", Name_Dir) < 0) return -1; //Запрос имени папки
UpdateWindow(MainWin); //Восстановили окно после диалога выбора файла
InitProgressBar = InitProgressBar1_2; //Функция прогресса для одного файла из группы
ProgressBar = ProgressBar2;
Close_ProgressBar = Close_ProgressBar1_2;
char Driv[MAXDRIVE], Dir[MAXPATH], Name[MAXFILE], Ext[MAXEXT], Path[MAXPATH];
fnsplit(Name_Dir, Driv, Dir, Name, Ext);
lstrcpy(Path, Driv);
lstrcat(Path, "\\");
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
if(GetDiskFreeSpace(Path, &SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters) == 0)
return ErrorSys1((Lan+46)->msg); //return ErrorSys1("Системная ошибка при запросе емкости диска.");
BytesPerClaster = SectorsPerCluster * BytesPerSector; //Число байт в кластере
numAllInCl = 0; //Суммарное число кластеров во всех копируемых файлах
numAllFi = 0; //Число копируемых файлов
num_T_Fi = 0; //Номер текущего копируемого файла
numAllOutCl = 0; //Суммарный число выходных кластеров
int l = lstrlen(Name_Dir) - 1;
if(*(Name_Dir + l) == '\\') *(Name_Dir + l) = 0; //Для имени диска косая всегда есть
if(Calc_SizeAllFile() < 0) return -1; //Вычисления для копирование выбранных файлов на диск ПК
DWORDLONG allSize = numAllOutCl * BytesPerClaster;
int ret = DiskFreeSpaceEx_F(Name_Dir, allSize); //Проверка свободного места
if(ret < 0) return -1;
if(ret == 1) return CopySelect(); //Копирование выбранной файлов на диск ПК (повторный запуск для запроса нового пути)
InitProgressBar2_2(numAllInCl, (Lan+122)->msg); //Функция прогресса для нескольких файлов // if(Get_Name_Dir("Укажите диск или папку для записи", Name_Dir) < 0) return -1; //Запрос имени папки
ret = Copy_AllFiles(Name_Dir); //Копирование выбранных файлов на диск ПК
Close_ProgressBar2_2();
return ret;
示例15: GetDiskFreeSpace
uint32_t FileSystemExperiment::GetLogicalSectorSize(const std::wstring& devicePath)
{
DWORD sectorsPerCluster;
DWORD bytesPerSector;
DWORD numberOfFreeClusters;
DWORD totalNumberOfClusters;
BOOL success;
success
= GetDiskFreeSpace(
devicePath.c_str(),
§orsPerCluster,
&bytesPerSector,
&numberOfFreeClusters,
&totalNumberOfClusters
)
;
if(!success)
{
HRESULT result = HRESULT_FROM_WIN32(GetLastError());
throw std::exception();
}
return bytesPerSector;
}