~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2013  Free Software Foundation, Inc.
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include <grub/fileid.h>
 
20
#include <grub/elfload.h>
 
21
 
 
22
#pragma GCC diagnostic ignored "-Wcast-align"
 
23
 
 
24
int
 
25
grub_file_check_netbsdXX (grub_elf_t elf)
 
26
{
 
27
  Elf_Shdr *s, *s0;
 
28
 
 
29
  grub_size_t shnum = elf->ehdr.ehdrXX.e_shnum;
 
30
  grub_size_t shentsize = elf->ehdr.ehdrXX.e_shentsize;
 
31
  grub_size_t shsize = shnum * shentsize;
 
32
  grub_off_t stroff;
 
33
 
 
34
  if (!shnum || !shentsize)
 
35
    return 0;
 
36
 
 
37
  s0 = grub_malloc (shsize);
 
38
  if (!s0)
 
39
    return 0;
 
40
 
 
41
  if (grub_file_seek (elf->file, elf->ehdr.ehdrXX.e_shoff) == (grub_off_t) -1)
 
42
    return 0;
 
43
 
 
44
  if (grub_file_read (elf->file, s0, shsize) != (grub_ssize_t) shsize)
 
45
    return 0;
 
46
 
 
47
  s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize);
 
48
  stroff = s->sh_offset;
 
49
 
 
50
  for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize);
 
51
       s = (Elf_Shdr *) ((char *) s + shentsize))
 
52
    {
 
53
      char name[sizeof(".note.netbsd.ident")];
 
54
      grub_memset (name, 0, sizeof (name));
 
55
      if (grub_file_seek (elf->file, stroff + s->sh_name) == (grub_off_t) -1)
 
56
        return grub_errno;
 
57
 
 
58
      if (grub_file_read (elf->file, name, sizeof (name)) != (grub_ssize_t) sizeof (name))
 
59
        {
 
60
          if (grub_errno)
 
61
            return grub_errno;
 
62
          continue;
 
63
        }
 
64
      if (grub_memcmp (name, ".note.netbsd.ident",
 
65
                       sizeof(".note.netbsd.ident")) != 0)
 
66
        continue;
 
67
      return 1;
 
68
    }
 
69
  return 0;
 
70
}