diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7f028d8..69bf8ac 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,7 +29,7 @@ jobs: - name: Install required packages run: | sudo apt-get update - sudo apt-get install dosfstools fakeroot genext2fs genisoimage libconfuse-dev mtd-utils mtools qemu-utils qemu-utils squashfs-tools ${{ matrix.pkgs }} + sudo apt-get install btrfs-progs dosfstools fakeroot genext2fs genisoimage libconfuse-dev mtd-utils mtools qemu-utils qemu-utils squashfs-tools ${{ matrix.pkgs }} ${{ matrix.fake }} - name: Build & Test (with ${{ matrix.options }}) diff --git a/Makefile.am b/Makefile.am index 1aac4f1..d45a57c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,6 +23,7 @@ genimage_SOURCES = \ image-cramfs.c \ image-ext2.c \ image-f2fs.c \ + image-btrfs.c \ image-file.c \ image-fip.c \ image-fit.c \ @@ -74,6 +75,7 @@ EXTRA_DIST += \ test/ext4test.1.dump \ test/ext4test.2.dump \ test/f2fs.config \ + test/btrfs.config \ test/fip.config \ test/fit.its \ test/fit.config \ diff --git a/config.c b/config.c index 431cac9..771a275 100644 --- a/config.c +++ b/config.c @@ -408,6 +408,11 @@ static struct config opts[] = { .opt = CFG_STR("mkfsf2fs", NULL, CFGF_NONE), .env = "GENIMAGE_MKFSF2FS", .def = "mkfs.f2fs", + }, { + .name = "mkfsbtrfs", + .opt = CFG_STR("mkfsfbtrfs", NULL, CFGF_NONE), + .env = "GENIMAGE_MKFSBTRFS", + .def = "mkfs.btrfs", }, { .name = "sloadf2fs", .opt = CFG_STR("sloadf2fs", NULL, CFGF_NONE), diff --git a/genimage.c b/genimage.c index a10a001..357e431 100644 --- a/genimage.c +++ b/genimage.c @@ -45,6 +45,7 @@ static struct image_handler *handlers[] = { &ext3_handler, &ext4_handler, &f2fs_handler, + &btrfs_handler, &file_handler, &fit_handler, &fip_handler, diff --git a/genimage.h b/genimage.h index 1fc1e45..055e294 100644 --- a/genimage.h +++ b/genimage.h @@ -112,6 +112,7 @@ extern struct image_handler ext2_handler; extern struct image_handler ext3_handler; extern struct image_handler ext4_handler; extern struct image_handler f2fs_handler; +extern struct image_handler btrfs_handler; extern struct image_handler file_handler; extern struct image_handler flash_handler; extern struct image_handler hdimage_handler; diff --git a/image-btrfs.c b/image-btrfs.c new file mode 100644 index 0000000..21532f4 --- /dev/null +++ b/image-btrfs.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 Tomas Mudrunka + * Copyright (c) 2024 Fiona Klute + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#include "genimage.h" + +static int btrfs_generate(struct image *image) +{ + int ret; + + const char *label = cfg_getstr(image->imagesec, "label"); + const char *extraargs = cfg_getstr(image->imagesec, "extraargs"); + + ret = prepare_image(image, image->size); + if(ret) + return ret; + + + ret = systemp(image, "%s %s %s %s %s%s%s %s '%s'", + get_opt("mkfsbtrfs"), + label ? "-L" : "", + label ? label : "", + /* initial filesystem content, if any */ + image->empty ? "" : "-r", + image->empty ? "" : "'", + image->empty ? "" : mountpath(image), + image->empty ? "" : "'", + extraargs, + imageoutfile(image)); /* destination file */ + + if(ret || image->empty) + return ret; + + + return ret; +} + +static cfg_opt_t btrfs_opts[] = { + CFG_STR("label", NULL, CFGF_NONE), + CFG_STR("extraargs", "", CFGF_NONE), + CFG_END() +}; + +struct image_handler btrfs_handler = { + .type = "btrfs", + .generate = btrfs_generate, + .opts = btrfs_opts, +}; diff --git a/test/btrfs.config b/test/btrfs.config new file mode 100644 index 0000000..2c62eb5 --- /dev/null +++ b/test/btrfs.config @@ -0,0 +1,8 @@ +image test.btrfs { + btrfs { + label = "btrfstest" + # set UUID to test if extraargs works + extraargs = "--uuid 47e790af-a2e1-42ff-92c7-83f45f7b2228" + } + size = 64M +} diff --git a/test/filesystem.test b/test/filesystem.test index 9f8ea6c..947ef8e 100755 --- a/test/filesystem.test +++ b/test/filesystem.test @@ -35,6 +35,15 @@ test_expect_success mkfs_f2fs,sload_f2fs,fsck_f2fs "f2fs" " fsck.f2fs images/test.f2fs " +exec_test_set_prereq btrfs +exec_test_set_prereq mkfs.btrfs +test_expect_success mkfs_btrfs,btrfs "btrfs" " + run_genimage_root btrfs.config test.btrfs + btrfs check images/test.btrfs + test \"\$(btrfs filesystem label images/test.btrfs)\" = btrfstest + btrfs filesystem show images/test.btrfs | grep \"uuid: 47e790af-a2e1-42ff-92c7-83f45f7b2228\" +" + exec_test_set_prereq mksquashfs test_expect_success mksquashfs "squashfs" " run_genimage_root squashfs.config test.squashfs &&