Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled

This commit is contained in:
domenico
2025-06-24 14:35:53 +02:00
commit c06fb25d1f
9263 changed files with 1750214 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
#
# Copyright (C) 2006-2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=sysfsutils
PKG_VERSION:=2.1.0
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/linux-diag
PKG_HASH:=e865de2c1f559fff0d3fc936e660c0efaf7afe662064f2fb97ccad1ec28d208a
PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
PKG_CPE_ID:=cpe:/a:sysfsutils_project:sysfsutils
PKG_LICENSE:=LGPL-2.1
PKG_LICENSE_FILES:=COPYING cmd/GPL lib/LGPL
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/libsysfs
SECTION:=libs
CATEGORY:=Libraries
SUBMENU:=Filesystem
TITLE:=Sysfs library
URL:=http://linux-diag.sourceforge.net/Sysfsutils.html
ABI_VERSION:=2
endef
define Package/sysfsutils
SECTION:=utils
CATEGORY:=Utilities
SUBMENU:=Filesystem
DEPENDS:=+libsysfs
TITLE:=System Utilities Based on Sysfs
URL:=http://linux-diag.sourceforge.net/Sysfsutils.html
endef
define Package/libsysfs/description
The library's purpose is to provide a consistant and stable interface for
querying system device information exposed through sysfs.
endef
define Package/sysfsutils/description
A utility built upon libsysfs that lists devices by bus, class, and topology.
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/sysfs $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libsysfs.{a,so*,la} $(1)/usr/lib/
endef
define Package/libsysfs/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libsysfs.so.* $(1)/usr/lib/
endef
define Package/sysfsutils/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/sysfsutils $(1)/etc/init.d/
$(INSTALL_DATA) ./files/sysfs.conf $(1)/etc/
$(INSTALL_DIR) $(1)/etc/sysfs.d
$(INSTALL_DATA) ./files/local.conf $(1)/etc/sysfs.d/
$(INSTALL_DIR) $(1)/usr/bin
$(CP) $(PKG_INSTALL_DIR)/usr/bin/systool $(1)/usr/bin/
endef
define Package/sysfsutils/conffiles
/etc/sysfs.conf
/etc/sysfs.d/local.conf
endef
$(eval $(call BuildPackage,libsysfs))
$(eval $(call BuildPackage,sysfsutils))

View File

@@ -0,0 +1 @@
# local sysctl settings can be stored in this directory

View File

@@ -0,0 +1,22 @@
#
# /etc/sysfs.conf - Configuration file for setting sysfs attributes.
#
# The sysfs mount directory is automatically prepended to the attribute paths.
#
# Syntax:
# attribute = value
# mode attribute = 0600 # (any valid argument for chmod)
# owner attribute = root:wheel # (any valid argument for chown)
#
# Examples:
#
# Always use the powersave CPU frequency governor
# devices/system/cpu/cpu0/cpufreq/scaling_governor = powersave
#
# Use userspace CPU frequency governor and set initial speed
# devices/system/cpu/cpu0/cpufreq/scaling_governor = userspace
# devices/system/cpu/cpu0/cpufreq/scaling_setspeed = 600000
#
# Set permissions of suspend control file
# mode power/state = 0660
# owner power/state = root:power

View File

@@ -0,0 +1,49 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2017 Rodolfo Giometti <giometti@enneenne.com>
#
# Based on Debian's script /etc/init.d/sysfsutils by
# Martin Pitt <mpitt@debian.org>
START=11
load_conffile() {
FILE="$1"
sed 's/#.*$//; /^[[:space:]]*$/d;
s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \
$FILE | {
while read f1 f2 f3; do
if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then
if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then
chmod "$f3" "/sys/$f2"
else
echo "unknown attribute $f2"
fi
elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then
if [ -f "/sys/$f2" ]; then
chown "$f3" "/sys/$f2"
else
echo "unknown attribute $f2"
fi
elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
if [ -f "/sys/$f1" ]; then
# Some fields need a terminating newline, others
# need the terminating newline to be absent :-(
echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
echo "$f2" > "/sys/$f1"
else
echo "unknown attribute $f1"
fi
else
echo "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
exit 1
fi
done
}
}
start() {
for file in /etc/sysfs.conf /etc/sysfs.d/*.conf; do
[ -r "$file" ] || continue
load_conffile "$file"
done
}

View File

@@ -0,0 +1,55 @@
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -22,6 +22,7 @@
*/
#include "libsysfs.h"
#include "sysfs.h"
+#include <mntent.h>
/**
* sysfs_remove_trailing_slash: Removes any trailing '/' in the given path
@@ -53,6 +54,9 @@ int sysfs_get_mnt_path(char *mnt_path, s
{
static char sysfs_path[SYSFS_PATH_MAX] = "";
const char *sysfs_path_env;
+ FILE *mnt;
+ struct mntent *mntent;
+ int ret;
if (len == 0 || mnt_path == NULL)
return -1;
@@ -64,12 +68,31 @@ int sysfs_get_mnt_path(char *mnt_path, s
if (sysfs_path_env != NULL) {
safestrcpymax(mnt_path, sysfs_path_env, len);
sysfs_remove_trailing_slash(mnt_path);
- return 0;
+ } else {
+ safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
}
- safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
}
- return 0;
+ /* check that mount point is indeed mounted */
+ ret = -1;
+ if ((mnt = setmntent(SYSFS_PROC_MNTS, "r")) == NULL) {
+ dprintf("Error getting mount information\n");
+ return -1;
+ }
+ while ((mntent = getmntent(mnt)) != NULL) {
+ if (strcmp(mntent->mnt_type, SYSFS_FSTYPE_NAME) == 0 &&
+ strcmp(mntent->mnt_dir, mnt_path) == 0) {
+ ret = 0;
+ break;
+ }
+ }
+
+ endmntent(mnt);
+
+ if (ret < 0)
+ errno = ENOENT;
+
+ return ret;
}
/**