Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161659208
D51559.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D51559.diff
View Options
diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h
--- a/sys/compat/linuxkpi/common/include/linux/printk.h
+++ b/sys/compat/linuxkpi/common/include/linux/printk.h
@@ -50,6 +50,12 @@
const char *, const char *, const int, const int, const int,
const void *, size_t, const bool, const bool);
+#define hex_dump_to_buffer(buf, len, rowsize, groupsize, linebuf, linebuflen, ascii) \
+ lkpi_hex_dump_to_buffer((buf), (len), (rowsize), (groupsize), (linebuf), (linebuflen), (ascii))
+
+int lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
+ int groupsize, char *linebuf, size_t linebuflen, bool ascii);
+
static inline void
print_hex_dump(const char *level, const char *prefix_str,
const int prefix_type, const int rowsize, const int groupsize,
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -1986,6 +1986,76 @@
}
}
+struct hdtb_context {
+ char *linebuf;
+ size_t linebuflen;
+ int written;
+};
+
+static int
+hdtb_cb(void *arg, const char *format, ...)
+{
+ struct hdtb_context *context;
+ int written;
+ va_list args;
+
+ context = arg;
+
+ va_start(args, format);
+ written = vsnprintf(
+ context->linebuf, context->linebuflen, format, args);
+ va_end(args);
+
+ if (written < 0)
+ return (written);
+
+ /*
+ * Linux' hex_dump_to_buffer() function has the same behaviour as
+ * snprintf() basically. Therefore, it returns the number of bytes it
+ * would have written if the destination buffer was large enough.
+ *
+ * If the destination buffer was exhausted, lkpi_hex_dump() will
+ * continue to call this callback but it will only compute the bytes it
+ * would have written but write nothing to that buffer.
+ */
+ context->written += written;
+
+ if (written < context->linebuflen) {
+ context->linebuf += written;
+ context->linebuflen -= written;
+ } else {
+ context->linebuf += context->linebuflen;
+ context->linebuflen = 0;
+ }
+
+ return (written);
+}
+
+int
+lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
+ int groupsize, char *linebuf, size_t linebuflen, bool ascii)
+{
+ int written;
+ struct hdtb_context context;
+
+ context.linebuf = linebuf;
+ context.linebuflen = linebuflen;
+ context.written = 0;
+
+ if (rowsize != 16 && rowsize != 32)
+ rowsize = 16;
+
+ len = min(len, rowsize);
+
+ lkpi_hex_dump(
+ hdtb_cb, &context, NULL, NULL, DUMP_PREFIX_NONE,
+ rowsize, groupsize, buf, len, ascii, false);
+
+ written = context.written;
+
+ return (written);
+}
+
static void
linux_timer_callback_wrapper(void *context)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jul 6, 4:58 PM (12 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34762943
Default Alt Text
D51559.diff (2 KB)
Attached To
Mode
D51559: linuxkpi: Add hex_dump_to_buffer()
Attached
Detach File
Event Timeline
Log In to Comment