How do you read hard disk sectors in C++ with gcc/linux? Is there a standard library that I can use or must something be downloaded? In Windows I can use CreateFile(…) to access raw disk sectors, but I do not know how to do in in Linux.
I am using GCC on Ubuntu LTS 10.4. Thank you for your help.
The hard disk is just another file (not a “regular file” but a “device file”, but still, a file). Open it the normal way…
You will get permission errors unless you have the right permissions. Note that
"/dev/sda1"is just an example, it is the first partition on disksda, the exact path will depend on your system. You can list mount points with themountcommand, and you can access entire disks (instead of just partitions) using/dev/sda,/dev/sdb, etc.You could also open it as a C++
fstreamor CFILE, but I do not recommend this. You will have a better time finding example code and getting help on forums if you useopeninstead.