Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image-erofs: introduce basic support for erofs #247

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ genimage_SOURCES = \
image-android-sparse.c \
image-cpio.c \
image-cramfs.c \
image-erofs.c \
image-ext2.c \
image-f2fs.c \
image-file.c \
Expand Down
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Here are all options for images:
Additionally each image can have one of the following sections describing the
type of the image:

cpio, cramfs, ext2, ext3, ext4, file, flash, hdimage, iso, jffs2, qemu, squashfs,
cpio, cramfs, erofs, ext2, ext3, ext4, file, flash, hdimage, iso, jffs2, qemu, squashfs,
tar, ubi, ubifs, vfat.

Partition options:
Expand Down Expand Up @@ -259,6 +259,14 @@ Options:

:extraargs: Extra arguments passed to mkcramfs

erofs
******
Generates erofs images.

Options:

:extraargs: Extra arguments passed to mkfs.erofs.

ext2, ext3, ext4
****************
Generates ext* images.
Expand Down Expand Up @@ -655,6 +663,7 @@ variable.
:mmd: path to the mmd program (default mmd)
:mkcramfs: path to the mkcramfs program (default mkcramfs)
:mkdosfs: path to the mkdosfs program (default mkdosfs)
:mkfserofs: path to the mkfs.erofs program (default mkfs.erofs)
:mkfsjffs2: path to the mkfs.jffs2 program (default mkfs.jffs2)
:mkfsubifs: path to the mkfs.ubifs program (default mkfs.ubifs)
:mksquashfs: path to the mksquashfs program (default mksquashfs)
Expand Down
5 changes: 5 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ static struct config opts[] = {
.opt = CFG_STR("mke2fs", NULL, CFGF_NONE),
.env = "GENIMAGE_MKE2FS",
.def = "mke2fs",
}, {
.name = "mkfserofs",
.opt = CFG_STR("mkfserofs", NULL, CFGF_NONE),
.env = "GENIMAGE_MKFSEROFS",
.def = "mkfs.erofs",
}, {
.name = "mkfsjffs2",
.opt = CFG_STR("mkfsjffs2", NULL, CFGF_NONE),
Expand Down
1 change: 1 addition & 0 deletions genimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static struct image_handler *handlers[] = {
&android_sparse_handler,
&cpio_handler,
&cramfs_handler,
&erofs_handler,
&ext2_handler,
&ext3_handler,
&ext4_handler,
Expand Down
1 change: 1 addition & 0 deletions genimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct flash_type *flash_type_get(const char *name);
extern struct image_handler android_sparse_handler;
extern struct image_handler cpio_handler;
extern struct image_handler cramfs_handler;
extern struct image_handler erofs_handler;
extern struct image_handler ext2_handler;
extern struct image_handler ext3_handler;
extern struct image_handler ext4_handler;
Expand Down
45 changes: 45 additions & 0 deletions image-erofs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Sebastian Muxel <[email protected]>, Entner Electronics
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <confuse.h>
#include "genimage.h"

static int erofs_generate(struct image *image)
{
int ret;
char *extraargs = cfg_getstr(image->imagesec, "extraargs");


ret = systemp(image, "%s %s '%s' '%s'",
get_opt("mkfserofs"),
extraargs,
imageoutfile(image),
mountpath(image)
);

return ret;
}

static cfg_opt_t erofs_opts[] = {
CFG_STR("extraargs", "", CFGF_NONE),
CFG_END()
};

struct image_handler erofs_handler = {
.type = "erofs",
.generate = erofs_generate,
.opts = erofs_opts,
};
5 changes: 5 additions & 0 deletions test/erofs.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
image test.erofs {
erofs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the filesystem uuid here with extraargs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i just hardcode the UUID to a specific value? I tried checking the other occurances of uuid's in tests and they mostly seem to revolve around the partition table uuid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also the possibility of adding a dedicated uuid parameter as the commit introduces new public API anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a dedicated parameter. We don't have it anywhere else either. Just put a random uuid here to make the output of dump.erofs more predictable.

}
size = 4M
}
8 changes: 8 additions & 0 deletions test/filesystem.test
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ test_expect_success dd,mkdosfs,mcopy "vfat" "
check_filelist
"

exec_test_set_prereq mkfs.erofs
exec_test_set_prereq fsck.erofs
test_expect_success mkfs_erofs,fsck_erofs "erofs" "
run_genimage_root erofs.config test.erofs &&
fsck.erofs -p images/test.erofs | tee erofs.log &&
test_must_fail grep -q 'Filesystem was changed' erofs.log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like something to see that the content actually reached the filesystem.

  1. use check_size
  2. dump.erofs -s -S --ls --path=/ test.erofs | grep -v 'Filesystem created' > dump
    test_cmp "${testdir}/erofs.dump" "dump"

That will not check everything, but that contains the file count and the dir listing of the toplevel dir.

Tip: I insert a "cp dump ${testdir}/erofs.dump" so save the expected output on the first try and remove the line again afterwards.
And don't forget to add the new file to EXTRA_DIST in Makefile.am

"

test_done

# vim: syntax=sh
Loading