2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 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/>.
19
#include <grub/fileid.h>
20
#include <grub/elfload.h>
22
#pragma GCC diagnostic ignored "-Wcast-align"
25
grub_file_check_netbsdXX (grub_elf_t elf)
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;
34
if (!shnum || !shentsize)
37
s0 = grub_malloc (shsize);
41
if (grub_file_seek (elf->file, elf->ehdr.ehdrXX.e_shoff) == (grub_off_t) -1)
44
if (grub_file_read (elf->file, s0, shsize) != (grub_ssize_t) shsize)
47
s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize);
48
stroff = s->sh_offset;
50
for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize);
51
s = (Elf_Shdr *) ((char *) s + shentsize))
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)
58
if (grub_file_read (elf->file, name, sizeof (name)) != (grub_ssize_t) sizeof (name))
64
if (grub_memcmp (name, ".note.netbsd.ident",
65
sizeof(".note.netbsd.ident")) != 0)