fs_linux.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2017 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fs
  15. import (
  16. "fmt"
  17. "os"
  18. "syscall"
  19. "time"
  20. )
  21. func (osFs) InodeNumber(info os.FileInfo) (number uint64, err error) {
  22. sys := info.Sys()
  23. linuxStats, ok := sys.(*syscall.Stat_t)
  24. if ok {
  25. return linuxStats.Ino, nil
  26. }
  27. return 0, fmt.Errorf("%v is not a *syscall.Stat_t", sys)
  28. }
  29. func (osFs) DeviceNumber(info os.FileInfo) (number uint64, err error) {
  30. sys := info.Sys()
  31. linuxStats, ok := sys.(*syscall.Stat_t)
  32. if ok {
  33. return linuxStats.Dev, nil
  34. }
  35. return 0, fmt.Errorf("%v is not a *syscall.Stat_t", sys)
  36. }
  37. func (osFs) PermTime(info os.FileInfo) (when time.Time, err error) {
  38. sys := info.Sys()
  39. linuxStats, ok := sys.(*syscall.Stat_t)
  40. if ok {
  41. return time.Unix(linuxStats.Ctim.Sec, linuxStats.Ctim.Nsec), nil
  42. }
  43. return time.Time{}, fmt.Errorf("%v is not a *syscall.Stat_t", sys)
  44. }