// Copyright (c) 2026 Petr BalvĂ­n (https://petrbalvin.org) // SPDX-License-Identifier: MIT //go:build darwin package nfsfs import "syscall" // mknod creates a device node. It needs the superuser on darwin, and a // failure of permission is reported as such rather than as an io error. // The kind is picked before the single call: a second mknod over an // existing node fails EEXIST and leaves the wrong kind behind. func mknod(path string, spec CreateSpec, perm uint32) error { dev := makedev(spec.Major, spec.Minor) kind := uint32(syscall.S_IFCHR) if spec.Kind == KindBlk { kind = syscall.S_IFBLK } return syscall.Mknod(path, perm|kind, int(dev)) } // makedev assembles a device number the way the kernel expects it: the // encoding of makedev in bsd/sys/types.h of xnu, where the major number // sits at bits twenty-four through thirty-one and the minor number keeps // bits zero through twenty-three. func makedev(major, minor uint32) uint64 { return uint64(major&0xff)<<24 | uint64(minor&0xffffff) }