From: Remy Bohmer <linux@bohmer.net>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Ingo Molnar <mingo@elte.hu>, Juergen Beisert <jbe@pengutronix.de>,
Darren Hart <dvhltc@us.ibm.com>,
linux-rt-users@vger.kernel.org,
Sven-Thorsten Dietrich <sdietrich@novell.com>,
LKML <linux-kernel@vger.kernel.org>,
Remy Bohmer <linux@bohmer.net>
Subject: [patch 1/3] Add generic routine for parsing map-like options on kernel cmd-line (repost:CC to LKML)
Date: Wed, 19 Dec 2007 20:45:52 +0100 [thread overview]
Message-ID: <4769787e.01b4420a.2b28.ffff88cf@mx.google.com> (raw)
In-Reply-To: <20071219194551.315868746@bohmer.net>
[-- Attachment #1: add-map-functionality-to-kernel-cmdline.patch --]
[-- Type: text/plain, Size: 3188 bytes --]
This patch adds a generic routine to the kernel, so that a map of
settings can be entered on the kernel commandline.
Signed-off-by: Remy Bohmer <linux@bohmer.net>
---
---
include/linux/kernel.h | 1
lib/cmdline.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
Index: linux-2.6.24-rc5-rt1/include/linux/kernel.h
===================================================================
--- linux-2.6.24-rc5-rt1.orig/include/linux/kernel.h 2007-12-18 21:32:09.000000000 +0100
+++ linux-2.6.24-rc5-rt1/include/linux/kernel.h 2007-12-18 21:33:58.000000000 +0100
@@ -164,6 +164,7 @@ extern int vsscanf(const char *, const c
extern int get_option(char **str, int *pint);
extern char *get_options(const char *str, int nints, int *ints);
+extern int get_map_option(const char *str, const char *key, int *pint);
extern unsigned long long memparse(char *ptr, char **retptr);
extern int core_kernel_text(unsigned long addr);
Index: linux-2.6.24-rc5-rt1/lib/cmdline.c
===================================================================
--- linux-2.6.24-rc5-rt1.orig/lib/cmdline.c 2007-10-09 22:31:38.000000000 +0200
+++ linux-2.6.24-rc5-rt1/lib/cmdline.c 2007-12-18 21:33:58.000000000 +0100
@@ -15,6 +15,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
+#include <asm/setup.h>
/*
* If a hyphen was found in get_option, this will handle the
@@ -114,6 +115,63 @@ char *get_options(const char *str, int n
}
/**
+ * get_map_option - Parse integer from an option map
+ *
+ * This function parses an integer from an option map like
+ * some_map=key1:99,key2:98,...,keyN:NN,NN
+ * Only the value of the first match is returned, or if no
+ * key option is given (key = NULL) the value of the first
+ * field without a ':' is returned.
+ *
+ * @str: option string
+ * @key: The key inside the map, can be NULL
+ * @pint: (output) integer value parsed from the map @str
+ *
+ * Return values:
+ * 0 - no int in string
+ * 1 - int found
+ */
+int get_map_option(const char *str, const char *key, int *pint)
+{
+ char buf[COMMAND_LINE_SIZE];
+ char *p, *substr;
+ int found = 0;
+
+ /* We must copy the string to the stack, because strsep()
+ changes it.*/
+ strncpy(buf, str, COMMAND_LINE_SIZE);
+ buf[COMMAND_LINE_SIZE-1] = '\0';
+
+ p = buf;
+ substr = strsep(&p, ",");
+ while ((!found) && (substr != NULL)) {
+ if (strlen(substr) != 0) {
+ if (key == NULL) {
+ /* Check for the absence of any ':' */
+ if (strchr(substr, ':') == NULL) {
+ sscanf(substr, "%d", pint);
+ found = 1;
+ }
+ } else {
+ /* check if the first part of the key matches */
+ if (!strncmp(substr, key, strlen(key))) {
+ substr += strlen(key);
+ /* Now the next char must be a ':',
+ if not, search for the next match */
+ if (*substr == ':') {
+ substr++;
+ sscanf(substr, "%d", pint);
+ found = 1;
+ }
+ }
+ }
+ }
+ substr = strsep(&p, ",");
+ }
+ return found;
+}
+
+/**
* memparse - parse a string with mem suffixes into a number
* @ptr: Where parse begins
* @retptr: (output) Pointer to next char after parse completes
--
next parent reply other threads:[~2007-12-19 20:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071219194551.315868746@bohmer.net>
2007-12-19 19:45 ` Remy Bohmer [this message]
2007-12-19 21:00 ` Randy Dunlap
2007-12-19 21:44 ` Remy Bohmer
2007-12-19 19:45 ` [patch 2/3] Enable setting of IRQ-thread priorities from kernel cmdline " Remy Bohmer
2007-12-19 20:51 ` Randy Dunlap
2007-12-20 12:02 ` Jaswinder Singh
2007-12-19 19:45 ` [patch 3/3] Enable setting of IRQ-thread priorities from kernel cmdline. " Remy Bohmer
2007-12-19 20:55 ` Randy Dunlap
2007-12-20 11:59 ` Jaswinder Singh
2007-12-20 12:25 ` Remy Bohmer
2007-12-20 12:45 ` Jaswinder Singh
2007-12-20 12:50 ` Remy Bohmer
2007-12-20 13:18 ` Juergen Beisert
2007-12-20 13:40 ` Jaswinder Singh
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=4769787e.01b4420a.2b28.ffff88cf@mx.google.com \
--to=linux@bohmer.net \
--cc=acme@ghostprotocols.net \
--cc=dvhltc@us.ibm.com \
--cc=jbe@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=sdietrich@novell.com \
/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®