| 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 |
#define PROGNAME "disktype" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <string.h> |
| 36 |
#include <unistd.h> |
| 37 |
#include <errno.h> |
| 38 |
|
| 39 |
#include <sys/types.h> |
| 40 |
#include <sys/stat.h> |
| 41 |
#include <sys/time.h> |
| 42 |
#include <fcntl.h> |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
#define FLAG_IN_DISKLABEL (0x0001) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
typedef signed char s1; |
| 52 |
typedef unsigned char u1; |
| 53 |
typedef short int s2; |
| 54 |
typedef unsigned short int u2; |
| 55 |
typedef long int s4; |
| 56 |
typedef unsigned long int u4; |
| 57 |
typedef long long int s8; |
| 58 |
typedef unsigned long long int u8; |
| 59 |
|
| 60 |
typedef struct source { |
| 61 |
u8 size; |
| 62 |
int size_known; |
| 63 |
void *cache_head; |
| 64 |
|
| 65 |
int sequential; |
| 66 |
u8 seq_pos; |
| 67 |
int blocksize; |
| 68 |
struct source *foundation; |
| 69 |
|
| 70 |
int (*analyze)(struct source *s, int level); |
| 71 |
u8 (*read_bytes)(struct source *s, u8 pos, u8 len, void *buf); |
| 72 |
int (*read_block)(struct source *s, u8 pos, void *buf); |
| 73 |
void (*close)(struct source *s); |
| 74 |
|
| 75 |
|
| 76 |
} SOURCE; |
| 77 |
|
| 78 |
typedef struct section { |
| 79 |
u8 pos, size; |
| 80 |
int flags; |
| 81 |
SOURCE *source; |
| 82 |
} SECTION; |
| 83 |
|
| 84 |
typedef void (*DETECTOR)(SECTION *section, int level); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
void analyze_source(SOURCE *s, int level); |
| 90 |
void analyze_source_special(SOURCE *s, int level, u8 pos, u8 size); |
| 91 |
void analyze_recursive(SECTION *section, int level, |
| 92 |
u8 rel_pos, u8 size, int flags); |
| 93 |
void stop_detect(void); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
SOURCE *init_file_source(int fd, int filekind); |
| 98 |
|
| 99 |
int analyze_cdaccess(int fd, SOURCE *s, int level); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
u8 get_buffer(SECTION *section, u8 pos, u8 len, void **buf); |
| 104 |
u8 get_buffer_real(SOURCE *s, u8 pos, u8 len, void *inbuf, void **outbuf); |
| 105 |
void close_source(SOURCE *s); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
void print_line(int level, const char *fmt, ...); |
| 110 |
void start_line(const char *fmt, ...); |
| 111 |
void continue_line(const char *fmt, ...); |
| 112 |
void finish_line(int level); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
void format_blocky_size(char *buf, u8 count, u4 blocksize, |
| 117 |
const char *blockname, const char *append); |
| 118 |
void format_size(char *buf, u8 size); |
| 119 |
void format_size_verbose(char *buf, u8 size); |
| 120 |
|
| 121 |
void format_ascii(void *from, char *to); |
| 122 |
void format_utf16_be(void *from, u4 len, char *to); |
| 123 |
void format_utf16_le(void *from, u4 len, char *to); |
| 124 |
|
| 125 |
void format_uuid(void *from, char *to); |
| 126 |
void format_uuid_lvm(void *uuid, char *to); |
| 127 |
void format_guid(void *guid, char *to); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
u2 get_be_short(void *from); |
| 132 |
u4 get_be_long(void *from); |
| 133 |
u8 get_be_quad(void *from); |
| 134 |
|
| 135 |
u2 get_le_short(void *from); |
| 136 |
u4 get_le_long(void *from); |
| 137 |
u8 get_le_quad(void *from); |
| 138 |
|
| 139 |
u2 get_ve_short(int endianness, void *from); |
| 140 |
u4 get_ve_long(int endianness, void *from); |
| 141 |
u8 get_ve_quad(int endianness, void *from); |
| 142 |
|
| 143 |
const char * get_ve_name(int endianness); |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
void get_string(void *from, int len, char *to); |
| 148 |
void get_pstring(void *from, char *to); |
| 149 |
void get_padded_string(void *from, int len, char pad, char *to); |
| 150 |
|
| 151 |
int find_memory(void *haystack, int haystack_len, |
| 152 |
void *needle, int needle_len); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
char * get_name_for_mbrtype(int type); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
void error(const char *msg, ...); |
| 161 |
void errore(const char *msg, ...); |
| 162 |
void bailout(const char *msg, ...); |
| 163 |
void bailoute(const char *msg, ...); |
| 164 |
|
| 165 |
|