ewmscp  ..
Classes | Functions | Variables
statvfs.cpp File Reference

(v0.19-24-g0617ca1 with changes)

#include <sys/statvfs.h>
#include <sys/vfs.h>
#include <iostream>
#include <list>
#include "Options.h"
#include "throwcall.h"
Include dependency graph for statvfs.cpp:

Go to the source code of this file.

Classes

class  fieldHandlerBase
 
class  fieldHandlerTpl< T >
 
class  idHandler
 

Functions

int main (int argc, const char *argv[])
 

Variables

static options::single< bool > quiet ('q', "quiet", "be quiet: no prefix to values")
 
static std::map< __fsword_t, std::string > magicMap
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 126 of file statvfs.cpp.

126  {
127  options::parser parser("", "", {});
128  std::list<fieldHandlerBase*> handlers;
129  handlers.emplace_back(new fieldHandlerTpl<unsigned long>(&statvfs::f_bsize, 'b', "bsize", "block size"));
130  handlers.emplace_back(new fieldHandlerTpl<unsigned long>(&statvfs::f_frsize, 'f', "frsize", "fragment size"));
131  handlers.emplace_back(new fieldHandlerTpl<fsblkcnt_t>(&statvfs::f_blocks, 'B', "blocks", "size in frsize units"));
132  handlers.emplace_back(new fieldHandlerTpl<fsblkcnt_t>(&statvfs::f_bfree, 'F', "bfree", "free blocks"));
133  handlers.emplace_back(new fieldHandlerTpl<fsblkcnt_t>(&statvfs::f_bavail, 'A', "bavail", "available blocks"));
134  handlers.emplace_back(new fieldHandlerTpl<fsfilcnt_t>(&statvfs::f_files, 'I', "files", "number of inodes"));
135  handlers.emplace_back(new fieldHandlerTpl<fsfilcnt_t>(&statvfs::f_ffree, 'J', "ffree", "free inodes"));
136  handlers.emplace_back(new fieldHandlerTpl<fsfilcnt_t>(&statvfs::f_favail, 'a', "favail", "available inodes"));
137  handlers.emplace_back(new idHandler('i', "fsid", "filesystem id"));
138  handlers.emplace_back(new fieldHandlerTpl<unsigned long>(&statvfs::f_flag, 'l', "fflag", "flags"));
139  handlers.emplace_back(new fieldHandlerTpl<unsigned long>(&statvfs::f_namemax, 'm', "namemax", "max filename length"));
140  options::single<bool> type('t', "type", "type of filesystem as number");
141  options::single<bool> Type('T', "Type", "type of filesystem as string");
142  options::positional<options::container<std::string>> fileSystems(10, "filesystems", "filesystems to look at");
143  parser.fParse(argc, argv);
144 
145  bool printAll = !(type || Type);
146  for (auto& handler : handlers) {
147  if (handler->opt) {
148  printAll = false;
149  }
150  }
151 
152  for (const auto& filesystem : fileSystems) {
153  {
154  struct statvfs stat;
155  throwcall::good0(statvfs(filesystem.c_str(), &stat), "can't statvfs ", filesystem);
156  for (auto& handler : handlers) {
157  handler->print(filesystem, stat, printAll);
158  }
159  }
160  if (type || Type || printAll) {
161  struct statfs stat;
162  throwcall::good0(statfs(filesystem.c_str(), &stat), "can't statfs ", filesystem);
163  if (!quiet) {
164  std::cout << filesystem << " " << "type" << ": ";
165  }
166  if (type || printAll) {
167  std::cout << stat.f_type;
168  if (Type || printAll) {
169  std::cout << " ";
170  }
171  }
172  if (Type || printAll) {
173  auto item = magicMap.find(stat.f_type);
174  if (item == magicMap.end()) {
175  std::cout << "unknown";
176  } else {
177  std::cout << item->second;
178  }
179  }
180  std::cout << "\n";
181  }
182  }
183 }

References throwcall::good0(), magicMap, and quiet.

Here is the call graph for this function:

Variable Documentation

◆ magicMap

std::map<__fsword_t, std::string> magicMap
static

Definition at line 62 of file statvfs.cpp.

Referenced by main().

◆ quiet

options::single<bool> quiet( 'q', "quiet", "be quiet: no prefix to values")
static
options::parser
class that contains the parser, i.e. does that option handling
Definition: Options.h:363
fieldHandlerTpl< unsigned long >
options::single< bool >
class specialisation for options of type bool
Definition: Options.h:595
magicMap
static std::map< __fsword_t, std::string > magicMap
Definition: statvfs.cpp:62
quiet
static options::single< bool > quiet('q', "quiet", "be quiet: no prefix to values")
options::positional
Definition: Options.h:876
idHandler
Definition: statvfs.cpp:48
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40