@@ -6,8 +6,9 @@
* */
#include " ../global.h"
#include < stdio.h>
#include < string.h>
#include < stdlib.h>
#include < string.h>
#include < ctype.h>
#include " utils.h"
#include " dircoms.h"
@@ -22,6 +23,10 @@ int LoadImage(FILE * img) {
if (status != 0 && status != 1 ) printf (" \n\n LoadImage error: %d \n " , status);
#ifdef _DEBUGGING_BOOT_SECT
PrintBootSectInfo ();
#endif
return status;
}
@@ -57,74 +62,16 @@ int LoadBPB(FILE * img) {
fread (&BS_VolLab, 1 , 11 , img);
fread (&BS_FilSysType, 1 , 8 , img);
#ifdef _DEBUGGING_BOOT_SECT
PrintBootSectInfo ();
#endif
return 0 ;
}
int PrintBootSectInfo () {
printf (" \n\n Bytes Per Sector: %d \n " , BPB_BytesPerSec);
printf (" Sector Per Cluster: %d \n " , BPB_SecPerClus);
printf (" Reserved Sector Count: %d \n " , BPB_RsvdSecCnt);
printf (" Number Of FATs: %d \n " , BPB_NumFATs);
printf (" Root Directory Entry Count: %d \n " , BPB_RootEntCnt);
printf (" Total Sector Count in 16Bit: %d \n " , BPB_TotSec16);
printf (" Total Hidden Sectors: %d \n " , BPB_HiddSec);
printf (" Total Sector Count in 32Bit: %d \n " , BPB_TotSec32);
printf (" Sectors Occupied (32-bit count): %d \n " , BPB_FATSz32);
printf (" Various External Flags: %d \n " , BPB_ExtFlags);
printf (" Version Number: %d \n " , BPB_FSVer);
printf (" Cluster Number of Root Dir !: %d \n " , BPB_RootClus);
printf (" Sector Number of Info struct: %d \n " , BPB_FSInfo);
printf (" Sector number of reserved boot record copy: %d \n " , BPB_BkBootSec);
printf (" Reserved for future expansion:" );
for (int i = 0 ; i < 3 ; i++)
printf (" %d -" , BPB_Reserved[i]);
printf (" \n Indicates media type for drive(0x00 is floppy): %d \n " , BS_DrvNum);
printf (" Used by windows NT lol: %d \n " , BS_Reserved1);
printf (" Indicates if following values are present (ID, LAB): %d \n " ,
BS_BootSig);
printf (" Volume Serial ID Number: %d \n " , BS_VolID);
printf (" Volume Serial Label:" );
for (int i = 0 ; i < 11 ; i++)
printf (" %d " , BS_VolLab[i]);
printf (" \n File System Type (indeterminate info only):" );
for (int i = 0 ; i < 8 ; i++)
printf (" %c " , BS_FilSysType[i]);
printf (" \n " );
return 0 ;
}
/*
* Note also that the CountofClusters value is exactly that—the count of data clusters starting at cluster
2. The maximum valid cluster number for the volume is CountofClusters + 1, and the “count of
clusters including the two reserved clusters” is CountofClusters + 2.
* Note also that the CountofClusters value is exactly that—the count of data
* clusters starting at cluster
* 2. The maximum valid cluster number for the volume is CountofClusters + 1,
* and the “count of clusters including the two reserved clusters” is CountofClusters + 2.
*/
int SetRootDir (FILE * img) {
@@ -154,13 +101,31 @@ int SetRootDir(FILE * img) {
return 1 ;
}
void nametofat (char * name){
for (int i=0 ; i < strlen (name); i++){
if (name[i] == ' /' ) name[i] = ' \0 ' ;
name[i] = toupper (name[i]);
}
}
unsigned int setclus (struct directory * dir){
struct cluster temp;
unsigned int clusval = 0 ;
unsigned int FindFirstSector (unsigned int cluster){
unsigned int firstSector = 0 ;
dir->cluster = malloc (sizeof (struct cluster));
firstSector = ((cluster - 2 ) * BPB_SecPerClus) + fatcat.firstDataSector ;
clusval = dir->FstClusHi ;
clusval = clusval << 1 ;
clusval = clusval | dir->FstClusLO ;
clusval = clusval == 0x00 ? BPB_RootClus : clusval;
return firstSector;
temp = FindClusterInfo (clusval);
#ifdef _DEBUGGING
printf (" \n Setting Cluster info" );
printf (" \n CLUSTER VALUE: %d \n " , clusval);
#endif
memcpy (dir->cluster , &temp, sizeof (struct cluster));
return 0 ;
}
struct cluster FindClusterInfo (unsigned int cluster){
@@ -173,8 +138,9 @@ struct cluster FindClusterInfo(unsigned int cluster){
while (more){
fatOffset = cluster * 4 ;
// Finds first data sector for cluster / cluster chain node
info.firstSectors [info.clusterNum ] = FindFirstSector ( cluster) ;
info.firstSectors [info.clusterNum ] = (( cluster - 2 ) * BPB_SecPerClus) + fatcat. firstDataSector ;
info.sectorNums [info.clusterNum ] = BPB_RsvdSecCnt + (fatOffset / BPB_BytesPerSec); // sector of cluster chain info
info.entryOffset [info.clusterNum ] = fatOffset % BPB_BytesPerSec; // offset of cluster chain info
@@ -190,6 +156,7 @@ struct cluster FindClusterInfo(unsigned int cluster){
if (more) cluster = next_cluster;
#ifdef _DEBUGGING
printf (" \n\n CLUSTER USED:%d " , cluster);
printf (" \n FatOffset: 0x%x " , fatOffset);
printf (" \n ThisFATSecNum: 0x%x " , info.sectorNums [info.clusterNum ]);
printf (" \n ThisFATEntOff: 0x%x " , info.entryOffset [info.clusterNum ]);
@@ -204,14 +171,60 @@ struct cluster FindClusterInfo(unsigned int cluster){
return info;
}
void GetClusterData (unsigned int cluster){
/* unsigned long DWORD = 0;
char* data = 0;
struct cluster info = FindClusterInfo(cluster);*/
int PrintBootSectInfo (){
}
printf (" \n\n Bytes Per Sector: %d \n " , BPB_BytesPerSec);
printf (" Sector Per Cluster: %d \n " , BPB_SecPerClus);
printf (" Reserved Sector Count: %d \n " , BPB_RsvdSecCnt);
printf (" Number Of FATs: %d \n " , BPB_NumFATs);
printf (" Root Directory Entry Count: %d \n " , BPB_RootEntCnt);
printf (" Total Sector Count in 16Bit: %d \n " , BPB_TotSec16);
printf (" Total Hidden Sectors: %d \n " , BPB_HiddSec);
printf (" Total Sector Count in 32Bit: %d \n " , BPB_TotSec32);
printf (" Sectors Occupied (32-bit count): %d \n " , BPB_FATSz32);
printf (" Various External Flags: %d \n " , BPB_ExtFlags);
printf (" Version Number: %d \n " , BPB_FSVer);
void SetClusterData (unsigned int cluster){
printf (" Cluster Number of Root Dir !: %d \n " , BPB_RootClus);
printf (" Sector Number of Info struct: %d \n " , BPB_FSInfo);
printf (" Sector number of reserved boot record copy: %d \n " , BPB_BkBootSec);
printf (" Reserved for future expansion:" );
for (int i = 0 ; i < 3 ; i++)
printf (" %d -" , BPB_Reserved[i]);
printf (" \n Indicates media type for drive(0x00 is floppy): %d \n " , BS_DrvNum);
printf (" Used by windows NT lol: %d \n " , BS_Reserved1);
printf (" Indicates if following values are present (ID, LAB): %d \n " ,
BS_BootSig);
printf (" Volume Serial ID Number: %d \n " , BS_VolID);
printf (" Volume Serial Label:" );
for (int i = 0 ; i < 11 ; i++)
printf (" %d " , BS_VolLab[i]);
printf (" \n File System Type (indeterminate info only):" );
for (int i = 0 ; i < 8 ; i++)
printf (" %c " , BS_FilSysType[i]);
printf (" \n " );
return 0 ;
}