File: hdump.c

package info (click to toggle)
hfsutils 3.1-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,408 kB
  • ctags: 1,340
  • sloc: ansic: 12,976; tcl: 1,894; makefile: 591; sh: 152; perl: 29
file content (147 lines) | stat: -rw-r--r-- 4,438 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * hfsutils - tools for reading and writing Macintosh HFS volumes
 * Copyright (C) 1996, 1997 Robert Leslie
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: hdump.c,v 1.2 1997/11/11 23:34:34 rob Exp $
 */

# include <stdio.h>

# include "libhfs.h"
# include "volume.h"
# include "low.h"
# include "data.h"

int main(int argc, char *argv[])
{
  hfsvol vol;
  Block0 ddr;
  Partition map;
  unsigned long bnum;
  int i;

  v_init(&vol, 0);

  if (argc != 2)
    {
      fprintf(stderr, "Usage: %s <device>\n", argv[0]);
      goto fail;
    }

  if (v_open(&vol, argv[1], HFS_MODE_RDONLY) == -1)
    {
      fprintf(stderr, "v_open: %s\n", hfs_error);
      goto fail;
    }

  if (l_getddr(&vol, &ddr) == -1)
    {
      fprintf(stderr, "l_getddr: %s\n", hfs_error);
      goto fail;
    }

  if (ddr.sbSig != HFS_DDR_SIGWORD)
    fprintf(stderr, "block 0: not a valid driver descriptor record\n");
  else
    {
      printf("===== Driver Descriptor Record =====\n");
      printf("  sbSig      \t= 0x%04x\n",  ddr.sbSig);
      printf("  sbBlkSize  \t= %d\n",  ddr.sbBlkSize);
      printf("  sbBlkCount \t= %ld\n", ddr.sbBlkCount);
      printf("  sbDevType  \t= %d\n",  ddr.sbDevType);
      printf("  sbDevId    \t= %d\n",  ddr.sbDevId);
      printf("  sbData     \t= %ld\n", ddr.sbData);
      printf("  sbDrvrCount\t= %d\n",  ddr.sbDrvrCount);

      printf("  ddBlock[0] \t= %ld\n", ddr.ddBlock);
      printf("  ddSize[0]  \t= %d\n",  ddr.ddSize);
      printf("  ddType[0]  \t= %d\n",  ddr.ddType);

      for (i = 0; i < 243; i += 4)
	{
	  ddr.ddBlock = d_getsl((char *) &ddr.ddPad[i]);
	  ddr.ddSize  = d_getsw((char *) &ddr.ddPad[i + 2]);
	  ddr.ddType  = d_getsw((char *) &ddr.ddPad[i + 3]);

	  if (ddr.ddBlock != 0 ||
	      ddr.ddSize  != 0 ||
	      ddr.ddType  != 0)
	    {
	      printf("  ddBlock[%d] \t= %ld\n", i >> 2, ddr.ddBlock);
	      printf("  ddSize[%d]  \t= %d\n",  i >> 2, ddr.ddSize);
	      printf("  ddType[%d]  \t= %d\n",  i >> 2, ddr.ddType);
	    }
	}
    }

  bnum = 1;
  while (1)
    {
      if (l_getpmentry(&vol, &map, bnum) == -1)
	{
	  fprintf(stderr, "l_getpmentry: %s\n", hfs_error);
	  goto fail;
	}

      if (map.pmSig != HFS_PM_SIGWORD)
	{
	  fprintf(stderr, "block %lu: not a valid partition entry\n", bnum);
	  goto fail;
	}

      printf("===== Partition Entry %lu =====\n", bnum);
      printf("  pmSig        \t= 0x%04x\n", map.pmSig);
      printf("  pmSigPad     \t= %d\n",     map.pmSigPad);
      printf("  pmMapBlkCnt  \t= %ld\n",    map.pmMapBlkCnt);
      printf("  pmPyPartStart\t= %ld\n",    map.pmPyPartStart);
      printf("  pmPartBlkCnt \t= %ld\n",    map.pmPartBlkCnt);
      printf("  pmPartName   \t= \"%s\"\n", map.pmPartName);
      printf("  pmParType    \t= \"%s\"\n", map.pmParType);
      printf("  pmLgDataStart\t= %ld\n",    map.pmLgDataStart);
      printf("  pmDataCnt    \t= %ld\n",    map.pmDataCnt);
      printf("  pmPartStatus \t= %ld\n",    map.pmPartStatus);
      printf("  pmLgBootStart\t= %ld\n",    map.pmLgBootStart);
      printf("  pmBootSize   \t= %ld\n",    map.pmBootSize);
      printf("  pmBootAddr   \t= %ld\n",    map.pmBootAddr);
      printf("  pmBootAddr2  \t= %ld\n",    map.pmBootAddr2);
      printf("  pmBootEntry  \t= %ld\n",    map.pmBootEntry);
      printf("  pmBootEntry2 \t= %ld\n",    map.pmBootEntry2);
      printf("  pmBootCksum  \t= %ld\n",    map.pmBootCksum);
      printf("  pmProcessor  \t= \"%s\"\n", map.pmProcessor);

      for (i = 0; i < 188; ++i)
	{
	  if (map.pmPad[i] != 0)
	    printf("  pmPad[%d]\t= %d\n", i, map.pmPad[i]);
	}

      if (bnum++ >= map.pmMapBlkCnt)
	break;
    }

  if (v_close(&vol) == -1)
    {
      fprintf(stderr, "v_close: %s\n", hfs_error);
      goto fail;
    }

  return 0;

fail:
  v_close(&vol);
  return 1;
}