sys.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // +build linux
  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 {
  33. return exec.Command(name, args...).Run()
  34. }
  35. )
  36. const (
  37. sysMsMgcVal = syscall.MS_MGC_VAL
  38. sysMsRdOnly = syscall.MS_RDONLY
  39. sysEInval = syscall.EINVAL
  40. sysSysIoctl = syscall.SYS_IOCTL
  41. sysEBusy = syscall.EBUSY
  42. osORdOnly = os.O_RDONLY
  43. osORdWr = os.O_RDWR
  44. osOCreate = os.O_CREATE
  45. osModeDevice = os.ModeDevice
  46. )
  47. func toSysStatT(i interface{}) *sysStatT {
  48. return (*sysStatT)(i.(*syscall.Stat_t))
  49. }