Skip to content

Commit 76720fe

Browse files
author
icex2
committed
todo move to launcher refactor PR: supports modern and old mounttables properly
1 parent 8b9eaf6 commit 76720fe

5 files changed

Lines changed: 148 additions & 77 deletions

File tree

src/main/launcher/avs-config.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,121 @@ void avs_config_local_fs_path_dev_nvram_and_raw_set(
363363
property_util_node_str_replace(
364364
NULL, fs_node, "raw/option", "vf=1,posix=1");
365365
}
366+
}
367+
368+
void avs_config_vfs_mounttable_get(struct property_node *node, struct avs_config_vfs_mounttable *mounttable)
369+
{
370+
struct property_node *fs_node;
371+
struct property_node *mounttable_node;
372+
struct property_node *cur;
373+
uint8_t pos;
374+
375+
log_assert(node);
376+
log_assert(mounttable);
377+
378+
fs_node = property_search(NULL, node, "fs");
379+
380+
if (!fs_node) {
381+
log_fatal("Cannot find 'fs' node in avs config");
382+
}
383+
384+
// Check if "new" mounttable config is used for dev/nvram and dev/raw or
385+
// legacy config
386+
mounttable_node = property_search(NULL, fs_node, "mounttable");
387+
388+
memset(mounttable, 0, sizeof(*mounttable));
389+
pos = 0;
390+
391+
property_util_node_log(mounttable_node);
392+
393+
if (mounttable_node) {
394+
cur = property_search(NULL, mounttable_node, "vfs");
395+
396+
while (cur) {
397+
if (pos >= AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES) {
398+
log_warning("Exceeding max number of supported mounttable entries (%d), ignoring remaining", pos);
399+
break;
400+
401+
}
402+
403+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "name@", PROPERTY_TYPE_ATTR,
404+
mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name)))) {
405+
// optional
406+
}
407+
408+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype@", PROPERTY_TYPE_ATTR,
409+
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
410+
// default
411+
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
412+
}
413+
414+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "src@", PROPERTY_TYPE_ATTR,
415+
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
416+
log_fatal("Missing 'src' attribute on vfs node, name: %s", mounttable->entry[pos].name);
417+
}
418+
419+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "dst@", PROPERTY_TYPE_ATTR,
420+
mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst)))) {
421+
log_fatal("Missing 'dst' attribute on vfs node, name: %s", mounttable->entry[pos].name);
422+
}
423+
424+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt@", PROPERTY_TYPE_ATTR,
425+
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
426+
// optional
427+
}
428+
429+
cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT);
430+
pos++;
431+
}
432+
} else {
433+
cur = property_search(NULL, node, "nvram");
434+
435+
if (cur) {
436+
str_cpy(mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name), "nvram");
437+
438+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype", PROPERTY_TYPE_STR,
439+
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
440+
// default
441+
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
442+
}
443+
444+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "device", PROPERTY_TYPE_STR,
445+
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
446+
log_fatal("Missing 'device' attribute on nvram node");
447+
}
448+
449+
str_cpy(mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst), "/dev/nvram");
450+
451+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt", PROPERTY_TYPE_STR,
452+
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
453+
// optional
454+
}
455+
}
456+
457+
cur = property_search(NULL, node, "raw");
458+
459+
if (cur) {
460+
str_cpy(mounttable->entry[pos].name, sizeof(mounttable->entry[pos].name), "raw");
461+
462+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "fstype", PROPERTY_TYPE_STR,
463+
mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype)))) {
464+
// default
465+
str_cpy(mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs");
466+
}
467+
468+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "device", PROPERTY_TYPE_STR,
469+
mounttable->entry[pos].src, sizeof(mounttable->entry[pos].src)))) {
470+
log_fatal("Missing 'device' attribute on raw node");
471+
}
472+
473+
str_cpy(mounttable->entry[pos].dst, sizeof(mounttable->entry[pos].dst), "/dev/raw");
474+
475+
if (AVS_IS_ERROR(property_node_refer(NULL, cur, "opt", PROPERTY_TYPE_STR,
476+
mounttable->entry[pos].opt, sizeof(mounttable->entry[pos].opt)))) {
477+
// optional
478+
}
479+
}
480+
}
481+
482+
mounttable->num_entries = pos;
366483
}

src/main/launcher/avs-config.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77

88
#include "launcher/bootstrap-config.h"
99

10+
#define AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES 16
11+
12+
struct avs_config_vfs_mounttable {
13+
struct {
14+
char name[64];
15+
char fstype[64];
16+
char src[512];
17+
char dst[512];
18+
char opt[256];
19+
} entry[AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES];
20+
21+
uint8_t num_entries;
22+
};
23+
1024
struct property *avs_config_load(const char *filepath);
1125
struct property_node *avs_config_root_get(struct property *property);
1226

@@ -36,4 +50,6 @@ void avs_config_set_log_level(
3650
void avs_config_local_fs_path_dev_nvram_and_raw_set(
3751
struct property_node *node, const char *dev_nvram_raw_path);
3852

53+
void avs_config_vfs_mounttable_get(struct property_node *node, struct avs_config_vfs_mounttable *mounttable);
54+
3955
#endif

src/main/launcher/avs.c

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -123,87 +123,27 @@ void avs_fs_assert_root_device_exists(struct property_node *node)
123123
}
124124
}
125125

126-
void avs_fs_mountpoint_dir_create(
127-
struct property_node *node, const char *folder_name)
126+
void avs_fs_mountpoints_fs_dirs_create(struct property_node *node)
128127
{
129-
char fs_path[1024];
130-
char fs_type[255];
131-
char device_path[1024];
132-
struct property_node *fs_node;
133-
int res;
128+
struct avs_config_vfs_mounttable mounttable;
129+
uint8_t i;
134130

135-
memset(fs_path, 0, sizeof(fs_path));
136-
memset(fs_type, 0, sizeof(fs_type));
131+
avs_config_vfs_mounttable_get(node, &mounttable);
137132

138-
str_cpy(fs_path, sizeof(fs_path), "/fs/");
139-
str_cat(fs_path, sizeof(fs_path), folder_name);
140-
141-
fs_node = property_search(NULL, node, fs_path);
142-
143-
if (!fs_node) {
144-
log_warning(
145-
"Could not find file system node %s in avs configuration", fs_path);
146-
return;
147-
}
148-
149-
res = property_node_refer(
150-
NULL,
151-
fs_node,
152-
"device",
153-
PROPERTY_TYPE_STR,
154-
device_path,
155-
sizeof(device_path));
156-
157-
if (res < 0) {
158-
log_fatal(
159-
"Getting 'device' attribute from avs config entry %s failed",
160-
fs_path);
161-
}
162-
163-
// 'fstype' attribute is optional and defaults to value 'fs'
164-
if (!property_search(NULL, fs_node, "fstype")) {
165-
if (path_exists(device_path)) {
166-
// skip if exists already
167-
return;
168-
}
169-
170-
log_misc("Creating avs directory %s", device_path);
171-
172-
if (!path_mkdir(device_path)) {
173-
log_fatal("Creating directory %s failed", device_path);
174-
}
175-
} else {
176-
res = property_node_refer(
177-
NULL,
178-
fs_node,
179-
"fstype",
180-
PROPERTY_TYPE_STR,
181-
fs_type,
182-
sizeof(fs_type));
183-
184-
if (res < 0) {
185-
log_fatal(
186-
"Getting 'fstype' attribute from avs config entry %s failed",
187-
fs_path);
188-
}
189-
190-
if (!strcmp(fs_type, "fs") || !strcmp(fs_type, "nvram")) {
191-
if (path_exists(device_path)) {
133+
for (i = 0; i < mounttable.num_entries; i++) {
134+
if (str_eq(mounttable.entry[i].fstype, "fs")) {
135+
if (path_exists(mounttable.entry[i].src)) {
192136
// skip if exists already
193137
return;
194138
}
195139

196-
log_misc("Creating avs directory %s", device_path);
140+
log_misc("Creating avs fs directory '%s' for destination/device '%s'",
141+
mounttable.entry[i].src,
142+
mounttable.entry[i].dst);
197143

198-
if (!path_mkdir(device_path)) {
199-
log_fatal("Creating directory %s failed", device_path);
144+
if (!path_mkdir(mounttable.entry[i].src)) {
145+
log_fatal("Creating fs directory %s failed", mounttable.entry[i].src);
200146
}
201-
} else {
202-
log_fatal(
203-
"Cannot create folders for unsupported file system type %s of "
204-
"path %s in avs config",
205-
fs_type,
206-
fs_path);
207147
}
208148
}
209149
}

src/main/launcher/avs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "imports/avs.h"
77

88
void avs_fs_assert_root_device_exists(struct property_node *node);
9-
void avs_fs_mountpoint_dir_create(
10-
struct property_node *node, const char *folder_name);
9+
void avs_fs_mountpoints_fs_dirs_create(struct property_node *node);
1110
void avs_init(
1211
struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size);
1312
void avs_fs_file_copy(const char *src, const char *dst);

src/main/launcher/bootstrap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ void bootstrap_avs_init(
175175

176176
avs_fs_assert_root_device_exists(node);
177177

178-
log_misc("Creating AVS file system directories for nvram and raw...");
178+
log_misc("Creating AVS file system directories...");
179179

180-
avs_fs_mountpoint_dir_create(node, "nvram");
181-
avs_fs_mountpoint_dir_create(node, "raw");
180+
avs_fs_mountpoints_fs_dirs_create(node);
182181

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

0 commit comments

Comments
 (0)