Skip to content

Commit

Permalink
Merge pull request #1375 from djr-spectrummfg/extra-mkfs-opts
Browse files Browse the repository at this point in the history
Add extra-mkfs-opts to allow customising filesystem format options
  • Loading branch information
jluebbe committed May 13, 2024
2 parents 3197c56 + 3ae12ec commit 3eb17dd
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
6 changes: 5 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ hierarchical separator.
See table :ref:`sec-slot-type` for a more detailed list of these different types.
Defaults to ``raw`` if none given.

``extra-mkfs-opts=<options>`` (optional)
Allows to specify custom filesystem creation options that will be passed to the slot's
``mkfs.<type>`` call (ext4, vfat, and ubifs only).

``bootname=<name>`` (optional)
Registers the slot for being handled by the
:ref:`bootselection interface <bootloader-interaction>` with the ``<name>``
Expand Down Expand Up @@ -511,7 +515,7 @@ hierarchical separator.
file system to an ext4 slot, i.e. if the slot has``type=ext4`` set.

``extra-mount-opts=<options>`` (optional)
Allows to specify custom mount options that will be passed to the slots
Allows to specify custom mount options that will be passed to the slot's
``mount`` call as ``-o`` argument value.

.. _ref-logger-sections:
Expand Down
2 changes: 2 additions & 0 deletions include/slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct _RaucSlot {
gchar *device;
/** the slots partition type */
gchar *type;
/** extra mkfs options for this slot */
gchar **extra_mkfs_opts;
/** the name this slot is known to the bootloader */
gchar *bootname;
/** flag to indicate that this slot can be updated even if already mounted */
Expand Down
5 changes: 4 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ G_GNUC_WARN_UNUSED_RESULT;
* Adds elements of a zero-terminated GStrv/gchar** to an existing GPtrArray
*
* @param ptrarray GPtrArray to add to
* @param argvp arguments to add
* @param argvp arguments to add (may be NULL)
* @param copy whether to just add the pointer (FALSE) or copy the underlying data (TRUE)
*/
static inline void r_ptr_array_addv(GPtrArray *ptrarray, gchar **argvp, gboolean copy)
{
if (argvp == NULL)
return;

for (gchar **addarg = argvp; *addarg != NULL; addarg++) {
g_ptr_array_add(ptrarray, copy ? g_strdup(*addarg) : *addarg);
}
Expand Down
10 changes: 10 additions & 0 deletions src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ static GHashTable *parse_slots(const char *filename, const char *data_directory,
return NULL;
}

value = key_file_consume_string(key_file, groups[i], "extra-mkfs-opts", NULL);
if (value != NULL) {
if (!g_shell_parse_argv(value, NULL, &(slot->extra_mkfs_opts), &ierror)) {
g_free(value);
g_propagate_prefixed_error(error, ierror, "Failed to parse extra-mkfs-opts: ");
return NULL;
}
g_free(value);
}

value = key_file_consume_string(key_file, groups[i], "bootname", NULL);

slot->bootname = value;
Expand Down
1 change: 1 addition & 0 deletions src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void r_slot_free(gpointer value)
g_free(slot->description);
g_free(slot->device);
g_free(slot->type);
g_strfreev(slot->extra_mkfs_opts);
g_free(slot->bootname);
g_free(slot->extra_mount_opts);
g_free(slot->parent_name);
Expand Down
5 changes: 4 additions & 1 deletion src/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ static gboolean ubifs_format_slot(RaucSlot *dest_slot, GError **error)

g_ptr_array_add(args, g_strdup("mkfs.ubifs"));
g_ptr_array_add(args, g_strdup("-y"));
r_ptr_array_addv(args, dest_slot->extra_mkfs_opts, TRUE);
g_ptr_array_add(args, g_strdup(dest_slot->device));
g_ptr_array_add(args, NULL);

Expand Down Expand Up @@ -995,7 +996,7 @@ static gboolean ext4_format_slot(RaucSlot *dest_slot, GError **error)
{
GError *ierror = NULL;
gboolean res = FALSE;
g_autoptr(GPtrArray) args = g_ptr_array_new_full(4, g_free);
g_autoptr(GPtrArray) args = g_ptr_array_new_full(6, g_free);

g_ptr_array_add(args, g_strdup("mkfs.ext4"));
g_ptr_array_add(args, g_strdup("-F"));
Expand All @@ -1004,6 +1005,7 @@ static gboolean ext4_format_slot(RaucSlot *dest_slot, GError **error)
g_ptr_array_add(args, g_strdup(dest_slot->name));
}
g_ptr_array_add(args, g_strdup("-I256"));
r_ptr_array_addv(args, dest_slot->extra_mkfs_opts, TRUE);
g_ptr_array_add(args, g_strdup(dest_slot->device));
g_ptr_array_add(args, NULL);

Expand Down Expand Up @@ -1073,6 +1075,7 @@ static gboolean vfat_format_slot(RaucSlot *dest_slot, GError **error)
g_ptr_array_add(args, g_strdup("mkfs.vfat"));
g_ptr_array_add(args, g_strdup("-n"));
g_ptr_array_add(args, vfat_label_generator(dest_slot->name));
r_ptr_array_addv(args, dest_slot->extra_mkfs_opts, TRUE);
g_ptr_array_add(args, g_strdup(dest_slot->device));
g_ptr_array_add(args, NULL);

Expand Down
55 changes: 54 additions & 1 deletion test/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ readonly=true\n\
description=Root filesystem partition 0\n\
device=/dev/rootfs-0\n\
type=ext4\n\
extra-mkfs-opts=\n\
bootname=system0\n\
readonly=false\n\
force-install-same=false\n\
Expand All @@ -78,6 +79,7 @@ force-install-same=false\n\
description=Root filesystem partition 1\n\
device=/dev/rootfs-1\n\
type=ext4\n\
extra-mkfs-opts= \n\
bootname=system1\n\
readonly=false\n\
ignore-checksum=false\n\
Expand All @@ -93,9 +95,9 @@ install-same=false\n\
description=Application filesystem partition 1\n\
device=/dev/appfs-1\n\
type=ext4\n\
extra-mkfs-opts=-L mylabel -i 8192\n\
parent=rootfs.1\n\
install-same=false\n";

g_autofree gchar* pathname = write_tmp_file(fixture->tmpdir, "full_config.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

Expand Down Expand Up @@ -135,6 +137,7 @@ install-same=false\n";
g_assert_cmpstr(slot->device, ==, "/dev/rootfs-0");
g_assert_cmpstr(slot->bootname, ==, "system0");
g_assert_cmpstr(slot->type, ==, "ext4");
g_assert_null(slot->extra_mkfs_opts);
g_assert_false(slot->readonly);
g_assert_false(slot->install_same);
g_assert_null(slot->parent);
Expand All @@ -146,6 +149,7 @@ install-same=false\n";
g_assert_cmpstr(slot->device, ==, "/dev/rootfs-1");
g_assert_cmpstr(slot->bootname, ==, "system1");
g_assert_cmpstr(slot->type, ==, "ext4");
g_assert_null(slot->extra_mkfs_opts);
g_assert_false(slot->readonly);
g_assert_false(slot->install_same);
g_assert_null(slot->parent);
Expand All @@ -157,6 +161,7 @@ install-same=false\n";
g_assert_cmpstr(slot->device, ==, "/dev/appfs-0");
g_assert_null(slot->bootname);
g_assert_cmpstr(slot->type, ==, "ext4");
g_assert_null(slot->extra_mkfs_opts);
g_assert_false(slot->readonly);
g_assert_false(slot->install_same);
g_assert_nonnull(slot->parent);
Expand All @@ -168,6 +173,14 @@ install-same=false\n";
g_assert_cmpstr(slot->device, ==, "/dev/appfs-1");
g_assert_null(slot->bootname);
g_assert_cmpstr(slot->type, ==, "ext4");

g_assert_nonnull(slot->extra_mkfs_opts);
g_assert_cmpstr(slot->extra_mkfs_opts[0], ==, "-L");
g_assert_cmpstr(slot->extra_mkfs_opts[1], ==, "mylabel");
g_assert_cmpstr(slot->extra_mkfs_opts[2], ==, "-i");
g_assert_cmpstr(slot->extra_mkfs_opts[3], ==, "8192");
g_assert_null(slot->extra_mkfs_opts[4]);

g_assert_false(slot->readonly);
g_assert_false(slot->install_same);
g_assert_nonnull(slot->parent);
Expand Down Expand Up @@ -943,6 +956,43 @@ extra-mount-opts=ro,noatime\n";
g_assert_cmpstr(slot->extra_mount_opts, ==, "ro,noatime");
}

static void config_file_extra_mkfs_opts(ConfigFileFixture *fixture,
gconstpointer user_data)
{
g_autoptr(RaucConfig) config = NULL;
GError *ierror = NULL;
gboolean res;
g_autofree gchar* pathname = NULL;
RaucSlot *slot = NULL;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=barebox\n\
\n\
[slot.rootfs.0]\n\
device=/dev/null\n\
type=ext4\n\
extra-mkfs-opts=-L \"my label\" -i 8192\n";

pathname = write_tmp_file(fixture->tmpdir, "extra_mkfs.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

res = load_config(pathname, &config, &ierror);
g_assert_no_error(ierror);
g_assert_true(res);
g_assert_nonnull(config);

slot = g_hash_table_lookup(config->slots, "rootfs.0");
g_assert_nonnull(slot);
g_assert_nonnull(slot->extra_mkfs_opts);
g_assert_cmpstr(slot->extra_mkfs_opts[0], ==, "-L");
g_assert_cmpstr(slot->extra_mkfs_opts[1], ==, "my label");
g_assert_cmpstr(slot->extra_mkfs_opts[2], ==, "-i");
g_assert_cmpstr(slot->extra_mkfs_opts[3], ==, "8192");
g_assert_null(slot->extra_mkfs_opts[4]);
}

static void config_file_statusfile_missing(ConfigFileFixture *fixture,
gconstpointer user_data)
{
Expand Down Expand Up @@ -1512,6 +1562,9 @@ int main(int argc, char *argv[])
g_test_add("/config-file/extra-mount-opts", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_extra_mount_opts,
config_file_fixture_tear_down);
g_test_add("/config-file/extra-mkfs-opts", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_extra_mkfs_opts,
config_file_fixture_tear_down);
g_test_add("/config-file/statusfile-missing", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_statusfile_missing,
config_file_fixture_tear_down);
Expand Down

0 comments on commit 3eb17dd

Please sign in to comment.