2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
21 #include <grub/emu/misc.h>
22 #include <grub/util/misc.h>
23 #include <grub/misc.h>
24 #include <grub/device.h>
25 #include <grub/disk.h>
26 #include <grub/file.h>
29 #include <grub/term.h>
31 #include <grub/lib/hexdump.h>
32 #include <grub/crypto.h>
33 #include <grub/command.h>
34 #include <grub/i18n.h>
35 #include <grub/zfs/zfs.h>
36 #include <grub/util/install.h>
37 #include <grub/util/resolve.h>
38 #include <grub/emu/hostfile.h>
39 #include <grub/emu/config.h>
40 #include <grub/emu/hostfile.h>
48 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
51 grub_install_help_filter (int key
, const char *text
,
52 void *input
__attribute__ ((unused
)))
56 case GRUB_INSTALL_OPTIONS_INSTALL_THEMES
:
57 return xasprintf(text
, "starfield");
58 case GRUB_INSTALL_OPTIONS_INSTALL_FONTS
:
59 return xasprintf(text
, "unicode");
60 case GRUB_INSTALL_OPTIONS_DIRECTORY
:
61 case GRUB_INSTALL_OPTIONS_DIRECTORY2
:
62 return xasprintf(text
, grub_util_get_pkglibdir ());
63 case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY
:
64 return xasprintf(text
, grub_util_get_localedir ());
65 case GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY
:
66 return grub_util_path_concat (2, grub_util_get_pkgdatadir (), "themes");
72 #pragma GCC diagnostic error "-Wformat-nonliteral"
74 static int (*compress_func
) (const char *src
, const char *dest
) = NULL
;
75 char *grub_install_copy_buffer
;
78 grub_install_copy_file (const char *src
,
82 grub_util_fd_t in
, out
;
85 grub_util_info ("copying `%s' -> `%s'", src
, dst
);
87 in
= grub_util_fd_open (src
, GRUB_UTIL_FD_O_RDONLY
);
88 if (!GRUB_UTIL_FD_IS_VALID (in
))
91 grub_util_error (_("cannot open `%s': %s"), src
, grub_util_fd_strerror ());
93 grub_util_info (_("cannot open `%s': %s"), src
, grub_util_fd_strerror ());
96 out
= grub_util_fd_open (dst
, GRUB_UTIL_FD_O_WRONLY
97 | GRUB_UTIL_FD_O_CREATTRUNC
);
98 if (!GRUB_UTIL_FD_IS_VALID (out
))
100 grub_util_error (_("cannot open `%s': %s"), dst
,
101 grub_util_fd_strerror ());
102 grub_util_fd_close (in
);
106 if (!grub_install_copy_buffer
)
107 grub_install_copy_buffer
= xmalloc (GRUB_INSTALL_COPY_BUFFER_SIZE
);
111 r
= grub_util_fd_read (in
, grub_install_copy_buffer
, GRUB_INSTALL_COPY_BUFFER_SIZE
);
114 grub_util_fd_write (out
, grub_install_copy_buffer
, r
);
116 grub_util_fd_sync (out
);
117 grub_util_fd_close (in
);
118 grub_util_fd_close (out
);
121 grub_util_error (_("cannot copy `%s' to `%s': %s"),
122 src
, dst
, grub_util_fd_strerror ());
128 grub_install_compress_file (const char *in_name
,
129 const char *out_name
,
135 ret
= grub_install_copy_file (in_name
, out_name
, is_needed
);
138 grub_util_info ("compressing `%s' -> `%s'", in_name
, out_name
);
139 ret
= !compress_func (in_name
, out_name
);
140 if (!ret
&& is_needed
)
141 grub_util_warn (_("can't compress `%s' to `%s'"), in_name
, out_name
);
144 if (!ret
&& is_needed
)
145 grub_util_error (_("cannot copy `%s' to `%s': %s"),
146 in_name
, out_name
, grub_util_fd_strerror ());
152 is_path_separator (char c
)
154 #if defined (__MINGW32__) || defined (__CYGWIN__)
164 grub_install_mkdir_p (const char *dst
)
166 char *t
= xstrdup (dst
);
170 if (is_path_separator (*p
))
183 clean_grub_dir (const char *di
)
185 grub_util_fd_dir_t d
;
186 grub_util_fd_dirent_t de
;
188 d
= grub_util_fd_opendir (di
);
190 grub_util_error (_("cannot open directory `%s': %s"),
191 di
, grub_util_fd_strerror ());
193 while ((de
= grub_util_fd_readdir (d
)))
195 const char *ext
= strrchr (de
->d_name
, '.');
196 if ((ext
&& (strcmp (ext
, ".mod") == 0
197 || strcmp (ext
, ".lst") == 0
198 || strcmp (ext
, ".img") == 0
199 || strcmp (ext
, ".mo") == 0)
200 && strcmp (de
->d_name
, "menu.lst") != 0)
201 || strcmp (de
->d_name
, "efiemu32.o") == 0
202 || strcmp (de
->d_name
, "efiemu64.o") == 0)
204 char *x
= grub_util_path_concat (2, di
, de
->d_name
);
205 if (grub_util_unlink (x
) < 0)
206 grub_util_error (_("cannot delete `%s': %s"), x
,
207 grub_util_fd_strerror ());
211 grub_util_fd_closedir (d
);
222 struct install_list install_modules
= { 1, 0, 0, 0 };
223 struct install_list modules
= { 1, 0, 0, 0 };
224 struct install_list install_locales
= { 1, 0, 0, 0 };
225 struct install_list install_fonts
= { 1, 0, 0, 0 };
226 struct install_list install_themes
= { 1, 0, 0, 0 };
227 char *grub_install_source_directory
= NULL
;
228 char *grub_install_locale_directory
= NULL
;
229 char *grub_install_themes_directory
= NULL
;
232 grub_install_push_module (const char *val
)
234 modules
.is_default
= 0;
235 if (modules
.n_entries
+ 1 >= modules
.n_alloc
)
237 modules
.n_alloc
<<= 1;
238 if (modules
.n_alloc
< 16)
239 modules
.n_alloc
= 16;
240 modules
.entries
= xrealloc (modules
.entries
,
241 modules
.n_alloc
* sizeof (*modules
.entries
));
243 modules
.entries
[modules
.n_entries
++] = xstrdup (val
);
244 modules
.entries
[modules
.n_entries
] = NULL
;
248 grub_install_pop_module (void)
251 free (modules
.entries
[modules
.n_entries
]);
252 modules
.entries
[modules
.n_entries
] = NULL
;
257 handle_install_list (struct install_list
*il
, const char *val
,
266 if (strcmp (val
, "all") == 0 && default_all
)
274 while (*ptr
&& grub_isspace (*ptr
))
278 while (*ptr
&& !grub_isspace (*ptr
))
282 il
->n_alloc
= il
->n_entries
+ 1;
283 il
->entries
= xmalloc (il
->n_alloc
* sizeof (il
->entries
[0]));
285 for (ce
= il
->entries
; ; ce
++)
288 while (*ptr
&& grub_isspace (*ptr
))
293 while (*ptr
&& !grub_isspace (*ptr
))
295 *ce
= xmalloc (ptr
- bptr
+ 1);
296 memcpy (*ce
, bptr
, ptr
- bptr
);
297 (*ce
)[ptr
- bptr
] = '\0';
302 static char **pubkeys
;
303 static size_t npubkeys
;
304 static grub_compression_t compression
;
307 grub_install_parse (int key
, char *arg
)
312 if (grub_strcmp (arg
, "xz") == 0)
315 compression
= GRUB_COMPRESSION_XZ
;
317 grub_util_error ("%s",
318 _("grub-mkimage is compiled without XZ support"));
321 else if (grub_strcmp (arg
, "none") == 0)
322 compression
= GRUB_COMPRESSION_NONE
;
323 else if (grub_strcmp (arg
, "auto") == 0)
324 compression
= GRUB_COMPRESSION_AUTO
;
326 grub_util_error (_("Unknown compression format %s"), arg
);
329 pubkeys
= xrealloc (pubkeys
,
332 pubkeys
[npubkeys
++] = xstrdup (arg
);
335 case GRUB_INSTALL_OPTIONS_VERBOSITY
:
339 case GRUB_INSTALL_OPTIONS_DIRECTORY
:
340 case GRUB_INSTALL_OPTIONS_DIRECTORY2
:
341 free (grub_install_source_directory
);
342 grub_install_source_directory
= xstrdup (arg
);
344 case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY
:
345 free (grub_install_locale_directory
);
346 grub_install_locale_directory
= xstrdup (arg
);
348 case GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY
:
349 free (grub_install_themes_directory
);
350 grub_install_themes_directory
= xstrdup (arg
);
352 case GRUB_INSTALL_OPTIONS_INSTALL_MODULES
:
353 handle_install_list (&install_modules
, arg
, 0);
355 case GRUB_INSTALL_OPTIONS_MODULES
:
356 handle_install_list (&modules
, arg
, 0);
358 case GRUB_INSTALL_OPTIONS_INSTALL_LOCALES
:
359 handle_install_list (&install_locales
, arg
, 0);
361 case GRUB_INSTALL_OPTIONS_INSTALL_THEMES
:
362 handle_install_list (&install_themes
, arg
, 0);
364 case GRUB_INSTALL_OPTIONS_INSTALL_FONTS
:
365 handle_install_list (&install_fonts
, arg
, 0);
367 case GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS
:
368 if (strcmp (arg
, "no") == 0
369 || strcmp (arg
, "none") == 0)
371 compress_func
= NULL
;
374 if (strcmp (arg
, "gz") == 0)
376 compress_func
= grub_install_compress_gzip
;
379 if (strcmp (arg
, "xz") == 0)
381 compress_func
= grub_install_compress_xz
;
384 if (strcmp (arg
, "lzo") == 0)
386 compress_func
= grub_install_compress_lzop
;
389 grub_util_error (_("Unrecognized compression `%s'"), arg
);
390 case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE
:
400 if (compress_func
== grub_install_compress_gzip
)
402 grub_install_push_module ("gzio");
405 if (compress_func
== grub_install_compress_xz
)
407 grub_install_push_module ("xzio");
408 grub_install_push_module ("gcry_crc");
411 if (compress_func
== grub_install_compress_lzop
)
413 grub_install_push_module ("lzopio");
414 grub_install_push_module ("adler32");
415 grub_install_push_module ("gcry_crc");
422 grub_install_make_image_wrap_file (const char *dir
, const char *prefix
,
423 FILE *fp
, const char *outname
,
426 const char *mkimage_target
, int note
)
428 const struct grub_install_image_target_desc
*tgt
;
429 const char *const compnames
[] =
431 [GRUB_COMPRESSION_AUTO
] = "auto",
432 [GRUB_COMPRESSION_NONE
] = "none",
433 [GRUB_COMPRESSION_XZ
] = "xz",
434 [GRUB_COMPRESSION_LZMA
] = "lzma",
436 grub_size_t slen
= 1;
439 int dc
= decompressors ();
442 slen
+= 20 + grub_strlen (memdisk_path
);
444 slen
+= 20 + grub_strlen (config_path
);
446 for (pk
= pubkeys
; pk
< pubkeys
+ npubkeys
; pk
++)
447 slen
+= 20 + grub_strlen (*pk
);
449 for (md
= modules
.entries
; *md
; md
++)
451 slen
+= 10 + grub_strlen (*md
);
454 p
= s
= xmalloc (slen
);
457 p
= grub_stpcpy (p
, "--memdisk '");
458 p
= grub_stpcpy (p
, memdisk_path
);
464 p
= grub_stpcpy (p
, "--config '");
465 p
= grub_stpcpy (p
, config_path
);
469 for (pk
= pubkeys
; pk
< pubkeys
+ npubkeys
; pk
++)
471 p
= grub_stpcpy (p
, "--pubkey '");
472 p
= grub_stpcpy (p
, *pk
);
477 for (md
= modules
.entries
; *md
; md
++)
480 p
= grub_stpcpy (p
, *md
);
487 grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'"
489 "--format '%s' --compression '%s' %s %s\n",
491 outname
, mkimage_target
,
492 compnames
[compression
], note
? "--note" : "", s
);
495 tgt
= grub_install_get_image_target (mkimage_target
);
497 grub_util_error (_("unknown target format %s\n"), mkimage_target
);
499 grub_install_generate_image (dir
, prefix
, fp
, outname
,
500 modules
.entries
, memdisk_path
,
501 pubkeys
, npubkeys
, config_path
, tgt
,
504 grub_install_pop_module ();
508 grub_install_make_image_wrap (const char *dir
, const char *prefix
,
509 const char *outname
, char *memdisk_path
,
511 const char *mkimage_target
, int note
)
515 fp
= grub_util_fopen (outname
, "wb");
517 grub_util_error (_("cannot open `%s': %s"), outname
,
519 grub_install_make_image_wrap_file (dir
, prefix
, fp
, outname
,
520 memdisk_path
, config_path
,
521 mkimage_target
, note
);
522 grub_util_file_sync (fp
);
527 copy_by_ext (const char *srcd
,
532 grub_util_fd_dir_t d
;
533 grub_util_fd_dirent_t de
;
535 d
= grub_util_fd_opendir (srcd
);
539 grub_util_error (_("cannot open directory `%s': %s"),
540 srcd
, grub_util_fd_strerror ());
542 while ((de
= grub_util_fd_readdir (d
)))
544 const char *ext
= strrchr (de
->d_name
, '.');
545 if (ext
&& strcmp (ext
, extf
) == 0)
547 char *srcf
= grub_util_path_concat (2, srcd
, de
->d_name
);
548 char *dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
549 grub_install_compress_file (srcf
, dstf
, 1);
554 grub_util_fd_closedir (d
);
558 copy_all (const char *srcd
,
561 grub_util_fd_dir_t d
;
562 grub_util_fd_dirent_t de
;
564 d
= grub_util_fd_opendir (srcd
);
566 grub_util_error (_("cannot open directory `%s': %s"),
567 srcd
, grub_util_fd_strerror ());
569 while ((de
= grub_util_fd_readdir (d
)))
573 if (strcmp (de
->d_name
, ".") == 0
574 || strcmp (de
->d_name
, "..") == 0)
576 srcf
= grub_util_path_concat (2, srcd
, de
->d_name
);
577 if (grub_util_is_special_file (srcf
)
578 || grub_util_is_directory (srcf
))
580 dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
581 grub_install_compress_file (srcf
, dstf
, 1);
585 grub_util_fd_closedir (d
);
591 if (grub_install_locale_directory
)
592 return grub_install_locale_directory
;
594 return grub_util_get_localedir ();
598 copy_locales (const char *dstd
)
600 grub_util_fd_dir_t d
;
601 grub_util_fd_dirent_t de
;
602 const char *locale_dir
= get_localedir ();
604 d
= grub_util_fd_opendir (locale_dir
);
607 grub_util_warn (_("cannot open directory `%s': %s"),
608 locale_dir
, grub_util_fd_strerror ());
612 while ((de
= grub_util_fd_readdir (d
)))
617 if (strcmp (de
->d_name
, ".") == 0)
619 if (strcmp (de
->d_name
, "..") == 0)
621 ext
= grub_strrchr (de
->d_name
, '.');
622 if (ext
&& (grub_strcmp (ext
, ".mo") == 0
623 || grub_strcmp (ext
, ".gmo") == 0))
625 srcf
= grub_util_path_concat (2, locale_dir
, de
->d_name
);
626 dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
627 ext
= grub_strrchr (dstf
, '.');
628 grub_strcpy (ext
, ".mo");
632 srcf
= grub_util_path_concat_ext (4, locale_dir
, de
->d_name
,
633 "LC_MESSAGES", PACKAGE
, ".mo");
634 dstf
= grub_util_path_concat_ext (2, dstd
, de
->d_name
, ".mo");
636 grub_install_compress_file (srcf
, dstf
, 0);
640 grub_util_fd_closedir (d
);
646 const char *platform
;
647 } platforms
[GRUB_INSTALL_PLATFORM_MAX
] =
649 [GRUB_INSTALL_PLATFORM_I386_PC
] = { "i386", "pc" },
650 [GRUB_INSTALL_PLATFORM_I386_EFI
] = { "i386", "efi" },
651 [GRUB_INSTALL_PLATFORM_I386_QEMU
] = { "i386", "qemu" },
652 [GRUB_INSTALL_PLATFORM_I386_COREBOOT
] = { "i386", "coreboot" },
653 [GRUB_INSTALL_PLATFORM_I386_MULTIBOOT
] = { "i386", "multiboot" },
654 [GRUB_INSTALL_PLATFORM_I386_IEEE1275
] = { "i386", "ieee1275" },
655 [GRUB_INSTALL_PLATFORM_X86_64_EFI
] = { "x86_64", "efi" },
656 [GRUB_INSTALL_PLATFORM_I386_XEN
] = { "i386", "xen" },
657 [GRUB_INSTALL_PLATFORM_X86_64_XEN
] = { "x86_64", "xen" },
658 [GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON
] = { "mipsel", "loongson" },
659 [GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS
] = { "mipsel", "qemu_mips" },
660 [GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS
] = { "mips", "qemu_mips" },
661 [GRUB_INSTALL_PLATFORM_MIPSEL_ARC
] = { "mipsel", "arc" },
662 [GRUB_INSTALL_PLATFORM_MIPS_ARC
] = { "mips", "arc" },
663 [GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275
] = { "sparc64", "ieee1275" },
664 [GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275
] = { "powerpc", "ieee1275" },
665 [GRUB_INSTALL_PLATFORM_IA64_EFI
] = { "ia64", "efi" },
666 [GRUB_INSTALL_PLATFORM_ARM_EFI
] = { "arm", "efi" },
667 [GRUB_INSTALL_PLATFORM_ARM64_EFI
] = { "arm64", "efi" },
668 [GRUB_INSTALL_PLATFORM_ARM_UBOOT
] = { "arm", "uboot" },
672 grub_install_get_platforms_string (void)
674 char **arr
= xmalloc (sizeof (char *) * ARRAY_SIZE (platforms
));
675 int platform_strins_len
= 0;
676 char *platforms_string
;
679 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
681 arr
[i
] = xasprintf ("%s-%s", platforms
[i
].cpu
,
682 platforms
[i
].platform
);
683 platform_strins_len
+= strlen (arr
[i
]) + 2;
685 ptr
= platforms_string
= xmalloc (platform_strins_len
);
686 qsort (arr
, ARRAY_SIZE (platforms
), sizeof (char *), grub_qsort_strcmp
);
687 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
689 strcpy (ptr
, arr
[i
]);
690 ptr
+= strlen (arr
[i
]);
698 return platforms_string
;
702 grub_install_get_platform_name (enum grub_install_plat platid
)
704 return xasprintf ("%s-%s", platforms
[platid
].cpu
,
705 platforms
[platid
].platform
);
709 grub_install_get_platform_cpu (enum grub_install_plat platid
)
711 return platforms
[platid
].cpu
;
715 grub_install_get_platform_platform (enum grub_install_plat platid
)
717 return platforms
[platid
].platform
;
722 grub_install_copy_files (const char *src
,
724 enum grub_install_plat platid
)
726 char *dst_platform
, *dst_locale
, *dst_fonts
;
727 const char *pkgdatadir
= grub_util_get_pkgdatadir ();
732 platform
= xasprintf ("%s-%s", platforms
[platid
].cpu
,
733 platforms
[platid
].platform
);
734 dst_platform
= grub_util_path_concat (2, dst
, platform
);
737 dst_locale
= grub_util_path_concat (2, dst
, "locale");
738 dst_fonts
= grub_util_path_concat (2, dst
, "fonts");
739 grub_install_mkdir_p (dst_platform
);
740 grub_install_mkdir_p (dst_locale
);
741 clean_grub_dir (dst
);
742 clean_grub_dir (dst_platform
);
743 clean_grub_dir (dst_locale
);
745 if (install_modules
.is_default
)
746 copy_by_ext (src
, dst_platform
, ".mod", 1);
749 struct grub_util_path_list
*path_list
, *p
;
751 path_list
= grub_util_resolve_dependencies (src
, "moddep.lst",
752 install_modules
.entries
);
753 for (p
= path_list
; p
; p
= p
->next
)
755 const char *srcf
= p
->name
;
759 dir
= grub_strrchr (srcf
, '/');
764 dstf
= grub_util_path_concat (2, dst_platform
, dir
);
765 grub_install_compress_file (srcf
, dstf
, 1);
770 const char *pkglib_DATA
[] = {"efiemu32.o", "efiemu64.o",
771 "moddep.lst", "command.lst",
772 "fs.lst", "partmap.lst",
774 "video.lst", "crypto.lst",
775 "terminal.lst", "modinfo.sh" };
778 for (i
= 0; i
< ARRAY_SIZE (pkglib_DATA
); i
++)
780 char *srcf
= grub_util_path_concat (2, src
, pkglib_DATA
[i
]);
781 char *dstf
= grub_util_path_concat (2, dst_platform
, pkglib_DATA
[i
]);
782 if (i
== 0 || i
== 1)
783 grub_install_compress_file (srcf
, dstf
, 0);
785 grub_install_compress_file (srcf
, dstf
, 1);
790 if (install_locales
.is_default
)
792 char *srcd
= grub_util_path_concat (2, src
, "po");
793 copy_by_ext (srcd
, dst_locale
, ".mo", 0);
794 copy_locales (dst_locale
);
799 const char *locale_dir
= get_localedir ();
801 for (i
= 0; i
< install_locales
.n_entries
; i
++)
803 char *srcf
= grub_util_path_concat_ext (3, src
,
805 install_locales
.entries
[i
],
807 char *dstf
= grub_util_path_concat_ext (2, dst_locale
,
808 install_locales
.entries
[i
],
810 if (grub_install_compress_file (srcf
, dstf
, 0))
817 srcf
= grub_util_path_concat_ext (4,
819 install_locales
.entries
[i
],
823 if (grub_install_compress_file (srcf
, dstf
, 0))
829 grub_util_error (_("cannot find locale `%s'"),
830 install_locales
.entries
[i
]);
834 if (install_themes
.is_default
)
836 install_themes
.is_default
= 0;
837 install_themes
.n_entries
= 1;
838 install_themes
.entries
= xmalloc (2 * sizeof (install_themes
.entries
[0]));
839 install_themes
.entries
[0] = xstrdup ("starfield");
840 install_themes
.entries
[1] = NULL
;
843 if (grub_install_themes_directory
)
844 themes_dir
= xstrdup (grub_install_themes_directory
);
846 themes_dir
= grub_util_path_concat (2, grub_util_get_pkgdatadir (),
849 for (i
= 0; i
< install_themes
.n_entries
; i
++)
851 char *srcf
= grub_util_path_concat (3, themes_dir
,
852 install_themes
.entries
[i
],
854 if (grub_util_is_regular (srcf
))
856 char *srcd
= grub_util_path_concat (2, themes_dir
,
857 install_themes
.entries
[i
]);
858 char *dstd
= grub_util_path_concat (3, dst
, "themes",
859 install_themes
.entries
[i
]);
860 grub_install_mkdir_p (dstd
);
861 copy_all (srcd
, dstd
);
870 if (install_fonts
.is_default
)
872 install_fonts
.is_default
= 0;
873 install_fonts
.n_entries
= 1;
874 install_fonts
.entries
= xmalloc (2 * sizeof (install_fonts
.entries
[0]));
875 install_fonts
.entries
[0] = xstrdup ("unicode");
876 install_fonts
.entries
[1] = NULL
;
879 grub_install_mkdir_p (dst_fonts
);
881 for (i
= 0; i
< install_fonts
.n_entries
; i
++)
883 char *srcf
= grub_util_path_concat_ext (2, pkgdatadir
,
884 install_fonts
.entries
[i
],
886 char *dstf
= grub_util_path_concat_ext (2, dst_fonts
,
887 install_fonts
.entries
[i
],
890 grub_install_compress_file (srcf
, dstf
, 0);
900 enum grub_install_plat
901 grub_install_get_target (const char *src
)
909 fn
= grub_util_path_concat (2, src
, "modinfo.sh");
910 f
= grub_util_fd_open (fn
, GRUB_UTIL_FD_O_RDONLY
);
911 if (!GRUB_UTIL_FD_IS_VALID (f
))
912 grub_util_error (_("%s doesn't exist. Please specify --target or --directory"),
914 r
= grub_util_fd_read (f
, buf
, sizeof (buf
) - 1);
916 grub_util_error (_("cannot read `%s': %s"), fn
, strerror (errno
));
917 grub_util_fd_close (f
);
919 c
= strstr (buf
, "grub_modinfo_target_cpu=");
920 if (!c
|| (c
!= buf
&& !grub_isspace (*(c
-1))))
921 grub_util_error (_("invalid modinfo file `%s'"), fn
);
922 pl
= strstr (buf
, "grub_modinfo_platform=");
923 if (!pl
|| (pl
!= buf
&& !grub_isspace (*(pl
-1))))
924 grub_util_error (_("invalid modinfo file `%s'"), fn
);
925 c
+= sizeof ("grub_modinfo_target_cpu=") - 1;
926 pl
+= sizeof ("grub_modinfo_platform=") - 1;
927 for (p
= c
; *p
&& !grub_isspace (*p
); p
++);
929 for (p
= pl
; *p
&& !grub_isspace (*p
); p
++);
932 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
933 if (strcmp (platforms
[i
].cpu
, c
) == 0
934 && strcmp (platforms
[i
].platform
, pl
) == 0)
939 grub_util_error (_("Unknown platform `%s-%s'"), c
, pl
);
944 grub_util_unlink_recursive (const char *name
)
946 grub_util_fd_dir_t d
;
947 grub_util_fd_dirent_t de
;
949 d
= grub_util_fd_opendir (name
);
951 while ((de
= grub_util_fd_readdir (d
)))
954 if (strcmp (de
->d_name
, ".") == 0)
956 if (strcmp (de
->d_name
, "..") == 0)
958 fp
= grub_util_path_concat (2, name
, de
->d_name
);
959 if (grub_util_is_special_file (fp
))
964 if (grub_util_is_regular (fp
))
965 grub_util_unlink (fp
);
966 else if (grub_util_is_directory (fp
))
967 grub_util_unlink_recursive (fp
);
970 grub_util_rmdir (name
);
971 grub_util_fd_closedir (d
);