write aC++ program that would read from a CD and display information

M

munif

i wnat write a C++ program that would read from a CD and display
information about files and folders in the given CD

In simple words you would be performing a simple (ls -l)[Linux] or (DIR
/S)[DOS] on the CD.

LOOk at this code


/*
CopyRight 2004 by Basit Qureshi

The following code illustrates how to open an iso file and read
its contents.

Notice most numbers stored in the CD are in Big_Endian or
Little_Endian format. For instance if a number is stored in
8 bytes long memory this means the first 4 bytes represent
the same number in Little_endian format and the other 4 bytes
respresent the same number in big_endian format.
*/

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

#define SECTOR_SIZE 2048
ifstream fin;
unsigned char buf[SECTOR_SIZE];

unsigned char PTAddress[4];
main()
{
fin.open("test2.iso");
//goto locations 16 * sizeof SECTOR to read the PVD
fin.seekg(16*sizeof(buf));
//read 2048 bytes in buffer
fin.read (buf,2048);
PTAddress[0]= buf[140]; // first bit
PTAddress[1]= buf[141]; //second bit
PTAddress[2]= buf[142]; // thirdbit
PTAddress[3]= buf[143]; //fourth bit

//convert the above binary number to integer!! notice this is 4 bytes
long
// address = PTAddress[3] * 2^24 + PTAddress[2] * 2^16 +
PTAddress[1] * 2^8 + PTAddress[0] * 2^0;
double address = PTAddress[3] * 16777216 + PTAddress[2] * 65536 +
PTAddress[1] * 256 + PTAddress[0] * 1;

//goto location of the path table
fin.seekg(address*sizeof(buf));
//read the sector that contains the path table.
fin.read(buf,2048);
//read the description of the path table. We are concered with the
location of the
//first directory so...goto that location...!

address = buf[5] * 16777216 + buf[4] * 65536 + buf[3] * 256 + buf[2] *
1;

fin.seekg(address*sizeof(buf));

//read the directory record's sector!!
fin.read(buf,2048);

//now that the directory record is loaded you can find all the files and
print
//their parameters!
fin.close();
}




please help me to complete this C++ code
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top