nvm_buf - Buffer Allocation

nvm_buf_set

struct nvm_buf_set

Public Members

char* write
char* write_meta
char* read
char* read_meta
size_t nbytes
size_t nbytes_meta

nvm_buf_to_file

int nvm_buf_to_file(char * buf, size_t nbytes, const char * path)

Write content of buffer into file.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • buf: Pointer to the buffer
  • nbytes: Size of buf
  • path: Destination where buffer will be dumped to

nvm_buf_from_file

int nvm_buf_from_file(char * buf, size_t nbytes, const char * path)

Read content of file into buffer.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • buf: Pointer to the buffer
  • nbytes: Size of buf
  • path: Source to read from

nvm_buf_diff

size_t nvm_buf_diff(char * expected, char * actual, size_t nbytes)

Returns the number of bytes where expected is different from actual.

nvm_buf_alloc

void* nvm_buf_alloc(const struct nvm_geo * geo, size_t nbytes)

Allocate a buffer aligned to match the given geometry.

Note
nbytes must be greater than zero and a multiple of minimal granularity
Note
Free the buffer using nvm_buf_free
Return
A pointer to the allocated memory. On error: NULL is returned and errno set appropriatly
Parameters
  • geo: The geometry to get alignment information from
  • nbytes: The size of the allocated buffer in bytes

nvm_buf_alloca

void* nvm_buf_alloca(size_t alignment, size_t nbytes)

Allocate a buffer of the given size with the given alignment.

Note
Free the buffer using nvm_buf_free
Return
A pointer to the allocated memory. On error: NULL is returned and errno set appropriatly
Parameters
  • alignment: The alignment in bytes
  • nbytes: The size of the buffer in bytes

nvm_buf_set_alloc

struct nvm_buf_set* nvm_buf_set_alloc(struct nvm_dev * dev, size_t nbytes, size_t nbytes_meta)

nvm_buf_fill

void nvm_buf_fill(char * buf, size_t nbytes)

Fills buf with chars A-Z.

Parameters
  • buf: Pointer to the buffer to fill
  • nbytes: Amount of bytes to fill in buf

nvm_buf_set_fill

void nvm_buf_set_fill(struct nvm_buf_set * bufs)

nvm_buf_free

void nvm_buf_free(void * buf)

Free the given buffer, calling regular “free” on the buffer might fail.

Parameters
  • buf: Pointer to the buffer to fill

nvm_buf_set_free

void nvm_buf_set_free(struct nvm_buf_set * bufs)

nvm_buf_diff_pr

void nvm_buf_diff_pr(char * expected, char * actual, size_t nbytes)

Prints the number and value of bytes where expected is different from actual.

nvm_buf_pr

void nvm_buf_pr(char * buf, size_t nbytes)

Prints buf to stdout.

Parameters
  • buf: Pointer to the buffer to print
  • nbytes: Amount of bytes of buf to print