本文整理汇总了C++中GetDiskFreeSpace函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDiskFreeSpace函数的具体用法?C++ GetDiskFreeSpace怎么用?C++ GetDiskFreeSpace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDiskFreeSpace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:identity0815,项目名称:os45,代码行数:25,代码来源:ZipPlatform.cpp
示例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;
}
开发者ID:bhaggerty,项目名称:wwiv,代码行数:65,代码来源:utility.cpp
示例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;
}
开发者ID:ericfillipe1,项目名称:shareaza-code,代码行数:55,代码来源:Downloads.cpp
示例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;
}
开发者ID:OS2World,项目名称:SYSTEM-LOADER-QSINIT,代码行数:33,代码来源:volio.c
示例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;
}
开发者ID:Vairn,项目名称:PUAE,代码行数:28,代码来源:fsusage.c
示例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;
}
开发者ID:ppeschke,项目名称:sf2,代码行数:26,代码来源:StreamingWave.cpp
示例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;
}
开发者ID:arthurtumanyan,项目名称:squid-2.6-stable13-shaga,代码行数:33,代码来源:win32lib.c
示例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;
}
}
开发者ID:BackupTheBerlios,项目名称:bimmerbox,代码行数:31,代码来源:io.c
示例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;
}
开发者ID:LarBob,项目名称:executor,代码行数:35,代码来源:winfs.c
示例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);
}
}
开发者ID:RickLeinecker,项目名称:WinSlacker,代码行数:29,代码来源:WinSlacker.cpp
示例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;
}
开发者ID:glaubitz,项目名称:kcemu-debian,代码行数:32,代码来源:sys_getdiskinfo.c
示例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_;
}
}
}
开发者ID:Cyaagain,项目名称:thrill,代码行数:33,代码来源:wfs_file_base.cpp
示例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;
}
开发者ID:GHubgenius,项目名称:FreeRDP,代码行数:30,代码来源:statvfs.c
示例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;
开发者ID:mpapierski,项目名称:from-hdd-lg-to-pc,代码行数:35,代码来源:hdd_lg_copy.cpp
示例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;
}
开发者ID:dcashman,项目名称:Coursework,代码行数:26,代码来源:FileSystemExperiment.cpp
示例16: MyGetDiskFreeSpace
__int64 MyGetDiskFreeSpace(const char *lpszRoot) {
__int64 client_free, total_space, free_space;
DWORD dwSectorsPerCluster, dwBytesPerSector, dwFreeClusters, dwTotalClusters;
char tmp[MAX_PATH];
if (!g_hInstKernel32 && !(g_hInstKernel32 = LoadLibrary("kernel32.dll")))
return -1;
if (!g_triedGetDiskFreeSpaceEx) {
g_fpGetDiskFreeSpaceEx = (BOOL (__stdcall *)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER))GetProcAddress(g_hInstKernel32, "GetDiskFreeSpaceExA");
g_triedGetDiskFreeSpaceEx = true;
}
lpszRoot = SplitPathRoot(tmp, lpszRoot);
if (g_fpGetDiskFreeSpaceEx) {
return g_fpGetDiskFreeSpaceEx(lpszRoot, (PULARGE_INTEGER)&client_free, (PULARGE_INTEGER)&total_space, (PULARGE_INTEGER)&free_space)
? free_space
: -1;
} else {
return GetDiskFreeSpace(lpszRoot, &dwSectorsPerCluster, &dwBytesPerSector, &dwFreeClusters, &dwTotalClusters)
? dwFreeClusters * dwSectorsPerCluster * dwBytesPerSector
: -1;
}
}
开发者ID:darealshinji,项目名称:Moitah.net,代码行数:25,代码来源:oshelper.cpp
示例17: php_disk_total_space
static int php_disk_total_space(char *path, double *space) /* {{{ */
#if defined(WINDOWS) /* {{{ */
{
double bytestotal = 0;
HINSTANCE kernel32;
FARPROC gdfse;
typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
gdfse_func func;
/* These are used by GetDiskFreeSpaceEx, if available. */
ULARGE_INTEGER FreeBytesAvailableToCaller;
ULARGE_INTEGER TotalNumberOfBytes;
ULARGE_INTEGER TotalNumberOfFreeBytes;
/* These are used by GetDiskFreeSpace otherwise. */
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
/* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2,
so we have to jump through some hoops to see if the function
exists. */
kernel32 = LoadLibrary("kernel32.dll");
if (kernel32) {
gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
/* It's available, so we can call it. */
if (gdfse) {
func = (gdfse_func)gdfse;
if (func(path,
&FreeBytesAvailableToCaller,
&TotalNumberOfBytes,
&TotalNumberOfFreeBytes) == 0) {
php_error_docref(NULL, E_WARNING, "%s", php_win_err());
return FAILURE;
}
/* i know - this is ugly, but i works <[email protected]> */
bytestotal = TotalNumberOfBytes.HighPart *
(double) (((zend_ulong)1) << 31) * 2.0 +
TotalNumberOfBytes.LowPart;
} else { /* If it's not available, we just use GetDiskFreeSpace */
if (GetDiskFreeSpace(path,
&SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters) == 0) {
php_error_docref(NULL, E_WARNING, "%s", php_win_err());
return FAILURE;
}
bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector;
}
} else {
php_error_docref(NULL, E_WARNING, "Unable to load kernel32.dll");
return FAILURE;
}
*space = bytestotal;
return SUCCESS;
}
开发者ID:Distrotech,项目名称:php-src,代码行数:58,代码来源:filestat.c
示例18: BLI_dir_free_space
/* Not actually used anywhere.
*/
double BLI_dir_free_space(const char *dir)
{
#ifdef WIN32
DWORD sectorspc, bytesps, freec, clusters;
char tmp[4];
tmp[0] = '\\'; tmp[1] = 0; /* Just a failsafe */
if (dir[0] == '/' || dir[0] == '\\') {
tmp[0] = '\\';
tmp[1] = 0;
}
else if (dir[1] == ':') {
tmp[0] = dir[0];
tmp[1] = ':';
tmp[2] = '\\';
tmp[3] = 0;
}
GetDiskFreeSpace(tmp, §orspc, &bytesps, &freec, &clusters);
return (double) (freec * bytesps * sectorspc);
#else
#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
struct statvfs disk;
#else
struct statfs disk;
#endif
char name[FILE_MAXDIR], *slash;
int len = strlen(dir);
if (len >= FILE_MAXDIR) /* path too long */
return -1;
strcpy(name, dir);
if (len) {
slash = strrchr(name, '/');
if (slash) slash[1] = 0;
}
else {
strcpy(name, "/");
}
#if defined(__FreeBSD__) || defined(__linux__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__GNU__) || defined(__GLIBC__)
if (statfs(name, &disk)) return(-1);
#endif
#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
if (statvfs(name, &disk)) return(-1);
#elif !defined(__FreeBSD__) && !defined(__linux__) && (defined(__sparc) || defined(__sparc__))
/* WARNING - This may not be supported by geeneric unix os's - Campbell */
if (statfs(name, &disk, sizeof(struct statfs), 0)) return(-1);
#endif
return ( ((double) disk.f_bsize) * ((double) disk.f_bfree));
#endif
}
开发者ID:Eibriel,项目名称:kiriblender,代码行数:60,代码来源:storage.c
示例19: sprintf
/////////////////////////////////////////////////////////////////////
// GetDiskInfo => 드라이브에 대한 정보를 얻어온다. (단위 MB)
// szDriveName : 드라이브 명
// dwTotalDriveMB : 해당 드라이브 전체 용량
// dwFreeDriveMB : 해당 드라이브 남은 용량(사용가능)
// return value : 성공하면 true 리턴, false => szDriveName이 디스크 드라이브명이 아닐 경우
/////////////////////////////////////////////////////////////////////
bool MBMatchSystemInfo::GetDiskInfo(char szDriveName, DWORD* dwTotalDriveMB, DWORD* dwFreeDriveMB)
{
#ifdef _MONITORING
char strDirveName[MAX_PATH] = {0};
sprintf(strDirveName, "%c:", szDriveName);
unsigned int uDrvType = GetDriveType(strDirveName);
if (uDrvType != DRIVE_FIXED) // 디스크 드라이버인 경우만
{
return false;
}
typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
P_GDFSE pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");
DWORD dwVolumeSerialNumber = 0;
DWORD dwMaxNameLength = 0;
DWORD dwFileSystemFlags = 0;
char szFileSysName[MAX_PATH] = {0};
char szLabel[MAX_PATH] = {0};
// GetVolumeInformation은 해당 디스크의 일반정보를 가지고 오는 함수이다.
GetVolumeInformation(strDirveName, szLabel, 256, &dwVolumeSerialNumber, &dwMaxNameLength, &dwFileSystemFlags, szFileSysName, 256);
BOOL fResult;
unsigned __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
DWORD dwTotalMBytes, dwFreeMBytes;
// 만약 95이상의 파일 시스템 일경우
if (pGetDiskFreeSpaceEx)
{
// Win98 or NT 나 그 이상이면 True 값을 반환한다.
fResult = pGetDiskFreeSpaceEx(strDirveName, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes);
if (fResult)
{
dwTotalMBytes = (DWORD)(i64TotalBytes / (1024 * 1024));
dwFreeMBytes = (DWORD)(i64FreeBytes / (1024 * 1024));
}
}
// 만약 95이하의 시스템 일경우
else
{
fResult = GetDiskFreeSpace(strDirveName, &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters);
if (fResult)
{
i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust * dwBytesPerSect;
i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust * dwBytesPerSect;
dwTotalMBytes = (DWORD)(i64TotalBytes / (1024 * 1024));
dwFreeMBytes = (DWORD)(i64FreeBytes / (1024 * 1024));
}
}
*dwTotalDriveMB = dwTotalMBytes;
*dwFreeDriveMB = dwFreeMBytes;
#endif
return true;
}
开发者ID:roseon,项目名称:life-marvelous,代码行数:64,代码来源:MBMatchSystemInfo.cpp
示例20: DosQueryFSInfo
APIRET os2APIENTRY DosQueryFSInfo(ULONG disknum,
ULONG infolevel,
PVOID pBuf,
ULONG /*cbBuf*/)
{
if(infolevel!=FSIL_ALLOC && infolevel!=FSIL_VOLSER)
return 87; //invalid parameter
char root[MAX_PATH];
if(disknum==0) {
GetCurrentDirectory(MAX_PATH,root);
if(root[0]=='\\' || root[1]!=':')
return 15; //invalid drive
root[3]='\0';
} else {
root[0]=(char)(disknum+'A'-1);
root[1]=':';
root[2]='\\';
root[4]='\0';
}
if(infolevel==FSIL_ALLOC) {
DWORD sectorsPerCluster;
DWORD bytesPerSector;
DWORD freeClusters;
DWORD clusters;
if(!GetDiskFreeSpace(root,§orsPerCluster,&bytesPerSector,&freeClusters,&clusters))
return (APIRET)GetLastError();
FSALLOCATE *pfsa=(FSALLOCATE*)pBuf;
pfsa->idFileSystem = 0;
pfsa->cSectorUnit = (ULONG)sectorsPerCluster;
pfsa->cUnit = (ULONG)clusters;
pfsa->cUnitAvail = (ULONG)freeClusters;
pfsa->cbSector = (USHORT)bytesPerSector;
} else {
char volumeNameBuffer[256];
DWORD volumeSerialNumber, maxComponentLength,fsf;
char fsName[256];
if(!GetVolumeInformation(root,
volumeNameBuffer,256,
&volumeSerialNumber,
&maxComponentLength,
&fsf,
fsName,256
))
return (APIRET)GetLastError();
FSINFO *pfsinfo = (FSINFO*)pBuf;
//the toolkit doc is wrong
//pfsinfo->ulVSN = (ULONG)volumeSerialNumber;
*((DWORD*)pfsinfo) = volumeSerialNumber;
pfsinfo->vol.cch = (os2BYTE)strlen(volumeNameBuffer);
strcpy(pfsinfo->vol.szVolLabel,volumeNameBuffer);
}
return 0;
}
开发者ID:ErisBlastar,项目名称:osfree,代码行数:57,代码来源:filemgr4.cpp
注:本文中的GetDiskFreeSpace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论