~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/commands/xnu_uuid.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* xnu_uuid.c - transform 64-bit serial number
 
2
   to 128-bit uuid suitable for xnu. */
 
3
/*
 
4
 *  GRUB  --  GRand Unified Bootloader
 
5
 *  Copyright (C) 1995,1996,1998,1999,2001,2002,
 
6
 *                2003, 2009  Free Software Foundation, Inc.
 
7
 *
 
8
 *  GRUB is free software: you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation, either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  GRUB is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#include <grub/types.h>
 
23
#include <grub/misc.h>
 
24
#include <grub/mm.h>
 
25
#include <grub/err.h>
 
26
#include <grub/dl.h>
 
27
#include <grub/device.h>
 
28
#include <grub/disk.h>
 
29
#include <grub/fs.h>
 
30
#include <grub/file.h>
 
31
#include <grub/misc.h>
 
32
#include <grub/env.h>
 
33
#include <grub/command.h>
 
34
#include <grub/i18n.h>
 
35
#include <grub/crypto.h>
 
36
 
 
37
/* This prefix is used by xnu and boot-132 to hash
 
38
   together with volume serial. */
 
39
static grub_uint8_t hash_prefix[16]
 
40
  = {0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6,
 
41
     0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC};
 
42
 
 
43
static grub_err_t
 
44
grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
 
45
                   int argc, char **args)
 
46
{
 
47
  grub_uint64_t serial;
 
48
  grub_uint8_t *xnu_uuid;
 
49
  char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
 
50
  char *ptr;
 
51
  grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
 
52
 
 
53
  if (argc < 1)
 
54
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required");
 
55
 
 
56
  serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16));
 
57
 
 
58
  GRUB_MD_MD5->init (&ctx);
 
59
  GRUB_MD_MD5->write (&ctx, hash_prefix, sizeof (hash_prefix));
 
60
  GRUB_MD_MD5->write (&ctx, &serial, sizeof (serial));
 
61
  GRUB_MD_MD5->final (&ctx);
 
62
  xnu_uuid = GRUB_MD_MD5->read (&ctx);
 
63
 
 
64
  grub_snprintf (uuid_string, sizeof (uuid_string),
 
65
                "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
 
66
                (unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1],
 
67
                (unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],
 
68
                (unsigned int) xnu_uuid[4], (unsigned int) xnu_uuid[5],
 
69
                (unsigned int) ((xnu_uuid[6] & 0xf) | 0x30),
 
70
                (unsigned int) xnu_uuid[7],
 
71
                (unsigned int) ((xnu_uuid[8] & 0x3f) | 0x80),
 
72
                (unsigned int) xnu_uuid[9],
 
73
                (unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
 
74
                (unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
 
75
                (unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
 
76
  for (ptr = uuid_string; *ptr; ptr++)
 
77
    *ptr = grub_toupper (*ptr);
 
78
  if (argc == 1)
 
79
    grub_printf ("%s", uuid_string);
 
80
  if (argc > 1)
 
81
    grub_env_set (args[1], uuid_string);
 
82
 
 
83
  return GRUB_ERR_NONE;
 
84
}
 
85
 
 
86
static grub_command_t cmd;
 
87
 
 
88
 
 
89
GRUB_MOD_INIT (xnu_uuid)
 
90
{
 
91
  cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid,
 
92
                               N_("GRUBUUID [VARNAME]"),
 
93
                               N_("Transform 64-bit UUID to format "
 
94
                               "suitable for XNU."));
 
95
}
 
96
 
 
97
GRUB_MOD_FINI (xnu_uuid)
 
98
{
 
99
  grub_unregister_command (cmd);
 
100
}