Skip to content

Commit 76ffcf8

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 79af924 commit 76ffcf8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/libostree/ostree-sysroot-deploy.c

+56
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,58 @@ install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion,
21802180
return TRUE;
21812181
}
21822182

2183+
/* Determine whether an existing directory implements the semantics described in
2184+
* https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-entry-keys
2185+
*/
2186+
static gboolean
2187+
is_bootconfig_type1_semantics (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
2188+
{
2189+
struct stat stbuf;
2190+
2191+
if (!_ostree_sysroot_ensure_boot_fd (sysroot, error))
2192+
return FALSE;
2193+
2194+
if (!glnx_fstatat_allow_noent (sysroot->boot_fd, "loader/entries.srel", &stbuf, AT_SYMLINK_NOFOLLOW,
2195+
error))
2196+
return FALSE;
2197+
2198+
2199+
if (errno == ENOENT)
2200+
{
2201+
g_debug ("Didn't find loader/entries.srel file");
2202+
return FALSE;
2203+
}
2204+
else
2205+
{
2206+
/* Get semantics type by reading loader/entries.srel */
2207+
gsize len;
2208+
g_autofree char* type =
2209+
glnx_file_get_contents_utf8_at(sysroot->boot_fd, "loader/entries.srel",
2210+
&len, cancellable, error);
2211+
if (type == NULL)
2212+
{
2213+
g_debug ("Invalid loader/entries.srel file");
2214+
return FALSE;
2215+
}
2216+
2217+
/* Remove trailing newline symbol if there is any */
2218+
type[strcspn(type, "\n")] = 0;
2219+
2220+
if (g_strcmp0 (type, "type1") == 0)
2221+
{
2222+
g_debug ("type1 semantics is found in loader/entries.srel file");
2223+
return TRUE;
2224+
}
2225+
else
2226+
{
2227+
g_debug ("Unsupported semantics type ('%s') in loader/entries.srel file", type);
2228+
return FALSE;
2229+
}
2230+
}
2231+
2232+
return FALSE;
2233+
}
2234+
21832235
/* We generate the symlink on disk, then potentially do a syncfs() to ensure
21842236
* that it (and everything else we wrote) has hit disk. Only after that do we
21852237
* rename it into place.
@@ -2507,6 +2559,7 @@ write_deployments_bootswap (OstreeSysroot *self, GPtrArray *new_deployments,
25072559
/* Handle when boot/loader is a link (normal deployment) and as a normal directory (e.g. EFI/vfat) */
25082560
struct stat stbuf;
25092561
gboolean loader_link = FALSE;
2562+
gboolean force_type1_semantics = is_bootconfig_type1_semantics(self, cancellable, error);
25102563
if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW, error))
25112564
return FALSE;
25122565
if (errno == ENOENT)
@@ -2529,6 +2582,9 @@ write_deployments_bootswap (OstreeSysroot *self, GPtrArray *new_deployments,
25292582
else
25302583
return FALSE;
25312584

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

0 commit comments

Comments
 (0)