Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / commands / fileXX.c
blobc17d26ce677ee1cb13928b6743be3901265a8c27
1 /*
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"
25 int
26 grub_file_check_netbsdXX (grub_elf_t elf)
28 Elf_Shdr *s, *s0;
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;
33 grub_off_t stroff;
35 if (!shnum || !shentsize)
36 return 0;
38 s0 = grub_malloc (shsize);
39 if (!s0)
40 return 0;
42 if (grub_file_seek (elf->file, elf->ehdr.ehdrXX.e_shoff) == (grub_off_t) -1)
43 goto fail;
45 if (grub_file_read (elf->file, s0, shsize) != (grub_ssize_t) shsize)
46 goto fail;
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)
57 goto fail;
59 if (grub_file_read (elf->file, name, sizeof (name)) != (grub_ssize_t) sizeof (name))
61 if (grub_errno)
62 goto fail;
63 continue;
65 if (grub_memcmp (name, ".note.netbsd.ident",
66 sizeof(".note.netbsd.ident")) != 0)
67 continue;
68 grub_free (s0);
69 return 1;
71 fail:
72 grub_free (s0);
73 return 0;