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