Motr  M0
buf.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_LIB_BUF_H__
26 #define __MOTR_LIB_BUF_H__
27 
28 #include "lib/types.h"
29 #include "xcode/xcode_attr.h"
30 
37 struct m0_buf {
39  void *b_addr;
40 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(conf|rpc);
41 
43 struct m0_bufs {
44  uint32_t ab_count;
45  struct m0_buf *ab_elems;
46 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(conf|rpc);
47 
64 #define M0_BUF_INIT(size, data) \
65  ((struct m0_buf){ .b_nob = (size), .b_addr = (data) })
66 #define M0_BUF_INIT_CONST(size, data) \
67  (const struct m0_buf) { .b_nob = (size), .b_addr = (void *)(data) }
68 
69 #define M0_BUF_INIT_PTR(p) M0_BUF_INIT(sizeof *(p), (p))
70 #define M0_BUF_INITS(str) M0_BUF_INIT(strlen(str), (str))
71 #define M0_BUF_INIT0 M0_BUF_INIT(0, NULL)
72 
73 #define M0_BUF_INIT_PTR_CONST(p) M0_BUF_INIT_CONST(sizeof *(p), (p))
74 
75 #define BUF_F "[%p,%llu]"
76 #define BUF_P(p) (p)->b_addr, (unsigned long long)(p)->b_nob
77 
79 M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob);
80 
82 M0_INTERNAL int m0_buf_alloc(struct m0_buf *buf, size_t size);
83 
85 M0_INTERNAL void m0_buf_free(struct m0_buf *buf);
86 
101 M0_INTERNAL int m0_buf_cmp(const struct m0_buf *x, const struct m0_buf *y);
102 
104 M0_INTERNAL bool m0_buf_eq(const struct m0_buf *x, const struct m0_buf *y);
105 
113 M0_INTERNAL void m0_buf_memcpy(struct m0_buf *dst, const struct m0_buf *src);
114 
123 M0_INTERNAL int m0_buf_copy(struct m0_buf *dest, const struct m0_buf *src);
124 
129 M0_INTERNAL int m0_buf_new_aligned(struct m0_buf *buf,
130  const void *data, uint32_t nob,
131  unsigned shift);
132 
139 M0_INTERNAL int m0_buf_copy_aligned(struct m0_buf *dst,
140  const struct m0_buf *src,
141  unsigned shift);
142 
144 M0_INTERNAL bool m0_buf_is_set(const struct m0_buf *buf);
145 
151 M0_INTERNAL bool m0_buf_streq(const struct m0_buf *buf, const char *str);
152 
159 M0_INTERNAL char *m0_buf_strdup(const struct m0_buf *buf);
160 
167 M0_INTERNAL int m0_bufs_from_strings(struct m0_bufs *dest, const char **src);
168 
176 M0_INTERNAL int m0_bufs_to_strings(const char ***dest,
177  const struct m0_bufs *src);
178 
184 M0_INTERNAL bool m0_bufs_streq(const struct m0_bufs *bufs, const char **strs);
185 
187 M0_INTERNAL void m0_bufs_free(struct m0_bufs *bufs);
188 
190 #endif /* __MOTR_LIB_BUF_H__ */
191 
192 /*
193  * Local variables:
194  * c-indentation-style: "K&R"
195  * c-basic-offset: 8
196  * tab-width: 8
197  * fill-column: 80
198  * scroll-step: 1
199  * End:
200  */
M0_INTERNAL int m0_buf_copy_aligned(struct m0_buf *dst, const struct m0_buf *src, unsigned shift)
Definition: buf.c:119
M0_INTERNAL int m0_buf_new_aligned(struct m0_buf *buf, const void *data, uint32_t nob, unsigned shift)
Definition: buf.c:61
struct m0_buf * ab_elems
Definition: buf.h:45
M0_INTERNAL bool m0_buf_is_set(const struct m0_buf *buf)
Definition: buf.c:127
struct m0_buf M0_XCA_DOMAIN(conf|rpc)
static struct m0_bufvec dst
Definition: xform.c:61
static bool x
Definition: sm.c:168
void * b_addr
Definition: buf.h:39
M0_INTERNAL bool m0_buf_eq(const struct m0_buf *x, const struct m0_buf *y)
Definition: buf.c:90
M0_INTERNAL bool m0_buf_streq(const struct m0_buf *buf, const char *str)
Definition: buf.c:132
uint32_t ab_count
Definition: buf.h:44
M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob)
Definition: buf.c:37
struct m0_bufvec data
Definition: di.c:40
Definition: conf.py:1
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL int m0_buf_cmp(const struct m0_buf *x, const struct m0_buf *y)
Definition: buf.c:73
Definition: sock.c:887
M0_INTERNAL void m0_buf_memcpy(struct m0_buf *dst, const struct m0_buf *src)
Definition: buf.c:96
Definition: buf.h:37
M0_INTERNAL bool m0_bufs_streq(const struct m0_bufs *bufs, const char **strs)
Definition: buf.c:217
m0_bcount_t b_nob
Definition: buf.h:38
M0_INTERNAL void m0_bufs_free(struct m0_bufs *bufs)
Definition: buf.c:229
M0_INTERNAL int m0_buf_alloc(struct m0_buf *buf, size_t size)
Definition: buf.c:43
M0_INTERNAL void m0_buf_free(struct m0_buf *buf)
Definition: buf.c:55
M0_INTERNAL int m0_buf_copy(struct m0_buf *dest, const struct m0_buf *src)
Definition: buf.c:104
M0_INTERNAL char * m0_buf_strdup(const struct m0_buf *buf)
Definition: buf.c:140
M0_INTERNAL int m0_bufs_to_strings(const char ***dest, const struct m0_bufs *src)
Definition: buf.c:188
m0_bcount_t size
Definition: di.c:39
Definition: buf.h:43
struct m0_pdclust_src_addr src
Definition: fd.c:108
M0_INTERNAL int m0_bufs_from_strings(struct m0_bufs *dest, const char **src)
Definition: buf.c:157