Motr  M0
ext.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-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 #include "lib/ext.h"
24 #include "lib/arith.h" /* max_check, min_check */
25 #include "lib/misc.h" /* M0_EXPORTED */
26 
32 M0_INTERNAL void m0_ext_init(struct m0_ext *ext)
33 {
35  .ot_version = M0_EXT_FORMAT_VERSION,
36  .ot_type = M0_FORMAT_TYPE_EXT,
37  .ot_footer_offset = offsetof(struct m0_ext, e_footer)
38  });
40 }
41 
42 M0_INTERNAL m0_bcount_t m0_ext_length(const struct m0_ext *ext)
43 {
44  return ext->e_end - ext->e_start;
45 }
46 M0_EXPORTED(m0_ext_length);
47 
48 M0_INTERNAL bool m0_ext_is_in(const struct m0_ext *ext, m0_bindex_t index)
49 {
50  return ext->e_start <= index && index < ext->e_end;
51 }
52 
53 M0_INTERNAL bool m0_ext_are_overlapping(const struct m0_ext *e0,
54  const struct m0_ext *e1)
55 {
56  struct m0_ext i;
57 
58  m0_ext_intersection(e0, e1, &i);
59  return m0_ext_is_valid(&i);
60 }
61 
62 M0_INTERNAL bool m0_ext_is_partof(const struct m0_ext *super,
63  const struct m0_ext *sub)
64 {
65  return
66  m0_ext_is_in(super, sub->e_start) &&
67  sub->e_end <= super->e_end;
68 }
69 
70 M0_INTERNAL bool m0_ext_equal(const struct m0_ext *a, const struct m0_ext *b)
71 {
72  return a->e_start == b->e_start && a->e_end == b->e_end;
73 }
74 
75 
76 M0_INTERNAL bool m0_ext_is_empty(const struct m0_ext *ext)
77 {
78  return ext->e_end <= ext->e_start;
79 }
80 
81 M0_INTERNAL void m0_ext_intersection(const struct m0_ext *e0,
82  const struct m0_ext *e1,
83  struct m0_ext *result)
84 {
85  result->e_start = max_check(e0->e_start, e1->e_start);
86  result->e_end = min_check(e0->e_end, e1->e_end);
87 }
88 M0_EXPORTED(m0_ext_intersection);
89 
90 M0_INTERNAL bool m0_ext_is_valid(const struct m0_ext *ext)
91 {
92  return ext->e_end > ext->e_start;
93 }
94 M0_EXPORTED(m0_ext_is_valid);
95 
98 /*
99  * Local variables:
100  * c-indentation-style: "K&R"
101  * c-basic-offset: 8
102  * tab-width: 8
103  * fill-column: 80
104  * scroll-step: 1
105  * End:
106  */
M0_INTERNAL m0_bcount_t m0_ext_length(const struct m0_ext *ext)
Definition: ext.c:42
M0_INTERNAL void m0_format_header_pack(struct m0_format_header *dest, const struct m0_format_tag *src)
Definition: format.c:40
m0_bindex_t e_end
Definition: ext.h:40
struct m0_format_header e_header
Definition: ext.h:38
#define min_check(a, b)
Definition: arith.h:88
#define max_check(a, b)
Definition: arith.h:95
uint64_t m0_bindex_t
Definition: types.h:80
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL bool m0_ext_equal(const struct m0_ext *a, const struct m0_ext *b)
Definition: ext.c:70
int i
Definition: dir.c:1033
M0_INTERNAL bool m0_ext_is_valid(const struct m0_ext *ext)
Definition: ext.c:90
M0_INTERNAL void m0_ext_init(struct m0_ext *ext)
Definition: ext.c:32
M0_INTERNAL bool m0_ext_is_partof(const struct m0_ext *super, const struct m0_ext *sub)
Definition: ext.c:62
M0_INTERNAL bool m0_ext_is_in(const struct m0_ext *ext, m0_bindex_t index)
Definition: ext.c:48
M0_INTERNAL bool m0_ext_is_empty(const struct m0_ext *ext)
Definition: ext.c:76
Definition: ext.h:37
m0_bindex_t e_start
Definition: ext.h:39
M0_INTERNAL void m0_format_footer_update(const void *buffer)
Definition: format.c:95
M0_INTERNAL bool m0_ext_are_overlapping(const struct m0_ext *e0, const struct m0_ext *e1)
Definition: ext.c:53
M0_INTERNAL void m0_ext_intersection(const struct m0_ext *e0, const struct m0_ext *e1, struct m0_ext *result)
Definition: ext.c:81