Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,932 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,657 people online right now. Registration is fast and FREE... Join Now!




Manipolation of HD in C

 
Reply to this topicStart new topic

Manipolation of HD in C, I would want access into HD at the address thet I prefer

Oscar53
15 May, 2008 - 09:01 AM
Post #1

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 23


My Contributions
Hi I'm Emanuele and I'm studing Informatic Science in Italy.
the school year is ending and I'm trying to write a code quite difficult (for me biggrin.gif ) for working in the HD as I want.
I asked at my teacher but he didn't know how help me because him never tried to do a similar program. blink.gif
I'm not crazy but I want learn to do something different for myself.

However the matter is it:
I would want write a program that permit me to read and write where I want what I want into the hard disk as if I use a pointer in RAM.
Is it possible for a beginner as me?

Thank you smile.gif

I'm sorry if my english is quite bad ph34r.gif





User is offlineProfile CardPM
+Quote Post

homemade-jam
RE: Manipolation Of HD In C
15 May, 2008 - 11:02 AM
Post #2

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,065



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(Oscar53 @ 15 May, 2008 - 10:01 AM) *

Hi I'm Emanuele and I'm studing Informatic Science in Italy.
the school year is ending and I'm trying to write a code quite difficult (for me biggrin.gif ) for working in the HD as I want.
I asked at my teacher but he didn't know how help me because him never tried to do a similar program. blink.gif
I'm not crazy but I want learn to do something different for myself.

However the matter is it:
I would want write a program that permit me to read and write where I want what I want into the hard disk as if I use a pointer in RAM.
Is it possible for a beginner as me?

Thank you smile.gif

I'm sorry if my english is quite bad ph34r.gif


You'll have want to look into using the <fstream> header, see here for more info: http://www.cplusplus.com/doc/tutorial/files.html

If you want to write to more complex file types, there are particular libraries you can use.
User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Manipolation Of HD In C
16 May, 2008 - 02:10 AM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
I believe what you want to do is to create a memory-mapped file I/O setup. Look up the functions CreateFileMapping (windows) and mmap (Unix-like systems), which should get you started. I don't believe the standard C++ library includes a standard way to do memory mapped file I/O.
User is offlineProfile CardPM
+Quote Post

Oscar53
RE: Manipolation Of HD In C
16 May, 2008 - 07:00 AM
Post #4

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 23


My Contributions
the first matter is point to the address "0" of the HD.
I use address "0" (MBR) for example but it could be an other.
I must declare a pointer...but FILE *p is wrong as char far *p.
I don't know well the C++ so I'm searching a solution in C that I know better than C++ or as last solution the ASM.

first to create a "memory-mapped file I/O" I must succeed to read and write in the HD as I prefer.
Exist a pointer for this work?
Can I get the address from an open file?

Thanks Oscar53 smile.gif



User is offlineProfile CardPM
+Quote Post

Oscar53
RE: Manipolation Of HD In C
16 May, 2008 - 09:17 AM
Post #5

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 23


My Contributions
maybe the solution could be call an API of Win32... searching in the forum I have found some links about "CreateFile" but I don't understand how use it in my code...

excuse me if I am boring icon_up.gif

Bye biggrin.gif
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Manipolation Of HD In C
16 May, 2008 - 10:13 AM
Post #6

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
If all you want to do is create folders and place files in them, you could use the CreateDirectory () function. I'll give you a sample:
cpp
#include <windows.h>

int main ()
{
LPSECURITY_ATTRIBUTES attr;
attr = NULL;
CreateDirectory("C:\\test", attr);
}

Hope this helps smile.gif

This post has been edited by gabehabe: 16 May, 2008 - 10:13 AM
User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Manipolation Of HD In C
16 May, 2008 - 08:49 PM
Post #7

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
QUOTE(Oscar53 @ 16 May, 2008 - 08:00 AM) *

the first matter is point to the address "0" of the HD.
I use address "0" (MBR) for example but it could be an other.
I must declare a pointer...but FILE *p is wrong as char far *p.
I don't know well the C++ so I'm searching a solution in C that I know better than C++ or as last solution the ASM.

first to create a "memory-mapped file I/O" I must succeed to read and write in the HD as I prefer.
Exist a pointer for this work?
Can I get the address from an open file?

Thanks Oscar53 smile.gif


Well, unless you're using Windows 9X/ME/3.1/DOS, it won't make much of a difference what language you write it in, as you have to use a windows API or NT API call anyway. You won't be able to directly access the bus controller if that is what you are asking.

CreateFile can accept a device name, such as \\?\PhysicalDrive0. CreateFile returns a handle in which you can use ReadFile to read from it, and CloseHandle to close it.

I suppose you could probably use CreateFileMapping on the returned handle do memory mapped I/O, though I've never tried it myself. MapViewOfFile will return a pointer to a portion of the device that you specify.


User is offlineProfile CardPM
+Quote Post

Oscar53
RE: Manipolation Of HD In C
17 May, 2008 - 08:57 AM
Post #8

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 23


My Contributions
QUOTE
You won't be able to directly access the bus controller if that is what you are asking.


Yes I want access directly to the hard disk...

I have tryed to do a code in ASM:

CODE

.MODEL SMALL

.STACK

.DATA

.CODE

INIZIO:
    MOV AX,@DATA
    MOV DS,AX
        MOV AX,0    
    MOV DL,0    
    PUSH BP        ;save BP on the stack
    MOV BX,SP      
        
    MOV AL,2     ;set HD
    MOV CX,1    ;1 sector to read
    MOV DX,0    ;address 0
    INT 25H
    JNC SOTTO
    JMP FINE

SOTTO:
    MOV AL,[BX]
    CALL OUTPUT;OUTPUT is a procedure for printing to video a char
    
FINE:   NOP
        MOV AX,4C00H
        INT 21H

        END INIZIO


the code should be right but while I run it, Win Xp says me that I can't access directly on the HD as you said to me.
Well but at this point although I call the API cuold be possible access directly or not?

If as says gabehabe I make a directory, can I manage it how I prefer?
for example create a my "file system" and a program that manages it...

last demand and for today I have finished biggrin.gif

Linux can perform this job more easily?

I apologise again for my poor English.

thanks much for your help icon_up.gif
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Manipolation Of HD In C
18 May, 2008 - 10:41 PM
Post #9

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
QUOTE
the code should be right but while I run it, Win Xp says me that I can't access directly on the HD as you said to me.

That's because application programs in Win32 environment are not allowed to access hardware directly.

Compile your code using the Windows Driver Kit (WDK) (previously DDK - Driver Development Kit) by using assembly inserts and you will be able to access the hard-drive as drivers run in Ring 0 and have complete access to hardware.

Alternatively, find the hard-disk driver and use it to read from the hard disk using the DeviceIOControl() API function.
User is offlineProfile CardPM
+Quote Post

Oscar53
RE: Manipolation Of HD In C
19 May, 2008 - 08:35 AM
Post #10

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 23


My Contributions
thanks for your help!

However I have searched the "Windows Driver Kit" but I could not get it... can you give me a direct link for the WDK???

can I easily use the "DeviceIOControl()" or the best thing is use the WDK?

Thank you very much biggrin.gif

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:24AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month