diff options
author | Sven-Göran Bergh <sgb@systemaxion.se> | 2018-01-19 20:36:15 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-19 20:37:13 +0100 |
commit | e411cd071a2b6456c653f1a7179b83bef810bb72 (patch) | |
tree | acaef2c064f79d3dc86ab6d532b3c2c360aefcdc /util-linux | |
parent | f6dd9e02155430a608e1b38036e355c045772d04 (diff) | |
download | busybox-e411cd071a2b6456c653f1a7179b83bef810bb72.tar.gz |
volume_id: add LittleFS detection
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>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/volume_id/lfs.c | 62 | ||||
-rw-r--r-- | util-linux/volume_id/volume_id.c | 3 | ||||
-rw-r--r-- | util-linux/volume_id/volume_id_internal.h | 2 |
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*/); |