Skip to content

Commit

Permalink
todo move to launcher refactor PR: supports modern and old mounttable…
Browse files Browse the repository at this point in the history
…s properly
  • Loading branch information
icex2 committed Feb 9, 2024
1 parent 8b9eaf6 commit 79b972d
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 77 deletions.
115 changes: 115 additions & 0 deletions src/main/launcher/avs-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,119 @@ void avs_config_local_fs_path_dev_nvram_and_raw_set(
property_util_node_str_replace(
NULL, fs_node, "raw/option", "vf=1,posix=1");
}
}

void avs_config_vfs_mounttable_get(struct property_node *node, struct avs_config_vfs_mounttable *mounttable)
{
struct property_node *fs_node;
struct property_node *mounttable_node;
struct property_node *cur;
uint8_t pos;

log_assert(node);
log_assert(mounttable);

fs_node = property_search(NULL, node, "fs");

if (!fs_node) {
log_fatal("Cannot find 'fs' node in avs config");
}

// Check if "new" mounttable config is used for dev/nvram and dev/raw or
// legacy config
mounttable_node = property_search(NULL, fs_node, "mounttable");

memset(mounttable, 0, sizeof(*mounttable));
pos = 0;

if (mounttable_node) {
cur = property_search(NULL, mounttable_node, "vfs");

while (cur) {
if (pos >= AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES) {
log_warning("Exceeding max number of supported mounttable entries (%d), ignoring remaining", pos);
break;

}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "name@", PROPERTY_TYPE_ATTR,
mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name)))) {
// optional
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype@", PROPERTY_TYPE_ATTR,
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
// default
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "src@", PROPERTY_TYPE_ATTR,
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
log_fatal("Missing 'src' attribute on vfs node, name: %s", mounttable->entry[pos].name);
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "dst@", PROPERTY_TYPE_ATTR,
mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst)))) {
log_fatal("Missing 'dst' attribute on vfs node, name: %s", mounttable->entry[pos].name);
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt@", PROPERTY_TYPE_ATTR,
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
// optional
}

cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT);
pos++;
}
} else {
cur = property_search(NULL, node, "nvram");

if (cur) {
str_cpy(mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name), "nvram");

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype", PROPERTY_TYPE_STR,
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
// default
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "device", PROPERTY_TYPE_STR,
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
log_fatal("Missing 'device' attribute on nvram node");
}

str_cpy(mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst), "/dev/nvram");

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt", PROPERTY_TYPE_STR,
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
// optional
}
}

cur = property_search(NULL, node, "raw");

if (cur) {
str_cpy(mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name), "raw");

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype", PROPERTY_TYPE_STR,
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
// default
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
}

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "device", PROPERTY_TYPE_STR,
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
log_fatal("Missing 'device' attribute on raw node");
}

str_cpy(mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst), "/dev/raw");

if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt", PROPERTY_TYPE_STR,
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
// optional
}
}
}

mounttable->num_entries = pos;
}
16 changes: 16 additions & 0 deletions src/main/launcher/avs-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@

#include "launcher/bootstrap-config.h"

#define AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES 16

struct avs_config_vfs_mounttable {
struct {
char name[64];
char fstype[64];
char src[512];
char dst[512];
char opt[256];
} entry[AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES];

uint8_t num_entries;
};

struct property *avs_config_load(const char *filepath);
struct property_node *avs_config_root_get(struct property *property);

Expand Down Expand Up @@ -36,4 +50,6 @@ void avs_config_set_log_level(
void avs_config_local_fs_path_dev_nvram_and_raw_set(
struct property_node *node, const char *dev_nvram_raw_path);

void avs_config_vfs_mounttable_get(struct property_node *node, struct avs_config_vfs_mounttable *mounttable);

#endif
84 changes: 12 additions & 72 deletions src/main/launcher/avs.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,87 +123,27 @@ void avs_fs_assert_root_device_exists(struct property_node *node)
}
}

void avs_fs_mountpoint_dir_create(
struct property_node *node, const char *folder_name)
void avs_fs_mountpoints_fs_dirs_create(struct property_node *node)
{
char fs_path[1024];
char fs_type[255];
char device_path[1024];
struct property_node *fs_node;
int res;
struct avs_config_vfs_mounttable mounttable;
uint8_t i;

memset(fs_path, 0, sizeof(fs_path));
memset(fs_type, 0, sizeof(fs_type));
avs_config_vfs_mounttable_get(node, &mounttable);

str_cpy(fs_path, sizeof(fs_path), "/fs/");
str_cat(fs_path, sizeof(fs_path), folder_name);

fs_node = property_search(NULL, node, fs_path);

if (!fs_node) {
log_warning(
"Could not find file system node %s in avs configuration", fs_path);
return;
}

res = property_node_refer(
NULL,
fs_node,
"device",
PROPERTY_TYPE_STR,
device_path,
sizeof(device_path));

if (res < 0) {
log_fatal(
"Getting 'device' attribute from avs config entry %s failed",
fs_path);
}

// 'fstype' attribute is optional and defaults to value 'fs'
if (!property_search(NULL, fs_node, "fstype")) {
if (path_exists(device_path)) {
// skip if exists already
return;
}

log_misc("Creating avs directory %s", device_path);

if (!path_mkdir(device_path)) {
log_fatal("Creating directory %s failed", device_path);
}
} else {
res = property_node_refer(
NULL,
fs_node,
"fstype",
PROPERTY_TYPE_STR,
fs_type,
sizeof(fs_type));

if (res < 0) {
log_fatal(
"Getting 'fstype' attribute from avs config entry %s failed",
fs_path);
}

if (!strcmp(fs_type, "fs") || !strcmp(fs_type, "nvram")) {
if (path_exists(device_path)) {
for (i = 0; i < mounttable.num_entries; i++) {
if (str_eq(mounttable.entry[i].fstype, "fs")) {
if (path_exists(mounttable.entry[i].src)) {
// skip if exists already
return;
}

log_misc("Creating avs directory %s", device_path);
log_misc("Creating avs fs directory '%s' for destination/device '%s'",
mounttable.entry[i].src,
mounttable.entry[i].dst);

if (!path_mkdir(device_path)) {
log_fatal("Creating directory %s failed", device_path);
if (!path_mkdir(mounttable.entry[i].src)) {
log_fatal("Creating fs directory %s failed", mounttable.entry[i].src);
}
} else {
log_fatal(
"Cannot create folders for unsupported file system type %s of "
"path %s in avs config",
fs_type,
fs_path);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/launcher/avs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "imports/avs.h"

void avs_fs_assert_root_device_exists(struct property_node *node);
void avs_fs_mountpoint_dir_create(
struct property_node *node, const char *folder_name);
void avs_fs_mountpoints_fs_dirs_create(struct property_node *node);
void avs_init(
struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size);
void avs_fs_file_copy(const char *src, const char *dst);
Expand Down
5 changes: 2 additions & 3 deletions src/main/launcher/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ void bootstrap_avs_init(

avs_fs_assert_root_device_exists(node);

log_misc("Creating AVS file system directories for nvram and raw...");
log_misc("Creating AVS file system directories...");

avs_fs_mountpoint_dir_create(node, "nvram");
avs_fs_mountpoint_dir_create(node, "raw");
avs_fs_mountpoints_fs_dirs_create(node);

avs_init(node, config->avs_heap_size, config->std_heap_size);

Expand Down

0 comments on commit 79b972d

Please sign in to comment.