-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmap.go
59 lines (49 loc) · 1.29 KB
/
mmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package mmap
import (
"os"
)
// Prot is the protection flag.
type Prot int
const (
// READ represents the read prot
READ Prot = 1 << iota
// WRITE represents the write prot
WRITE
// COPY represents the copy prot
COPY
// EXEC represents the exec prot
EXEC
)
// Fd returns the integer file descriptor referencing the open file.
// The file descriptor is valid only until f.Close is called or f is garbage collected.
func Fd(f *os.File) int {
return int(f.Fd())
}
// FSize returns the file size.
func FSize(f *os.File) int {
cursor, _ := f.Seek(0, os.SEEK_CUR)
ret, _ := f.Seek(0, os.SEEK_END)
f.Seek(cursor, os.SEEK_SET)
return int(ret)
}
// ProtFlags returns prot and flags by Prot p.
func ProtFlags(p Prot) (prot int, flags int) {
return protFlags(p)
}
// Open opens a MMap
func Open(fd int, offset int64, length int, p Prot) (data []byte, err error) {
prot, flags := ProtFlags(p)
return MMap(fd, offset, length, prot, flags)
}
//MMap calls the MMap system call.
func MMap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
return mMap(fd, offset, length, prot, flags)
}
// MSync calls the msync system call.
func MSync(b []byte) (err error) {
return mSync(b)
}
// MUnmap calls the MUnmap system call.
func MUnmap(b []byte) (err error) {
return mUnmap(b)
}