Skip to content

Commit 11f4940

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 <igor.opaniuk@foundries.io>
1 parent bbce457 commit 11f4940

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/libostree/ostree-sysroot-deploy.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,58 @@ install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion,
21852185
return TRUE;
21862186
}
21872187

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

2590+
if (force_type1_semantics && loader_link)
2591+
return glnx_throw_errno_prefix (error, "type1 semantics, but boot/loader is symlink");
2592+
25372593
if (loader_link)
25382594
{
25392595
/* Default and when loader is a link is to swap links */

0 commit comments

Comments
 (0)