I was trying to write a program as a proof of concept in order to delete the GPT partition table from my HDD. To cut it short after opening the disk, I do something like the following:
//Removes the first partition table in the beginning of the disk
::lseek(fd, 0, SEEK_SET);
::write(fd, '\0', GPT_PARTITION_TABLE_SIZE);
//Removes the backup partition in the end of the disk
::lseek(fd, -GPT_PARTITION_TABLE_SIZE, SEEK_END);
::write(fd, '\0', GPT_PARTITION_TABLE_SIZE);
Even though that seemed to work well, I got a word from a friend that this way is not correct and I should use a local buffer for writing and that my code tries to use NULL as a pointer into write() which is not the right way.
I spend quite a few hours to understand what he meant, but I am still not sure I get it. Has anyone have ever tried something similar?