-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpseclog.c
65 lines (57 loc) · 1.45 KB
/
dumpseclog.c
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "vdisk.h"
#define LINESIZE 16
#define SECSIZE 512
#define SEC_X_TRACK 27
#define SFIP 2
#define HIP 0
#define SUP 8
int secfis,cilindro,superficie;
void log_to_phys(int nseclog) {
secfis = ((nseclog + SFIP - 1) % SEC_X_TRACK) +1;
superficie = ((nseclog + SFIP - 1) / SEC_X_TRACK + HIP) % SUP;
cilindro = ((nseclog + SFIP - 1) + (HIP * SEC_X_TRACK)) / (SEC_X_TRACK * SUP);
}
int main(int argc,char *argv[]) {
int drive;
int ncyl,nhead,nsec;
int fd;
unsigned char buffer[SECSIZE];
int offset;
int i,j,r;
unsigned char c;
if(argc==2) {
log_to_phys(atoi(argv[1]));
drive=0;
if(drive<0 || drive> 3 || cilindro>CYLINDERS || superficie > HEADS || secfis > SECTORS || cilindro<0 || superficie<0 || secfis<1) {
fprintf(stderr,"Posición invalida\n");
exit(1);
}
printf("Desplegando de disco%d.vd Cil=%d, Sup=%d, Sec=%d\n",drive,cilindro,superficie,secfis);
} else {
fprintf(stderr,"Error en los argumentos\n");
exit(1);
}
if(vdreadsector(drive,superficie,cilindro,secfis,1,buffer)==-1) {
fprintf(stderr,"Error al abrir disco virtual\n");
exit(1);
}
for(i=0;i<SECSIZE/LINESIZE;i++) {
printf("\n %3X -->",i*LINESIZE);
for(j=0;j<LINESIZE;j++) {
c=buffer[i*LINESIZE+j];
printf("%2X ",c);
}
printf(" | ");
for(j=0;j<LINESIZE;j++) {
c=buffer[i*LINESIZE+j]%256;
if(c>0x1F && c<127)
printf("%c",c);
else
printf(".");
}
}
printf("\n");
}