ewmscp  ..
Classes | Public Member Functions | Protected Attributes | Friends | List of all members
posixFileIoCommon Class Reference

base class for posixFile reader and writer class with the common stuff like fd, path and xattr handling More...

#include <posixFileCommon.h>

Inheritance diagram for posixFileIoCommon:
[legend]
Collaboration diagram for posixFileIoCommon:
[legend]

Classes

class  attrDataType
 

Public Member Functions

 posixFileIoCommon (const std::string &aPath)
 
void setXattr (const std::string &name, const std::string &value) override
 
std::string getXattr (const std::string &name) override
 get one extended attribute value More...
 
void removeXattr (const std::string &name) override
 
std::unique_ptr< const genericStatgetStat () override
 
std::unique_ptr< ioHandle::attrDataTypegetAttrData (const outputHandler::base *aOutputHandler) override
 get attributes in the optimal way for setting with aOutputHandler More...
 
- Public Member Functions inherited from ioHandle
 ioHandle ()
 
virtual ~ioHandle () noexcept(false)
 
virtual bool parallelizable () const
 tell if this handler is capable of parallel IO. Unsually not the case More...
 
virtual size_t getBlockSize () const
 
virtual void setBlockSize (size_t newSize)
 
virtual std::unique_ptr< acl::listgetAclData ()
 get acls More...
 

Protected Attributes

const std::string & path
 
int fd = -1
 
- Protected Attributes inherited from ioHandle
size_t blockSize
 in bytes, block size to be used when reading or writing More...
 

Friends

class gpfsIoCommon
 

Detailed Description

base class for posixFile reader and writer class with the common stuff like fd, path and xattr handling

Definition at line 17 of file posixFileCommon.h.

Constructor & Destructor Documentation

◆ posixFileIoCommon()

posixFileIoCommon::posixFileIoCommon ( const std::string &  aPath)

Definition at line 110 of file posixFileCommon.cpp.

110  :
111  path(aPath) {
112 }

Member Function Documentation

◆ getAttrData()

std::unique_ptr< ioHandle::attrDataType > posixFileIoCommon::getAttrData ( const outputHandler::base )
overridevirtual

get attributes in the optimal way for setting with aOutputHandler

Returns
std::unique_ptr to the attribute data or nullptr if none available
Exceptions
std::system_errorwhen reading of attributes fails

Reimplemented from ioHandle.

Definition at line 205 of file posixFileCommon.cpp.

205  {
206  return ioHandle::getAttrData(aOutputHandler);
207 }

References ioHandle::getAttrData().

Here is the call graph for this function:

◆ getStat()

std::unique_ptr< const genericStat > posixFileIoCommon::getStat ( )
overridevirtual

Implements ioHandle.

Definition at line 116 of file posixFileCommon.cpp.

116  {
117  struct stat statBuf;
118  timerInst(fstat);
119  throwcall::good0(fstat(fd, &statBuf), "can't stat", path);
120  return std::unique_ptr<const genericStat>(new genericStat(statBuf, std::chrono::nanoseconds(1)));
121 }

References fd, throwcall::good0(), path, and timerInst.

Here is the call graph for this function:

◆ getXattr()

std::string posixFileIoCommon::getXattr ( const std::string &  )
overridevirtual

get one extended attribute value

Returns
value or empty string if attribute not present
Exceptions
std::system_errorif attribute setting fails
unimplementedActionErrorif not implemented (most handlers)

Reimplemented from ioHandle.

Definition at line 132 of file posixFileCommon.cpp.

132  {
133  #if defined(WithXattr) || defined(WithXattrUgly)
134  char buffer[512];
136  auto retval = fgetxattr(fd, name.c_str(), buffer, sizeof(buffer));
137  if (retval == -1) {
138  if (errno != ENOATTR) {
139  throwcall::badval(retval, -1, "can't read xattr '", name, "' from ", path);
140  }
141  return "";
142  } else {
143  buffer[retval] = '\0';
144  }
145  return buffer;
146  #else
147  throw unimplementedActionError("no xattr support");
148  return ""; // newver reached
149  #endif
150 
151 }

References throwcall::badval(), ENOATTR, fd, path, and timerInst.

Here is the call graph for this function:

◆ removeXattr()

void posixFileIoCommon::removeXattr ( const std::string &  name)
overridevirtual

Reimplemented from ioHandle.

Definition at line 153 of file posixFileCommon.cpp.

153  {
154  #if defined(WithXattr) || defined(WithXattrUgly)
155  timerInst(fremovexattr);
156  auto result = fremovexattr(fd, name.c_str());
157  if (result && errno == ENOATTR) {
158  return; // be silent about this
159  }
160  throwcall::good0(result,
161  "can't remove xattr ", name, " from ", path);
162  #else
163  throw unimplementedActionError("no xattr support");
164  #endif
165 
166 }

References ENOATTR, fd, throwcall::good0(), path, and timerInst.

Here is the call graph for this function:

◆ setXattr()

void posixFileIoCommon::setXattr ( const std::string &  name,
const std::string &  value 
)
overridevirtual

Reimplemented from ioHandle.

Definition at line 122 of file posixFileCommon.cpp.

122  {
123  #if defined(WithXattr) || defined(WithXattrUgly)
124  timerInst(fsetxattr);
125  throwcall::good0(fsetxattr(fd, name.c_str(), value.data(), value.size(), 0),
126  "can't set xattr '", name, "' to '", value, "' on ", path);
127  #else
128  throw unimplementedActionError("no xattr support");
129  #endif
130 }

References fd, throwcall::good0(), path, and timerInst.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ gpfsIoCommon

friend class gpfsIoCommon
friend

Definition at line 18 of file posixFileCommon.h.

Member Data Documentation

◆ fd

int posixFileIoCommon::fd = -1
protected

◆ path

const std::string& posixFileIoCommon::path
protected

The documentation for this class was generated from the following files:
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
genericStat
generic stat abstraction class Used to abstract the variants of the stat structure.
Definition: genericStat.h:12
unimplementedActionError
class for exceptions that result from unimplemented functions Exceptions of this kind are to be throw...
Definition: copyRequestTypes.h:32
ioHandle::getAttrData
virtual std::unique_ptr< attrDataType > getAttrData(const outputHandler::base *)
get attributes in the optimal way for setting with aOutputHandler
Definition: ioHandle.h:69
posixFileIoCommon::fd
int fd
Definition: posixFileCommon.h:21
ENOATTR
#define ENOATTR
Definition: posixFileCommon.cpp:17
timerInst
#define timerInst(subfunc)
Definition: timer.h:157
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
posixFileIoCommon::getXattr
std::string getXattr(const std::string &name) override
get one extended attribute value
Definition: posixFileCommon.cpp:132
posixFileIoCommon::path
const std::string & path
Definition: posixFileCommon.h:20