1 #include <sys/statvfs.h>
15 const std::string& aName,
16 const std::string& aExplanation) :
19 opt(shortName, aName, aExplanation) {};
20 virtual void print(
const std::string& fsname,
21 const struct statvfs& stat,
32 const std::string& aName,
33 const std::string& aExplanation) :
fieldHandlerBase(shortName, aName, aExplanation),
35 void print(
const std::string& fsname,
36 const struct statvfs& stat,
37 bool printAll)
override {
38 if (printAll ||
opt) {
40 std::cout << fsname <<
" " <<
fieldName <<
": ";
42 std::cout << stat.*
field <<
"\n";
50 idHandler(
char shortName,
const std::string& aName,
const std::string& aExplanation) :
fieldHandlerTpl<unsigned long>(&statvfs::f_fsid, shortName, aName, aExplanation) {};
51 void print(
const std::string& fsname,
52 const struct statvfs& stat,
53 bool printAll)
override {
54 std::cout << std::hex;
56 std::cout << std::dec;
62 static std::map<__fsword_t, std::string>
magicMap {
63 {0xadf5,
"ADFS_SUPER_MAGIC"},
64 {0xadff,
"AFFS_SUPER_MAGIC"},
65 {0x5346414F,
"AFS_SUPER_MAGIC"},
66 {0x0187,
"AUTOFS_SUPER_MAGIC"},
67 {0x73757245,
"CODA_SUPER_MAGIC"},
68 {0x28cd3d45,
"CRAMFS_MAGIC"},
69 {0x64626720,
"DEBUGFS_MAGIC"},
70 {0x73636673,
"SECURITYFS_MAGIC"},
71 {0xf97cff8c,
"SELINUX_MAGIC"},
72 {0x43415d53,
"SMACK_MAGIC"},
73 {0x858458f6,
"RAMFS_MAGIC"},
74 {0x01021994,
"TMPFS_MAGIC"},
75 {0x958458f6,
"HUGETLBFS_MAGIC"},
76 {0x73717368,
"SQUASHFS_MAGIC"},
77 {0xf15f,
"ECRYPTFS_SUPER_MAGIC"},
78 {0x414A53,
"EFS_SUPER_MAGIC"},
79 {0xEF53,
"EXT2_SUPER_MAGIC"},
80 {0xEF53,
"EXT3_SUPER_MAGIC"},
81 {0xabba1974,
"XENFS_SUPER_MAGIC"},
82 {0xEF53,
"EXT4_SUPER_MAGIC"},
83 {0x9123683E,
"BTRFS_SUPER_MAGIC"},
84 {0x3434,
"NILFS_SUPER_MAGIC"},
85 {0xF2F52010,
"F2FS_SUPER_MAGIC"},
86 {0xf995e849,
"HPFS_SUPER_MAGIC"},
87 {0x9660,
"ISOFS_SUPER_MAGIC"},
88 {0x72b6,
"JFFS2_SUPER_MAGIC"},
89 {0x6165676C,
"PSTOREFS_MAGIC"},
90 {0xde5e81e4,
"EFIVARFS_MAGIC"},
91 {0x00c0ffee,
"HOSTFS_SUPER_MAGIC"},
92 {0x794c7630,
"OVERLAYFS_SUPER_MAGIC"},
93 {0x137F,
"MINIX_SUPER_MAGIC"},
94 {0x2468,
"MINIX2_SUPER_MAGIC"},
95 {0x4d5a,
"MINIX3_SUPER_MAGIC"},
96 {0x4d44,
"MSDOS_SUPER_MAGIC"},
97 {0x564c,
"NCP_SUPER_MAGIC"},
98 {0x6969,
"NFS_SUPER_MAGIC"},
99 {0x9fa1,
"OPENPROM_SUPER_MAGIC"},
100 {0x002f,
"QNX4_SUPER_MAGIC"},
101 {0x68191122,
"QNX6_SUPER_MAGIC"},
102 {0x52654973,
"REISERFS_SUPER_MAGIC"},
103 {0x517B,
"SMB_SUPER_MAGIC"},
104 {0x27e0eb,
"CGROUP_SUPER_MAGIC"},
105 {0x7655821,
"RDTGROUP_SUPER_MAGIC"},
106 {0x57AC6E9D,
"STACK_END_MAGIC"},
107 {0x01021997,
"V9FS_MAGIC"},
108 {0x62646576,
"BDEVFS_MAGIC"},
109 {0x64646178,
"DAXFS_MAGIC"},
110 {0x42494e4d,
"BINFMTFS_MAGIC"},
111 {0x1cd1,
"DEVPTS_SUPER_MAGIC"},
112 {0xBAD1DEA,
"FUTEXFS_SUPER_MAGIC"},
113 {0x50495045,
"PIPEFS_MAGIC"},
114 {0x9fa0,
"PROC_SUPER_MAGIC"},
115 {0x534F434B,
"SOCKFS_MAGIC"},
116 {0x62656572,
"SYSFS_MAGIC"},
117 {0x9fa2,
"USBDEVICE_SUPER_MAGIC"},
118 {0x11307854,
"MTD_INODE_FS_MAGIC"},
119 {0x09041934,
"ANON_INODE_FS_MAGIC"},
120 {0x73727279,
"BTRFS_TEST_MAGIC"},
121 {0xcafe4a11,
"BPF_FS_MAGIC"},
123 {0x47504653,
"GPFS_SUPER_MAGIC"}
126 int main(
int argc,
const char *argv[]) {
128 std::list<fieldHandlerBase*> handlers;
137 handlers.emplace_back(
new idHandler(
'i',
"fsid",
"filesystem id"));
143 parser.fParse(argc, argv);
145 bool printAll = !(type || Type);
146 for (
auto& handler : handlers) {
152 for (
const auto& filesystem : fileSystems) {
155 throwcall::good0(statvfs(filesystem.c_str(), &stat),
"can't statvfs ", filesystem);
156 for (
auto& handler : handlers) {
157 handler->print(filesystem, stat, printAll);
160 if (type || Type || printAll) {
162 throwcall::good0(statfs(filesystem.c_str(), &stat),
"can't statfs ", filesystem);
164 std::cout << filesystem <<
" " <<
"type" <<
": ";
166 if (type || printAll) {
167 std::cout << stat.f_type;
168 if (Type || printAll) {
172 if (Type || printAll) {
173 auto item =
magicMap.find(stat.f_type);
175 std::cout <<
"unknown";
177 std::cout << item->second;