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!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

80 lines
2.1KB

  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. import re
  19. with open('/usr/include/sys/mount.h', 'r') as f:
  20. rx = re.compile('[ \t]')
  21. lines = f.read().split('\n')
  22. lines = [ a.strip() for a in lines \
  23. if list(filter(lambda b: b, rx.split(a))) [:2] == \
  24. [ '#define', 'MNAMELEN'] ]
  25. MNAMELEN = int(rx.split(lines[0])[2])
  26. # print('MNAMELEN:', MNAMELEN)
  27. #line = list(filter(lambda a: \
  28. # list(filter(lambda b: b, rx.split(a), a)[:2]) == \
  29. # ['#define', 'MNAMELEN'], f.read().split('\n')))
  30. #line[0]
  31. MFSNAMELEN = 16
  32. # MNAMELEN = 1024
  33. class statfs(Structure):
  34. pass
  35. statfs._fields_ = [
  36. ('f_version', c_uint32),
  37. ('f_type', c_uint32),
  38. ('f_flags', c_uint64),
  39. ('f_bsize', c_uint64),
  40. ('f_iosize', c_uint64),
  41. ('f_blocks', c_uint64),
  42. ('f_bfree', c_uint64),
  43. ('f_bavail', c_int64),
  44. ('f_files', c_uint64),
  45. ('f_ffree', c_int64),
  46. ('f_syncwrites', c_uint64),
  47. ('f_asyncwrites', c_uint64),
  48. ('f_syncreads', c_uint64),
  49. ('f_asyncreads', c_uint64),
  50. ('f_spare', ARRAY(c_uint64, 10)),
  51. ('f_namemax', c_uint32),
  52. ('f_owner', c_uint32),
  53. ('f_fsid', ARRAY(c_uint32, 2)),
  54. ('f_charspare', ARRAY(c_char, 80)),
  55. ('f_fstypename', ARRAY(c_char, MFSNAMELEN)),
  56. ('f_mntfromname', ARRAY(c_char, MNAMELEN)),
  57. ('f_mntonname', ARRAY(c_char, MNAMELEN))
  58. ]
  59. libc = CDLL(find_library('c'))
  60. def getdict(struct):
  61. return dict((field, getattr(struct, field)) for field, _ in struct._fields_)
  62. _getmntinfo = libc.getmntinfo
  63. _getmntinfo.argtypes = [ POINTER(POINTER(statfs)), c_int ]
  64. def getmntinfo():
  65. p = POINTER(statfs)()
  66. n = _getmntinfo(byref(p), c_int(1))
  67. res = [ getdict(p[i]) for i in range(n) ]
  68. return res