nvm_buf - Buffer Allocation¶
nvm_buf_set¶
-
struct
nvm_buf_set
¶ Encapsulation of a IO buffer-set for common-case setup.
This structure is allocated and initialized by
nvm_buf_set_alloc
, and de-allocated bynvm_buf_set_free
nvm_buf_vtophys¶
-
int
nvm_buf_vtophys
(const struct nvm_dev * dev, void * buf, uint64_t * phys)¶ Retrieve the physical address of the given buffer.
- Return
- On success, 0 is returned. On error, -1 is returned and errno set to indicate the error.
- Parameters
dev
: Pointer to the device which the IO buffer was allocated forbuf
: Pointer to a buffer allocated withnvm_buf_alloc
phys
: A pointer to the variable to hold the physical address of the given buffer.
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 buffernbytes
: Size of bufpath
: 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 buffernbytes
: Size of bufpath
: 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_dev * dev, size_t nbytes, uint64_t * phys)¶ Allocate a buffer for IO with the given device.
The buffer will be aligned to device geometry and DMA allocated if required by the backend for IO
- Note
- nbytes must be greater than zero and a multiple of minimal granularity
- Note
- De-allocate the buffer using
nvm_buf_free
- See
- nvm_buf_free
- Return
- On success, a pointer to the allocated memory is returned. On error, NULL is returned and
errno
set to indicate the error. - Parameters
dev
: The device to allocate IO buffers fornbytes
: The size of the allocated buffer in bytesphys
: A pointer to the variable to hold the physical address of the allocated buffer. If NULL, the physical address is not returned.
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_virt_alloc¶
-
void*
nvm_buf_virt_alloc
(size_t alignment, size_t nbytes)¶ Allocate a buffer of virtual memory of the given ‘nbytes’ and ‘alignment’.
- Note
- You must use
nvm_buf_virt_free
to de-allocate the buffer - Return
- A pointer to the allocated memory. On error: NULL is returned and
errno
set appropriatly - Parameters
alignment
: The alignment in bytesnbytes
: The size of the buffer in bytes
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 fillnbytes
: 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
(const struct nvm_dev * dev, void * buf)¶ Free the given IO buffer allocated with
nvm_buf_alloc
- See
- nvm_buf_alloc
- Parameters
dev
: Pointer to the device which the IO buffer was allocated forbuf
: Pointer to a buffer allocated withnvm_buf_alloc
nvm_buf_set_free¶
-
void
nvm_buf_set_free
(struct nvm_buf_set * bufs)¶
nvm_buf_virt_free¶
-
void
nvm_buf_virt_free
(void * buf)¶ Free the given virtual memory buffer.
- Parameters
buf
: Pointer to a buffer allocated withnvm_buf_virt_alloc
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 printnbytes
: Amount of bytes of buf to print
nvm_buf_set_pr¶
-
void
nvm_buf_set_pr
(struct nvm_buf_set * bufs)¶ Prints the given nvm_buf_set.