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

« back to all changes in this revision

Viewing changes to util/i386/pc/grub-setup.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2007-11-01 13:18:51 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20071101131851-63uqsb4dax2h1cbm
Tags: upstream-1.95+20071101
ImportĀ upstreamĀ versionĀ 1.95+20071101

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* grub-setup.c - make GRUB usable */
2
2
/*
3
3
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
 
4
 *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007  Free Software Foundation, Inc.
5
5
 *
6
 
 *  GRUB is free software; you can redistribute it and/or modify
 
6
 *  GRUB is free software: you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  the Free Software Foundation, either version 3 of the License, or
9
9
 *  (at your option) any later version.
10
10
 *
11
 
 *  This program is distributed in the hope that it will be useful,
 
11
 *  GRUB is distributed in the hope that it will be useful,
12
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 *  GNU General Public License for more details.
15
15
 *
16
16
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with GRUB; if not, write to the Free Software
18
 
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
35
34
#include <grub/util/raid.h>
36
35
#include <grub/util/lvm.h>
37
36
 
 
37
#include <grub_setup_init.h>
 
38
 
38
39
#include <stdio.h>
39
40
#include <unistd.h>
40
41
#include <string.h>
50
51
#define DEFAULT_BOOT_FILE       "boot.img"
51
52
#define DEFAULT_CORE_FILE       "core.img"
52
53
 
53
 
#ifdef __NetBSD__
54
 
/* NetBSD uses /boot for its boot block.  */
55
 
# define DEFAULT_DIRECTORY      "/grub"
56
 
#else
57
 
# define DEFAULT_DIRECTORY      "/boot/grub"
58
 
#endif
59
 
 
60
 
#define DEFAULT_DEVICE_MAP      DEFAULT_DIRECTORY "/device.map"
61
 
 
62
54
/* This is the blocklist used in the diskboot image.  */
63
55
struct boot_blocklist
64
56
{
115
107
  grub_file_t file;
116
108
  FILE *fp;
117
109
  unsigned long first_start = ~0UL;
 
110
  int able_to_embed = 1;
118
111
  
119
 
  auto void save_first_sector (grub_disk_addr_t sector, unsigned offset,
 
112
  auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
120
113
                               unsigned length);
121
 
  auto void save_blocklists (grub_disk_addr_t sector, unsigned offset,
 
114
  auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
122
115
                             unsigned length);
123
116
 
124
117
  auto int find_first_partition_start (grub_disk_t disk,
137
130
      return 0;
138
131
    }
139
132
  
140
 
  void save_first_sector (grub_disk_addr_t sector, unsigned offset,
 
133
  void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
141
134
                          unsigned length)
142
135
    {
143
136
      grub_util_info ("the first sector is <%llu,%u,%u>",
149
142
      first_sector = sector;
150
143
    }
151
144
 
152
 
  void save_blocklists (grub_disk_addr_t sector, unsigned offset,
 
145
  void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
153
146
                        unsigned length)
154
147
    {
155
148
      struct boot_blocklist *prev = block + 1;
333
326
 
334
327
          goto finish;
335
328
        }
 
329
      else
 
330
        able_to_embed = 0;
336
331
    }
337
 
  else if (must_embed)
 
332
  else
 
333
    able_to_embed = 0;
 
334
 
 
335
  if (must_embed && !able_to_embed)
338
336
    grub_util_error ("Can't embed the core image, but this is required when\n"
339
337
                     "the root device is on a RAID array or LVM volume.");
340
338
  
662
660
 
663
661
  /* Initialize the emulated biosdisk driver.  */
664
662
  grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
665
 
  grub_pc_partition_map_init ();
666
 
  grub_gpt_partition_map_init ();
667
663
 
 
664
  /* Initialize all modules. */
 
665
  grub_init_all ();
 
666
  
668
667
  dest_dev = get_device_name (argv[optind]);
669
668
  if (! dest_dev)
670
669
    {
682
681
 
683
682
  prefix = grub_get_prefix (dir ? : DEFAULT_DIRECTORY);
684
683
  
685
 
  /* Initialize filesystems.  */
686
 
  grub_fat_init ();
687
 
  grub_ext2_init ();
688
 
  grub_ufs_init ();
689
 
  grub_minix_init ();
690
 
  grub_hfs_init ();
691
 
  grub_jfs_init ();
692
 
  
693
684
  if (root_dev)
694
685
    {
695
686
      char *tmp = get_device_name (root_dev);
758
749
           root_dev, dest_dev, must_embed);
759
750
 
760
751
  /* Free resources.  */
761
 
  grub_ext2_fini ();
762
 
  grub_fat_fini ();
763
 
  grub_ufs_fini ();
764
 
  grub_minix_fini ();
765
 
  grub_hfs_fini ();
766
 
  grub_jfs_fini ();
767
 
  
768
 
  grub_gpt_partition_map_fini ();
769
 
  grub_pc_partition_map_fini ();
 
752
  grub_fini_all ();
770
753
  grub_util_biosdisk_fini ();
771
754
  
772
755
  free (boot_file);