Reputation: 235
I am a beginner learning windows programming using C. My program to read boot sectors displays the same output for every drive i.e floppy or harddisk.the program isn't suppose to generate the same output for every drive.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#pragma pack(1)
struct boot
{
BYTE JUMP[3];
char bsOemName[8];
WORD bytesperSector;
BYTE sectorspercluster;
WORD sectorsreservedarea;
BYTE copiesFAT;
WORD maxrootdirentries;
WORD totalSectors;
BYTE mediaDescripter;
WORD sectorsperFAT;
WORD sectorsperTrack;
WORD sides;
WORD hiddenSectors;
char reserve[480];
WORD volumelabel;
};
void ReadSector(char *src,int ss,int num,void *buff);
void main()
{
struct boot b;
ReadSector("\\\\dell-PC\\c:",0,1,&b);
printf("Boot Sector name: %d\n",b.bsOemName);
printf("Bytes per Sector: %d\n",b.bytesperSector);
printf("Sectors per Cluster: %d\n",b.sectorspercluster);
printf("Total sectors: %d\n",b.totalSectors);
printf("copies FAT: %d\n",b.copiesFAT);
printf("hidden sectors: %d\n",b.hiddenSectors);
printf("volume label: %d\n",b.volumelabel);
}
void ReadSector(char *src,int ss,int num,void *buff)
{
HANDLE h;
unsigned int br;
h=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
SetFilePointer(h,(ss*512),NULL,FILE_BEGIN);
ReadFile(h,buff,512*num,&br,NULL);
CloseHandle(h);
}
It is generating the same output for every argument i pass to the ReadSector() function. That is, if i pass d:
or e:
, the output is always the same. Am I getting garbage values as output?
Boot Sector name: 1637707
Bytes per Sector: 52428
Sectors per Cluster: 204
Total sectors: 52428
copies FAT: 204
hidden sectors: 52428
volume label: 52428
Upvotes: 2
Views: 350
Reputation: 57784
Check the return status from each call to determine whether it is giving an error. If it does, you can learn quite a bit about what you are doing wrong by looking up the error code and determining its meaning.
To be sure you are getting values, initialize the structure before using it:
struct boot b; memset (&b, 0, sizeof b);
I have arbitrarily chosen zero, but any value will do.
Upvotes: 2