stat_linux.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Copyright The containerd Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fs
  14. import (
  15. "syscall"
  16. "time"
  17. )
  18. // StatAtime returns the Atim
  19. func StatAtime(st *syscall.Stat_t) syscall.Timespec {
  20. return st.Atim
  21. }
  22. // StatCtime returns the Ctim
  23. func StatCtime(st *syscall.Stat_t) syscall.Timespec {
  24. return st.Ctim
  25. }
  26. // StatMtime returns the Mtim
  27. func StatMtime(st *syscall.Stat_t) syscall.Timespec {
  28. return st.Mtim
  29. }
  30. // StatATimeAsTime returns st.Atim as a time.Time
  31. func StatATimeAsTime(st *syscall.Stat_t) time.Time {
  32. // The int64 conversions ensure the line compiles for 32-bit systems as well.
  33. return time.Unix(int64(st.Atim.Sec), int64(st.Atim.Nsec)) // nolint: unconvert
  34. }