From 22079cca941d02857377b214960236679c0a7d19 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 23 Jun 2020 04:30:57 +0200 Subject: [PATCH] sysutils/e2fsprogs: sync with upstream Taken from: HardenedBSD --- sysutils/e2fsprogs/Makefile | 3 +- .../e2fsprogs/files/patch-lib_blkid_devname.c | 110 ++++++++++++++++++ .../e2fsprogs/files/patch-misc_blkid.8.in | 17 +++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 sysutils/e2fsprogs/files/patch-lib_blkid_devname.c create mode 100644 sysutils/e2fsprogs/files/patch-misc_blkid.8.in diff --git a/sysutils/e2fsprogs/Makefile b/sysutils/e2fsprogs/Makefile index 70f827b3ff4..e976d8d55dd 100644 --- a/sysutils/e2fsprogs/Makefile +++ b/sysutils/e2fsprogs/Makefile @@ -3,7 +3,7 @@ PORTNAME= e2fsprogs PORTVERSION= 1.45.6 -PORTREVISION?= 2 +PORTREVISION?= 3 CATEGORIES?= sysutils MASTER_SITES= KERNEL_ORG/linux/kernel/people/tytso/${PORTNAME}/v${PORTVERSION} @@ -142,6 +142,7 @@ post-patch:: -e "s/ == 0/ = 0/" -e "s/tar x$$/tar xf -/" -e "s/\/gdd/" \ ${WRKSRC}/tests/[a-z]_*/script @${REINPLACE_CMD} -e 's///' ${WRKSRC}/*/*.c + @${REINPLACE_CMD} -e 's,/etc/blkid.tab,${ETCDIR}/blkid.tab,' ${WRKSRC}/misc/blkid* ${WRKSRC}/lib/blkid/blkidP.h @${REINPLACE_CMD} -E -e 's/__GNUC_PREREQ\>/__GNUC_PREREQ__/' ${WRKSRC}/*/*/*.[ch] ${WRKSRC}/*/*.c .if empty(PORT_OPTIONS:MALLTESTS) . for i in \ diff --git a/sysutils/e2fsprogs/files/patch-lib_blkid_devname.c b/sysutils/e2fsprogs/files/patch-lib_blkid_devname.c new file mode 100644 index 00000000000..220b03b9ba7 --- /dev/null +++ b/sysutils/e2fsprogs/files/patch-lib_blkid_devname.c @@ -0,0 +1,110 @@ +--- lib/blkid/devname.c.orig 2020-03-21 04:24:04 UTC ++++ lib/blkid/devname.c +@@ -40,6 +40,9 @@ + #include + #endif + #include ++#ifdef __FreeBSD__ ++#include ++#endif + + #include "blkidP.h" + +@@ -397,11 +400,15 @@ evms_probe_all(blkid_cache cache, int only_if_new) + static int probe_all(blkid_cache cache, int only_if_new) + { + FILE *proc; ++#ifndef __FreeBSD__ + char line[1024]; ++ int ma, mi; ++#else ++ char *line; ++#endif /* __FreeBSD__ */ + char ptname0[129], ptname1[129], *ptname = 0; + char *ptnames[2]; + dev_t devs[2]; +- int ma, mi; + unsigned long long sz; + int lens[2] = { 0, 0 }; + int which = 0, last = 0; +@@ -423,20 +430,68 @@ static int probe_all(blkid_cache cache, int only_if_ne + lvm_probe_all(cache, only_if_new); + #endif + ++#ifndef __FreeBSD__ + proc = fopen(PROC_PARTITIONS, "r"); + if (!proc) + return -BLKID_ERR_PROC; + + while (fgets(line, sizeof(line), proc)) { ++#else ++ size_t len, bufsiz = 4096; ++ char *buf = NULL; ++ ++ for(;;) { ++ buf = realloc(buf, bufsiz); ++ if (!buf) return -BLKID_ERR_MEM; ++ len = bufsiz - 1; ++ if (sysctlbyname("kern.geom.conftxt", buf, &len, NULL, 0)) { ++ if (ENOMEM != errno) { ++ free(buf); ++ return -BLKID_ERR_IO; ++ } ++ bufsiz <<= 1; ++ } else { ++ if (len < bufsiz) buf[len] = '\0'; ++ else buf[bufsiz - 1] = '\0'; ++ break; ++ } ++ } ++ char *str = buf; ++ while (line = strsep(&str, "\n")) { ++#endif /* __FreeBSD__ */ + last = which; + which ^= 1; + ptname = ptnames[which]; + ++#ifndef __FreeBSD__ + if (sscanf(line, " %d %d %llu %128[^\n ]", + &ma, &mi, &sz, ptname) != 4) + continue; + devs[which] = makedev(ma, mi); ++#else ++ char type[5]; ++ int dummy; + ++ if (sscanf(line, "%*d %5s %128[^ ] %lld %d", ++ type, ptname, &sz, &dummy) != 4) ++ continue; ++ sz /= 1024; ++ ++ if (strcmp("PART", type) && strcmp("DISK", type)) ++ continue; ++ { ++ struct stat st; ++ char dn[128]; ++ if (snprintf(dn, sizeof dn, "/dev/%s", ptname) >= sizeof dn) ++ continue; ++ ++ if (stat(dn, &st)) ++ continue; ++ ++ devs[which] = st.st_rdev; ++ } ++#endif /* __FreeBSD__ */ ++ + DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname)); + + /* Skip whole disk devs unless they have no partitions. +@@ -507,7 +562,11 @@ static int probe_all(blkid_cache cache, int only_if_ne + if (lens[which]) + probe_one(cache, ptname, devs[which], 0, only_if_new); + ++#ifndef __FreeBSD__ + fclose(proc); ++#else ++ free(buf); ++#endif /* __FreeBSD__ */ + blkid_flush_cache(cache); + return 0; + } diff --git a/sysutils/e2fsprogs/files/patch-misc_blkid.8.in b/sysutils/e2fsprogs/files/patch-misc_blkid.8.in new file mode 100644 index 00000000000..c6532a4a1a2 --- /dev/null +++ b/sysutils/e2fsprogs/files/patch-misc_blkid.8.in @@ -0,0 +1,17 @@ +--- misc/blkid.8.in.orig 2020-03-21 04:24:04 UTC ++++ misc/blkid.8.in +@@ -144,10 +144,10 @@ option. + Display tokens from only the specified device. It is possible to + give multiple + .I device +-options on the command line. If none is given, all devices which +-appear in +-.I /proc/partitions +-are shown, if they are recognized. ++options on the command line. If none is given, all DISK and PART devices which ++appear in the ++.I kern.geom.conftxt ++sysctl variable are shown, if they are recognized. + .SH "RETURN CODE" + If the specified token was found, or if any tags were shown from (specified) + devices, 0 is returned. If the specified token was not found, or no