-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplinter_cli_cmd_config.c
More file actions
69 lines (57 loc) · 1.94 KB
/
splinter_cli_cmd_config.c
File metadata and controls
69 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Copyright 2025 Tim Post
* License: Apache 2 (MIT available upon request to timthepost@protonmail.com)
*
* @file splinter_cli_cmd_config.c
* @brief Implements the CLI 'config' command.
*/
#include <stdio.h>
#include <string.h>
#include <stdalign.h>
#include "splinter_cli.h"
static const char *modname = "config";
void help_cmd_config(unsigned int level) {
(void) level;
printf("Usage: %s\n %s [feature_flag] [flag_value]\n", modname, modname);
printf("If no other arguments are given, %s displays the current bus settings.\n", modname);
printf("Supported flags:\n\t\"mop\" -> 0, 1 or 2\n\n");
return;
}
static void show_bus_config(void) {
splinter_header_snapshot_t snap = {0};
splinter_get_header_snapshot(&snap);
printf("magic: %u\n", snap.magic);
printf("version: %u\n", snap.version);
printf("slots: %u\n", snap.slots);
printf("alignment: %zu\n", alignof(struct splinter_slot));
printf("max_val_sz: %u\n", snap.max_val_sz);
printf("epoch: %lu\n", snap.epoch);
printf("auto_scrub : %u\n", (snap.core_flags & SPL_SYS_AUTO_SCRUB) == 1 ? 1 : 0);
puts("");
return;
}
int cmd_config(int argc, char *argv[]) {
(void) argv;
if (argc == 1) {
show_bus_config();
return 0;
}
if (argc == 3) {
// okay for now, but will need more robust argument parsing here.
// ideally we can get current values by passing just the key, for instance.
// later on ...
int opt = cli_safer_atoi(argv[2]);
if (!strncmp(argv[1], "av", 2)) {
if (opt > 2 || opt < 0) {
fprintf(stderr, "Invalid setting flag (0 = off, 1 = hybrid, 2 = boil)");
return 1;
}
return splinter_set_mop(opt);
} else {
fprintf(stderr, "Invalid configuration token: %s\n", argv[1]);
return 1;
}
}
help_cmd_config(1);
return 1;
}