![]() |
|
#1
|
|||
|
|||
Find size of hard diskCan I anyone tell me how to find the total size of the hard disk using C?
The hard disk may not be formatted. I need to use it before installing the operating system on the hard disk. I need to do the program in C. Can anyone please help me? |
|
#2
|
|||
|
|||
Re: Find size of hard diskQuote:
I find this to be an interesting question. (See footnote 1.) Like most "interesting" questions, there may be lots of answers, but they all depend on other information that must be known before you even think of creating a program (in C or anything else). The couple of questions that I post below encompass some things to ask (and answer) yourself. I do not intend to take the list of your answers and give you a cookbook formula to success. (I probably can't, and I probably wouldn't, even if I could. If all you want is an answer, you probably will stop reading right about now, and I wouldn't blame you if you did.) Anyhow, here are a few things that you should write down before writing #include <stdio.h> 1. What is the context of your statement that you "need to do" the program? Is this a class assignment or a research project or some other edificational experience? (If so, what are the prerequisites that you are supposed to have mastered by now. What courses? What programming and programming project knowledge/experience?) 2. What is the context (environment) of the program? I'll expand: Since the program is going to examine a disk drive before it is formatted, obviously the program is not resident on that drive. So: is the program going to run on a machine that has another disk drive already formatted and running an operating system from which you can launch your program? If so: what operating system? Since things like disk accesses are not part of the C or C++ standards, programs that look at your system's hardware must necessarily be implementation-dependent. DOS can access disk drive information. Windows can access disk drive information. Linux can access disk drive information (so can OS/2, BSD, and anything else). Actually, you don't even need an operating system: Your computer's BIOS accesses disk drive information before your operating system is even loaded. If not (that is, if the new disk drive is attached to a computer that doesn't already have an operating system running), then how is the program going to be running? Is it on a CD (or other medium) or what? If it's on the CD, then what other stuff on the CD has been loaded into the machine's memory to allow the new program to be running? Maybe you have a CD, like Knoppix, that loads Linux into your computer's memory and then presents you with a Linux command line and/or graphical interface, from which you could read in your disk examination program (from another CD, from a FLASH drive, from the network, ...). Well, that doesn't make much sense, since if you have an operating system running in your computer's memory ---regardless of how it got there--- then you could use that operating system's disk management tools to find out the disk drive's information (fdisk for Linux, for example). The Windows installation disks load a stripped-down version of Windows before it gets to the part where it evaluates your disk drives and other attached hardware. So, depending on your answer to question number 2, you may need to revisit question number 1: Why do you "need to write" the program in the first place? If it's for your education (institutional or on-the-job training or otherwise), and you have no experience with disk drive access, you could try to find some source code somewhere. For example the GNU fdisk program from any Linux distribution performs the task. Since source code is freely available you could look at that. (See footnote 2.) I have to warn you that looking at Linux source code (or any other significant operating-system type of code--- "low level" or not) may not be the easiest thing you have ever done. Functionality is almost always spread out over a large number of files (some of which are really hard to understand). Low-level stuff like disk drive information of raw (unformatted) disks may very well involve links to architecture-dependent low level code that is even more difficult to follow (some of it may depend on initialization code buried even deeper in the source code tree and even more difficult to understand). GNU fdisk is actually an interface to the GNU parted (partition editing) library. (See footnote 3.) One final thing: a quote, and it's too important for a footnote. "Ya gotta have a plan." ---me Regards, Dave Footnote 1: "May you live in interesting times." ---Often quoted as an "ancient Chinese curse", but I doubt that there is anything Chinese about it. There is something interesting about it, however. (Or, maybe, not so interesting to you. But if you have some free time:Get a(n interesting) life!) Footnote 2: Freely available means, in this case, both "free" as in "free beer" and "free" as in "free speech". Start at http://www.gnu.org or http://linux.slashdot.org or http://www.sourceforge.net or ... ---Free Software Foundation Footnote 3: "toebone's connected to the footbone... footbone's connected to the legbone... legbone's connected to the thighbone... etc. ---Bottom-up description of human anatomy from an old Spiritual song. |
|
#3
|
|||
|
|||
Re: Find size of hard diskHi Dave,
Thanks for the info. I'm sorry to have missed out the details that you asked in the first post. In fact, I'll boot the system into DOS mode using a CD and run the program in DOS mode using a BAT script. The system will have only one hard disk and it need not be formatted ie. "a new disk drive is attached to a computer that doesn't already have an operating system running". And there's nothing much that gets loaded into the memory from the CD like Knoppix as you mentioned. And about the UNIX source code, will the program, if made similarly as in UNIX, work in DOS mode? I had gone through the source code "df". But I need to know if it will work in DOS mode before I proceed further. Thanks in advance... Aju |
|
#4
|
|||
|
|||
Re: Find size of hard diskQuote:
It sounds interesting, and I wish I knew how to help. Even if I had any specific recommendations, I don't have any way to test them, since I don't have anything for DOS program development. (I can create a DOS floppy boot disk on my Windows XP system, but I hadn't even thought about how one would go about making a bootable DOS CD. Hmmm...) Here's the thing: if you are going to write a "DOS mode" program in C, what compiler are you using? The reason that I ask is that all hardware-aware programs are necessarily using functions that are not part of the C standard library. That is to say, each compiler writer/vendor chooses a particular set of functions to implement that allows such access. There is no guarantee that any particular vendor will even supply such functions with the product (although, obviously, they had such functions in whatever in-house system they were using for development and testing.) So, if you have (or can get) any documentation from wherever you got your compiler, you can look. Lacking that, you can poke around in all of the header files (the compler's include directory and subdirectories) and look for functions that may appear to have something to do with hardware access. I can't imagine that there will be anything ready-made for your purposes, but you can look. I'm guessing that what you want might require access to BIOS routines to access the hardware. Compilers for Windows XP won't have any such things, but, again, depending on your compiler (since it is for DOS) you probably have some kind of BIOS call. Now, of course you have to become familiar with BIOS access to your disk information. Obviously it will be there, but I'm not sure things are set up the way they used to be when we used int13 to get to the disk in DOS programs (in a time long, long ago, in a galaxy far, far away). If you are familiar with something like djgpp, you may be able to find projects on sourceforge or other source project sites. Quote:
Quote:
1. Shut down all non-critical systems and enter minimum-maintenance subsistence mode. or 2. Direct my feet to the nearest public house. The "df" program on my Linux systems specifically lists disk space available on all mounted file systems. Note that in Windows parlance, the UNIX/Linux term "mounted file systems" in reference to hard drives means that the disk has been partitioned and formatted and has been mounted by the operating system. The fdisk program (and its big brother, parted) look at disk capacity in order to allow creation editing of disk partitions. I haven't tried to look at its source code (I'm not sure my tired old nervous system and cardiovascular system could tolerate it.) It is entirely possible that someone else reading this thread can offer more substantial help. I hope so. I would be literally thrilled to see more information about it. Maybe there are some PC/XT design engineers out there who haven't been confined to rubber rooms, and they can give us some clues. I wish you well, and if you ever get any questions that I could actually help with, I would like to hear from you. Actually I would like to hear about your progress even (especially) if you don't need help. Regards, Dave |
|
#5
|
|||
|
|||
Re: Find size of hard diskHi Dave,
Your reply was really inspirational. And I think I'm inching forward to finding a solution. It's easy to make a bootable DOS CD. you just have to make an image file and include it in the CD image. The system automatically boots from the CD and "autoexec.bat" is executed first. The compiler that i use is Turbo C. And as you said, there are no in-built functions that could be useful to me. But I think i have found a solution. I'm using int13 Extensions. Well, I found in the internet this soltion. But the new problem that i'm facing now is that, I get the same value in different machines!!! I'm still trying. I'm supposed to give the buffer address to the stack segment register. I'm not able to do that. Here's the code segment. CPP / C++ / C Code:
I've assigned the buffer like this CPP / C++ / C Code:
It's not working. Later in the code, this statement CPP / C++ / C Code:
Here's the whole program, CPP / C++ / C Code:
Last edited by LuciWiz : 23-Jun-2006 at 02:21.
Reason: Please insert your C code between [c] & [/c] tags
|
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hard disk serial number | ameynirgude | C Programming Language | 1 | 20-Nov-2005 05:55 |
| How to Remove Host Protected Area (HPA) of (ATA) Hard disk in windows with API calls? | nagamohan_p | MS Visual C++ / MFC Forum | 0 | 27-Sep-2005 23:27 |
| i can't find the wrong!! | small_ticket | C++ Forum | 2 | 20-Sep-2004 23:05 |
| Having a problem | Chuckles | Computer Hardware Forum | 19 | 13-Sep-2004 12:17 |
| Hard disk problem!! | jack21 | Computer Hardware Forum | 2 | 17-May-2004 10:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The