summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-12 18:39:17 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-12 18:39:17 -0600
commita249fae4d0757e305a5a27758f1d1dfb0df6eda9 (patch)
tree58d0fa5a2d2350958880d930550cb6ded2f8dd44 /cmd
parentc0aa439917eb204ef481bc037dc3f552ab9d36c0 (diff)
srv9p: Tidy file tree
Diffstat (limited to 'cmd')
-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)