Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Returns the volume serial number of the file or directory at fsPath.
- func statVolumeSerialNumber(fsPath string) (uint32, error) {
- pathp, err := syscall.UTF16PtrFromString(fsPath)
- if err != nil {
- return 0, err
- }
- h, err := syscall.CreateFile(pathp, 0, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
- if err != nil {
- return 0, err
- }
- defer syscall.CloseHandle(h)
- var i syscall.ByHandleFileInformation
- if err = syscall.GetFileInformationByHandle(h, &i); err != nil {
- return 0, err
- }
- return i.VolumeSerialNumber, nil
- }
- // sameMount reports whether childInfo and parentInfo describe
- // the same file or directory in the same mount. For example,
- // on Unix this means that the device fields of the two underlying
- // structures are identical; on other systems the decision may
- // be based on the path names. sameMount only applies to results
- // returned by os.Stat. It returns false in other cases.
- func sameMount(childInfo os.FileInfo, childPath string, parentInfo os.FileInfo, parentPath string) bool {
- if childInfo == nil || parentInfo == nil {
- return false
- }
- if childPath == "" || parentPath == "" {
- return false
- }
- vol1, err := statVolumeSerialNumber(childPath)
- if err != nil {
- return false
- }
- vol2, err := statVolumeSerialNumber(parentPath)
- if err != nil {
- return false
- }
- return vol1 == vol2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement