|
|
48cf39d |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
48cf39d |
From: Robbie Harwood <rharwood@redhat.com>
|
|
|
48cf39d |
Date: Thu, 9 Mar 2023 11:18:19 -0500
|
|
|
48cf39d |
Subject: [PATCH] hostdisk: work around /proc not reporting size
|
|
|
48cf39d |
|
|
|
48cf39d |
fstat(2) of files in /proc will yield st_size == 0 regardless of file
|
|
|
48cf39d |
contents. Use a negative value in grub_file_t's size to denote "ignore"
|
|
|
48cf39d |
and plumb through.
|
|
|
48cf39d |
|
|
|
48cf39d |
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
|
|
48cf39d |
---
|
|
|
48cf39d |
grub-core/kern/file.c | 28 ++++++++++++++++------------
|
|
|
48cf39d |
grub-core/lib/progress.c | 2 +-
|
|
|
48cf39d |
grub-core/osdep/unix/hostdisk.c | 6 ++++++
|
|
|
48cf39d |
3 files changed, 23 insertions(+), 13 deletions(-)
|
|
|
48cf39d |
|
|
|
48cf39d |
diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c
|
|
|
48cf39d |
index 868ce3b63e..4ea6d1ce95 100644
|
|
|
48cf39d |
--- a/grub-core/kern/file.c
|
|
|
48cf39d |
+++ b/grub-core/kern/file.c
|
|
|
48cf39d |
@@ -172,26 +172,30 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
|
|
48cf39d |
grub_disk_read_hook_t read_hook;
|
|
|
48cf39d |
void *read_hook_data;
|
|
|
48cf39d |
|
|
|
48cf39d |
- if (file->offset > file->size)
|
|
|
48cf39d |
- {
|
|
|
48cf39d |
- grub_error (GRUB_ERR_OUT_OF_RANGE,
|
|
|
48cf39d |
- N_("attempt to read past the end of file"));
|
|
|
48cf39d |
- return -1;
|
|
|
48cf39d |
- }
|
|
|
48cf39d |
-
|
|
|
48cf39d |
if (len == 0)
|
|
|
48cf39d |
return 0;
|
|
|
48cf39d |
|
|
|
48cf39d |
- if (len > file->size - file->offset)
|
|
|
48cf39d |
- len = file->size - file->offset;
|
|
|
48cf39d |
+#ifdef GRUB_MACHINE_EMU
|
|
|
48cf39d |
+ if (file->size >= 0)
|
|
|
48cf39d |
+ {
|
|
|
48cf39d |
+#endif
|
|
|
48cf39d |
+ if (file->offset > file->size)
|
|
|
48cf39d |
+ {
|
|
|
48cf39d |
+ grub_error (GRUB_ERR_OUT_OF_RANGE,
|
|
|
48cf39d |
+ N_("attempt to read past the end of file"));
|
|
|
48cf39d |
+ return -1;
|
|
|
48cf39d |
+ }
|
|
|
48cf39d |
+
|
|
|
48cf39d |
+ if (len > file->size - file->offset)
|
|
|
48cf39d |
+ len = file->size - file->offset;
|
|
|
48cf39d |
+#ifdef GRUB_MACHINE_EMU
|
|
|
48cf39d |
+ }
|
|
|
48cf39d |
+#endif
|
|
|
48cf39d |
|
|
|
48cf39d |
/* Prevent an overflow. */
|
|
|
48cf39d |
if ((grub_ssize_t) len < 0)
|
|
|
48cf39d |
len >>= 1;
|
|
|
48cf39d |
|
|
|
48cf39d |
- if (len == 0)
|
|
|
48cf39d |
- return 0;
|
|
|
48cf39d |
-
|
|
|
48cf39d |
read_hook = file->read_hook;
|
|
|
48cf39d |
read_hook_data = file->read_hook_data;
|
|
|
48cf39d |
if (!file->read_hook)
|
|
|
48cf39d |
diff --git a/grub-core/lib/progress.c b/grub-core/lib/progress.c
|
|
|
48cf39d |
index 4b7cbbca6d..f3226b6898 100644
|
|
|
48cf39d |
--- a/grub-core/lib/progress.c
|
|
|
48cf39d |
+++ b/grub-core/lib/progress.c
|
|
|
48cf39d |
@@ -71,7 +71,7 @@ grub_file_progress_hook_real (grub_disk_addr_t sector __attribute__ ((unused)),
|
|
|
48cf39d |
* 100ULL * 1000ULL,
|
|
|
48cf39d |
now - file->last_progress_time, 0);
|
|
|
48cf39d |
|
|
|
48cf39d |
- if (file->size == 0)
|
|
|
48cf39d |
+ if (file->size <= 0)
|
|
|
48cf39d |
percent = 100;
|
|
|
48cf39d |
else
|
|
|
48cf39d |
percent = grub_divmod64 (100 * file->progress_offset,
|
|
|
48cf39d |
diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c
|
|
|
48cf39d |
index 3a00d7451a..e5f4b4d5f9 100644
|
|
|
48cf39d |
--- a/grub-core/osdep/unix/hostdisk.c
|
|
|
48cf39d |
+++ b/grub-core/osdep/unix/hostdisk.c
|
|
|
48cf39d |
@@ -71,6 +71,12 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz
|
|
|
48cf39d |
if (log_secsize)
|
|
|
48cf39d |
*log_secsize = 9;
|
|
|
48cf39d |
|
|
|
48cf39d |
+#ifdef GRUB_MACHINE_EMU
|
|
|
48cf39d |
+ /* /proc doesn't behave itself and gives 0 for file sizes to stat. */
|
|
|
48cf39d |
+ if (st.st_size == 0 && !grub_strncmp ("/proc", name, 5))
|
|
|
48cf39d |
+ return -1;
|
|
|
48cf39d |
+#endif
|
|
|
48cf39d |
+
|
|
|
48cf39d |
return st.st_size;
|
|
|
48cf39d |
}
|
|
|
48cf39d |
|