ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/package/libs/sysfsutils/Makefile b/package/libs/sysfsutils/Makefile
new file mode 100644
index 0000000..61dbc6e
--- /dev/null
+++ b/package/libs/sysfsutils/Makefile
@@ -0,0 +1,88 @@
+#
+# 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
+PKG_BUILD_PARALLEL:=0
+
+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))
diff --git a/package/libs/sysfsutils/files/local.conf b/package/libs/sysfsutils/files/local.conf
new file mode 100644
index 0000000..891da73
--- /dev/null
+++ b/package/libs/sysfsutils/files/local.conf
@@ -0,0 +1 @@
+# local sysctl settings can be stored in this directory
diff --git a/package/libs/sysfsutils/files/sysfs.conf b/package/libs/sysfsutils/files/sysfs.conf
new file mode 100644
index 0000000..f032462
--- /dev/null
+++ b/package/libs/sysfsutils/files/sysfs.conf
@@ -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
diff --git a/package/libs/sysfsutils/files/sysfsutils b/package/libs/sysfsutils/files/sysfsutils
new file mode 100644
index 0000000..3c5b35e
--- /dev/null
+++ b/package/libs/sysfsutils/files/sysfsutils
@@ -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
+}
diff --git a/package/libs/sysfsutils/patches/200-mnt_path_check.patch b/package/libs/sysfsutils/patches/200-mnt_path_check.patch
new file mode 100644
index 0000000..8710578
--- /dev/null
+++ b/package/libs/sysfsutils/patches/200-mnt_path_check.patch
@@ -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;
+ }
+
+ /**