blob: 8b88900f71910247609a0095f3492df331b6f141 [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:
Patrick Williams2390b1b2022-11-03 13:47:49 -050043 mountPointList = d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint)
44 if not mountPointList:
45 bb.debug(1, "No mount points defined for %s flag, don't add to file list", mountPoint)
46 continue
47 for path in mountPointList.split():
Patrick Williams0ca19cc2021-08-16 14:03:13 -050048 fileList.append(mountUnitName(path))
49 fileList.append(helperUnitName(path))
50
Andrew Geissler595f6302022-01-24 19:11:47 +000051 fileList.append(allOverlaysUnitName(d))
52
Patrick Williams0ca19cc2021-08-16 14:03:13 -050053 return fileList
54