Internal Structure of the DIR ommand of MS-DOS purely for a floppy drive media

  • Thread starter Anil Kumar Narayanan
  • Start date
A

Anil Kumar Narayanan

This is the DIR command of MS-DOS and works for a floppy drive media..
it retrieves all the files whether deleted or not from the floppy
drive.. but i was unsuccessful in getting the Date and Time Format..
So if any of u have any info on how to get the Date and Time please
forward me through an email.. I would appreciate that..

//--------------------------- F*****K IT COMPANIES ---------------
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>

//----------Directory Area Structure
struct dirstruct
{
unsigned char fname[8];
unsigned char fext[3];
unsigned char fatt;
unsigned char fres[10];
unsigned char ftime[2];
unsigned char fdate[2];
unsigned char fclust[2];
unsigned char fsize[4];
};
//----------Other Constants

const DIR='D';
const FIL='F';

//----------File Attributes
const r=0x01; //Read
const h=0x02; //Hide
const s=0x04; //System
const v=0x08; //Volume
const d=0x10; //Directory
const e=0x20; //Archive
const re=0x21; //Read+Archive
const reh=0x23; //Read+Archive+Hide
const rehs=0x27; //Read+Archive+Hide+System
const rh=0x3; //Read+Hide
const rhs=0x7; //Read+Hide+System
const hs=0x6; //Hide+System
const hse=0x26; //Hide+System+Archive
const he=0x22; //Hide+Archive
const es=0x24; //Archive+System
const rs=0x5; //Read+System
const res=0x25; //Read+Archive+System
//----------

//----------Function Declaration

void sendsectors(unsigned char*);
void displaystruct(char *, char, char*);
//----------

//----------Starting point of the program

void main()
{

int drive=0, sects=14, lsect=19;
unsigned char *buf;
//----------

clrscr();
printf(" Dedicated to my love\n");
printf("--------------------------- F*****K IT COMPANIES
---------------\n");
printf("FILENAME EXT TYP ATTR DATE TIME CLUST SIZE(byts)\n");
printf("----------------------------------------------------------------\n");

absread(drive,sects,lsect,buf);
sendsectors(buf); //Send's sectors to pointer variable
getch();
}

//----------Function

void sendsectors(unsigned char *buf)
{

//----------Variable Declaration

unsigned char bit16[16], bit32[32];
int col=0, i, fdcount=0, tmpfdcount=0;

while(col<7168)
{

//----------populating bit16

for(int x=0,i=col;i<col+16;x++,i++)
{
bit16[x]=buf;
}

switch(bit16[11])
{

//----------Atribute for Directory
case d:

if(bit16[0]!=0xE5)
{

for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'D'," ");
}
else
if(bit16[0]==0xE5)
{

for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'L'," ");
}
fdcount=fdcount+1; //File_Directory count
break;


//----------Read attribute
case r:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"R ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Hide attribute
case h:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"H ");
fdcount=fdcount+1; //File_Directory count
break;

//----------System attribute
case s:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"S ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Archive attribute
case e:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"E ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Archive attribute
case re:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"RE ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Archive+Hide attribute
case reh:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"REH ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Archive+Hide+System attribute
case rehs:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"REHS");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Hide attribute
case rh:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"RH ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Hide+System attribute
case rhs:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"RHS ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Hide+System attribute
case hs:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"HS ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Hide+System+Archive attribute
case hse:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"HSE ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Hide+Archive attribute
case he:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"HE ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Archive+System attribute
case es:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"ES ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+System attribute
case rs:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"RS ");
fdcount=fdcount+1; //File_Directory count
break;

//----------Read+Archive+System attribute
case res:
for(x=0,i=i-16;i<col+32;x++,i++)
{
bit32[x]=buf;
}
displaystruct(bit32,'F',"RES ");
fdcount=fdcount+1; //File_Directory count
break;
}

col=i;

if(fdcount>=tmpfdcount+20)
{
printf("Press any key to continue . . .");
getch();
printf("\n\n");
tmpfdcount+=20;
}
}
printf("\nTotal <<Files+Directories>>: %d",fdcount);

}

//----------Function

void displaystruct(char *bit32, char type, char *attrib)
{
dirstruct ds;
int x,y; unsigned long int fsizebits[8], fclustbits[4];
unsigned long int ftotalsize;

switch(type)
{
//----------Directory display
case 'D':
{
for(x=0,y=0;x<8;x++,y++)
{
ds.fname[y]=bit32[x];
}
ds.fname[y]='\0';
printf("%s ",ds.fname);
printf("<D>\n");

break;
}
//----------Deleted-Directory display
case 'L':
{
for(x=0,y=0;x<8;x++,y++)
{
ds.fname[y]=bit32[x];
}
ds.fname[y]='\0';
printf("%s ",ds.fname);
printf("<X>\n");

break;
}
//----------File display
case 'F':
{
//----------Display File Name

for(x=0,y=0;x<8;x++,y++)
{
ds.fname[y]=bit32[x];
}
ds.fname[y]='\0';
printf("%s ",ds.fname);

//----------Display File Extension

for(y=0;x<11;x++,y++)
{
ds.fext[y]=bit32[x];
}
ds.fext[y]='\0';
printf("%s ",ds.fext);
printf("<F> ");

//----------Display File Attribute

ds.fatt=bit32[x];
x++;
printf("%s ", attrib);

//----------Storing File Reserved Data

for(y=0;x<21;x++,y++)
{
ds.fres[y]=bit32[x];
}
x++;
//----------Display File Time

ds.ftime[0]=bit32[x];x++;
ds.ftime[1]=bit32[x];x++;
printf("%03d:%03d ", ds.ftime[0], ds.ftime[1]);

//----------Display File Date

ds.fdate[0]=bit32[x];x++;
ds.fdate[1]=bit32[x];x++
printf("%03d:%03d ", ds.fdate[0], ds.fdate[1]);

//----------Storing File Clusters

ds.fclust[0]=bit32[x];x++;
ds.fclust[1]=bit32[x];x++;
printf("%03d:%03d ", ds.fclust[0], ds.fclust[1]);

//----------Storing File Size

ds.fsize[3]=bit32[x];x++;
ds.fsize[2]=bit32[x];x++;
ds.fsize[1]=bit32[x];x++;
ds.fsize[0]=bit32[x];

printf("%x:%x:%x:%x",
ds.fsize[0],ds.fsize[1],ds.fsize[2],ds.fsize[3]);

//----------Converting Hexadecimal to decimal for TotalFileSize

for(x=0,y=3;x<8;y--)
{
fsizebits[x]=(int)(ds.fsize[y])%16;
printf("%d", fsizebits[x]);
x=x+1;
fsizebits[x]=(int)(ds.fsize[y])/16;
printf("%d ",fsizebits[x]);
x=x+1;
}

ftotalsize=fsizebits[0]*1+fsizebits[1]*16+fsizebits[2]*256+fsizebits[3]*4096+fsizebits[4]*65536+fsizebits[5]*1048576+fsizebits[6]*16777216+fsizebits[7]*268435456;


if(fsizebits[4]!=0)
{
printf("%lu ",ftotalsize);
}
else
{
printf("%u ",ftotalsize);
}

printf("\n"); //Next Line
}
}
}
 
P

Peter van Merkerk

Anil Kumar Narayanan said:
This is the DIR command of MS-DOS and works for a floppy drive media..
it retrieves all the files whether deleted or not from the floppy
drive.. but i was unsuccessful in getting the Date and Time Format..

What is your C++ question?
MS-DOS related questions are best asked here: See also: http://www.slack.net/~shiva/welcome.txt
So if any of u have any info on how to get the Date and Time please
forward me through an email.. I would appreciate that..

Post here, read here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top