Refactor host.canMap.

Simplify the canMap check. We do not have plans to allow mmap for anything
beyond regular files, so we can just inline canMap() as a simple file mode
check.

Updates #1672.

PiperOrigin-RevId: 316929654
This commit is contained in:
Dean Deng
2020-06-17 11:34:06 -07:00
committed by gVisor bot
parent 50afec55c7
commit e5d97cbcc1
2 changed files with 3 additions and 11 deletions
+3 -1
View File
@@ -91,7 +91,9 @@ func NewFD(ctx context.Context, mnt *vfs.Mount, hostFD int, opts *NewFDOptions)
isTTY: opts.IsTTY,
wouldBlock: wouldBlock(uint32(fileType)),
seekable: seekable,
canMap: canMap(uint32(fileType)),
// NOTE(b/38213152): Technically, some obscure char devices can be memory
// mapped, but we only allow regular files.
canMap: fileType == linux.S_IFREG,
}
i.pf.inode = i
-10
View File
@@ -49,16 +49,6 @@ func wouldBlock(fileType uint32) bool {
return fileType == syscall.S_IFIFO || fileType == syscall.S_IFCHR || fileType == syscall.S_IFSOCK
}
// canMap returns true if a file with fileType is allowed to be memory mapped.
// This is ported over from VFS1, but it's probably not the best way for us
// to check if a file can be memory mapped.
func canMap(fileType uint32) bool {
// TODO(gvisor.dev/issue/1672): Also allow "special files" to be mapped (see fs/host:canMap()).
//
// TODO(b/38213152): Some obscure character devices can be mapped.
return fileType == syscall.S_IFREG
}
// isBlockError checks if an error is EAGAIN or EWOULDBLOCK.
// If so, they can be transformed into syserror.ErrWouldBlock.
func isBlockError(err error) bool {