mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Cc: Kay Sievers <kay@vrfy.org>
Subject: [PATCH 21/23] printk: Move functions printk_print_time and printk_msg_print_text
Date: Tue, 16 Oct 2012 23:06:25 -0700	[thread overview]
Message-ID: <fda2d6aa0ee7cd0fa72b91f05f747c05f0682f72.1350449852.git.joe@perches.com> (raw)
In-Reply-To: <cover.1350449851.git.joe@perches.com>

Move these functions to printk_log.
Move the static function print_prefix too.
Add "#include <linux/moduleparam.h>" to printk_log.c.

Signed-off-by: Joe Perches <joe@perches.com>
---
 kernel/printk/printk.c     |  112 -------------------------------------------
 kernel/printk/printk_log.c |  114 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 112 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index cd0d317..343b0ce 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -311,111 +311,6 @@ static int check_syslog_permissions(int type, bool from_file)
 	return 0;
 }
 
-#if defined(CONFIG_PRINTK_TIME)
-static bool printk_time = 1;
-#else
-static bool printk_time;
-#endif
-module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
-
-size_t printk_print_time(u64 ts, char *buf)
-{
-	unsigned long rem_nsec;
-
-	if (!printk_time)
-		return 0;
-
-	if (!buf)
-		return 15;
-
-	rem_nsec = do_div(ts, 1000000000);
-	return sprintf(buf, "[%5lu.%06lu] ",
-		       (unsigned long)ts, rem_nsec / 1000);
-}
-
-static size_t print_prefix(const struct printk_log *msg, bool syslog, char *buf)
-{
-	size_t len = 0;
-	unsigned int prefix = (msg->facility << 3) | msg->level;
-
-	if (syslog) {
-		if (buf) {
-			len += sprintf(buf, "<%u>", prefix);
-		} else {
-			len += 3;
-			if (prefix > 999)
-				len += 3;
-			else if (prefix > 99)
-				len += 2;
-			else if (prefix > 9)
-				len++;
-		}
-	}
-
-	len += printk_print_time(msg->ts_nsec, buf ? buf + len : NULL);
-	return len;
-}
-
-size_t printk_msg_print_text(const struct printk_log *msg,
-			     enum printk_log_flags prev,
-			     bool syslog, char *buf, size_t size)
-{
-	const char *text = printk_log_text(msg);
-	size_t text_size = msg->text_len;
-	bool prefix = true;
-	bool newline = true;
-	size_t len = 0;
-
-	if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))
-		prefix = false;
-
-	if (msg->flags & LOG_CONT) {
-		if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE))
-			prefix = false;
-
-		if (!(msg->flags & LOG_NEWLINE))
-			newline = false;
-	}
-
-	do {
-		const char *next = memchr(text, '\n', text_size);
-		size_t text_len;
-
-		if (next) {
-			text_len = next - text;
-			next++;
-			text_size -= next - text;
-		} else {
-			text_len = text_size;
-		}
-
-		if (buf) {
-			if (print_prefix(msg, syslog, NULL) +
-			    text_len + 1 >= size - len)
-				break;
-
-			if (prefix)
-				len += print_prefix(msg, syslog, buf + len);
-			memcpy(buf + len, text, text_len);
-			len += text_len;
-			if (next || newline)
-				buf[len++] = '\n';
-		} else {
-			/* SYSLOG_ACTION_* buffer size only calculation */
-			if (prefix)
-				len += print_prefix(msg, syslog, NULL);
-			len += text_len;
-			if (next || newline)
-				len++;
-		}
-
-		prefix = true;
-		text = next;
-	} while (text);
-
-	return len;
-}
-
 static int syslog_print(char __user *buf, int size)
 {
 	char *text;
@@ -1186,13 +1081,6 @@ static struct cont {
 struct printk_log *printk_log_from_idx(u32 idx) { return NULL; }
 u32 printk_log_next(u32 idx) { return 0; }
 static void call_console_drivers(int level, const char *text, size_t len) {}
-size_t printk_print_time(u64 ts, char *buf) { return 0; }
-size_t printk_msg_print_text(const struct printk_log *msg,
-			     enum printk_log_flags prev,
-			     bool syslog, char *buf, size_t size)
-{
-	return 0;
-}
 
 static size_t cont_print_text(char *text, size_t size) { return 0; }
 
diff --git a/kernel/printk/printk_log.c b/kernel/printk/printk_log.c
index b5c2b8f..d38129c 100644
--- a/kernel/printk/printk_log.c
+++ b/kernel/printk/printk_log.c
@@ -2,6 +2,8 @@
 #include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/kexec.h>
+#include <linux/moduleparam.h>
+#include <linux/stat.h>
 
 #include "printk_log.h"
 
@@ -135,6 +137,111 @@ void printk_log_store(int facility, int level,
 	printk_log_next_seq++;
 }
 
+#if defined(CONFIG_PRINTK_TIME)
+static bool printk_time = 1;
+#else
+static bool printk_time;
+#endif
+module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
+
+size_t printk_print_time(u64 ts, char *buf)
+{
+	unsigned long rem_nsec;
+
+	if (!printk_time)
+		return 0;
+
+	if (!buf)
+		return 15;
+
+	rem_nsec = do_div(ts, 1000000000);
+	return sprintf(buf, "[%5lu.%06lu] ",
+		       (unsigned long)ts, rem_nsec / 1000);
+}
+
+static size_t print_prefix(const struct printk_log *msg, bool syslog, char *buf)
+{
+	size_t len = 0;
+	unsigned int prefix = (msg->facility << 3) | msg->level;
+
+	if (syslog) {
+		if (buf) {
+			len += sprintf(buf, "<%u>", prefix);
+		} else {
+			len += 3;
+			if (prefix > 999)
+				len += 3;
+			else if (prefix > 99)
+				len += 2;
+			else if (prefix > 9)
+				len++;
+		}
+	}
+
+	len += printk_print_time(msg->ts_nsec, buf ? buf + len : NULL);
+	return len;
+}
+
+size_t printk_msg_print_text(const struct printk_log *msg,
+			     enum printk_log_flags prev,
+			     bool syslog, char *buf, size_t size)
+{
+	const char *text = printk_log_text(msg);
+	size_t text_size = msg->text_len;
+	bool prefix = true;
+	bool newline = true;
+	size_t len = 0;
+
+	if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))
+		prefix = false;
+
+	if (msg->flags & LOG_CONT) {
+		if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE))
+			prefix = false;
+
+		if (!(msg->flags & LOG_NEWLINE))
+			newline = false;
+	}
+
+	do {
+		const char *next = memchr(text, '\n', text_size);
+		size_t text_len;
+
+		if (next) {
+			text_len = next - text;
+			next++;
+			text_size -= next - text;
+		} else {
+			text_len = text_size;
+		}
+
+		if (buf) {
+			if (print_prefix(msg, syslog, NULL) +
+			    text_len + 1 >= size - len)
+				break;
+
+			if (prefix)
+				len += print_prefix(msg, syslog, buf + len);
+			memcpy(buf + len, text, text_len);
+			len += text_len;
+			if (next || newline)
+				buf[len++] = '\n';
+		} else {
+			/* SYSLOG_ACTION_* buffer size only calculation */
+			if (prefix)
+				len += print_prefix(msg, syslog, NULL);
+			len += text_len;
+			if (next || newline)
+				len++;
+		}
+
+		prefix = true;
+		text = next;
+	} while (text);
+
+	return len;
+}
+
 #else /* CONFIG_PRINTK */
 
 #define LOG_LINE_MAX		0
@@ -145,5 +252,12 @@ u32 printk_log_first_idx;
 u64 printk_log_next_seq;
 struct printk_log *printk_log_from_idx(u32 idx) { return NULL; }
 u32 printk_log_next(u32 idx) { return 0; }
+size_t printk_print_time(u64 ts, char *buf) { return 0; }
+size_t printk_msg_print_text(const struct printk_log *msg,
+			     enum printk_log_flags prev,
+			     bool syslog, char *buf, size_t size)
+{
+	return 0;
+}
 
 #endif /* CONFIG_PRINTK */
-- 
1.7.10.4


  parent reply	other threads:[~2012-10-17  6:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-17  6:06 [PATCH 00/23] printk: refactoring Joe Perches
2012-10-17  6:06 ` [PATCH 01/23] printk: Move to separate directory for easier modification Joe Perches
2012-10-17  6:06 ` [PATCH 02/23] printk: Add console_cmdline.h Joe Perches
2012-10-17  6:06 ` [PATCH 03/23] printk: Move braille console support into separate braille.[ch] files Joe Perches
2012-10-17 23:47   ` Samuel Thibault
2012-10-25  0:12   ` Stephen Warren
2012-10-25  0:31     ` Joe Perches
2012-10-25 15:32       ` Stephen Warren
2012-10-17  6:06 ` [PATCH 04/23] printk: Use pointer for console_cmdline indexing Joe Perches
2012-10-17  6:06 ` [PATCH 05/23] printk: rename struct log to struct printk_log Joe Perches
2012-10-17  6:06 ` [PATCH 06/23] printk: Rename log_buf and __LOG_BUF_LEN Joe Perches
2012-10-17  6:06 ` [PATCH 07/23] printk: Rename log_first and log_next variables Joe Perches
2012-10-17  6:06 ` [PATCH 08/23] printk: Rename log_<foo> variables and functions Joe Perches
2012-10-17  6:06 ` [PATCH 09/23] printk: Rename enum log_flags to printk_log_flags Joe Perches
2012-10-17  6:06 ` [PATCH 10/23] printk: Rename log_wait to printk_log_wait Joe Perches
2012-10-17  6:06 ` [PATCH 11/23] printk: Rename logbuf_lock to printk_logbuf_lock Joe Perches
2012-10-17  6:06 ` [PATCH 12/23] printk: Rename clear_seq and clear_idx variables Joe Perches
2012-10-17  6:06 ` [PATCH 13/23] printk: Remove static from printk_ variables Joe Perches
2012-10-17  6:06 ` [PATCH 14/23] printk: Rename LOG_ALIGN to PRINTK_LOG_ALIGN Joe Perches
2012-10-17  6:06 ` [PATCH 15/23] printk: Add and use printk_log.h Joe Perches
2012-10-17  6:06 ` [PATCH 16/23] printk: Add printk_log.c Joe Perches
2012-10-17  6:06 ` [PATCH 17/23] printk: Make wait_queue_head_t printk_log_wait extern Joe Perches
2012-10-17  6:06 ` [PATCH 18/23] printk: Rename and move 2 #defines to printk_log.h Joe Perches
2012-10-17  6:06 ` [PATCH 19/23] printk: Move devkmsg bits to separate file Joe Perches
2012-10-17  6:06 ` [PATCH 20/23] printk: Prefix print_time and msg_print_text with printk_ Joe Perches
2012-10-17  6:06 ` Joe Perches [this message]
2012-10-17  6:06 ` [PATCH 22/23] printk: Add printk_syslog.c and .h Joe Perches
2012-10-17  6:06 ` [PATCH 23/23] printk: Move kmsg_dump functions to separate file Joe Perches
2012-10-18 23:16 ` [PATCH 00/23] printk: refactoring Andrew Morton
2012-10-19  0:43   ` Joe Perches
2012-10-19  1:00   ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fda2d6aa0ee7cd0fa72b91f05f747c05f0682f72.1350449852.git.joe@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®