Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // Returns the volume serial number of the file or directory at fsPath.
  2. func statVolumeSerialNumber(fsPath string) (uint32, error) {
  3. pathp, err := syscall.UTF16PtrFromString(fsPath)
  4. if err != nil {
  5. return 0, err
  6. }
  7. h, err := syscall.CreateFile(pathp, 0, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
  8. if err != nil {
  9. return 0, err
  10. }
  11. defer syscall.CloseHandle(h)
  12. var i syscall.ByHandleFileInformation
  13. if err = syscall.GetFileInformationByHandle(h, &i); err != nil {
  14. return 0, err
  15. }
  16. return i.VolumeSerialNumber, nil
  17. }
  18.  
  19. // sameMount reports whether childInfo and parentInfo describe
  20. // the same file or directory in the same mount. For example,
  21. // on Unix this means that the device fields of the two underlying
  22. // structures are identical; on other systems the decision may
  23. // be based on the path names. sameMount only applies to results
  24. // returned by os.Stat. It returns false in other cases.
  25. func sameMount(childInfo os.FileInfo, childPath string, parentInfo os.FileInfo, parentPath string) bool {
  26. if childInfo == nil || parentInfo == nil {
  27. return false
  28. }
  29. if childPath == "" || parentPath == "" {
  30. return false
  31. }
  32. vol1, err := statVolumeSerialNumber(childPath)
  33. if err != nil {
  34. return false
  35. }
  36. vol2, err := statVolumeSerialNumber(parentPath)
  37. if err != nil {
  38. return false
  39. }
  40. return vol1 == vol2
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement