• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

read/write to HDD rawly

Red Squirrel

No Lifer
I want to write a program that can read/write to a HDD at the raw level, (non MS specific code - needs to work in Linux).

Basically, something like SPFdisk does, where you can edit byte by byte. Just wondering which functions/classes/headers I'd have to look at for these abilities. Just need a link in right direction so I can RTFM further on this subject. Thanks.
 
Originally posted by: Journer
i would think it would need to be written in assembler
what are you doing, writing viruses or something?

Yeah I want to write a boot sector virus.

No. j/k

I'm more or less just curious and want to screw around with low level stuff, well at least at the bit/byte level. I would imagine at the mechanical level would require to know that exact drive, and be written in assembly so I can talk directly to the drive itself.

 
I don't think you can access the harddrive directly from within protected mode. An app running not in ring 0 simply doesn't have the permissions to do so. At least that's the case on modern OSs
 
I think you would need to run it as root to get into ring 0. I'm not sure though.
On Windows only processes running as "System user" can do that. Some Services for instance.
 
I think you would need to run it as root to get into ring 0. I'm not sure though.
On Windows only processes running as "System user" can do that. Some Services for instance.

Unless you're running in the kernel you're not in ring 0, just running as root or SYSTEM doesn't get you into the kernel.

But works fine from userland anyway, there's nothing stopping you from accessing /dev/whatever directly. I just ran 'less -f /dev/sda' and saw some GRUB strings since that's where the bootloader's installed.
 
Originally posted by: ChristianV
I think you would need to run it as root to get into ring 0. I'm not sure though.
On Windows only processes running as "System user" can do that. Some Services for instance.

You can access the raw block devices in Windows using DeviceIoCtrl in user mode. However, that being said, you don't have complete raw access - it's still block level access. Doing full raw access means accessing the IO port directly or going through the BIOS, which means a kernel driver.

That being said, you can do most any disk IO you would generally need to do from a block device (LBA block addressing will let you read and write bytes anywhere, what it won't let you do is for example place head 4 directly at physical sector 233224 on it's corresponding platter - there are a few levels of abstraction that make LBA linear, which physical access isn't).
 
Back
Top