From 1b883507b4d25537e079b840bda8ef7b0f76d549 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 14 Dec 2022 00:13:19 +0000 Subject: [PATCH] libblkid: swap: report endianess --- libblkid/src/superblocks/swap.c | 9 +++++++++ tests/expected/blkid/low-probe-swap1 | 1 + 2 files changed, 10 insertions(+) diff --git a/libblkid/src/superblocks/swap.c b/libblkid/src/superblocks/swap.c index fcdb13bd7c..6a05c257b6 100644 --- a/libblkid/src/superblocks/swap.c +++ b/libblkid/src/superblocks/swap.c @@ -36,6 +36,14 @@ struct swap_header_v1_2 { #define TOI_MAGIC_STRING "\xed\xc3\x02\xe9\x98\x56\xe5\x0c" #define TOI_MAGIC_STRLEN (sizeof(TOI_MAGIC_STRING) - 1) +static void swap_set_info_swap1(blkid_probe pr, + const struct swap_header_v1_2 *hdr) +{ + enum BLKID_ENDIANNESS endianness = le32_to_cpu(hdr->version) == 1 ? + BLKID_ENDIANNESS_LITTLE : BLKID_ENDIANNESS_BIG; + blkid_probe_set_fsendianness(pr, endianness); +} + static int swap_set_info(blkid_probe pr, const char *version) { struct swap_header_v1_2 *hdr; @@ -56,6 +64,7 @@ static int swap_set_info(blkid_probe pr, const char *version) DBG(LOWPROBE, ul_debug("not set last swap page")); return 1; } + swap_set_info_swap1(pr, hdr); } /* arbitrary sanity check.. is there any garbage down there? */ diff --git a/tests/expected/blkid/low-probe-swap1 b/tests/expected/blkid/low-probe-swap1 index bfac28e3e8..3565ce236c 100644 --- a/tests/expected/blkid/low-probe-swap1 +++ b/tests/expected/blkid/low-probe-swap1 @@ -1,3 +1,4 @@ +ID_FS_ENDIANNESS=LITTLE ID_FS_LABEL=SWAP-TEST ID_FS_LABEL_ENC=SWAP-TEST ID_FS_TYPE=swap -- 2.47.3