Hi,
I'm using c++ and Ubuntu and I need to write/copy some files to a directory chosen by the user of my system (the user can save it on any folder of any disk of the pc or other usb device). Before I do it, I need to know if there's space available on the disk. I cannot only check the result of write() function, the validation must be executed before I start to save or copy.
I was trying to use statvsf structure, but I only have the complete filepath (/home/lobinho/myDocs/), not the disk path. The statvfs() function only works with disk path (i.e. /media/KINGSTON ).
The source of my function:
Code:
int MyClass::availableSpace(string dst, ulong* availableSize) {
int result = ERROR;
try {
struct statvfs devData;
memset(&devData, 0, sizeof (struct statvfs));
if ((statvfs(dst.c_str(), &devData)) >= 0) {
if (availableSize != NULL) {
//I don't know if it's right, but I'll set availableSize only if the available size doesn't pass the ulong limit.
if (devData.f_bfree * devData.f_bsize > 4294967295UL) {
*availableSize = 4294967295UL;
} else {
*availableSize = devData.f_bfree * devData.f_bsize;
}
}
result = OK;
}
} catch (...) {
}
return result;
}
This function works perfectly with the disk path.
Is there any other function that could help me?
I've tried search references on cplusplus, google, but no answer until now... :/
thanks in advance!