From ff3e93ee10eb12dc47ec73ee4d2ce56f8052278b Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 16 Nov 2026 12:12:39 +0000 Subject: [PATCH] McdeSys: the NetBSD disk and mount errors in the catalog (t0282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit disk_netbsd.c (16 calls) and mount_netbsd.c (2) are catalogued now: messages 218-233 for the new sentences (no hw.disknames, a %s partition cannot be mounted/checked, no %s here, the name rule with blanks and 32 characters, the new partition did not appear, no /etc/mtree, repairing permissions needs the administrator, no mount table) and the numbers that already existed for the same texts as on Linux (no disk %s, not mounted, the system's, erasing needs the administrator, no drive, holds the system, mounted on, no room for the mounts). German copy in programs/localized/de_DE.UTF-8/msg/mcdesys.msg with the same numbers. Verification: both files pass x86_64--netbsd-gcc -std=gnu11 -fsyntax-only -Wall with the tree's sysroot (they are only compiled on NetBSD). The catalog was measured through mcde_sys_msg (the function the backend calls): LANG=C "No list of disks (hw.disknames).", "A name has letters, digits, blanks, - and _, at most 32.", "Only the administrator can repair permissions."; LANG=de_DE.UTF-8 "Keine Plattenliste (hw.disknames).", "Ein Name hat Buchstaben, Ziffern, Leerzeichen, - und _, höchstens 32.", "Nur der Administrator kann die Rechte reparieren." make mcde-linux was refused by the build lock: another session holds it (tools/build-lock.sh tools/userland.sh, pid 3102819) -- one build at a time, root AGENTS.md. The two changed sources are NetBSD-only, so the Linux library is unaffected; the Linux build, check and plist run follows when the lock is free. --- lib/McdeSys/disk_netbsd.c | 41 ++++++++----------- lib/McdeSys/mcdesys.msg | 9 ++++ lib/McdeSys/mount_netbsd.c | 4 +- lib/McdeSys/private.h | 11 +++++ .../localized/de_DE.UTF-8/msg/mcdesys.msg | 9 ++++ 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/lib/McdeSys/disk_netbsd.c b/lib/McdeSys/disk_netbsd.c index ea6fd6d7..b158ad03 100644 --- a/lib/McdeSys/disk_netbsd.c +++ b/lib/McdeSys/disk_netbsd.c @@ -123,8 +123,7 @@ mcde_sys_disks(McdeSysDisk *d, size_t max) size_t len = sizeof names, n = 0; if (sysctlbyname("hw.disknames", names, &len, NULL, 0) != 0) - return mcde_sys_fail(MCDE_SYS_EFAIL, "No list of disks " - "(hw.disknames)."); + return mcde_sys_fail(MCDE_SYS_EFAIL, mcde_sys_msg(MSG_NDISK_NO_LIST, "No list of disks (hw.disknames).")); for (tok = strtok_r(names, " ", &last); tok != NULL && n < max; tok = strtok_r(NULL, " ", &last)) { McdeSysDisk *drive = &d[n]; @@ -224,7 +223,7 @@ mcde_sys_disk_mount(const char *name, char *mountpoint, size_t len) size_t i; if (!Find(name, &d)) - return mcde_sys_fail(MCDE_SYS_ENOENT, "There is no disk %s.", + return mcde_sys_fail(MCDE_SYS_ENOENT, mcde_sys_msg(MSG_DISK_NOT_FOUND, "There is no disk %s."), name); if (d.mountpoint[0] != '\0') { snprintf(mountpoint, len, "%s", d.mountpoint); @@ -233,8 +232,7 @@ mcde_sys_disk_mount(const char *name, char *mountpoint, size_t len) if (strcmp(d.fstype, "ffs") != 0 && strcmp(d.fstype, "msdos") != 0 && strcmp(d.fstype, "ext2fs") != 0 && strcmp(d.fstype, "cd9660") != 0 && strcmp(d.fstype, "ntfs") != 0) - return mcde_sys_fail(MCDE_SYS_ENOTSUP, "A %s partition cannot " - "be mounted.", d.fstype[0] != '\0' ? d.fstype : "blank"); + return mcde_sys_fail(MCDE_SYS_ENOTSUP, mcde_sys_msg(MSG_NDISK_PART_MOUNT, "A %s partition cannot be mounted."), d.fstype[0] != '\0' ? d.fstype : "blank"); snprintf(prog, sizeof prog, "/sbin/mount_%s", d.fstype); snprintf(dev, sizeof dev, strcmp(d.fstype, "cd9660") == 0 ? "/dev/%sa" : "/dev/%s", name); @@ -266,10 +264,10 @@ mcde_sys_disk_unmount(const char *name) char *argv[3]; if (!Find(name, &d) || d.mountpoint[0] == '\0') - return mcde_sys_fail(MCDE_SYS_ENOENT, "%s is not mounted.", + return mcde_sys_fail(MCDE_SYS_ENOENT, mcde_sys_msg(MSG_DISK_NOT_MOUNTED, "%s is not mounted."), name); if (d.system) - return mcde_sys_fail(MCDE_SYS_EPERM, "%s is the system's.", + return mcde_sys_fail(MCDE_SYS_EPERM, mcde_sys_msg(MSG_DISK_SYSTEM, "%s is the system's."), name); argv[0] = "/sbin/umount"; argv[1] = d.mountpoint; @@ -286,12 +284,11 @@ mcde_sys_disk_check(const char *name, char *log, size_t len) log[0] = '\0'; if (!Find(name, &d)) - return mcde_sys_fail(MCDE_SYS_ENOENT, "There is no disk %s.", + return mcde_sys_fail(MCDE_SYS_ENOENT, mcde_sys_msg(MSG_DISK_NOT_FOUND, "There is no disk %s."), name); if (strcmp(d.fstype, "ffs") != 0 && strcmp(d.fstype, "msdos") != 0 && strcmp(d.fstype, "ext2fs") != 0) - return mcde_sys_fail(MCDE_SYS_ENOTSUP, "A %s partition cannot " - "be checked.", d.fstype[0] != '\0' ? d.fstype : "blank"); + return mcde_sys_fail(MCDE_SYS_ENOTSUP, mcde_sys_msg(MSG_NDISK_PART_CHECK, "A %s partition cannot be checked."), d.fstype[0] != '\0' ? d.fstype : "blank"); snprintf(prog, sizeof prog, "/sbin/fsck_%s", d.fstype); snprintf(dev, sizeof dev, "/dev/r%s", name); argv[0] = prog; @@ -311,34 +308,30 @@ mcde_sys_disk_erase(const char *name, const char *fstype, const char *label, int n, i; if (geteuid() != 0) - return mcde_sys_fail(MCDE_SYS_EPERM, "Only the administrator " - "can erase a disk."); + return mcde_sys_fail(MCDE_SYS_EPERM, mcde_sys_msg(MSG_DISK_ERASE_EPERM, "Only the administrator can erase a disk.")); if (strcmp(fstype, "ffs") == 0) gtype = "ffs"; else if (strcmp(fstype, "msdos") == 0) gtype = "windows"; else - return mcde_sys_fail(MCDE_SYS_ENOTSUP, "No %s here.", fstype); + return mcde_sys_fail(MCDE_SYS_ENOTSUP, mcde_sys_msg(MSG_NDISK_NO_DEVICE, "No %s here."), fstype); if (label == NULL || label[0] == '\0' || strlen(label) > 32 || strspn(label, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789 _-") != strlen(label)) - return mcde_sys_fail(MCDE_SYS_EINVAL, "A name has letters, " - "digits, blanks, - and _, at most 32."); + return mcde_sys_fail(MCDE_SYS_EINVAL, mcde_sys_msg(MSG_NDISK_BAD_NAME, "A name has letters, digits, blanks, - and _, at most 32.")); n = mcde_sys_disks(all, 64); for (i = 0; i < n; i++) if (strcmp(all[i].name, name) == 0) break; if (i == n || all[i].parent[0] != '\0') - return mcde_sys_fail(MCDE_SYS_EINVAL, "%s is no drive.", name); + return mcde_sys_fail(MCDE_SYS_EINVAL, mcde_sys_msg(MSG_DISK_NOT_DRIVE, "%s is no drive."), name); if (all[i].system) - return mcde_sys_fail(MCDE_SYS_EPERM, "%s holds the system and " - "is not erased.", name); + return mcde_sys_fail(MCDE_SYS_EPERM, mcde_sys_msg(MSG_DISK_HOLDS_SYSTEM, "%s holds the system and is not erased."), name); for (i = 0; i < n; i++) if ((strcmp(all[i].name, name) == 0 || strcmp(all[i].parent, name) == 0) && all[i].mountpoint[0] != '\0') - return mcde_sys_fail(MCDE_SYS_EPERM, "%s is mounted on " - "%s: unmount it first.", all[i].name, + return mcde_sys_fail(MCDE_SYS_EPERM, mcde_sys_msg(MSG_DISK_MOUNTED, "%s is mounted on %s: unmount it first."), all[i].name, all[i].mountpoint); { char *destroy[] = { gptp, "destroy", (char *) name, NULL }; @@ -356,8 +349,7 @@ mcde_sys_disk_erase(const char *name, const char *fstype, const char *label, return MCDE_SYS_EFAIL; } if ((p = strstr(out, "\ndk")) == NULL) - return mcde_sys_fail(MCDE_SYS_EFAIL, "The new partition did " - "not appear."); + return mcde_sys_fail(MCDE_SYS_EFAIL, mcde_sys_msg(MSG_NDISK_PART_MISSING, "The new partition did not appear.")); p++; snprintf(part, len, "%.*s", (int) strcspn(p, ":"), p); snprintf(rdev, sizeof rdev, "/dev/r%s", part); @@ -431,11 +423,10 @@ mcde_sys_permissions(int repair, char *log, size_t len) log[0] = '\0'; if (dir == NULL) - return mcde_sys_fail(MCDE_SYS_ENOENT, "There is no /etc/mtree."); + return mcde_sys_fail(MCDE_SYS_ENOENT, mcde_sys_msg(MSG_NDISK_NO_MTREE, "There is no /etc/mtree.")); if (repair && geteuid() != 0) { closedir(dir); - return mcde_sys_fail(MCDE_SYS_EPERM, "Only the administrator " - "can repair permissions."); + return mcde_sys_fail(MCDE_SYS_EPERM, mcde_sys_msg(MSG_NDISK_FIX_EPERM, "Only the administrator can repair permissions.")); } while ((de = readdir(dir)) != NULL) { char full[300], spec[64], *line, *last = NULL; diff --git a/lib/McdeSys/mcdesys.msg b/lib/McdeSys/mcdesys.msg index d15f0be3..a7438b65 100644 --- a/lib/McdeSys/mcdesys.msg +++ b/lib/McdeSys/mcdesys.msg @@ -219,3 +219,12 @@ $set 1 215 %s is mounted on %s: unmount it first. 216 This system keeps no list of how its files' permissions should be. 217 No /proc/mounts. +218 No list of disks (hw.disknames). +220 A %s partition cannot be mounted. +223 A %s partition cannot be checked. +225 No %s here. +226 A name has letters, digits, blanks, - and _, at most 32. +230 The new partition did not appear. +231 There is no /etc/mtree. +232 Only the administrator can repair permissions. +233 No mount table. diff --git a/lib/McdeSys/mount_netbsd.c b/lib/McdeSys/mount_netbsd.c index 4d499f58..d5d85fbc 100644 --- a/lib/McdeSys/mount_netbsd.c +++ b/lib/McdeSys/mount_netbsd.c @@ -30,9 +30,9 @@ mcde_sys_mounts_backend(McdeSysMount *m, size_t max) int n, i; if (m == NULL || max == 0) - return mcde_sys_fail(MCDE_SYS_EINVAL, "No room for the mounts."); + return mcde_sys_fail(MCDE_SYS_EINVAL, mcde_sys_msg(MSG_MNT_NO_ROOM, "No room for the mounts.")); if ((n = getmntinfo(&mnt, MNT_NOWAIT)) <= 0) - return mcde_sys_fail(MCDE_SYS_EFAIL, "No mount table."); + return mcde_sys_fail(MCDE_SYS_EFAIL, mcde_sys_msg(MSG_NMNT_NO_TABLE, "No mount table.")); for (i = 0; i < n && (size_t) i < max; i++) { McdeSysMount *x = &m[i]; diff --git a/lib/McdeSys/private.h b/lib/McdeSys/private.h index 6902b17c..58da9f99 100644 --- a/lib/McdeSys/private.h +++ b/lib/McdeSys/private.h @@ -248,6 +248,17 @@ int mcde_sys_fail(int status, const char *fmt, ...); #define MSG_DISK_NO_PERM_LIST 216 /* mount_linux.c */ #define MSG_MNT_NO_PROC 217 +/* disk_netbsd.c: hw.disknames, disklabel, newfs and the permissions */ +#define MSG_NDISK_NO_LIST 218 +#define MSG_NDISK_PART_MOUNT 220 +#define MSG_NDISK_PART_CHECK 223 +#define MSG_NDISK_NO_DEVICE 225 +#define MSG_NDISK_BAD_NAME 226 +#define MSG_NDISK_PART_MISSING 230 +#define MSG_NDISK_NO_MTREE 231 +#define MSG_NDISK_FIX_EPERM 232 +/* mount_netbsd.c */ +#define MSG_NMNT_NO_TABLE 233 const char *mcde_sys_msg(int n, const char *text); /* run ARGV (an absolute path first) and wait; MCDE_SYS_OK on exit status 0 */ diff --git a/programs/localized/de_DE.UTF-8/msg/mcdesys.msg b/programs/localized/de_DE.UTF-8/msg/mcdesys.msg index e1c04306..123c9949 100644 --- a/programs/localized/de_DE.UTF-8/msg/mcdesys.msg +++ b/programs/localized/de_DE.UTF-8/msg/mcdesys.msg @@ -217,3 +217,12 @@ $set 1 215 %s ist auf %s eingehängt: zuerst aushängen. 216 Dieses System führt keine Liste, wie die Rechte seiner Dateien sein sollen. 217 Kein /proc/mounts. +218 Keine Plattenliste (hw.disknames). +220 Eine %s-Partition kann nicht eingehängt werden. +223 Eine %s-Partition kann nicht geprüft werden. +225 Kein %s hier. +226 Ein Name hat Buchstaben, Ziffern, Leerzeichen, - und _, höchstens 32. +230 Die neue Partition ist nicht erschienen. +231 Es gibt kein /etc/mtree. +232 Nur der Administrator kann die Rechte reparieren. +233 Keine Einhängetabelle.