Skip to content

Commit 3bb62ab

Browse files
committed
caformat: don't mask out feature flags based on compile time options in public headers
The caxyz.h headers should really stay free of #ifdef-fery based on compile time options, as it's the stuff that is supposed to become the publicly installed library API headers. Hence, let's define the feature bits unconditionally in the header in all its most featureful flory, but then let's mask out what we can't support internally. This is a rework of #127
1 parent 864b346 commit 3bb62ab

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

Diff for: src/caencoder.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ CaEncoder *ca_encoder_new(void) {
223223
if (!e)
224224
return NULL;
225225

226-
assert_se(ca_feature_flags_normalize(CA_FORMAT_DEFAULT, &e->feature_flags) >= 0);
226+
e->feature_flags = CA_FORMAT_DEFAULT & SUPPORTED_FEATURE_MASK;
227227
e->time_granularity = 1;
228228

229229
return e;

Diff for: src/caformat.h

-6
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ enum {
154154
CA_FORMAT_WITH_SUBVOLUME_RO|
155155
CA_FORMAT_WITH_XATTRS|
156156
CA_FORMAT_WITH_ACL|
157-
#if HAVE_SELINUX
158157
CA_FORMAT_WITH_SELINUX|
159-
#endif
160158
CA_FORMAT_WITH_FCAPS|
161159
CA_FORMAT_WITH_QUOTA_PROJID,
162160

@@ -204,9 +202,7 @@ enum {
204202
CA_FORMAT_WITH_SUBVOLUME|
205203
CA_FORMAT_WITH_SUBVOLUME_RO|
206204
CA_FORMAT_WITH_ACL|
207-
#if HAVE_SELINUX
208205
CA_FORMAT_WITH_SELINUX|
209-
#endif
210206
CA_FORMAT_WITH_FCAPS|
211207
CA_FORMAT_WITH_QUOTA_PROJID,
212208

@@ -258,9 +254,7 @@ enum {
258254
CA_FORMAT_WITH_SUBVOLUME_RO|
259255
CA_FORMAT_WITH_XATTRS|
260256
CA_FORMAT_WITH_ACL|
261-
#if HAVE_SELINUX
262257
CA_FORMAT_WITH_SELINUX|
263-
#endif
264258
CA_FORMAT_WITH_FCAPS|
265259
CA_FORMAT_WITH_QUOTA_PROJID,
266260

Diff for: src/caseed.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "caformat.h"
1212
#include "calocation.h"
1313
#include "caseed.h"
14+
#include "def.h"
1415
#include "realloc-buffer.h"
1516
#include "rm-rf.h"
1617
#include "util.h"
@@ -63,7 +64,7 @@ CaSeed *ca_seed_new(void) {
6364

6465
s->chunker = (CaChunker) CA_CHUNKER_INIT;
6566

66-
assert_se(ca_feature_flags_normalize(CA_FORMAT_DEFAULT, &s->feature_flags) >= 0);
67+
s->feature_flags = CA_FORMAT_DEFAULT & SUPPORTED_FEATURE_MASK;
6768

6869
return s;
6970
}

Diff for: src/casync-tool.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "caremote.h"
2323
#include "castore.h"
2424
#include "casync.h"
25+
#include "def.h"
2526
#include "gc.h"
2627
#include "notify.h"
2728
#include "parse-util.h"
@@ -299,7 +300,7 @@ static int dump_with_flags(void) {
299300
_cleanup_free_ char *s = NULL;
300301
uint64_t flag = UINT64_C(1) << i;
301302

302-
if (!(flag & CA_FORMAT_WITH_MASK))
303+
if (!(flag & SUPPORTED_WITH_MASK))
303304
continue;
304305

305306
r = ca_with_feature_flags_format(flag, &s);
@@ -1268,7 +1269,7 @@ static int verb_make(int argc, char *argv[]) {
12681269
return log_error_errno(r, "Failed to set store: %m");
12691270
}
12701271

1271-
r = load_feature_flags(s, operation == MAKE_BLOB_INDEX ? 0 : CA_FORMAT_WITH_MASK);
1272+
r = load_feature_flags(s, operation == MAKE_BLOB_INDEX ? 0 : SUPPORTED_WITH_MASK);
12721273
if (r < 0)
12731274
return r;
12741275

@@ -1583,7 +1584,7 @@ static int verb_extract(int argc, char *argv[]) {
15831584
if (r < 0)
15841585
return r;
15851586

1586-
r = load_feature_flags(s, CA_FORMAT_WITH_MASK);
1587+
r = load_feature_flags(s, SUPPORTED_WITH_MASK);
15871588
if (r < 0)
15881589
return r;
15891590

@@ -2191,7 +2192,7 @@ static int verb_list(int argc, char *argv[]) {
21912192
if (r < 0)
21922193
return r;
21932194

2194-
r = load_feature_flags(s, CA_FORMAT_WITH_MASK);
2195+
r = load_feature_flags(s, SUPPORTED_WITH_MASK);
21952196
if (r < 0)
21962197
return r;
21972198

@@ -2500,7 +2501,7 @@ static int verb_digest(int argc, char *argv[]) {
25002501
if (r < 0)
25012502
return r;
25022503

2503-
r = load_feature_flags(s, IN_SET(operation, DIGEST_BLOB, DIGEST_BLOB_INDEX) ? 0 : CA_FORMAT_WITH_MASK);
2504+
r = load_feature_flags(s, IN_SET(operation, DIGEST_BLOB, DIGEST_BLOB_INDEX) ? 0 : SUPPORTED_WITH_MASK);
25042505
if (r < 0)
25052506
return r;
25062507

Diff for: src/casync.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ CaSync *ca_sync_new_encode(void) {
184184
return NULL;
185185

186186
s->direction = CA_SYNC_ENCODE;
187-
assert_se(ca_feature_flags_normalize(CA_FORMAT_DEFAULT, &s->feature_flags) >= 0);
187+
s->feature_flags = CA_FORMAT_DEFAULT & SUPPORTED_FEATURE_MASK;
188188

189189
return s;
190190
}

Diff for: src/def.h

+8
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@
77

88
#define BUFFER_SIZE (64U*1024U)
99

10+
#if HAVE_SELINUX
11+
#define SUPPORTED_FEATURE_MASK CA_FORMAT_FEATURE_FLAGS_MAX
12+
#else
13+
#define SUPPORTED_FEATURE_MASK (CA_FORMAT_FEATURE_FLAGS_MAX &~ CA_FORMAT_WITH_SELINUX)
14+
#endif
15+
16+
#define SUPPORTED_WITH_MASK (CA_FORMAT_WITH_MASK & SUPPORTED_FEATURE_MASK)
17+
1018
#endif

0 commit comments

Comments
 (0)