Skip to content

Commit 4f469e1

Browse files
committed
chore: Updated documentation
Signed-off-by: Dominik De Zordo <[email protected]>
1 parent 3da71c9 commit 4f469e1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

kernelargs.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import (
1919
"strings"
2020
)
2121

22-
// kernelArgs serializes+deserializes kernel boot parameters from/into a map.
23-
// Kernel docs: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt
24-
//
25-
// "key=value" will result in map["key"] = &"value"
26-
// "key=" will result in map["key"] = &""
27-
// "key" will result in map["key"] = nil
22+
// kernelArg represents a key and optional value pair for passing an argument
23+
// into the kernel. Additionally, it also saves the position of the argument
24+
// in the whole command line input. This is important because the kernel stops reading
25+
// everything after `--` and passes these keys into the init process
2826
type kernelArg struct {
2927
position uint
3028
key string
@@ -38,10 +36,17 @@ func (karg kernelArg) String() string {
3836
return karg.key
3937
}
4038

39+
// kernelArgs serializes + deserializes kernel boot parameters from/into a map.
40+
// Kernel docs: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt
41+
//
42+
// "key=value flag emptykey=" will be converted to
43+
// map["key"] = { position: 0, key: "key", value: &"value" }
44+
// map["flag"] = { position: 1, key: "flag", value: nil }
45+
// map["emptykey"] = { position: 2, key: "emptykey", value: &"" }
4146
type kernelArgs map[string]kernelArg
4247

43-
// serialize the sorted kernelArgs back to a string that can be provided
44-
// to the kernel
48+
// Sorts the arguments by its position
49+
// and serializes the map back into a single string
4550
func (kargs kernelArgs) String() string {
4651
sortedArgs := make([]kernelArg, 0)
4752
for _, arg := range kargs {
@@ -58,6 +63,7 @@ func (kargs kernelArgs) String() string {
5863
return strings.Join(args, " ")
5964
}
6065

66+
// Add a new kernel argument to the kernelArgs, also the position is saved
6167
func (kargs kernelArgs) Add(key string, value *string) {
6268
kargs[key] = kernelArg{
6369
position: uint(len(kargs)),
@@ -66,7 +72,8 @@ func (kargs kernelArgs) Add(key string, value *string) {
6672
}
6773
}
6874

69-
// deserialize the provided string to a kernelArgs map
75+
// Parses an input string and deserializes it into a map
76+
// saving its position in the command line
7077
func parseKernelArgs(rawString string) kernelArgs {
7178
args := make(map[string]kernelArg)
7279
for index, kv := range strings.Fields(rawString) {

0 commit comments

Comments
 (0)