]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* util/grub-install.in: Clarify strings.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 27 Feb 2012 20:36:58 +0000 (21:36 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 27 Feb 2012 20:36:58 +0000 (21:36 +0100)
Fix source dir check.

23 files changed:
grub-core/fs/affs.c
grub-core/fs/bfs.c
grub-core/fs/btrfs.c
grub-core/fs/cpio.c
grub-core/fs/ext2.c
grub-core/fs/fat.c
grub-core/fs/hfs.c
grub-core/fs/hfsplus.c
grub-core/fs/iso9660.c
grub-core/fs/jfs.c
grub-core/fs/minix.c
grub-core/fs/nilfs2.c
grub-core/fs/ntfs.c
grub-core/fs/reiserfs.c
grub-core/fs/romfs.c
grub-core/fs/sfs.c
grub-core/fs/squash4.c
grub-core/fs/udf.c
grub-core/fs/ufs.c
grub-core/fs/xfs.c
grub-core/fs/zfs/zfs.c
include/grub/fs.h
util/grub-setup.c

index 4ebdbd5e4a56dd87aebf8bd80cd9ac6956cf0b4e..50ab8026b8692aeca82d1f29b7aa40adc1e1aba5 100644 (file)
@@ -571,6 +571,7 @@ static struct grub_fs grub_affs_fs =
     .label = grub_affs_label,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 0,
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index 095764ffe902d182f355b1ebb5ca0ed301916eaa..fd5deb056bf0bb968e0ccc731d6f9cb44b297829 100644 (file)
@@ -1027,6 +1027,7 @@ static struct grub_fs grub_bfs_fs = {
 #endif
 #ifdef GRUB_UTIL
   .reserved_first_sector = 1,
+  .blocklist_install = 1,
 #endif
 };
 
index a3a72a495dd869a5118a398893abc20206999bfc..c7b09fa8b0e5bfe3b8337b866cec35f228156289 100644 (file)
@@ -1656,6 +1656,7 @@ static struct grub_fs grub_btrfs_fs = {
 #ifdef GRUB_UTIL
   .embed = grub_btrfs_embed,
   .reserved_first_sector = 1,
+  .blocklist_install = 0,
 #endif
 };
 
index 1065df94afc1fd6836d1f7b92eee1b8c29ce619a..cadb5c184937d5c6271da7184aaade1a7f51cda3 100644 (file)
@@ -715,6 +715,7 @@ static struct grub_fs grub_cpio_fs = {
   .close = grub_cpio_close,
 #ifdef GRUB_UTIL
   .reserved_first_sector = 0,
+  .blocklist_install = 0,
 #endif
 };
 
index 875f7b9283905006762c2e314455fc2ff99cdc10..7ff3cb6f59278e33f9569c02cc18e72b941c29d1 100644 (file)
@@ -972,6 +972,7 @@ static struct grub_fs grub_ext2_fs =
     .mtime = grub_ext2_mtime,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 1,
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index a6c9760c6e886ceb3ec9260b289698a352b51557..0694051e90913d97cadf176e8f2a25f801ef11d8 100644 (file)
@@ -1154,6 +1154,7 @@ static struct grub_fs grub_fat_fs =
 #else
     .reserved_first_sector = 1,
 #endif
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index 7a5947b2309772bfe154dc4d7a39d873c07a4be7..890cdacbe3286f6ece2d572536eec9bb31e90e6f 100644 (file)
@@ -1357,6 +1357,10 @@ static struct grub_fs grub_hfs_fs =
     .label = grub_hfs_label,
     .uuid = grub_hfs_uuid,
     .mtime = grub_hfs_mtime,
+#ifdef GRUB_UTIL
+    .reserved_first_sector = 1,
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index 19cbe563fef7159c6655a3a485de4a7720e7ca7d..5635ebdede50203af5e40df8ed7e8ea7161d5339 100644 (file)
@@ -1108,6 +1108,7 @@ static struct grub_fs grub_hfsplus_fs =
     .uuid = grub_hfsplus_uuid,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 1,
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index 5e767dc27c3686361d62ebaa2bec37537d6d835b..2cff864ff3c63f3a2497ba7d4ecd96144f85789c 100644 (file)
@@ -1093,6 +1093,10 @@ static struct grub_fs grub_iso9660_fs =
     .label = grub_iso9660_label,
     .uuid = grub_iso9660_uuid,
     .mtime = grub_iso9660_mtime,
+#ifdef GRUB_UTIL
+    .reserved_first_sector = 1,
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index 3676ed7193f89dd6425508e6a298f13f62440ba6..b323fe0c8a429aa5b9e2f0457f586696ba6e4d96 100644 (file)
@@ -913,6 +913,10 @@ static struct grub_fs grub_jfs_fs =
     .close = grub_jfs_close,
     .label = grub_jfs_label,
     .uuid = grub_jfs_uuid,
+#ifdef GRUB_UTIL
+    .reserved_first_sector = 1,
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index ce5c4c7385807437b6b17d69518a70f72504eb30..03122ea4b7a584013783068b610e3b52295387cb 100644 (file)
@@ -652,6 +652,10 @@ static struct grub_fs grub_minix_fs =
     .open = grub_minix_open,
     .read = grub_minix_read,
     .close = grub_minix_close,
+#ifdef GRUB_UTIL
+    .reserved_first_sector = 1,
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index 31d91dbd904372afca5161864ca7abdf2613a0dc..89fc28bd373fa55f617da286b8a14afdb465c3a0 100644 (file)
@@ -1178,6 +1178,7 @@ static struct grub_fs grub_nilfs2_fs = {
   .mtime = grub_nilfs2_mtime,
 #ifdef GRUB_UTIL
   .reserved_first_sector = 1,
+  .blocklist_install = 0,
 #endif
   .next = 0
 };
index a2e0149458238f0e8f3174f7362133f0fc826e9e..31c01f3d5aba9264508f65c33c92da247da8a547 100644 (file)
@@ -1252,6 +1252,7 @@ static struct grub_fs grub_ntfs_fs =
     .uuid = grub_ntfs_uuid,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 1,
+    .blocklist_install = 1,
 #endif
     .next = 0
 };
index 5bb529285e2e9469c829a33a1ddb0cfa197fca48..4cb6d66c1acadd40170ea2d5ce2b6a1515623329 100644 (file)
@@ -1389,6 +1389,10 @@ static struct grub_fs grub_reiserfs_fs =
     .close = grub_reiserfs_close,
     .label = grub_reiserfs_label,
     .uuid = grub_reiserfs_uuid,
+#ifdef GRUB_UTIL
+    .reserved_first_sector = 1,
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index 3ea90a2144a6a3c24a875c512be76d0d87ed6156..c32ae9e55204ef8116281ca47583913a9d9c1961 100644 (file)
@@ -455,6 +455,7 @@ static struct grub_fs grub_romfs_fs =
     .label = grub_romfs_label,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 0,
+    .blocklist_install = 0,
 #endif
     .next = 0
   };
index bc725896309efd3ca86506b41ede24f7e1f303ed..790c361a57ad8ff10fcc73cf20c6c24e29b832c9 100644 (file)
@@ -616,6 +616,7 @@ static struct grub_fs grub_sfs_fs =
     .label = grub_sfs_label,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 0,
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index 2d66abf0799c6783232a285136cef3832dfbb7f3..06fac32df29e04f358f1dd744475b93fa1c20712 100644 (file)
@@ -935,6 +935,7 @@ static struct grub_fs grub_squash_fs =
     .mtime = grub_squash_mtime,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 0,
+    .blocklist_install = 0,
 #endif
     .next = 0
   };
index 537bb37f0ec35f8bf478d4d92c720c67425cec63..60653a54cf9f96d476ee0baf64972d3f5d75d255 100644 (file)
@@ -1097,6 +1097,10 @@ static struct grub_fs grub_udf_fs = {
   .read = grub_udf_read,
   .close = grub_udf_close,
   .label = grub_udf_label,
+#ifdef GRUB_UTIL
+  .reserved_first_sector = 1,
+  .blocklist_install = 1,
+#endif
   .next = 0
 };
 
index 12c0e87153554bdd0cf061327c6c5be97ab8ae80..1d0f7a08810d573fd040b3584c279281a0f01513 100644 (file)
@@ -791,6 +791,10 @@ static struct grub_fs grub_ufs_fs =
     .label = grub_ufs_label,
     .uuid = grub_ufs_uuid,
     .mtime = grub_ufs_mtime,
+    /* FIXME: set reserved_first_sector.  */
+#ifdef GRUB_UTIL
+    .blocklist_install = 1,
+#endif
     .next = 0
   };
 
index fbadc8fa5fe1d1d2ecc9a407c50a136e40651abd..b86e2ed0ab2474a1c7748884c09c776a1510ba21 100644 (file)
@@ -884,6 +884,7 @@ static struct grub_fs grub_xfs_fs =
     .uuid = grub_xfs_uuid,
 #ifdef GRUB_UTIL
     .reserved_first_sector = 0,
+    .blocklist_install = 1,
 #endif
     .next = 0
   };
index 131d03feb96c401ef620c213b31cd47591718e66..2320050437dac384076692caf2e2a288ffb535d2 100644 (file)
@@ -3939,6 +3939,7 @@ static struct grub_fs grub_zfs_fs = {
 #ifdef GRUB_UTIL
   .embed = grub_zfs_embed,
   .reserved_first_sector = 1,
+  .blocklist_install = 0,
 #endif
   .next = 0
 };
index 10374ed90ab1ca0e6365fb4aff9842674263714a..00b78591dc134e430cb3fd21f86c6d4bb7a194d3 100644 (file)
@@ -86,6 +86,9 @@ struct grub_fs
 
   /* Whether this filesystem reserves first sector for DOS-style boot.  */
   int reserved_first_sector;
+
+  /* Whether blocklist installs have a chance to work.  */
+  int blocklist_install;
 #endif
 };
 typedef struct grub_fs *grub_fs_t;
index 9768497c15eb46b62e6dd356197856b4c2e93dc2..2b4dce4aa72de9cab57a9335e3191d4fdd8289f5 100644 (file)
 #include <grub/msdos_partition.h>
 #include <include/grub/crypto.h>
 
+#ifdef __linux__
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#include <linux/fiemap.h>
+#endif
+
 #define _GNU_SOURCE    1
 #include <argp.h>
 
@@ -153,7 +159,6 @@ setup (const char *dir,
     = GRUB_BOOT_I386_PC_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
 #endif
   grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
-  grub_file_t file;
   FILE *fp;
 
   auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
@@ -554,6 +559,17 @@ unable_to_embed:
     grub_util_error ("%s", _("embedding is not possible, but this is required for "
                             "RAID and LVM install"));
 
+  {
+    grub_fs_t fs;
+    fs = grub_fs_probe (root_dev);
+    if (!fs)
+      grub_util_error (_("can't determine filesystem on %s"), root);
+
+    if (!fs->blocklist_install)
+      grub_util_error (_("filesystem `%s' doesn't support blocklists"),
+                      fs->name);
+  }
+
 #ifdef GRUB_SETUP_BIOS
   if (dest_dev->disk->id != root_dev->disk->id
       || dest_dev->disk->dev->id != root_dev->disk->dev->id)
@@ -580,11 +596,15 @@ unable_to_embed:
 
   grub_util_biosdisk_flush (root_dev->disk);
 
+#ifndef __linux__
+
 #define MAX_TRIES      5
   {
     int i;
     for (i = 0; i < MAX_TRIES; i++)
       {
+       grub_file_t file;
+
        grub_util_info ((i == 0) ? _("attempting to read the core image `%s' from GRUB")
                        : _("attempting to read the core image `%s' from GRUB again"),
                        core_path_dev);
@@ -648,6 +668,8 @@ unable_to_embed:
       grub_util_error (_("cannot read `%s' correctly"), core_path_dev);
   }
 
+#endif
+
   /* Clean out the blocklists.  */
   block = first_block;
   while (block->len)
@@ -664,22 +686,132 @@ unable_to_embed:
        grub_util_error ("%s", _("no terminator in the core image"));
     }
 
-  /* Now read the core image to determine where the sectors are.  */
-  grub_file_filter_disable_compression ();
-  file = grub_file_open (core_path_dev);
-  if (! file)
-    grub_util_error ("%s", grub_errmsg);
+  block = first_block;
 
-  file->read_hook = save_first_sector;
-  if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
-      != GRUB_DISK_SECTOR_SIZE)
-    grub_util_error ("%s", _("failed to read the first sector of the core image"));
+#ifdef __linux__
+  {
+    grub_partition_t container = root_dev->disk->partition;
+    struct fiemap fie1;
+    int fd;
+
+    /* Write the first two sectors of the core image onto the disk.  */
+    grub_util_info ("opening the core image `%s'", core_path);
+    fp = fopen (core_path, "rb");
+    if (! fp)
+      grub_util_error (_("cannot open `%s': %s"), core_path,
+                      strerror (errno));
+    fd = fileno (fp);
+
+    grub_memset (&fie1, 0, sizeof (fie1));
+    fie1.fm_length = core_size;
+    fie1.fm_flags = FIEMAP_FLAG_SYNC;
+
+    if (ioctl (fd, FS_IOC_FIEMAP, &fie1) < 0)
+      {
+       int nblocks, i, j;
+       int bsize;
+       int mul;
+
+       grub_util_info ("FIEMAP failed. Reverting to FIBMAP");
+
+       if (ioctl (fd, FIGETBSZ, &bsize) < 0)
+         grub_util_error (_("can't retrieve blocklists: %s"),
+                          strerror (errno));
+       if (bsize & (GRUB_DISK_SECTOR_SIZE - 1))
+         grub_util_error ("%s", _("blocksize is not divisible by 512"));
+       mul = bsize >> GRUB_DISK_SECTOR_BITS;
+       nblocks = (core_size + bsize - 1) / bsize;
+       for (i = 0; i < nblocks; i++)
+         {
+           unsigned blk = i;
+           if (ioctl (fd, FIBMAP, &blk) < 0)
+             grub_util_error (_("can't retrieve blocklists: %s"),
+                              strerror (errno));
+           
+           for (j = 0; j < mul; j++)
+             {
+               int rest = core_size - ((i * mul + j) << GRUB_DISK_SECTOR_BITS);
+               if (rest <= 0)
+                 break;
+               if (rest > GRUB_DISK_SECTOR_SIZE)
+                 rest = GRUB_DISK_SECTOR_SIZE;
+               if (i == 0 && j == 0)
+                 save_first_sector (((grub_uint64_t) blk) * mul
+                                    + grub_partition_get_start (container),
+                                    0, rest);
+               else
+                 save_blocklists (((grub_uint64_t) blk) * mul + j
+                                  + grub_partition_get_start (container),
+                                  0, rest);
+             }
+         }
+      }
+    else
+      {
+       struct fiemap *fie2;
+       int i, j;
+       fie2 = xmalloc (sizeof (*fie2)
+                       + fie1.fm_mapped_extents
+                       * sizeof (fie1.fm_extents[1]));
+       memset (fie2, 0, sizeof (*fie2)
+               + fie1.fm_mapped_extents * sizeof (fie2->fm_extents[1]));
+       fie2->fm_length = core_size;
+       fie2->fm_flags = FIEMAP_FLAG_SYNC;
+       fie2->fm_extent_count = fie1.fm_mapped_extents;
+       if (ioctl (fd, FS_IOC_FIEMAP, fie2) < 0)
+         grub_util_error (_("can't retrieve blocklists: %s"),
+                          strerror (errno));
+       for (i = 0; i < fie2->fm_mapped_extents; i++)
+         {
+           for (j = 0;
+                j < ((fie2->fm_extents[i].fe_length
+                      + GRUB_DISK_SECTOR_SIZE - 1)
+                     >> GRUB_DISK_SECTOR_BITS);
+                j++)
+             {
+               size_t len = (fie2->fm_extents[i].fe_length
+                             - j * GRUB_DISK_SECTOR_SIZE);
+               if (len > GRUB_DISK_SECTOR_SIZE)
+                 len = GRUB_DISK_SECTOR_SIZE;
+               if (i == 0 && j == 0)
+                 save_first_sector ((fie2->fm_extents[i].fe_physical
+                                     >> GRUB_DISK_SECTOR_BITS)
+                                    + j,
+                                    fie2->fm_extents[i].fe_physical
+                                    & (GRUB_DISK_SECTOR_SIZE - 1), len);
+               else
+                 save_blocklists ((fie2->fm_extents[i].fe_physical
+                                   >> GRUB_DISK_SECTOR_BITS)
+                                  + j,
+                                  fie2->fm_extents[i].fe_physical
+                                  & (GRUB_DISK_SECTOR_SIZE - 1), len);
 
-  block = first_block;
-  file->read_hook = save_blocklists;
-  if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
-      != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
-    grub_util_error ("%s", _("failed to read the rest sectors of the core image"));
+
+             }
+         }
+      }
+    fclose (fp);
+  }
+#else
+  {
+    /* Now read the core image to determine where the sectors are.  */
+    grub_file_filter_disable_compression ();
+    file = grub_file_open (core_path_dev);
+    if (! file)
+      grub_util_error ("%s", grub_errmsg);
+
+    file->read_hook = save_first_sector;
+    if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
+       != GRUB_DISK_SECTOR_SIZE)
+      grub_util_error ("%s", _("failed to read the first sector of the core image"));
+
+    block = first_block;
+    file->read_hook = save_blocklists;
+    if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
+       != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
+      grub_util_error ("%s", _("failed to read the rest sectors of the core image"));
+  }
+#endif
 
 #ifdef GRUB_SETUP_SPARC64
   {
@@ -710,8 +842,6 @@ unable_to_embed:
   }
 #endif
 
-  grub_file_close (file);
-
   free (core_path_dev);
   free (tmp_img);
 
@@ -725,7 +855,61 @@ unable_to_embed:
                     strerror (errno));
 
   grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp, core_path);
+  fflush (fp);
+  fsync (fileno (fp));
   fclose (fp);
+  grub_util_biosdisk_flush (root_dev->disk);
+
+  grub_disk_cache_invalidate_all ();
+
+  {
+    char *buf, *ptr = core_img;
+    size_t len = core_size;
+    grub_uint64_t blk;
+    grub_partition_t container = root_dev->disk->partition;
+    grub_err_t err;
+
+    root_dev->disk->partition = 0;
+
+    buf = xmalloc (core_size);
+    blk = first_sector;
+    err = grub_disk_read (dest_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE, buf);
+    if (err)
+      grub_util_error (_("cannot read `%s': %s"), dest_dev->disk->name,
+                      grub_errmsg);
+    if (grub_memcmp (buf, ptr, GRUB_DISK_SECTOR_SIZE) != 0)
+      grub_util_error ("%s", _("blocklists are invalid"));
+
+    ptr += GRUB_DISK_SECTOR_SIZE;
+    len -= GRUB_DISK_SECTOR_SIZE;
+
+    block = first_block;
+    while (block->len)
+      {
+       size_t cur = grub_target_to_host16 (block->len) << GRUB_DISK_SECTOR_BITS;
+       blk = grub_target_to_host64 (block->start);
+
+       if (cur > len)
+         cur = len;
+
+       err = grub_disk_read (dest_dev->disk, blk, 0, cur, buf);
+       if (err)
+         grub_util_error (_("cannot read `%s': %s"), dest_dev->disk->name,
+                          grub_errmsg);
+
+       if (grub_memcmp (buf, ptr, cur) != 0)
+         grub_util_error ("%s", _("blocklists are invalid"));
+
+       ptr += cur;
+       len -= cur;
+       block--;
+       
+       if ((char *) block <= core_img)
+         grub_util_error ("%s", _("no terminator in the core image"));
+      }
+    root_dev->disk->partition = container;
+    free (buf);
+  }
 
 #ifdef GRUB_SETUP_BIOS
  finish: