ewmscp  ..
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
block Class Reference

data block, used to hold the data that are being copied (or checksummed). More...

#include <block.h>

Public Member Functions

 block (size_t aBlockSize)
 Allocate block via mmap to ensure proper alignment along page borders, needed for efficient read/write ops. More...
 
 ~block ()
 
size_t size () const
 
bool empty () const
 
size_t max_size () const
 
size_t offset () const
 
void clear (size_t aOffset)
 
void bump_size (size_t additionalBytes)
 
bool isHole () const
 
void setHoleState (bool holeState)
 
void * bufferAt (size_t offset)
 only way to access the data in the block More...
 
const void * bufferAt (size_t offset) const
 only way to access the data in the block More...
 

Static Public Member Functions

static const void * nullBuffer ()
 
static size_t nullBufferSize ()
 

Private Attributes

void * buffer
 
size_t bytes
 number of bytes actually stored here More...
 
size_t blockSize
 capacity of the block More...
 
size_t startOffset
 offset in the file that is represented by this block More...
 
bool hole
 represents a hole in the file with bytes bytes. More...
 

Detailed Description

data block, used to hold the data that are being copied (or checksummed).

The interface implements a subset of standard container class methods.

Definition at line 7 of file block.h.

Constructor & Destructor Documentation

◆ block()

block::block ( size_t  aBlockSize)
explicit

Allocate block via mmap to ensure proper alignment along page borders, needed for efficient read/write ops.

Definition at line 8 of file block.cpp.

8  :
9  bytes(0),
10  blockSize(aBlockSize),
11  startOffset(0),
12  hole(false) {
13  buffer = throwcall::badval(mmap(nullptr, blockSize,
14  PROT_READ | PROT_WRITE,
15  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0),
16  MAP_FAILED, "can't allocate buffer with size ", blockSize);
17 }

References throwcall::badval(), blockSize, and buffer.

Here is the call graph for this function:

◆ ~block()

block::~block ( )

Definition at line 18 of file block.cpp.

18  {
19  throwcall::good0(munmap(buffer, blockSize), "can't unmap buffer");
20 }

References blockSize, buffer, and throwcall::good0().

Here is the call graph for this function:

Member Function Documentation

◆ bufferAt() [1/2]

void * block::bufferAt ( size_t  offset)

◆ bufferAt() [2/2]

const void * block::bufferAt ( size_t  offset) const

only way to access the data in the block

Definition at line 22 of file block.cpp.

22  {
23  if (__builtin_expect(hole, false)) {
24  return nullBuffer();
25  }
26  return static_cast<const void*>(static_cast<char*>(buffer) + aOffset);
27 }

References buffer, hole, and nullBuffer().

Here is the call graph for this function:

◆ bump_size()

void block::bump_size ( size_t  additionalBytes)
inline

◆ clear()

void block::clear ( size_t  aOffset)
inline

◆ empty()

bool block::empty ( ) const
inline

< check if no data are stored

Definition at line 19 of file block.h.

19  {
20  return bytes == 0;
21  }

References bytes.

◆ isHole()

bool block::isHole ( ) const
inline

Definition at line 36 of file block.h.

36  {
37  return hole;
38  }

References hole.

Referenced by copyRequest::base::doUnthreadedCopy(), outputHandler::davix::writerDavix::writeBlock(), outputHandler::dcap::writerDcap::writeBlock(), outputHandler::libssh::writerLibssh::writeBlock(), outputHandler::posixFile::writerPosixFile::writeBlock(), and outputHandler::daosFs::writerDaosFs::writeBlock().

Here is the caller graph for this function:

◆ max_size()

size_t block::max_size ( ) const
inline

◆ nullBuffer()

const void * block::nullBuffer ( )
static

Definition at line 37 of file block.cpp.

37  {
38  static void* nullBuf = nullptr;
39  if (nullBuf == nullptr) {
40  nullBuf = throwcall::badval(mmap(nullptr, nullBufferSize(),
41  PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0),
42  MAP_FAILED, "can't allocate buffer with size ", nullBufferSize());
43  // according no mmap(2) the buffer is zero-filled
44  }
45  return nullBuf;
46 }

References throwcall::badval(), and nullBufferSize().

Referenced by bufferAt(), checksum::sslSum::update(), checksum::md5sum::update(), checksum::adler32noOpt::update(), and checksum::crc32::update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nullBufferSize()

size_t block::nullBufferSize ( )
static

Definition at line 34 of file block.cpp.

34  {
35  return 1024 * 1024 * 16;
36 }

Referenced by nullBuffer(), checksum::sslSum::update(), checksum::md5sum::update(), checksum::adler32noOpt::update(), checksum::crc32::update(), outputHandler::davix::writerDavix::writeBlock(), and outputHandler::dcap::writerDcap::writeBlock().

Here is the caller graph for this function:

◆ offset()

size_t block::offset ( ) const
inline

< returns offset in the file

Definition at line 25 of file block.h.

25  {
26  return startOffset;
27  }

References startOffset.

Referenced by inputHandler::Gpfs::readerGpfs::readBlock(), outputHandler::Gpfs::writerGpfs::writeBlock(), outputHandler::Gpfs::writerGpfs::writeBlockP(), outputHandler::posixFile::writerPosixFile::writeBlockP(), and outputHandler::daosFs::writerDaosFs::writeBlockP().

Here is the caller graph for this function:

◆ setHoleState()

void block::setHoleState ( bool  holeState)
inline

Definition at line 39 of file block.h.

39  {
40  hole = holeState;
41  }

References hole.

Referenced by inputHandler::posixFile::readerPosixFile::readBlock().

Here is the caller graph for this function:

◆ size()

size_t block::size ( ) const
inline

Member Data Documentation

◆ blockSize

size_t block::blockSize
private

capacity of the block

Definition at line 10 of file block.h.

Referenced by block(), max_size(), and ~block().

◆ buffer

void* block::buffer
private

Definition at line 8 of file block.h.

Referenced by block(), bufferAt(), and ~block().

◆ bytes

size_t block::bytes
private

number of bytes actually stored here

Definition at line 9 of file block.h.

Referenced by bump_size(), clear(), empty(), and size().

◆ hole

bool block::hole
private

represents a hole in the file with bytes bytes.

Definition at line 12 of file block.h.

Referenced by bufferAt(), clear(), isHole(), and setHoleState().

◆ startOffset

size_t block::startOffset
private

offset in the file that is represented by this block

Definition at line 11 of file block.h.

Referenced by clear(), and offset().


The documentation for this class was generated from the following files:
block::startOffset
size_t startOffset
offset in the file that is represented by this block
Definition: block.h:11
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
block::nullBuffer
static const void * nullBuffer()
Definition: block.cpp:37
block::bytes
size_t bytes
number of bytes actually stored here
Definition: block.h:9
block::blockSize
size_t blockSize
capacity of the block
Definition: block.h:10
block::buffer
void * buffer
Definition: block.h:8
block::nullBufferSize
static size_t nullBufferSize()
Definition: block.cpp:34
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
block::hole
bool hole
represents a hole in the file with bytes bytes.
Definition: block.h:12