void SelectDestination::filenameEditLostFocus() { long long dummy; m_archiveDestination.freeSpace = getDiskSpace(m_filenameEdit->GetText(), dummy, dummy); // if we don't get a valid freespace value it probably means the file doesn't // exist yet so try looking up the freespace for the parent directory if (m_archiveDestination.freeSpace == -1) { QString dir = m_filenameEdit->GetText(); int pos = dir.lastIndexOf('/'); if (pos > 0) dir = dir.left(pos); else dir = "/"; m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy); } if (m_archiveDestination.freeSpace != -1) { m_freespaceText->SetText(formatSize(m_archiveDestination.freeSpace, 2)); m_freeSpace = m_archiveDestination.freeSpace; } else { m_freespaceText->SetText(tr("Unknown")); m_freeSpace = 0; } }
QString StorageGroup::FindNextDirMostFree(void) { QString nextDir; long long nextDirFree = 0; long long thisDirTotal; long long thisDirUsed; long long thisDirFree; LOG(VB_FILE, LOG_DEBUG, LOC + QString("FindNextDirMostFree: Starting")); if (m_allowFallback) nextDir = kDefaultStorageDir; if (m_dirlist.size()) nextDir = m_dirlist[0]; QDir checkDir(""); int curDir = 0; while (curDir < m_dirlist.size()) { checkDir.setPath(m_dirlist[curDir]); if (!checkDir.exists()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("FindNextDirMostFree: '%1' does not exist!") .arg(m_dirlist[curDir])); curDir++; continue; } thisDirFree = getDiskSpace(m_dirlist[curDir], thisDirTotal, thisDirUsed); LOG(VB_FILE, LOG_DEBUG, LOC + QString("FindNextDirMostFree: '%1' has %2 KiB free") .arg(m_dirlist[curDir]) .arg(QString::number(thisDirFree))); if (thisDirFree > nextDirFree) { nextDir = m_dirlist[curDir]; nextDirFree = thisDirFree; } curDir++; } if (nextDir.isEmpty()) LOG(VB_FILE, LOG_ERR, LOC + "FindNextDirMostFree: Unable to find any directories to use."); else LOG(VB_FILE, LOG_DEBUG, LOC + QString("FindNextDirMostFree: Using '%1'").arg(nextDir)); nextDir.detach(); return nextDir; }
void DiskSpaceBar::setDrive(const QString &path) { uint total, free; if (getDiskSpace(path, total, free) && total) { m_diskSpace = qMax(m_diskSpace, total-free); m_path = path; setValue(m_diskSpace); setMaximum(total); show(); } }
FileLog::EDiskStatus FileLog::checkDiskStatus() { unsigned long long leftsize = 0, alarmsize = 0; EDiskStatus status = DiskStatus_Idle; leftsize = getDiskSpace(); alarmsize = getDiskAlarmSize(); if (leftsize < alarmsize) { status = DiskStatus_Full; } return status; }
void CmaEvent::vitaEventSendStorageSize(vita_event_t *event, int eventId) { qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId); QMutexLocker locker(&m_db->mutex); int ohfi = event->Param2; QString fullpath = m_db->getAbsolutePath(ohfi); if(fullpath.isNull()) { qWarning("Error: Cannot find OHFI %d", ohfi); VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI); return; } else { QFile file(fullpath); if(!file.exists()) { // create the directory if doesn't exist so the query don't fail qDebug() << "Creating" << fullpath; if(!QDir(QDir::root()).mkpath(QDir(fullpath).absolutePath())) { qWarning("Create directory failed"); VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_Permission); return; } } } quint64 total; quint64 free; if(!getDiskSpace(fullpath, &free, &total)) { qWarning("Cannot get disk space"); VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_Permission); return; } qDebug("Storage stats for drive containing OHFI %d, free: %llu, total: %llu", ohfi, free, total); if(VitaMTP_SendStorageSize(device, eventId, total, free) != PTP_RC_OK) { qWarning("Send storage size failed"); } else { VitaMTP_ReportResult(device, eventId, PTP_RC_OK); } }
void DiskSpaceBar::refresh() { if (!isVisible()) return; uint total, free; if (!getDiskSpace(m_path, total, free)) return; uint usedmb = total-free; m_diskSpace = qMax(m_diskSpace, usedmb); qreal gbyte = usedmb/1024.0; uint percnt = usedmb*100/total; QString gbt = PLCHD.arg(gbyte,7,FMT_F,2,FILLSPC); QString pct = QString::number(percnt).rightJustified(3,FILLSPC); setValue(usedmb); setFormat(qtBuilderDiskSpaceTmpl.arg(m_name, gbt, pct)); }
unsigned long long SocamFSBusinessLogic::getMaxFileSystemSize() { struct mntent *ent; FILE *aFile; unsigned long long size = 0; aFile = setmntent("/proc/mounts", "r"); if (aFile == NULL) { perror("setmntent"); exit(1); } while (NULL != (ent = getmntent(aFile))) { if(!strcmp(ent->mnt_fsname, ROOTFS)) { size = getDiskSpace(ent->mnt_dir); break; } } endmntent(aFile); cout << "SocamFSBusinessLogic::getMaxFileSystemSize=" << size << endl; return size / 1024; }
void SelectDestination::setDestination(MythUIButtonListItem* item) { if (!item) return; int itemNo = item->GetData().value<ARCHIVEDESTINATION>(); if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1) itemNo = 0; m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description)); m_archiveDestination = ArchiveDestinations[itemNo]; switch(itemNo) { case AD_DVD_SL: case AD_DVD_DL: m_filenameEdit->Hide(); m_findButton->Hide(); m_eraseDvdRwCheck->Hide(); m_eraseDvdRwText->Hide(); m_doBurnCheck->Show(); m_doBurnText->Show(); break; case AD_DVD_RW: m_filenameEdit->Hide(); m_findButton->Hide(); m_eraseDvdRwCheck->Show(); m_eraseDvdRwText->Show(); m_doBurnCheck->Show(); m_doBurnText->Show(); break; case AD_FILE: long long dummy; ArchiveDestinations[itemNo].freeSpace = getDiskSpace(m_filenameEdit->GetText(), dummy, dummy); m_filenameEdit->Show(); m_findButton->Show(); m_eraseDvdRwCheck->Hide(); m_eraseDvdRwText->Hide(); m_doBurnCheck->Hide(); m_doBurnText->Hide(); break; } // update free space if (ArchiveDestinations[itemNo].freeSpace != -1) { m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2)); m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024; } else { m_freespaceText->SetText(tr("Unknown")); m_freeSpace = 0; } BuildFocusList(); }
DTC::StorageGroupDirList *Myth::GetStorageGroupDirs( const QString &sGroupName, const QString &sHostName ) { MSqlQuery query(MSqlQuery::InitCon()); if (!query.isConnected()) throw( QString("Database not open while trying to list " "Storage Group Dirs")); if (!sGroupName.isEmpty() && !sHostName.isEmpty()) { query.prepare("SELECT id, groupname, hostname, dirname " "FROM storagegroup " "WHERE groupname = :GROUP AND hostname = :HOST " "ORDER BY groupname, hostname, dirname" ); query.bindValue(":HOST", sHostName); query.bindValue(":GROUP", sGroupName); } else if (!sHostName.isEmpty()) { query.prepare("SELECT id, groupname, hostname, dirname " "FROM storagegroup " "WHERE hostname = :HOST " "ORDER BY groupname, hostname, dirname" ); query.bindValue(":HOST", sHostName); } else if (!sGroupName.isEmpty()) { query.prepare("SELECT id, groupname, hostname, dirname " "FROM storagegroup " "WHERE groupname = :GROUP " "ORDER BY groupname, hostname, dirname" ); query.bindValue(":GROUP", sGroupName); } else query.prepare("SELECT id, groupname, hostname, dirname " "FROM storagegroup " "ORDER BY groupname, hostname, dirname" ); if (!query.exec()) { MythDB::DBError("MythAPI::GetStorageGroupDirs()", query); throw( QString( "Database Error executing query." )); } // ---------------------------------------------------------------------- // return the results of the query plus R/W and size information // ---------------------------------------------------------------------- DTC::StorageGroupDirList* pList = new DTC::StorageGroupDirList(); while (query.next()) { DTC::StorageGroupDir *pStorageGroupDir = pList->AddNewStorageGroupDir(); QFileInfo fi(query.value(3).toString()); int64_t free, total, used; free = getDiskSpace(query.value(3).toString(), total, used); pStorageGroupDir->setId ( query.value(0).toInt() ); pStorageGroupDir->setGroupName ( query.value(1).toString() ); pStorageGroupDir->setHostName ( query.value(2).toString() ); pStorageGroupDir->setDirName ( query.value(3).toString() ); pStorageGroupDir->setDirRead ( fi.isReadable() ); pStorageGroupDir->setDirWrite ( fi.isWritable() ); pStorageGroupDir->setKiBFree ( free ); } return pList; }
str CMDbbpDiskSpace(lng *ret) { *ret= getDiskSpace(); return MAL_SUCCEED; }