commit 7617251

chld  ·  2026-03-22 17:56:14 +0000 UTC
parent 8a2d575
create a devmajor for freebsd
1 files changed,  +78, -0
+78, -0
 1@@ -0,0 +1,78 @@
 2+/* swc: launch/devmajor-freebsd.c
 3+ *
 4+ * Copyright (c) 2020 Nia Alarie
 5+ * Copyright (c) 2026 uint
 6+ * Copyright (c) 2026 chld
 7+ *
 8+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 9+ * of this software and associated documentation files (the "Software"), to deal
10+ * in the Software without restriction, including without limitation the rights
11+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+ * copies of the Software, and to permit persons to whom the Software is
13+ * furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+ * SOFTWARE.
25+ */
26+#include "devmajor.h"
27+#include <stdlib.h>
28+#include <string.h>
29+#include <sys/stat.h>
30+
31+static bool
32+devname_is(dev_t rdev, const char *prefix)
33+{
34+	const char *name;
35+	size_t len;
36+
37+	name = devname(rdev, S_IFCHR);
38+	if (!name || name[0] == '?' || name[1] == '?') {
39+		return false;
40+	}
41+
42+	len = strlen(prefix);
43+	return strncmp(name, prefix, len) == 0;
44+}
45+
46+bool
47+device_is_input(dev_t rdev)
48+{
49+	if (devname_is(rdev, "input/event")) {
50+		return true;
51+	}
52+	if (devname_is(rdev, "kbd")) {
53+		return true;
54+	}
55+	if (devname_is(rdev, "mouse")) {
56+		return true;
57+	}
58+	return false;
59+}
60+
61+bool
62+device_is_tty(dev_t rdev)
63+{
64+	return devname_is(rdev, "ttyv");
65+}
66+
67+bool
68+device_is_drm(dev_t rdev)
69+{
70+	const char *n;
71+
72+	n = devname(rdev, S_IFCHR);
73+	if (!n || n[0] == '?' || n[0] == '#') {
74+		return false;
75+	}
76+
77+	return strncmp(n, "drm", 3) == 0 || strncmp(n, "dri/card", 8) == 0 ||
78+	       strncmp(n, "dri/renderD", 11) == 0;
79+}