I'm an amateur programmer. I have a lot of interest in the inner workings of operating systems, a subject that I've been reading a lot about.
What I've understood about kernels is that on most operating systems, a process is not able to access the hard disk (or other storage media) directly, but rather through system calls. So, for example, when a process wants to handle files, it asks the kernel to do it on its behalf rather than writing/reading the disk directly.
Now, I've also understood that when files are deleted, they usually are not actively overwritten by the kernel but just marked as unused so that they can be overwritten when space is needed. This means that even if I've deleted a file, it might still be recoverable as long as it hasn't been overwritten yet (it's just sitting on the hard drive).
This can pose somewhat of a security risk if I dump my hard drive, or an opportunity to recover accidentally deleted files. So there are software to both recover deleted files or purge the hard drive of deleted, but not yet overwritten files. Here is my guess on how they work: For recovery, we basically just scan the hard drive, looking for sections of data marked as available to see if our file is still there (apparently sections/chunks of data have metadata signifying things like availability, file name). Then if we find our file, we just mark it back as non-available. For purging the drive, the software probably just writes zeroes or something over the old data.
But my question is (if my guess about the workings of these kind of software is right): How can an application do this, since it is not part of the kernel? The kernel has a very defined API for file handling, and if we ask it to delete a file it will do so in its own manner and there should be nothing we can do about as normal applications. So how do these kind of software work? How can I build a program that accesses the hard drive in free manner?