llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8
v0.7.0: real drive space, M.2 and USB downloads, unload before download
Abhiramfdcd90d90312
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c17f7b5..e2b6064 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,38 @@ v0.1.x are the upstream payload releases by cobanov.## [Unreleased]+## [0.7.0] - 2026-10-10++### Added+- Downloads check free space first: the file and 1 GiB to spare must fit on+ the drive. When it does not, a dialog offers the drive with the most room+ for this one download; the download itself refuses too, for the+ after-restart path.+- M.2 and every mounted USB drive: Download to in Settings steps through the+ drives that are mounted (internal, `/mnt/ext0`, `/mnt/usb0..3`), the+ STORAGE tile and the usage details list each one, and the library groups+ models by drive. Models in `PS5LM/models` on the M.2 drive are found too.+- Before a download while a model holds the memory (under 2 GiB free), a+ dialog offers to unload it first: the app restarts without the model and+ the download starts on its own.++### Fixed+- Storage figures were made up: a title's `statvfs` is a stub that reports+ 64 GiB with 16 GiB free for every path, and `statfs` is not exported to+ titles. Free and total space now come from ps5-exporter (bundled since+ v0.4.0), which reads the kernel's; internal storage is `/user`. Without the+ exporter the space shows as unknown and does not block a download.+- Get models opened after a restart now lists the popular repositories.+- A download without a checksum survives the unload-and-download restart.++### Checked on the console+- Real space: internal 166.7 of 627.6 GiB free, USB 461 of 477 GiB, as+ ps5-exporter reports them; the drive's 33 MB second partition is left out.+- A 500 GiB job refused on internal storage; a download to the USB drive;+ Download to stepping between internal and USB, saved; unload and download+ (SmolLM2 Q2_K); the scratch size warning and Clear.+- No M.2 drive is fitted, so that path is checked in the preview only.+## [0.6.0] - 2026-10-10### Addeddiff --git a/ps5/app/dashboard.cpp b/ps5/app/dashboard.cppindex 1aa0b8c..4aa25ec 100644--- a/ps5/app/dashboard.cpp+++ b/ps5/app/dashboard.cpp@@ -201,7 +201,7 @@ constexpr SettingCategory kCategories[] = {3 },{ "App", "The app itself.",{ { Setting::sounds, "Sounds", "Interface sounds on the TV." },- { Setting::download_dir, "Download to", "Where Get models saves: internal storage, or PS5LM/models on the USB drive." } },+ { Setting::download_dir, "Download to", "Where Get models saves: internal storage, or PS5LM/models on an M.2 or USB drive." } },2 },};constexpr int kCategoryCount = 4;@@ -382,7 +382,8 @@ void Dashboard::update_dashboard(const hui::InputFrame & input, ui::Feedback & fnamespace {// The value of a setting as the row shows it, and one step of it.-std::string setting_text(const Settings & s, Setting id, const std::vector<ModelRow> & models) {+std::string setting_text(const Settings & s, Setting id, const std::vector<ModelRow> & models,+ const std::vector<Drive> & drives) {char t[32];switch (id) {case Setting::default_model: {@@ -404,7 +405,14 @@ std::string setting_text(const Settings & s, Setting id, const std::vector<Modelcase Setting::scratch_limit:std::snprintf(t, sizeof(t), "%u GiB", s.scratch_limit_gib);return t;- case Setting::download_dir: return s.download_dir.rfind("/mnt/", 0) == 0 ? "USB drive" : "Internal storage";+ case Setting::download_dir: {+ for (const auto & d : drives) {+ if (d.models == s.download_dir) {+ return d.name;+ }+ }+ return s.download_dir.rfind("/mnt/ext", 0) == 0 ? "M.2 drive (not found)" : "USB drive (not found)";+ }default: return "";}}@@ -418,7 +426,7 @@ bool toggle_value(const Settings & s, Setting id) {constexpr uint32_t kScratchSteps[] = { 1, 2, 5, 10, 20 };// Moves a stepper one place; false at either end.-bool step_setting(Settings & s, Setting id, int dir, const std::vector<ModelRow> & models) {+bool step_setting(Settings & s, Setting id, int dir, const std::vector<ModelRow> & models, const std::vector<Drive> & drives) {switch (id) {case Setting::default_model: {// "None", then each model that fits, in the library's order.@@ -485,11 +493,18 @@ bool step_setting(Settings & s, Setting id, int dir, const std::vector<ModelRow>case Setting::tools: s.tools = !s.tools; return true;case Setting::clear_scratch: return false;case Setting::download_dir: {- const bool usb = s.download_dir.rfind("/mnt/", 0) == 0;- if ((dir > 0) == usb) {+ // Each mounted drive in turn; a missing one counts as before the first.+ int at = -1;+ for (int i = 0; i < (int) drives.size(); ++i) {+ if (drives[(size_t) i].models == s.download_dir) {+ at = i;+ }+ }+ const int next = at + dir;+ if (next < 0 || next >= (int) drives.size()) {return false;}- s.download_dir = usb ? "/data/PS5LM/models" : "/mnt/usb0/PS5LM/models";+ s.download_dir = drives[(size_t) next].models;return true;}}@@ -556,7 +571,7 @@ void Dashboard::update_settings(const hui::InputFrame & input, ui::Feedback & fedir = 0;}}- if (dir != 0 && step_setting(settings_, id, dir, live_.models)) {+ if (dir != 0 && step_setting(settings_, id, dir, live_.models, live_.drives)) {request_ = { Request::settings, "" };feedback.play(is_toggle(id) ? hui::audio::Cue::toggle : hui::audio::Cue::slider, 1.0f + 0.05f * (float) dir);} else if (dir != 0 && !input.nav_repeat) {@@ -589,7 +604,45 @@ int log_level(const std::string & line) {} // namespace+// After the space check: ask about a loaded model first, or start.+void Dashboard::start_download(ui::Feedback & feedback) {+ if (!live_.model_label.empty() && live_.free_gib < 2.0) {+ market_confirm_ = true; // a model holds the memory: ask first+ feedback.play(hui::audio::Cue::modal_open);+ } else {+ request_ = { Request::market_download, market_dir_, market_.open, market_file_ };+ feedback.play(hui::audio::Cue::complete);+ }+}+void Dashboard::update_market(const hui::InputFrame & input, ui::Feedback & feedback) {+ // The download does not fit where it would go.+ if (market_space_) {+ if (input.is_pressed(Action::confirm) && !market_dir_.empty()) {+ market_space_ = false;+ start_download(feedback);+ } else if (input.is_pressed(Action::back)) {+ market_space_ = false;+ feedback.play(hui::audio::Cue::back);+ }+ return;+ }+ // The question before a download while a model holds the memory.+ if (market_confirm_) {+ if (input.is_pressed(Action::north)) {+ request_ = { Request::market_download_unload, market_dir_, market_.open, market_file_ };+ market_confirm_ = false;+ feedback.play(hui::audio::Cue::complete);+ } else if (input.is_pressed(Action::confirm)) {+ request_ = { Request::market_download, market_dir_, market_.open, market_file_ };+ market_confirm_ = false;+ feedback.play(hui::audio::Cue::complete);+ } else if (input.is_pressed(Action::back)) {+ market_confirm_ = false;+ feedback.play(hui::audio::Cue::back);+ }+ return;+ }const int step = input.is_pressed(Action::jump_next) ? 1 : input.is_pressed(Action::jump_prev) ? -1 : 0;if (step != 0) {const int next = market_chip_ + step;@@ -629,11 +682,25 @@ void Dashboard::update_market(const hui::InputFrame & input, ui::Feedback & feedfeedback.play(hui::audio::Cue::open);} else if (market_files_ && open && cursor < files) {const MarketFile & f = open->files[(size_t) cursor];+ const double need = f.bytes / 1073741824.0 + 1.0; // and 1 GiB spare, as Market::download wants+ const Drive * to = nullptr;+ const Drive * other = nullptr; // the roomiest other drive it fits on+ for (const auto & d : live_.drives) {+ if (d.models == settings_.download_dir) {+ to = &d;+ } else if (d.free >= need && (!other || d.free > other->free)) {+ other = &d;+ }+ }+ market_dir_.clear();if (f.fits == 0 || market_.download_progress >= 0) {feedback.play(hui::audio::Cue::error); // too big, or one download already runs+ } else if (!to || (to->total > 0 && to->free < need)) { // unknown space (no exporter) does not block+ market_space_ = true;+ market_dir_ = other ? other->models : "";+ feedback.play(hui::audio::Cue::modal_open);} else {- request_ = { Request::market_download, "", market_.open, cursor };- feedback.play(hui::audio::Cue::complete);+ start_download(feedback);}}}@@ -932,22 +999,23 @@ void Dashboard::draw_content(gfx::DrawList & list, int tile, const Rect & r, flobreak;}case kStorage: {- const struct {- const char * name;- double free, total;- } drives[2] = { { "INTERNAL", L.data_free, L.data_total }, { "USB", L.usb_free, L.usb_total } };- for (int k = 0; k < 2; ++k) {- const float y = r.y + 92 + k * 52.0f;- caps(list, f, drives[k].name, r.x + kPad, y, 15, kInk.with_alpha(kMuted));- if (drives[k].total <= 0) {- ui::text(list, f.regular, k == 1 ? "No drive" : kDash, r.x + r.w - kPad, y, 20, kInk.with_alpha(kFaint),- gfx::Align::right);+ // Internal storage and the first two drives; no drive shows as such.+ const size_t n = std::min<size_t>(L.drives.size(), 3);+ for (size_t k = 0; k < n; ++k) {+ const Drive & d = L.drives[k];+ const float y = n > 2 ? r.y + 80 + (float) k * 40.0f : r.y + 92 + (float) k * 52.0f; // three fit tighter+ caps(list, f, d.name.substr(0, d.name.find(' ')), r.x + kPad, y, 15, kInk.with_alpha(kMuted));+ if (d.total <= 0) {+ ui::text(list, f.regular, kDash, r.x + r.w - kPad, y, 20, kInk.with_alpha(kFaint), gfx::Align::right);continue;}- std::snprintf(text, sizeof(text), "%.0f GiB free", drives[k].free);+ std::snprintf(text, sizeof(text), "%.0f GiB free", d.free);ui::text(list, f.mono, text, r.x + r.w - kPad, y, 20, kInk, gfx::Align::right);- bar(list, { r.x + kPad, y + 14, r.w - 2 * kPad, 8 },- (float) ((drives[k].total - drives[k].free) / drives[k].total) * up, kRose);+ bar(list, { r.x + kPad, y + 14, r.w - 2 * kPad, 8 }, (float) ((d.total - d.free) / d.total) * up, kRose);+ }+ if (n == 1) {+ caps(list, f, "USB / M.2", r.x + kPad, r.y + 144, 15, kInk.with_alpha(kMuted));+ ui::text(list, f.regular, "No drive", r.x + r.w - kPad, r.y + 144, 20, kInk.with_alpha(kFaint), gfx::Align::right);}break;}@@ -1094,12 +1162,16 @@ void Dashboard::draw_library(gfx::DrawList & list, std::uint32_t glass) const {for (int i = 0; i < rows; ++i) {const ModelRow & m = live_.models[(size_t) i];const int s = slot(i);- if (i == 0 || m.on_usb != live_.models[(size_t) i - 1].on_usb) {+ if (i == 0 || m.drive != live_.models[(size_t) i - 1].drive) {const int h = s - 1;if (h >= first && h < first + 8) {const float hy = top + (float) (h - first) * kRowH;- caps(list, f, m.on_usb ? "USB DRIVE" : "INTERNAL STORAGE", panel.x + 60, hy + 50, 16,- m.on_usb ? kAmber : kCyan);+ std::string head = m.drive.empty() ? "OTHER" : m.drive;+ for (char & c : head) {+ c = (char) std::toupper((unsigned char) c);+ }+ const bool internal = m.drive.rfind("Internal", 0) == 0;+ caps(list, f, head, panel.x + 60, hy + 50, 16, internal ? kCyan : kAmber);list.rounded_rect({ panel.x + 60, hy + 62, panel.w - 120, 1 }, 0, kInk.with_alpha(0.12f));}}@@ -1135,12 +1207,12 @@ void Dashboard::open_library() {cursor_y_.snap((float) slot(library_cursor_));}-// Rows come sorted by path, so internal (/data) ones precede USB (/mnt) ones;-// each group gets a header line above it.+// Rows come sorted by path, so they group by drive (/data, then /mnt/ext0,+// /mnt/usb0...); each group gets a header line above it.int Dashboard::slot(int row) const {int s = row + 1;- if (row > 0 && live_.models[(size_t) row].on_usb && !live_.models[0].on_usb) {- ++s;+ for (int i = 1; i <= row; ++i) {+ s += live_.models[(size_t) i].drive != live_.models[(size_t) i - 1].drive;}return s;}@@ -1308,20 +1380,22 @@ void Dashboard::draw_usage_details(gfx::DrawList & list, const Rect & panel) conbar(list, { x0, panel.y + 534, colw, 12 }, L.pool_gib > 0 ? (float) (used / L.pool_gib) : 0.0f, kAmber);caps(list, f, "STORAGE", x1, panel.y + 514, 16, kRose);- const struct {- const char * name;- double free, total;- } drives[2] = { { "Internal", L.data_free, L.data_total }, { "USB", L.usb_free, L.usb_total } };- for (int k = 0; k < 2; ++k) {- const float y = panel.y + 570 + k * 70.0f;- ui::text(list, f.regular, drives[k].name, x1, y, 20, kInk.with_alpha(0.85f));- if (drives[k].total <= 0) {- ui::text(list, f.regular, "No drive", x1 + colw, y, 20, kInk.with_alpha(kFaint), gfx::Align::right);+ const size_t n = std::min<size_t>(L.drives.size(), 3);+ for (size_t k = 0; k < n; ++k) {+ const Drive & d = L.drives[k];+ const float y = panel.y + 570 + (float) k * 56.0f;+ ui::text(list, f.regular, d.name, x1, y, 20, kInk.with_alpha(0.85f));+ if (d.total <= 0) {+ ui::text(list, f.regular, kDash, x1 + colw, y, 20, kInk.with_alpha(kFaint), gfx::Align::right);continue;}- std::snprintf(text, sizeof(text), "%.0f of %.0f GiB free", drives[k].free, drives[k].total);+ std::snprintf(text, sizeof(text), "%.0f of %.0f GiB free", d.free, d.total);ui::text(list, f.mono, text, x1 + colw, y, 20, kInk, gfx::Align::right);- bar(list, { x1, y + 16, colw, 10 }, (float) ((drives[k].total - drives[k].free) / drives[k].total), kRose);+ bar(list, { x1, y + 16, colw, 10 }, (float) ((d.total - d.free) / d.total), kRose);+ }+ if (n == 1) {+ ui::text(list, f.regular, "USB or M.2", x1, panel.y + 626, 20, kInk.with_alpha(0.85f));+ ui::text(list, f.regular, "No drive", x1 + colw, panel.y + 626, 20, kInk.with_alpha(kFaint), gfx::Align::right);}caps(list, f, "MODELS", x0, panel.y + 610, 16, kInk.with_alpha(kMuted));double on_disk = 0;@@ -1468,13 +1542,13 @@ void Dashboard::draw_settings(gfx::DrawList & list) const {if (focused) {list.rounded_rect({ cx - w * 0.5f + 34, row.cy() - 24, w - 68, 48 }, 14, kBlack.with_alpha(0.25f));}- const std::string v = setting_text(settings_, sr.id, live_.models);+ const std::string v = setting_text(settings_, sr.id, live_.models, live_.drives);ui::text(list, f.semibold, f.semibold.font->fit(v, 26, w - 100), cx, row.cy() + 9, 26,focused ? kInk : kInk.with_alpha(0.84f), gfx::Align::center);Settings probe = settings_;- const bool left_ok = step_setting(probe, sr.id, -1, live_.models);+ const bool left_ok = step_setting(probe, sr.id, -1, live_.models, live_.drives);probe = settings_;- const bool right_ok = step_setting(probe, sr.id, 1, live_.models);+ const bool right_ok = step_setting(probe, sr.id, 1, live_.models, live_.drives);const Color tint = focused ? kCyan : kInk;const float rest = focused ? 1.0f : 0.5f;ui::text(list, f.mono, "\xE2\x97\x80", cx - w * 0.5f + 12, row.cy() + 10, 30,@@ -1515,7 +1589,7 @@ void Dashboard::draw_market(gfx::DrawList & list) const {const float lx = p.x + kPad, lw = 620, rx = lx + lw + 40, rw = p.x + p.w - kPad - rx, top = p.y + 96;list.rounded_rect({ rx - 20, top, 1, kMarketRows * kMarketRowH }, 0, kInk.with_alpha(0.1f));- char text[160];+ char text[256];// Repositories.const int repos = (int) M.repos.size();const int rfirst = std::max(0, market_repo_ - (kMarketRows - 1));@@ -1569,6 +1643,64 @@ void Dashboard::draw_market(gfx::DrawList & list) const {}}+ // A question over the lists: a title, a headline, a paragraph, buttons.+ const auto dialog = [&](Color c, const char * title, const std::string & head, const char * body, const ui::Hint * hints,+ int n) {+ const Rect d{ p.cx() - 430, p.cy() - 150, 860, 300 };+ list.rounded_rect(p, kRadius, kBlack.with_alpha(0.55f)); // a scrim over the lists+ list.shadow({ d.x, d.y + 18, d.w, d.h }, 28, 40, kBlack.with_alpha(0.6f));+ draw_panel(list, d, 28, 1.0f, c);+ caps(list, f, title, d.x + 44, d.y + 56, 18, c);+ ui::text(list, f.semibold, f.semibold.font->fit(head, 24, d.w - 88), d.x + 44, d.y + 104, 24, kInk);+ ui::paragraph(list, f.regular, body, d.x + 44, d.y + 144, 21, d.w - 88, 30, kInk.with_alpha(kMuted), 3);+ ui::HintLayout layout;+ layout.size = 34.0f;+ layout.text_size = 22.0f;+ layout.cy = d.y + d.h - 40;+ layout.item_gap = 32.0f;+ ui::draw_hints(list, fonts_, ui::GlyphStyle::dark(), hints, n, d.x + d.w - 44, true, layout);+ };+ // The download does not fit where it would go.+ if (market_space_ && open && market_file_ < (int) open->files.size()) {+ const MarketFile & mf = open->files[(size_t) market_file_];+ const Drive * to = nullptr;+ const Drive * other = nullptr;+ for (const auto & d : live_.drives) {+ to = d.models == settings_.download_dir ? &d : to;+ other = d.models == market_dir_ ? &d : other;+ }+ char head[160];+ std::snprintf(head, sizeof(head), "%s needs %.1f GiB.", mf.name.c_str(), mf.bytes / 1073741824.0);+ char where[96];+ if (to) {+ std::snprintf(where, sizeof(where), "%s has %.1f GiB free", to->name.c_str(), to->free);+ } else {+ std::snprintf(where, sizeof(where), "The drive in Settings is not connected");+ }+ if (other) {+ std::snprintf(text, sizeof(text), "%s, and 1 GiB stays spare. %s has %.0f GiB free; this one download can go "+ "there. Download to in Settings keeps the default.", where, other->name.c_str(), other->free);+ } else {+ std::snprintf(text, sizeof(text), "%s, and 1 GiB stays spare. No other drive has room: free some space, or "+ "connect a USB drive or an M.2 drive.", where);+ }+ const std::string save = other ? "Save to " + other->name : "";+ const ui::Hint hints[] = { { ui::Button::cross, save.c_str() }, { ui::Button::circle, "Cancel" } };+ dialog(kRose, "NOT ENOUGH SPACE", head, text, other ? hints : hints + 1, other ? 2 : 1);+ }+ // The question before downloading next to a loaded model.+ if (market_confirm_) {+ std::snprintf(text, sizeof(text), "%s holds most of the memory.", live_.model_label.c_str());+ const std::string head = text;+ std::snprintf(text, sizeof(text),+ "%.1f GiB is free. The download may be slower while it stays loaded. Unloading restarts the app "+ "without it, and the download starts on its own.",+ live_.free_gib);+ const ui::Hint hints[] = { { ui::Button::triangle, "Unload and download" }, { ui::Button::cross, "Download anyway" },+ { ui::Button::circle, "Cancel" } };+ dialog(kAmber, "A MODEL IS LOADED", head, text, hints, 3);+ }+// The download, under both panes.const float by = p.y + p.h - 64;list.rounded_rect({ p.x + kPad, by - 24, p.w - 2 * kPad, 1 }, 0, kInk.with_alpha(0.1f));@@ -1662,6 +1794,8 @@ void Dashboard::draw_hints(DashboardFrame & frame) const {const ui::Hint plain[] = { { ui::Button::dpad, "Change" }, { ui::Button::circle, "Back" } };ui::draw_hints(frame.scene, fonts_, style, toggle ? hints : plain, toggle ? 3 : 2, kGridX + kGridW, true);}+ } else if (page_ == kMarketPage && (market_confirm_ || market_space_)) {+ // The dialog carries its own buttons.} else if (page_ == kMarketPage) {const ui::Hint browse[] = { { ui::Button::l2, "Search" }, { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Open" } };const ui::Hint files[] = { { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Download" }, { ui::Button::circle, "Back" } };diff --git a/ps5/app/dashboard.hpp b/ps5/app/dashboard.hppindex d7a2ee3..f63872f 100644--- a/ps5/app/dashboard.hpp+++ b/ps5/app/dashboard.hpp@@ -51,14 +51,24 @@ class Dashboard {void set_logs(std::vector<std::string> app, std::vector<std::string> llama);void set_market(MarketView view) { market_ = std::move(view); }int page() const { return page_; }+ void show_page(int page) {+ page_from_ = page_;+ page_ = page;+ page_age_ = 0;+ if (page == kMarketPage && !market_searched_) {+ market_searched_ = true;+ request_ = { Request::market_search, "" }; // the popular list, as arriving with R1 does+ }+ }void update(const hui::InputFrame & input, float dt, hui::ui::Feedback & feedback);void draw(DashboardFrame & frame) const;// What the user asked for, once: load or unload a model, or the settings// changed (read them with settings()).struct Request {- enum Kind { none, load, unload, settings, clear_scratch, market_search, market_open, market_plan, market_download } kind = none;- std::string path; // a model, or a market query+ enum Kind { none, load, unload, settings, clear_scratch, market_search, market_open, market_plan, market_download,+ market_download_unload } kind = none;+ std::string path; // a model, a market query, or the folder a download goes to (empty: the setting)int repo = -1, file = -1;};Request take_request() {@@ -84,6 +94,7 @@ class Dashboard {void update_settings(const hui::InputFrame & input, hui::ui::Feedback & feedback);void update_logs(const hui::InputFrame & input, hui::ui::Feedback & feedback);void update_market(const hui::InputFrame & input, hui::ui::Feedback & feedback);+ void start_download(hui::ui::Feedback & feedback);void draw_market(hui::gfx::DrawList & list) const;const std::vector<std::string> & log_view() const { return log_llama_ ? llama_view_ : app_view_; }void refilter_logs();@@ -134,6 +145,9 @@ class Dashboard {int market_file_ = 0; // cursor in the open repository's filesbool market_files_ = false; // the cursor is in the filesbool market_searched_ = false;+ bool market_confirm_ = false; // asking whether to unload the model first+ bool market_space_ = false; // telling that the download does not fit where it would go+ std::string market_dir_; // where this download goes instead of the setting, or emptymutable char size_text_[64] = {};};diff --git a/ps5/app/main.cpp b/ps5/app/main.cppindex d9ebafd..6884b9f 100644--- a/ps5/app/main.cpp+++ b/ps5/app/main.cpp@@ -103,14 +103,15 @@ constexpr const char * kChoice = "/data/PS5LM/model.txt";constexpr const char * kQuit = "/data/PS5LM/quit";constexpr const char * kSettings = "/data/PS5LM/settings.json";constexpr const char * kScratch = "/data/PS5LM/scratch";+constexpr const char * kPendingDownload = "/data/PS5LM/download.txt"; // a download to start after a restart// The file tools only: a title cannot start processes (no shell command).constexpr const char * kTools = "read_file,write_file,edit_file,file_glob_search,grep_search,get_info";constexpr const char * kLlamaLog = "/data/PS5LM/llama.log";constexpr const char * kModels = "/data/PS5LM/models";constexpr const char * kAssets = "/app0/assets";constexpr int kPort = 8081;-const std::vector<std::string> kModelDirs = { kModels, "/mnt/usb0/PS5LM/models", "/mnt/usb1/PS5LM/models",- "/mnt/usb0", "/mnt/usb1" };+const std::vector<std::string> kModelDirs = { kModels, "/mnt/ext0/PS5LM/models", "/mnt/usb0/PS5LM/models",+ "/mnt/usb1/PS5LM/models", "/mnt/usb0", "/mnt/usb1" };// The last lines of a log, up to about 64 KiB of it, oldest first.std::vector<std::string> tail_lines(const char * path) {@@ -322,7 +323,15 @@ std::vector<std::string> read_lines(const char * path) {return out;}-bool is_usb(const std::string & path) { return path.rfind("/mnt/usb", 0) == 0; }+// Free GiB on the drive whose models folder is `dir`, or -1 when unknown.+double free_gib(const std::string & dir) {+ for (const auto & d : mounted_drives()) {+ if (d.models == dir && d.total > 0) {+ return d.free;+ }+ }+ return -1;+}std::string base_name(const std::string & path) {std::string n = path.substr(path.find_last_of('/') + 1);@@ -377,7 +386,7 @@ struct Models {ModelRow row;row.file = path;row.label = base_name(path);- row.on_usb = is_usb(path);+ row.drive = drive_name(path);if (!m.ok) {row.plan = m.error;rows.push_back(row);@@ -603,6 +612,15 @@ int main(int, char **) {dash.set_settings(models.settings);bool library_shown = false; // opened once at launch when no model is loadedbool scratch_warned = false;+ // A download asked for with "unload and download" before the restart.+ if (const auto pending = read_lines(kPendingDownload); pending.size() >= 5) {+ unlink(kPendingDownload);+ MarketJob job{ pending[0], pending[1], pending[2] == "-" ? "" : pending[2], pending[4], std::strtoull(pending[3].c_str(), nullptr, 10) };+ market.download(job, free_gib(job.dir));+ dash.show_page(Dashboard::kMarketPage);+ library_shown = true; // stay on Get models, not the library+ std::printf("ps5lm-app: downloading %s/%s after the restart\n", job.repo.c_str(), job.file.c_str());+ }DashboardFrame frame;hui::ui::Feedback feedback;hui::PadSample samples[64];@@ -689,6 +707,7 @@ int main(int, char **) {char text[128];std::snprintf(text, sizeof(text), "PS5LM: the chat's scratch folder holds %.1f GiB; clear it in Settings", gib);notify(text);+ std::printf("ps5lm-app: %s\n", text + 7);}scratch_warned = over;}@@ -722,9 +741,26 @@ int main(int, char **) {case Dashboard::Request::market_open: market.open_repo(req.repo); break;case Dashboard::Request::market_plan: market.plan_file(req.repo, req.file); break;case Dashboard::Request::market_download: {- std::error_code ec;- std::filesystem::create_directories(models.settings.download_dir, ec);- market.download(req.repo, req.file, models.settings.download_dir);+ MarketJob job;+ if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job)) {+ market.download(job, free_gib(job.dir));+ }+ break;+ }+ case Dashboard::Request::market_download_unload: {+ // Unload by restarting (as the library does), leaving the+ // download for the new process to start.+ MarketJob job;+ if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job)) {+ std::ofstream(kPendingDownload) << job.repo << "\n" << job.file << "\n" << (job.sha256.empty() ? "-" : job.sha256) << "\n"+ << job.bytes << "\n" << job.dir << "\n";+ std::ofstream(kChoice) << "none\n";+ notify("PS5LM: unloading the model, then downloading");+ std::printf("ps5lm-app: restarting to download %s/%s without a model\n", job.repo.c_str(), job.file.c_str());+ std::fflush(nullptr);+ models.stop();+ sceSystemServiceLoadExec("/app0/eboot.bin", nullptr);+ }break;}default: break;diff --git a/ps5/app/market.cpp b/ps5/app/market.cppindex e89a4e5..87efc6e 100644--- a/ps5/app/market.cpp+++ b/ps5/app/market.cpp@@ -12,6 +12,7 @@ extern "C" {#include <cstdio>#include <fcntl.h>+#include <filesystem>#include <unistd.h>namespace ps5lm {@@ -187,26 +188,39 @@ void Market::plan_file(int repo, int file) {});}-void Market::download(int repo, int file, const std::string & dir) {- std::string id, name, sha;- uint64_t bytes = 0;+bool Market::job(int repo, int file, const std::string & dir, MarketJob * out) {+ std::lock_guard<std::mutex> lock(mutex_);+ if (repo < 0 || repo >= (int) view_.repos.size() || file < 0 || file >= (int) view_.repos[(size_t) repo].files.size()) {+ return false;+ }+ const MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];+ *out = { view_.repos[(size_t) repo].id, f.name, f.sha256, dir, f.bytes };+ return true;+}++void Market::download(const MarketJob & job, double free) {+ const std::string id = job.repo, name = job.file, sha = job.sha256, dir = job.dir;+ const uint64_t bytes = job.bytes;{std::lock_guard<std::mutex> lock(mutex_);- if (repo < 0 || repo >= (int) view_.repos.size() || file < 0 ||- file >= (int) view_.repos[(size_t) repo].files.size()) {- return;- }- const MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];- id = view_.repos[(size_t) repo].id;- name = f.name;- sha = f.sha256;- bytes = f.bytes;if (downloading_) {return;}view_.download_file = name;- view_.download_progress = 0;view_.download_result.clear();+ // Room for the file and 1 GiB to spare, so a download never fills a+ // drive (a full /data upsets the system, not only this app).+ std::error_code ec;+ std::filesystem::create_directories(dir, ec);+ if (free >= 0 && free < bytes / 1073741824.0 + 1.0) {+ char text[256];+ std::snprintf(text, sizeof(text), "Not enough space: %s needs %.1f GiB and 1 GiB spare, %s has %.1f GiB free",+ name.c_str(), bytes / 1073741824.0, dir.c_str(), free);+ view_.download_result = text;+ std::printf("ps5lm-app: download %s/%s: %s\n", id.c_str(), name.c_str(), text);+ return;+ }+ view_.download_progress = 0;}run(downloading_, [this, id, name, sha, bytes, dir] {const size_t slash = name.find_last_of('/');diff --git a/ps5/app/market.hpp b/ps5/app/market.hppindex 021083e..13935fd 100644--- a/ps5/app/market.hpp+++ b/ps5/app/market.hpp@@ -42,6 +42,13 @@ struct MarketView {std::string download_result; // "Saved to …" or the error};+// One file to download, by name: it survives the app restarting (a download+// asked for after unloading the model is picked up by the new process).+struct MarketJob {+ std::string repo, file, sha256, dir;+ uint64_t bytes = 0;+};+class Market {public:// budget_gib: GPU memory free before any model, for the fit column.@@ -51,7 +58,9 @@ class Market {void search(const std::string & query);void open_repo(int index);void plan_file(int repo, int file); // reads its header (16 MiB range request)- void download(int repo, int file, const std::string & dir);+ bool job(int repo, int file, const std::string & dir, MarketJob * out);+ // `free_gib`: room on the drive it goes to, or -1 when unknown (the check is skipped).+ void download(const MarketJob & job, double free_gib);private:// One browse job (search, listing, plan) and one download at a time.diff --git a/ps5/app/preview_main.cpp b/ps5/app/preview_main.cppindex a6f94d0..cd733e5 100644--- a/ps5/app/preview_main.cpp+++ b/ps5/app/preview_main.cpp@@ -78,10 +78,7 @@ ps5lm::Live sample(float seconds, bool generating) {L.temps = { { "cpu", 54 }, { "soc0", 61 }, { "soc1", 60 }, { "soc2", 59 }, { "soc3", 62 }, { "soc4", 61 },{ "soc5", 60 }, { "soc6", 58 } };L.cpu_ghz = 3.5f;- L.data_free = 412;- L.data_total = 825;- L.usb_free = 455;- L.usb_total = 477;+ L.drives = { { "Internal storage", "/data/PS5LM/models", 8, 825 }, { "M.2 drive", "/mnt/ext0/PS5LM/models", 1520, 1863 }, { "USB drive", "/mnt/usb0/PS5LM/models", 455, 477 } };L.pool_gib = 11.44;L.free_gib = 0.31;L.heap_gib = 0.76;@@ -113,6 +110,7 @@ ps5lm::Live sample(float seconds, bool generating) {for (int i = 0; i < 5; ++i) {ps5lm::ModelRow m;m.file = std::string("/data/PS5LM/models/") + files[i] + ".gguf";+ m.drive = "Internal storage";m.label = files[i];m.plan = plans[i];m.size_gib = sizes[i];@@ -127,7 +125,8 @@ ps5lm::Live sample(float seconds, bool generating) {usb.plan = "64k context, q8_0 cache: 8.6 of 11.0 GiB";usb.preset = "Ornith 1.5";usb.size_gib = 5.38;- usb.fits = usb.on_usb = true;+ usb.fits = true;+ usb.drive = "USB drive";L.models.push_back(usb);usb.file = "/mnt/usb0/PS5LM/models/gemma-4-12b-it-Q3_K_M.gguf";usb.label = "gemma-4-12b-it-Q3_K_M";@@ -324,5 +323,11 @@ int main(int argc, char ** argv) {step(30, press(hui::Action::confirm), false);step(20, nav(hui::Direction::down), false);shot("12-market-files");+ mv.download_progress = -1; // nothing downloading, so Cross asks first+ dash.set_market(mv);+ step(30, press(hui::Action::confirm), false);+ shot("13-market-space");+ step(30, press(hui::Action::confirm), false);+ shot("14-market-confirm");return ok ? 0 : 1;}diff --git a/ps5/app/stats.cpp b/ps5/app/stats.cppindex 9c7de5a..2126587 100644--- a/ps5/app/stats.cpp+++ b/ps5/app/stats.cpp@@ -59,6 +59,40 @@ void space(const char * path, double * free, double * total) {*total = (double) v.f_blocks * v.f_frsize / kGiB;}+} // namespace++// A title's statvfs is a stub (the same 64 GiB for every path) and statfs is+// not exported to titles, so the space comes from ps5-exporter, a payload.+// /data is /user/data. Without the exporter the space is unknown (total 0).+std::vector<Drive> drives_from_metrics(const std::string & text) {+ std::vector<Drive> out = { { "Internal storage", "/data/PS5LM/models" } };+ const std::string key = "ps5_filesystem_size_bytes{mountpoint=\"";+ for (size_t at = text.find(key); at != std::string::npos; at = text.find(key, at + 1)) {+ const size_t from = at + key.size();+ const std::string mount = text.substr(from, text.find('"', from) - from);+ const size_t brace = text.find('{', at);+ const std::string labels = text.substr(brace, text.find('}', from) + 1 - brace); // {mountpoint=...,fstype=...}+ const double total = sample(text, "ps5_filesystem_size_bytes" + labels, 0) / kGiB;+ const double free = sample(text, "ps5_filesystem_avail_bytes" + labels, 0) / kGiB;+ if (mount == "/user") {+ out[0].free = free;+ out[0].total = total;+ } else if ((mount.rfind("/mnt/ext", 0) == 0 || mount.rfind("/mnt/usb", 0) == 0) && total >= 1.0) {+ // ponytail: drives under 1 GiB are left out (a USB stick's small partition)+ out.push_back({ drive_name(mount), mount + "/PS5LM/models", free, total });+ }+ }+ return out;+}++std::vector<Drive> mounted_drives() { return drives_from_metrics(http_get(9100, "/metrics", 2)); }++std::string drive_name(const std::string & path) {+ return path.rfind("/mnt/ext", 0) == 0 ? "M.2 drive" : path.rfind("/mnt/usb", 0) == 0 ? "USB drive" : "Internal storage";+}++namespace {+double now_s() {return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count();}@@ -302,8 +336,9 @@ void StatsCollector::run() {float fan = -1;bool from_exporter = false;std::vector<std::pair<std::string, float>> temps;+ std::string p; // ps5-exporter's metricsif (soc_t < -100) {- std::string p = http_get(9100, "/metrics");+ p = http_get(9100, "/metrics");// Not running: hand the bundled copy to elfldr, at start and then// once a minute (elfldr may come later).if (p.empty() && (long) (wall - start) % 60 == 1) {@@ -329,13 +364,7 @@ void StatsCollector::run() {}}}- double data_free = 0, data_total = 0, usb_free = 0, usb_total = 0;- space("/data", &data_free, &data_total);- // An empty /mnt/usb0 is a directory of the root filesystem, not a drive.- struct statvfs usb = {}, mnt = {};- if (statvfs("/mnt/usb0", &usb) == 0 && statvfs("/mnt", &mnt) == 0 && usb.f_fsid != mnt.f_fsid) {- space("/mnt/usb0", &usb_free, &usb_total);- }+ std::vector<Drive> drives = drives_from_metrics(p);std::lock_guard<std::mutex> lock(mutex_);const double dt = wall - last_wall;@@ -353,10 +382,7 @@ void StatsCollector::run() {if (soc_t > -100) {push(live_.temp_history, soc_t);}- live_.data_free = data_free;- live_.data_total = data_total;- live_.usb_free = usb_free;- live_.usb_total = usb_total;+ live_.drives = std::move(drives);live_.uptime_s = wall - start;live_.pool_gib = pool;live_.free_gib = free;diff --git a/ps5/app/stats.hpp b/ps5/app/stats.hppindex 14d8048..4a40260 100644--- a/ps5/app/stats.hpp+++ b/ps5/app/stats.hpp@@ -18,6 +18,13 @@namespace ps5lm {+// A place models can live: internal storage, the M.2 slot, or a USB drive.+struct Drive {+ std::string name; // "Internal storage", "M.2 drive", "USB drive"+ std::string models; // where PS5LM keeps models on it+ double free = 0, total = 0; // GiB; total 0 when unknown (no ps5-exporter)+};+enum class ServerState : uint8_t { loading, ready, generating, failed, no_model };struct ModelRow {@@ -29,7 +36,7 @@ struct ModelRow {double size_gib = 0;bool fits = false;bool current = false;- bool on_usb = false; // on a USB drive; loads from there like internal ones+ std::string drive; // the Drive's name it is on; every drive loads alike};struct Live {@@ -73,9 +80,8 @@ struct Live {double energy_wh = 0; // SoC energy since the app startedstd::vector<std::pair<std::string, float>> temps; // every sensor that answered ("cpu", "soc0", ...)- // Storage, GiB; usb_total 0 when no drive is mounted.- double data_free = 0, data_total = 0;- double usb_free = 0, usb_total = 0;+ // Storage: internal first, then the M.2 slot and USB drives that are mounted.+ std::vector<Drive> drives;double scratch_gib = 0; // the chat tools' scratch folder// Memory, GiB.@@ -118,6 +124,14 @@ class StatsCollector {// The console's address on the LAN, as the PC sees it ("192.168.1.19"), or// empty. Asks the routing table through an unconnected UDP socket: nothing is sent.// Sends a payload file to an ELF loader on this console; false if none listens.+// Internal storage, then each mounted M.2 or USB drive, with its space, from+// ps5-exporter's metrics (asked for here, or text already fetched).+std::vector<Drive> mounted_drives();+std::vector<Drive> drives_from_metrics(const std::string & text);++// The kind of drive holding `path`: "Internal storage", "M.2 drive", "USB drive".+std::string drive_name(const std::string & path);+bool send_payload(const char * path, int port);std::string local_address();@@ -128,4 +142,7 @@ std::string http_get(int port, const char * path, int timeout_s = 1);// One value from Prometheus text ("llamacpp:tokens_predicted_total 42").double metric(const std::string & text, const char * name);+// One sample from Prometheus text by its full name and labels, or `missing`.+double sample(const std::string & text, const std::string & key, double missing);+} // namespace ps5lmdiff --git a/ps5/app/version.hpp b/ps5/app/version.hppindex 58f24e8..4a33fb9 100644--- a/ps5/app/version.hpp+++ b/ps5/app/version.hpp@@ -4,4 +4,4 @@// The app's version, semver. The one place it is set: scripts read it from// here (scripts/release-app.sh), and git tags are v<this>. Bump it with an// entry in CHANGELOG.md.-#define PS5LM_VERSION "0.6.0"+#define PS5LM_VERSION "0.7.0"