MCPcopy
hub / github.com/opencontainers/runc / createDeviceNode

Function createDeviceNode

libcontainer/rootfs_linux.go:988–1011  ·  view source on GitHub ↗

Creates the device node in the rootfs of the container.

(rootFd *os.File, node *devices.Device, bind bool)

Source from the content-addressed store, hash-verified

986
987// Creates the device node in the rootfs of the container.
988func createDeviceNode(rootFd *os.File, node *devices.Device, bind bool) error {
989 if node.Path == "" {
990 // The node only exists for cgroup reasons, ignore it here.
991 return nil
992 }
993 destDir, destName, err := pathrs.MkdirAllParentInRoot(rootFd, node.Path, 0o755)
994 if err != nil {
995 return fmt.Errorf("mkdir parent of device inode %q: %w", node.Path, err)
996 }
997 defer destDir.Close()
998
999 if bind {
1000 return bindMountDeviceNode(destDir, destName, node)
1001 }
1002 if err := mknodDevice(destDir, destName, node); err != nil {
1003 if errors.Is(err, os.ErrExist) {
1004 return nil
1005 } else if errors.Is(err, os.ErrPermission) {
1006 return bindMountDeviceNode(destDir, destName, node)
1007 }
1008 return err
1009 }
1010 return nil
1011}
1012
1013func mknodDevice(destDir *os.File, destName string, node *devices.Device) error {
1014 fileMode := node.FileMode

Callers 1

createDevicesFunction · 0.85

Calls 4

MkdirAllParentInRootFunction · 0.92
bindMountDeviceNodeFunction · 0.85
mknodDeviceFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…