title: What do file operations look like at assembly level
body: <p>To my naivete , everything stored in the secondary memory (hard disks) are stored in files. As such I understand of file system as the systematization of the information about each and every block of a file .(This in turn might turn out to be a systematization of the information about inodes) . </p>
  
  <p>So what I wanted to know is what happens at assembly and hardware level when a program intends to do an operation on a file . I tried thinking about it and it was along the following lines .</p>
  
  <p>So if my understanding , which I wrote down in the first paragraph , is correct ,then any read operation demanding a certain number of bytes , let's say X , will divide X by block size to get a result ,say  N , then query the file system for the location of the contents of the first N blocks and fetch the content stored in those locations . If it is a hard disk then the contents are fetched from the disk . But does this reading from disk involve using DMA and hence the communication being controlled through some DMA controller ?</p>
  
  <p>When the required number of bytes are read then do they place the content in the stack of the program executed where a variable will be holding the required number of bytes or the hence obtained contents are placed in some other location , like , heap ? </p>
  
  <p>Similar mechanism I could think of for write operation , where the offset is taken , the required block number is determined , then the new bytes to be written are divided into blocks and the new blocks are updated in the file-system .</p>
  
  <p>Please correct if my above understanding is wrong .</p>
  
  <p>However, I could not think of anything significant for closing of files  and could not figure out the ill effects of not closing files in terms of hardware and assembly . </p>
  
  <p>I have been through the following posts : </p>
  
  <p><a href="http://www.brokenthorn.com/Resources/OSDev20.html" rel="nofollow noreferrer">http://www.brokenthorn.com/Resources/OSDev20.html</a></p>
  
  <p>and </p>
  
  <p><a href="http://www.brokenthorn.com/Resources/OSDev20.html" rel="nofollow noreferrer">http://www.brokenthorn.com/Resources/OSDev20.html</a> .</p>
  
  <p>Here , I can see the illustration in assembly for writing to a floppy device or doing DMA  but in the following chapter :</p>
  
  <p><a href="http://www.brokenthorn.com/Resources/OSDev22.html" rel="nofollow noreferrer">http://www.brokenthorn.com/Resources/OSDev22.html</a> </p>
  
  <p>which is about file systems I could not exactly find out the assembly level details of file operations . (Although in some of the previous chapters , reading from FAT had been covered but to the best of my memory it used BIOS interrupts ) . </p>
  
  <p>So in a nutshell , what happens at hardware and assembly level during file opening , file reading , file writing and file closing ?</p>