/* * startupdisk.c -- dtsystemsettings: the startup volume (t0174) * * Copyright (c) 2006 The Makronix project. GNU LGPL 2.0 or later, as CDE. * * The reference's window: the volumes of the computer, the one it starts * from marked, and "Restart...". The volumes come from mcde_sys_disks and * mcde_sys_info (the device of /); restarting goes through the bar's power * dialog, so it asks before anything happens. Choosing another startup * volume means writing the boot loader's configuration (root: grub on * Linux, boot.cfg on NetBSD) -- that is the follow-up, and the pane says so * instead of pretending. * * C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md). */ #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include #include #include #include #include #include #include "ui.h" static Widget list, detail, status; static McdeSysDisk disks[32]; static int ndisks, current = -1; static void Size(unsigned long long b, char *buf, size_t len) { if (b >= 1000000000ULL) (void)snprintf(buf, len, "%.1f GB", b / 1e9); else if (b >= 1000000ULL) (void)snprintf(buf, len, "%.0f MB", b / 1e6); else (void)snprintf(buf, len, "%llu bytes", b); } static void Show(int at) { char text[512], size[32]; if (at < 0 || at >= ndisks) { SetText(detail, "Choose a volume."); return; } Size(disks[at].bytes, size, sizeof size); (void)snprintf(text, sizeof text, "%s\nType: %s\nSize: %s\nMounted at: %s", disks[at].label[0] != '\0' ? disks[at].label : disks[at].name, disks[at].fstype[0] != '\0' ? disks[at].fstype : "unknown", size, disks[at].mountpoint[0] != '\0' ? disks[at].mountpoint : "not mounted"); SetText(detail, text); } static void Chosen(Widget w, XtPointer data, XtPointer call) { (void) w; (void) data; if (((XmListCallbackStruct *) call)->item_position > 0) Show(((XmListCallbackStruct *) call)->item_position - 1); } static void Restart(Widget w, XtPointer data, XtPointer call) { (void) w; (void) data; (void) call; /* the bar's power dialog: it asks, and only then restarts */ Spawn("dtbar -command power"); } Widget MakeStartupDisk(Widget parent) { Widget box = XtVaCreateManagedWidget("startupdisk", xmRowColumnWidgetClass, parent, XmNorientation, XmVERTICAL, XmNspacing, 8, NULL); Widget buttons; McdeSysInfo info; char row[256]; int i, at = 0; (void) Text(box, "startupLabel", "The volumes of this computer:"); list = XmCreateScrolledList(box, "volumes", NULL, 0); XtVaSetValues(list, XmNvisibleItemCount, 8, XmNwidth, 460, XmNheight, 200, NULL); XtManageChild(list); XtAddCallback(list, XmNbrowseSelectionCallback, Chosen, NULL); detail = Text(box, "startupDetail", ""); ndisks = mcde_sys_disks(disks, 32); if (mcde_sys_info(&info) == MCDE_SYS_OK) { for (i = 0; i < ndisks; i++) if (strcmp(disks[i].name, info.disk) == 0 || strcmp(disks[i].mountpoint, "/") == 0) current = i; } for (i = 0; i < ndisks; i++) { XmString s; (void)snprintf(row, sizeof row, "%s%s", i == current ? "* " : " ", disks[i].label[0] != '\0' ? disks[i].label : disks[i].name); s = XmStringCreateLocalized(row); XmListAddItemUnselected(list, s, 0); XmStringFree(s); if (i == 0) at = 0; } if (ndisks > 0) { XmListSelectPos(list, current >= 0 ? current + 1 : 1, False); Show(current >= 0 ? current : 0); } else SetText(detail, ndisks < 0 ? mcde_sys_error() : "No volume was " "found."); buttons = XtVaCreateManagedWidget("startupButtons", xmRowColumnWidgetClass, box, XmNorientation, XmHORIZONTAL, XmNspacing, 8, XmNmarginWidth, 0, NULL); (void) Button(buttons, "Restart...", Restart, NULL); (void) Text(box, "startupNote", "Choosing another startup volume " "writes the boot loader's configuration (root: grub on Linux, " "boot.cfg on NetBSD); that part is a follow-up. The volume in " "use is marked with *."); status = Text(box, "startupStatus", ""); if (current >= 0) { (void)snprintf(row, sizeof row, "Started from: %s", disks[current].label[0] != '\0' ? disks[current].label : disks[current].name); SetText(status, row); } (void) at; return box; }