1
0
Fork 0
forked from len0rd/rockbox

Take cluster size into account when calculating zip extracted size.

Allow passing an (optional) cluster size to round up all file sizes when
calculating the total size of an extracted zip archive. This allows to check if
the space on disk is actually sufficient without relying on an arbitrary
headroom value which might be wrong. Addresses FS#12195.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30214 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2011-07-26 20:54:44 +00:00
parent 3bb0fed345
commit 743308e882
5 changed files with 51 additions and 10 deletions

View file

@ -187,13 +187,25 @@ QString Utils::filesystemName(QString path)
//! @return size in bytes
qulonglong Utils::filesystemFree(QString path)
{
return filesystemSize(path, FilesystemFree);
qulonglong size = filesystemSize(path, FilesystemFree);
qDebug() << "[Utils] free disk space for" << path << size;
return size;
}
qulonglong Utils::filesystemTotal(QString path)
{
return filesystemSize(path, FilesystemTotal);
qulonglong size = filesystemSize(path, FilesystemTotal);
qDebug() << "[Utils] total disk space for" << path << size;
return size;
}
qulonglong Utils::filesystemClusterSize(QString path)
{
qulonglong size = filesystemSize(path, FilesystemClusterSize);
qDebug() << "[Utils] cluster size for" << path << size;
return size;
}
@ -214,6 +226,9 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
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)
@ -230,9 +245,19 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
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
qDebug() << "[Utils] Filesystem:" << path << size;
return size;
}