-4

I want to write a program that formats a disc to a new format (not NTFS or FAT32) and can read from and write to the disc, In order to do this, I have to have a way to write single bytes to a disc (without creating files). How do I do that?

EDIT: I found this. But I'm not sure if using CreateFile() as Eli Bendersky said in the first answer (when organized in order of votes) let's you write one byte (or even one bit) at a time, or do you have to write full sectors at a time.

Answer: Since I can't post an answer the question because it was closed, I will answer it write here. You don't need need API functions to do this. All you need to do is open the disk like you open any other file. Like this:

int hFile;
hFile=open("/dev/sdb",0_RDWR);
Community
  • 1
  • 1
Isaac D. Cohen
  • 797
  • 2
  • 10
  • 26
  • Hi Isaac; I suspect this question is going to continue to attract negative votes, primarily because it doesn't provide any examples of effort (namely, what documentation have you read, what code have you tries, and what do know so far.) Your best bet is to do some googling and see what you find out. – Lynn Crumbling Feb 11 '14 at 17:07
  • Windows is going to prevent any kind of direct hardware access to the disk. It's going to want you to use Win API calls for everything. A driver is one approach that would work, but these are incredibly complicated to write. You may try using an existing one: https://www.eldos.com/rawdisk/ Also, take a look at this question: http://stackoverflow.com/a/8808596/656243 – Lynn Crumbling Feb 11 '14 at 17:13
  • Which API calls can I use? – Isaac D. Cohen Feb 11 '14 at 17:23
  • Take a look at this: http://stackoverflow.com/a/8541873/656243 .. in which they say to use `CreateFile()`. Also, Microsoft has put up this KB article about restrictions: http://support.microsoft.com/kb/942448 – Lynn Crumbling Feb 11 '14 at 17:39
  • It's worth mentioning that this is a *REALLY* scary thing to do. You should not do it with a volume that you care about, like your current PC. The target hard drive should have no valuable data on it. – Lynn Crumbling Feb 11 '14 at 17:40
  • Once I open the disk how do I access it's bytes? – Isaac D. Cohen Feb 11 '14 at 23:53
  • If it works like every other handle-based call, once CreateFile hands back a handle, you [can use ReadFile() to get data](http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx). – Lynn Crumbling Feb 12 '14 at 04:05

1 Answers1

-2

You program has to directly talk to the driver as you will be by-passing the file-system.

Nipun Talukdar
  • 4,975
  • 6
  • 30
  • 42