diff --git a/sbin/fsck_ext2fs/setup.c b/sbin/fsck_ext2fs/setup.c index 0c7c0164680..686cbb45fb4 100644 --- a/sbin/fsck_ext2fs/setup.c +++ b/sbin/fsck_ext2fs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.35 2024/12/18 10:36:05 sthen Exp $ */ +/* $OpenBSD: setup.c,v 1.36 2025/09/17 16:07:57 deraadt Exp $ */ /* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */ /* @@ -455,7 +455,7 @@ calcsb(char *dev, int devfd, struct m_ext2fs *fs, struct disklabel *lp) char *cp; cp = strchr(dev, '\0'); - if ((cp == NULL || (cp[-1] < 'a' || cp[-1] >= 'a' + MAXPARTITIONS)) && + if ((cp == NULL || DL_PARTNAME2NUM(cp[-1]) == -1) && !isdigit((unsigned char)cp[-1])) { pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); return (0); @@ -466,7 +466,7 @@ calcsb(char *dev, int devfd, struct m_ext2fs *fs, struct disklabel *lp) if (isdigit((unsigned char)*cp)) pp = &lp->d_partitions[0]; else - pp = &lp->d_partitions[*cp - 'a']; + pp = &lp->d_partitions[DL_PARTNAME2NUM(*cp)]; if (pp->p_fstype != FS_EXT2FS) { pfatal("%s: NOT LABELED AS A EXT2 FILE SYSTEM (%s)\n", dev, pp->p_fstype < FSMAXTYPES ? diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index 72e77f40a78..2f3a500bd75 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.71 2025/02/26 06:18:56 otto Exp $ */ +/* $OpenBSD: setup.c,v 1.72 2025/09/17 16:07:57 deraadt Exp $ */ /* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */ /* @@ -614,7 +614,7 @@ calcsb(char *dev, int devfd, struct fs *fs, struct disklabel *lp, int i; cp = strchr(dev, '\0'); - if ((cp == NULL || (cp[-1] < 'a' || cp[-1] >= 'a' + MAXPARTITIONS)) && + if ((cp == NULL || DL_PARTNAME2NUM(cp[-1]) == -1) && !isdigit((unsigned char)cp[-1])) { pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); return (0); @@ -627,7 +627,7 @@ calcsb(char *dev, int devfd, struct fs *fs, struct disklabel *lp, if (isdigit((unsigned char)*cp)) pp = &lp->d_partitions[0]; else - pp = &lp->d_partitions[*cp - 'a']; + pp = &lp->d_partitions[DL_PARTNAME2NUM(*cp)]; if (pp->p_fstype != FS_BSDFFS) { pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n", dev, pp->p_fstype < FSMAXTYPES ? diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 94c023a3aad..be78f2b40df 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs.c,v 1.119 2025/09/17 10:51:17 deraadt Exp $ */ +/* $OpenBSD: newfs.c,v 1.120 2025/09/17 16:07:57 deraadt Exp $ */ /* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */ /* @@ -424,8 +424,7 @@ main(int argc, char *argv[]) if (*argv[0] == '\0') fatal("empty partition name supplied"); cp = argv[0] + strlen(argv[0]) - 1; - if ((*cp < 'a' || *cp > ('a' + maxpartitions - 1)) - && !isdigit((unsigned char)*cp)) + if (DL_PARTNAME2NUM(*cp) == -1 && !isdigit((unsigned char)*cp)) fatal("%s: can't figure out file system partition", argv[0]); lp = getdisklabel(special, fsi); @@ -436,7 +435,7 @@ main(int argc, char *argv[]) if (isdigit((unsigned char)*cp)) pp = &lp->d_partitions[0]; else - pp = &lp->d_partitions[*cp - 'a']; + pp = &lp->d_partitions[DL_PARTNAME2NUM(*cp)]; if (DL_GETPSIZE(pp) == 0) fatal("%s: `%c' partition is unavailable", argv[0], *cp); diff --git a/sbin/newfs_ext2fs/newfs_ext2fs.c b/sbin/newfs_ext2fs/newfs_ext2fs.c index f7e48286f7c..62b3d6beee9 100644 --- a/sbin/newfs_ext2fs/newfs_ext2fs.c +++ b/sbin/newfs_ext2fs/newfs_ext2fs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs_ext2fs.c,v 1.29 2022/12/04 23:50:47 cheloha Exp $ */ +/* $OpenBSD: newfs_ext2fs.c,v 1.30 2025/09/17 16:07:57 deraadt Exp $ */ /* $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */ /* @@ -478,14 +478,13 @@ getpartition(int fsi, const char *special, char *argv[], struct disklabel **dl) if (*argv[0] == '\0') errx(EXIT_FAILURE, "empty partition name supplied"); cp = argv[0] + strlen(argv[0]) - 1; - if ((*cp < 'a' || *cp > ('a' + getmaxpartitions() - 1)) - && !isdigit((unsigned char)*cp)) + if (DL_PARTNAME2NUM(*cp) == -1 && !isdigit((unsigned char)*cp)) errx(EXIT_FAILURE, "%s: can't figure out file system partition", argv[0]); lp = getdisklabel(special, fsi); if (isdigit((unsigned char)*cp)) pp = &lp->d_partitions[0]; else - pp = &lp->d_partitions[*cp - 'a']; + pp = &lp->d_partitions[DL_PARTNAME2NUM(*cp)]; if (DL_GETPSIZE(pp) == 0) errx(EXIT_FAILURE, "%s: `%c' partition is unavailable", argv[0], *cp); *dl = lp; diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index 0cc837778d8..df3bc1a332b 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs_msdos.c,v 1.29 2024/04/28 16:43:42 florian Exp $ */ +/* $OpenBSD: newfs_msdos.c,v 1.30 2025/09/17 16:07:57 deraadt Exp $ */ /* * Copyright (c) 1998 Robert Nordier @@ -727,9 +727,8 @@ getdiskinfo(int fd, const char *fname, const char *dtype, int oflag, else while (isdigit((unsigned char)*++s2)); s1 = s2; - if (s2 && *s2 >= 'a' && *s2 <= 'a' + MAXPARTITIONS - 1) { - part = *s2++ - 'a'; - } + if (s2) + part = DL_PARTNAME2NUM(*s2++); if (!s2 || (*s2 && *s2 != '.')) errx(1, "%s: can't figure out partition info", fname); if ((((!oflag && part != -1) || !bpb->bsec)) ||