I know files are kept as chunks of blocks on disk or SD card. (SD card, being a block device, writes or reads in 512 Byte block. And file system itself manages with bigger size composed of those blocks like 4KByte maybe? I remember it is what is called allocation size and I know we can set this value when formatting the disk.)

When we edit a file, whether it's a plain text file or powerpoint file, and then save it, what happens in the file system?

My guess is the file system in the OS just allocates new blocks for the blocks from the point where the file had been changed and stores the parts after the changed location to the newly allocated blocks. Or if the application is written more smart, it will detect the changes and tries to minimize new block allocation (I mean accommodate the changes in as less number of blocks as possible and link them to the existing file blocks, like replacing blocks in the middle of a linked list). Of course this will have to waste some space in the newly assigned blocks but will keep the blocks in the later parts after the modification intact.

I would be glad if anyone can answer to my question or tell me my guess is correct or not.

ADD : from the comments, I figure it depends on OS and applications. and if I were a programmer who wrote the application(like power point or Word or any software) I would have overwrite to the allocation on the disk if it fits the change. I would appreciate it if someone just elaborate on this with some known examples.

  • 1
    "SD card, being a block device, writes or reads in 512 Byte block." ... not necessarily. The sector size could be larger, 1024 bytes, for example. – muru Mar 29 '18 at 1:56
  • It depends on which filesystem do you use. – Ipor Sircer Mar 29 '18 at 8:07
  • 1
    Which editor? Binary editors generally write in place, text editors almost always write out the full contents to a new temp file and then rename it. – Mark Plotnick Mar 29 '18 at 16:03

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.