From 66657505287743e8dbf0c1c66f1f58df7fcadcc9 Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Wed, 11 Nov 2026 15:24:05 +0100 Subject: [PATCH] feat: split About view into separate app; bump ramdisk in-memory file limit --- kernel/src/Api/BuildNo.hpp | 2 +- kernel/src/Fs/Ramdisk.hpp | 9 +- programs/GNUmakefile | 11 +- programs/include/montauk/user.h | 6 +- programs/src/about/Makefile | 44 +++++++ programs/src/about/main.cpp | 107 ++++++++++++++++++ programs/src/about/manifest.toml | 19 ++++ programs/src/about/stb_truetype_impl.cpp | 2 + programs/src/desktop/apps/settings/about.cpp | 50 -------- programs/src/desktop/apps/settings/app.cpp | 3 - .../apps/settings/settings_internal.hpp | 10 +- scripts/install_apps.sh | 1 + scripts/mkramdisk.sh | 11 ++ 13 files changed, 205 insertions(+), 70 deletions(-) create mode 100644 programs/src/about/Makefile create mode 100644 programs/src/about/main.cpp create mode 100644 programs/src/about/manifest.toml create mode 100644 programs/src/about/stb_truetype_impl.cpp delete mode 100644 programs/src/desktop/apps/settings/about.cpp diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp index 5e3f826..8812502 100644 --- a/kernel/src/Api/BuildNo.hpp +++ b/kernel/src/Api/BuildNo.hpp @@ -12,4 +12,4 @@ #pragma once -#define MONTAUK_BUILD_NUMBER 126 +#define MONTAUK_BUILD_NUMBER 132 diff --git a/kernel/src/Fs/Ramdisk.hpp b/kernel/src/Fs/Ramdisk.hpp index 46917b4..960a4d7 100644 --- a/kernel/src/Fs/Ramdisk.hpp +++ b/kernel/src/Fs/Ramdisk.hpp @@ -10,9 +10,12 @@ namespace Fs::Ramdisk { - // Static file table. The base image ships ~650 files since the - // 0:/usr devkit; keep generous headroom for runtime file creation. - static constexpr int MaxFiles = 2048; + // Static file table. The SDK image ships ~2000 entries; the rest is + // headroom for files created at runtime. Running out is not loud: Create + // fails, so e.g. users.toml is never written and login rejects the + // account that was just created. scripts/mkramdisk.sh checks the image + // against this number, so keep the two in step. + static constexpr int MaxFiles = 8192; // USTAR: 155-byte prefix field + '/' + 100-byte name field. static constexpr int MaxNameLen = 260; diff --git a/programs/GNUmakefile b/programs/GNUmakefile index 9da24bb..04136bc 100644 --- a/programs/GNUmakefile +++ b/programs/GNUmakefile @@ -45,7 +45,7 @@ BINDIR := bin$(ARCH_SUFFIX) PROGRAMS := $(notdir $(wildcard src/*)) # Programs with custom Makefiles (built separately). -CUSTOM_BUILDS := 2048 files settings fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard sshserver terminal syslog procmgr powermgr calculator charmap desktop login shell paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs libloader crashpad sshd rtlsdr sdr firstboot +CUSTOM_BUILDS := 2048 files settings fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard about sshserver terminal syslog procmgr powermgr calculator charmap desktop login shell paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs libloader crashpad sshd rtlsdr sdr firstboot SYSTEM_PROGRAMS := $(filter-out $(CUSTOM_BUILDS),$(PROGRAMS)) # Build targets: system programs go to bin/os/, apps go to bin/apps//. @@ -92,7 +92,7 @@ WPDIR := data/wallpapers WPSRC := $(wildcard $(WPDIR)/*.jpg) WPDST := $(patsubst $(WPDIR)/%,$(BINDIR)/os/wallpapers/%,$(WPSRC)) -.PHONY: all clean 2048 files settings fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard sshserver sshd terminal syslog procmgr powermgr calculator charmap login desktop shell paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs icons fonts configs osdata bearssl libc tls libjpeg libjpegwrite install-apps libloader crashpad rtlsdr sdr check-syscalls gen-syscalls rust firstboot +.PHONY: all clean 2048 files settings fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard about sshserver sshd terminal syslog procmgr powermgr calculator charmap login desktop shell paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs icons fonts configs osdata bearssl libc tls libjpeg libjpegwrite install-apps libloader crashpad rtlsdr sdr check-syscalls gen-syscalls rust firstboot # The on-OS SDK, tcc (an x86 code generator) and the Rust programs exist # for x86_64 only. @@ -252,6 +252,10 @@ capabilities: libc keyboard: libc $(MAKE) -C src/keyboard +# Build About applet (depends on libc). +about: libc + $(MAKE) -C src/about + # Build the Settings app (depends on libc, bearssl for user.h). settings: libc bearssl $(MAKE) -C src/settings @@ -421,7 +425,7 @@ crashpad: libc $(MAKE) -C src/crashpad # Install app bundles (manifests, icons, data files) into bin/apps//. -install-apps: 2048 files settings paint spreadsheet wordprocessor weather wikipedia imageviewer fontpreview pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard sshserver terminal syslog procmgr powermgr calculator charmap screenshot texteditor mandelbrot printers timezone crashpad +install-apps: 2048 files settings paint spreadsheet wordprocessor weather wikipedia imageviewer fontpreview pdfviewer disks devexplorer installer audio music video bluetooth network display capabilities keyboard about sshserver terminal syslog procmgr powermgr calculator charmap screenshot texteditor mandelbrot printers timezone crashpad PROGRAMS_BIN=$(BINDIR) ../scripts/install_apps.sh # Copy man pages into bin/os/man/ so mkramdisk.sh picks them up. @@ -576,6 +580,7 @@ clean: $(MAKE) -C src/bluetooth clean $(MAKE) -C src/network clean $(MAKE) -C src/keyboard clean + $(MAKE) -C src/about clean $(MAKE) -C src/settings clean $(MAKE) -C src/terminal clean $(MAKE) -C src/syslog clean diff --git a/programs/include/montauk/user.h b/programs/include/montauk/user.h index 37259c5..ef2062a 100644 --- a/programs/include/montauk/user.h +++ b/programs/include/montauk/user.h @@ -275,7 +275,8 @@ namespace user { hash_password(password, u->salt, u->password_hash); count++; - save_users(users, count); + // A full or read-only volume must not look like a created account. + if (save_users(users, count) < 0) return false; // Create home directory structure char dir[128]; @@ -321,8 +322,7 @@ namespace user { hash_password(new_password, users[i].salt, users[i].password_hash); - save_users(users, count); - return true; + return save_users(users, count) >= 0; } } return false; diff --git a/programs/src/about/Makefile b/programs/src/about/Makefile new file mode 100644 index 0000000..ced5601 --- /dev/null +++ b/programs/src/about/Makefile @@ -0,0 +1,44 @@ +# Makefile for the About applet on MontaukOS + +MAKEFLAGS += -rR +.SUFFIXES: + +include ../../mk/arch.mk +ifeq ($(wildcard $(TOOLCHAIN_PREFIX)gcc),) + CXX = $(error $(TOOLCHAIN_MISSING)) +else + CXX := $(TOOLCHAIN_PREFIX)g++ +endif + +PROG_INC := ../../include +LINK_LD := ../../link.ld +BINDIR := ../../bin$(ARCH_SUFFIX) +OBJDIR := obj$(ARCH_SUFFIX) +LIBDIR := ../../lib + +CXXFLAGS := -std=gnu++20 -g -O2 -pipe -Wall -Wextra -Wno-unused-parameter \ + -Wno-unused-function -ffreestanding -fno-stack-protector -fno-stack-check \ + -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections $(ARCH_FP_FLAGS) \ + -MMD -MP -I $(PROG_INC) -isystem $(PROG_INC)/libc +LDFLAGS := -nostdlib -Wl,--gc-sections -T $(LINK_LD) + +SRCS := main.cpp stb_truetype_impl.cpp +OBJS := $(addprefix $(OBJDIR)/,$(SRCS:.cpp=.o)) +TARGET := $(BINDIR)/apps/about/about.elf +LIBS := $(LIBDIR)/libc/$(ARCH_OUT)liblibc.a + +.PHONY: all clean +all: $(TARGET) + +$(TARGET): $(OBJS) $(LINK_LD) Makefile $(LIBS) + mkdir -p $(BINDIR)/apps/about + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ + +$(OBJDIR)/%.o: %.cpp Makefile + mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +-include $(OBJS:.o=.d) + +clean: + rm -rf $(OBJDIR) $(TARGET) diff --git a/programs/src/about/main.cpp b/programs/src/about/main.cpp new file mode 100644 index 0000000..afbb933 --- /dev/null +++ b/programs/src/about/main.cpp @@ -0,0 +1,107 @@ +/* + * main.cpp + * MontaukOS About applet: OS name, version, build number, architecture and uptime. + * Copyright (c) 2026 Daniel Hammer + */ + +#include +#include +#include +#include + +extern "C" { +#include +} + +using namespace gui; + +static constexpr int WIN_W = 460; +static constexpr int WIN_H = 260; + +static WsWindow g_win; +static montauk::abi::SysInfo g_info = {}; +static Color g_accent = colors::ACCENT; + +// Userspace is built per architecture and only runs on a matching kernel, +// so the compile target is the running system's architecture. +#if defined(__x86_64__) +static constexpr const char* OS_VARIANT = "MontaukOS for x86_64"; +#elif defined(__aarch64__) +static constexpr const char* OS_VARIANT = "MontaukOS for AArch64 (ARM 64-bit)"; +#else +static constexpr const char* OS_VARIANT = "MontaukOS (unknown platform)"; +#endif +static uint64_t g_drawn_sec = 0; // uptime second the window last showed + +static void render() { + mtk::StandaloneHost host(&g_win); + Canvas c = host.canvas(); + mtk::Theme theme = mtk::make_theme(g_accent); + c.fill(theme.window_bg); + + int x = 16; + int y = 20; + char line[128]; + int line_h = system_font_height() + 6; + + c.text_2x(x, y, g_info.osName, theme.accent); + int large_h = (fonts::system_font && fonts::system_font->valid) + ? fonts::system_font->get_line_height(fonts::LARGE_SIZE) : (FONT_HEIGHT * 2); + y += large_h + 8; + + snprintf(line, sizeof(line), "%s", OS_VARIANT); + c.kv_line(x, &y, line, theme.text, line_h); + + snprintf(line, sizeof(line), "Version %s (Build %u)", + g_info.osVersion, (unsigned)g_info.buildNumber); + c.text(x, y, line, theme.text); + y += line_h + 8; + + mtk::draw_separator(c, x, y, c.w - 2 * x, theme); + y += 12; + + snprintf(line, sizeof(line), "Build number: %u", (unsigned)g_info.buildNumber); + c.kv_line(x, &y, line, theme.text, line_h); + + g_drawn_sec = montauk::get_milliseconds() / 1000; + int up_sec = (int)g_drawn_sec; + int up_min = up_sec / 60; + int up_hr = up_min / 60; + snprintf(line, sizeof(line), "Uptime: %d:%02d:%02d", up_hr, up_min % 60, up_sec % 60); + c.kv_line(x, &y, line, theme.text, line_h); + y += 8; + + mtk::draw_separator(c, x, y, c.w - 2 * x, theme); + y += 12; + + c.text(x, y, "Copyright © 2025-2026 Montauk Operating System Project", theme.text_muted); + + g_win.present(); +} + +extern "C" void _start() { + if (!fonts::init()) montauk::exit(1); + g_accent = mtk::load_system_accent(); + montauk::get_info(&g_info); + + if (!g_win.create("About", WIN_W, WIN_H)) montauk::exit(1); + render(); + while (g_win.id >= 0 && !g_win.closed) { + montauk::abi::WinEvent ev; + int result = g_win.poll(&ev); + if (result < 0) break; + if (result == 0) { + // Keep the uptime line ticking. + if (montauk::get_milliseconds() / 1000 != g_drawn_sec) render(); + montauk::sleep_ms(16); + continue; + } + if (ev.type == 3) break; + if (ev.type == 0 && ev.key.pressed && ev.key.scancode == 0x01) + g_win.closed = true; + else if (ev.type == 2 || ev.type == 4) + render(); + } + g_win.destroy(); + montauk::exit(0); +} diff --git a/programs/src/about/manifest.toml b/programs/src/about/manifest.toml new file mode 100644 index 0000000..4397afb --- /dev/null +++ b/programs/src/about/manifest.toml @@ -0,0 +1,19 @@ +[app] +id = "about" +name = "About" +binary = "about.elf" +icon = "help-about.svg" + +[menu] +category = "System" +visible = false + +[desktop] +section = "settings" +admin_only = false + +# Where the Settings app lists this page and what its search matches. +[settings] +category = "System" +description = "OS version, build number and uptime" +keywords = "about version build number uptime system information montauk copyright" diff --git a/programs/src/about/stb_truetype_impl.cpp b/programs/src/about/stb_truetype_impl.cpp new file mode 100644 index 0000000..8d03b2b --- /dev/null +++ b/programs/src/about/stb_truetype_impl.cpp @@ -0,0 +1,2 @@ +#define STB_TRUETYPE_IMPLEMENTATION +#include diff --git a/programs/src/desktop/apps/settings/about.cpp b/programs/src/desktop/apps/settings/about.cpp deleted file mode 100644 index b4669f1..0000000 --- a/programs/src/desktop/apps/settings/about.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * about.cpp - * About tab for the embedded desktop settings app - * Copyright (c) 2026 Daniel Hammer -*/ - -#include "settings_internal.hpp" - -namespace settings_app { - -void settings_draw_about(Canvas& c, SettingsState* st) { - st->uptime_ms = montauk::get_milliseconds(); - - mtk::Theme theme = settings_theme(st); - int x = 16; - int y = 20; - char line[128]; - int sfh = system_font_height(); - int line_h = sfh + 6; - - c.text_2x(x, y, st->sys_info.osName, theme.accent); - int large_h = (fonts::system_font && fonts::system_font->valid) - ? fonts::system_font->get_line_height(fonts::LARGE_SIZE) : (FONT_HEIGHT * 2); - y += large_h + 8; - - snprintf(line, sizeof(line), "Version %s (Build %u)", - st->sys_info.osVersion, (unsigned)st->sys_info.buildNumber); - c.text(x, y, line, theme.text); - y += line_h + 8; - - mtk::draw_separator(c, x, y, c.w - 2 * x, theme); - y += 12; - - snprintf(line, sizeof(line), "Build number: %u", (unsigned)st->sys_info.buildNumber); - c.kv_line(x, &y, line, theme.text, line_h); - - int up_sec = (int)(st->uptime_ms / 1000); - int up_min = up_sec / 60; - int up_hr = up_min / 60; - snprintf(line, sizeof(line), "Uptime: %d:%02d:%02d", up_hr, up_min % 60, up_sec % 60); - c.kv_line(x, &y, line, theme.text, line_h); - y += 8; - - mtk::draw_separator(c, x, y, c.w - 2 * x, theme); - y += 12; - - c.text(x, y, "Copyright \u00A9 2025-2026 Montauk Operating System Project", theme.text_muted); -} - -} // namespace settings_app diff --git a/programs/src/desktop/apps/settings/app.cpp b/programs/src/desktop/apps/settings/app.cpp index 3934cc3..4092de7 100644 --- a/programs/src/desktop/apps/settings/app.cpp +++ b/programs/src/desktop/apps/settings/app.cpp @@ -26,7 +26,6 @@ static void settings_on_draw(Window* win, Framebuffer& fb) { case 0: settings_draw_appearance(content, st); break; case 1: settings_draw_display(content, st); break; case 2: settings_draw_widgets(content, st); break; - case 3: settings_draw_about(content, st); break; } } @@ -89,8 +88,6 @@ void open_settings(DesktopState* ds) { montauk::memset(st, 0, sizeof(settings_app::SettingsState)); st->desktop = ds; st->active_tab = 0; - montauk::get_info(&st->sys_info); - st->uptime_ms = montauk::get_milliseconds(); st->wp_scanned = false; st->wp_files.count = 0; st->status_msg[0] = '\0'; diff --git a/programs/src/desktop/apps/settings/settings_internal.hpp b/programs/src/desktop/apps/settings/settings_internal.hpp index c7082ab..08ce9bf 100644 --- a/programs/src/desktop/apps/settings/settings_internal.hpp +++ b/programs/src/desktop/apps/settings/settings_internal.hpp @@ -17,9 +17,7 @@ namespace settings_app { struct SettingsState { DesktopState* desktop; - int active_tab; // 0=Appearance, 1=Display, 2=Widgets, 3=About - montauk::abi::SysInfo sys_info; - uint64_t uptime_ms; + int active_tab; // 0=Appearance, 1=Display, 2=Widgets WallpaperFileList wp_files; bool wp_scanned; @@ -68,8 +66,8 @@ inline const Color accent_palette[SWATCH_COUNT] = { }; inline constexpr int TAB_BAR_H = 36; -inline constexpr int TAB_COUNT = 4; -inline constexpr const char* tab_labels[TAB_COUNT] = { "Appearance", "Display", "Widgets", "About" }; +inline constexpr int TAB_COUNT = 3; +inline constexpr const char* tab_labels[TAB_COUNT] = { "Appearance", "Display", "Widgets" }; inline constexpr int WP_ITEM_H = 24; @@ -93,8 +91,6 @@ bool settings_handle_display_click(SettingsState* st, int mx, int cy); void settings_draw_widgets(Canvas& c, SettingsState* st); bool settings_handle_widgets_click(Window* win, SettingsState* st, int mx, int cy); -void settings_draw_about(Canvas& c, SettingsState* st); - void settings_persist(SettingsState* st); } // namespace settings_app diff --git a/scripts/install_apps.sh b/scripts/install_apps.sh index cc1c896..189d2de 100755 --- a/scripts/install_apps.sh +++ b/scripts/install_apps.sh @@ -35,6 +35,7 @@ APPS=( "display|apps/scalable/preferences-desktop-display.svg" "capabilities|apps/scalable/stock_lock.svg" "keyboard|categories/scalable/preferences-keyboard.svg" + "about|categories/scalable/help-about.svg" "sshserver|apps/scalable/utilities-terminal.svg" "terminal|apps/scalable/utilities-terminal.svg" "syslog|apps/scalable/utilities-terminal.svg" diff --git a/scripts/mkramdisk.sh b/scripts/mkramdisk.sh index 62fc9be..765dd54 100755 --- a/scripts/mkramdisk.sh +++ b/scripts/mkramdisk.sh @@ -28,4 +28,15 @@ if tar -tvf "$OUTPUT_PATH" | grep -q '^l'; then exit 1 fi +# The kernel's ramdisk file table is fixed-size (MaxFiles in +# kernel/src/Fs/Ramdisk.hpp). Entries past it are dropped, and an image that +# only just fits leaves no slots for files created at runtime (users.toml!). +MAX_FILES=$(sed -n 's/.*constexpr int MaxFiles = \([0-9]*\);.*/\1/p' \ + "$(dirname "$0")/../kernel/src/Fs/Ramdisk.hpp") +ENTRIES=$(tar -tf "$OUTPUT_PATH" | wc -l) +if [ -n "$MAX_FILES" ] && [ "$ENTRIES" -gt $((MAX_FILES - 512)) ]; then + echo "mkramdisk: ERROR: $ENTRIES entries leaves under 512 free of the kernel's $MAX_FILES ramdisk slots; raise MaxFiles" >&2 + exit 1 +fi + echo "mkramdisk: created $OUTPUT_PATH from $INPUT_DIR ($(wc -c < "$OUTPUT_PATH") bytes)"