[Concept,08/12] ext4l: Add ext4l_msgs env var to print messages on mount

Message ID 20251223011632.380026-9-sjg@u-boot.org
State New
Headers
Series ext4l: Add support for listing directoties (Part H) |

Commit Message

Simon Glass Dec. 23, 2025, 1:16 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add runtime control for printing ext4 messages via the ext4l_msgs
environment variable. When set to 'y' or '1', the recorded message
buffer is printed after a successful mount.

This provides a runtime alternative to the compile-time
CONFIG_EXT4L_DEBUG option.

Usage: setenv ext4l_msgs y

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/interface.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Patch

diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c
index 9b6f4c0b02b..638f51d8c64 100644
--- a/fs/ext4l/interface.c
+++ b/fs/ext4l/interface.c
@@ -10,6 +10,7 @@ 
  */
 
 #include <blk.h>
+#include <env.h>
 #include <membuf.h>
 #include <part.h>
 #include <malloc.h>
@@ -127,6 +128,20 @@  struct membuf *ext4l_get_msg_buf(void)
 	return &ext4l_msg_buf;
 }
 
+/**
+ * ext4l_print_msgs() - Print all recorded messages
+ *
+ * Prints the contents of the message buffer to the console.
+ */
+static void ext4l_print_msgs(void)
+{
+	char *data;
+	int len;
+
+	while ((len = membuf_getraw(&ext4l_msg_buf, 80, true, &data)) > 0)
+		printf("%.*s", len, data);
+}
+
 int ext4l_probe(struct blk_desc *fs_dev_desc,
 		struct disk_partition *fs_partition)
 {
@@ -263,6 +278,11 @@  int ext4l_probe(struct blk_desc *fs_dev_desc,
 
 	/* Store super_block for later operations */
 	ext4l_sb = sb;
+
+	/* Print messages if ext4l_msgs environment variable is set */
+	if (env_get_yesno("ext4l_msgs") == 1)
+		ext4l_print_msgs();
+
 	return 0;
 
 err_free_buf: