github.com/opencontainers/runtime-tools@v0.9.0/validation/linux_devices/linux_devices.go (about) 1 package main 2 3 import ( 4 "os" 5 6 rspecs "github.com/opencontainers/runtime-spec/specs-go" 7 "github.com/opencontainers/runtime-tools/validation/util" 8 ) 9 10 func main() { 11 g, err := util.GetDefaultGenerator() 12 if err != nil { 13 util.Fatal(err) 14 } 15 16 // add char device 17 cdev := rspecs.LinuxDevice{} 18 cdev.Path = "/dev/test1" 19 cdev.Type = "c" 20 cdev.Major = 10 21 cdev.Minor = 666 22 cmode := os.FileMode(int32(432)) 23 cdev.FileMode = &cmode 24 cuid := uint32(0) 25 cdev.UID = &cuid 26 cgid := uint32(0) 27 cdev.GID = &cgid 28 g.AddDevice(cdev) 29 30 // add block device 31 bdev := rspecs.LinuxDevice{} 32 bdev.Path = "/dev/test2" 33 bdev.Type = "b" 34 bdev.Major = 8 35 bdev.Minor = 666 36 bmode := os.FileMode(int32(432)) 37 bdev.FileMode = &bmode 38 uid := uint32(0) 39 bdev.UID = &uid 40 gid := uint32(0) 41 bdev.GID = &gid 42 g.AddDevice(bdev) 43 44 // add fifo device 45 pdev := rspecs.LinuxDevice{} 46 pdev.Path = "/dev/test3" 47 pdev.Type = "p" 48 pdev.Major = 8 49 pdev.Minor = 666 50 pmode := os.FileMode(int32(432)) 51 pdev.FileMode = &pmode 52 g.AddDevice(pdev) 53 54 err = util.RuntimeInsideValidate(g, nil, nil) 55 if err != nil { 56 util.Fatal(err) 57 } 58 }