bootloader: rebase onto upstream 1.0.0, sync firmware-loader version

Bootloader fork rebase:
- Base changed from 0.1.0 pre-patched archive to upstream 1.0.0 tag (c7eeb9f)
- Applied 0001-redbear-local-forks.patch (Cargo.toml crate path redirects)
- Applied fix-uefi-alloc-panic.patch equivalents (4 panic!() -> graceful
  error handling in src/main.rs)
- Applied P5-live-preload-cap-1gib.patch (1 GiB cap on live image preload)
- Skipped: P0 GPT partition scan (requires new module + integration),
  P1 timeout/default-resolution, P2 live preload guard (subsumed by
  panic fixes + cap), P3 live image safe read, P4 large ISO boot,
  redox.patch — to be applied in dedicated rebase session.

firmware-loader/Cargo.toml: version 0.1.0 -> 0.3.0 (sync with other
Red Bear custom crates which are at 0.3.0).

fork-upstream-map.toml: bootloader back from PENDING_REBASE to 1.0.0
since the partial rebase matches upstream 1.0.0 content.

fork-upstream-map.toml: base restored to 'main' tracked (was correctly
tracked by build-redbear.sh).
This commit is contained in:
2026-07-11 09:47:59 +03:00
parent 9bbc38fe60
commit 068a1ca63e
1609 changed files with 256532 additions and 299729 deletions
+202 -211
View File
@@ -1,7 +1,7 @@
/* Read, sort and compare two directories. Used for GNU DIFF.
Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006-2007,
2009-2013, 2015-2017 Free Software Foundation, Inc.
2009-2013, 2015-2025 Free Software Foundation, Inc.
This file is part of GNU DIFF.
@@ -19,20 +19,28 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "diff.h"
#include <diagnose.h>
#include <dirname.h>
#include <error.h>
#include <exclude.h>
#include <filenamecat.h>
#include <mcel.h>
#include <quote.h>
#include <setjmp.h>
#include <xalloc.h>
/* Read the directory named by DIR and store into DIRDATA a sorted vector
of filenames for its contents. DIR->desc == -1 means this directory is
known to be nonexistent, so set DIRDATA to an empty vector.
Return -1 (setting errno) if error, 0 otherwise. */
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
# define HAVE_STRUCT_DIRENT_D_TYPE false
#endif
/* A sorted vector of file names obtained by reading a directory.
If HAVE_STRUCT_DIRENT_D_TYPE, each name is preceded by a byte
giving the file type as an enum detype value. */
struct dirdata
{
size_t nnames; /* Number of names. */
idx_t nnames; /* Number of names. */
char const **names; /* Sorted names of files in dir, followed by 0. */
char *data; /* Allocated storage for file names. */
};
@@ -44,98 +52,132 @@ static bool locale_specific_sorting;
/* Where to go if locale-specific sorting fails. */
static jmp_buf failed_locale_specific_sorting;
static int compare_names (char const *, char const *);
static bool dir_loop (struct comparison const *, int);
/* Read a directory and get its vector of names. */
/* Given the parent directory PARENTDIRFD (negative for current dir),
read the directory named by DIR and store into DIRDATA a sorted
vector of filenames for its contents.
Use DIR's basename if PARENTDIRFD is nonnegative, for efficiency.
If DIR->desc == NONEXISTENT, this directory is known to be
nonexistent so set DIRDATA to an empty vector;
otherwise, update DIR->desc and DIR->dirstream as needed.
If STARTFILE, ignore directory entries less than STARTFILE, and if
STARTFILE_ONLY, also ignore directory entries greater than STARTFILE.
Return true if successful, false (setting errno) otherwise. */
static bool
dir_read (struct file_data const *dir, struct dirdata *dirdata)
dir_read (int parentdirfd, struct file_data *dir, struct dirdata *dirdata,
char const *startfile, bool startfile_only)
{
register struct dirent *next;
register size_t i;
/* Address of block containing the files that are described. */
char const **names;
/* Number of files in directory. */
size_t nnames;
idx_t nnames = 0;
/* Allocated and used storage for file name data. */
char *data;
size_t data_alloc, data_used;
dirdata->names = 0;
dirdata->data = 0;
nnames = 0;
data = 0;
dirdata->names = nullptr;
dirdata->data = nullptr;
if (dir->desc != -1)
if (dir->desc != NONEXISTENT)
{
/* Open the directory and check for errors. */
register DIR *reading = opendir (dir->name);
int dirfd = dir->desc;
if (dirfd < 0)
{
dirfd = openat (parentdirfd,
(parentdirfd < 0 ? dir->name
: last_component (dir->name)),
(O_RDONLY | O_CLOEXEC | O_DIRECTORY
| (no_dereference_symlinks ? O_NOFOLLOW : 0)));
if (dirfd < 0)
return false;
dir->desc = dirfd;
}
DIR *reading = fdopendir (dirfd);
if (!reading)
return false;
return false;
dir->dirstream = reading;
/* Initialize the table of filenames. */
data_alloc = 512;
data_used = 0;
dirdata->data = data = xmalloc (data_alloc);
idx_t data_alloc = 512;
idx_t data_used = 0;
dirdata->data = data = ximalloc (data_alloc);
/* Read the directory entries, and insert the subfiles
into the 'data' table. */
into the 'data' table. */
while ((errno = 0, (next = readdir (reading)) != 0))
{
char *d_name = next->d_name;
size_t d_size = _D_EXACT_NAMLEN (next) + 1;
while (true)
{
errno = 0;
struct dirent *next = readdir (reading);
if (!next)
break;
/* Ignore "." and "..". */
if (d_name[0] == '.'
&& (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
continue;
char *d_name = next->d_name;
if (excluded_file_name (excluded, d_name))
continue;
/* Ignore "." and "..". */
if (d_name[0] == '.'
&& (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
continue;
while (data_alloc < data_used + d_size)
if (startfile)
{
if (PTRDIFF_MAX / 2 <= data_alloc)
xalloc_die ();
dirdata->data = data = xrealloc (data, data_alloc *= 2);
int cmp = compare_names (d_name, startfile);
if (cmp < 0 || (startfile_only && !!cmp))
continue;
}
memcpy (data + data_used, d_name, d_size);
data_used += d_size;
nnames++;
}
if (errno)
{
int e = errno;
closedir (reading);
errno = e;
return false;
}
#if CLOSEDIR_VOID
closedir (reading);
#else
if (closedir (reading) != 0)
return false;
if (excluded_file_name (excluded, d_name))
continue;
idx_t d_size = HAVE_STRUCT_DIRENT_D_TYPE + _D_EXACT_NAMLEN (next) + 1;
if (data_alloc - data_used < d_size)
dirdata->data = data
= xpalloc (data, &data_alloc,
d_size - (data_alloc - data_used), -1, 1);
#if HAVE_STRUCT_DIRENT_D_TYPE
char detype;
switch (next->d_type)
{
case DT_BLK: detype = DE_BLK; break;
case DT_CHR: detype = DE_CHR; break;
case DT_DIR: detype = DE_DIR; break;
case DT_FIFO: detype = DE_FIFO; break;
case DT_LNK: detype = DE_LNK; break;
case DT_REG: detype = DE_REG; break;
case DT_SOCK: detype = DE_SOCK; break;
# ifdef DT_WHT
case DT_WHT: detype = DE_WHT; break;
# endif
case DT_UNKNOWN: detype = DE_UNKNOWN; break;
default: detype = DE_OTHER; break;
}
data[data_used++] = detype;
d_size--;
#endif
memcpy (data + data_used, d_name, d_size);
data_used += d_size;
nnames++;
}
if (errno)
return false;
}
/* Create the 'names' table from the 'data' table. */
if (PTRDIFF_MAX / sizeof *names - 1 <= nnames)
xalloc_die ();
dirdata->names = names = xmalloc ((nnames + 1) * sizeof *names);
char const **names = xinmalloc (nnames + 1, sizeof *names);
dirdata->names = names;
dirdata->nnames = nnames;
for (i = 0; i < nnames; i++)
for (idx_t i = 0; i < nnames; i++)
{
data += HAVE_STRUCT_DIRENT_D_TYPE;
names[i] = data;
data += strlen (data) + 1;
}
names[nnames] = 0;
names[nnames] = nullptr;
return true;
}
@@ -145,16 +187,12 @@ dir_read (struct file_data const *dir, struct dirdata *dirdata)
static int
compare_collated (char const *name1, char const *name2)
{
int r;
errno = 0;
if (ignore_file_name_case)
r = strcasecoll (name1, name2);
else
r = strcoll (name1, name2);
int r = strcoll (name1, name2);
if (errno)
{
error (0, errno, _("cannot compare file names '%s' and '%s'"),
name1, name2);
error (0, errno, _("cannot compare file names %s and %s"),
quote_n (0, name1), quote_n (1, name2));
longjmp (failed_locale_specific_sorting, 1);
}
return r;
@@ -165,11 +203,14 @@ compare_collated (char const *name1, char const *name2)
static int
compare_names (char const *name1, char const *name2)
{
if (ignore_file_name_case)
return mbscasecmp (name1, name2); /* Best we can do. */
if (locale_specific_sorting)
{
int diff = compare_collated (name1, name2);
if (diff || ignore_file_name_case)
return diff;
if (diff)
return diff;
}
return file_name_cmp (name1, name2);
}
@@ -182,138 +223,108 @@ compare_names_for_qsort (void const *file1, void const *file2)
{
char const *const *f1 = file1;
char const *const *f2 = file2;
char const *name1 = *f1;
char const *name2 = *f2;
if (locale_specific_sorting)
{
int diff = compare_collated (name1, name2);
if (diff)
return diff;
}
return file_name_cmp (name1, name2);
return compare_names (*f1, *f2);
}
/* Compare the contents of two directories named in CMP.
This is a top-level routine; it does everything necessary for diff
on two directories.
CMP->file[0].desc == -1 says directory CMP->file[0] doesn't exist,
but pretend it is empty. Likewise for CMP->file[1].
If CMP->file[0].desc == NONEXISTENT, directory CMP->file[0] doesn't exist
and pretend it is empty. Otherwise, update CMP->file[0].desc and
CMP->file[0].dirstream as needed. Likewise for CMP->file[1].
HANDLE_FILE is a caller-provided subroutine called to handle each file.
It gets three operands: CMP, name of file in dir 0, name of file in dir 1.
These names are relative to the original working directory.
For a file that appears in only one of the dirs, one of the name-args
to HANDLE_FILE is zero.
Returns the maximum of all the values returned by HANDLE_FILE,
Returns the maximum of all the values returned by compare_files,
or EXIT_TROUBLE if trouble is encountered in opening files. */
int
diff_dirs (struct comparison const *cmp,
int (*handle_file) (struct comparison const *,
char const *, char const *))
diff_dirs (struct comparison *cmp)
{
struct dirdata dirdata[2];
int volatile val = EXIT_SUCCESS;
int i;
if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
&& (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
if ((cmp->file[0].desc == NONEXISTENT || dir_loop (cmp, 0))
&& (cmp->file[1].desc == NONEXISTENT || dir_loop (cmp, 1)))
{
error (0, 0, _("%s: recursive directory loop"),
cmp->file[cmp->file[0].desc == -1].name);
squote (0, cmp->file[cmp->file[0].desc == NONEXISTENT].name));
return EXIT_TROUBLE;
}
/* Get contents of both dirs. */
for (i = 0; i < 2; i++)
if (! dir_read (&cmp->file[i], &dirdata[i]))
struct dirdata dirdata[2];
int val = EXIT_SUCCESS;
for (int i = 0; i < 2; i++)
if (! dir_read (cmp->parent->file[i].desc, &cmp->file[i], &dirdata[i],
cmp->parent == &noparent ? starting_file : nullptr, false))
{
perror_with_name (cmp->file[i].name);
val = EXIT_TROUBLE;
perror_with_name (cmp->file[i].name);
val = EXIT_TROUBLE;
}
if (val == EXIT_SUCCESS)
{
char const **volatile names[2];
names[0] = dirdata[0].names;
names[1] = dirdata[1].names;
/* Use locale-specific sorting if possible, else native byte order. */
locale_specific_sorting = true;
if (setjmp (failed_locale_specific_sorting))
locale_specific_sorting = false;
if (! ignore_file_name_case)
if (setjmp (failed_locale_specific_sorting))
locale_specific_sorting = false;
/* Sort the directories. */
for (i = 0; i < 2; i++)
qsort (names[i], dirdata[i].nnames, sizeof *dirdata[i].names,
compare_names_for_qsort);
/* If '-S name' was given, and this is the topmost level of comparison,
ignore all file names less than the specified starting name. */
if (starting_file && ! cmp->parent)
{
while (*names[0] && compare_names (*names[0], starting_file) < 0)
names[0]++;
while (*names[1] && compare_names (*names[1], starting_file) < 0)
names[1]++;
}
for (int i = 0; i < 2; i++)
qsort (dirdata[i].names, dirdata[i].nnames, sizeof *dirdata[i].names,
compare_names_for_qsort);
/* Loop while files remain in one or both dirs. */
while (*names[0] || *names[1])
{
/* Compare next name in dir 0 with next name in dir 1.
At the end of a dir,
pretend the "next name" in that dir is very large. */
int nameorder = (!*names[0] ? 1 : !*names[1] ? -1
: compare_names (*names[0], *names[1]));
char const **n0 = dirdata[0].names;
char const **n1 = dirdata[1].names;
while (*n0 || *n1)
{
/* Compare next name in dir 0 with next name in dir 1.
At the end of a dir,
pretend the "next name" in that dir is very large. */
int nameorder = !*n0 ? 1 : !*n1 ? -1 : compare_names (*n0, *n1);
/* Prefer a file_name_cmp match if available. This algorithm is
O(N**2), where N is the number of names in a directory
that compare_names says are all equal, but in practice N
is so small it's not worth tuning. */
if (nameorder == 0 && ignore_file_name_case)
{
int raw_order = file_name_cmp (*names[0], *names[1]);
if (raw_order != 0)
{
int greater_side = raw_order < 0;
int lesser_side = 1 - greater_side;
char const **lesser = names[lesser_side];
char const *greater_name = *names[greater_side];
char const **p;
/* Prefer a file_name_cmp match if available. This algorithm is
O(N**2), where N is the number of names in a directory
that compare_names says are all equal, but in practice N
is so small it's not worth tuning. */
if (nameorder == 0 && ignore_file_name_case)
{
int raw_order = file_name_cmp (*n0, *n1);
if (raw_order != 0)
{
char const **lesser = raw_order < 0 ? n0 : n1;
char const *greater_name = *(raw_order < 0 ? n1 : n0);
for (p = lesser + 1;
*p && compare_names (*p, greater_name) == 0;
p++)
{
int c = file_name_cmp (*p, greater_name);
if (0 <= c)
{
if (c == 0)
{
memmove (lesser + 1, lesser,
(char *) p - (char *) lesser);
*lesser = greater_name;
}
break;
}
}
}
}
for (char const **p = lesser + 1;
*p && compare_names (*p, greater_name) == 0;
p++)
{
int c = file_name_cmp (*p, greater_name);
if (0 <= c)
{
if (c == 0)
{
memmove (lesser + 1, lesser,
(char *) p - (char *) lesser);
*lesser = greater_name;
}
break;
}
}
}
}
int v1 = (*handle_file) (cmp,
0 < nameorder ? 0 : *names[0]++,
nameorder < 0 ? 0 : *names[1]++);
if (val < v1)
val = v1;
}
enum detype detypes[]
= { HAVE_STRUCT_DIRENT_D_TYPE && *n0 ? (*n0)[-1] : DE_UNKNOWN,
HAVE_STRUCT_DIRENT_D_TYPE && *n1 ? (*n1)[-1] : DE_UNKNOWN };
int v1 = compare_files (cmp, detypes,
0 < nameorder ? nullptr : *n0++,
nameorder < 0 ? nullptr : *n1++);
if (val < v1)
val = v1;
}
}
for (i = 0; i < 2; i++)
for (int i = 0; i < 2; i++)
{
free (dirdata[i].names);
free (dirdata[i].data);
@@ -324,12 +335,11 @@ diff_dirs (struct comparison const *cmp,
/* Return nonzero if CMP is looping recursively in argument I. */
static bool _GL_ATTRIBUTE_PURE
static bool ATTRIBUTE_PURE
dir_loop (struct comparison const *cmp, int i)
{
struct comparison const *p = cmp;
while ((p = p->parent))
if (0 < same_file (&p->file[i].stat, &cmp->file[i].stat))
for (struct comparison const *p = cmp; (p = p->parent) != &noparent; )
if (same_file (&p->file[i].stat, &cmp->file[i].stat))
return true;
return false;
}
@@ -337,48 +347,29 @@ dir_loop (struct comparison const *cmp, int i)
/* Find a matching filename in a directory. */
char *
find_dir_file_pathname (char const *dir, char const *file)
find_dir_file_pathname (struct file_data *dir, char const *file,
enum detype *detype)
{
/* The 'IF_LINT (volatile)' works around what appears to be a bug in
gcc 4.8.0 20120825; see
<http://lists.gnu.org/archive/html/bug-diffutils/2012-08/msg00007.html>.
*/
char const * IF_LINT (volatile) match = file;
char const *match = file;
char *val;
struct dirdata dirdata;
dirdata.names = NULL;
dirdata.data = NULL;
dirdata.names = nullptr;
dirdata.data = nullptr;
if (ignore_file_name_case)
{
struct file_data filedata;
filedata.name = dir;
filedata.desc = 0;
if (ignore_file_name_case && dir_read (AT_FDCWD, dir, &dirdata, file, true))
for (char const **p = dirdata.names; *p; p++)
{
if (file_name_cmp (*p, file) == 0)
{
match = *p;
break;
}
if (match == file)
match = *p;
}
if (dir_read (&filedata, &dirdata))
{
locale_specific_sorting = true;
if (setjmp (failed_locale_specific_sorting))
match = file; /* longjmp may mess up MATCH. */
else
{
for (char const **p = dirdata.names; *p; p++)
if (compare_names (*p, file) == 0)
{
if (file_name_cmp (*p, file) == 0)
{
match = *p;
break;
}
if (match == file)
match = *p;
}
}
}
}
val = file_name_concat (dir, match, NULL);
*detype = HAVE_STRUCT_DIRENT_D_TYPE && match != file ? match[-1] : DE_UNKNOWN;
char *val = file_name_concat (dir->name, match, nullptr);
free (dirdata.names);
free (dirdata.data);
return val;