Использование диска
This commit is contained in:
parent
11209d13d5
commit
4a253e105a
23
code/C/disk_usage.c
Normal file
23
code/C/disk_usage.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#define PATH "/media/user/Samsung USB"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
const unsigned int GB = (1024 * 1024) * 1024;
|
||||
struct statvfs buffer;
|
||||
int ret = statvfs(PATH, &buffer);
|
||||
|
||||
if (!ret) {
|
||||
const double total = (double)(buffer.f_blocks * buffer.f_frsize) / GB;
|
||||
const double available = (double)(buffer.f_bfree * buffer.f_frsize) / GB;
|
||||
const double used = total - available;
|
||||
const double usedPercentage = (double)(used / total) * (double)100;
|
||||
printf("Total: %f --> %.0f\n", total, total);
|
||||
printf("Available: %f --> %.0f\n", available, available);
|
||||
printf("Used: %f --> %.1f\n", used, used);
|
||||
printf("Used Percentage: %f --> %.0f\n", usedPercentage, usedPercentage);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user