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>
21 #include <grub/misc.h>
23 #pragma GCC diagnostic ignored "-Wcast-align"
26 grub_file_check_netbsdXX (grub_elf_t elf
)
30 grub_size_t shnum
= elf
->ehdr
.ehdrXX
.e_shnum
;
31 grub_size_t shentsize
= elf
->ehdr
.ehdrXX
.e_shentsize
;
32 grub_size_t shsize
= shnum
* shentsize
;
35 if (!shnum
|| !shentsize
)
38 s0
= grub_malloc (shsize
);
42 if (grub_file_seek (elf
->file
, elf
->ehdr
.ehdrXX
.e_shoff
) == (grub_off_t
) -1)
45 if (grub_file_read (elf
->file
, s0
, shsize
) != (grub_ssize_t
) shsize
)
48 s
= (Elf_Shdr
*) ((char *) s0
+ elf
->ehdr
.ehdrXX
.e_shstrndx
* shentsize
);
49 stroff
= s
->sh_offset
;
51 for (s
= s0
; s
< (Elf_Shdr
*) ((char *) s0
+ shnum
* shentsize
);
52 s
= (Elf_Shdr
*) ((char *) s
+ shentsize
))
54 char name
[sizeof(".note.netbsd.ident")];
55 grub_memset (name
, 0, sizeof (name
));
56 if (grub_file_seek (elf
->file
, stroff
+ s
->sh_name
) == (grub_off_t
) -1)
59 if (grub_file_read (elf
->file
, name
, sizeof (name
)) != (grub_ssize_t
) sizeof (name
))
65 if (grub_memcmp (name
, ".note.netbsd.ident",
66 sizeof(".note.netbsd.ident")) != 0)