source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/gpl-linux/dumpconv.c @ 146

Last change on this file since 146 was 16, checked in by rock, 17 years ago
File size: 3.7 KB
RevLine 
[16]1/***************************************************************************
2 *
3 * Copyright (C) 2001 International Business Machines
4 * All rights reserved.
5 *
6 * This file is part of the GPFS mmfslinux kernel module.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 *  1. Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright
15 *     notice, this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *  3. The name of the author may not be used to endorse or promote products
18 *     derived from this software without specific prior written
19 *     permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *************************************************************************** */
33static char sccsid[] = "@(#)00  1.1  src/avs/fs/mmfs/ts/kernext/gpl-linux/dumpconv.c, mmfs, avs_rgpfs24, rgpfs240610b 10/9/01 13:11:31";
34
35/*
36 * A conversion program for translating output from
37 * the lcrash internal "dump -B" command into binary format.
38 * This command expects an input file that was written via
39 *
40 *   dump -B <address> <bytecount> -w <outfile>
41 *
42 * The "dump -B" command produces output such as this
43 *
44 * 0xc8b63000: 71 82 e9 ac fd d6 bc 3b c0 5f 0d 00 c0 0c 00 00 : q......;._.....
45 * 0xc8b63010: 00 00 0c 00 6a 3c 70 30 01 fa 00 00 58 05 38 08 : ....j<p0....X.8
46 * 0xc8b63020: 71 82 e9 ac fe d6 bc 3b ef ac 01 00 c1 0c 00 00 : q......;.......
47 *
48 * Usage:
49 *   dumpconv <lcrashDumpFile> <outBinaryFile>
50 */
51#include <stdio.h>
52#include <fcntl.h>
53#include <unistd.h>
54#include <stdlib.h>
55
56int
57convert(FILE *fp, int fd)
58{
59  unsigned int hex;
60  unsigned char byte;
61  char string[160];
62  int i, rc, found;
63
64  while (fgets(string, sizeof(string), fp) != NULL)
65  {
66    found = 0;
67    for (i = 0; i < sizeof(string); i++)
68    {
69      if (string[i] == ':')
70      {
71        found = 1;
72        break;
73      }
74    }
75
76    if (!found)
77      goto xerror;
78   
79    found = 0;
80    for (i = i + 1; i < sizeof(string); i++)
81    {
82      if (string[i] == ' ')
83        continue;
84      if (string[i] == ':')
85      {
86        found = 1;
87        break;
88      }
89
90      rc = sscanf(&string[i], "%2x", &hex);
91      if (rc == 0)
92        goto xerror;
93      i = i + 1;  /* read two digits */
94
95      byte = (char)hex;
96      write(fd, (void *)&byte, 1);
97    }
98
99    if (!found)
100      goto xerror;
101  }
102  return 0;
103
104xerror:
105  printf("Confused by: %s\n", string);
106  return -1;
107}
108
109int
110main(int argc, char **argv)
111{
112  FILE *fp;
113  int fd;
114
115  if (argc != 3)
116  {
117    printf("dumpconv <lcrashDumpFile> <outBinaryFile>\n");
118    exit(1);
119  }
120
121  fp = fopen(argv[1], "r");
122  if (fp == NULL)
123  {
124    perror("fopen");
125    exit(1);
126  }
127
128  fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0600);
129  if (fd < 0)
130  {
131    perror("open");
132    exit(2);
133  }
134
135  convert(fp, fd);
136}
Note: See TracBrowser for help on using the repository browser.