github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/mkdir/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) != 2 {
    13  		fmt.Printf("Usage: %s dir_path\n", os.Args[0])
    14  		return
    15  	}
    16  	path := os.Args[1]
    17  
    18  	iour, err := iouring.New(1)
    19  	if err != nil {
    20  		panic(err)
    21  	}
    22  	defer iour.Close()
    23  
    24  	pathDir, err := os.Open(filepath.Dir(path))
    25  	if err != nil {
    26  		fmt.Printf("open directory error: %v\n", err)
    27  		return
    28  	}
    29  	defer pathDir.Close()
    30  
    31  	pr, err := iouring.Mkdirat(int(pathDir.Fd()), filepath.Base(path), 0)
    32  	if err != nil {
    33  		fmt.Printf("prep request error: %v\n", err)
    34  		return
    35  	}
    36  	request, err := iour.SubmitRequest(pr, nil)
    37  	<-request.Done()
    38  	if err := request.Err(); err != nil {
    39  		fmt.Printf("submit iouring request error: %v\n", err)
    40  		return
    41  	}
    42  }