Skip to content

Commit 2c985fe

Browse files
committed
Add BTRFS
Signed-off-by: liberodark <[email protected]>
1 parent b4e4b18 commit 2c985fe

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ genimage_SOURCES = \
2323
image-cramfs.c \
2424
image-ext2.c \
2525
image-f2fs.c \
26+
image-btrfs.c \
2627
image-file.c \
2728
image-fip.c \
2829
image-fit.c \
@@ -70,6 +71,7 @@ EXTRA_DIST += \
7071
test/ext4test.0.dump \
7172
test/ext4test.1.dump \
7273
test/f2fs.config \
74+
test/btrfs.config \
7375
test/fip.config \
7476
test/fit.its \
7577
test/fit.config \

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,13 @@ To include a ``"foo.cfg"`` config file, use the following statement::
670670
include("foo.cfg")
671671

672672
This allows to re-use, for example flash configuration files, across different image configurations.
673+
674+
# To develop and run the test
675+
676+
```bash
677+
./autogen.sh
678+
./configure CFLAGS='-g -O2' --prefix=/usr
679+
make
680+
make check-TESTS
681+
# and check error in test-suite.log
682+
```

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ static struct config opts[] = {
408408
.opt = CFG_STR("mkfsf2fs", NULL, CFGF_NONE),
409409
.env = "GENIMAGE_MKFSF2FS",
410410
.def = "mkfs.f2fs",
411+
}, {
412+
.name = "mkfsbtrfs",
413+
.opt = CFG_STR("mkfsfbtrfs", NULL, CFGF_NONE),
414+
.env = "GENIMAGE_MKFSBTRFS",
415+
.def = "mkfs.btrfs",
411416
}, {
412417
.name = "sloadf2fs",
413418
.opt = CFG_STR("sloadf2fs", NULL, CFGF_NONE),

genimage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static struct image_handler *handlers[] = {
4545
&ext3_handler,
4646
&ext4_handler,
4747
&f2fs_handler,
48+
&btrfs_handler,
4849
&file_handler,
4950
&fit_handler,
5051
&fip_handler,

genimage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ extern struct image_handler ext2_handler;
110110
extern struct image_handler ext3_handler;
111111
extern struct image_handler ext4_handler;
112112
extern struct image_handler f2fs_handler;
113+
extern struct image_handler btrfs_handler;
113114
extern struct image_handler file_handler;
114115
extern struct image_handler flash_handler;
115116
extern struct image_handler hdimage_handler;

image-btrfs.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2022 Tomas Mudrunka <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2
6+
* as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include <confuse.h>
18+
#include <stdio.h>
19+
#include <string.h>
20+
#include <stdlib.h>
21+
#include <errno.h>
22+
23+
#include "genimage.h"
24+
25+
static int btrfs_generate(struct image *image)
26+
{
27+
int ret;
28+
29+
char *label = cfg_getstr(image->imagesec, "label");
30+
31+
ret = prepare_image(image, image->size);
32+
if(ret)
33+
return ret;
34+
35+
36+
ret = systemp(image, "%s %s %s %s '%s' '%s'",
37+
get_opt("mkfsbtrfs"),
38+
label ? "-L" : "",
39+
label ? label : "",
40+
label ? "-r" : "",
41+
mountpath(image), /* source dir */
42+
imageoutfile(image)); /* destination file */
43+
44+
if(ret || image->empty)
45+
return ret;
46+
47+
48+
return ret;
49+
}
50+
51+
static cfg_opt_t btrfs_opts[] = {
52+
CFG_STR("label", NULL, CFGF_NONE),
53+
CFG_END()
54+
};
55+
56+
struct image_handler btrfs_handler = {
57+
.type = "btrfs",
58+
.generate = btrfs_generate,
59+
.opts = btrfs_opts,
60+
};

test/btrfs.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
image test.btrfs {
2+
btrfs {
3+
label = "btrfstest"
4+
}
5+
size = 64M
6+
}

test/filesystem.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ test_expect_success mkfs_f2fs,sload_f2fs,fsck_f2fs "f2fs" "
3535
fsck.f2fs images/test.f2fs
3636
"
3737

38+
exec_test_set_prereq mkfs.btrfs
39+
exec_test_set_prereq sload.btrfs
40+
exec_test_set_prereq fsck.btrfs
41+
test_expect_success mkfs_btrfs,fsck_btrfs "btrfs" "
42+
run_genimage_root btrfs.config test.btrfs
43+
btrfsck images/test.btrfs
44+
"
45+
3846
exec_test_set_prereq mksquashfs
3947
test_expect_success mksquashfs "squashfs" "
4048
run_genimage_root squashfs.config test.squashfs &&

0 commit comments

Comments
 (0)