overlayfs.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. # This file contains common functions for overlayfs and its QA check
  7. # this function is based on https://github.com/systemd/systemd/blob/main/src/basic/unit-name.c
  8. def escapeSystemdUnitName(path):
  9. escapeMap = {
  10. '/': '-',
  11. '-': "\\x2d",
  12. '\\': "\\x5d"
  13. }
  14. return "".join([escapeMap.get(c, c) for c in path.strip('/')])
  15. def strForBash(s):
  16. return s.replace('\\', '\\\\')
  17. def allOverlaysUnitName(d):
  18. return d.getVar('PN') + '-overlays.service'
  19. def mountUnitName(unit):
  20. return escapeSystemdUnitName(unit) + '.mount'
  21. def helperUnitName(unit):
  22. return escapeSystemdUnitName(unit) + '-create-upper-dir.service'
  23. def unitFileList(d):
  24. fileList = []
  25. overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
  26. if not overlayMountPoints:
  27. bb.fatal("A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
  28. # check that we have required mount points set first
  29. requiredMountPoints = d.getVarFlags('OVERLAYFS_WRITABLE_PATHS')
  30. for mountPoint in requiredMountPoints:
  31. if mountPoint not in overlayMountPoints:
  32. bb.fatal("Missing required mount point for OVERLAYFS_MOUNT_POINT[%s] in your MACHINE configuration" % mountPoint)
  33. for mountPoint in overlayMountPoints:
  34. mountPointList = d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint)
  35. if not mountPointList:
  36. bb.debug(1, "No mount points defined for %s flag, don't add to file list", mountPoint)
  37. continue
  38. for path in mountPointList.split():
  39. fileList.append(mountUnitName(path))
  40. fileList.append(helperUnitName(path))
  41. fileList.append(allOverlaysUnitName(d))
  42. return fileList