wa_init_api_afs.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package openngvfs
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "fmt"
  6. "git.swzry.com/zry/GoHiedaLogger/hiedalog"
  7. go_int32_handle "git.swzry.com/zry/go-int32-handle"
  8. "github.com/bep/overlayfs"
  9. "github.com/spf13/afero"
  10. wa_api "github.com/tetratelabs/wazero/api"
  11. "os"
  12. "regexp"
  13. "time"
  14. )
  15. func (a *InitWAVMHostModuleAdapter) mfaAddAfs() {
  16. a.addFunc("afs_free", a.efnAfsFree,
  17. []wa_api.ValueType{wa_api.ValueTypeI32},
  18. []wa_api.ValueType{wa_api.ValueTypeI32})
  19. a.addFunc("afs_mkdir", a.efnAfsMkdir,
  20. []wa_api.ValueType{
  21. wa_api.ValueTypeI32, wa_api.ValueTypeI32,
  22. wa_api.ValueTypeI32, wa_api.ValueTypeI32,
  23. },
  24. []wa_api.ValueType{wa_api.ValueTypeI32})
  25. a.addFunc("afs_create_osfs", a.efnAfsCreateOsFs,
  26. []wa_api.ValueType{},
  27. []wa_api.ValueType{wa_api.ValueTypeI32})
  28. a.addFunc("afs_create_memfs", a.efnAfsCreateMemFs,
  29. []wa_api.ValueType{},
  30. []wa_api.ValueType{wa_api.ValueTypeI32})
  31. a.addFunc("afs_create_bpfs", a.efnAfsCreateBpFs,
  32. []wa_api.ValueType{wa_api.ValueTypeI32, wa_api.ValueTypeI32, wa_api.ValueTypeI32},
  33. []wa_api.ValueType{wa_api.ValueTypeI32})
  34. a.addFunc("afs_create_regfs", a.efnAfsCreateRegFs,
  35. []wa_api.ValueType{wa_api.ValueTypeI32, wa_api.ValueTypeI32, wa_api.ValueTypeI32},
  36. []wa_api.ValueType{wa_api.ValueTypeI32})
  37. a.addFunc("afs_create_rofs", a.efnAfsCreateRoFs,
  38. []wa_api.ValueType{wa_api.ValueTypeI32},
  39. []wa_api.ValueType{wa_api.ValueTypeI32})
  40. a.addFunc("afs_create_cowfs", a.efnAfsCreateCowFs,
  41. []wa_api.ValueType{wa_api.ValueTypeI32, wa_api.ValueTypeI32},
  42. []wa_api.ValueType{wa_api.ValueTypeI32})
  43. a.addFunc("afs_create_corfs", a.efnAfsCreateCorFs,
  44. []wa_api.ValueType{wa_api.ValueTypeI32, wa_api.ValueTypeI32, wa_api.ValueTypeI32},
  45. []wa_api.ValueType{wa_api.ValueTypeI32})
  46. a.addFunc("afs_create_bep_ovfs", a.efnAfsCreateBepOvFs,
  47. []wa_api.ValueType{wa_api.ValueTypeI32, wa_api.ValueTypeI32, wa_api.ValueTypeI32},
  48. []wa_api.ValueType{wa_api.ValueTypeI32})
  49. }
  50. func (a *InitWAVMHostModuleAdapter) efnAfsFree(_ context.Context, _ wa_api.Module, stack []uint64) {
  51. hAfs := int32(stack[0])
  52. if hAfs <= 0 {
  53. var neg1 int32 = -1
  54. stack[0] = uint64(neg1)
  55. return
  56. }
  57. _, ok := a.api.AferoFsInstancesMgr.Release(hAfs)
  58. if !ok {
  59. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  60. "type": "afs_release_error",
  61. "handle": fmt.Sprintf("%d", hAfs),
  62. })
  63. var neg1 int32 = -1
  64. stack[0] = uint64(neg1)
  65. return
  66. }
  67. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  68. "type": "afs_free_ok",
  69. "handle": fmt.Sprintf("%d", hAfs),
  70. })
  71. stack[0] = 0
  72. return
  73. }
  74. func (a *InitWAVMHostModuleAdapter) efnAfsMkdir(_ context.Context, mod wa_api.Module, stack []uint64) {
  75. hAfs := int32(stack[0])
  76. ptrPath := uint32(stack[1])
  77. lenPath := uint32(stack[2])
  78. perm := uint32(stack[3])
  79. dirPath, ok := mod.Memory().Read(ptrPath, lenPath)
  80. if !ok {
  81. var ecode int32 = -3
  82. stack[0] = uint64(ecode)
  83. return
  84. }
  85. if hAfs <= 0 {
  86. var ecode int32 = -2
  87. stack[0] = uint64(ecode)
  88. return
  89. }
  90. objAfs, ok := a.api.AferoFsInstancesMgr.Get(hAfs)
  91. if !ok {
  92. var ecode int32 = -2
  93. stack[0] = uint64(ecode)
  94. return
  95. }
  96. err := objAfs.Fs.MkdirAll(string(dirPath), os.FileMode(perm))
  97. if err != nil {
  98. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  99. "type": "afs_mkdir_error",
  100. "dir-path": string(dirPath),
  101. "afs": fmt.Sprintf("%d", hAfs),
  102. "perm": fmt.Sprintf("%04o", perm),
  103. "raw-err": err.Error(),
  104. })
  105. var ecode int32 = -1
  106. stack[0] = uint64(ecode)
  107. return
  108. }
  109. a.logger.LogComplex("openngvfs", hiedalog.DLN_VERBOSE, map[string]string{
  110. "type": "afs_mkdir_ok",
  111. "afs": fmt.Sprintf("%d", hAfs),
  112. "path": string(dirPath),
  113. })
  114. stack[0] = 0
  115. return
  116. }
  117. func (a *InitWAVMHostModuleAdapter) efnAfsCreateOsFs(_ context.Context, _ wa_api.Module, stack []uint64) {
  118. osfs := afero.NewOsFs()
  119. afsObj := &AferoFsInstance{
  120. Fs: osfs,
  121. TypeDescription: "afero-osfs",
  122. }
  123. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  124. if err != nil {
  125. if err == go_int32_handle.ErrHandleExceedMax {
  126. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  127. "type": "afs_handle_alloc_error",
  128. "msg": "handle exceed max",
  129. })
  130. var ecode int32 = -1
  131. stack[0] = uint64(ecode)
  132. return
  133. } else {
  134. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  135. "type": "afs_handle_alloc_error",
  136. "msg": err.Error(),
  137. })
  138. var ecode int32 = -1
  139. stack[0] = uint64(ecode)
  140. return
  141. }
  142. }
  143. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  144. "type": "afs_create_osfs_ok",
  145. "handle": fmt.Sprintf("%d", h),
  146. })
  147. stack[0] = uint64(h)
  148. return
  149. }
  150. func (a *InitWAVMHostModuleAdapter) efnAfsCreateMemFs(_ context.Context, _ wa_api.Module, stack []uint64) {
  151. memfs := afero.NewMemMapFs()
  152. afsObj := &AferoFsInstance{
  153. Fs: memfs,
  154. TypeDescription: "afero-memfs",
  155. }
  156. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  157. if err != nil {
  158. if err == go_int32_handle.ErrHandleExceedMax {
  159. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  160. "type": "afs_handle_alloc_error",
  161. "msg": "handle exceed max",
  162. })
  163. var ecode int32 = -1
  164. stack[0] = uint64(ecode)
  165. return
  166. } else {
  167. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  168. "type": "afs_handle_alloc_error",
  169. "msg": err.Error(),
  170. })
  171. var ecode int32 = -1
  172. stack[0] = uint64(ecode)
  173. return
  174. }
  175. }
  176. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  177. "type": "afs_create_memfs_ok",
  178. "handle": fmt.Sprintf("%d", h),
  179. })
  180. stack[0] = uint64(h)
  181. return
  182. }
  183. func (a *InitWAVMHostModuleAdapter) efnAfsCreateBpFs(_ context.Context, mod wa_api.Module, stack []uint64) {
  184. hBaseAfs := int32(stack[0])
  185. ptrBasePath := uint32(stack[1])
  186. lenBasePath := uint32(stack[2])
  187. basePath, ok := mod.Memory().Read(ptrBasePath, lenBasePath)
  188. if !ok {
  189. var ecode int32 = -3
  190. stack[0] = uint64(ecode)
  191. return
  192. }
  193. if hBaseAfs <= 0 {
  194. var ecode int32 = -2
  195. stack[0] = uint64(ecode)
  196. return
  197. }
  198. objBaseAfs, ok := a.api.AferoFsInstancesMgr.Get(hBaseAfs)
  199. if !ok {
  200. var ecode int32 = -2
  201. stack[0] = uint64(ecode)
  202. return
  203. }
  204. bpfs := afero.NewBasePathFs(objBaseAfs.Fs, string(basePath))
  205. afsObj := &AferoFsInstance{
  206. Fs: bpfs,
  207. TypeDescription: "afero-base-path-fs",
  208. }
  209. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  210. if err != nil {
  211. if err == go_int32_handle.ErrHandleExceedMax {
  212. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  213. "type": "afs_handle_alloc_error",
  214. "msg": "handle exceed max",
  215. })
  216. var ecode int32 = -1
  217. stack[0] = uint64(ecode)
  218. return
  219. } else {
  220. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  221. "type": "afs_handle_alloc_error",
  222. "msg": err.Error(),
  223. })
  224. var ecode int32 = -1
  225. stack[0] = uint64(ecode)
  226. return
  227. }
  228. }
  229. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  230. "type": "afs_create_bpfs_ok",
  231. "handle": fmt.Sprintf("%d", h),
  232. "base-afs": fmt.Sprintf("%d", hBaseAfs),
  233. "base-path": string(basePath),
  234. })
  235. stack[0] = uint64(h)
  236. return
  237. }
  238. func (a *InitWAVMHostModuleAdapter) efnAfsCreateRegFs(_ context.Context, mod wa_api.Module, stack []uint64) {
  239. hBaseAfs := int32(stack[0])
  240. ptrRegExp := uint32(stack[1])
  241. lenRegExp := uint32(stack[2])
  242. strRegExp, ok := mod.Memory().Read(ptrRegExp, lenRegExp)
  243. if !ok {
  244. var ecode int32 = -3
  245. stack[0] = uint64(ecode)
  246. return
  247. }
  248. if hBaseAfs <= 0 {
  249. var ecode int32 = -2
  250. stack[0] = uint64(ecode)
  251. return
  252. }
  253. objBaseAfs, ok := a.api.AferoFsInstancesMgr.Get(hBaseAfs)
  254. if !ok {
  255. var ecode int32 = -2
  256. stack[0] = uint64(ecode)
  257. return
  258. }
  259. cpdRegExp, err := regexp.Compile(string(strRegExp))
  260. if err != nil {
  261. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  262. "type": "afs_regfs_regexp_compile_error",
  263. "msg": err.Error(),
  264. })
  265. var ecode int32 = -4
  266. stack[0] = uint64(ecode)
  267. return
  268. }
  269. regfs := afero.NewRegexpFs(objBaseAfs.Fs, cpdRegExp)
  270. afsObj := &AferoFsInstance{
  271. Fs: regfs,
  272. TypeDescription: "afero-regexp-fs",
  273. }
  274. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  275. if err != nil {
  276. if err == go_int32_handle.ErrHandleExceedMax {
  277. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  278. "type": "afs_handle_alloc_error",
  279. "msg": "handle exceed max",
  280. })
  281. var ecode int32 = -1
  282. stack[0] = uint64(ecode)
  283. return
  284. } else {
  285. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  286. "type": "afs_handle_alloc_error",
  287. "msg": err.Error(),
  288. })
  289. var ecode int32 = -1
  290. stack[0] = uint64(ecode)
  291. return
  292. }
  293. }
  294. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  295. "type": "afs_create_regfs_ok",
  296. "handle": fmt.Sprintf("%d", h),
  297. "base-afs": fmt.Sprintf("%d", hBaseAfs),
  298. "regexp": string(strRegExp),
  299. })
  300. stack[0] = uint64(h)
  301. return
  302. }
  303. func (a *InitWAVMHostModuleAdapter) efnAfsCreateRoFs(_ context.Context, _ wa_api.Module, stack []uint64) {
  304. hBaseAfs := int32(stack[0])
  305. if hBaseAfs <= 0 {
  306. var ecode int32 = -2
  307. stack[0] = uint64(ecode)
  308. return
  309. }
  310. objBaseAfs, ok := a.api.AferoFsInstancesMgr.Get(hBaseAfs)
  311. if !ok {
  312. var ecode int32 = -2
  313. stack[0] = uint64(ecode)
  314. return
  315. }
  316. rofs := afero.NewReadOnlyFs(objBaseAfs.Fs)
  317. afsObj := &AferoFsInstance{
  318. Fs: rofs,
  319. TypeDescription: "afero-readonly-fs",
  320. }
  321. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  322. if err != nil {
  323. if err == go_int32_handle.ErrHandleExceedMax {
  324. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  325. "type": "afs_handle_alloc_error",
  326. "msg": "handle exceed max",
  327. })
  328. var ecode int32 = -1
  329. stack[0] = uint64(ecode)
  330. return
  331. } else {
  332. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  333. "type": "afs_handle_alloc_error",
  334. "msg": err.Error(),
  335. })
  336. var ecode int32 = -1
  337. stack[0] = uint64(ecode)
  338. return
  339. }
  340. }
  341. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  342. "type": "afs_create_rofs_ok",
  343. "handle": fmt.Sprintf("%d", h),
  344. "base-afs": fmt.Sprintf("%d", hBaseAfs),
  345. })
  346. stack[0] = uint64(h)
  347. return
  348. }
  349. func (a *InitWAVMHostModuleAdapter) efnAfsCreateCowFs(_ context.Context, _ wa_api.Module, stack []uint64) {
  350. hRoAfs := int32(stack[0])
  351. hWrAfs := int32(stack[1])
  352. if hRoAfs <= 0 {
  353. var ecode int32 = -2
  354. stack[0] = uint64(ecode)
  355. return
  356. }
  357. objRoAfs, ok := a.api.AferoFsInstancesMgr.Get(hRoAfs)
  358. if !ok {
  359. var ecode int32 = -2
  360. stack[0] = uint64(ecode)
  361. return
  362. }
  363. if hWrAfs <= 0 {
  364. var ecode int32 = -3
  365. stack[0] = uint64(ecode)
  366. return
  367. }
  368. objWrAfs, ok := a.api.AferoFsInstancesMgr.Get(hWrAfs)
  369. if !ok {
  370. var ecode int32 = -3
  371. stack[0] = uint64(ecode)
  372. return
  373. }
  374. cowfs := afero.NewCopyOnWriteFs(objRoAfs.Fs, objWrAfs.Fs)
  375. afsObj := &AferoFsInstance{
  376. Fs: cowfs,
  377. TypeDescription: "afero-copy-on-write-fs",
  378. }
  379. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  380. if err != nil {
  381. if err == go_int32_handle.ErrHandleExceedMax {
  382. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  383. "type": "afs_handle_alloc_error",
  384. "msg": "handle exceed max",
  385. })
  386. var ecode int32 = -1
  387. stack[0] = uint64(ecode)
  388. return
  389. } else {
  390. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  391. "type": "afs_handle_alloc_error",
  392. "msg": err.Error(),
  393. })
  394. var ecode int32 = -1
  395. stack[0] = uint64(ecode)
  396. return
  397. }
  398. }
  399. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  400. "type": "afs_create_cowfs_ok",
  401. "handle": fmt.Sprintf("%d", h),
  402. "base-ro-afs": fmt.Sprintf("%d", hRoAfs),
  403. "base-wr-afs": fmt.Sprintf("%d", hWrAfs),
  404. })
  405. stack[0] = uint64(h)
  406. return
  407. }
  408. func (a *InitWAVMHostModuleAdapter) efnAfsCreateCorFs(_ context.Context, _ wa_api.Module, stack []uint64) {
  409. hRoAfs := int32(stack[0])
  410. hWrAfs := int32(stack[1])
  411. cacheTime := int32(stack[3])
  412. if cacheTime < 0 {
  413. var ecode int32 = -4
  414. stack[0] = uint64(ecode)
  415. return
  416. }
  417. if hRoAfs <= 0 {
  418. var ecode int32 = -2
  419. stack[0] = uint64(ecode)
  420. return
  421. }
  422. objRoAfs, ok := a.api.AferoFsInstancesMgr.Get(hRoAfs)
  423. if !ok {
  424. var ecode int32 = -2
  425. stack[0] = uint64(ecode)
  426. return
  427. }
  428. if hWrAfs <= 0 {
  429. var ecode int32 = -3
  430. stack[0] = uint64(ecode)
  431. return
  432. }
  433. objWrAfs, ok := a.api.AferoFsInstancesMgr.Get(hWrAfs)
  434. if !ok {
  435. var ecode int32 = -3
  436. stack[0] = uint64(ecode)
  437. return
  438. }
  439. cacheTimeDuration := time.Duration(cacheTime) * time.Second
  440. corfs := afero.NewCacheOnReadFs(objRoAfs.Fs, objWrAfs.Fs, cacheTimeDuration)
  441. afsObj := &AferoFsInstance{
  442. Fs: corfs,
  443. TypeDescription: "afero-cache-on-read-fs",
  444. }
  445. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  446. if err != nil {
  447. if err == go_int32_handle.ErrHandleExceedMax {
  448. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  449. "type": "afs_handle_alloc_error",
  450. "msg": "handle exceed max",
  451. })
  452. var ecode int32 = -1
  453. stack[0] = uint64(ecode)
  454. return
  455. } else {
  456. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  457. "type": "afs_handle_alloc_error",
  458. "msg": err.Error(),
  459. })
  460. var ecode int32 = -1
  461. stack[0] = uint64(ecode)
  462. return
  463. }
  464. }
  465. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  466. "type": "afs_create_corfs_ok",
  467. "handle": fmt.Sprintf("%d", h),
  468. "base-ro-afs": fmt.Sprintf("%d", hRoAfs),
  469. "base-wr-afs": fmt.Sprintf("%d", hWrAfs),
  470. "cache-time": cacheTimeDuration.String(),
  471. })
  472. stack[0] = uint64(h)
  473. return
  474. }
  475. func (a *InitWAVMHostModuleAdapter) efnAfsCreateBepOvFs(_ context.Context, mod wa_api.Module, stack []uint64) {
  476. ptrAfsArray := uint32(stack[0])
  477. lenAfsArray := uint32(stack[1])
  478. intIsWritable := int32(stack[2])
  479. boolIsWritable := intIsWritable > 0
  480. if lenAfsArray == 0 {
  481. var ecode int32 = -1
  482. stack[0] = uint64(ecode)
  483. return
  484. }
  485. sliceAfsHandleArray := make([]int32, lenAfsArray)
  486. var i uint32
  487. for i = 0; i < lenAfsArray; i++ {
  488. offset := ptrAfsArray + i*4
  489. b, ok := mod.Memory().Read(offset, 4)
  490. if !ok {
  491. var ecode int32 = -2
  492. stack[0] = uint64(ecode)
  493. return
  494. }
  495. if len(b) != 4 {
  496. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  497. "type": "afs_create_bep_ovfs_error",
  498. "sub-type": "read_fs_layer_array_error",
  499. "msg": "the length of the array element is not 4",
  500. "i": fmt.Sprintf("%d", i),
  501. "offset": fmt.Sprintf("%d", offset),
  502. "len": fmt.Sprintf("%d", len(b)),
  503. })
  504. var ecode int32 = -3
  505. stack[0] = uint64(ecode)
  506. return
  507. }
  508. sliceAfsHandleArray[i] = int32(binary.LittleEndian.Uint32(b))
  509. }
  510. afsObjArray := make([]afero.Fs, lenAfsArray)
  511. for i, v := range sliceAfsHandleArray {
  512. if v <= 0 {
  513. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  514. "type": "afs_create_bep_ovfs_error",
  515. "sub-type": "read_fs_layer_invalid_handle",
  516. "msg": "the value of this element is a invalid handle",
  517. "i": fmt.Sprintf("%d", i),
  518. "handle": fmt.Sprintf("%d", v),
  519. })
  520. var ecode int32 = -4
  521. stack[0] = uint64(ecode)
  522. return
  523. }
  524. objV, ok := a.api.AferoFsInstancesMgr.Get(v)
  525. if !ok {
  526. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  527. "type": "afs_create_bep_ovfs_error",
  528. "sub-type": "read_fs_layer_invalid_handle",
  529. "msg": "the value of this element is a invalid handle",
  530. "i": fmt.Sprintf("%d", i),
  531. "handle": fmt.Sprintf("%d", v),
  532. })
  533. var ecode int32 = -4
  534. stack[0] = uint64(ecode)
  535. return
  536. }
  537. a.logger.LogComplex("openngvfs", hiedalog.DLN_DEBUG, map[string]string{
  538. "type": "afs_create_bep_ovfs_debug",
  539. "sub-type": "get_valid_fs_layer",
  540. "i": fmt.Sprintf("%d", i),
  541. "handle": fmt.Sprintf("%d", v),
  542. "fs-name": objV.Fs.Name(),
  543. "fs-desc": objV.TypeDescription,
  544. })
  545. afsObjArray[i] = objV.Fs
  546. }
  547. ovfsOpt := overlayfs.Options{
  548. Fss: afsObjArray,
  549. FirstWritable: boolIsWritable,
  550. DirsMerger: nil,
  551. }
  552. ovfs := overlayfs.New(ovfsOpt)
  553. afsObj := &AferoFsInstance{
  554. Fs: ovfs,
  555. TypeDescription: "3rd-party-bep-overlayfs",
  556. }
  557. h, err := a.api.AferoFsInstancesMgr.AllocateAndPut(afsObj)
  558. if err != nil {
  559. if err == go_int32_handle.ErrHandleExceedMax {
  560. a.logger.LogComplex("openngvfs", hiedalog.DLN_WARN, map[string]string{
  561. "type": "afs_handle_alloc_error",
  562. "msg": "handle exceed max",
  563. })
  564. var ecode int32 = -5
  565. stack[0] = uint64(ecode)
  566. return
  567. } else {
  568. a.logger.LogComplex("openngvfs", hiedalog.DLN_ERROR, map[string]string{
  569. "type": "afs_handle_alloc_error",
  570. "msg": err.Error(),
  571. })
  572. var ecode int32 = -5
  573. stack[0] = uint64(ecode)
  574. return
  575. }
  576. }
  577. a.logger.LogComplex("openngvfs-debug", hiedalog.DLN_DEBUG, map[string]string{
  578. "type": "afs_create_bep_ovfs_ok",
  579. "handle": fmt.Sprintf("%d", h),
  580. })
  581. stack[0] = uint64(h)
  582. return
  583. }