summaryrefslogtreecommitdiffhomepage
path: root/pkg/abi
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/abi')
-rw-r--r--pkg/abi/flag.go25
-rw-r--r--pkg/abi/linux/file.go35
2 files changed, 17 insertions, 43 deletions
diff --git a/pkg/abi/flag.go b/pkg/abi/flag.go
index 0698e410f..049c1b0dd 100644
--- a/pkg/abi/flag.go
+++ b/pkg/abi/flag.go
@@ -46,30 +46,25 @@ func (s FlagSet) Parse(val uint64) string {
return strings.Join(flags, "|")
}
-// ValueSet is a slice of syscall values and their name. Parse will replace
-// values that exactly match an entry with its name.
-type ValueSet []struct {
- Value uint64
- Name string
-}
+// ValueSet is a map of syscall values to their name. Parse will use the name
+// or the value if unknown.
+type ValueSet map[uint64]string
// Parse returns the name of the value associated with `val`. Unknown values
// are converted to hex.
-func (e ValueSet) Parse(val uint64) string {
- for _, f := range e {
- if val == f.Value {
- return f.Name
- }
+func (s ValueSet) Parse(val uint64) string {
+ if v, ok := s[val]; ok {
+ return v
}
return fmt.Sprintf("%#x", val)
}
// ParseName returns the flag value associated with 'name'. Returns false
// if no value is found.
-func (e ValueSet) ParseName(name string) (uint64, bool) {
- for _, f := range e {
- if name == f.Name {
- return f.Value, true
+func (s ValueSet) ParseName(name string) (uint64, bool) {
+ for k, v := range s {
+ if v == name {
+ return k, true
}
}
return math.MaxUint64, false
diff --git a/pkg/abi/linux/file.go b/pkg/abi/linux/file.go
index 8d48e1753..ac49ae9a6 100644
--- a/pkg/abi/linux/file.go
+++ b/pkg/abi/linux/file.go
@@ -223,32 +223,11 @@ var modeExtraBits = abi.FlagSet{
}
var fileType = abi.ValueSet{
- {
- Value: ModeSocket,
- Name: "S_IFSOCK",
- },
- {
- Value: ModeSymlink,
- Name: "S_IFLINK",
- },
- {
- Value: ModeRegular,
- Name: "S_IFREG",
- },
- {
- Value: ModeBlockDevice,
- Name: "S_IFBLK",
- },
- {
- Value: ModeDirectory,
- Name: "S_IFDIR",
- },
- {
- Value: ModeCharacterDevice,
- Name: "S_IFCHR",
- },
- {
- Value: ModeNamedPipe,
- Name: "S_IFIFO",
- },
+ ModeSocket: "S_IFSOCK",
+ ModeSymlink: "S_IFLINK",
+ ModeRegular: "S_IFREG",
+ ModeBlockDevice: "S_IFBLK",
+ ModeDirectory: "S_IFDIR",
+ ModeCharacterDevice: "S_IFCHR",
+ ModeNamedPipe: "S_IFIFO",
}