diff options
-rw-r--r-- | arch/x86/include/asm/cmdline.h | 6 | ||||
-rw-r--r-- | arch/x86/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/lib/cmdline.c | 84 |
3 files changed, 91 insertions, 1 deletions
diff --git a/arch/x86/include/asm/cmdline.h b/arch/x86/include/asm/cmdline.h new file mode 100644 index 000000000000..e01f7f7ccb0c --- /dev/null +++ b/arch/x86/include/asm/cmdline.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef _ASM_X86_CMDLINE_H | ||
2 | #define _ASM_X86_CMDLINE_H | ||
3 | |||
4 | int cmdline_find_option_bool(const char *cmdline_ptr, const char *option); | ||
5 | |||
6 | #endif /* _ASM_X86_CMDLINE_H */ | ||
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index eabcb6e6a900..4d4f96a27638 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile | |||
@@ -16,7 +16,7 @@ clean-files := inat-tables.c | |||
16 | 16 | ||
17 | obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o | 17 | obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o |
18 | 18 | ||
19 | lib-y := delay.o misc.o | 19 | lib-y := delay.o misc.o cmdline.o |
20 | lib-y += thunk_$(BITS).o | 20 | lib-y += thunk_$(BITS).o |
21 | lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o | 21 | lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o |
22 | lib-y += memcpy_$(BITS).o | 22 | lib-y += memcpy_$(BITS).o |
diff --git a/arch/x86/lib/cmdline.c b/arch/x86/lib/cmdline.c new file mode 100644 index 000000000000..422db000d727 --- /dev/null +++ b/arch/x86/lib/cmdline.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * This file is part of the Linux kernel, and is made available under | ||
3 | * the terms of the GNU General Public License version 2. | ||
4 | * | ||
5 | * Misc librarized functions for cmdline poking. | ||
6 | */ | ||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/string.h> | ||
9 | #include <linux/ctype.h> | ||
10 | #include <asm/setup.h> | ||
11 | |||
12 | static inline int myisspace(u8 c) | ||
13 | { | ||
14 | return c <= ' '; /* Close enough approximation */ | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Find a boolean option (like quiet,noapic,nosmp....) | ||
19 | * | ||
20 | * @cmdline: the cmdline string | ||
21 | * @option: option string to look for | ||
22 | * | ||
23 | * Returns the position of that @option (starts counting with 1) | ||
24 | * or 0 on not found. | ||
25 | */ | ||
26 | int cmdline_find_option_bool(const char *cmdline, const char *option) | ||
27 | { | ||
28 | char c; | ||
29 | int len, pos = 0, wstart = 0; | ||
30 | const char *opptr = NULL; | ||
31 | enum { | ||
32 | st_wordstart = 0, /* Start of word/after whitespace */ | ||
33 | st_wordcmp, /* Comparing this word */ | ||
34 | st_wordskip, /* Miscompare, skip */ | ||
35 | } state = st_wordstart; | ||
36 | |||
37 | if (!cmdline) | ||
38 | return -1; /* No command line */ | ||
39 | |||
40 | len = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE); | ||
41 | if (!len) | ||
42 | return 0; | ||
43 | |||
44 | while (len--) { | ||
45 | c = *(char *)cmdline++; | ||
46 | pos++; | ||
47 | |||
48 | switch (state) { | ||
49 | case st_wordstart: | ||
50 | if (!c) | ||
51 | return 0; | ||
52 | else if (myisspace(c)) | ||
53 | break; | ||
54 | |||
55 | state = st_wordcmp; | ||
56 | opptr = option; | ||
57 | wstart = pos; | ||
58 | /* fall through */ | ||
59 | |||
60 | case st_wordcmp: | ||
61 | if (!*opptr) | ||
62 | if (!c || myisspace(c)) | ||
63 | return wstart; | ||
64 | else | ||
65 | state = st_wordskip; | ||
66 | else if (!c) | ||
67 | return 0; | ||
68 | else if (c != *opptr++) | ||
69 | state = st_wordskip; | ||
70 | else if (!len) /* last word and is matching */ | ||
71 | return wstart; | ||
72 | break; | ||
73 | |||
74 | case st_wordskip: | ||
75 | if (!c) | ||
76 | return 0; | ||
77 | else if (myisspace(c)) | ||
78 | state = st_wordstart; | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return 0; /* Buffer overrun */ | ||
84 | } | ||