-
Notifications
You must be signed in to change notification settings - Fork 43
/
prep_request.go
778 lines (670 loc) · 17.8 KB
/
prep_request.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//go:build linux
// +build linux
package iouring
import (
"errors"
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
iouring_syscall "github.com/iceber/iouring-go/syscall"
)
type PrepRequest func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData)
// WithInfo request with extra info
func (prepReq PrepRequest) WithInfo(info interface{}) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
prepReq(sqe, userData)
userData.SetRequestInfo(info)
}
}
func (prepReq PrepRequest) WithDrain() PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
prepReq(sqe, userData)
sqe.SetFlags(iouring_syscall.IOSQE_FLAGS_IO_DRAIN)
}
}
func (prepReq PrepRequest) WithCallback(callback RequestCallback) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
prepReq(sqe, userData)
userData.SetRequestCallback(callback)
}
}
func (iour *IOURing) Read(file *os.File, b []byte, ch chan<- Result) (Request, error) {
fd := int(file.Fd())
if fd < 0 {
return nil, errors.New("invalid file")
}
return iour.SubmitRequest(Read(fd, b), ch)
}
func (iour *IOURing) Write(file *os.File, b []byte, ch chan<- Result) (Request, error) {
fd := int(file.Fd())
if fd < 0 {
return nil, errors.New("invalid file")
}
return iour.SubmitRequest(Write(fd, b), ch)
}
func (iour *IOURing) Pread(file *os.File, b []byte, offset uint64, ch chan<- Result) (Request, error) {
fd := int(file.Fd())
if fd < 0 {
return nil, errors.New("invalid file")
}
return iour.SubmitRequest(Pread(fd, b, offset), ch)
}
func (iour *IOURing) Pwrite(file *os.File, b []byte, offset uint64, ch chan<- Result) (Request, error) {
fd := int(file.Fd())
if fd < 0 {
return nil, errors.New("invalid file")
}
return iour.SubmitRequest(Pwrite(fd, b, offset), ch)
}
func Nop() PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
sqe.PrepOperation(iouring_syscall.IORING_OP_NOP, -1, 0, 0, 0)
}
}
func Read(fd int, b []byte) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_READ,
int32(fd),
uint64(uintptr(bp)),
uint32(len(b)),
0,
)
}
}
func Pread(fd int, b []byte, offset uint64) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_READ,
int32(fd),
uint64(uintptr(bp)),
uint32(len(b)),
uint64(offset),
)
}
}
func Write(fd int, b []byte) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_WRITE,
int32(fd),
uint64(uintptr(bp)),
uint32(len(b)),
0,
)
}
}
func Pwrite(fd int, b []byte, offset uint64) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_WRITE,
int32(fd),
uint64(uintptr(bp)),
uint32(len(b)),
uint64(offset),
)
}
}
func Readv(fd int, bs [][]byte) PrepRequest {
iovecs := bytes2iovec(bs)
var bp unsafe.Pointer
if len(iovecs) > 0 {
bp = unsafe.Pointer(&iovecs[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffers(bs)
sqe.PrepOperation(
iouring_syscall.IORING_OP_READV,
int32(fd),
uint64(uintptr(bp)),
uint32(len(iovecs)),
0,
)
}
}
func Preadv(fd int, bs [][]byte, offset uint64) PrepRequest {
iovecs := bytes2iovec(bs)
var bp unsafe.Pointer
if len(iovecs) > 0 {
bp = unsafe.Pointer(&iovecs[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffers(bs)
sqe.PrepOperation(iouring_syscall.IORING_OP_READV,
int32(fd),
uint64(uintptr(bp)),
uint32(len(iovecs)),
offset,
)
}
}
func Writev(fd int, bs [][]byte) PrepRequest {
iovecs := bytes2iovec(bs)
var bp unsafe.Pointer
if len(iovecs) > 0 {
bp = unsafe.Pointer(&iovecs[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffers(bs)
sqe.PrepOperation(
iouring_syscall.IORING_OP_WRITEV,
int32(fd),
uint64(uintptr(bp)),
uint32(len(iovecs)),
0,
)
}
}
func Pwritev(fd int, bs [][]byte, offset int64) PrepRequest {
iovecs := bytes2iovec(bs)
var bp unsafe.Pointer
if len(iovecs) > 0 {
bp = unsafe.Pointer(&iovecs[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = fdResolver
userData.SetRequestBuffers(bs)
sqe.PrepOperation(
iouring_syscall.IORING_OP_WRITEV,
int32(fd),
uint64(uintptr(bp)),
uint32(len(iovecs)),
uint64(offset),
)
}
}
func Send(sockfd int, b []byte, flags int) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_SEND,
int32(sockfd),
uint64(uintptr(bp)),
uint32(len(b)),
0,
)
sqe.SetOpFlags(uint32(flags))
}
}
func Recv(sockfd int, b []byte, flags int) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_RECV,
int32(sockfd),
uint64(uintptr(bp)),
uint32(len(b)),
0,
)
sqe.SetOpFlags(uint32(flags))
}
}
func Sendmsg(sockfd int, p, oob []byte, to syscall.Sockaddr, flags int) (PrepRequest, error) {
var ptr unsafe.Pointer
var salen uint32
if to != nil {
var err error
ptr, salen, err = sockaddr(to)
if err != nil {
return nil, err
}
}
msg := &syscall.Msghdr{}
msg.Name = (*byte)(ptr)
msg.Namelen = uint32(salen)
var iov syscall.Iovec
if len(p) > 0 {
iov.Base = &p[0]
iov.SetLen(len(p))
}
var dummy byte
if len(oob) > 0 {
if len(p) == 0 {
var sockType int
sockType, err := syscall.GetsockoptInt(sockfd, syscall.SOL_SOCKET, syscall.SO_TYPE)
if err != nil {
return nil, err
}
// send at least one normal byte
if sockType != syscall.SOCK_DGRAM {
iov.Base = &dummy
iov.SetLen(1)
}
}
msg.Control = &oob[0]
msg.SetControllen(len(oob))
}
msg.Iov = &iov
msg.Iovlen = 1
resolver := func(req Request) {
result := req.(*request)
result.r0 = int(result.res)
errResolver(result)
if result.err != nil {
return
}
if len(oob) > 0 && len(p) == 0 {
result.r0 = 0
}
}
msgptr := unsafe.Pointer(msg)
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(msg, to)
userData.request.resolver = resolver
userData.SetRequestBuffer(p, oob)
sqe.PrepOperation(iouring_syscall.IORING_OP_SENDMSG, int32(sockfd), uint64(uintptr(msgptr)), 1, 0)
sqe.SetOpFlags(uint32(flags))
}, nil
}
func Recvmsg(sockfd int, p, oob []byte, to syscall.Sockaddr, flags int) (PrepRequest, error) {
var msg syscall.Msghdr
var rsa syscall.RawSockaddrAny
msg.Name = (*byte)(unsafe.Pointer(&rsa))
msg.Namelen = uint32(syscall.SizeofSockaddrAny)
var iov syscall.Iovec
if len(p) > 0 {
iov.Base = &p[0]
iov.SetLen(len(p))
}
var dummy byte
if len(oob) > 0 {
if len(p) == 0 {
var sockType int
sockType, err := syscall.GetsockoptInt(sockfd, syscall.SOL_SOCKET, syscall.SO_TYPE)
if err != nil {
return nil, err
}
// receive at least one normal byte
if sockType != syscall.SOCK_DGRAM {
iov.Base = &dummy
iov.SetLen(1)
}
}
msg.Control = &oob[0]
msg.SetControllen(len(oob))
}
msg.Iov = &iov
msg.Iovlen = 1
resolver := func(req Request) {
result := req.(*request)
result.r0 = int(result.res)
errResolver(result)
if result.err != nil {
return
}
if len(oob) > 0 && len(p) == 0 {
result.r0 = 0
}
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&msg, &rsa)
userData.request.resolver = resolver
userData.SetRequestBuffer(p, oob)
sqe.PrepOperation(
iouring_syscall.IORING_OP_RECVMSG,
int32(sockfd),
uint64(uintptr(unsafe.Pointer(&msg))),
1,
0,
)
sqe.SetOpFlags(uint32(flags))
}, nil
}
func Accept(sockfd int) PrepRequest {
var rsa syscall.RawSockaddrAny
var len uint32 = syscall.SizeofSockaddrAny
resolver := func(req Request) {
result := req.(*request)
fd := int(result.res)
errResolver(result)
if result.err != nil {
return
}
result.r0 = fd
result.r1, result.err = anyToSockaddr(&rsa)
if result.err != nil {
syscall.Close(fd)
result.r0 = 0
}
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&len)
userData.request.resolver = resolver
sqe.PrepOperation(iouring_syscall.IORING_OP_ACCEPT, int32(sockfd), uint64(uintptr(unsafe.Pointer(&rsa))), 0, uint64(uintptr(unsafe.Pointer(&len))))
}
}
func Accept4(sockfd int, flags int) PrepRequest {
var rsa syscall.RawSockaddrAny
var len uint32 = syscall.SizeofSockaddrAny
resolver := func(req Request) {
result := req.(*request)
fd := int(result.res)
errResolver(result)
if result.err != nil {
return
}
if len > syscall.SizeofSockaddrAny {
panic("RawSockaddrAny too small")
}
result.r0 = fd
result.r1, result.err = anyToSockaddr(&rsa)
if result.err != nil {
syscall.Close(fd)
result.r0 = 0
}
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&rsa, &len)
userData.request.resolver = resolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_ACCEPT,
int32(sockfd),
uint64(uintptr(unsafe.Pointer(&rsa))),
0,
uint64(uintptr(unsafe.Pointer(&len))),
)
sqe.SetOpFlags(uint32(flags))
}
}
func Connect(sockfd int, sa syscall.Sockaddr) (PrepRequest, error) {
ptr, n, err := sockaddr(sa)
if err != nil {
return nil, err
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(sa)
userData.request.resolver = errResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_CONNECT,
int32(sockfd),
uint64(uintptr(ptr)),
0,
uint64(n),
)
}, nil
}
func Openat(dirfd int, path string, flags uint32, mode uint32) (PrepRequest, error) {
flags |= syscall.O_LARGEFILE
b, err := syscall.ByteSliceFromString(path)
if err != nil {
return nil, err
}
bp := unsafe.Pointer(&b[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&b)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_OPENAT,
int32(dirfd),
uint64(uintptr(bp)),
mode,
0,
)
sqe.SetOpFlags(flags)
}, nil
}
func Openat2(dirfd int, path string, how *unix.OpenHow) (PrepRequest, error) {
b, err := syscall.ByteSliceFromString(path)
if err != nil {
return nil, err
}
bp := unsafe.Pointer(&b[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&b)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_OPENAT2,
int32(dirfd),
uint64(uintptr(bp)),
unix.SizeofOpenHow,
uint64(uintptr(unsafe.Pointer(how))),
)
}, nil
}
func Statx(dirfd int, path string, flags uint32, mask int, stat *unix.Statx_t) (PrepRequest, error) {
b, err := syscall.ByteSliceFromString(path)
if err != nil {
return nil, err
}
bp := unsafe.Pointer(&b[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
userData.hold(&b, stat)
sqe.PrepOperation(
iouring_syscall.IORING_OP_STATX,
int32(dirfd),
uint64(uintptr(bp)),
uint32(mask),
uint64(uintptr(unsafe.Pointer(stat))),
)
sqe.SetOpFlags(flags)
}, nil
}
func Fsync(fd int) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
sqe.PrepOperation(iouring_syscall.IORING_OP_FSYNC, int32(fd), 0, 0, 0)
}
}
func Fdatasync(fd int) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
sqe.PrepOperation(iouring_syscall.IORING_OP_FSYNC, int32(fd), 0, 0, 0)
sqe.SetOpFlags(iouring_syscall.IORING_FSYNC_DATASYNC)
}
}
func Fallocate(fd int, mode uint32, off int64, length int64) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_FALLOCATE,
int32(fd),
uint64(length),
uint32(mode),
uint64(off),
)
}
}
func Close(fd int) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
sqe.PrepOperation(iouring_syscall.IORING_OP_CLOSE, int32(fd), 0, 0, 0)
}
}
func Madvise(b []byte, advice int) PrepRequest {
var bp unsafe.Pointer
if len(b) > 0 {
bp = unsafe.Pointer(&b[0])
} else {
bp = unsafe.Pointer(&_zero)
}
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
userData.SetRequestBuffer(b, nil)
sqe.PrepOperation(
iouring_syscall.IORING_OP_MADVISE,
-1,
uint64(uintptr(bp)),
uint32(len(b)),
0,
)
sqe.SetOpFlags(uint32(advice))
}
}
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) PrepRequest {
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.request.resolver = errResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_EPOLL_CTL,
int32(epfd),
uint64(uintptr(unsafe.Pointer(event))),
uint32(op),
uint64(fd),
)
}
}
func Mkdirat(dirFd int, path string, mode uint32) (PrepRequest, error) {
b, err := syscall.ByteSliceFromString(path)
if err != nil {
return nil, err
}
bp := unsafe.Pointer(&b[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&b)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_MKDIRAT,
int32(dirFd),
uint64(uintptr(bp)),
mode,
0,
)
}, nil
}
func Unlinkat(fd int, path string, flags int32) (PrepRequest, error) {
b, err := syscall.ByteSliceFromString(path)
if err != nil {
return nil, err
}
bp := unsafe.Pointer(&b[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&b)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_UNLINKAT,
int32(fd),
uint64(uintptr(bp)),
0,
0,
)
sqe.SetOpFlags(uint32(flags))
}, nil
}
func Symlinkat(target string, newDirFd int, linkPath string) (PrepRequest, error) {
bTarget, err := syscall.ByteSliceFromString(target)
if err != nil {
return nil, err
}
bLink, err := syscall.ByteSliceFromString(linkPath)
if err != nil {
return nil, err
}
bpTarget := unsafe.Pointer(&bTarget[0])
bpLink := unsafe.Pointer(&bLink[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&bTarget, &bLink)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_SYMLINKAT,
int32(newDirFd),
uint64(uintptr(bpTarget)),
0,
uint64(uintptr(bpLink)),
)
}, nil
}
func Renameat2(oldDirFd int, oldPath string, newDirFd int, newPath string, flags int) (PrepRequest, error) {
bOldPath, err := syscall.ByteSliceFromString(oldPath)
if err != nil {
return nil, err
}
bNewPath, err := syscall.ByteSliceFromString(newPath)
if err != nil {
return nil, err
}
bpOldPath := unsafe.Pointer(&bOldPath[0])
bpNewPath := unsafe.Pointer(&bNewPath[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&bOldPath, &bNewPath)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_RENAMEAT,
int32(oldDirFd), uint64(uintptr(bpOldPath)),
uint32(newDirFd), uint64(uintptr(bpNewPath)),
)
sqe.SetOpFlags(uint32(flags))
}, nil
}
func Renameat(oldDirFd int, oldPath string, newDirFd int, newPath string) (PrepRequest, error) {
return Renameat2(oldDirFd, oldPath, newDirFd, newPath, 0)
}
func Linkat(targetDirFd int, targetPath string, linkDirFd int, linkPath string, flags int) (PrepRequest, error) {
bTargetPath, err := syscall.ByteSliceFromString(targetPath)
if err != nil {
return nil, err
}
bLinkPath, err := syscall.ByteSliceFromString(linkPath)
if err != nil {
return nil, err
}
bpTargetPath := unsafe.Pointer(&bTargetPath[0])
bpLinkPath := unsafe.Pointer(&bLinkPath[0])
return func(sqe iouring_syscall.SubmissionQueueEntry, userData *UserData) {
userData.hold(&bpTargetPath, &bpLinkPath)
userData.request.resolver = fdResolver
sqe.PrepOperation(
iouring_syscall.IORING_OP_LINKAT,
int32(targetDirFd),
uint64(uintptr(bpTargetPath)),
uint32(linkDirFd),
uint64(uintptr(bpLinkPath)),
)
sqe.SetOpFlags(uint32(flags))
}, nil
}