Created
February 18, 2024 02:56
-
-
Save t0rr3sp3dr0/8361930bc4b01f7a2d45f13afbb7d018 to your computer and use it in GitHub Desktop.
macOS POSIX File Path from Device Number and Inode Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo LDFLAGS: -framework Carbon | |
// #include <Carbon/Carbon.h> | |
import "C" | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
func MakePath(dev uint64, ino uint64) (string, error) { | |
vol := fmt.Sprintf("/.vol/%d/%d", dev, ino) | |
volC := C.CString(vol) | |
defer C.free(unsafe.Pointer(volC)) | |
var refC C.FSRef | |
if statusC := C.FSPathMakeRefWithOptions((*C.UInt8)(unsafe.Pointer(volC)), C.kFSPathMakeRefDoNotFollowLeafSymlink, &refC, (*C.Boolean)(C.NULL)); statusC != 0 { | |
return "", fmt.Errorf("%v", statusC) | |
} | |
pathC := unsafe.Pointer(&make([]C.UInt8, 1024)[0]) | |
if statusC := C.FSRefMakePath(&refC, (*C.UInt8)(pathC), C.UInt32(1024)); statusC != 0 { | |
return "", fmt.Errorf("%v", statusC) | |
} | |
return C.GoString((*C.char)(pathC)), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment