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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

60 lignes
1.4KB

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