initial commit
This commit is contained in:
commit
cf2b28beca
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build
|
||||
.cache
|
59
bin/main.cpp
Normal file
59
bin/main.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
#include <sys/statvfs.h>
|
||||
#include <mntent.h>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
|
||||
template <typename T>
|
||||
void print_in_color(const T& text, const std::string& color)
|
||||
{
|
||||
std::cout << "\033[" << color << "m" << text << "\033[0m";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string get_size_string(const T& size) {
|
||||
if (size < 1024) {
|
||||
return std::to_string(size) + " B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return std::to_string(size / 1024) + " KB";
|
||||
} else if (size < 1024 * 1024 * 1024) {
|
||||
return std::to_string(size / 1024 / 1024) + " MB";
|
||||
} else {
|
||||
return std::to_string(size / 1024 / 1024 / 1024) + " GB";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto main() -> int
|
||||
{
|
||||
std::ifstream fs("/etc/mtab");
|
||||
std::FILE* file = std::fopen("/etc/fstab", "r");
|
||||
struct mntent* mount_entry = nullptr;
|
||||
|
||||
std::cout << "\n\n";
|
||||
while ((mount_entry = getmntent(file)))
|
||||
{
|
||||
struct statvfs stat;
|
||||
if (statvfs(mount_entry->mnt_dir, &stat) != 0) {
|
||||
std::cerr << "Ошибка при получении информации о файловой системе: " << mount_entry->mnt_dir << "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned long long total_size = (unsigned long long) stat.f_frsize * stat.f_blocks;
|
||||
unsigned long long free_size = (unsigned long long) stat.f_frsize * stat.f_bfree;
|
||||
unsigned long long used_size = total_size - free_size;
|
||||
|
||||
std::cout << "Точка монтирования: " << mount_entry->mnt_dir << "\n";
|
||||
std::cout << "Тип файловой системы: " << mount_entry->mnt_type << "\n";
|
||||
std::cout << "Общий объем: ";
|
||||
print_in_color(get_size_string(total_size), "0;33");
|
||||
std::cout << "\nСвободное место: ";
|
||||
print_in_color(get_size_string(free_size), "0;32");
|
||||
std::cout << "\nИспользовано: ";
|
||||
print_in_color(get_size_string(used_size), "0;35");
|
||||
std::cout << "\n\n";
|
||||
}
|
||||
|
||||
std::fclose(file);
|
||||
fs.close();
|
||||
}
|
6
bin/meson.build
Normal file
6
bin/meson.build
Normal file
@ -0,0 +1,6 @@
|
||||
executable(
|
||||
'disk-info',
|
||||
'main.cpp',
|
||||
dependencies : deps,
|
||||
cpp_args: args
|
||||
)
|
37
meson.build
Normal file
37
meson.build
Normal file
@ -0,0 +1,37 @@
|
||||
project(
|
||||
'disk-info',
|
||||
'cpp',
|
||||
version : run_command('jq', '-r', '.version', join_paths(meson.source_root(), 'props.json'), check: true).stdout().strip(),
|
||||
default_options : [
|
||||
'warning_level=1',
|
||||
'optimization=3',
|
||||
'default_library=static',
|
||||
'cpp_std=c++20',
|
||||
])
|
||||
|
||||
add_project_arguments (
|
||||
'-Wpedantic',
|
||||
'-Wno-shadow',
|
||||
'-Wno-unused-but-set-variable',
|
||||
'-Wno-comment',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-unused-value',
|
||||
'-Wno-missing-field-initializers',
|
||||
'-Wno-narrowing',
|
||||
'-Wno-deprecated-enum-enum-conversion',
|
||||
'-Wno-volatile',
|
||||
'-Wno-deprecated-declarations',
|
||||
language: 'cpp'
|
||||
)
|
||||
|
||||
#############################################################
|
||||
|
||||
args = []
|
||||
deps = []
|
||||
inc = []
|
||||
|
||||
#############################################################
|
||||
|
||||
#subdir('src')
|
||||
subdir('bin')
|
||||
#subdir('tests')
|
2
props.json
Normal file
2
props.json
Normal file
@ -0,0 +1,2 @@
|
||||
{"version": "0.1.0"}
|
||||
|
Loading…
Reference in New Issue
Block a user