os.Stat()
returns os.FileInfo
struct and that provides passthrough via Sys()
to the underlying data source - on UNIX systems (so the code is obviously not portable to e.g. Windows) it is outcome of stat
syscall which has device number information. Device number can be obtained from Dev
field of syscall.Stat_t
struct. Here is a quick example of how to get device number from FileInfo
:
// NOTE This is PoC for SO purposes so do error handling, etc.
stat1, _ := os.Stat("/drive1/a.txt")
stat2, _ := os.Stat("/drive2/b.txt")
// returns *syscall.Stat_t
fmt.Println(reflect.TypeOf(statA.Sys()))
fmt.Println(stat1.Sys().(*syscall.Stat_t).Dev)
fmt.Println(stat2.Sys().(*syscall.Stat_t).Dev)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…