| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/archive3/public/freebsd-releng-10.4-src/sys/compat/linprocfs/linprocfs.c freebsd-10.4/sys/compat/linprocfs/linprocfs.c |
| --- /var/archive3/public/freebsd-releng-10.4-src/sys/compat/linprocfs/linprocfs.c 2017-09-29 08:19:56.000000000 +0800 |
| +++ freebsd-10.4/sys/compat/linprocfs/linprocfs.c 2022-05-22 23:39:48.863132000 +0800 |
| @@ -39,6 +39,13 @@ |
| * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 |
| */ |
| |
| +#include "linprocfs_version.h" |
| +#ifndef LINPROCFS_VERSION |
| +#define LINPROCFS_VERSION LINRPOCFS_VERSION_BUILD_VERSION " " LINPROCFS_VERSION_BUILD_TIME |
| +#endif |
| + |
| +#define _NO_CONVERT_IFNAME 1 |
| + |
| #include <sys/cdefs.h> |
| __FBSDID("$FreeBSD: releng/10.4/sys/compat/linprocfs/linprocfs.c 299221 2016-05-07 19:05:39Z dchagin $"); |
| |
| @@ -119,6 +126,13 @@ |
| #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ |
| #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000) |
| |
| +static SYSCTL_NODE(_vfs, OID_AUTO, linprocfs, CTLFLAG_RW, 0, "Linux procfs"); |
| + |
| +int compatible_unit_prefix = 1; |
| +SYSCTL_INT(_vfs_linprocfs, OID_AUTO, compatible_unit_prefix, CTLFLAG_RW, |
| + &compatible_unit_prefix, 0, |
| + "use Linux-compatible (but incorrect) unit prefix names for byte values"); |
| + |
| /** |
| * @brief Mapping of ki_stat in struct kinfo_proc to the linux state |
| * |
| @@ -133,7 +147,7 @@ |
| * This character array is used with ki_stati-1 as an index and tries to |
| * map our states to suitable linux states. |
| */ |
| -static char linux_state[] = "RRSTZDD"; |
| +static char linux_state[] = "RRSTZID"; |
| |
| /* |
| * Filler function for proc/meminfo |
| @@ -152,18 +166,14 @@ |
| vm_object_t object; |
| int i, j; |
| |
| + const char *kibibyte_name = compatible_unit_prefix ? "kB" : "KiB"; |
| + |
| memtotal = physmem * PAGE_SIZE; |
| /* |
| - * The correct thing here would be: |
| - * |
| memfree = cnt.v_free_count * PAGE_SIZE; |
| memused = memtotal - memfree; |
| - * |
| - * but it might mislead linux binaries into thinking there |
| - * is very little memory left, so we cheat and tell them that |
| - * all memory that isn't wired down is free. |
| */ |
| - memused = cnt.v_wire_count * PAGE_SIZE; |
| + memused = (cnt.v_active_count + cnt.v_wire_count + cnt.v_cache_count) * PAGE_SIZE; |
| memfree = memtotal - memused; |
| swap_pager_status(&i, &j); |
| swaptotal = (unsigned long long)i * PAGE_SIZE; |
| @@ -171,9 +181,11 @@ |
| swapfree = swaptotal - swapused; |
| memshared = 0; |
| mtx_lock(&vm_object_list_mtx); |
| - TAILQ_FOREACH(object, &vm_object_list, object_list) |
| - if (object->shadow_count > 1) |
| + TAILQ_FOREACH(object, &vm_object_list, object_list) { |
| + if (object->shadow_count > 1) { |
| memshared += object->resident_page_count; |
| + } |
| + } |
| mtx_unlock(&vm_object_list_mtx); |
| memshared *= PAGE_SIZE; |
| /* |
| @@ -191,18 +203,26 @@ |
| " total: used: free: shared: buffers: cached:\n" |
| "Mem: %lu %lu %lu %lu %lu %lu\n" |
| "Swap: %llu %llu %llu\n" |
| - "MemTotal: %9lu kB\n" |
| - "MemFree: %9lu kB\n" |
| - "MemShared:%9lu kB\n" |
| - "Buffers: %9lu kB\n" |
| - "Cached: %9lu kB\n" |
| - "SwapTotal:%9llu kB\n" |
| - "SwapFree: %9llu kB\n", |
| + "MemTotal: %9lu %s\n" |
| + "MemFree: %9lu %s\n" |
| + "MemShared:%9lu %s\n" |
| + "Buffers: %9lu %s\n" |
| + "Cached: %9lu %s\n" |
| + "SwapTotal:%9llu %s\n" |
| + "SwapFree: %9llu %s\n" |
| + "Active: %9lu %s\n" |
| + "Inactive: %9lu %s\n", |
| memtotal, memused, memfree, memshared, buffers, cached, |
| swaptotal, swapused, swapfree, |
| - B2K(memtotal), B2K(memfree), |
| - B2K(memshared), B2K(buffers), B2K(cached), |
| - B2K(swaptotal), B2K(swapfree)); |
| + B2K(memtotal), kibibyte_name, |
| + B2K(memfree), kibibyte_name, |
| + B2K(memshared), kibibyte_name, |
| + B2K(buffers), kibibyte_name, |
| + B2K(cached), kibibyte_name, |
| + B2K(swaptotal), kibibyte_name, |
| + B2K(swapfree), kibibyte_name, |
| + P2K((unsigned long int)cnt.v_active_count), kibibyte_name, |
| + P2K((unsigned long int)cnt.v_inactive_count), kibibyte_name); |
| |
| return (0); |
| } |
| @@ -350,26 +370,24 @@ |
| /* determine mount point */ |
| mntto = mp->mnt_stat.f_mntonname; |
| if (strncmp(mntto, lep, lep_len) == 0 && |
| - mntto[lep_len] == '/') |
| + mntto[lep_len] == '/') { |
| mntto += lep_len; |
| + } |
| |
| /* determine fs type */ |
| fstype = mp->mnt_stat.f_fstypename; |
| - if (strcmp(fstype, pn->pn_info->pi_name) == 0) |
| - mntfrom = fstype = "proc"; |
| - else if (strcmp(fstype, "procfs") == 0) |
| + if (strcmp(fstype, pn->pn_info->pi_name) == 0) { |
| + fstype = "proc"; |
| + } else if (strcmp(fstype, "procfs") == 0) { |
| continue; |
| - |
| - if (strcmp(fstype, "linsysfs") == 0) { |
| - sbuf_printf(sb, "/sys %s sysfs %s", mntto, |
| - mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); |
| - } else { |
| + } else if(strcmp(fstype, "linsysfs") == 0) { |
| + fstype = "sysfs"; |
| + } else if (strcmp(fstype, "msdosfs") == 0) { |
| /* For Linux msdosfs is called vfat */ |
| - if (strcmp(fstype, "msdosfs") == 0) |
| - fstype = "vfat"; |
| - sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype, |
| - mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); |
| + fstype = "vfat"; |
| } |
| + sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype, |
| + mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); |
| #define ADD_OPTION(opt, name) \ |
| if (mp->mnt_stat.f_flags & (opt)) sbuf_printf(sb, "," name); |
| ADD_OPTION(MNT_SYNCHRONOUS, "sync"); |
| @@ -541,7 +559,8 @@ |
| sbuf_printf(sb, "%s%s", cp1, cp2 + 1); |
| else |
| #endif |
| - sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); |
| + // sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); |
| + sbuf_cat(sb, LINPROCFS_VERSION); |
| } |
| |
| /* |
| @@ -566,7 +585,8 @@ |
| sbuf_cat(sb, builder); |
| else |
| #endif |
| - sbuf_cat(sb, "des@freebsd.org"); |
| + // sbuf_cat(sb, "des@freebsd.org"); |
| + sbuf_cat(sb, LINPROCFS_VERSION_BUILD_BY); |
| } |
| |
| /* |
| @@ -642,8 +662,10 @@ |
| kp.ki_stat, sizeof(linux_state)); |
| ++ratelimit; |
| } |
| - } else |
| - state = linux_state[kp.ki_stat - 1]; |
| + } else { |
| + state = kp.ki_stat == SRUN ? |
| + ((kp.ki_tdflags & TDF_SINTR) ? 'S' : 'D') : linux_state[kp.ki_stat - 1]; |
| + } |
| PS_ADD("state", "%c", state); |
| PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); |
| PS_ADD("pgrp", "%d", p->p_pgid); |
| @@ -1096,6 +1118,7 @@ |
| return (error); |
| } |
| |
| +#ifndef _NO_CONVERT_IFNAME |
| /* |
| * Criteria for interface name translation |
| */ |
| @@ -1124,6 +1147,7 @@ |
| |
| return (0); |
| } |
| +#endif |
| |
| /* |
| * Filler function for proc/net/dev |
| @@ -1131,7 +1155,9 @@ |
| static int |
| linprocfs_donetdev(PFS_FILL_ARGS) |
| { |
| +#ifndef _NO_CONVERT_IFNAME |
| char ifname[16]; /* XXX LINUX_IFNAMSIZ */ |
| +#endif |
| struct ifnet *ifp; |
| |
| sbuf_printf(sb, "%6s|%58s|%s\n" |
| @@ -1144,8 +1170,12 @@ |
| CURVNET_SET(TD_TO_VNET(curthread)); |
| IFNET_RLOCK(); |
| TAILQ_FOREACH(ifp, &V_ifnet, if_link) { |
| +#ifdef _NO_CONVERT_IFNAME |
| + sbuf_printf(sb, "%6.6s: ", ifp->if_xname); |
| +#else |
| linux_ifname(ifp, ifname, sizeof ifname); |
| sbuf_printf(sb, "%6.6s: ", ifname); |
| +#endif |
| sbuf_printf(sb, "%7lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu ", |
| ifp->if_ibytes, /* rx_bytes */ |
| ifp->if_ipackets, /* rx_packets */ |
| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/archive3/public/freebsd-releng-10.4-src/sys/modules/linprocfs/Makefile freebsd-10.4/sys/modules/linprocfs/Makefile |
| --- /var/archive3/public/freebsd-releng-10.4-src/sys/modules/linprocfs/Makefile 2017-09-29 08:19:59.000000000 +0800 |
| +++ freebsd-10.4/sys/modules/linprocfs/Makefile 2019-08-17 22:23:56.243622065 +0800 |
| @@ -5,6 +5,12 @@ |
| KMOD= linprocfs |
| SRCS= vnode_if.h \ |
| device_if.h bus_if.h \ |
| - linprocfs.c |
| + linprocfs.c \ |
| + linprocfs_version.h |
| + |
| +CLEANFILES += linprocfs_version.h .linprocfs_build_version |
| + |
| +linprocfs_version.h: generate-linprocfs-version.sh linprocfs.c |
| + sh ${.CURDIR}/generate-linprocfs-version.sh > $@ |
| |
| .include <bsd.kmod.mk> |
| --- /dev/null 2019-08-17 22:27:18.000000000 +0800 |
| +++ freebsd-10.4/sys/modules/linprocfs/generate-linprocfs-version.sh 2019-08-17 22:24:15.370617775 +0800 |
| @@ -0,0 +1,13 @@ |
| +#!/bin/sh |
| + |
| +export LANG=C |
| +if [ -f .linprocfs_build_version ]; then |
| + build_version="`cat .linprocfs_build_version`" |
| +else |
| + build_version=1 |
| +fi |
| +printf '#define LINRPOCFS_VERSION_BUILD_VERSION "#%s"\n' "$build_version" |
| +printf '#define LINPROCFS_VERSION_BUILD_TIME "%s"\n' "`date`" |
| +printf '#define LINPROCFS_VERSION LINRPOCFS_VERSION_BUILD_VERSION " " LINPROCFS_VERSION_BUILD_TIME\n' |
| +printf '#define LINPROCFS_VERSION_BUILD_BY "%s@%s"\n' "`whoami`" "`hostname`" |
| +echo $((build_version+1)) > .linprocfs_build_version |