inline VolumeInfo volumeInfoForDriveLetter(const QString& driveLetter)
{
	VolumeInfo info;

	WCHAR volumeName[256], filesystemName[256];
	const DWORD error = GetVolumeInformationW((WCHAR*)driveLetter.utf16(), volumeName, 256, nullptr, nullptr, nullptr, filesystemName, 256) != 0 ? 0 : GetLastError();

	if (error != 0 && error != ERROR_NOT_READY)
	{
		qInfo() << "GetVolumeInformationW() returned error:" << ErrorStringFromLastError();
		return info;
	}
	else
		info.isReady = error != ERROR_NOT_READY;

	info.rootObjectInfo = driveLetter;

	if (info.isReady)
	{
		ULARGE_INTEGER totalSpace, freeSpace;
		if (GetDiskFreeSpaceExW((WCHAR*)driveLetter.utf16(), &freeSpace, &totalSpace, nullptr) != 0)
		{
			info.volumeSize = totalSpace.QuadPart;
			info.freeSize = freeSpace.QuadPart;
		}
		else
			qInfo() << "GetDiskFreeSpaceExW() returned error:" << ErrorStringFromLastError();
	}

	info.volumeLabel = QString::fromWCharArray(volumeName);
	info.fileSystemName = QString::fromWCharArray(filesystemName);
	return info;
}
Exemple #2
0
/*****************************************************************************
 * WCMD_dir_trailer
 *
 * Print out the trailer for the supplied drive letter
 */
static void WCMD_dir_trailer(WCHAR drive) {
    ULARGE_INTEGER avail, total, freebytes;
    DWORD status;
    WCHAR driveName[4] = {'c',':','\\','\0'};

    driveName[0] = drive;
    status = GetDiskFreeSpaceExW(driveName, &avail, &total, &freebytes);
    WINE_TRACE("Writing trailer for '%s' gave %d(%d)\n", wine_dbgstr_w(driveName),
               status, GetLastError());

    if (errorlevel==0 && !bare) {
      if (recurse) {
        static const WCHAR fmt1[] = {'\n',' ',' ',' ',' ',' ','T','o','t','a','l',' ','f','i','l','e','s',
                                     ' ','l','i','s','t','e','d',':','\n','%','8','d',' ','f','i','l','e',
                                     's','%','2','5','s',' ','b','y','t','e','s','\n','\0'};
        static const WCHAR fmt2[] = {'%','8','d',' ','d','i','r','e','c','t','o','r','i','e','s',' ','%',
                                     '1','8','s',' ','b','y','t','e','s',' ','f','r','e','e','\n','\n',
                                     '\0'};
        WCMD_output (fmt1, file_total, WCMD_filesize64 (byte_total));
        WCMD_output (fmt2, dir_total, WCMD_filesize64 (freebytes.QuadPart));
      } else {
        static const WCHAR fmt[] = {' ','%','1','8','s',' ','b','y','t','e','s',' ','f','r','e','e',
                                    '\n','\n','\0'};
        WCMD_output (fmt, WCMD_filesize64 (freebytes.QuadPart));
      }
    }
}
double VMPI_getFreeDiskSpace16(const wchar *path)
{
    ULARGE_INTEGER available;
    if(!GetDiskFreeSpaceExW(path, &available, NULL, NULL)) {
        return -1;
    }
    return static_cast<double>(available.QuadPart);
}
double VMPI_getTotalDiskSpace16(const wchar *path)
{
    ULARGE_INTEGER total;
    if(!GetDiskFreeSpaceExW(path, NULL, &total, NULL)) {
        return -1;
    }
    return static_cast<double>(total.QuadPart);
}
Exemple #5
0
static uint64_t volumeFreeSize(CFStringRef cfstringPath)
{
    WTF::String path(cfstringPath);
    ULARGE_INTEGER freeBytesToCaller;
    BOOL result = GetDiskFreeSpaceExW((LPCWSTR)path.charactersWithNullTermination(), &freeBytesToCaller, 0, 0);
    if (!result)
        return 0;
    return freeBytesToCaller.QuadPart;
}
Exemple #6
0
FileImpl::FileSizeImpl FileImpl::freeSpaceImpl() const
{
	poco_assert(!_path.empty());

	ULARGE_INTEGER space;
	if (!GetDiskFreeSpaceExW(_upath.c_str(), NULL, NULL, &space))
		handleLastErrorImpl(_path);
	return space.QuadPart;
}
BOOL My_GetDiskFreeSpaceExW()
{
	LPCWSTR lpDirectoryName=NULL;
	PULARGE_INTEGER lpFreeBytesAvailableToCaller=NULL;
	PULARGE_INTEGER lpTotalNumberOfBytes=NULL;
	PULARGE_INTEGER lpTotalNumberOfFreeBytes=NULL;
	BOOL returnVal_Real = NULL;
	BOOL returnVal_Intercepted = NULL;

	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	disableInterception();
	returnVal_Real = GetDiskFreeSpaceExW (lpDirectoryName,lpFreeBytesAvailableToCaller,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
	error_Real = GetLastError();
	enableInterception();
	returnVal_Intercepted = GetDiskFreeSpaceExW (lpDirectoryName,lpFreeBytesAvailableToCaller,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
	error_Intercepted = GetLastError();
	return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
 BOOL
 WINAPI
 MyGetDiskFreeSpaceExA(
     __in_opt  LPCSTR lpDirectoryName,
     __out_opt PULARGE_INTEGER lpFreeBytesAvailableToCaller,
     __out_opt PULARGE_INTEGER lpTotalNumberOfBytes,
     __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes
     )
 {
     return GetDiskFreeSpaceExW( FromUTF8( lpDirectoryName ), lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes );
 }
Exemple #9
0
static void
InitComboxList(HWND hDlg)
{
    HWND hwndGroupsBox = GetDlgItem(hDlg, IDC_COMBOX_DISK);
    wchar_t drives[SEAF_PATH_MAX];
    wchar_t *p;
    ULARGE_INTEGER free_space;
    ULARGE_INTEGER largest_free_space;
    int i = 0;
    int largest_disk_index = 0;

    largest_free_space.QuadPart = 0;
    SendMessage (hwndGroupsBox, CB_RESETCONTENT, 0, 0);

    GetLogicalDriveStringsW (sizeof(drives), drives);
    for (p = drives; *p != L'\0'; p += wcslen(p) + 1) {
        /* Skip floppy disk, network drive, etc */
        if (GetDriveTypeW(p) != DRIVE_FIXED)
            continue;

        if (GetDiskFreeSpaceExW (p, &free_space, NULL, NULL)) {
            if (free_space.QuadPart > largest_free_space.QuadPart) {
                largest_free_space.QuadPart = free_space.QuadPart;
                largest_disk_index = i;
            }
        } else {
            free_space.QuadPart = 0;
            applet_warning ("failed to GetDiskFreeSpaceEx(), GLE=%lu\n",
                            GetLastError());
        }

        wchar_t wbuf[128];
        wchar_t *trans;

        if (free_space.QuadPart) {
            double space = ((double)(free_space.QuadPart)) / (1024 * 1024 * 1024);

            trans = wchar_from_utf8 (_("free"));
            _snwprintf (wbuf, sizeof(wbuf) / sizeof(wchar_t),
                       L"%s\t   (%.1f GB %s)",
                       p, space, trans);
        } else {
            trans = wchar_from_utf8 (_("free space unknown"));
            _snwprintf (wbuf, sizeof(wbuf), L"%s\t   (%s)", p, trans);
        }
        g_free (trans);

        i++;

        SendMessageW (hwndGroupsBox, CB_ADDSTRING, 0, (LPARAM) wbuf);
    }

    SendDlgItemMessage (hDlg, IDC_COMBOX_DISK, CB_SETCURSEL, largest_disk_index, 0);
}
Exemple #10
0
 __int64 AmountOfFreeDiskSpace(const std::wstring& path) 
 {
     ULARGE_INTEGER available, total, free;
     if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) 
     {
         return -1;
     }
     __int64 rv = static_cast<__int64>(available.QuadPart);
     if (rv < 0)
         rv = 0x7FFFFFFFFFFFFFFF;
     return rv;
 }
int win_statvfs(const char *path, backend_statvfsstruct * buf)
{
    wchar_t *winpath;
    DWORD SectorsPerCluster;
    DWORD BytesPerSector;
    DWORD NumberOfFreeClusters;
    DWORD TotalNumberOfClusters;
    ULARGE_INTEGER FreeBytesAvailable;
    ULARGE_INTEGER TotalNumberOfBytes;
    ULARGE_INTEGER TotalNumberOfFreeBytes;

    if (!strcmp("/", path)) {
	/* Emulate root */
	buf->f_bsize = 1024;
	buf->f_blocks = 1024;
	buf->f_bfree = 0;
	buf->f_bavail = 0;
	buf->f_files = 1024;
	buf->f_ffree = 0;
	return 0;
    }

    winpath = intpath2winpath(path);
    if (!winpath) {
	errno = EINVAL;
	return -1;
    }

    winpath[3] = '\0';		       /* Cut off after x:\ */

    if (!GetDiskFreeSpaceW
	(winpath, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters,
	 &TotalNumberOfClusters)) {
	errno = EIO;
	return -1;
    }

    if (!GetDiskFreeSpaceExW
	(winpath, &FreeBytesAvailable, &TotalNumberOfBytes,
	 &TotalNumberOfFreeBytes)) {
	errno = EIO;
	return -1;
    }

    buf->f_bsize = BytesPerSector;
    buf->f_blocks = TotalNumberOfBytes.QuadPart / BytesPerSector;
    buf->f_bfree = TotalNumberOfFreeBytes.QuadPart / BytesPerSector;
    buf->f_bavail = FreeBytesAvailable.QuadPart / BytesPerSector;
    buf->f_files = buf->f_blocks / SectorsPerCluster;
    buf->f_ffree = buf->f_bfree / SectorsPerCluster;
    free(winpath);
    return 0;
}
uint64_t os_get_free_disk_space(const char *dir)
{
	wchar_t *wdir = NULL;
	if (!os_utf8_to_wcs_ptr(dir, 0, &wdir))
		return 0;

	ULARGE_INTEGER free;
	bool success = !!GetDiskFreeSpaceExW(wdir, &free, NULL, NULL);
	bfree(wdir);

	return success ? free.QuadPart : 0;
}
Exemple #13
0
 intmax_t File::freeSpace(const std::string& path) {
     ULARGE_INTEGER avail;
     if (GetDiskFreeSpaceExW(toWideString(path.c_str()).c_str(),
                            &avail,      // bytes available to caller
                            NULL,        // ptr to returned total size
                            NULL)) {     // ptr to returned total free
         return avail.QuadPart;
     }
     DWORD dosError = GetLastError();
     log() << "In File::freeSpace(), GetDiskFreeSpaceEx for '" << path
           << "' failed with " << errnoWithDescription(dosError) << std::endl;
     return -1;
 }
Exemple #14
0
void CPieView::GetDiskInfo(CString driveLetter)
{
    ULARGE_INTEGER AvailableToCaller;

    ZeroMemory(&AvailableToCaller, sizeof(ULARGE_INTEGER));

    InitMembers();

    GetDiskFreeSpaceExW((driveLetter).Left(3), &AvailableToCaller,
                        &pCapacity, &pFree);
    pUsed.QuadPart = pCapacity.QuadPart - pFree.QuadPart;

}
Exemple #15
0
static int php_disk_total_space(char *path, double *space) /* {{{ */
#if defined(WINDOWS) /* {{{ */
{
	ULARGE_INTEGER FreeBytesAvailableToCaller;
	ULARGE_INTEGER TotalNumberOfBytes;
	ULARGE_INTEGER TotalNumberOfFreeBytes;
	PHP_WIN32_IOUTIL_INIT_W(path)

	if (GetDiskFreeSpaceExW(pathw, &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) {
		php_error_docref(NULL, E_WARNING, "%s", php_win_err());
		PHP_WIN32_IOUTIL_CLEANUP_W()
		return FAILURE;
	}
Exemple #16
0
qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
{
    qlonglong size = 0;
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) 
    // the usage of statfs() is deprecated by the LSB so use statvfs().
    struct statvfs fs;
    int ret;

    ret = statvfs(qPrintable(path), &fs);

    if(ret == 0) {
        if(type == FilesystemFree) {
            size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail;
        }
        if(type == FilesystemTotal) {
            size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_blocks;
        }
        if(type == FilesystemClusterSize) {
            size = (qulonglong)fs.f_frsize;
        }
    }
#endif
#if defined(Q_OS_WIN32)
    BOOL ret;
    ULARGE_INTEGER freeAvailBytes;
    ULARGE_INTEGER totalNumberBytes;

    ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes,
            &totalNumberBytes, NULL);
    if(ret) {
        if(type == FilesystemFree) {
            size = freeAvailBytes.QuadPart;
        }
        if(type == FilesystemTotal) {
            size = totalNumberBytes.QuadPart;
        }
        if(type == FilesystemClusterSize) {
            DWORD sectorsPerCluster;
            DWORD bytesPerSector;
            DWORD freeClusters;
            DWORD totalClusters;
            ret = GetDiskFreeSpaceW((LPCTSTR)path.utf16(), &sectorsPerCluster,
                    &bytesPerSector, &freeClusters, &totalClusters);
            if(ret) {
                size = bytesPerSector * sectorsPerCluster;
            }
        }
    }
#endif
    return size;
}
Exemple #17
0
 // static
 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path)
 {
     ULARGE_INTEGER available, total, free;
     if(!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free))
     {
         return -1;
     }
     int64 rv = static_cast<int64>(available.QuadPart);
     if(rv < 0)
     {
         rv = kint64max;
     }
     return rv;
 }
Exemple #18
0
// Get drive free bytes available to the current user
uint SharedUtil::GetPathFreeSpaceMB( const SString& strPath )
{
    SString strDrive = GetPathDriveName( strPath );
    if ( !strDrive.empty() )
    {
        ULARGE_INTEGER llUserFreeBytesAvailable;
        if ( GetDiskFreeSpaceExW( FromUTF8( strDrive ), &llUserFreeBytesAvailable, NULL, NULL ) )
        {
            llUserFreeBytesAvailable.QuadPart /= 1048576UL;
            if ( llUserFreeBytesAvailable.HighPart == 0 )
                return llUserFreeBytesAvailable.LowPart;
        }
    }
    return -1;
}
Exemple #19
0
BOOL XCEAPI
XCEGetDiskFreeSpaceExA(const char *path, 
		       ULARGE_INTEGER *pl1, 
		       ULARGE_INTEGER *pl2, 
		       ULARGE_INTEGER *pl3)
{
  wchar_t pathw[MAX_PATH];

#ifdef _WIN32_WCE_EMULATION
  return FALSE;
#else
  MultiByteToWideChar(CP_ACP, 0, path, -1, pathw, COUNTOF(pathw));

  return GetDiskFreeSpaceExW(pathw, pl1, pl2, pl3);
#endif
}
Exemple #20
0
/*
 * Arguments: path (string)
 * Returns: [total_bytes (number), available_bytes (number),
 *	free_bytes (number)]
 */
static int
sys_statfs (lua_State *L)
{
  const char *path = luaL_checkstring(L, 1);
  int64_t ntotal, navail, nfree;
  int res;

#ifndef _WIN32
  struct statvfs buf;

  sys_vm_leave(L);
  res = statvfs(path, &buf);
  sys_vm_enter(L);

  ntotal = buf.f_blocks * buf.f_frsize;
  nfree = buf.f_bfree * buf.f_bsize;
  navail = buf.f_bavail * buf.f_bsize;
#else
  ULARGE_INTEGER na, nt, nf;

  SetErrorMode(SEM_FAILCRITICALERRORS);  /* for floppy disks */
  {
    void *os_path = utf8_to_filename(path);
    if (!os_path)
      return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY);

    sys_vm_leave(L);
    res = is_WinNT
     ? !GetDiskFreeSpaceExW(os_path, &na, &nt, &nf)
     : !GetDiskFreeSpaceExA(os_path, &na, &nt, &nf);

    free(os_path);
    sys_vm_enter(L);
  }

  ntotal = (int64_t) nt.QuadPart;
  nfree = (int64_t) nf.QuadPart;
  navail = (int64_t) na.QuadPart;
#endif
  if (!res) {
    lua_pushnumber(L, (lua_Number) ntotal);
    lua_pushnumber(L, (lua_Number) navail);
    lua_pushnumber(L, (lua_Number) nfree);
    return 3;
  }
  return sys_seterror(L, 0);
}
int64 os_total_space(const std::string &path)
{
	std::string cp=path;
	if(path.size()==0)
		return -1;
	if(cp[cp.size()-1]=='/')
		cp.erase(cp.size()-1, 1);
	if(cp[cp.size()-1]!='\\')
		cp+='\\';

	ULARGE_INTEGER li;
	BOOL r=GetDiskFreeSpaceExW(ConvertToWchar(path).c_str(), NULL, &li, NULL);
	if(r!=0)
		return li.QuadPart;
	else
		return -1;
}
Exemple #22
0
void FileLib::getFileSystemStatus(
		const char8_t *path, FileSystemStatus *status) {
#ifdef _WIN32
	std::wstring pathStr;
	CodeConverter(Code::UTF8, Code::WCHAR_T)(path, pathStr);

	ULARGE_INTEGER availableBytes;
	ULARGE_INTEGER totalBytes;
	ULARGE_INTEGER freeBytes;
	if (!GetDiskFreeSpaceExW(pathStr.c_str(),
			&availableBytes, &totalBytes, &freeBytes)) {
		UTIL_THROW_PLATFORM_ERROR(NULL);
	}

	SYSTEM_INFO systemInfo;
	GetSystemInfo(&systemInfo);

	const DWORD blockSize = systemInfo.dwPageSize;
	status->blockSize_ = blockSize;
	status->fragmentSize_ = blockSize;
	status->blockCount_ = totalBytes.QuadPart / blockSize;
	status->freeBlockCount_ = freeBytes.QuadPart / blockSize;
	status->availableBlockCount_ = availableBytes.QuadPart / blockSize;
#else
	std::string pathStr;
	CodeConverter(Code::UTF8, Code::CHAR)(path, pathStr);

	struct statvfs stvBuf;
	if (statvfs(pathStr.c_str(), &stvBuf) != 0) {
		UTIL_THROW_PLATFORM_ERROR(NULL);
	}

	status->blockSize_ = stvBuf.f_bsize;
	status->fragmentSize_ = stvBuf.f_frsize;
	status->blockCount_ = stvBuf.f_blocks;
	status->freeBlockCount_ = stvBuf.f_bfree;
	status->availableBlockCount_ = stvBuf.f_bavail;

	status->iNodeCount_ = stvBuf.f_files;
	status->freeINodeCount_ = stvBuf.f_ffree;
	status->availableINodeCount_ = stvBuf.f_favail;
	status->id_ = stvBuf.f_fsid;
	status->flags_ = stvBuf.f_flag;
	status->maxFileNameSize_ = stvBuf.f_namemax;
#endif
}
Exemple #23
0
VOID
ChkDskNow(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
{
    DWORD ClusterSize = 0, dwMaxComponentLength, FileSystemFlags;
    WCHAR szFs[30];
    WCHAR szDrive[] = {'C',':','\\', 0};
    WCHAR szVolumeLabel[40];
    ULARGE_INTEGER TotalNumberOfFreeBytes, FreeBytesAvailableUser;
    BOOLEAN bCorrectErrors = FALSE, bScanDrive = FALSE;

    szDrive[0] = pContext->Drive;
    if(!GetVolumeInformationW(szDrive, szVolumeLabel, sizeof(szVolumeLabel)/sizeof(WCHAR), NULL, &dwMaxComponentLength, &FileSystemFlags, szFs, sizeof(szFs)/sizeof(WCHAR)))
    {
        FIXME("failed to get drive fs type\n");
        return;
    }

    if (!GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailableUser, &TotalNumberOfFreeBytes, NULL))
    {
        FIXME("failed to get drive space type\n");
        return;
    }

    if (!GetDefaultClusterSize(szFs, &ClusterSize, &TotalNumberOfFreeBytes))
    {
        FIXME("invalid cluster size\n");
        return;
    }

    if (SendDlgItemMessageW(hwndDlg, 14000, BM_GETCHECK, 0, 0) == BST_CHECKED)
        bCorrectErrors = TRUE;

    if (SendDlgItemMessageW(hwndDlg, 14001, BM_GETCHECK, 0, 0) == BST_CHECKED)
        bScanDrive = TRUE;

    ChkdskDrvDialog = hwndDlg;
    bChkdskSuccess = FALSE;
    SendDlgItemMessageW(hwndDlg, 14002, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
    pContext->Chkdsk(szDrive, szFs, bCorrectErrors, TRUE, FALSE, bScanDrive, NULL, NULL, ChkdskCallback);
    
    ChkdskDrvDialog = NULL;
    pContext->Result = bChkdskSuccess;
    bChkdskSuccess = FALSE;

}
int64_t os_get_free_space(const char *path)
{
	ULARGE_INTEGER  remainingSpace;
	char            abs_path[512];
	wchar_t         w_abs_path[512];

	if (os_get_abs_path(path, abs_path, 512) > 0) {
		if (os_utf8_to_wcs(abs_path, 0, w_abs_path, 512) > 0) {
			BOOL success = GetDiskFreeSpaceExW(w_abs_path,
					(PULARGE_INTEGER)&remainingSpace,
					NULL, NULL);
			if (success)
				return (int64_t)remainingSpace.QuadPart;
		}
	}

	return -1;
}
JNIEXPORT jlongArray JNICALL Java_org_jdesktop_jdic_fileutil_Win32NativeFileUtil_getTotalSpace
  (JNIEnv *env, jobject obj, jstring fullPath) {
    wchar_t* pFullPath = (wchar_t*) (*env)->GetStringChars(env, fullPath, NULL);
    ULARGE_INTEGER freeBytesAvailable;
    ULARGE_INTEGER totalNumberOfBytes;
    ULARGE_INTEGER totalNumberOfFreeBytes;
    jlongArray retorno = (*env)->NewLongArray(env, 2);
    jlong buf[2];
    wchar_t* pTerminator = L"\0";

    pFullPath = (wchar_t*) realloc(pFullPath, sizeof(wchar_t) * (wcslen(pFullPath) + 1));
    wcsncat(pFullPath, pTerminator, 1);
    GetDiskFreeSpaceExW(pFullPath, &freeBytesAvailable, &totalNumberOfBytes, 
                             &totalNumberOfFreeBytes);
    buf[0] = (jlong) totalNumberOfBytes.LowPart;
    buf[1] = (jlong) totalNumberOfBytes.HighPart;
    (*env)->SetLongArrayRegion(env, retorno, 0, 2, buf);
    (*env)->ReleaseStringChars(env, fullPath, pFullPath);
    
    return retorno;
}
Exemple #26
0
static VOID
ChkDskNow(HWND hwndDlg, LPCWSTR pwszDrive)
{
    //DWORD ClusterSize = 0;
    WCHAR wszFs[30];
    ULARGE_INTEGER TotalNumberOfFreeBytes, FreeBytesAvailableUser;
    BOOLEAN bCorrectErrors = FALSE, bScanDrive = FALSE;

    if(!GetVolumeInformationW(pwszDrive, NULL, 0, NULL, NULL, NULL, wszFs, _countof(wszFs)))
    {
        FIXME("failed to get drive fs type\n");
        return;
    }

    if (!GetDiskFreeSpaceExW(pwszDrive, &FreeBytesAvailableUser, &TotalNumberOfFreeBytes, NULL))
    {
        FIXME("failed to get drive space type\n");
        return;
    }

    /*if (!GetDefaultClusterSize(wszFs, &ClusterSize, &TotalNumberOfFreeBytes))
    {
        FIXME("invalid cluster size\n");
        return;
    }*/

    if (SendDlgItemMessageW(hwndDlg, 14000, BM_GETCHECK, 0, 0) == BST_CHECKED)
        bCorrectErrors = TRUE;

    if (SendDlgItemMessageW(hwndDlg, 14001, BM_GETCHECK, 0, 0) == BST_CHECKED)
        bScanDrive = TRUE;

    hChkdskDrvDialog = hwndDlg;
    bChkdskSuccess = FALSE;
    SendDlgItemMessageW(hwndDlg, 14002, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
    Chkdsk((LPWSTR)pwszDrive, (LPWSTR)wszFs, bCorrectErrors, TRUE, FALSE, bScanDrive, NULL, NULL, ChkdskCallback); // FIXME: casts

    hChkdskDrvDialog = NULL;
    bChkdskSuccess = FALSE;
}
Exemple #27
0
/**
 * The getTotalSize function checks the total space in storage.
 */
jlong pcsl_file_gettotalsize(const pcsl_string * path)
{
    BOOL res;
    const jchar * pszOsFilename = pcsl_string_get_utf16_data(path);

    ULARGE_INTEGER available;
    ULARGE_INTEGER totalBytes;
    ULARGE_INTEGER freeBytes;

    if (NULL == pszOsFilename) {
        return -1;
    }

    res = GetDiskFreeSpaceExW(pszOsFilename, &available, &totalBytes, &freeBytes);
    pcsl_string_release_utf16_data(pszOsFilename, path);

    if (!res) {
        return -1;
    }

    return (jlong)totalBytes.QuadPart;
}
Exemple #28
0
int32_t
omrfile_stat_filesystem(struct OMRPortLibrary *portLibrary, const char *path, uint32_t flags, struct J9FileStatFilesystem *buf)
{
	DWORD result;
	wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;
	wchar_t driveBuffer[UNICODE_BUFFER_SIZE];
	if (NULL == path || NULL == buf) {
		return -1;
	}

	/* Convert the filename from UTF8 to Unicode */
	unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
	if (NULL == unicodePath) {
		return -1;
	}

	result = GetFullPathNameW(unicodePath, UNICODE_BUFFER_SIZE, driveBuffer, NULL);

	if (unicodeBuffer != unicodePath) {
		portLibrary->mem_free_memory(portLibrary, unicodePath);
	}

	if (result == 0 || result > UNICODE_BUFFER_SIZE) {
		result = GetLastError();
		return portLibrary->error_set_last_error(portLibrary, result, findError(result));
	}
	driveBuffer[3] = '\0'; /* Chop off everything after the initial X:\ */

	result = GetDiskFreeSpaceExW(driveBuffer,
								 (PULARGE_INTEGER)&buf->freeSizeBytes,
								 (PULARGE_INTEGER)&buf->totalSizeBytes,
								 NULL);
	if (0 == result) {
		result = GetLastError();
		return portLibrary->error_set_last_error(portLibrary, result, findError(result));
	}
	return 0;
}
Exemple #29
0
UINT WINAPI  DiscoverRemoveableDrives(ULONGLONG limitSize)
{
	UINT index = 0;
	wchar_t buffer[2048] = { 0 };
	wchar_t drivePath[8] = { 0 };
	wchar_t driveLetter[4] = { 0 };
	DWORD iSub = 0;
	DWORD iLength= GetLogicalDriveStringsW(2048, buffer);
	for (iSub = 0; iSub < iLength; iSub += 4)
	{
		wcscpy_s(drivePath, buffer+iSub);
		
		if (GetDriveTypeW(drivePath) == DRIVE_REMOVABLE&&GetVolumeInformationW(drivePath, NULL, 0, NULL, NULL, NULL, NULL, 0) == TRUE)
		{
			wcscpy_s(driveLetter, drivePath);
			(wcsrchr(driveLetter, _T(':')))[1] = 0;
			ULARGE_INTEGER lpFreeToCaller;
			ULARGE_INTEGER lpTotalSize;
			ULARGE_INTEGER lpFreeSize;
			if (GetDiskFreeSpaceExW(drivePath, &lpFreeToCaller, &lpTotalSize, &lpFreeSize) ==TRUE)
			{
				if (limitSize>0){
					if (lpTotalSize.QuadPart < limitSize)
						continue;
				}
				swprintf_s(g_DriveList[index].sizeInfo, L"%s  The total size of USB device: %4.1f GB |Free Space: %4.1f GB",
					drivePath,
					(float)(lpTotalSize.QuadPart) / (1024 * 1024 * 1024),
					(float)(lpFreeSize.QuadPart) / (1024 * 1024 * 1024));
				wcscpy_s(g_DriveList[index].driveLetter, driveLetter);
				wcscpy_s(g_DriveList[index].drivePath, drivePath);
				index++;
			}
		}
	}
	return index;
}
Exemple #30
0
//! @brief figure the free disk space on a filesystem
//! @param path path on the filesystem to check
//! @return size in bytes
qulonglong Utils::filesystemFree(QString path)
{
    qlonglong size = 0;
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) 
    // the usage of statfs() is deprecated by the LSB so use statvfs().
    struct statvfs fs;
    int ret;

    ret = statvfs(qPrintable(path), &fs);

    if(ret == 0)
        size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail;
#endif
#if defined(Q_OS_WIN32)
    BOOL ret;
    ULARGE_INTEGER freeAvailBytes;

    ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes, NULL, NULL);
    if(ret)
        size = freeAvailBytes.QuadPart;
#endif
    qDebug() << "[Utils] Filesystem free:" << path << size;
    return size;
}