direct-io.hg

view tools/xcutils/readnotes.c @ 13754:b235a7acaf4a

[TOOLS] Fix typos which breaks readnotes transparent gunzipping ...
From: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Emmanuel Ackaouy <ack@xensource.com>
author Emmanuel Ackaouy <ack@xensource.com>
date Wed Jan 31 15:23:51 2007 +0000 (2007-01-31)
parents 9d1d9877131d
children 5a07ea77a61d
line source
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <inttypes.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/mman.h>
13 #include <xg_private.h>
14 #include <xc_dom.h> /* gunzip bits */
16 #include <xen/libelf.h>
18 static void print_string_note(const char *prefix, struct elf_binary *elf,
19 const elf_note *note)
20 {
21 printf("%s: %s\n", prefix, (char*)elf_note_desc(elf, note));
22 }
24 static void print_numeric_note(const char *prefix, struct elf_binary *elf,
25 const elf_note *note)
26 {
27 uint64_t value = elf_note_numeric(elf, note);
28 int descsz = elf_uval(elf, note, descsz);
30 printf("%s: %#*" PRIx64 " (%d bytes)\n",
31 prefix, 2+2*descsz, value, descsz);
32 }
34 int main(int argc, char **argv)
35 {
36 const char *f;
37 int fd,h,size,usize,count;
38 void *image,*tmp;
39 struct stat st;
40 struct elf_binary elf;
41 const elf_shdr *shdr;
42 const elf_note *note, *end;
44 if (argc != 2)
45 {
46 fprintf(stderr, "Usage: readnotes <elfimage>\n");
47 return 1;
48 }
49 f = argv[1];
51 fd = open(f, O_RDONLY);
52 if (fd == -1)
53 {
54 fprintf(stderr, "Unable to open %s: %s\n", f, strerror(errno));
55 return 1;
56 }
57 if (fstat(fd, &st) == -1)
58 {
59 fprintf(stderr, "Unable to determine size of %s: %s\n",
60 f, strerror(errno));
61 return 1;
62 }
64 image = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
65 if (image == MAP_FAILED)
66 {
67 fprintf(stderr, "Unable to map %s: %s\n", f, strerror(errno));
68 return 1;
69 }
70 size = st.st_size;
72 usize = xc_dom_check_gzip(image, st.st_size);
73 if (usize)
74 {
75 tmp = malloc(usize);
76 xc_dom_do_gunzip(image, st.st_size, tmp, usize);
77 image = tmp;
78 size = usize;
79 }
81 if (0 != elf_init(&elf, image, size))
82 {
83 fprintf(stderr, "File %s is not an ELF image\n", f);
84 return 1;
85 }
86 elf_set_logfile(&elf, stderr, 0);
88 count = elf_shdr_count(&elf);
89 for ( h=0; h < count; h++)
90 {
91 shdr = elf_shdr_by_index(&elf, h);
92 if (elf_uval(&elf, shdr, sh_type) != SHT_NOTE)
93 continue;
94 end = elf_section_end(&elf, shdr);
95 for (note = elf_section_start(&elf, shdr);
96 note < end;
97 note = elf_note_next(&elf, note))
98 {
99 if (0 != strcmp(elf_note_name(&elf, note), "Xen"))
100 continue;
101 switch(elf_uval(&elf, note, type))
102 {
103 case XEN_ELFNOTE_INFO:
104 print_string_note("INFO", &elf , note);
105 break;
106 case XEN_ELFNOTE_ENTRY:
107 print_numeric_note("ENTRY", &elf , note);
108 break;
109 case XEN_ELFNOTE_HYPERCALL_PAGE:
110 print_numeric_note("HYPERCALL_PAGE", &elf , note);
111 break;
112 case XEN_ELFNOTE_VIRT_BASE:
113 print_numeric_note("VIRT_BASE", &elf , note);
114 break;
115 case XEN_ELFNOTE_PADDR_OFFSET:
116 print_numeric_note("PADDR_OFFSET", &elf , note);
117 break;
118 case XEN_ELFNOTE_XEN_VERSION:
119 print_string_note("XEN_VERSION", &elf , note);
120 break;
121 case XEN_ELFNOTE_GUEST_OS:
122 print_string_note("GUEST_OS", &elf , note);
123 break;
124 case XEN_ELFNOTE_GUEST_VERSION:
125 print_string_note("GUEST_VERSION", &elf , note);
126 break;
127 case XEN_ELFNOTE_LOADER:
128 print_string_note("LOADER", &elf , note);
129 break;
130 case XEN_ELFNOTE_PAE_MODE:
131 print_string_note("PAE_MODE", &elf , note);
132 break;
133 case XEN_ELFNOTE_FEATURES:
134 print_string_note("FEATURES", &elf , note);
135 break;
136 default:
137 printf("unknown note type %#x\n",
138 (int)elf_uval(&elf, note, type));
139 break;
140 }
141 }
142 }
144 shdr = elf_shdr_by_name(&elf, "__xen_guest");
145 if (shdr)
146 printf("__xen_guest: %s\n", (char*)elf_section_start(&elf, shdr));
148 return 0;
149 }