Click here to Skip to main content
15,065,328 members
Please Sign up or sign in to vote.
1.40/5 (5 votes)
See more:
I know this looks strange; but I want to create a file without using any APIs and libraries like STL or DOS interrupts. In fact I'm going to know what's going on inside that black boxes. ANY CLUE can be quite cooperative for me. I myself guess it should be kind of linked to dealing with Device Driver or something.

To be more clear, I want to know how thouse APIs (e.g. CreateFile()) communicate with device drivers. Is there a standardized way? Furthermore, how device drivers deal with their hardwares? Is a certain portion of memory specified for them? and such questions ...
Posted
Updated 13-Dec-10 11:23am
v3

Hi Joseph,

If I understand your question correctly, you're mainly curious and want insight in how the OS interacts with hardware (using drivers).

I haven't worked with hardware or direct driver access for decades, but I would suggest starting here, if you're into Windows:

Windows Hardware Developer Central[^]

There is plenty of information on how drivers should be designed, including how they can interact with hardware (interrupt handlers, direct I/O, adapter memory access and so on), and how the OS interacts with the drivers (driver API).

I very much doubt (though I may be wrong) that you can interact directly with drivers from a normal user-mode program, at least not without going through Windows APIs (I think there are API:s to query drivers for status and so on). I suspect they're protected so that only the OS (or other kernel-mode software) has access to them - this is the case in all operating systems I have worked with.

I hope this helped.
   
Comments
Joseph Marzbani 14-Dec-10 0:14am
   
Thank you very very much for your reply, specially that link. I caought usefull information from your clues. Thank you :)
You mentioned not wanting to use any APIs and I'm going to suggest CreateFile[^] anyway, but because I think it's used in a way that is acceptable for you :)

CreateFile can be used to create a file, but it can also be used to directly access sectors on a disk. I learned how to do this a while ago from this[^] article.

You can open the floppy disk for example with
hFloppyDisk = CreateFile("\\\\.\\A:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

You can then access the required sector like so:
SetFilePointer(hFloppyDisk,512*(18*(cylinder*2+head)+(sector-1)),0,FILE_BEGIN);

And then write like so:
WriteFile(hFloppyDisk,buffer, 512,&count,NULL);


Now you have access to the raw disk data, you can create files if you have the knowledge how the file system stores it.
Do note that Windows might not allow you access to the disk you're interested in; for example your C:\ drive where Windows is installed is most likely going to result in an access denied error.
   
v3
Comments
Joseph Marzbani 13-Dec-10 17:21pm
   
I really apreciate your attention. You know what, to be more clear, I want to know how thouse APIs (e.g. CreateFile()) communicate with device drivers. Is there a standardized way? Furthermore, how device drivers deal with their hardwares? Is a certain portion of memory specified for them? and such questions ...
[no name] 13-Dec-10 17:28pm
   
Device drivers exist because different hardware often has a different interface to access it. So the communication between device and driver varies per device, while the communication between driver and API is similar, independant of the device.
Joseph Marzbani 13-Dec-10 17:33pm
   
I guess you meant to mention the difference between "Logical Device Drivers" and "Phisical Device Drivers", right? anyway, the point is to understand the way APIs communicate with device drivers. That's enough for now.
Are you by any chance writing a OS or a driver?
   
Comments
Joseph Marzbani 13-Dec-10 16:55pm
   
Do you think you're so funny?
LloydA111 13-Dec-10 16:56pm
   
WTF. I was asking a serious question.
Joseph Marzbani 13-Dec-10 17:09pm
   
No, I'm not.
LloydA111 13-Dec-10 17:11pm
   
No you are not what?
Joseph Marzbani 13-Dec-10 17:25pm
   
No, I'm not writing those things
LloydA111 13-Dec-10 17:27pm
   
Well OK then, that's all you had to say the first time round.
AspDotNetDev 13-Dec-10 17:30pm
   
Lloyd, this would probably be more appropriate as a comment rather than an answer.
LloydA111 13-Dec-10 17:32pm
   
I think "Well OK then, that's all you had to say the first time round." as an answer may seem a little random :P unless I misunderstand you which I probably have done.
#realJSOP 13-Dec-10 17:33pm
   
I think you're funny, but not as funny as me.
LloydA111 13-Dec-10 17:34pm
   
I was asking a serious question though :) But yes I agree with you John.
AspDotNetDev 13-Dec-10 17:39pm
   
Uh, now I'm really confused... not sure if you are kidding. I was referring to your "answer", which states "Are you by any chance writing a OS or a driver". It is that "answer" that I was saying should have been posted as a comment to the original question rather than as an answer to the question, because it is not an answer to the question. Unless you were trying to answer a question with a question (note that is different than answering with a reply to an answer to a question to a question) :-P
LloydA111 13-Dec-10 17:40pm
   
Erm yes... good point :)
Soulus83 14-Dec-10 10:07am
   
I do need a beer too....
0. Learn to spin a disk on one finger.
1. Introduce a magnet at just the right point.
2. ???
3. Profit!
   
Comments
LloydA111 13-Dec-10 17:13pm
   
You forgot LIQUID NITROGEN!
Keith Barrow 13-Dec-10 17:56pm
   
My Vote of 5: Your answer is a little old-fashioned, I have heard there are new solid-state technologies that are likely to supersede your electromechanical idea.
Hammer & chisel may do the job.
:rolleyes:
   
Comments
Joseph Marzbani 13-Dec-10 16:56pm
   
and an apprentice programmer like you!
LloydA111 13-Dec-10 17:05pm
   
You fool, how is he an "apprentice"? If you want to ask questions and expect an answer then offending people is clearly not the best way to do so.
Joseph Marzbani 13-Dec-10 17:12pm
   
I expected an "answer", not a joke. Anyway, are you his attorney?
LloydA111 13-Dec-10 17:15pm
   
I think you will find that had you provided me with some more information, I would have pointed you to some very useful information about what you were asking, hence I asked for more information but apparently that is not good enough.
Joseph Marzbani 13-Dec-10 17:29pm
   
I've added more info like what u asked 4. do ur best man, i need it
#realJSOP 13-Dec-10 17:35pm
   
@ Joseph Marsbunny - I think you've been spending too much time near the centrifuges...
CPallini 13-Dec-10 17:41pm
   
It is very diffucult to give you a serious answer, because the topic is deep, very difficult (daunting, I would say) and your sentences shows you're light-years aways from the kernel.
Soulus83 14-Dec-10 10:10am
   
I'd join any Linux distribution group and navigate through the code if I'd like to exactly know the insides of this types of api's as in old times =D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900