Help needed: reading disks 
Author Message
 Help needed: reading disks

I am trying to write a simple program that will dump to the screen the
(printable) contents of one of the hard drives (in this case, C:).

My code (included below) has two problems with it.
        1.  Using interrupt 13,2 I can read sector 1 of cyl 0/side 0.
            I can't seem to read sector 0 though.

        2.  It doesn't work. :) That is, it compiles okay, but on
            execution all it prints out is whatever I've initialized
            the data array to. It's as if the sector isn't even read
            into the array (which is being pointed to correctly,
            I believe.)

Any help would be appreciated.

Sam.

-----------------------CODE TO FOLLOW------------------------------

#include <stdio.h>
#include <dos.h>
#include <conio.h>

void main(void)
{
        unsigned char data[512];
        int i;
        unsigned int segment, offset;
        struct REGPACK reg;

        // initialize each data object to a '.'
        for(i=0; i<512; i++) data[i]=46;

        offset = FP_OFF(data);
        segment = FP_SEG(data);

        // Loads the registers and performs the interrupt.
        reg.r_ax = 0x0201;
        reg.r_cx = 0x0001;
        reg.r_dx = (0 ^ 0x0080);
        reg.r_bx = offset;
        reg.r_es = segment;
        intr(0x13, &reg);

        // Checks to see if the char. is printable.
        for(i=0; i<512; i++)
        {
                if ((data[i] > 0x20) && (data[i] < 0x7e))
                        printf("%d ", data[i]);
                else
                        printf(" ");
        }

Quote:
}

  .----------------------------------------------------------------.
  |                    Samantha Spry (Nikita)                      |

  |             Computer Systems Engineering - 5th Year.           |
  |  Latrobe University - Melbourne, Australia.  Ph: 0412 055 376  |
  `----------------------------------------------------------------'


Fri, 07 Jan 2000 03:00:00 GMT  
 Help needed: reading disks

Quote:

> I am trying to write a simple program that will dump to the screen the
> (printable) contents of one of the hard drives (in this case, C:).

> My code (included below) has two problems with it.
>         1.  Using interrupt 13,2 I can read sector 1 of cyl 0/side 0.
>             I can't seem to read sector 0 though.

No, since there is no sector 0, sectors start at 1.  DOS is weird.

Quote:
>         2.  It doesn't work. :) That is, it compiles okay, but on
>             execution all it prints out is whatever I've initialized
>             the data array to. It's as if the sector isn't even read
>             into the array (which is being pointed to correctly,
>             I believe.)

> Any help would be appreciated.

> Sam.

> -----------------------CODE TO FOLLOW------------------------------

> #include <stdio.h>
> #include <dos.h>
> #include <conio.h>

> void main(void)
> {
>         unsigned char data[512];
>         int i;
>         unsigned int segment, offset;
>         struct REGPACK reg;

>         // initialize each data object to a '.'
>         for(i=0; i<512; i++) data[i]=46;

>         offset = FP_OFF(data);
>         segment = FP_SEG(data);

>         // Loads the registers and performs the interrupt.
>         reg.r_ax = 0x0201;
>         reg.r_cx = 0x0001;
>         reg.r_dx = (0 ^ 0x0080);
>         reg.r_bx = offset;
>         reg.r_es = segment;
>         intr(0x13, &reg);

>         // Checks to see if the char. is printable.
>         for(i=0; i<512; i++)
>         {
>                 if ((data[i] > 0x20) && (data[i] < 0x7e))
>                         printf("%d ", data[i]);
>                 else
>                         printf(" ");
>         }
> }

--
********************************************

********************************************
I've never had a humble opinion in my life.
If you're going to have one,
why bother to be humble about it?
                                Joan Baez


Fri, 07 Jan 2000 03:00:00 GMT  
 Help needed: reading disks



Quote:
>I am trying to write a simple program that will dump to the screen the
>(printable) contents of one of the hard drives (in this case, C:).

>My code (included below) has two problems with it.
>        1.  Using interrupt 13,2 I can read sector 1 of cyl 0/side 0.
>            I can't seem to read sector 0 though.

The C language has no support for "interrupts". You appear to be using a
feature of the DOS environment so your questions should be posted to
a DOS related newsgroup such as comp.os.msdos.programmer.

Quote:
>#include <stdio.h>
>#include <dos.h>
>#include <conio.h>

These last two headers aren't standard, again they are related to DOS.

Quote:
>void main(void)

main returns int in C.

--
-----------------------------------------


-----------------------------------------



Fri, 07 Jan 2000 03:00:00 GMT  
 Help needed: reading disks



Quote:
> My code (included below) has two problems with it.
>    1.  Using interrupt 13,2 I can read sector 1 of cyl 0/side 0.
>        I can't seem to read sector 0 though.

Sector numbers in the PC under DOS/Windows and the BIOS start at 1, not at
0, so there is no sector 0 to read.

--

Jack Klein

All views expressed in this message are mine,
and not necessarily that of my company or any
of our clients.



Sun, 09 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. need source code to read floppy disk

2. raw disk sector read HELP

3. Help - Reading disk serial number

4. Help wanted on reading/writing disk and writing your own OS

5. please help me!How to read physical fixed disk secs under win9x

6. Reading Disks Directly (Hex Read)

7. Help with writing to disk needed

8. newbie needs help with disk file

9. Disk commands - help needed to control

10. Need help speeding up disk access in C program

11. PROBLEM ON THE BOOT SECTOR OF A 1Go PC Hard Disk - HELP NEEDED

12. Question about Serializing and Object to Disk....Need Help/Opinion

 

 
Powered by phpBB® Forum Software