-
Notifications
You must be signed in to change notification settings - Fork 2
/
export_solodn.go
132 lines (108 loc) · 3.03 KB
/
export_solodn.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import "C"
import (
"io"
"reflect"
"soloos/common/log"
"soloos/common/solofsapi"
"unsafe"
)
//export GoSolofsPappend
func GoSolofsPappend(fdID uint64, buffer unsafe.Pointer, bufferLen, offset int32) (int32, C.int) {
var (
fd = env.solofsClient.FdTableGetFd(fdID)
err error
)
var data = *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(buffer),
Len: int(bufferLen),
Cap: int(bufferLen),
}))
err = env.solofsClient.SimpleWriteWithMem(fd.FsINodeIno, data, uint64(offset))
if err != nil {
return 0, solofsapi.CODE_ERR
}
return bufferLen, 0
}
//export GoSolofsAppend
func GoSolofsAppend(fdID uint64, buffer unsafe.Pointer, bufferLen int32) (int32, C.int) {
var (
fd = env.solofsClient.FdTableGetFd(fdID)
err error
)
var data = *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(buffer),
Len: int(bufferLen),
Cap: int(bufferLen),
}))
err = env.solofsClient.SimpleWriteWithMem(fd.FsINodeIno, data, fd.AppendPosition)
if err != nil {
log.Warn(err)
return 0, solofsapi.CODE_ERR
}
env.solofsClient.FdTableFdAddAppendPosition(fdID, uint64(bufferLen))
return bufferLen, solofsapi.CODE_OK
}
//export GoSolofsRead
func GoSolofsRead(fdID uint64, buffer unsafe.Pointer, bufferLen int32) (int32, C.int) {
var (
fd = env.solofsClient.FdTableGetFd(fdID)
readDataLength int
err error
)
var data = *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(buffer),
Len: int(bufferLen),
Cap: int(bufferLen),
}))
readDataLength, err = env.solofsClient.SimpleReadWithMem(fd.FsINodeIno, data, fd.ReadPosition)
if err != nil && err != io.EOF {
log.Warn(err, readDataLength)
return int32(readDataLength), solofsapi.CODE_ERR
}
env.solofsClient.FdTableFdAddReadPosition(fdID, uint64(bufferLen))
return int32(readDataLength), solofsapi.CODE_OK
}
//export GoSolofsPread
func GoSolofsPread(fdID uint64, buffer unsafe.Pointer, bufferLen int32, position uint64) (int32, C.int) {
var (
fd = env.solofsClient.FdTableGetFd(fdID)
readDataLength int
err error
)
var data = *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(buffer),
Len: int(bufferLen),
Cap: int(bufferLen),
}))
readDataLength, err = env.solofsClient.SimpleReadWithMem(fd.FsINodeIno, data, position)
if err != nil {
return int32(readDataLength), solofsapi.CODE_ERR
}
return int32(readDataLength), solofsapi.CODE_OK
}
//export GoSolofsCloseFile
func GoSolofsCloseFile(fdID uint64) C.int {
ret := doFlushINode(fdID)
// env.solofsClient.FdTableReleaseFd(fdID)
return ret
}
//export GoSolofsFlushFile
func GoSolofsFlushFile(fdID uint64) C.int {
return doFlushINode(fdID)
}
//export GoSolofsHFlushINode
func GoSolofsHFlushINode(fdID uint64) C.int {
return doFlushINode(fdID)
}
//export GoSolofsHSyncINode
func GoSolofsHSyncINode(fdID uint64) C.int {
return doFlushINode(fdID)
}
func doFlushINode(fdID uint64) C.int {
var (
fd = env.solofsClient.FdTableGetFd(fdID)
)
env.solofsClient.SimpleFlush(fd.FsINodeIno)
return solofsapi.CODE_OK
}