Skip to content

Commit

Permalink
libblkid: add erofs filesystem support
Browse files Browse the repository at this point in the history
Enhanced Read-Only File System (EROFS) has been included in Linux
kernel, many Linux distributions, buildroot and Android AOSP for
a while. Plus, nowadays, it's known that EROFS has been commercially
used by several Android vendors for their system partitions.

This patch adds support for detecting EROFS filesystem to libblkid.

Since util-linux/util-linux@cd129b7 introduced blkid_probe_set_block_size
function to report filesystem block size, TWRP is using blkid 2.25.0, which
means blkid_probe_set_block_size wasn't supported and required, so remove
the blkszbits judgement and blkid_probe_set_block_size for fixing building.

Test: Add erofs mount point to twrp.flags, build and boot
OP4A7A:/ # logcat | grep erofs
I (6)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.
I (6)[571:recovery]erofs: (device dm-9): mounted with opts: , root inode @ nid 43.
I (6)[571:recovery]erofs: (device dm-1): mounted with opts: , root inode @ nid 52.
I (6)[571:recovery]erofs: (device dm-10): mounted with opts: , root inode @ nid 45.
I (6)[571:recovery]erofs: (device dm-8): mounted with opts: , root inode @ nid 42.
I (0)[571:recovery]erofs: (device dm-12): mounted with opts: , root inode @ nid 38.
I (3)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.
I (3)[571:recovery]erofs: (device dm-1): mounted with opts: , root inode @ nid 52.
I (3)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.
I (3)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.
I (3)[571:recovery]erofs: (device dm-9): mounted with opts: , root inode @ nid 43.
I (2)[571:recovery]erofs: (device dm-1): mounted with opts: , root inode @ nid 52.
I (2)[571:recovery]erofs: (device dm-10): mounted with opts: , root inode @ nid 45.
I (2)[571:recovery]erofs: (device dm-8): mounted with opts: , root inode @ nid 42.
I (2)[571:recovery]erofs: (device dm-12): mounted with opts: , root inode @ nid 38.
I (6)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.
I (6)[571:recovery]erofs: (device dm-0): mounted with opts: , root inode @ nid 58.

OP4A7A:/ # cat /tmp/recovery.log | grep erofs
   Current_File_System: erofs
   Fstab_File_System: erofs
   Current_File_System: erofs
   Fstab_File_System: erofs
   Fstab_File_System: erofs
   Current_File_System: erofs
   Fstab_File_System: erofs
   Current_File_System: erofs
   Fstab_File_System: erofs
   Current_File_System: erofs
   Fstab_File_System: erofs
   Current_File_System: erofs
   Fstab_File_System: erofs

Now TWRP can recognize the EROFS filesystem perfectly after setting fs in twrp.flags

Signed-off-by: Gao Xiang <[email protected]>
[@pomelohan: Adapt for TWRP's libblkid version and add erofs.c to build]
Co-authored-by: GarfieldHan <[email protected]>
Signed-off-by: GarfieldHan <[email protected]>
Change-Id: I00263757b5b6ed881165e65795ef849d86763165
  • Loading branch information
2 people authored and uixdess committed Dec 27, 2021
1 parent 8b06436 commit bdd15ee
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions libblkid/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ LOCAL_SRC_FILES = src/cache.c \
src/superblocks/drbdproxy_datalog.c \
src/superblocks/exfat.c \
src/superblocks/ext.c \
src/superblocks/erofs.c \
src/superblocks/f2fs.c \
src/superblocks/gfs.c \
src/superblocks/hfs.c \
Expand Down
71 changes: 71 additions & 0 deletions libblkid/src/superblocks/erofs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2020 Gao Xiang
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License
*/
#include <stddef.h>
#include <string.h>

#include "superblocks.h"

#define EROFS_SUPER_OFFSET 1024
#define EROFS_SB_KBOFF (EROFS_SUPER_OFFSET >> 10)

#define EROFS_SUPER_MAGIC_V1 "\xe2\xe1\xf5\xe0"
#define EROFS_MAGIC_OFF 0

/* All in little-endian */
struct erofs_super_block {
uint32_t magic;
uint32_t checksum;
uint32_t feature_compat;
uint8_t blkszbits;
uint8_t reserved;

uint16_t root_nid;
uint64_t inos;

uint64_t build_time;
uint32_t build_time_nsec;
uint32_t blocks;
uint32_t meta_blkaddr;
uint32_t xattr_blkaddr;
uint8_t uuid[16];
uint8_t volume_name[16];
uint32_t feature_incompat;
uint8_t reserved2[44];
};

static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
{
struct erofs_super_block *sb;

sb = blkid_probe_get_sb(pr, mag, struct erofs_super_block);
if (!sb)
return errno ? -errno : BLKID_PROBE_NONE;

if (sb->volume_name[0])
blkid_probe_set_label(pr, (unsigned char *)sb->volume_name,
sizeof(sb->volume_name));

blkid_probe_set_uuid(pr, sb->uuid);

return BLKID_PROBE_OK;
}

const struct blkid_idinfo erofs_idinfo =
{
.name = "erofs",
.usage = BLKID_USAGE_FILESYSTEM,
.probefunc = probe_erofs,
.magics =
{
{
.magic = EROFS_SUPER_MAGIC_V1,
.len = 4,
.kboff = EROFS_SB_KBOFF,
.sboff = EROFS_MAGIC_OFF,
}, { NULL }
}
};
3 changes: 2 additions & 1 deletion libblkid/src/superblocks/superblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ static const struct blkid_idinfo *idinfos[] =
&befs_idinfo,
&nilfs2_idinfo,
&exfat_idinfo,
&f2fs_idinfo
&f2fs_idinfo,
&erofs_idinfo
};

/*
Expand Down
1 change: 1 addition & 0 deletions libblkid/src/superblocks/superblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern const struct blkid_idinfo nilfs2_idinfo;
extern const struct blkid_idinfo exfat_idinfo;
extern const struct blkid_idinfo f2fs_idinfo;
extern const struct blkid_idinfo bcache_idinfo;
extern const struct blkid_idinfo erofs_idinfo;

/*
* superblock functions
Expand Down

0 comments on commit bdd15ee

Please sign in to comment.