Thread: How to get floppy disk information ?!!

  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497

    How to get floppy disk information ?!!

    hi guys ..im asking for your help on solving this mind boggling problem ...
    you know 2 or 3 month ago i wrote this piece of code in order to get the floppy disk geometry ...and it was as follows:
    Code:
    //In the name of GOD
    
    
    #include <conio.h>
    #include <stdio.h>
    #include <process.h>
    #include <dos.h>
    #include <stdlib.h>
    main(void){
    int i,k,start,sector;
    char x[512];
    clrscr();
    gotoxy(27,5);
    textcolor(2);
    cprintf("In the name of God\n");
    gotoxy(22,7);
    printf ("First project  Project\n\n");
    cprintf ("  This program will show you the information stored on sector 0  of your Floppy disk.\n ");             
    printf("     if you are ready press any key to continue ");
    for (k=0;k<=4;k++){
    delay(500);
    cprintf(".");       }
    getch();
    sector =0;
    if (absread (0, 1, sector, &x)!=0){
    cprintf ("Error");
    exit(1);
    }
    gotoxy(30,8);
    cprintf("Read Successful!\n\n\n");
    for (i=0;i<=512;i++)
    cprintf("&#37;c",x[i]);
    getch();
    return 0;
    }
    after that i see some irrelevant characters on screen ... i just went after it and found some progs and also information concerning FAT
    and it was :
    Code:
    {
      char jumpCode[3];//0 - 2 	Assembly Instruction for jump code.
       char oemName[8];//3 - 10 	OEM Name.
       char bytes_Sector[2];//*11 - 12 	Bytes per sector.
       char sec_Cluster;//13 	Sector per cluster.
       char size_Sector_Reserved[2];//14 - 15 	Number of reserved sector(Boot Sector)
       char fatCount;//16 	Number of File Allocation Table
       char Max_Root_Entry[2];//17 - 18 	Maximum entries possible under root directory.
       char Total_Sector_FS[2];//19 - 20 	Total number of sectors in file system.
       char Media_Type;//21 	Media Type(According to Microsoft 0xf8 for fixed disk and 0xf0 for removable disk.
       char sectors_per_fat[2];//22 - 23 	Sectors allocated for each File allocation table.
       char sectors_per_track[2];//24 - 25 	Sectors per track.
       char total_Head_Count[2];//26 - 27 	Number of head in storage device.
       char no_Sectors_Before_Part[4];//28 - 31 	Number of sectors before start of partition(Not applicable for floppy).
       char no_Sector_FS32[4];//32 - 35 	Number of sectors in file system(32-bit value, not applicable for floppy).
       char BIOS_13h_Drive_No;//36 	BIOS INT13h drive number.
       char reserved;//37 	Not Used.
       char ext_Boot_Part_Signature;//38 	Extended boot signature.
       char vol_Serial_Number[4];//39 - 42 	Volume Serial Number.
       char vol_Lebel_Name[11];//43 - 53 	Volume label in ASCII.
       char FS_Type[8];//54 - 61 	File System Type.
       char boot_Code[448];//62 - 509 	Boot Code, otherwise contains information to replace disk.
       char signature[2];//510 - 511 	Signature for File System.
    i just tried to use loops to save the data of the specific regions of the floppy disk on the screen for example i used:
    Code:
    for(j=0;j<=2;j++)
    printf("Assembly instruction for jump code : %C",&x[j])
    but again no luck !!
    im really confused !!! how to deal with it in C?
    (ive already noticed the VC++ equivalent but i have not worked on Vc++ ,so i dont know anything about that ...please tell me and help me on C .... tell me how i can do it under C

    oh by the way i was using TC 3 ..thats why it looks ancient ..( im using Pelles C now ..but it seems it doesnt have some header files such as Dos.h ..so i just used TC )

    many tanx in advand
    Last edited by Masterx; 11-09-2007 at 12:09 AM.

  2. #2
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    plz sb help me on this

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I can't help you; this is a question related to hardware much more than it is to C. C is independent of such devices, and looks to the hardware folks to provide the "hook" to query their device for info.

    I'd bet $$$ that you could find a program to do this on one of the code depot website, like sourceforge.net, etc.

    I'd hate to bet whether the old "DOS" type programs could query the device, in Windows or Linux. DOS was certainly OK with such direct access, but newer OS's may be quite particular about this sort of thing.

    In any case, this will bump your question back up to the top of the heap, but sourceforge.net and similar sites, will surely have what you want.

    "In the name of GOD" ?? You want to query a floppy drive in the name of God?? I'd change that little line at light speed. You've found a brilliant way to tick off both atheists and believers, at the same time!
    Last edited by Adak; 11-09-2007 at 01:10 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about beginning with telling us which OS you have, then we can advice a suitable compiler and API to use.

    Just because your ancient fossil compiler manages to run "hello world" doesn't make it suitable for messing with the hardware at such a low level.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    tanx anyway guys
    first
    Adak ...
    "In the name of GOD" ?? You want to query a floppy drive in the name of God?? I'd change that little line at light speed. You've found a brilliant way to tick off both atheists and believers, at the same time!
    i always start my works with the name of God .. cause it makes me think better ... i do love him ..and of course i place his name on all of my progs and other stuff ..thats it .. no other intention ...

    Salem :
    im using Windows Xp pro ,and under this Os . im using Pelles C Compiler ....

    you know we were asked to get the floppy disk infos using C ... to me it means it runs under DOs ..so i couldnt use VC++ or other Apis ... i thought it would be wrong ...

    anyway ... now ..all i want is to know if it is possible to get the data using C (sure it is possible)
    and HOw to do it ...

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm not 100% sure which function(s) you need of these, but I think you can get the relevant info in one of these functions - and it will work under XP. This is a more secure and portable method.

    If that fails, you can open the device (A as a file with CreateFile():
    http://msdn2.microsoft.com/en-us/library/aa363858.aspx

    If you scroll down, there's a section on the "open a physical device" mechanisms. Then read 512 bytes to read a sector, and you should be able to get the disk info you have in the struct. You are "on your own" when you use this sort of mechanism - nothing to prevent you from "getting it wrong".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    tanx mat , i ll give it a try .
    Last edited by Masterx; 11-09-2007 at 06:14 AM.

  8. #8
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    em .. Mat . i m sorry . but isnt it A windows API ? how can i use a windows Api under C? (not VC++)
    im not familiar with working with win APIs under C ...
    is it possible just to use them in the program ? but what header file should i choose?

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ehm, my previous post should have had a link to the volume control functions:
    http://msdn2.microsoft.com/en-us/library/aa365730.aspx

    You can use all Win32 API functions in C by including the correct header-file, which is specified by each function in the links given - it is USUALLY <windows.h> but some funcitons are in other header files. [Of course, the actual function may be in a different file - but you usually have to include the "main" header file, as the individual functions header file is incomplete and will require other header files to be included first, and which those are and what they are called may change over time, so including the main file is a much better idea].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    By the way:
    Code:
    for(j=0;j<=2;j++)
    printf("Assembly instruction for jump code : %C",&x[j])
    Not sure what %C does, but I would expect this to print badly if %C is similar to %c - particularly if you take the ADDRESS fo x[j] - as that will not print anything useful. [unless x is a char whose address is at the jump code.]

    Unfortunately, searching with google for %C shows up a bunch of %c, so I wasn't able to find the meaning of %C.

    The jump code should be 0xE9 0xXX 0x0X where X's are variable depending on exactly where the jump leads. A highly likely scenario is that the 0xE9 0x3E 0x00. Technically, it can also be 0xEB 0xXX, with possibly with a single byte instruction first.

    What did you expect this to do?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    well i just mistyped it ... its &#37;c and the intention was to print the instruction ... well i used %d and he other % sign stuff ..but no luck , thats it ..i was seeking a way to show the desired data...
    by the way those codes you ve just mentioned must be hex ? am i right? if thats right ,why didnt i get my answer by using %#x? its supposed to be used to show stuff in hexadecimal right? so whats the problem here too?
    well at last im going to say that im kinda confused with Assembly jump codes

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, using "&#37;02x" should show you the opcode as a two digit number, which is probably the most sensible.

    What did you expect it to show, what DOES it show?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    Quote Originally Posted by matsp View Post
    Yes, using "%02x" should show you the opcode as a two digit number, which is probably the most sensible.

    What did you expect it to show, what DOES it show?

    --
    Mats
    Unfortunately when i was testing the prog ... my whole system crashed ! and i was forced to install a fresh copy of Windows Xp (pro) ... after spending more than 3 hours of installing different kinds of softwares .now im online ..
    by the way i still have no idea what caused the crash ... (maybe the fossil Tc caused that ...cause i just wanted to test the prog under damn Tc and that happened !

    anyway to give you the answer: well it prints sth like this :fd5d and in the next line it printed :fd4d ( i m not sure if this was the one ...but they were descending .. )

    anyway i will try to use that lets see what happens then ..
    tanx bro

  14. #14
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    Well i tired "&#37;02x" and no luck ...things that was printed are >>:fdf2,fdf3,fdf4
    thats all

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Looks like my sig-line is true

    But we have no idea what code you ran, or which compiler you were using last (pick one of the ones which isn't TurboC and stick with it for more than 5 minutes).

    As it stood, you were just two typo's away from reading the boot sector of A: to writing the boot sector of C:.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floppy disk filesystems
    By Leeman_s in forum Tech Board
    Replies: 5
    Last Post: 12-10-2003, 04:54 PM
  2. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  3. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 08:20 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  5. Information about disk
    By GaPe in forum C Programming
    Replies: 18
    Last Post: 08-05-2002, 06:48 AM