MCPcopy Index your code
hub / github.com/coder/envbox / createDevice

Function createDevice

xunix/device.go:101–124  ·  view source on GitHub ↗
(ctx context.Context, conf deviceConfig)

Source from the content-addressed store, hash-verified

99}
100
101func createDevice(ctx context.Context, conf deviceConfig) error {
102 var (
103 fs = GetFS(ctx)
104 dir = filepath.Dir(conf.path)
105 )
106
107 err := fs.MkdirAll(dir, 0o700)
108 if err != nil {
109 return xerrors.Errorf("ensure parent dir: %w", err)
110 }
111
112 //nolint:gosec
113 err = fs.Mknod(conf.path, conf.ftype|conf.mode, int(conf.dev))
114 if err != nil {
115 return xerrors.Errorf("mknod %s c %d %d: %w", conf.path, conf.major, conf.minor, err)
116 }
117
118 err = fs.Chmod(conf.path, os.FileMode(conf.mode))
119 if err != nil {
120 return xerrors.Errorf("chown %v %q: %w", conf.mode, conf.path, err)
121 }
122
123 return nil
124}
125
126func dev(major, minor uint) uint {
127 // This is lifted from the Linux kernel's makedev function.

Callers 2

CreateTUNDeviceFunction · 0.85
CreateFuseDeviceFunction · 0.85

Calls 3

GetFSFunction · 0.85
ErrorfMethod · 0.65
MknodMethod · 0.65

Tested by

no test coverage detected