bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/4] Add %X option to printf functions.


From: Lubomir Rintel
Subject: [PATCH 2/4] Add %X option to printf functions.
Date: Mon, 20 Jan 2014 22:32:35 +0100

From: Paulo Flabiano Smorigo <address@hidden>

This will be needed for locating the configuration file via the same algorithm
as utilized by PXEBOOT and Yaboot, which look up file names crafted from
upper-case hexadecimal host address (will be submitted in a separate patch).

address@hidden: Clarified the commit message]
address@hidden: Add Changelog]
---
 ChangeLog             | 12 ++++++++++++
 grub-core/kern/misc.c |  7 +++++--
 grub-core/net/bootp.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------
 include/grub/net.h    |  2 ++
 4 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c91689e..f74f9a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2014-01-20  Paulo Flabiano Smorigo  <address@hidden>
+
+       * grub-core/net/bootp.c (hexdigit): Move.
+       * (parse_dhcp_vendor): Grok GRUB_NET_BOOTP_CLIENT_ID and
+       GRUB_NET_BOOTP_CLIENT_UUID.
+       * include/grub/net.h: Add GRUB_NET_BOOTP_CLIENT_ID and
+       GRUB_NET_BOOTP_CLIENT_UUID.
+
+2014-01-20  Paulo Flabiano Smorigo  <address@hidden>
+
+       * grub-core/kern/misc.c (grub_lltoa): Understand %X format.
+
 2014-01-20  Gustavo Luiz Duarte  <address@hidden>
 
        * grub-core/net/http.c (http_establish): Don't free file->data on
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 54db2e1..50f7f53 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -759,7 +759,7 @@ __umoddi3 (grub_uint64_t a, grub_uint64_t b)
 static inline char *
 grub_lltoa (char *str, int c, unsigned long long n)
 {
-  unsigned base = (c == 'x') ? 16 : 10;
+  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
   char *p;
 
   if ((long long) n < 0 && c == 'd')
@@ -774,7 +774,7 @@ grub_lltoa (char *str, int c, unsigned long long n)
     do
       {
        unsigned d = (unsigned) (n & 0xf);
-       *p++ = (d > 9) ? d + 'a' - 10 : d + '0';
+       *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
       }
     while (n >>= 4);
   else
@@ -847,6 +847,7 @@ parse_printf_args (const char *fmt0, struct printf_args 
*args,
        {
        case 'p':
        case 'x':
+       case 'X':
        case 'u':
        case 'd':
        case 'c':
@@ -927,6 +928,7 @@ parse_printf_args (const char *fmt0, struct printf_args 
*args,
       switch (c)
        {
        case 'x':
+       case 'X':
        case 'u':
          args->ptr[curn].type = UNSIGNED_INT + longfmt;
          break;
@@ -1064,6 +1066,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, 
const char *fmt0,
          c = 'x';
          /* Fall through. */
        case 'x':
+       case 'X':
        case 'u':
        case 'd':
          {
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index c14e9de..656bb71 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -60,6 +60,14 @@ set_env_limn_ro (const char *intername, const char *suffix,
   grub_free (varvalue);
 }
 
+static char
+hexdigit (grub_uint8_t val)
+{
+  if (val < 10)
+    return val + '0';
+  return val + 'a' - 10;
+}
+
 static void
 parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
 {
@@ -90,6 +98,9 @@ parse_dhcp_vendor (const char *name, const void *vend, int 
limit, int *mask)
 
       taglength = *ptr++;
 
+      grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n",
+                   tagtype, tagtype, taglength);
+
       switch (tagtype)
        {
        case GRUB_NET_BOOTP_NETMASK:
@@ -151,6 +162,39 @@ parse_dhcp_vendor (const char *name, const void *vend, int 
limit, int *mask)
          set_env_limn_ro (name, "extensionspath", (const char *) ptr, 
taglength);
          break;
 
+        case GRUB_NET_BOOTP_CLIENT_ID:
+         set_env_limn_ro (name, "clientid", (char *) ptr, taglength);
+          break;
+
+        case GRUB_NET_BOOTP_CLIENT_UUID:
+            {
+              if (taglength != 17)
+                break;
+
+              /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */
+
+              ptr += 1;
+              taglength -= 1;
+
+              char *val = grub_malloc (2 * taglength + 4 + 1);
+              int i = 0;
+              int j = 0;
+              for (i = 0; i < taglength; i++)
+                {
+                  val[2 * i + j] = hexdigit (ptr[i] >> 4);
+                  val[2 * i + 1 + j] = hexdigit (ptr[i] & 0xf);
+
+                  if ((i == 3) || (i == 5) || (i == 7) || (i == 9))
+                    {
+                      j++;
+                      val[2 * i + 1+ j] = '-';
+                    }
+                }
+
+              set_env_limn_ro (name, "clientuuid", (char *) val, 2 * taglength 
+ 4);
+            }
+          break;
+
          /* If you need any other options please contact GRUB
             development team.  */
        }
@@ -319,14 +363,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
     }
 }
 
-static char
-hexdigit (grub_uint8_t val)
-{
-  if (val < 10)
-    return val + '0';
-  return val + 'a' - 10;
-}
-
 static grub_err_t
 grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
                  int argc, char **args)
diff --git a/include/grub/net.h b/include/grub/net.h
index de6259e..64e2125 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -433,6 +433,8 @@ enum
     GRUB_NET_BOOTP_DOMAIN = 0x0f,
     GRUB_NET_BOOTP_ROOT_PATH = 0x11,
     GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12,
+    GRUB_NET_BOOTP_CLIENT_ID = 0x3d,
+    GRUB_NET_BOOTP_CLIENT_UUID = 0x61,
     GRUB_NET_BOOTP_END = 0xff
   };
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]