aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/volume_id/lfs.c62
-rw-r--r--util-linux/volume_id/volume_id.c3
-rw-r--r--util-linux/volume_id/volume_id_internal.h2
3 files changed, 67 insertions, 0 deletions
diff --git a/util-linux/volume_id/lfs.c b/util-linux/volume_id/lfs.c
new file mode 100644
index 000000000..1a2a2987f
--- /dev/null
+++ b/util-linux/volume_id/lfs.c
@@ -0,0 +1,62 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2018 Sven-Göran Bergh <sgb@systemaxion.se>
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+//config:config FEATURE_VOLUMEID_LFS
+//config: bool "LittleFS filesystem"
+//config: default y
+//config: depends on VOLUMEID && FEATURE_BLKID_TYPE
+//config: help
+//config: LittleFS is a small fail-safe filesystem designed for embedded
+//config: systems. It has strong copy-on-write guarantees and storage on disk
+//config: is always kept in a valid state. It also provides a form of dynamic
+//config: wear levelling for systems that can not fit a full flash translation
+//config: layer.
+
+//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LFS) += lfs.o
+
+#include "volume_id_internal.h"
+
+#define LFS_SB1_OFFSET 0x10
+#define LFS_MAGIC_NAME "littlefs"
+#define LFS_MAGIC_LEN 8
+
+// The superblock is stored in the first metadata pair, i.e the first two blocks.
+struct lfs_super_block { // A block in a metadata pair
+// /* 0x00 */ uint32_t rev_count; // Revision count
+// /* 0x04 */ uint32_t dir_size; // Directory size
+// /* 0x08 */ uint64_t tail_ptr; // Tail pointer
+/* 0x10 */ uint8_t entry_type; // Entry type
+/* 0x11 */ uint8_t entry_len; // Entry length
+/* 0x12 */ uint8_t att_len; // Attribute length
+/* 0x13 */ uint8_t name_len; // Name length
+/* 0x14 */ uint64_t root_dir; // Root directory
+/* 0x1C */ uint32_t block_size; // Block size
+/* 0x20 */ uint32_t block_count; // Block count
+/* 0x24 */ uint16_t ver_major; // Version major
+/* 0x26 */ uint16_t ver_minor; // Version minor
+/* 0x28 */ uint8_t magic[LFS_MAGIC_LEN]; // Magic string "littlefs"
+// /* 0x30 */ uint32_t crc; // CRC-32 checksum
+} PACKED;
+
+int FAST_FUNC volume_id_probe_lfs(struct volume_id *id /*,uint64_t off*/)
+{
+ struct lfs_super_block *sb;
+
+ // Go for primary super block (ignore second sb)
+ dbg("lfs: probing at offset 0x%x", LFS_SB1_OFFSET);
+ sb = volume_id_get_buffer(id, LFS_SB1_OFFSET, sizeof(*sb));
+
+ if (!sb)
+ return -1;
+
+ if (memcmp(sb->magic, LFS_MAGIC_NAME, LFS_MAGIC_LEN) != 0)
+ return -1;
+
+ IF_FEATURE_BLKID_TYPE(id->type = LFS_MAGIC_NAME);
+
+ return 0;
+}
diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c
index 85315ced6..c3f07a741 100644
--- a/util-linux/volume_id/volume_id.c
+++ b/util-linux/volume_id/volume_id.c
@@ -97,6 +97,9 @@ static const probe_fptr fs1[] = {
#if ENABLE_FEATURE_VOLUMEID_EXFAT
volume_id_probe_exfat,
#endif
+#if ENABLE_FEATURE_VOLUMEID_LFS
+ volume_id_probe_lfs,
+#endif
#if ENABLE_FEATURE_VOLUMEID_MAC
volume_id_probe_mac_partition_map,
#endif
diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h
index 0eaea9b34..ada18339d 100644
--- a/util-linux/volume_id/volume_id_internal.h
+++ b/util-linux/volume_id/volume_id_internal.h
@@ -187,6 +187,8 @@ int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/);
int FAST_FUNC volume_id_probe_jfs(struct volume_id *id /*,uint64_t off*/);
+int FAST_FUNC volume_id_probe_lfs(struct volume_id *id /*,uint64_t off*/);
+
int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/);
int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/);