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

« back to all changes in this revision

Viewing changes to debian/grub-extras/zfs/zfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  GRUB  --  GRand Unified Bootloader
3
3
 *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4
 
 *  Copyright 2008  Sun Microsystems, Inc.
 
4
 *  Copyright 2010  Sun Microsystems, Inc.
5
5
 *  Copyright (C) 2009  Vladimir Serbinenko <phcoder@gmail.com>
 
6
 *  Copyright (C) 2010  Robert Millan <rmh@gnu.org>
6
7
 *
7
8
 *  This program is free software; you can redistribute it and/or modify
8
9
 *  it under the terms of the GNU General Public License as published by
50
51
#include <grub/zfs/zfs_znode.h>
51
52
#include <grub/zfs/dmu.h>
52
53
#include <grub/zfs/dmu_objset.h>
 
54
#include <grub/zfs/sa_impl.h>
53
55
#include <grub/zfs/dsl_dir.h>
54
56
#include <grub/zfs/dsl_dataset.h>
55
57
 
163
165
};
164
166
 
165
167
decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = {
166
 
  {"inherit", 0},               /* ZIO_COMPRESS_INHERIT */
 
168
  {"inherit", NULL},            /* ZIO_COMPRESS_INHERIT */
167
169
  {"on", lzjb_decompress},      /* ZIO_COMPRESS_ON */
168
 
  {"off", 0},                   /* ZIO_COMPRESS_OFF */
 
170
  {"off", NULL},                /* ZIO_COMPRESS_OFF */
169
171
  {"lzjb", lzjb_decompress},    /* ZIO_COMPRESS_LZJB */
170
 
  {"empty", 0}                  /* ZIO_COMPRESS_EMPTY */
 
172
  {"empty", NULL},              /* ZIO_COMPRESS_EMPTY */
 
173
  {"gzip", NULL},               /* ZIO_COMPRESS_GZIP */
171
174
};
172
175
 
173
176
static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
207
210
  {zio_checksum_off, 0, 0, "off"},
208
211
  {zio_checksum_SHA256, 1, 1, "label"},
209
212
  {zio_checksum_SHA256, 1, 1, "gang_header"},
210
 
  {fletcher_2, 0, 1, "zilog"},
 
213
  {NULL, 0, 0, "zilog"},
211
214
  {fletcher_2, 0, 0, "fletcher2"},
212
215
  {fletcher_4, 1, 0, "fletcher4"},
213
216
  {zio_checksum_SHA256, 1, 0, "SHA256"},
 
217
  {NULL, 0, 0, "zilog2"},
214
218
};
215
219
 
216
220
/*
223
227
zio_checksum_verify (zio_cksum_t zc, grub_uint32_t checksum,
224
228
                     grub_zfs_endian_t endian, char *buf, int size)
225
229
{
226
 
  zio_block_tail_t *zbt = (zio_block_tail_t *) (buf + size) - 1;
 
230
  zio_eck_t *zec = (zio_eck_t *) (buf + size) - 1;
227
231
  zio_checksum_info_t *ci = &zio_checksum_table[checksum];
228
232
  zio_cksum_t actual_cksum, expected_cksum;
229
233
 
234
238
                         "unknown checksum function %d", checksum);
235
239
    }
236
240
 
237
 
  if (ci->ci_zbt)
 
241
  if (ci->ci_eck)
238
242
    {
239
 
      expected_cksum = zbt->zbt_cksum;
240
 
      zbt->zbt_cksum = zc;
 
243
      expected_cksum = zec->zec_cksum;  
 
244
      zec->zec_cksum = zc;  
241
245
      ci->ci_func (buf, size, endian, &actual_cksum);
242
 
      zbt->zbt_cksum = expected_cksum;
 
246
      zec->zec_cksum = expected_cksum;
243
247
      zc = expected_cksum;
244
248
    }
245
249
  else
515
519
          grub_size_t *size, struct grub_zfs_data *data)
516
520
{
517
521
  grub_size_t lsize, psize;
518
 
  int comp;
519
 
  char *compbuf;
 
522
  unsigned int comp;
 
523
  char *compbuf = NULL;
520
524
  grub_err_t err;
521
525
  zio_cksum_t zc = bp->blk_cksum;
522
526
  grub_uint32_t checksum;
523
527
 
 
528
  *buf = NULL;
 
529
 
524
530
  checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff;
525
 
  comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff;
 
531
  comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7;
526
532
  lsize = (BP_IS_HOLE(bp) ? 0 :
527
533
           (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1)
528
534
            << SPA_MINBLOCKSHIFT));
531
537
  if (size)
532
538
    *size = lsize;
533
539
 
534
 
  if ((unsigned int) comp >= ZIO_COMPRESS_FUNCTIONS ||
535
 
      (comp != ZIO_COMPRESS_OFF && decomp_table[comp].decomp_func == NULL))
536
 
    {
537
 
      grub_dprintf ("zfs", "comp=%d\n", comp);
538
 
      return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
539
 
                         "compression algorithm not supported\n");
540
 
    }
 
540
  if (comp >= ZIO_COMPRESS_FUNCTIONS)
 
541
    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 
542
                       "compression algorithm %u not supported\n", (unsigned int) comp);
 
543
 
 
544
  if (comp != ZIO_COMPRESS_OFF && decomp_table[comp].decomp_func == NULL)
 
545
    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 
546
                       "compression algorithm %s not supported\n", decomp_table[comp].name);
541
547
 
542
548
  if (comp != ZIO_COMPRESS_OFF)
543
549
    {
553
559
  if (err)
554
560
    {
555
561
      grub_free (compbuf);
 
562
      *buf = NULL;
556
563
      return err;
557
564
    }
558
565
 
561
568
    {
562
569
      grub_dprintf ("zfs", "incorrect checksum\n");
563
570
      grub_free (compbuf);
 
571
      *buf = NULL;
564
572
      return err;
565
573
    }
566
574
 
567
575
  if (comp != ZIO_COMPRESS_OFF)
568
576
    {
569
577
      *buf = grub_malloc (lsize);
 
578
      if (!*buf)
 
579
        {
 
580
          grub_free (compbuf);
 
581
          return grub_errno;
 
582
        }
 
583
 
570
584
      err = decomp_table[comp].decomp_func (compbuf, *buf, psize, lsize);
571
585
      grub_free (compbuf);
572
586
      if (err)
573
 
        return err;
 
587
        {
 
588
          grub_free (*buf);
 
589
          *buf = NULL;
 
590
          return err;
 
591
        }
574
592
    }
575
593
 
576
594
  return GRUB_ERR_NONE;
839
857
  return grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't find %s", name);
840
858
}
841
859
 
 
860
 
 
861
/* Verify if this is a fat zap header block */
 
862
static grub_err_t
 
863
zap_verify (zap_phys_t *zap)
 
864
{
 
865
  if (zap->zap_magic != (grub_uint64_t) ZAP_MAGIC)
 
866
    return grub_error (GRUB_ERR_BAD_FS, "bad ZAP magic");
 
867
 
 
868
  if (zap->zap_flags != 0)
 
869
    return grub_error (GRUB_ERR_BAD_FS, "bad ZAP flags");
 
870
 
 
871
  if (zap->zap_salt == 0)
 
872
    return grub_error (GRUB_ERR_BAD_FS, "bad ZAP salt");
 
873
 
 
874
  return GRUB_ERR_NONE;
 
875
}
 
876
 
842
877
/*
843
878
 * Fat ZAP lookup
844
879
 *
855
890
  grub_err_t err;
856
891
  grub_zfs_endian_t leafendian;
857
892
 
858
 
  /* Verify if this is a fat zap header block */
859
 
  if (zap->zap_magic != (grub_uint64_t) ZAP_MAGIC)
860
 
    return grub_error (GRUB_ERR_BAD_FS, "bad ZAP magic");
 
893
  err = zap_verify (zap);
 
894
  if (err)
 
895
    return err;
861
896
 
862
 
  if (zap->zap_salt == 0)
863
 
    return grub_error (GRUB_ERR_BAD_FS, "bad ZAP salt");
864
897
  hash = zap_hash (zap->zap_salt, name);
865
898
 
866
899
  /* get block id from index */
897
930
  grub_err_t err;
898
931
  grub_zfs_endian_t endian;
899
932
 
900
 
  /* Verify if this is a fat zap header block */
901
 
  if (zap->zap_magic != (grub_uint64_t) ZAP_MAGIC)
902
 
    {
903
 
      grub_error (GRUB_ERR_BAD_FS, "bad ZAP magic");
904
 
      return 0;
905
 
    }
 
933
  if (zap_verify (zap))
 
934
    return 0;
906
935
 
907
936
  /* get block id from index */
908
937
  if (zap->zap_ptrtbl.zt_numblks != 0)
1448
1477
  err = zio_read (bp, mdn->endian, (void **) &osp, &ospsize, data);
1449
1478
  if (err)
1450
1479
    return err;
1451
 
  if (ospsize < sizeof (objset_phys_t))
 
1480
  if (ospsize < OBJSET_PHYS_SIZE_V14)
1452
1481
    {
1453
1482
      grub_free (osp);
1454
1483
      return grub_error (GRUB_ERR_BAD_FS, "too small osp");
2020
2049
          continue;
2021
2050
        }
2022
2051
 
2023
 
      if (ospsize < sizeof (objset_phys_t))
 
2052
      if (ospsize < OBJSET_PHYS_SIZE_V14)
2024
2053
        {
2025
2054
          grub_dprintf ("zfs", "osp too small\n"); 
2026
2055
          grub_free (osp);
2167
2196
    }
2168
2197
 
2169
2198
  /* get the file size and set the file position to 0 */
 
2199
 
 
2200
  /*
 
2201
   * For DMU_OT_SA we will need to locate the SIZE attribute
 
2202
   * attribute, which could be either in the bonus buffer
 
2203
   * or the "spill" block.
 
2204
   */
 
2205
  if (data->dnode.dn.dn_bonustype == DMU_OT_SA)
 
2206
    {
 
2207
      sa_hdr_phys_t *sahdrp;
 
2208
      int hdrsize;
 
2209
 
 
2210
      if (data->dnode.dn.dn_bonuslen != 0)
 
2211
        {
 
2212
          sahdrp = (sa_hdr_phys_t *) DN_BONUS (&data->dnode.dn);
 
2213
        }
 
2214
      else if (data->dnode.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR)
 
2215
        {
 
2216
          blkptr_t *bp = &data->dnode.dn.dn_spill;
 
2217
 
 
2218
          err = zio_read (bp, data->dnode.endian, (void **) &sahdrp, NULL, data);
 
2219
          if (err)
 
2220
            return err;
 
2221
        }
 
2222
      else
 
2223
        {
 
2224
          return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt");
 
2225
        }
 
2226
 
 
2227
      hdrsize = SA_HDR_SIZE (sahdrp);
 
2228
      file->size = *(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET);
 
2229
    }
 
2230
  else
 
2231
    {
 
2232
      file->size = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&data->dnode.dn))->zp_size, data->dnode.endian);
 
2233
    }
 
2234
 
2170
2235
  file->data = data;
2171
2236
  file->offset = 0;
2172
 
  file->size = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&data->dnode.dn))->zp_size, data->dnode.endian);
2173
2237
 
2174
2238
#ifndef GRUB_UTIL
2175
2239
  grub_dl_ref (my_mod);