volume_id: add LittleFS detection
authorSven-Göran Bergh <sgb@systemaxion.se>
Fri, 19 Jan 2018 19:36:15 +0000 (20:36 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 19 Jan 2018 19:37:13 +0000 (20:37 +0100)
Add support for LittleFS to blkid. Not included if FEATURE_BLKID_TYPE
is not selected (neither UUID nor label).

LittleFS is a small fail-safe filesystem designed for embedded
systems. It has strong copy-on-write guarantees and storage on disk
is always kept in a valid state. It also provides a form of dynamic
wear levelling for systems that can not fit a full flash translation
layer. (https://github.com/geky/littlefs)

ARM has introduced it in its Mbed OS 5.7, so it starts to gain focus.
(https://os.mbed.com/blog/entry/littlefs-high-integrity-embedded-fs/)

function                                             old     new   delta
volume_id_probe_lfs                                    -      62     +62
fs1                                                   20      24      +4

Signed-off-by: Sven-Göran Bergh <sgb@systemaxion.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
util-linux/volume_id/lfs.c [new file with mode: 0644]
util-linux/volume_id/volume_id.c
util-linux/volume_id/volume_id_internal.h

diff --git a/util-linux/volume_id/lfs.c b/util-linux/volume_id/lfs.c
new file mode 100644 (file)
index 0000000..1a2a298
--- /dev/null
@@ -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;
+}
index 85315ced6c2720c9321211286c365287bbfa60b3..c3f07a741a21c70faa67193b684bf79a521156b0 100644 (file)
@@ -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
index 0eaea9b34c5c2d2197e5ff72c08d545f372a1c3c..ada18339d07c6458d4970e4cc45ceea2038b9b9f 100644 (file)
@@ -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*/);