summaryrefslogtreecommitdiff
path: root/usr/src/cmd/devfsadm
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/devfsadm')
-rw-r--r--usr/src/cmd/devfsadm/Makefile.com7
-rw-r--r--usr/src/cmd/devfsadm/devfsadm.c21
-rw-r--r--usr/src/cmd/devfsadm/sensor_link.c79
3 files changed, 99 insertions, 8 deletions
diff --git a/usr/src/cmd/devfsadm/Makefile.com b/usr/src/cmd/devfsadm/Makefile.com
index b446b148ff..cec58108c8 100644
--- a/usr/src/cmd/devfsadm/Makefile.com
+++ b/usr/src/cmd/devfsadm/Makefile.com
@@ -21,7 +21,7 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright (c) 2018, Joyent, Inc.
+# Copyright 2019, Joyent, Inc.
# This target builds both a command (daemon) and various shared objects. This
# isn't a typical target, and the inclusion of both library and command
@@ -71,7 +71,8 @@ LINK_OBJS_CMN = \
dtrace_link.o \
vscan_link.o \
zfs_link.o \
- zut_link.o
+ zut_link.o \
+ sensor_link.o
LINK_OBJS = $(LINK_OBJS_CMN) \
$(LINK_OBJS_$(MACH))
@@ -164,7 +165,7 @@ install: all \
clean:
- $(RM) $(OBJS)
+ $(RM) $(OBJS)
lint: $(DEVFSADM_MOD).ln $(LINT_MODULES)
diff --git a/usr/src/cmd/devfsadm/devfsadm.c b/usr/src/cmd/devfsadm/devfsadm.c
index f81d5b5d67..52f4f4c0da 100644
--- a/usr/src/cmd/devfsadm/devfsadm.c
+++ b/usr/src/cmd/devfsadm/devfsadm.c
@@ -23,6 +23,7 @@
* Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright 2016 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2019, Joyent, Inc.
*/
/*
@@ -2073,6 +2074,16 @@ class_ok(char *class)
return (DEVFSADM_SUCCESS);
}
+ /*
+ * Some create tabs operate on multiple classes of devices because the
+ * kernel doesn't have a good way for a driver to indicate that a
+ * particular minor's class is different from that of the dev_info_t
+ * it belongs to. As such, we'll always fail to match those here.
+ */
+ if (class == NULL) {
+ return (DEVFSADM_FAILURE);
+ }
+
for (i = 0; i < num_classes; i++) {
if (strcmp(class, classes[i]) == 0) {
return (DEVFSADM_SUCCESS);
@@ -3717,10 +3728,10 @@ do_inst_sync(char *filename, char *instfilename)
* safely, the database is flushed to a temporary file, then moved into place.
*
* The following files are used during this process:
- * /etc/path_to_inst: The path_to_inst file
- * /etc/path_to_inst.<pid>: Contains data flushed from the kernel
- * /etc/path_to_inst.old: The backup file
- * /etc/path_to_inst.old.<pid>: Temp file for creating backup
+ * /etc/path_to_inst: The path_to_inst file
+ * /etc/path_to_inst.<pid>: Contains data flushed from the kernel
+ * /etc/path_to_inst.old: The backup file
+ * /etc/path_to_inst.old.<pid>: Temp file for creating backup
*
*/
static void
@@ -7803,7 +7814,7 @@ add_verbose_id(char *mid)
* returns DEVFSADM_TRUE if contents is a minor node in /devices.
* If mn_root is not NULL, mn_root is set to:
* if contents is a /dev node, mn_root = contents
- * OR
+ * OR
* if contents is a /devices node, mn_root set to the '/'
* following /devices.
*/
diff --git a/usr/src/cmd/devfsadm/sensor_link.c b/usr/src/cmd/devfsadm/sensor_link.c
new file mode 100644
index 0000000000..7a2b48af75
--- /dev/null
+++ b/usr/src/cmd/devfsadm/sensor_link.c
@@ -0,0 +1,79 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019, Joyent, Inc.
+ */
+
+/*
+ * Create /devices links for various sensors. The sensor series of node types
+ * all begin with ddi_sensor. After which, there is a series of : delineated
+ * paths in the node type. Those represent the directory under /dev/sensors that
+ * the nodes should ultimately be created.
+ *
+ * For example, ddi_sensor:temperature:cpu would cause us to place the named
+ * minor under /dev/sensors/temperature/cpu/. Currently it is up to drivers to
+ * not conflict in names or if there is a fear of conflicting, make sure their
+ * minor is unique.
+ */
+
+#include <devfsadm.h>
+#include <string.h>
+
+#define SENSORS_BASE "sensors"
+
+static int
+sensor_link(di_minor_t minor, di_node_t node)
+{
+ const char *t, *minor_name, *dir_path = NULL;
+ char *type, *c;
+ char buf[PATH_MAX];
+ size_t len;
+
+ if ((t = di_minor_nodetype(minor)) == NULL) {
+ return (DEVFSADM_CONTINUE);
+ }
+
+ if ((minor_name = di_minor_name(minor)) == NULL) {
+ return (DEVFSADM_CONTINUE);
+ }
+
+ if ((type = strdup(t)) == NULL) {
+ return (DEVFSADM_TERMINATE);
+ }
+
+ while ((c = strchr(type, ':')) != NULL) {
+ if (dir_path == NULL) {
+ dir_path = c + 1;
+ }
+ *c = '/';
+ }
+
+ if (dir_path == NULL || *dir_path == '\0') {
+ len = snprintf(buf, sizeof (buf), "%s/%s", SENSORS_BASE,
+ minor_name);
+ } else {
+ len = snprintf(buf, sizeof (buf), "%s/%s/%s", SENSORS_BASE,
+ dir_path, minor_name);
+ }
+
+ if (len < sizeof (buf)) {
+ (void) devfsadm_mklink(buf, node, minor, 0);
+ }
+
+ free(type);
+ return (DEVFSADM_CONTINUE);
+}
+
+static devfsadm_create_t sensor_create_cbt[] = {
+ { NULL, "ddi_sensor", NULL, TYPE_PARTIAL, ILEVEL_0, sensor_link }
+};
+DEVFSADM_CREATE_INIT_V0(sensor_create_cbt);