summaryrefslogtreecommitdiff
path: root/cmd/srv9p
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/srv9p')
-rw-r--r--cmd/srv9p/main.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c
index 8609f36..94a00f7 100644
--- a/cmd/srv9p/main.c
+++ b/cmd/srv9p/main.c
@@ -20,42 +20,54 @@
#define UNUSED(name) /* name __attribute__((unused)) */
-static struct static_file readme = {
- .metadata = {
- .header = { .vtable = &static_file_vtable },
-
- .u_name = "root", .u_num = 0, /* owner user */
- .g_name = "root", .g_num = 0, /* owner group */
- .m_name = "root", .m_num = 0, /* last-modified-by user */
-
- .pathnum = __COUNTER__,
- .name = "README.md",
- .perm = 0444,
- .atime = 1728337905,
- .mtime = 1728337904,
- },
-
- .data_start = _binary_static_README_md_start,
- .data_end = _binary_static_README_md_end,
-};
+/* file tree ******************************************************************/
+
+#define FILE_METADATA(NAME) { \
+ .header = { .vtable = &static_file_vtable }, \
+ \
+ .u_name = "root", .u_num = 0, /* owner user */ \
+ .g_name = "root", .g_num = 0, /* owner group */ \
+ .m_name = "root", .m_num = 0, /* last-modified-by user */ \
+ \
+ .pathnum = __COUNTER__, \
+ .name = NAME, \
+ .perm = 0444, \
+ .atime = 1728337905, \
+ .mtime = 1728337904, \
+ }
+
+#define DIR_METADATA(NAME) { \
+ .header = { .vtable = &static_dir_vtable }, \
+ \
+ .u_name = "root", .u_num = 0, /* owner user */ \
+ .g_name = "root", .g_num = 0, /* owner group */ \
+ .m_name = "root", .m_num = 0, /* last-modified-by user */ \
+ \
+ .pathnum = __COUNTER__, \
+ .name = NAME, \
+ .perm = 0555, \
+ .atime = 1728337905, \
+ .mtime = 1728337904, \
+ }
+
+#define STATIC_FILE(STRNAME, SYMNAME) \
+ &((static struct static_file){ \
+ .metadata = FILE_METADATA(STRNAME), \
+ .data_start = _binary_static_##SYMNAME##_start, \
+ .data_end = _binary_static_##SYMNAME##_end, \
+ }).metadata.header
static struct static_dir root = {
- .metadata = {
- .header = { .vtable = &static_dir_vtable },
-
- .u_name = "root", .u_num = 0, /* owner user */
- .g_name = "root", .g_num = 0, /* owner group */
- .m_name = "root", .m_num = 0, /* last-modified-by user */
-
- .pathnum = __COUNTER__,
- .name = "",
- .perm = 0555,
- .atime = 1728337905,
- .mtime = 1728337904,
- },
-
+ .metadata = DIR_METADATA(""),
.members = {
- &readme.metadata.header,
+ &((static struct static_dir){
+ .metadata = DIR_METADATA("Documentation"),
+ .members = {
+ STATIC_FILE("x", Documentation_x),
+ NULL
+ },
+ }).metadata.header,
+ STATIC_FILE("README.md", README_md),
NULL,
},
};
@@ -64,6 +76,8 @@ static struct lib9p_srv_file *get_root(struct lib9p_srv_ctx *UNUSED(ctx), char *
return &root.metadata.header;
}
+/* main ***********************************************************************/
+
int main() {
int sock = netio_listen(9000);
if (sock < 0)