0
$\begingroup$

I have recently been interested in low level computer science (as a hobby), and I have just learned about the way a computer organizes and stores information on a hard drive. I have learned the basics of how a filesystem works. I understand that in the case of Unix, an inode entry is created for each file in the inode table near the beginning of your drive, and each inode has a preallocated block for storing direct and indirect pointers to fragments of the file.

I have a few questions regarding this:

  • If the block pointers are stored in order (which I'm assuming they are), how does the computer handle deleting or modifying from the middle of a file? As I've understood so far, filesystems were designed because storing files in order on the drive is messy and modifying/removing files in the middle of the drive would mean everything else would have to be shifted around. But don't inodes create this same issue on a smaller scale? When deleting or modifying the middle of a file, if the computer reads from the block pointers in order, you would need to shift every pointer back one space, even in the indirect pointers, because there would be a new empty space in the inode table for a block pointer, assuming you deleted/modified more than the size of the block its pointing to. How does the filesystem handle this?

  • The same question applies to the actual inode table itself. When removing a file indexed somewhere between other inodes, are all the following inodes just shifted back? I would think if this is how the filesystem truly operates, it would slow down your computer a lot.

  • How is empty space in each block dealt with? Say the size of each block being pointed to is 4K on this particular system. What if I delete 2K of data from the center of the file? Is the remaining 2K zeroed over and left unused? What about the end of the file? If this is the case how does the CPU know how much free space is at the end of each block when loading a file into RAM? And wouldn't this leave a lot of wasted storage space on your drive?

If someone could clear these questions up for me that would be great. I have a curious mind. Thank you.

$\endgroup$
  • $\begingroup$ Please ask only one question per post. $\endgroup$ – Raphael Nov 7 '17 at 20:17
  • $\begingroup$ @Raphael Often a larger question has a subset of smaller questions that lead into understanding the answer to the larger question at whole. That was my intent. My apologies if I was too broad. $\endgroup$ – James C. Nov 7 '17 at 20:54
  • 1
    $\begingroup$ @JamesC. OK, but your third question about empty space does seem to be quite distinct from the questions (or multipart single question) about inodes. Also, your title is extremely broad: when I saw your question on the front page, my first thought was that I was going to have to leave a comment along the lines of, "Dude, there are whole books about that!" and vote to close. It might help to give a more specific title so that potential answerers come in with the viewpoint that you might be asking something answerable. :-) $\endgroup$ – David Richerby Nov 7 '17 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.