github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/hardlink/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 "github.com/iceber/iouring-go" 9 ) 10 11 func main() { 12 if len(os.Args) != 3 { 13 fmt.Printf("Usage: %s target link\n", os.Args[0]) 14 return 15 } 16 target := os.Args[1] 17 link := os.Args[2] 18 19 iour, err := iouring.New(1) 20 if err != nil { 21 panic(err) 22 } 23 defer iour.Close() 24 25 targetDir, err := os.Open(filepath.Dir(target)) 26 if err != nil { 27 fmt.Printf("open old directory error: %v\n", err) 28 return 29 } 30 linkDir, err := os.Open(filepath.Dir(link)) 31 if err != nil { 32 fmt.Printf("open new directory error: %v\n", err) 33 return 34 } 35 36 pr, err := iouring.Linkat( 37 int(targetDir.Fd()), filepath.Base(target), 38 int(linkDir.Fd()), filepath.Base(link), 0) 39 if err != nil { 40 fmt.Printf("prep request error: %v\n", err) 41 return 42 } 43 request, err := iour.SubmitRequest(pr, nil) 44 <-request.Done() 45 if err := request.Err(); err != nil { 46 return 47 } 48 }