github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/strace/open.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 15 package strace 16 17 import ( 18 "github.com/nicocha30/gvisor-ligolo/pkg/abi" 19 "github.com/nicocha30/gvisor-ligolo/pkg/abi/linux" 20 ) 21 22 // OpenMode represents the mode to open(2) a file. 23 var OpenMode = abi.ValueSet{ 24 linux.O_RDWR: "O_RDWR", 25 linux.O_WRONLY: "O_WRONLY", 26 linux.O_RDONLY: "O_RDONLY", 27 } 28 29 // OpenFlagSet is the set of open(2) flags. 30 var OpenFlagSet = abi.FlagSet{ 31 { 32 Flag: linux.O_APPEND, 33 Name: "O_APPEND", 34 }, 35 { 36 Flag: linux.O_ASYNC, 37 Name: "O_ASYNC", 38 }, 39 { 40 Flag: linux.O_CLOEXEC, 41 Name: "O_CLOEXEC", 42 }, 43 { 44 Flag: linux.O_CREAT, 45 Name: "O_CREAT", 46 }, 47 { 48 Flag: linux.O_DIRECT, 49 Name: "O_DIRECT", 50 }, 51 { 52 Flag: linux.O_DIRECTORY, 53 Name: "O_DIRECTORY", 54 }, 55 { 56 Flag: linux.O_EXCL, 57 Name: "O_EXCL", 58 }, 59 { 60 Flag: linux.O_NOATIME, 61 Name: "O_NOATIME", 62 }, 63 { 64 Flag: linux.O_NOCTTY, 65 Name: "O_NOCTTY", 66 }, 67 { 68 Flag: linux.O_NOFOLLOW, 69 Name: "O_NOFOLLOW", 70 }, 71 { 72 Flag: linux.O_NONBLOCK, 73 Name: "O_NONBLOCK", 74 }, 75 { 76 Flag: 0x200000, // O_PATH 77 Name: "O_PATH", 78 }, 79 { 80 Flag: linux.O_SYNC, 81 Name: "O_SYNC", 82 }, 83 { 84 Flag: linux.O_TMPFILE, 85 Name: "O_TMPFILE", 86 }, 87 { 88 Flag: linux.O_TRUNC, 89 Name: "O_TRUNC", 90 }, 91 } 92 93 func open(val uint64) string { 94 s := OpenMode.Parse(val & linux.O_ACCMODE) 95 if flags := OpenFlagSet.Parse(val &^ linux.O_ACCMODE); flags != "" { 96 s += "|" + flags 97 } 98 return s 99 }