카테고리 없음
[C언어] 디스크 관리 함수 - _getdiskfree()
s뽈록이s
2013. 7. 9. 11:25
void main() { struct _diskfree_t df; int bytes; int total, avail; _getdiskfree(4, &df); bytes = df.sectors_per_cluster*df.bytes_per_sector; total = df.total_clusters * bytes / 1048576; avail = df.avail_clusters * bytes / 1048576; printf("총 용량 = %dM, 사용한 용량 = %dM\n 남은 용량 = %dM, 클러스터당 바이트 = %dB.\n", total,total - avail, avail, bytes); }
프로그램 실행화면
unsigned _getdiskfree(unsigned drive, struct _diskfree_t * driveinfo);
struct _diskfree_t {
unsigned total_clusters;
unsigned avail_clusters;
unsigned sectors_per_cluster;
unsigned bytes_per_sector;
};
디스크의 총 용량, 사용한 용량, 남은 용량을 구해주는 예제이다.
원래는 total = MulDiv(df.total_clusters, bytes, 1048576); 이걸로 계산해야 하는데 avail도 마찬가지로, 하지만 이상하게 MulDiv()함수를 호출할 수 없다고 나와서 그냥 계산해 버렸다.
아마 오버플로우가 발생해서 정확한 값이 나오지 않은 것이라 생각된다. MulDiv()함수는 큰 단위의 계산에 사용된다.
오버플로우가 발생하는 범위라도 64bit로 처리해 주기 때문에 오버플로우가 발생하지 않는다. 이제 OS도 64bit로 전환되는 추세이니 이 함수의 사용 빈도는 더 줄어들 것으로 보인다.