-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshow.cpp
More file actions
143 lines (124 loc) · 4.77 KB
/
show.cpp
File metadata and controls
143 lines (124 loc) · 4.77 KB
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
/*
show.c: print summaries of disk contents
Copyright (C) 2013 Adam Sampson <ats@offog.org>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "disk.h"
#include "util.h"
#include <stdio.h>
void show_mode(const data_mode_t *mode, FILE *out) {
if (mode == NULL) {
fprintf(out, "-");
} else {
fprintf(out, "%s", mode->name);
}
}
void show_sector(const sector_t& sector, FILE *out) {
char label = ' ';
switch (sector.status) {
case SECTOR_MISSING:
fprintf(out, " . ");
return;
case SECTOR_BAD:
label = '?';
break;
case SECTOR_GOOD:
if (sector.deleted) {
label = 'x';
} else {
label = '+';
}
break;
}
fprintf(out, "%3d%c", sector.log_sector, label);
}
void show_track(const track_t& track, FILE *out) {
show_mode(track.data_mode, out);
fprintf(out, " %dx%ld",
track.num_sectors,
sector_bytes(track.sector_size_code));
for (int phys_sec = 0; phys_sec < track.num_sectors; phys_sec++) {
show_sector(track.sectors[phys_sec], out);
}
}
void show_track_data(const track_t& track, FILE* const out) {
for (int phys_sec = 0; phys_sec < track.num_sectors; phys_sec++) {
const sector_t& sector = track.sectors[phys_sec];
if (sector.status == SECTOR_MISSING) continue;
const int data_len = sector_bytes(track.sector_size_code);
fprintf(out, "Physical C %d H %d S %d, Logical C %d H %d S %d",
track.phys_cyl, track.phys_head, phys_sec,
sector.log_cyl, sector.log_head, sector.log_sector);
if (sector.datas.size() > 1) {
fprintf(out, ": (unique read datas: %ld)", sector.datas.size());
}
fprintf(out, ":\n");
size_t data_id = 0;
for (data_map_t::const_iterator iter = sector.datas.begin(); iter != sector.datas.end(); iter++) {
if ((sector.datas.size() > 1) || (iter->second > 1)) {
fprintf(out, "IMD data id: %zd. Repeat count: %d.\n", data_id++, iter->second);
}
// The format here is based on "hexdump -C".
// (Although it's not smart enough to fold identical data.)
const int line_len = 16;
for (int i = 0; i < data_len; i += line_len) {
fprintf(out, "%2d%2d%2d %04x ", sector.log_cyl, sector.log_head, sector.log_sector, i);
for (int j = 0; j < line_len; j++) {
const int pos = i + j;
if (pos < data_len) {
fprintf(out, " %02x", iter->first[pos]);
} else {
fprintf(out, " ");
}
}
fprintf(out, " |");
for (int j = 0; j < line_len; j++) {
const int pos = i + j;
if (pos < data_len) {
const uint8_t c = iter->first[pos];
if (c >= 32 && c < 127) {
fprintf(out, "%c", c);
} else {
fprintf(out, ".");
}
} else {
fprintf(out, " ");
}
}
fprintf(out, "|\n");
}
}
fprintf(out, "\n");
}
}
void show_comment(const disk_t& disk, FILE *out) {
if (!disk.comment.empty()) {
fwrite(disk.comment.c_str(), 1, disk.comment.length(), out);
}
}
void show_disk(const disk_t& disk, bool with_data, FILE *out) {
show_comment(disk, out);
fprintf(out, "\n");
for (int phys_cyl = 0; phys_cyl < disk.num_phys_cyls; phys_cyl++) {
for (int phys_head = 0; phys_head < disk.num_phys_heads; phys_head++) {
fprintf(out, "%2d.%d:", phys_cyl, phys_head);
show_track(disk.tracks[phys_cyl][phys_head], out);
fprintf(out, "\n");
if (with_data) {
fprintf(out, "\n");
show_track_data(disk.tracks[phys_cyl][phys_head], out);
}
}
}
}