I'm trying to write a program that writes data to a disk in C++ without caring about it's file system. Here is what I can do so far:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
usingnamespace std;
char buffer[] = "Wow! I'm writing this data to a disk without puttting it into a file!";
int main(){
int Disk=open("/dev/sdb",O_RDWR);
write(Disk,buffer,sizeof(buffer));
close(Disk);
return 0;}
But this program can only write ASCII characters to the disk. But what if I want to mainipulate bits on the disk, how would I do that?
The C and C++ file functions work on bytes, which in the language is called a char.
Modify the bits of the characters (bytes) you read and/or write.
Hope this helps.
PS. I don't recommend blithely opening hard drives and writing data to them. There is no such thing as file-system agnostic. Either you obey the filesystem structure or you obliterate it. There is no other option.