I encountered a problem when reading the root directory. I have its address, BOOT-sector, but I have no idea how to calculate the directory parameters (cylinder, head, sector). The main purpose of the program is to read information about the files in this directory and display it on the screen. I read this directory using interrupt function 2 and 13. I work on win98 in BorlandC++.
The code that they gave me to calculate (cylinder, head, sector). But he didn't help
int cyl = rootKatalog/(trk_sec*head_cnt);
int head = (rootKatalog%(trk_sec*head_cnt))/trk_sec;
int sec = (rootKatalog%(trk_sec*head_cnt))%trk_sec+1;
The code of the program itself
#include <dos.h>
#include <stdio.h>
#include <conio.h>
struct sec_cat{
unsigned char name[8];
unsigned char name_e[3];
unsigned char atr;
unsigned char rez[10];
unsigned short time;
unsigned short date;
unsigned short n_clast;
unsigned long size ;
}*sec;
unsigned char buf[512];
const unsigned int rootKatalog = 0xF002;
int read_sector(int cyl, int head, int sec) {
union REGS in, out;
struct SREGS sr;
sr.es = FP_SEG(buf);
in.x.bx = FP_OFF(buf);
in.h.ah = 0x02;
in.h.al = 1;
in.h.dl = 0x80;
in.h.dh = head;
in.h.cl = sec;
in.h.ch = cyl;
int86x(0x13, &in, &out, &sr);
if (out.x.cflag || out.h.ah)
return 1;
return 0;
}
void print_files_info(){
int i = 0;
int j = 0;
printf("Name: ");
for(;j < 16; j++)
printf("%c", sec->name[j]);
printf("\nType: ");
for(j = 0; j < 12; j++)
printf("%c", sec->name_e[j]);/*
printf("\nAtributs: %c", sec->atr);
printf("\nTime create: %d\.%d\.%d", (sec->time & 0x1F), ((sec->time >> 5) & 0x3F), ((sec->time >> 11) & 0x1F));
printf("\nDate create: %d\.%d\.%d", (sec->date & 0x1F), ((sec->date >> 5) & 0xF), ((sec->date >> 9) & 0x13F));
printf("\nClaster: %d", sec->n_clast);
printf("\nSize: %d\n\n\n", sec->size); */
}
int main() {
int i = 0;
int j = 0;
int trk_sec = 255;
int head_cnt = 63;
int cyl = rootKatalog/(trk_sec*head_cnt);
int head = (rootKatalog%(trk_sec*head_cnt))/trk_sec;
int sect = (rootKatalog%(trk_sec*head_cnt))%trk_sec+1;
clrscr();
if (read_sector(cyl,head,sect))
printf("Error reading sector\n");
else
printf("Sector read successfully\n");
//printf("Name file Type file Atributs Time create Date create Claster Size\n");
for(;i < 1; i++){
sec = (struct set_cat*)&buf[i * 32];
print_files_info();
}
getch();
return 0;
}