sysutils/e2fsprogs: sync with upstream

Taken from: HardenedBSD
This commit is contained in:
Franco Fichtner 2020-06-23 04:30:57 +02:00
parent 0a5e3096dc
commit 22079cca94
3 changed files with 129 additions and 1 deletions

View File

@ -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/\<dd\>/gdd/" \
${WRKSRC}/tests/[a-z]_*/script
@${REINPLACE_CMD} -e 's/<malloc\.h>/<stdlib.h>/' ${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 \

View File

@ -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 <sys/sysmacros.h>
#endif
#include <time.h>
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#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;
}

View File

@ -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