github.com/charlievieth/fastwalk@v1.0.3/internal/dirent/dirent_dragonfly.go (about) 1 //go:build dragonfly 2 3 package dirent 4 5 import ( 6 "os" 7 "syscall" 8 "unsafe" 9 ) 10 11 func direntIno(buf []byte) (uint64, bool) { 12 return readInt(buf, unsafe.Offsetof(syscall.Dirent{}.Fileno), unsafe.Sizeof(syscall.Dirent{}.Fileno)) 13 } 14 15 func direntReclen(buf []byte) (uint64, bool) { 16 namlen, ok := direntNamlen(buf) 17 if !ok { 18 return 0, false 19 } 20 return (16 + namlen + 1 + 7) &^ 7, true 21 } 22 23 func direntNamlen(buf []byte) (uint64, bool) { 24 return readInt(buf, unsafe.Offsetof(syscall.Dirent{}.Namlen), unsafe.Sizeof(syscall.Dirent{}.Namlen)) 25 } 26 27 func direntType(buf []byte) os.FileMode { 28 off := unsafe.Offsetof(syscall.Dirent{}.Type) 29 if off >= uintptr(len(buf)) { 30 return ^os.FileMode(0) // unknown 31 } 32 typ := buf[off] 33 switch typ { 34 case syscall.DT_BLK: 35 return os.ModeDevice 36 case syscall.DT_CHR: 37 return os.ModeDevice | os.ModeCharDevice 38 case syscall.DT_DBF: 39 // DT_DBF is "database record file". 40 // fillFileStatFromSys treats as regular file. 41 return 0 42 case syscall.DT_DIR: 43 return os.ModeDir 44 case syscall.DT_FIFO: 45 return os.ModeNamedPipe 46 case syscall.DT_LNK: 47 return os.ModeSymlink 48 case syscall.DT_REG: 49 return 0 50 case syscall.DT_SOCK: 51 return os.ModeSocket 52 } 53 return ^os.FileMode(0) // unknown 54 }