summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-18 12:51:36 -0400
committerLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-18 13:00:59 -0400
commit1e13f3671739e98f4e6d8531b9b22c93d24589f8 (patch)
treec480dd88275d9ae41b6a00e239cb0a0da130d096 /src
parent39eff20bd938bae630270a3f06b17f787663826c (diff)
pull strextentflags in to a function
Diffstat (limited to 'src')
-rw-r--r--src/cow-extent-map.c87
1 files changed, 4 insertions, 83 deletions
diff --git a/src/cow-extent-map.c b/src/cow-extent-map.c
index 1a791a0..aeedadf 100644
--- a/src/cow-extent-map.c
+++ b/src/cow-extent-map.c
@@ -5,10 +5,9 @@
#include <fcntl.h> /* for open(2) and O_RDONLY */
#include <getopt.h> /* for getopt_long(3gnu), struct option, optind, optarg */
#include <inttypes.h> /* PRI* */
-#include <stdbool.h> /* for bool, true, false */
-#include <stdio.h> /* for printf(3p), fprintf(3p), sprintf(3p), stderr */
-#include <stdlib.h> /* malloc(3p), freep(3p), exit(3p), EXIT_SUCCESS, EXIT_FAILURE */
-#include <string.h> /* for strcmp(3p), strlen(3p), strcpy(3p) */
+#include <stdio.h> /* for printf(3p), fprintf(3p), stderr */
+#include <stdlib.h> /* free(3p), exit(3p), EXIT_SUCCESS, EXIT_FAILURE */
+#include <string.h> /* for strcmp(3p) */
#include "extent-map.h" /* for uint32_t, fiemap stuff */
@@ -19,86 +18,8 @@
exit(EXIT_INVALIDARGUMENT); \
} while(0)
-struct flag {
- char *name;
- uint32_t value;
- bool active;
-};
-
int print_extent(struct fiemap_extent extent) {
- struct flag known_flags[] = {
- {"LAST", FIEMAP_EXTENT_LAST, false},
- {"UNKNOWN", FIEMAP_EXTENT_UNKNOWN, false},
- {"DELALLOC", FIEMAP_EXTENT_DELALLOC, false},
- {"ENCODED", FIEMAP_EXTENT_ENCODED, false},
- {"DATA_ENCRYPTED", FIEMAP_EXTENT_DATA_ENCRYPTED, false},
- {"NOT_ALIGNED", FIEMAP_EXTENT_NOT_ALIGNED, false},
- {"DATA_INLINE", FIEMAP_EXTENT_DATA_INLINE, false},
- {"DATA_TAIL", FIEMAP_EXTENT_DATA_TAIL, false},
- {"UNWRITTEN", FIEMAP_EXTENT_UNWRITTEN, false},
- {"MERGED", FIEMAP_EXTENT_MERGED, false},
- {"SHARED", FIEMAP_EXTENT_SHARED, false},
- };
- uint32_t flags = extent.fe_flags;
- size_t flagstr_cap = 0;
- for (size_t i = 0; i < sizeof(known_flags)/sizeof(known_flags[0]); i++) {
- if (!(flags & known_flags[i].value))
- continue;
- known_flags[i].active = true;
- flags ^= known_flags[i].value;
- switch (known_flags[i].value) {
- case FIEMAP_EXTENT_UNKNOWN:
- if (flags & FIEMAP_EXTENT_DELALLOC) {
- known_flags[i].name = "(UNKNOWN|DELALLOC)";
- flags ^= FIEMAP_EXTENT_DELALLOC;
- }
- break;
- case FIEMAP_EXTENT_ENCODED:
- if (flags & FIEMAP_EXTENT_DATA_ENCRYPTED) {
- known_flags[i].name = "(ENCODED|DATA_ENCRYPTED)";
- flags ^= FIEMAP_EXTENT_DATA_ENCRYPTED;
- }
- break;
- case FIEMAP_EXTENT_NOT_ALIGNED:
- switch (flags & (FIEMAP_EXTENT_DATA_INLINE|FIEMAP_EXTENT_DATA_TAIL)) {
- case FIEMAP_EXTENT_DATA_INLINE:
- known_flags[i].name = "(NOT_ALIGNED|DATA_INLINE)";
- flags ^= FIEMAP_EXTENT_DATA_INLINE;
- break;
- case FIEMAP_EXTENT_DATA_TAIL:
- known_flags[i].name = "(NOT_ALIGNED|DATA_TAIL)";
- flags ^= FIEMAP_EXTENT_DATA_TAIL;
- break;
- case FIEMAP_EXTENT_DATA_INLINE|FIEMAP_EXTENT_DATA_TAIL:
- known_flags[i].name = "(NOT_ALIGNED|DATA_INLINE|DATA_TAIL)";
- flags ^= FIEMAP_EXTENT_DATA_INLINE|FIEMAP_EXTENT_DATA_TAIL;
- break;
- }
- break;
- }
- if (flagstr_cap)
- flagstr_cap++;
- flagstr_cap += strlen(known_flags[i].name);
- }
- if (flags)
- flagstr_cap += (flagstr_cap ? 1 : 0) + 10;
- char *flagstr = malloc(flagstr_cap+1);
- if (!flagstr)
- error(EXIT_FAILURE, errno, "malloc");
- size_t flagstr_len = 0;
- for (size_t i = 0; i < sizeof(known_flags)/sizeof(known_flags[0]); i++) {
- if (!known_flags[i].active)
- continue;
- if (flagstr_len)
- flagstr[flagstr_len++] = '|';
- strcpy(&flagstr[flagstr_len], known_flags[i].name);
- flagstr_len += strlen(known_flags[i].name);
- }
- if (flags) {
- if (flagstr_len)
- flagstr[flagstr_len++] = '|';
- sprintf(&flagstr[flagstr_len], "0x%08"PRIx32, flags);
- };
+ char *flagstr = strextentflags(extent.fe_flags);
printf("logical=%"PRIu64" "
"physical=%"PRIu64" "
"length=%"PRIu64" "