FreeCalypso > hg > freecalypso-reveng
annotate miscprog/grokdsn.c @ 194:805e99848aea
grokdsn: buglet in the hierarchy traversal order
author | Michael Spacefalcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 07 Jan 2015 22:15:51 +0000 |
parents | 37f78f986a0a |
children |
rev | line source |
---|---|
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * We have TI's Leonardo reference schematics in the form of 3 different PDF |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * versions and an OrCAD DSN file corresponding to one of them. The latter |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * appears (based on a cursory strings(1) inspection) to contain more |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * juicy information than is present in the PDF prints. We need to extract |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 * as much of this information as we can in order to replicate the lost |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 * Leonardo board as closely as possible. |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 * |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 * The top level structure of this DSN file appears to be Microsoft CDF. |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 * Therefore, I shall begin by parsing this "archive" structure and |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 * extracting the individual files contained therein, in an effort to gain |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 * more insight as to what goes with what than can be gleaned from strings(1) |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 * on the raw DSN file. This hack-utility is my CDF parser written for |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 * this specific purpose. |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 */ |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include <sys/types.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 #include <sys/file.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 #include <sys/stat.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 #include <sys/mman.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 #include <stdio.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 #include <stdint.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 #include <endian.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 #include <stdlib.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 #include <unistd.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 #include <string.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 #include <strings.h> |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 #define HEADER_MFAT_ENTRIES 109 |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 struct cdf_header { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 u_char magic[8]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 u_char uid[16]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 uint16_t fmt_minor; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 uint16_t fmt_major; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 uint16_t byte_order; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 uint16_t sector_size; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 uint16_t subsec_size; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 u_char rsvd1[10]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 uint32_t fat_sectors; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 uint32_t dir_start; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 u_char rsvd2[4]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 uint32_t min_large_file; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 uint32_t subfat_start; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 uint32_t subfat_sectors; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 uint32_t mfat_start; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 uint32_t mfat_sectors; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 uint32_t fat_secids[HEADER_MFAT_ENTRIES]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 }; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
50 struct dir_entry { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
51 uint16_t uni_name[32]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
52 uint16_t name_len; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
53 u_char type; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
54 u_char color; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
55 uint32_t left_child; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
56 uint32_t right_child; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
57 uint32_t subtree_dirid; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
58 u_char uid[16]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
59 u_char user_flags[4]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
60 u_char time_creat[8]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
61 u_char time_lastmod[8]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
62 uint32_t content_secid; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
63 uint32_t content_bytes; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
64 u_char rsvd[4]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
65 }; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
66 |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 char *dsnfilename; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 u_char *filemapping; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 struct cdf_header *cdf_header; |
192
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
70 unsigned total_sectors, fat_nsectors; |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
72 #define MAX_DIR_SECTORS 64 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
73 unsigned dir_nsectors, dir_secids[MAX_DIR_SECTORS]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
74 |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 open_and_mmap_file() |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 int fd; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 struct stat st; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 fd = open(dsnfilename, O_RDONLY); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 if (fd < 0) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 perror(dsnfilename); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 fstat(fd, &st); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 if (!S_ISREG(st.st_mode)) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 fprintf(stderr, "error: %s is not a regular file\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 dsnfilename); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 if (st.st_size < 512) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 fprintf(stderr, "error: %s is shorter than 512 bytes\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 dsnfilename); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (st.st_size % 512) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 fprintf(stderr, "error: %s is not a multiple of 512 bytes\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 dsnfilename); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 filemapping = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 if (filemapping == MAP_FAILED) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 perror("mmap"); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 close(fd); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 cdf_header = (struct cdf_header *) filemapping; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 total_sectors = st.st_size / 512 - 1; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 return(0); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 dump_cdf_header() |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 printf("Magic: %02X %02X %02X %02X %02X %02X %02X %02X\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 cdf_header->magic[0], cdf_header->magic[1], |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 cdf_header->magic[2], cdf_header->magic[3], |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 cdf_header->magic[4], cdf_header->magic[5], |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 cdf_header->magic[6], cdf_header->magic[7]); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 printf("Format version: %04X.%04X\n", le16toh(cdf_header->fmt_major), |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 le16toh(cdf_header->fmt_minor)); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 printf("Sector / subsector shift: %u / %u\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 le16toh(cdf_header->sector_size), |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 le16toh(cdf_header->subsec_size)); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 printf("Total FAT sectors: %u\n", le32toh(cdf_header->fat_sectors)); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 printf("Directory start sector: %u\n", le32toh(cdf_header->dir_start)); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 printf("File size threshold: %u\n", |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 le32toh(cdf_header->min_large_file)); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 return(0); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 |
192
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
131 u_char * |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
132 get_sector_ptr(secid) |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
133 unsigned secid; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
134 { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
135 if (secid > total_sectors) { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
136 fprintf(stderr, |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
137 "error: request for sector #%u; we only have %u in total\n", |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
138 secid, total_sectors); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
139 exit(1); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
140 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
141 return filemapping + (secid + 1) * 512; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
142 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
143 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
144 init_fat_access() |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
145 { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
146 fat_nsectors = le32toh(cdf_header->fat_sectors); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
147 if (fat_nsectors > HEADER_MFAT_ENTRIES) { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
148 fprintf(stderr, "error: large FAT not supported\n"); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
149 exit(1); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
150 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
151 return(0); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
152 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
153 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
154 u_char * |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
155 get_fat_sector(fat_sec_no) |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
156 unsigned fat_sec_no; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
157 { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
158 unsigned secid; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
159 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
160 if (fat_sec_no > fat_nsectors) { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
161 fprintf(stderr, |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
162 "error: request for FAT sector #%u; we only have %u in total\n", |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
163 fat_sec_no, fat_nsectors); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
164 exit(1); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
165 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
166 secid = le32toh(cdf_header->fat_secids[fat_sec_no]); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
167 return get_sector_ptr(secid); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
168 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
169 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
170 int32_t |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
171 get_fat_entry(entry_no) |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
172 unsigned entry_no; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
173 { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
174 unsigned fat_sec_no, entry_in_sec; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
175 uint32_t *fat_sector; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
176 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
177 fat_sec_no = entry_no / 128; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
178 entry_in_sec = entry_no % 128; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
179 fat_sector = (uint32_t *) get_fat_sector(fat_sec_no); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
180 return le32toh(fat_sector[entry_in_sec]); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
181 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
182 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
183 dump_fat_chain(sarg) |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
184 char *sarg; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
185 { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
186 int i, n; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
187 |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
188 init_fat_access(); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
189 i = atoi(sarg); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
190 while (i >= 0) { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
191 n = get_fat_entry(i); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
192 printf("FAT[%d] = %d\n", i, n); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
193 i = n; |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
194 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
195 return(0); |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
196 } |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
197 |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
198 locate_dir_sectors() |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
199 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
200 int sec, next, num; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
201 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
202 sec = le32toh(cdf_header->dir_start); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
203 for (num = 0; sec >= 0; sec = next) { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
204 if (num >= MAX_DIR_SECTORS) { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
205 fprintf(stderr, "error: MAX_DIR_SECTORS exceeded\n"); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
206 exit(1); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
207 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
208 dir_secids[num++] = sec; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
209 next = get_fat_entry(sec); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
210 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
211 dir_nsectors = num; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
212 return(0); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
213 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
214 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
215 u_char * |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
216 get_dir_sector(dir_sec_no) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
217 unsigned dir_sec_no; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
218 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
219 unsigned secid; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
220 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
221 if (dir_sec_no > dir_nsectors) { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
222 fprintf(stderr, |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
223 "error: request for dir sector #%u; we only have %u in total\n", |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
224 dir_sec_no, dir_nsectors); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
225 exit(1); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
226 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
227 secid = dir_secids[dir_sec_no]; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
228 return get_sector_ptr(secid); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
229 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
230 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
231 struct dir_entry * |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
232 get_dir_entry(dirid) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
233 unsigned dirid; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
234 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
235 unsigned dir_sec_no, entry_in_sec; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
236 struct dir_entry *dir_sector; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
237 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
238 dir_sec_no = dirid / 4; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
239 entry_in_sec = dirid % 4; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
240 dir_sector = (struct dir_entry *) get_dir_sector(dir_sec_no); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
241 return dir_sector + entry_in_sec; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
242 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
243 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
244 dump_dir_entry(rec, indent) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
245 struct dir_entry *rec; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
246 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
247 int i, u; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
248 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
249 for (i = indent; i; i--) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
250 putchar(' '); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
251 for (i = 0; i < 32; i++) { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
252 u = le16toh(rec->uni_name[i]); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
253 if (u == 0) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
254 break; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
255 if (u >= ' ' && u <= '~') |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
256 putchar(u); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
257 else |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
258 printf("<%04X>", u); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
259 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
260 printf(" (type %02X, length %u)\n", rec->type, rec->content_bytes); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
261 return(0); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
262 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
263 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
264 dump_dir_level(dirid, indent) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
265 unsigned dirid; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
266 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
267 struct dir_entry *rec; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
268 int32_t ndir; |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
269 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
270 rec = get_dir_entry(dirid); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
271 ndir = le32toh(rec->left_child); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
272 if (ndir >= 0) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
273 dump_dir_level(ndir, indent); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
274 dump_dir_entry(rec, indent); |
194
805e99848aea
grokdsn: buglet in the hierarchy traversal order
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
193
diff
changeset
|
275 ndir = le32toh(rec->subtree_dirid); |
805e99848aea
grokdsn: buglet in the hierarchy traversal order
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
193
diff
changeset
|
276 if (ndir >= 0) |
805e99848aea
grokdsn: buglet in the hierarchy traversal order
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
193
diff
changeset
|
277 dump_dir_level(ndir, indent + 2); |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
278 ndir = le32toh(rec->right_child); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
279 if (ndir >= 0) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
280 dump_dir_level(ndir, indent); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
281 return(0); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
282 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
283 |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
284 dump_dir_tree() |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
285 { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
286 init_fat_access(); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
287 locate_dir_sectors(); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
288 dump_dir_level(0, 0); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
289 return(0); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
290 } |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
291 |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
292 main(argc, argv) |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
293 char **argv; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
294 { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
295 if (sizeof(struct cdf_header) != 512) { |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
296 fprintf(stderr, "error: struct cdf_header is misdefined\n"); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
297 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
298 } |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
299 if (sizeof(struct dir_entry) != 128) { |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
300 fprintf(stderr, "error: struct dir_entry is misdefined\n"); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
301 exit(1); |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
302 } |
192
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
303 if (argc < 3) { |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
304 fprintf(stderr, "usage: %s binfile.dsn <op> [args]\n", argv[0]); |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
305 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
306 } |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
307 dsnfilename = argv[1]; |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
308 open_and_mmap_file(); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
309 if (!strcmp(argv[2], "hdr")) |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
310 return dump_cdf_header(); |
192
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
311 if (!strcmp(argv[2], "fatchain")) |
5d84f63eff72
grokdsn: able to follow the FAT chain for the directory
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
312 return dump_fat_chain(argv[3]); |
193
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
313 if (!strcmp(argv[2], "ls")) |
37f78f986a0a
grokdsn: tree dump implemented
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
192
diff
changeset
|
314 return dump_dir_tree(); |
191
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
315 fprintf(stderr, "error: \"%s\" is not a recognized command\n", argv[2]); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
316 exit(1); |
0c631396b8ce
started grokdsn utility, parses header successfully
Michael Spacefalcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
317 } |