summaryrefslogtreecommitdiffstats
path: root/src/modules/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/kernel')
-rw-r--r--src/modules/kernel/kernel.c81
-rw-r--r--src/modules/kernel/kernel.h11
-rw-r--r--src/modules/kernel/option.h9
3 files changed, 101 insertions, 0 deletions
diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c
new file mode 100644
index 0000000..c405cbf
--- /dev/null
+++ b/src/modules/kernel/kernel.c
@@ -0,0 +1,81 @@
+#include "common/printing.h"
+#include "common/jsonconfig.h"
+#include "common/size.h"
+#include "common/strutil.h"
+#include "modules/kernel/kernel.h"
+
+bool ffPrintKernel(FFKernelOptions* options) {
+ const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
+ if (options->moduleArgs.outputFormat.length == 0) {
+ ffPrintLogoAndKey(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
+ printf("%s %s\n", info->name.chars, info->release.chars);
+ } else {
+ FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
+ ffSizeAppendNum(info->pageSize, &str);
+ FF_PRINT_FORMAT_CHECKED(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
+ FF_ARG(info->name, "sysname"),
+ FF_ARG(info->release, "release"),
+ FF_ARG(info->version, "version"),
+ FF_ARG(info->architecture, "arch"),
+ FF_ARG(str, "page-size"),
+ }));
+ }
+
+ return true;
+}
+
+void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module) {
+ yyjson_val *key, *val;
+ size_t idx, max;
+ yyjson_obj_foreach (module, idx, max, key, val) {
+ if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
+ continue;
+ }
+
+ ffPrintError(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
+ }
+}
+
+void ffGenerateKernelJsonConfig(FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
+}
+
+bool ffGenerateKernelJsonResult(FF_A_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
+
+ yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
+ yyjson_mut_obj_add_strbuf(doc, obj, "architecture", &info->architecture);
+ yyjson_mut_obj_add_strbuf(doc, obj, "name", &info->name);
+ yyjson_mut_obj_add_strbuf(doc, obj, "release", &info->release);
+ yyjson_mut_obj_add_strbuf(doc, obj, "version", &info->version);
+ yyjson_mut_obj_add_uint(doc, obj, "pageSize", info->pageSize);
+
+ return true;
+}
+
+void ffInitKernelOptions(FFKernelOptions* options) {
+ ffOptionInitModuleArg(&options->moduleArgs, "");
+}
+
+void ffDestroyKernelOptions(FFKernelOptions* options) {
+ ffOptionDestroyModuleArg(&options->moduleArgs);
+}
+
+FFModuleBaseInfo ffKernelModuleInfo = {
+ .name = FF_KERNEL_MODULE_NAME,
+ .description = "Print system kernel version",
+ .initOptions = (void*) ffInitKernelOptions,
+ .destroyOptions = (void*) ffDestroyKernelOptions,
+ .parseJsonObject = (void*) ffParseKernelJsonObject,
+ .printModule = (void*) ffPrintKernel,
+ .generateJsonResult = (void*) ffGenerateKernelJsonResult,
+ .generateJsonConfig = (void*) ffGenerateKernelJsonConfig,
+ .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
+ { "Sysname", "sysname" },
+ { "Release", "release" },
+ { "Version", "version" },
+ { "Architecture", "arch" },
+ { "Display version", "display-version" },
+ { "Page size", "page-size" },
+ }))
+};
diff --git a/src/modules/kernel/kernel.h b/src/modules/kernel/kernel.h
new file mode 100644
index 0000000..010ec54
--- /dev/null
+++ b/src/modules/kernel/kernel.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "option.h"
+
+#define FF_KERNEL_MODULE_NAME "Kernel"
+
+bool ffPrintKernel(FFKernelOptions* options);
+void ffInitKernelOptions(FFKernelOptions* options);
+void ffDestroyKernelOptions(FFKernelOptions* options);
+
+extern FFModuleBaseInfo ffKernelModuleInfo;
diff --git a/src/modules/kernel/option.h b/src/modules/kernel/option.h
new file mode 100644
index 0000000..a6520a9
--- /dev/null
+++ b/src/modules/kernel/option.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "common/option.h"
+
+typedef struct FFKernelOptions {
+ FFModuleArgs moduleArgs;
+} FFKernelOptions;
+
+static_assert(sizeof(FFKernelOptions) <= FF_OPTION_MAX_SIZE, "FFKernelOptions size exceeds maximum allowed size");