기본 콘텐츠로 건너뛰기

라벨이 filesystem인 게시물 표시

파일 시스템 정보 읽어오기

이왕 하는 거 파일 시스템 정보까지 얻어오면 좋겠다 싶으면 POSIX표준인 statvfs()를 쓸 수 있다. 자세한 설명은 역시나 man 페이지를 확인하고, 아래 예제 소스는 /dev/shm 파일 시스템에 전체 크기와 남아 있는 용량을 기가바이트 단위로 표시한 것이다. #include <iostream> using namespace std; #include <sys/statvfs.h> const double div4giga(1024*1024*1024); bool printFSStat(const char* dev) {     struct statvfs vfs;     if ( statvfs(dev, &vfs) < 0 )     {        return false;     }     cout << "Total: " << vfs.f_bsize * vfs.f_blocks / div4giga << endl;     cout << "Free: " << vfs.f_bsize * vfs.f_bavail / div4giga << endl;     cout << "Used: " << vfs.f_bsize * (vfs.f_blocks-vfs.f_bavail) / div4giga << endl;     return true; } int main(int argc, char* argv[]) {     if ( !printFSStat("/dev/shm") )     {        cout <...