Motr  M0
Basic buffer type

Data Structures

struct  m0_buf
 
struct  m0_bufs
 

Macros

#define M0_BUF_INIT(size, data)   ((struct m0_buf){ .b_nob = (size), .b_addr = (data) })
 
#define M0_BUF_INIT_CONST(size, data)   (const struct m0_buf) { .b_nob = (size), .b_addr = (void *)(data) }
 
#define M0_BUF_INIT_PTR(p)   M0_BUF_INIT(sizeof *(p), (p))
 
#define M0_BUF_INITS(str)   M0_BUF_INIT(strlen(str), (str))
 
#define M0_BUF_INIT0   M0_BUF_INIT(0, NULL)
 
#define M0_BUF_INIT_PTR_CONST(p)   M0_BUF_INIT_CONST(sizeof *(p), (p))
 
#define BUF_F   "[%p,%llu]"
 
#define BUF_P(p)   (p)->b_addr, (unsigned long long)(p)->b_nob
 

Functions

M0_INTERNAL void m0_buf_init (struct m0_buf *buf, void *data, uint32_t nob)
 
M0_INTERNAL int m0_buf_alloc (struct m0_buf *buf, size_t size)
 
M0_INTERNAL void m0_buf_free (struct m0_buf *buf)
 
M0_INTERNAL int m0_buf_new_aligned (struct m0_buf *buf, const void *data, uint32_t nob, unsigned shift)
 
M0_INTERNAL int m0_buf_cmp (const struct m0_buf *x, const struct m0_buf *y)
 
M0_INTERNAL bool m0_buf_eq (const struct m0_buf *x, const struct m0_buf *y)
 
M0_INTERNAL void m0_buf_memcpy (struct m0_buf *dst, const struct m0_buf *src)
 
M0_INTERNAL int m0_buf_copy (struct m0_buf *dest, const struct m0_buf *src)
 
M0_INTERNAL int m0_buf_copy_aligned (struct m0_buf *dst, const struct m0_buf *src, unsigned shift)
 
M0_INTERNAL bool m0_buf_is_set (const struct m0_buf *buf)
 
M0_INTERNAL bool m0_buf_streq (const struct m0_buf *buf, const char *str)
 
M0_INTERNAL char * m0_buf_strdup (const struct m0_buf *buf)
 
M0_INTERNAL int m0_bufs_from_strings (struct m0_bufs *dest, const char **src)
 
M0_INTERNAL int m0_bufs_to_strings (const char ***dest, const struct m0_bufs *src)
 
M0_INTERNAL bool m0_bufs_streq (const struct m0_bufs *bufs, const char **strs)
 
M0_INTERNAL void m0_bufs_free (struct m0_bufs *bufs)
 
struct m0_buf M0_XCA_DOMAIN (conf|rpc)
 

Detailed Description

Macro Definition Documentation

◆ BUF_F

#define BUF_F   "[%p,%llu]"

Definition at line 75 of file buf.h.

◆ BUF_P

#define BUF_P (   p)    (p)->b_addr, (unsigned long long)(p)->b_nob

Definition at line 76 of file buf.h.

◆ M0_BUF_INIT

#define M0_BUF_INIT (   size,
  data 
)    ((struct m0_buf){ .b_nob = (size), .b_addr = (data) })

Initialisers for struct m0_buf.

Note
  1. #include "lib/misc.h" for M0_BUF_INITS().
  2. M0_BUF_INITS() cannot be used with ‘static’ variables.
    // static const struct m0_buf bad = M0_BUF_INITS("foo");
    // ==> warning: initializer element is not constant
    static char str[] = "foo";
    static const struct m0_buf good = M0_BUF_INIT(sizeof str, str);

Definition at line 64 of file buf.h.

◆ M0_BUF_INIT0

#define M0_BUF_INIT0   M0_BUF_INIT(0, NULL)

Definition at line 71 of file buf.h.

◆ M0_BUF_INIT_CONST

#define M0_BUF_INIT_CONST (   size,
  data 
)    (const struct m0_buf) { .b_nob = (size), .b_addr = (void *)(data) }

Definition at line 66 of file buf.h.

◆ M0_BUF_INIT_PTR

#define M0_BUF_INIT_PTR (   p)    M0_BUF_INIT(sizeof *(p), (p))

Definition at line 69 of file buf.h.

◆ M0_BUF_INIT_PTR_CONST

#define M0_BUF_INIT_PTR_CONST (   p)    M0_BUF_INIT_CONST(sizeof *(p), (p))

Definition at line 73 of file buf.h.

◆ M0_BUF_INITS

#define M0_BUF_INITS (   str)    M0_BUF_INIT(strlen(str), (str))

Definition at line 70 of file buf.h.

Function Documentation

◆ m0_buf_alloc()

M0_INTERNAL int m0_buf_alloc ( struct m0_buf buf,
size_t  size 
)

Allocates memory pointed to by ->b_addr of size .

Definition at line 43 of file buf.c.

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

◆ m0_buf_cmp()

M0_INTERNAL int m0_buf_cmp ( const struct m0_buf x,
const struct m0_buf y 
)

Compares memory of two buffers.

Returns zero if buffers are equal (including their sizes). Otherwise, returns difference between the first pair of bytes that differ in ‘x’ and ‘y’. If buffers have different sizes and one is a prefix of the second, the sign of the expression (x->b_nob - y->b_nob) is returned.

Therefore, sign of the return value can be used to determine lexicographical order of the buffers.

m0_buf_cmp() can be treated as an analogue of strcmp(3) for m0_buf strings that may contain '\0'.

Definition at line 73 of file buf.c.

Here is the caller graph for this function:

◆ m0_buf_copy()

M0_INTERNAL int m0_buf_copy ( struct m0_buf dest,
const struct m0_buf src 
)

Copies a buffer.

User is responsible for m0_buf_free()ing ‘dest’.

Precondition
dest->b_nob == 0 && dest->b_addr == NULL
Postcondition
ergo(result == 0, m0_buf_eq(dest, src))

Definition at line 104 of file buf.c.

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

◆ m0_buf_copy_aligned()

M0_INTERNAL int m0_buf_copy_aligned ( struct m0_buf dst,
const struct m0_buf src,
unsigned  shift 
)

Allocates 'dst' buffer aligned on (2^shift)-byte boundary and copies 'src' into it.

Precondition
dst->b_nob == 0 && dst->b_addr == NULL

Definition at line 119 of file buf.c.

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

◆ m0_buf_eq()

M0_INTERNAL bool m0_buf_eq ( const struct m0_buf x,
const struct m0_buf y 
)

Returns true iff two buffers are equal.

Definition at line 90 of file buf.c.

Here is the caller graph for this function:

◆ m0_buf_free()

M0_INTERNAL void m0_buf_free ( struct m0_buf buf)

Frees memory pointed to by buf->b_addr and zeroes buffer's fields.

Definition at line 55 of file buf.c.

◆ m0_buf_init()

M0_INTERNAL void m0_buf_init ( struct m0_buf buf,
void *  data,
uint32_t  nob 
)

Initialises struct m0_buf.

Definition at line 37 of file buf.c.

◆ m0_buf_is_set()

M0_INTERNAL bool m0_buf_is_set ( const struct m0_buf buf)

Does the buffer point at anything?

Definition at line 127 of file buf.c.

Here is the caller graph for this function:

◆ m0_buf_memcpy()

M0_INTERNAL void m0_buf_memcpy ( struct m0_buf dst,
const struct m0_buf src 
)

Copies a buffer without allocation. Destination buffer must point to a valid memory location and it has to have the same size as the source buffer.

Precondition
dst->b_nob == src->b_nob

Definition at line 96 of file buf.c.

Here is the caller graph for this function:

◆ m0_buf_new_aligned()

M0_INTERNAL int m0_buf_new_aligned ( struct m0_buf buf,
const void *  data,
uint32_t  nob,
unsigned  shift 
)

Allocates 'buf' aligned on (2^shift)-byte boundary and copies 'data' into it.

Definition at line 61 of file buf.c.

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

◆ m0_buf_strdup()

M0_INTERNAL char * m0_buf_strdup ( const struct m0_buf buf)

Duplicates a string pointed to by buf->b_addr.

Maximum length of the resulting string, including null character, is buf->b_nob.

Definition at line 140 of file buf.c.

Here is the caller graph for this function:

◆ m0_buf_streq()

M0_INTERNAL bool m0_buf_streq ( const struct m0_buf buf,
const char *  str 
)

Do ‘buf’ and ‘str’ contain equal sequences of non-'\0' characters?

Precondition
str != NULL

Definition at line 132 of file buf.c.

Here is the caller graph for this function:

◆ m0_bufs_free()

M0_INTERNAL void m0_bufs_free ( struct m0_bufs bufs)

Frees memory buffers.

Definition at line 229 of file buf.c.

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

◆ m0_bufs_from_strings()

M0_INTERNAL int m0_bufs_from_strings ( struct m0_bufs dest,
const char **  src 
)

Constructs a sequence of memory buffers, copying data from NULL-terminated array of C strings.

User is responsible for m0_bufs_free()ing ‘dest’.

Definition at line 157 of file buf.c.

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

◆ m0_bufs_streq()

M0_INTERNAL bool m0_bufs_streq ( const struct m0_bufs bufs,
const char **  strs 
)

Checks equality of given sequences.

See also
m0_buf_streq()

Definition at line 217 of file buf.c.

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

◆ m0_bufs_to_strings()

M0_INTERNAL int m0_bufs_to_strings ( const char ***  dest,
const struct m0_bufs src 
)

Constructs a NULL-terminated array of C strings, copying data from a sequence of memory buffers.

The elements of ‘*dest’ should be freed eventually.

See also
m0_strings_free()

Definition at line 188 of file buf.c.

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

◆ M0_XCA_DOMAIN()

struct m0_buf M0_XCA_DOMAIN ( conf rpc)