Skip to contentSkip to conversation

Improve newc generation logging

PATCH In review Glenn Washburn 2 participants 5 messages Jun 28, 2023

lore
Share & tools
lore
#0 lore raw

cover Improve newc generation logging

The first two patches stand on their own, but are needed for the last patch. The first patch adds the support for the %o format specifier, which prints numbers in octal. The second patch was something Daniel requested in reply to a different patch, adding PRI* macros for types grub_off_t and grub_disk_addr_t. And the last patch improves the logging when generating newc archives on the fly. Now all paths generated will be logged with their size and mode.

Glenn

Glenn Washburn (3):
misc: Support octal printf format code include/grub/types.h: Add PRI*GRUB_OFFSET and PRI*GRUB_DISK_ADDR loader/linux: Print debug message for each generated newc path
generated

 grub-core/kern/misc.c    | 13 +++++++++++--
 grub-core/loader/linux.c |  3 ++-
 include/grub/types.h     |  7 +++++--
 3 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 misc: Support octal printf format code

Also add parenthesis to nested terciary operator to improve clarity.

---
 grub-core/kern/misc.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
grub-core/kern/misc.c +11 -2
index 977535282a33..739cc56691a1 100644
@@ -666,7 +666,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
 static inline char *
 grub_lltoa (char *str, int c, unsigned long long n)
 {
-  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
+  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : ((c == 'o') ? 8 : 10);
   char *p;
 
   if ((long long) n < 0 && c == 'd')
@@ -681,9 +681,15 @@ grub_lltoa (char *str, int c, unsigned long long n)
     do
       {
 	unsigned d = (unsigned) (n & 0xf);
-	*p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
+	*p++ = (d > 9) ? (d + ((c == 'x') ? 'a' : 'A') - 10) : d + '0';
       }
     while (n >>= 4);
+  else if (base == 8)
+    do
+      {
+	*p++ = ((unsigned) (n & 0x7)) + '0';
+      }
+    while (n >>= 3);
   else
     /* BASE == 10 */
     do
@@ -782,6 +788,7 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
 	case 'X':
 	case 'u':
 	case 'd':
+	case 'o':
 	case 'c':
 	case 'C':
 	case 's':
@@ -880,6 +887,7 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
 	{
 	case 'x':
 	case 'X':
+	case 'o':
 	case 'u':
 	  args->ptr[curn].type = UNSIGNED_INT + longfmt;
 	  break;
@@ -1089,6 +1097,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
 	case 'X':
 	case 'u':
 	case 'd':
+	case 'o':
 	  write_number (str, &count, max_len, format1, rightfill, zerofill, c, curarg);
 	  break;
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 include/grub/types.h: Add PRI*GRUB_OFFSET and PRI*GRUB_DISK_ADDR

In reply to Glenn Washburn

These are currently always the same as PRI*GRUB_UINT64_T, but they may not be in the future.

---
 include/grub/types.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/grub/types.h +5 -2
index 9f43a5580935..0d96006fe2a2 100644
@@ -182,10 +182,13 @@ typedef grub_uint64_t grub_properly_aligned_t;
 #define GRUB_PROPERLY_ALIGNED_ARRAY(name, size) grub_properly_aligned_t name[((size) + sizeof (grub_properly_aligned_t) - 1) / sizeof (grub_properly_aligned_t)]
 
 /* The type for representing a file offset.  */
-typedef grub_uint64_t	grub_off_t;
+typedef grub_uint64_t		grub_off_t;
+#define PRIxGRUB_OFFSET		PRIxGRUB_UINT64_T
+#define PRIuGRUB_OFFSET		PRIuGRUB_UINT64_T
 
 /* The type for representing a disk block address.  */
-typedef grub_uint64_t	grub_disk_addr_t;
+typedef grub_uint64_t		grub_disk_addr_t;
+#define PRIxGRUB_DISK_ADDR	PRIxGRUB_UINT64_T
 
 /* Byte-orders.  */
 static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x)
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/3 loader/linux: Print debug message for each generated newc path generated

In reply to Glenn Washburn
---
 grub-core/loader/linux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/loader/linux.c +2 -1
index cb2c3f6e4f06..35ad6bf19460 100644
@@ -64,6 +64,7 @@ make_header (grub_uint8_t *ptr,
   struct newc_head *head = (struct newc_head *) ptr;
   grub_uint8_t *optr;
   grub_size_t oh = 0;
+  grub_dprintf ("linux", "newc: Creating path '%s', mode=%s%o, size=%"PRIuGRUB_OFFSET"\n", name, (mode == 0) ? "" : "0", mode, fsize);
   grub_memcpy (head->magic, "070701", 6);
   set_field (head->ino, 0);
   set_field (head->mode, mode);
@@ -106,6 +107,7 @@ insert_dir (const char *name, struct dir **root,
   struct dir *cur, **head = root;
   const char *cb, *ce = name;
   *size = 0;
+
   while (1)
     {
       for (cb = ce; *cb == '/'; cb++);
@@ -137,7 +139,6 @@ insert_dir (const char *name, struct dir **root,
 		grub_free (n);
 		return grub_errno;
 	      }
-	      grub_dprintf ("linux", "Creating directory %s, %s\n", name, ce);
 	      ptr = make_header (ptr, tmp_name, ce - name + 1,
 				 040777, 0);
 	      grub_free (tmp_name);
Signature · 1 line
2.34.1
#4 lore raw
In reply to Glenn Washburn
Quoted 8 lines · Glenn Washburn

The first two patches stand on their own, but are needed for the last patch. The first patch adds the support for the %o format specifier, which prints numbers in octal. The second patch was something Daniel requested in reply to a different patch, adding PRI* macros for types grub_off_t and grub_disk_addr_t. And the last patch improves the logging when generating newc archives on the fly. Now all paths generated will be logged with their size and mode.

Quoted 7 lines

Glenn

Glenn Washburn (3):
misc: Support octal printf format code include/grub/types.h: Add PRI*GRUB_OFFSET and PRI*GRUB_DISK_ADDR loader/linux: Print debug message for each generated newc path
generated

For all patches Reviewed-by: Daniel Kiper <[email protected]>...

Daniel