2019-04-29 21:25:05 +00:00
|
|
|
// Copyright 2018 The gVisor Authors.
|
2018-04-27 17:37:02 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package linux
|
|
|
|
|
|
|
|
import (
|
2019-06-13 23:49:09 +00:00
|
|
|
"gvisor.dev/gvisor/pkg/abi/linux"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/fs"
|
2018-04-27 17:37:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// flagsToPermissions returns a Permissions object from Linux flags.
|
|
|
|
// This includes truncate permission if O_TRUNC is set in the mask.
|
|
|
|
func flagsToPermissions(mask uint) (p fs.PermMask) {
|
2018-12-06 17:25:57 +00:00
|
|
|
if mask&linux.O_TRUNC != 0 {
|
|
|
|
p.Write = true
|
|
|
|
}
|
2018-07-27 19:26:42 +00:00
|
|
|
switch mask & linux.O_ACCMODE {
|
|
|
|
case linux.O_WRONLY:
|
2018-04-27 17:37:02 +00:00
|
|
|
p.Write = true
|
2018-07-27 19:26:42 +00:00
|
|
|
case linux.O_RDWR:
|
2018-04-27 17:37:02 +00:00
|
|
|
p.Write = true
|
|
|
|
p.Read = true
|
2018-07-27 19:26:42 +00:00
|
|
|
case linux.O_RDONLY:
|
2018-04-27 17:37:02 +00:00
|
|
|
p.Read = true
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:49:23 +00:00
|
|
|
// linuxToFlags converts Linux file flags to a FileFlags object.
|
|
|
|
func linuxToFlags(mask uint) fs.FileFlags {
|
2018-04-27 17:37:02 +00:00
|
|
|
return fs.FileFlags{
|
2018-07-27 19:26:42 +00:00
|
|
|
Direct: mask&linux.O_DIRECT != 0,
|
2019-07-17 22:48:33 +00:00
|
|
|
DSync: mask&(linux.O_DSYNC|linux.O_SYNC) != 0,
|
2018-07-27 19:26:42 +00:00
|
|
|
Sync: mask&linux.O_SYNC != 0,
|
|
|
|
NonBlocking: mask&linux.O_NONBLOCK != 0,
|
|
|
|
Read: (mask & linux.O_ACCMODE) != linux.O_WRONLY,
|
|
|
|
Write: (mask & linux.O_ACCMODE) != linux.O_RDONLY,
|
|
|
|
Append: mask&linux.O_APPEND != 0,
|
|
|
|
Directory: mask&linux.O_DIRECTORY != 0,
|
|
|
|
Async: mask&linux.O_ASYNC != 0,
|
|
|
|
LargeFile: mask&linux.O_LARGEFILE != 0,
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
}
|