A Pointer to non-Virtual Address, and All of my Hard drive

How do I get a pointer to any 32 bit address on my hard drive, in which I then could read that memory or write to that memory address?

And, while the subject is on, how do get a 32 bit pointer in RAM also, in which I can do the same?

I'm using C and Objective-C with gcc on an iBook G4.

A small example in C would be greatly appreciated. :o

What you want to do is direct physical I/O. It is completely hardware/kernel depdendant. You will probably have to write a kernel mode module, since user mode I/O does not have access to an address on a disk. You do realize you can trash your whole filesystem by writing something in the wrong place.

You'll have to get information on your kernel's source, and actually create a system call to do what you want, if one doesn't already exist.

When you say get information on your kernel's source, does that mean the C code will be different from platform to platform?

I asking, because I'm really after a C code example to get me going. I'm assuming the code example has got to be pretty simple.

Psuedocode:

Get a pointer to an address;
Write this value to such an address;

I have a tutorial on writing kernels for OS X, but I just don't know what the C code would begin to look like.

Yes - the kernel source is different from distro to distro and has lots of hardware dependencies for things like endianess.

Some points --

  1. OS X is open source, I believe. That means either you already have or can download kernel source.

  2. kernel code is not always super-simple, but there may be an existing physical I/O function you can work with. If there is you can make a minor change and allow the function to be exported from the kernel to user space. Then you can call it from C.

  3. If there is no function you can use, then you will have to create one.

In any event, you will have to learn something about the kernel. I just googled for
'linux kernel programming' and got a load of white papers, turtorials, and books.
You will have to do some reading.

PS: sometimes you can directly access the BIOS on your box. I'm not an OS X person, but be sure to research BIOS access - sometimes it's possible from a simple 3 line ASM call embedded in C.

Hey thanks. I've began a turotial on loading and unloading kexts in the kernel. I'll see how far that takes me.

<deleted message>

I don't know if you can do it with pointers, but on some UNIX systems you can get access to physical memory via /dev/mem.

[edit] Actually, if you can mmap it, you can get pointers to these things. Find out what device under /dev your hard drive is, and mmap-ing it will map a region of virtual memory into your memory which will act like this area of space on the device you've mapped. It's a very elegant way to access things. See 'man mmap'.

I think he wants to do low-level I/O directly, essentially bypassing most of the kernel's protections. Essentially, hack a disk.

I got a simple kernel working. Some guy on another site said to use fopen() to get a pointer in /dev from file called disk0, disk1, disk?, etc.

I can't use this syntax without getting an error: FILE *f.

I can't include stdio.h. It gives me an error. Now I'm stuck. this platform makes it hard, because hardly any one knows it and there aren't any kernel books. I probably switch platforms in the next year, because my development is being retarded because of these issues. Unix and Windows both have a jealous amount of stuff for their platforms at my local bookstores, but the Mac section and book search produce scant.

None the less, for the time being, if anyone could help me with the stdio.h file inclusion, it would be much appreciated.

iBook G4, dunno what system that is.
any case is it some linux system? some linuxes I have found throw error for stdio.h
is ur gcc and c++ compiler the same, if yes try using
#include<stdio.h>
using namespace std;

and then compile.
i think for FILE *f, u shud include fcntl.h.