Skip to content

Commit f567c5e

Browse files
committed
sysroot: Support for standard-conformance marker file
Add support for standard-conformance marker file loader/entries.srel. There might be implementations of boot loading infrastructure that are also using the /loader/entries/ directory, but install files that do not follow the [1] specification. In order to minimize confusion, a boot loader implementation may place the file /loader/entries.srel next to the /loader/entries/ directory containing the ASCII string type1 (followed by a UNIX newline). Tools that need to determine whether an existing directory implements the semantics described here may check for this file and contents: if it exists and contains the mentioned string, it shall assume a standards-compliant implementation is in place. If it exists but contains a different string it shall assume other semantics are implemented. If the file does not exist, no assumptions should be made. [1] https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-entry-keys Signed-off-by: Igor Opaniuk <[email protected]>
1 parent de1fdb5 commit f567c5e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/libostree/ostree-sysroot-deploy.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,53 @@ install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion,
21912191
return TRUE;
21922192
}
21932193

2194+
/* Determine whether an existing directory implements the semantics described in
2195+
* https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-entry-keys
2196+
*/
2197+
static gboolean
2198+
is_bootconfig_type1_semantics (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
2199+
{
2200+
struct stat stbuf;
2201+
2202+
if (!_ostree_sysroot_ensure_boot_fd (sysroot, error))
2203+
return FALSE;
2204+
2205+
if (!glnx_fstatat_allow_noent (sysroot->boot_fd, "loader/entries.srel", &stbuf,
2206+
AT_SYMLINK_NOFOLLOW, error))
2207+
return FALSE;
2208+
2209+
if (errno == ENOENT)
2210+
{
2211+
g_debug ("Didn't find loader/entries.srel file");
2212+
return FALSE;
2213+
}
2214+
else
2215+
{
2216+
/* Get semantics type by reading loader/entries.srel */
2217+
gsize len;
2218+
g_autofree char *type = glnx_file_get_contents_utf8_at (
2219+
sysroot->boot_fd, "loader/entries.srel", &len, cancellable, error);
2220+
if (type == NULL)
2221+
{
2222+
g_debug ("Invalid loader/entries.srel file");
2223+
return FALSE;
2224+
}
2225+
2226+
if (g_str_has_prefix (type, "type1"))
2227+
{
2228+
g_debug ("type1 semantics is found in loader/entries.srel file");
2229+
return TRUE;
2230+
}
2231+
else
2232+
{
2233+
g_debug ("Unsupported semantics type ('%s') in loader/entries.srel file", type);
2234+
return FALSE;
2235+
}
2236+
}
2237+
2238+
return FALSE;
2239+
}
2240+
21942241
/* We generate the symlink on disk, then potentially do a syncfs() to ensure
21952242
* that it (and everything else we wrote) has hit disk. Only after that do we
21962243
* rename it into place.
@@ -2522,6 +2569,7 @@ write_deployments_bootswap (OstreeSysroot *self, GPtrArray *new_deployments,
25222569
*/
25232570
struct stat stbuf;
25242571
gboolean loader_link = FALSE;
2572+
gboolean force_type1_semantics = is_bootconfig_type1_semantics (self, cancellable, error);
25252573
if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW,
25262574
error))
25272575
return FALSE;
@@ -2534,6 +2582,9 @@ write_deployments_bootswap (OstreeSysroot *self, GPtrArray *new_deployments,
25342582
else
25352583
return FALSE;
25362584

2585+
if (force_type1_semantics && loader_link)
2586+
return glnx_throw_errno_prefix (error, "type1 semantics, but boot/loader is symlink");
2587+
25372588
if (loader_link)
25382589
{
25392590
/* Default and when loader is a link is to swap links */

0 commit comments

Comments
 (0)