summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/sbc_harness/main.c35
-rw-r--r--lib9p/tests/test_server/main.c46
-rw-r--r--lib9p_util/include/util9p/static.h42
3 files changed, 54 insertions, 69 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index 2e83476..1c14762 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -39,42 +39,11 @@
/* file tree ******************************************************************/
-#define _box(nam, obj) \
- ((struct lib9p_srv_file){ \
- .self = obj, \
- .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \
- })
-#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) _box(util9p_static_file, obj)
-#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) _box(util9p_static_dir, obj)
-#define lo_box_api_as_lib9p_srv_file(obj) _box(api, obj)
-
enum { PATH_BASE = __COUNTER__ };
#define PATH_COUNTER __COUNTER__ - PATH_BASE
-#define STATIC_COMMON(STRNAME, MODE) \
- { \
- .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 = PATH_COUNTER, \
- .name = STRNAME, \
- .perm = MODE, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define STATIC_FILE(STRNAME, ...) \
- lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0444), \
- __VA_ARGS__ \
- }))
-
-#define STATIC_DIR(STRNAME, ...) \
- lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0555), \
- .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \
- }))
+#define STATIC_FILE(STRNAME, ...) UTIL9P_STATIC_FILE(PATH_COUNTER, STRNAME, __VA_ARGS__)
+#define STATIC_DIR(STRNAME, ...) UTIL9P_STATIC_DIR(PATH_COUNTER, STRNAME, __VA_ARGS__)
struct lib9p_srv_file root =
STATIC_DIR("",
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index 2c64cd4..c60dd71 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -73,8 +73,8 @@ static struct lib9p_stat api_stat(struct api_file *self, struct lib9p_srv_ctx *c
.kern_dev = 0,
.file_qid = api_qid(self),
.file_mode = 0222,
- .file_atime = 1728337905,
- .file_mtime = 1728337904,
+ .file_atime = UTIL9P_ATIME,
+ .file_mtime = UTIL9P_MTIME,
.file_size = 0,
.file_name = lib9p_str("shutdown"),
.file_owner_uid = lib9p_str("root"),
@@ -113,45 +113,19 @@ static uint32_t api_pread(struct api_file *, struct lib9p_srv_ctx *, void *, uin
assert_notreached("not readable");
}
-/* file tree ******************************************************************/
+#define lo_box_api_as_lib9p_srv_file(obj) util9p_box(api, obj)
-#define _box(nam, obj) \
- ((struct lib9p_srv_file){ \
- .self = obj, \
- .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \
- })
-#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) _box(util9p_static_file, obj)
-#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) _box(util9p_static_dir, obj)
-#define lo_box_api_as_lib9p_srv_file(obj) _box(api, obj)
+/* file tree ******************************************************************/
enum { PATH_BASE = __COUNTER__ };
#define PATH_COUNTER __COUNTER__ - PATH_BASE
-#define STATIC_COMMON(STRNAME, MODE) \
- { \
- .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 = PATH_COUNTER, \
- .name = STRNAME, \
- .perm = MODE, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define STATIC_FILE(STRNAME, SYMNAME) \
- lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0444), \
- .data_start = _binary_static_##SYMNAME##_start, \
- .data_end = _binary_static_##SYMNAME##_end, \
- }))
-
-#define STATIC_DIR(STRNAME, ...) \
- lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0555), \
- .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \
- }))
+#define STATIC_FILE(STRNAME, SYMNAME) \
+ UTIL9P_STATIC_FILE(PATH_COUNTER, STRNAME, \
+ .data_start = _binary_static_##SYMNAME##_start, \
+ .data_end = _binary_static_##SYMNAME##_end)
+#define STATIC_DIR(STRNAME, ...) \
+ UTIL9P_STATIC_DIR(PATH_COUNTER, STRNAME, __VA_ARGS__)
struct lib9p_srv_file root =
STATIC_DIR("",
diff --git a/lib9p_util/include/util9p/static.h b/lib9p_util/include/util9p/static.h
index 4afdb51..0b391b8 100644
--- a/lib9p_util/include/util9p/static.h
+++ b/lib9p_util/include/util9p/static.h
@@ -9,6 +9,17 @@
#include <lib9p/srv.h>
+#define util9p_box(nam, obj) \
+ ((struct lib9p_srv_file){ \
+ .self = obj, \
+ .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \
+ })
+
+#define UTIL9P_ATIME 1728337905
+#define UTIL9P_MTIME 1728337904
+
+/* Common *********************************************************************/
+
typedef struct {
char *u_name;
uint32_t u_num;
@@ -23,6 +34,21 @@ typedef struct {
uint32_t atime, mtime;
} _util9p_static_common;
+#define UTIL9P_STATIC_COMMON(PATH, STRNAME, MODE) \
+ { \
+ .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 = PATH, \
+ .name = STRNAME, \
+ .perm = MODE, \
+ .atime = UTIL9P_ATIME, \
+ .mtime = UTIL9P_MTIME, \
+ }
+
+/* Dir ************************************************************************/
+
struct util9p_static_dir {
_util9p_static_common;
@@ -30,6 +56,15 @@ struct util9p_static_dir {
lo_interface lib9p_srv_file members[];
};
LO_IMPLEMENTATION_H(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir);
+#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) util9p_box(util9p_static_dir, obj)
+
+#define UTIL9P_STATIC_DIR(PATH, STRNAME, ...) \
+ lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \
+ ._util9p_static_common = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0555), \
+ .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \
+ }))
+
+/* File ***********************************************************************/
struct util9p_static_file {
_util9p_static_common;
@@ -39,5 +74,12 @@ struct util9p_static_file {
size_t data_size; /* only used if .data_end==NULL */
};
LO_IMPLEMENTATION_H(lib9p_srv_file, struct util9p_static_file, util9p_static_file);
+#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) util9p_box(util9p_static_file, obj)
+
+#define UTIL9P_STATIC_FILE(PATH, STRNAME, ...) \
+ lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \
+ ._util9p_static_common = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0444), \
+ __VA_ARGS__ \
+ }))
#endif /* _UTIL9P_STATIC_H_ */