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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* Copyright (C) 2020 - Vito Caputo - <vcaputo@pengaru.com>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <iou.h>
#include "reclaim-tail-waste.h"
#include "report-tail-waste.h"
#include "report-usage.h"
#include "upstream/journal-def.h"
/* jio - journal-file input/output tool */
/* Copyright (c) 2020 Vito Caputo <vcaputo@pengaru.com> */
/* XXX: This is a WIP experiment, use at your own risk! XXX */
int main(int argc, char *argv[])
{
iou_t *iou;
int r;
if (argc < 2) {
printf("Usage: %s {help,reclaim,report} [subcommand-args]\n", argv[0]);
return 0;
}
iou = iou_new(8);
if (!iou)
return 1;
/* FIXME TODO This is ad-hoc open-coded jank for now */
if (!strcmp(argv[1], "help")) {
printf(
"\n"
" help show this help\n"
" license print license header\n"
" reclaim [subcmd] reclaim space from journal files\n"
" tail-waste reclaim wasted space from tails of archives\n"
"\n"
" report [subcmd] report statistics about journal files\n"
" usage report space used by various object types\n"
" tail-waste report extra space allocated onto tails\n"
" version print jio version\n"
"\n"
);
return 0;
} else if (!strcmp(argv[1], "license")) {
printf(
"\n"
" Copyright (C) 2020 - Vito Caputo - <vcaputo@pengaru.com>\n"
"\n"
" This program is free software: you can redistribute it and/or modify it\n"
" under the terms of the GNU General Public License version 3 as published\n"
" by the Free Software Foundation.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License\n"
" along with this program. If not, see <http://www.gnu.org/licenses/>.\n"
"\n"
);
return 0;
} else if (!strcmp(argv[1], "reclaim")) {
if (argc < 3) {
printf("Usage: %s reclaim {tail-waste}\n", argv[0]);
return 0;
}
if (!strcmp(argv[2], "tail-waste")) {
r = jio_reclaim_tail_waste(iou, argc, argv);
if (r < 0) {
fprintf(stderr, "failed to reclaim tail waste: %s\n", strerror(-r));
return 1;
}
} else {
fprintf(stderr, "Unsupported reclaim subcommand: \"%s\"\n", argv[2]);
return 1;
}
} else if (!strcmp(argv[1], "report")) {
if (argc < 3) {
printf("Usage: %s report {usage,tail-waste}\n", argv[0]);
return 0;
}
if (!strcmp(argv[2], "tail-waste")) {
r = jio_report_tail_waste(iou, argc, argv);
if (r < 0) {
fprintf(stderr, "failed to report tail waste: %s\n", strerror(-r));
return 1;
}
} else if (!strcmp(argv[2], "usage")) {
r = jio_report_usage(iou, argc, argv);
if (r < 0) {
fprintf(stderr, "failed to report usage: %s\n", strerror(-r));
return 1;
}
} else {
fprintf(stderr, "Unsupported report subcommand: \"%s\"\n", argv[2]);
return 1;
}
} else if (!strcmp(argv[1], "version")) {
puts("jio version " VERSION);
return 0;
} else {
fprintf(stderr, "Unsupported subcommand: \"%s\"\n", argv[1]);
return 1;
}
if (!r) {
/* XXX: note this is a successful noop if there's no outstanding io */
r = iou_run(iou);
if (r < 0)
fprintf(stderr, "iou error: %s\n", strerror(-r));
}
iou_free(iou);
return r != 0;
}
|