blob: 8d7a047125a5b8d3fbd88f791d9c8163179e49dd [file] [log] [blame]
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004# SPDX-License-Identifier: GPL-2.0-only
5#
6# This file contains common functions for overlayfs and its QA check
7
8# this function is based on https://github.com/systemd/systemd/blob/main/src/basic/unit-name.c
9def escapeSystemdUnitName(path):
10 escapeMap = {
11 '/': '-',
12 '-': "\\x2d",
13 '\\': "\\x5d"
14 }
15 return "".join([escapeMap.get(c, c) for c in path.strip('/')])
16
17def strForBash(s):
18 return s.replace('\\', '\\\\')
19
Andrew Geissler595f6302022-01-24 19:11:47 +000020def allOverlaysUnitName(d):
21 return d.getVar('PN') + '-overlays.service'
22
Patrick Williams0ca19cc2021-08-16 14:03:13 -050023def mountUnitName(unit):
24 return escapeSystemdUnitName(unit) + '.mount'
25
26def helperUnitName(unit):
27 return escapeSystemdUnitName(unit) + '-create-upper-dir.service'
28
29def unitFileList(d):
30 fileList = []
31 overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
32
33 if not overlayMountPoints:
34 bb.fatal("A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
35
36 # check that we have required mount points set first
37 requiredMountPoints = d.getVarFlags('OVERLAYFS_WRITABLE_PATHS')
38 for mountPoint in requiredMountPoints:
39 if mountPoint not in overlayMountPoints:
40 bb.fatal("Missing required mount point for OVERLAYFS_MOUNT_POINT[%s] in your MACHINE configuration" % mountPoint)
41
42 for mountPoint in overlayMountPoints:
43 for path in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
44 fileList.append(mountUnitName(path))
45 fileList.append(helperUnitName(path))
46
Andrew Geissler595f6302022-01-24 19:11:47 +000047 fileList.append(allOverlaysUnitName(d))
48
Patrick Williams0ca19cc2021-08-16 14:03:13 -050049 return fileList
50