mcde: dtdiskutility, the disks of the computer
A program of its own: the drives on the left, each followed by its partitions (label, or where mounted, and size); on the right the chosen one's name, model, device, capacity, file system, mount point, used and available, and a bar of how full it is; below two pages. First Aid: Verify Disk (fsck -n, changes nothing), Verify Permissions and Repair Permissions (the system's files against /etc/mtree/set.*), with their report. Erase: a name and a format -- NetBSD FFS, MS-DOS FAT32, Linux ext4 -- for a whole drive, after a warning that names the drive and says everything on it is lost; a drive that holds the system is never offered. The toolbar mounts and unmounts. As a user it shows and verifies, and Unlock... starts it again as root under su in a terminal. All through McdeSys. Measured on Xvfb as a user (build/mcde-shots/du-*.png): the host's NVMe drive with /boot/efi, /boot and the crypto partition; /boot chosen showed ext4, 318 MB used, 603 MB available, "Holds the system" and the bar; the Erase page offers the three formats and erases nothing for a partition. Not measured: mounting, verifying, erasing, repairing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfc5c3f22c
commit
5eee8d5d8f
6 files changed
+719
-1
No files matched your search
@@ -144,6 +144,15 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
|
||||
libpng, the rest through XmGetPixmap -- Motif 2.3.8 draws an RGB PNG
|
||||
without alpha as its blue channel only (docs/reference/motif-png.txt in
|
||||
the Makronix tree). Give such pixmaps back with McdeImageFreePixmap.
|
||||
- `programs/dtdiskutility` -- the disks: drives with their partitions on
|
||||
the left; on the right name, model, size, file system, mount point and a
|
||||
bar of used and free; First Aid (Verify Disk: fsck -n; Verify and Repair
|
||||
Permissions: mcde_sys_permissions against /etc/mtree/set.*) and Erase
|
||||
(one partition over a whole drive, FFS, FAT32 or ext4, after a warning
|
||||
that names the drive); Mount and Unmount. Changing needs root; as a user
|
||||
Unlock... starts it again under su in a terminal. Never erase, mount or
|
||||
repair anything on the development host or the build VM's disk in a
|
||||
test.
|
||||
- `programs/dtsystemsettings` -- the settings of the computer in one window:
|
||||
four bands (Personal, Hardware, Internet & Network, System) of icons
|
||||
(`panes.c`, plain C with `test_panes`), a click opens the pane in the
|
||||
|
||||
@@ -810,6 +810,7 @@ programs/dtcalc/Makefile
|
||||
programs/dtlaunch/Makefile
|
||||
programs/dtbar/Makefile
|
||||
programs/dtsystemsettings/Makefile
|
||||
programs/dtdiskutility/Makefile
|
||||
|
||||
programs/dtaction/Makefile
|
||||
|
||||
|
||||
@@ -2523,6 +2523,7 @@ dt/bin/dtcm_lookup
|
||||
dt/bin/dtcodegen
|
||||
dt/bin/dtcreate
|
||||
dt/bin/dtdbcache
|
||||
dt/bin/dtdiskutility
|
||||
dt/bin/dtdocbook2infolib
|
||||
dt/bin/dtdocbook2man
|
||||
dt/bin/dtdocbook2sdl
|
||||
|
||||
@@ -6,7 +6,7 @@ SUBDIRS = backdrops icons dsdm dtmail dtpad dtfile dtwm dtlogin \
|
||||
dtappbuilder palettes dtappintegrate dtprintegrate dtconfig \
|
||||
dtcreate dtprintinfo fontaliases dtdspmsg ttsnoop dtimsstart \
|
||||
dtpdm dtsr dtpdmd dtinfo types tttypes util dtopen localized \
|
||||
dthelp dtdocbook dtlaunch dtbar dtsystemsettings
|
||||
dthelp dtdocbook dtlaunch dtbar dtsystemsettings dtdiskutility
|
||||
|
||||
install-data-hook:
|
||||
-if [ $(CDE_INSTALLATION_TOP)/bin != $(bindir) ];then \
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
# dtdiskutility, the disks of the computer and what can be done to them
|
||||
# (main.c); the system is behind McdeSys (include/Mcde/McdeSys.h).
|
||||
bin_PROGRAMS = dtdiskutility
|
||||
|
||||
dtdiskutility_SOURCES = main.c
|
||||
dtdiskutility_CPPFLAGS = -I$(top_srcdir)/include $(DT_INCDIR) \
|
||||
-I$(top_builddir)/include \
|
||||
-DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\"
|
||||
dtdiskutility_LDADD = $(LIBMCDESYS) $(DTCLIENTLIBS) $(XTOOLLIB)
|
||||
@@ -0,0 +1,696 @@
|
||||
/*
|
||||
* main.c -- dtdiskutility: the disks of the computer, and what can be done
|
||||
* to them
|
||||
*
|
||||
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
||||
*
|
||||
* On the left the drives, each followed by its partitions. On the right
|
||||
* what is chosen: its name, model, size, file system, where it is mounted
|
||||
* and how full, as a bar; below, two pages:
|
||||
*
|
||||
* First Aid Verify Disk (fsck -n: looks, changes nothing), Verify
|
||||
* Permissions and Repair Permissions (the system's files
|
||||
* against the list the system keeps), with their report;
|
||||
* Erase a drive made new: one partition, a file system, a name --
|
||||
* after a question that says what is lost.
|
||||
*
|
||||
* The toolbar mounts and unmounts. Everything goes through McdeSys
|
||||
* (mcde_sys_disks, _disk_mount, _unmount, _check, _erase,
|
||||
* mcde_sys_permissions). Changing anything needs the administrator:
|
||||
* as a user the program shows and verifies, and Unlock... starts it again
|
||||
* as root in a terminal where su(1) asks for the password.
|
||||
*
|
||||
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Shell.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/DrawingA.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/Frame.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/List.h>
|
||||
#include <Xm/MessageB.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
#include <Xm/Separator.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Xm/TextF.h>
|
||||
#include <Xm/ToggleB.h>
|
||||
#include <Dt/Dt.h>
|
||||
|
||||
#include <Mcde/McdeSys.h>
|
||||
|
||||
#define MAX_DISKS 64
|
||||
|
||||
static XtAppContext app;
|
||||
static Widget shell, diskList, title, info, bar, pageAid, pageErase;
|
||||
static Widget tabAid, tabErase, report, mountButton, unmountButton;
|
||||
static Widget eraseName, eraseFormat, eraseButton, eraseNote, statusLine;
|
||||
static Widget fsButtons[3];
|
||||
static McdeSysDisk disks[MAX_DISKS];
|
||||
static int ndisks, chosen = -1, isRoot;
|
||||
|
||||
static const char *fallback[] = {
|
||||
"*renderTable: mcde",
|
||||
"*mcde.fontType: FONT_IS_XFT",
|
||||
"*mcde.fontName: Hack",
|
||||
"*mcde.fontSize: 10",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* ---- small helpers ------------------------------------------------------ */
|
||||
|
||||
static void
|
||||
SetText(Widget w, const char *text)
|
||||
{
|
||||
XmString s = XmStringCreateLocalized((char *) text);
|
||||
|
||||
XtVaSetValues(w, XmNlabelString, s, NULL);
|
||||
XmStringFree(s);
|
||||
}
|
||||
|
||||
static Widget
|
||||
Text(Widget parent, const char *name, const char *text)
|
||||
{
|
||||
XmString s = XmStringCreateLocalized((char *) text);
|
||||
Widget w = XtVaCreateManagedWidget(name, xmLabelWidgetClass, parent,
|
||||
XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
||||
|
||||
XmStringFree(s);
|
||||
return w;
|
||||
}
|
||||
|
||||
static Widget
|
||||
Button(Widget parent, const char *label, XtCallbackProc cb, XtPointer data)
|
||||
{
|
||||
XmString s = XmStringCreateLocalized((char *) label);
|
||||
Widget b = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass,
|
||||
parent, XmNlabelString, s, NULL);
|
||||
|
||||
XmStringFree(s);
|
||||
if (cb != NULL)
|
||||
XtAddCallback(b, XmNactivateCallback, cb, data);
|
||||
return b;
|
||||
}
|
||||
|
||||
static void
|
||||
Size(unsigned long long b, char *buf, size_t len)
|
||||
{
|
||||
if (b >= 1000000000000ULL)
|
||||
snprintf(buf, len, "%.2f TB", b / 1e12);
|
||||
else if (b >= 1000000000ULL)
|
||||
snprintf(buf, len, "%.1f GB", b / 1e9);
|
||||
else if (b >= 1000000ULL)
|
||||
snprintf(buf, len, "%.0f MB", b / 1e6);
|
||||
else
|
||||
snprintf(buf, len, "%llu bytes", b);
|
||||
}
|
||||
|
||||
static void
|
||||
ShowStatus(const char *text)
|
||||
{
|
||||
SetText(statusLine, text);
|
||||
XmUpdateDisplay(statusLine);
|
||||
}
|
||||
|
||||
static void
|
||||
Message(const char *text, int error)
|
||||
{
|
||||
Widget d;
|
||||
XmString s = XmStringCreateLocalized((char *) text);
|
||||
|
||||
d = error ? XmCreateErrorDialog(shell, "message", NULL, 0) :
|
||||
XmCreateInformationDialog(shell, "message", NULL, 0);
|
||||
XtVaSetValues(d, XmNmessageString, s, NULL);
|
||||
XmStringFree(s);
|
||||
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_CANCEL_BUTTON));
|
||||
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_HELP_BUTTON));
|
||||
XtManageChild(d);
|
||||
}
|
||||
|
||||
/* ---- the bar: used and free ---------------------------------------------- */
|
||||
|
||||
static void
|
||||
BarExpose(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
Display *dpy = XtDisplay(w);
|
||||
Dimension width = 0, height = 0;
|
||||
Pixel fg, bg, sel;
|
||||
GC gc;
|
||||
unsigned long long total;
|
||||
int used = 0;
|
||||
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (!XtIsRealized(w))
|
||||
return;
|
||||
XtVaGetValues(w, XmNwidth, &width, XmNheight, &height,
|
||||
XmNforeground, &fg, XmNbackground, &bg, NULL);
|
||||
XtVaGetValues(info, XmNbackground, &sel, NULL);
|
||||
gc = XCreateGC(dpy, XtWindow(w), 0, NULL);
|
||||
XSetForeground(dpy, gc, bg);
|
||||
XFillRectangle(dpy, XtWindow(w), gc, 0, 0, width, height);
|
||||
if (chosen >= 0 && disks[chosen].mountpoint[0] != '\0') {
|
||||
total = disks[chosen].used + disks[chosen].avail;
|
||||
if (total > 0)
|
||||
used = (int) ((double) disks[chosen].used / total *
|
||||
(width - 2));
|
||||
/* the used part in the palette's select colour, as a scale */
|
||||
XtVaGetValues(diskList, XmNselectColor, &sel, NULL);
|
||||
XSetForeground(dpy, gc, sel);
|
||||
XFillRectangle(dpy, XtWindow(w), gc, 1, 1, (unsigned) used,
|
||||
height > 2 ? height - 2 : 1);
|
||||
}
|
||||
XSetForeground(dpy, gc, fg);
|
||||
XDrawRectangle(dpy, XtWindow(w), gc, 0, 0, width - 1, height - 1);
|
||||
XFreeGC(dpy, gc);
|
||||
}
|
||||
|
||||
/* ---- the list and the information ---------------------------------------- */
|
||||
|
||||
static void
|
||||
ShowInfo(void)
|
||||
{
|
||||
char text[2048], size[32], used[32], avail[32];
|
||||
McdeSysDisk *d;
|
||||
|
||||
XtSetSensitive(mountButton, False);
|
||||
XtSetSensitive(unmountButton, False);
|
||||
if (chosen < 0 || chosen >= ndisks) {
|
||||
SetText(title, "Choose a disk");
|
||||
SetText(info, "");
|
||||
BarExpose(bar, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
d = &disks[chosen];
|
||||
Size(d->bytes, size, sizeof size);
|
||||
if (d->parent[0] == '\0')
|
||||
snprintf(text, sizeof text, "%s", d->model[0] != '\0' ?
|
||||
d->model : d->name);
|
||||
else
|
||||
snprintf(text, sizeof text, "%s", d->label[0] != '\0' ?
|
||||
d->label : d->name);
|
||||
SetText(title, text);
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
n += (size_t) snprintf(text + n, sizeof text - n,
|
||||
"Device: /dev/%s\nCapacity: %s\n", d->name, size);
|
||||
if (d->parent[0] != '\0')
|
||||
n += (size_t) snprintf(text + n, sizeof text - n,
|
||||
"On drive: %s\n", d->parent);
|
||||
if (d->fstype[0] != '\0')
|
||||
n += (size_t) snprintf(text + n, sizeof text - n,
|
||||
"File system: %s\n", d->fstype);
|
||||
if (d->mountpoint[0] != '\0') {
|
||||
Size(d->used, used, sizeof used);
|
||||
Size(d->avail, avail, sizeof avail);
|
||||
n += (size_t) snprintf(text + n, sizeof text - n,
|
||||
"Mounted at: %s\nUsed: %s Available: %s\n",
|
||||
d->mountpoint, used, avail);
|
||||
} else if (d->parent[0] != '\0')
|
||||
n += (size_t) snprintf(text + n, sizeof text - n,
|
||||
"Not mounted\n");
|
||||
n += (size_t) snprintf(text + n, sizeof text - n, "%s%s",
|
||||
d->removable ? "Removable\n" : "",
|
||||
d->system ? "Holds the system\n" : "");
|
||||
}
|
||||
SetText(info, text);
|
||||
BarExpose(bar, NULL, NULL);
|
||||
if (isRoot && d->parent[0] != '\0' && !d->system) {
|
||||
XtSetSensitive(mountButton, d->mountpoint[0] == '\0' &&
|
||||
d->fstype[0] != '\0' && strcmp(d->fstype, "swap") != 0);
|
||||
XtSetSensitive(unmountButton, d->mountpoint[0] != '\0');
|
||||
}
|
||||
/* erasing is for a whole drive that is not the system's */
|
||||
XtSetSensitive(eraseButton, isRoot && d->parent[0] == '\0' &&
|
||||
!d->system && d->bytes > 0);
|
||||
SetText(eraseNote, d->parent[0] != '\0' ? "Choose a drive to erase "
|
||||
"it." : d->system ? "This drive holds the system: it is not "
|
||||
"erased." : "Erasing makes one partition over the whole drive; "
|
||||
"all on it is lost.");
|
||||
}
|
||||
|
||||
static void
|
||||
Reload(void)
|
||||
{
|
||||
char text[512], size[32];
|
||||
char keep[32] = "";
|
||||
int i;
|
||||
|
||||
if (chosen >= 0 && chosen < ndisks)
|
||||
snprintf(keep, sizeof keep, "%s", disks[chosen].name);
|
||||
ndisks = mcde_sys_disks(disks, MAX_DISKS);
|
||||
if (ndisks < 0) {
|
||||
ShowStatus(mcde_sys_error());
|
||||
ndisks = 0;
|
||||
}
|
||||
XmListDeleteAllItems(diskList);
|
||||
chosen = -1;
|
||||
for (i = 0; i < ndisks; i++) {
|
||||
XmString s;
|
||||
McdeSysDisk *d = &disks[i];
|
||||
|
||||
Size(d->bytes, size, sizeof size);
|
||||
if (d->parent[0] == '\0')
|
||||
snprintf(text, sizeof text, "%s %s",
|
||||
d->model[0] != '\0' ? d->model : d->name, size);
|
||||
else
|
||||
snprintf(text, sizeof text, " %s %s",
|
||||
d->label[0] != '\0' ? d->label :
|
||||
(d->mountpoint[0] != '\0' ? d->mountpoint :
|
||||
d->name), size);
|
||||
s = XmStringCreateLocalized(text);
|
||||
XmListAddItemUnselected(diskList, s, 0);
|
||||
XmStringFree(s);
|
||||
if (strcmp(d->name, keep) == 0)
|
||||
chosen = i;
|
||||
}
|
||||
if (chosen >= 0)
|
||||
XmListSelectPos(diskList, chosen + 1, False);
|
||||
ShowInfo();
|
||||
}
|
||||
|
||||
static void
|
||||
Chosen(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
chosen = ((XmListCallbackStruct *) call)->item_position - 1;
|
||||
ShowInfo();
|
||||
}
|
||||
|
||||
/* ---- the actions --------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
MountCB(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
char where[300], text[400];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (chosen < 0)
|
||||
return;
|
||||
if (mcde_sys_disk_mount(disks[chosen].name, where, sizeof where) !=
|
||||
MCDE_SYS_OK)
|
||||
Message(mcde_sys_error(), 1);
|
||||
else {
|
||||
snprintf(text, sizeof text, "Mounted at %s.", where);
|
||||
ShowStatus(text);
|
||||
}
|
||||
Reload();
|
||||
}
|
||||
|
||||
static void
|
||||
UnmountCB(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (chosen < 0)
|
||||
return;
|
||||
if (mcde_sys_disk_unmount(disks[chosen].name) != MCDE_SYS_OK)
|
||||
Message(mcde_sys_error(), 1);
|
||||
else
|
||||
ShowStatus("Unmounted.");
|
||||
Reload();
|
||||
}
|
||||
|
||||
static void
|
||||
Report(const char *head, const char *body)
|
||||
{
|
||||
size_t n = strlen(head) + strlen(body) + 4;
|
||||
char *t = malloc(n);
|
||||
|
||||
if (t == NULL)
|
||||
return;
|
||||
snprintf(t, n, "%s\n\n%s", head, body);
|
||||
XmTextSetString(report, t);
|
||||
free(t);
|
||||
}
|
||||
|
||||
static void
|
||||
VerifyDisk(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
static char log[65536];
|
||||
char head[300];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (chosen < 0 || disks[chosen].parent[0] == '\0') {
|
||||
Report("Choose a partition to verify.", "");
|
||||
return;
|
||||
}
|
||||
ShowStatus("Verifying ...");
|
||||
if (mcde_sys_disk_check(disks[chosen].name, log, sizeof log) ==
|
||||
MCDE_SYS_OK)
|
||||
snprintf(head, sizeof head, "%s: no problems found.",
|
||||
disks[chosen].name);
|
||||
else
|
||||
snprintf(head, sizeof head, "%s: %s", disks[chosen].name,
|
||||
mcde_sys_error());
|
||||
Report(head, log);
|
||||
ShowStatus("");
|
||||
}
|
||||
|
||||
static void
|
||||
Permissions(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
static char log[262144];
|
||||
int repair = (int) (intptr_t) data, n;
|
||||
char head[300];
|
||||
|
||||
(void) w;
|
||||
(void) call;
|
||||
ShowStatus(repair ? "Repairing permissions ..." :
|
||||
"Verifying permissions ...");
|
||||
n = mcde_sys_permissions(repair, log, sizeof log);
|
||||
if (n < 0)
|
||||
snprintf(head, sizeof head, "%s", mcde_sys_error());
|
||||
else if (n == 0)
|
||||
snprintf(head, sizeof head, "Every file has the permissions "
|
||||
"it should have.");
|
||||
else
|
||||
snprintf(head, sizeof head, repair ? "%d files were set back:"
|
||||
: "%d files differ:", n);
|
||||
Report(head, n > 0 ? log : "");
|
||||
ShowStatus("");
|
||||
}
|
||||
|
||||
static const char *const fsNames[3] = { "ffs", "msdos", "ext4" };
|
||||
|
||||
static void
|
||||
EraseNow(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
char *name = XmTextFieldGetString(eraseName), part[64], text[400];
|
||||
Widget chosenFs = NULL;
|
||||
int i, fs = 0;
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
XtVaGetValues(eraseFormat, XmNmenuHistory, &chosenFs, NULL);
|
||||
for (i = 0; i < 3; i++)
|
||||
if (fsButtons[i] == chosenFs)
|
||||
fs = i;
|
||||
ShowStatus("Erasing ...");
|
||||
if (mcde_sys_disk_erase(disks[chosen].name, fsNames[fs],
|
||||
name != NULL ? name : "", part, sizeof part) != MCDE_SYS_OK)
|
||||
Message(mcde_sys_error(), 1);
|
||||
else {
|
||||
snprintf(text, sizeof text, "%s is erased: %s, named \"%s\".",
|
||||
disks[chosen].name, part, name);
|
||||
ShowStatus(text);
|
||||
}
|
||||
XtFree(name);
|
||||
Reload();
|
||||
}
|
||||
|
||||
static void
|
||||
EraseAsk(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
Widget d;
|
||||
XmString s, ok;
|
||||
char text[600], size[32];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (chosen < 0)
|
||||
return;
|
||||
Size(disks[chosen].bytes, size, sizeof size);
|
||||
snprintf(text, sizeof text, "Erase %s (%s, %s)?\n\nEverything on "
|
||||
"this drive is lost, every partition and every file. This "
|
||||
"cannot be undone.", disks[chosen].model[0] != '\0' ?
|
||||
disks[chosen].model : disks[chosen].name, disks[chosen].name,
|
||||
size);
|
||||
d = XmCreateWarningDialog(shell, "eraseAsk", NULL, 0);
|
||||
s = XmStringCreateLocalized(text);
|
||||
ok = XmStringCreateLocalized("Erase");
|
||||
XtVaSetValues(d, XmNmessageString, s, XmNokLabelString, ok,
|
||||
XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON, NULL);
|
||||
XmStringFree(s);
|
||||
XmStringFree(ok);
|
||||
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_HELP_BUTTON));
|
||||
XtAddCallback(d, XmNokCallback, EraseNow, NULL);
|
||||
XtManageChild(d);
|
||||
}
|
||||
|
||||
static void
|
||||
RefreshCB(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
Reload();
|
||||
}
|
||||
|
||||
static void
|
||||
Spawn(const char *command)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == 0) {
|
||||
if (fork() == 0) {
|
||||
setsid();
|
||||
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
||||
_exit(127);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
if (pid > 0)
|
||||
(void) waitpid(pid, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
Unlock(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
Spawn("dtterm -title 'Disk Utility' -geometry 70x12 -e su -m root "
|
||||
"-c dtdiskutility");
|
||||
}
|
||||
|
||||
/* ---- the pages ----------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
ShowPage(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
int erase = (int) (intptr_t) data;
|
||||
|
||||
(void) w;
|
||||
if (call != NULL && !((XmToggleButtonCallbackStruct *) call)->set)
|
||||
return;
|
||||
XtUnmanageChild(erase ? pageAid : pageErase);
|
||||
XtManageChild(erase ? pageErase : pageAid);
|
||||
}
|
||||
|
||||
static Widget
|
||||
MakeAid(Widget parent)
|
||||
{
|
||||
Widget page = XtVaCreateWidget("firstAid", xmFormWidgetClass, parent,
|
||||
NULL);
|
||||
Widget row;
|
||||
Arg a[8];
|
||||
int n = 0;
|
||||
|
||||
row = XtVaCreateManagedWidget("buttons", xmRowColumnWidgetClass, page,
|
||||
XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNleftAttachment, XmATTACH_FORM, NULL);
|
||||
(void) Button(row, "Verify Disk", VerifyDisk, NULL);
|
||||
(void) Button(row, "Verify Permissions", Permissions, (XtPointer) 0);
|
||||
XtSetSensitive(Button(row, "Repair Permissions", Permissions,
|
||||
(XtPointer) 1), isRoot);
|
||||
XtSetArg(a[n], XmNeditable, False); n++;
|
||||
XtSetArg(a[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
|
||||
XtSetArg(a[n], XmNcursorPositionVisible, False); n++;
|
||||
XtSetArg(a[n], XmNrows, 12); n++;
|
||||
XtSetArg(a[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(a[n], XmNtopWidget, row); n++;
|
||||
report = XmCreateScrolledText(page, "report", a, n);
|
||||
XtVaSetValues(XtParent(report), XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment,
|
||||
XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, row,
|
||||
NULL);
|
||||
XtManageChild(report);
|
||||
XmTextSetString(report, "Verify Disk looks at the chosen partition "
|
||||
"and changes nothing.\nVerify Permissions compares the system's "
|
||||
"files with the list the system keeps\nof how they should be; "
|
||||
"Repair Permissions sets them back to it.");
|
||||
return page;
|
||||
}
|
||||
|
||||
static Widget
|
||||
MakeErase(Widget parent)
|
||||
{
|
||||
static const char *const fsLabels[3] = {
|
||||
"NetBSD (FFS)", "MS-DOS (FAT32)", "Linux (ext4)"
|
||||
};
|
||||
Widget page = XtVaCreateWidget("erase", xmRowColumnWidgetClass, parent,
|
||||
XmNspacing, 8, NULL);
|
||||
Widget row, pulldown;
|
||||
XmString s;
|
||||
Arg a[2];
|
||||
int i;
|
||||
|
||||
row = XtVaCreateManagedWidget("name", xmRowColumnWidgetClass, page,
|
||||
XmNorientation, XmHORIZONTAL, NULL);
|
||||
(void) Text(row, "label", "Name:");
|
||||
eraseName = XtVaCreateManagedWidget("eraseName",
|
||||
xmTextFieldWidgetClass, row, XmNcolumns, 24, XmNvalue, "Untitled",
|
||||
NULL);
|
||||
pulldown = XmCreatePulldownMenu(page, "formats", NULL, 0);
|
||||
for (i = 0; i < 3; i++) {
|
||||
s = XmStringCreateLocalized((char *) fsLabels[i]);
|
||||
fsButtons[i] = XtVaCreateManagedWidget("format",
|
||||
xmPushButtonWidgetClass, pulldown, XmNlabelString, s, NULL);
|
||||
XmStringFree(s);
|
||||
}
|
||||
s = XmStringCreateLocalized("Format:");
|
||||
XtSetArg(a[0], XmNsubMenuId, pulldown);
|
||||
XtSetArg(a[1], XmNlabelString, s);
|
||||
eraseFormat = XmCreateOptionMenu(page, "format", a, 2);
|
||||
XmStringFree(s);
|
||||
XtManageChild(eraseFormat);
|
||||
eraseNote = Text(page, "note", "");
|
||||
eraseButton = Button(page, "Erase...", EraseAsk, NULL);
|
||||
return page;
|
||||
}
|
||||
|
||||
/* ---- the window ---------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Widget form, toolbar, left, right, tabs, sep, frame;
|
||||
Arg a[10];
|
||||
int n;
|
||||
|
||||
XtSetLanguageProc(NULL, NULL, NULL);
|
||||
shell = XtVaAppInitialize(&app, "Dtdiskutility", NULL, 0, &argc, argv,
|
||||
(String *) fallback, XmNtitle, "Disk Utility", NULL);
|
||||
(void) DtInitialize(XtDisplay(shell), shell, argv[0], "Dtdiskutility");
|
||||
isRoot = geteuid() == 0;
|
||||
|
||||
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, shell,
|
||||
XmNwidth, 760, XmNheight, 520, NULL);
|
||||
toolbar = XtVaCreateManagedWidget("toolbar", xmRowColumnWidgetClass,
|
||||
form, XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
||||
NULL);
|
||||
mountButton = Button(toolbar, "Mount", MountCB, NULL);
|
||||
unmountButton = Button(toolbar, "Unmount", UnmountCB, NULL);
|
||||
(void) Button(toolbar, "Refresh", RefreshCB, NULL);
|
||||
if (!isRoot)
|
||||
(void) Button(toolbar, "Unlock...", Unlock, NULL);
|
||||
|
||||
statusLine = XtVaCreateManagedWidget("status", xmLabelWidgetClass, form,
|
||||
XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNrightAttachment, XmATTACH_FORM, XmNalignment,
|
||||
XmALIGNMENT_BEGINNING, NULL);
|
||||
SetText(statusLine, isRoot ? "" : "Showing and verifying only: "
|
||||
"Unlock... to change disks.");
|
||||
|
||||
n = 0;
|
||||
XtSetArg(a[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
|
||||
XtSetArg(a[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(a[n], XmNtopWidget, toolbar); n++;
|
||||
XtSetArg(a[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(a[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(a[n], XmNbottomWidget, statusLine); n++;
|
||||
diskList = XmCreateScrolledList(form, "disks", a, n);
|
||||
left = XtParent(diskList);
|
||||
XtVaSetValues(left, XmNwidth, 260, NULL);
|
||||
XtManageChild(diskList);
|
||||
XtAddCallback(diskList, XmNbrowseSelectionCallback, Chosen, NULL);
|
||||
|
||||
right = XtVaCreateManagedWidget("right", xmFormWidgetClass, form,
|
||||
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, toolbar,
|
||||
XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, left,
|
||||
XmNleftOffset, 10, XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 6, XmNbottomAttachment, XmATTACH_WIDGET,
|
||||
XmNbottomWidget, statusLine, NULL);
|
||||
title = XtVaCreateManagedWidget("title", xmLabelWidgetClass, right,
|
||||
XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
||||
info = XtVaCreateManagedWidget("info", xmLabelWidgetClass, right,
|
||||
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, title,
|
||||
XmNtopOffset, 6, XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
||||
frame = XtVaCreateManagedWidget("barFrame", xmFrameWidgetClass, right,
|
||||
XmNshadowType, XmSHADOW_IN, XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, info, XmNtopOffset, 6,
|
||||
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNheight, 18, NULL);
|
||||
bar = XtVaCreateManagedWidget("bar", xmDrawingAreaWidgetClass, frame,
|
||||
XmNheight, 14, XmNresizePolicy, XmRESIZE_NONE, NULL);
|
||||
XtAddCallback(bar, XmNexposeCallback, BarExpose, NULL);
|
||||
sep = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, right,
|
||||
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, frame,
|
||||
XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNrightAttachment, XmATTACH_FORM, NULL);
|
||||
tabs = XtVaCreateManagedWidget("tabs", xmRowColumnWidgetClass, right,
|
||||
XmNorientation, XmHORIZONTAL, XmNradioBehavior, True,
|
||||
XmNspacing, 0, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, sep,
|
||||
XmNleftAttachment, XmATTACH_FORM, NULL);
|
||||
tabAid = XtVaCreateManagedWidget("First Aid", xmToggleButtonWidgetClass,
|
||||
tabs, XmNindicatorOn, XmINDICATOR_NONE, XmNshadowThickness, 2,
|
||||
XmNset, True, NULL);
|
||||
tabErase = XtVaCreateManagedWidget("Erase", xmToggleButtonWidgetClass,
|
||||
tabs, XmNindicatorOn, XmINDICATOR_NONE, XmNshadowThickness, 2,
|
||||
NULL);
|
||||
XtAddCallback(tabAid, XmNvalueChangedCallback, ShowPage, (XtPointer) 0);
|
||||
XtAddCallback(tabErase, XmNvalueChangedCallback, ShowPage,
|
||||
(XtPointer) 1);
|
||||
{
|
||||
Widget pages = XtVaCreateManagedWidget("pages",
|
||||
xmFormWidgetClass, right, XmNtopAttachment,
|
||||
XmATTACH_WIDGET, XmNtopWidget, tabs, XmNtopOffset, 6,
|
||||
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment,
|
||||
XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL);
|
||||
|
||||
pageAid = MakeAid(pages);
|
||||
pageErase = MakeErase(pages);
|
||||
XtVaSetValues(pageAid, XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
|
||||
XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL);
|
||||
XtVaSetValues(pageErase, XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNleftAttachment, XmATTACH_FORM, NULL);
|
||||
XtManageChild(pageAid);
|
||||
}
|
||||
{
|
||||
/* the title larger, as the panes of System Settings */
|
||||
XmRendition r;
|
||||
XmRenderTable rt;
|
||||
Arg ra[4];
|
||||
int rn = 0;
|
||||
|
||||
XtSetArg(ra[rn], XmNfontType, XmFONT_IS_XFT); rn++;
|
||||
XtSetArg(ra[rn], XmNfontName, "Hack"); rn++;
|
||||
XtSetArg(ra[rn], XmNfontSize, 14); rn++;
|
||||
XtSetArg(ra[rn], XmNfontStyle, "Bold"); rn++;
|
||||
r = XmRenditionCreate(title, XmFONTLIST_DEFAULT_TAG, ra, rn);
|
||||
rt = XmRenderTableAddRenditions(NULL, &r, 1, XmMERGE_REPLACE);
|
||||
XmRenditionFree(r);
|
||||
XtVaSetValues(title, XmNrenderTable, rt, NULL);
|
||||
XmRenderTableFree(rt);
|
||||
}
|
||||
XtRealizeWidget(shell);
|
||||
Reload();
|
||||
XtAppMainLoop(app);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user