IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

67 linhas
1.6KB

  1. #
  2. # Copyright (C) Stanislaw Adaszewski, 2020
  3. # License: GNU General Public License v3.0
  4. # URL: https://github.com/sadaszewski/focker
  5. # URL: https://adared.ch/focker
  6. #
  7. from ctypes import Structure, \
  8. c_uint32, \
  9. c_uint64, \
  10. c_int64, \
  11. c_int, \
  12. c_char, \
  13. CDLL, \
  14. POINTER, \
  15. ARRAY, \
  16. byref
  17. from ctypes.util import find_library
  18. MFSNAMELEN = 16
  19. MNAMELEN = 1024
  20. class statfs(Structure):
  21. pass
  22. statfs._fields_ = [
  23. ('f_version', c_uint32),
  24. ('f_type', c_uint32),
  25. ('f_flags', c_uint64),
  26. ('f_bsize', c_uint64),
  27. ('f_iosize', c_uint64),
  28. ('f_blocks', c_uint64),
  29. ('f_bfree', c_uint64),
  30. ('f_bavail', c_int64),
  31. ('f_files', c_uint64),
  32. ('f_ffree', c_int64),
  33. ('f_syncwrites', c_uint64),
  34. ('f_asyncwrites', c_uint64),
  35. ('f_syncreads', c_uint64),
  36. ('f_asyncreads', c_uint64),
  37. ('f_spare', ARRAY(c_uint64, 10)),
  38. ('f_namemax', c_uint32),
  39. ('f_owner', c_uint32),
  40. ('f_fsid', ARRAY(c_uint32, 2)),
  41. ('f_charspare', ARRAY(c_char, 80)),
  42. ('f_fstypename', ARRAY(c_char, MFSNAMELEN)),
  43. ('f_mntfromname', ARRAY(c_char, MNAMELEN)),
  44. ('f_mntonname', ARRAY(c_char, MNAMELEN))
  45. ]
  46. libc = CDLL(find_library('c'))
  47. def getdict(struct):
  48. return dict((field, getattr(struct, field)) for field, _ in struct._fields_)
  49. _getmntinfo = libc.getmntinfo
  50. _getmntinfo.argtypes = [ POINTER(POINTER(statfs)), c_int ]
  51. def getmntinfo():
  52. p = POINTER(statfs)()
  53. n = _getmntinfo(byref(p), c_int(1))
  54. res = [ getdict(p[i]) for i in range(n) ]
  55. return res