1
// Copyright 2023 The Inspektor Gadget authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
17
var flagNames = []string{
34
func DecodeFlags(flags int32) []string {
35
flagsStr := []string{}
37
// We first need to deal with the first 3 bits which indicates access mode.
40
flagsStr = append(flagsStr, "O_RDONLY")
42
flagsStr = append(flagsStr, "O_WRONLY")
44
flagsStr = append(flagsStr, "O_RDWR")
47
// Then, we need to remove the last 6 bits and we can deal with the other
49
// Indeed, O_CREAT is defined as 00000100, see:
50
// https://github.com/torvalds/linux/blob/9d646009f65d/include/uapi/asm-generic/fcntl.h#L24
52
for i, val := range flagNames {
53
if (1<<i)&flags == 0 {
56
flagsStr = append(flagsStr, val)