Skip to content

Commit 9806a3d

Browse files
Derek Foremanjprvita
authored andcommitted
[Endless] sd-boot: Read fake symlinks
ostree uses symlinks on the boot filesystem, this isn't great when that filesystem is vfat, which can't do symlinks. Since the EFI ESP must be vfat on most implementation, this makes ostree incompaible with sd-boot. To allow ostree to keep making symlinks, we make a fake symlink that's just a text file with the name of the file that would be linked to. https://phabricator.endlessm.com/T27040
1 parent 13cc1b7 commit 9806a3d

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/boot/efi/boot.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,39 @@ static void config_entry_add_from_file(
15731573
TAKE_PTR(entry);
15741574
}
15751575

1576+
static CHAR16 *resolve_link(EFI_FILE *root_dir, CHAR16 *link, CHAR16 *file) {
1577+
EFI_STATUS err;
1578+
_cleanup_freepool_ CHAR8 *contents = NULL;
1579+
_cleanup_freepool_ CHAR16 *linkname = NULL;
1580+
_cleanup_freepool_ CHAR16 *target = NULL;
1581+
CHAR16 *out = NULL;
1582+
1583+
linkname = AllocatePool(StrSize(link) + StrSize(L".sln"));
1584+
if (!linkname)
1585+
return NULL;
1586+
StrCpy(linkname, link);
1587+
StrCat(linkname, L".sln");
1588+
1589+
err = file_read(root_dir, linkname, 0, 0, &contents, NULL);
1590+
if (EFI_ERROR(err))
1591+
return NULL;
1592+
1593+
target = xstra_to_str(contents);
1594+
if (!target)
1595+
return NULL;
1596+
1597+
out = AllocatePool(StrSize(target) + StrSize(file));
1598+
if (!out)
1599+
return NULL;
1600+
StrCpy(out, target);
1601+
StrCat(out, file);
1602+
1603+
return out;
1604+
}
1605+
15761606
static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
15771607
_cleanup_freepool_ CHAR8 *content = NULL;
1608+
_cleanup_freepool_ CHAR16 *link = NULL;
15781609
UINTN value;
15791610
EFI_STATUS err;
15801611

@@ -1593,7 +1624,10 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
15931624
.timeout_sec_efivar = TIMEOUT_UNSET,
15941625
};
15951626

1596-
err = file_read(root_dir, L"\\loader\\loader.conf", 0, 0, &content, NULL);
1627+
link = resolve_link(root_dir, L"\\loader", L"\\entries");
1628+
if (!link)
1629+
link = L"\\loader\\entries";
1630+
err = file_read(root_dir, link, 0, 0, &content, NULL);
15971631
if (!EFI_ERROR(err))
15981632
config_defaults_load_from_file(config, content);
15991633

@@ -1639,14 +1673,18 @@ static void config_load_entries(
16391673
_cleanup_freepool_ EFI_FILE_INFO *f = NULL;
16401674
UINTN f_size = 0;
16411675
EFI_STATUS err;
1676+
_cleanup_freepool_ CHAR16 *link = NULL;
16421677

16431678
assert(config);
16441679
assert(device);
16451680
assert(root_dir);
16461681

16471682
/* Adds Boot Loader Type #1 entries (i.e. /loader/entries/….conf) */
16481683

1649-
err = open_directory(root_dir, L"\\loader\\entries", &entries_dir);
1684+
link = resolve_link(root_dir, L"\\loader", L"\\entries");
1685+
if (!link)
1686+
link = L"\\loader\\entries";
1687+
err = open_directory(root_dir, link, &entries_dir);
16501688
if (EFI_ERROR(err))
16511689
return;
16521690

0 commit comments

Comments
 (0)