ewmscp  ..
Public Member Functions | List of all members
findMinHoleSize Class Reference
Inheritance diagram for findMinHoleSize:
[legend]
Collaboration diagram for findMinHoleSize:
[legend]

Public Member Functions

 findMinHoleSize ()
 
void execute (const std::vector< std::string > &remainingOptions) override
 
- Public Member Functions inherited from baseTest
 baseTest (const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
 
void ensuredWrite (int fd, const std::string &data)
 
void ensuredRead (int fd, std::string &data)
 
void Execute (const std::vector< std::string > &remainingOptions)
 

Additional Inherited Members

- Static Public Member Functions inherited from baseTest
static std::map< std::string, baseTest * > & getList ()
 
static void setUpOptions ()
 
static const std::string & getDescriptions ()
 
- Protected Attributes inherited from baseTest
std::string name
 
std::string description
 
std::list< std::pair< std::string, std::string > > parameters
 
std::list< std::pair< options::base &, std::string > > options
 
std::set< std::string > createdFiles
 
- Static Protected Attributes inherited from baseTest
static options::single< unsigned int > repeat
 
static options::single< bool > cleanup
 
static options::single< bool > urandom
 
static options::single< bool > einsZweiDrei
 
static options::single< std::string > contentFile
 
static options::single< size_t > size
 
static options::single< unsigned int > blocks
 
static options::single< std::string > content
 
static options::single< bool > truncate
 
static options::single< std::chrono::duration< double > > time
 
static options::single< unsigned long > syncus
 
static options::single< unsigned long > skewus
 
static std::string descriptions = "\npossible actions and their parameters:\n"
 

Detailed Description

Definition at line 537 of file fileOpsTests.cpp.

Constructor & Destructor Documentation

◆ findMinHoleSize()

findMinHoleSize::findMinHoleSize ( )
inline

Definition at line 539 of file fileOpsTests.cpp.

539  : baseTest("findMinHoleSize",
540  "find minimum hole size", {
541  {"file", "path to file"
542  }
543  }) {};

Member Function Documentation

◆ execute()

void findMinHoleSize::execute ( const std::vector< std::string > &  remainingOptions)
inlineoverridevirtual

Implements baseTest.

Definition at line 544 of file fileOpsTests.cpp.

544  {
545  auto file = remainingOptions.at(0);
546  auto fd = throwcall::badval(open(file.c_str(), O_CREAT | O_WRONLY, 0744), -1, "open ", file);
547  struct stat statbuf;
548  throwcall::good0(fstat(fd, &statbuf), "stat ", file);
549  auto testSize = statbuf.st_blksize;
550  while (testSize > 0) {
551  throwcall::good0(close(fd), "close ", file);
552  fd = throwcall::badval(open(file.c_str(), O_WRONLY | O_TRUNC, 0744), -1, "open ", file);
553  throwcall::badval(lseek(fd, testSize, SEEK_SET), -1, "seek ", testSize, " in ", file);
554  ensuredWrite(fd, content);
555  throwcall::good0(close(fd), "close ", file);
556  createdFiles.emplace(file);
557  fd = throwcall::badval(open(file.c_str(), O_RDONLY), -1, "open ", file);
558  auto dataPos = throwcall::badval(lseek(fd, 0, SEEK_DATA), -1, "seek data in ", file);
559  if (dataPos != testSize) {
560  break;
561  }
562  std::cout << testSize << " bytes hole size worked\n";
563  testSize /= 2;
564  }
565  };

References throwcall::badval(), baseTest::content, baseTest::createdFiles, baseTest::ensuredWrite(), and throwcall::good0().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
baseTest::content
static options::single< std::string > content
Definition: fileOpsTests.cpp:51
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
baseTest::createdFiles
std::set< std::string > createdFiles
Definition: fileOpsTests.cpp:42
baseTest::baseTest
baseTest(const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
Definition: fileOpsTests.cpp:68
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
baseTest::ensuredWrite
void ensuredWrite(int fd, const std::string &data)
Definition: fileOpsTests.cpp:106