Mail Archives: djgpp/1996/10/27/10:42:35
From: | Jon Slaughter <lobo AT iamerica DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | source code help
|
Date: | Wed, 23 Oct 1996 19:53:02 -0500
|
Organization: | none
|
Lines: | 127
|
Message-ID: | <326EBDEE.4ED@iamerica.net>
|
NNTP-Posting-Host: | 205.173.253.150
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
here is some code that is supose to read the boot sector and print out
all the information in BOOT_RECORD. But for some reason, it doesn't :( I
have no idea why. It would seem that I left some variable out of the
structure because the first two are ok, but I've looked over it and
couldn't find anything wrong. It also could be the strings since I have
no idea of how c handles them(except that they are null terminated)...
Its probably something stupid, but if anyone can help me, please!!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <bios.h>
#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned long
#define disk_drive = 0;
struct BOOT_RECORD_STRUCT {
BYTE jump[3];
BYTE oem_name[8];
WORD bytes_per_sector;
BYTE sectors_per_cluster;
WORD number_of_reserved_sectors;
BYTE number_of_fats;
WORD number_of_root_dir_entries;
WORD number_of_total_sectors;
BYTE media_descriptor_byte;
WORD sectors_per_fat;
WORD sectors_per_track;
WORD number_of_heads;
WORD number_of_hidden_sectors1;
WORD number_of_hidden_sectors2;
DWORD number_of_sectors;
BYTE physical_drive_number;
BYTE reserved;
BYTE signature_byte;
DWORD volume_serial_number;
BYTE volume_label[11];
BYTE fat_type_char_str[8];
BYTE filler[500];
};
struct BOOT_RECORD_STRUCT BOOT_RECORD;
void load_boot_record()
{
struct _diskinfo_t diskinfo;
diskinfo.track = 0;
diskinfo.sector = 1;
diskinfo.head = 0;
diskinfo.nsectors = 1;
diskinfo.buffer = &BOOT_RECORD;
_bios_disk(_DISK_READ,&diskinfo);
}
void read_sector(int linear_sector,void *buf)
{
struct _diskinfo_t diskinfo;
diskinfo.sector = 1 + (linear_sector % BOOT_RECORD.sectors_per_track);
diskinfo.track = linear_sector / (BOOT_RECORD.sectors_per_track *
BOOT_RECORD.number_of_heads);
diskinfo.head = (linear_sector / BOOT_RECORD.sectors_per_track) %
BOOT_RECORD.number_of_heads;
diskinfo.nsectors = 1;
diskinfo.buffer = buf;
_bios_disk(_DISK_READ,&diskinfo);
}
void main (void)
{
BYTE *tmp_str = (BYTE *)malloc(15);
load_boot_record();
strncpy(tmp_str,BOOT_RECORD.jump,sizeof(BOOT_RECORD.jump));tmp_str[sizeof(BOOT_RECORD.jump)]
= 0;
printf("\nJump chars = %s",tmp_str);
strncpy(tmp_str,BOOT_RECORD.oem_name,sizeof(BOOT_RECORD.oem_name));tmp_str[sizeof(BOOT_RECORD.oem_name)]
= 0;
printf("\nOEM = %s",tmp_str);
printf("\nBytes per sector =
%d",BOOT_RECORD.bytes_per_sector);
printf("\nSectors per cluster =
%d",BOOT_RECORD.sectors_per_cluster);
printf("\nReserved sectors =
%d",BOOT_RECORD.number_of_reserved_sectors);
printf("\nNumber of FAT's on disk =
%d",BOOT_RECORD.number_of_fats);
printf("\nNumber of root directory entries =
%d",BOOT_RECORD.number_of_root_dir_entries);
if (BOOT_RECORD.number_of_total_sectors != 0)
printf("\nTotal number of sectors on disk =
%d",BOOT_RECORD.number_of_total_sectors);
printf("\nMedia descriptor byte =
%d",BOOT_RECORD.media_descriptor_byte);
printf("\nFat size(sectors) =
%d",BOOT_RECORD.sectors_per_fat);
printf("\nSectors per track =
%d",BOOT_RECORD.sectors_per_track);
printf("\nNumber of heads =
%d",BOOT_RECORD.number_of_heads);
printf("\nNumber of hidden sectors =
%d",BOOT_RECORD.number_of_hidden_sectors1);
if (BOOT_RECORD.number_of_total_sectors == 0)
printf("\nTotal number of sectors on disk =
%ld",BOOT_RECORD.number_of_sectors);
printf("\nPhysical drive number =
%d",BOOT_RECORD.physical_drive_number);
printf("\nSignature byte (29h) =
%Xh",BOOT_RECORD.signature_byte);
printf("\nVolume serial number =
%lX",BOOT_RECORD.volume_serial_number);
strncpy(tmp_str,BOOT_RECORD.volume_label,11);tmp_str[11] = 0;
printf("\nVolume label = %s",tmp_str);
strncpy(tmp_str,BOOT_RECORD.fat_type_char_str,8);tmp_str[8] = 0;
printf("\nFAT str type = %s",tmp_str);
//read_sector(1,&BOOT_RECORD);
}
- Raw text -