git: e02d4fab5453 - main - kdump: Add support for decoding inotify events

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 04 Jul 2025 14:56:00 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=e02d4fab54539a5d127c12e9e9f8b0ddd2a1cafa

commit e02d4fab54539a5d127c12e9e9f8b0ddd2a1cafa
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-07-03 19:53:30 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-07-04 14:42:33 +0000

    kdump: Add support for decoding inotify events
    
    These are emitted when reading from an inotify descriptor.
    
    MFC after:      3 months
    Sponsored by:   Klara, Inc.
---
 usr.bin/kdump/kdump.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 9cc22d382de5..17ed43b55c5a 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -46,6 +46,7 @@
 #include <sys/ktrace.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#include <sys/inotify.h>
 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -105,6 +106,7 @@ static void ktrcsw(struct ktr_csw *);
 static void ktrcsw_old(struct ktr_csw_old *);
 static void ktruser(int, void *);
 static void ktrcaprights(cap_rights_t *);
+static void ktrinotify(struct inotify_event *);
 static void ktritimerval(struct itimerval *it);
 static void ktrsockaddr(struct sockaddr *);
 static void ktrsplice(struct splice *);
@@ -1860,6 +1862,14 @@ ktrtimeval(struct timeval *tv)
 	printf("{%ld, %ld}", (long)tv->tv_sec, tv->tv_usec);
 }
 
+static void
+ktrinotify(struct inotify_event *ev)
+{
+	printf(
+    "inotify { .wd = %d, .mask = %#x, .cookie = %u, .len = %u, .name = %s }\n",
+	    ev->wd, ev->mask, ev->cookie, ev->len, ev->name);
+}
+
 static void
 ktritimerval(struct itimerval *it)
 {
@@ -2128,6 +2138,17 @@ ktrstruct(char *buf, size_t buflen)
 			goto invalid;
 		memcpy(&rights, data, datalen);
 		ktrcaprights(&rights);
+	} else if (strcmp(name, "inotify") == 0) {
+		struct inotify_event *ev;
+
+		if (datalen < sizeof(struct inotify_event) ||
+		    datalen > sizeof(struct inotify_event) + NAME_MAX + 1)
+			goto invalid;
+		ev = malloc(datalen);
+		if (ev == NULL)
+			err(1, "malloc");
+		memcpy(ev, data, datalen);
+		ktrinotify(ev);
 	} else if (strcmp(name, "itimerval") == 0) {
 		if (datalen != sizeof(struct itimerval))
 			goto invalid;