sys.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // +build linux,amd64
  2. package devmapper
  3. import (
  4. "os"
  5. "os/exec"
  6. "syscall"
  7. )
  8. type (
  9. sysStatT syscall.Stat_t
  10. sysErrno syscall.Errno
  11. osFile struct{ *os.File }
  12. )
  13. var (
  14. sysMount = syscall.Mount
  15. sysUnmount = syscall.Unmount
  16. sysCloseOnExec = syscall.CloseOnExec
  17. sysSyscall = syscall.Syscall
  18. osOpenFile = func(name string, flag int, perm os.FileMode) (*osFile, error) {
  19. f, err := os.OpenFile(name, flag, perm)
  20. return &osFile{File: f}, err
  21. }
  22. osOpen = func(name string) (*osFile, error) { f, err := os.Open(name); return &osFile{File: f}, err }
  23. osNewFile = os.NewFile
  24. osCreate = os.Create
  25. osStat = os.Stat
  26. osIsNotExist = os.IsNotExist
  27. osIsExist = os.IsExist
  28. osMkdirAll = os.MkdirAll
  29. osRemoveAll = os.RemoveAll
  30. osRename = os.Rename
  31. osReadlink = os.Readlink
  32. execRun = func(name string, args ...string) error { return exec.Command(name, args...).Run() }
  33. )
  34. const (
  35. sysMsMgcVal = syscall.MS_MGC_VAL
  36. sysMsRdOnly = syscall.MS_RDONLY
  37. sysEInval = syscall.EINVAL
  38. sysSysIoctl = syscall.SYS_IOCTL
  39. sysEBusy = syscall.EBUSY
  40. osORdOnly = os.O_RDONLY
  41. osORdWr = os.O_RDWR
  42. osOCreate = os.O_CREATE
  43. osModeDevice = os.ModeDevice
  44. )
  45. func toSysStatT(i interface{}) *sysStatT {
  46. return (*sysStatT)(i.(*syscall.Stat_t))
  47. }