File: linux_devices.go

package info (click to toggle)
golang-github-opencontainers-runtime-tools 0.9.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,108 kB
  • sloc: sh: 557; makefile: 104
file content (58 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (4)
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
package main

import (
	"os"

	rspecs "github.com/opencontainers/runtime-spec/specs-go"
	"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
	g, err := util.GetDefaultGenerator()
	if err != nil {
		util.Fatal(err)
	}

	// add char device
	cdev := rspecs.LinuxDevice{}
	cdev.Path = "/dev/test1"
	cdev.Type = "c"
	cdev.Major = 10
	cdev.Minor = 666
	cmode := os.FileMode(int32(432))
	cdev.FileMode = &cmode
	cuid := uint32(0)
	cdev.UID = &cuid
	cgid := uint32(0)
	cdev.GID = &cgid
	g.AddDevice(cdev)

	// add block device
	bdev := rspecs.LinuxDevice{}
	bdev.Path = "/dev/test2"
	bdev.Type = "b"
	bdev.Major = 8
	bdev.Minor = 666
	bmode := os.FileMode(int32(432))
	bdev.FileMode = &bmode
	uid := uint32(0)
	bdev.UID = &uid
	gid := uint32(0)
	bdev.GID = &gid
	g.AddDevice(bdev)

	// add fifo device
	pdev := rspecs.LinuxDevice{}
	pdev.Path = "/dev/test3"
	pdev.Type = "p"
	pdev.Major = 8
	pdev.Minor = 666
	pmode := os.FileMode(int32(432))
	pdev.FileMode = &pmode
	g.AddDevice(pdev)

	err = util.RuntimeInsideValidate(g, nil, nil)
	if err != nil {
		util.Fatal(err)
	}
}