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


 
Thread Tools Search this Thread
Top Forums Programming A Pointer to non-Virtual Address, and All of my Hard drive
# 1  
Old 12-12-2005
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. Smilie
# 2  
Old 12-12-2005
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.
# 3  
Old 12-12-2005
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:
Code:
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.
# 4  
Old 12-12-2005
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.
# 5  
Old 12-12-2005
Hey thanks. I've began a turotial on loading and unloading kexts in the kernel. I'll see how far that takes me.
# 6  
Old 12-13-2005
<deleted message>

Last edited by xcoder66; 12-16-2005 at 02:00 AM..
# 7  
Old 12-18-2005
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'.

Last edited by Corona688; 12-18-2005 at 03:46 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Pointer and address

This code is to print out the program name and arguments list one by one: 1 #include<stdio.h> 2 3 void main(int argc, char *argv) 4 { 5 int iCount = 0; 6 while (iCount < argc) { 7 printf("argc:%d\t%s\n",iCount, argv); 8 ... (14 Replies)
Discussion started by: yifangt
14 Replies

2. UNIX for Dummies Questions & Answers

Printing pointer address

How can I print the memory address of a pointer using printf (or any other STDOUT functions?). I see in Linux its %p but not in unix, help? thanks (5 Replies)
Discussion started by: perleo
5 Replies

3. Linux

C++ Code to Access Linux Hard Disk Sectors (with a LoopBack Virtual Hard Disk)

Hi all, I'm kind of new to programming in Linux & c/c++. I'm currently writing a FileManager using Ubuntu Linux(10.10) for Learning Purposes. I've got started on this project by creating a loopback device to be used as my virtual hard disk. After creating the loop back hard disk and mounting it... (23 Replies)
Discussion started by: shen747
23 Replies

4. UNIX for Dummies Questions & Answers

What would the physical address be for virtual address?

Hi guys, I got one problem which I definetily no idea. What would the physical address be for virtual address? 1) 2ABC 2) 3F4B Here is the page table:see attached Thank you sos sososososso much!! (0 Replies)
Discussion started by: lemon_06
0 Replies

5. Programming

address of pointer

Hi i'm new to c programming and i'm trying to change the address of a pointer/variable but i can't seem to get it right, I have this char heap; char *firstFree = heap; char *allocMem( int size ) { void *malloc(size_t sizeofint); /*allocate space for an array with size... (19 Replies)
Discussion started by: Poison Ivy
19 Replies

6. Filesystems, Disks and Memory

The best partitioning schem for a 250GB Sata hard drive & a 75GB SCSI hard drive

Hi I have 2 75GB SCSI hard drives and 2 250GB SATA hard drives which are using RAID Level 1 respectively. I wana have both FTP and Apache installed on them as services. I'm wondering what's the best partitioning schem? I wana use FC3 as my OS, so, I thought I can use the 75GB hard drive as the /... (0 Replies)
Discussion started by: sirbijan
0 Replies

7. UNIX for Dummies Questions & Answers

Trying to copy old hard drive to new hard drive.

:confused: ........I have a new hard drive and I need to copy ALL info from the old to the new. I would like to use the dd command. I know the command is as follows...... dd if=/dev/rdsk/c1t1d0s0 of=/dev/rdsk/???????? Where I have the question marks is the problem. How do I find out what the... (4 Replies)
Discussion started by: shorty
4 Replies
Login or Register to Ask a Question