Have you ever used VIM editer in the linux? If yes then you must have observed that whatever you type in the editor is visible to you and your system knows that what characters you have written. It means these characters are stored somewhere in the system.
What happens when you just gave the :q command in the VIM editor, the editor is closed now and whatever characters you have written in the Vim Editor is lost now.
What happens when you gave the :wq command in VIM, the editor is closed but whatever you have written in the Editor is not lost. You can get this saved file even after rebooting your system. If you know the secondary memory then it simply means that now the file is in the secondary storage.
Both the times the file was saved in the system but only difference is that for the first observation the file was saved in you primary memory and the second time you just saved your file in the secondary storage.
Who did this stuff? The answer is block layer of the Operating system.
This is just a example to understand what is the role of Block layer of the Operating System but there are too many stuffs in the operating system where the block driver works. To implement the block driver we can simply have a conclusion i.e. whenever we need to save the primary storage data into the secondary storage or to fetch the data stored in the secondary storage into the primary one, the block layer comes into the picture.
The block driver simply writes the block of bytes into the secondary storage from the primary storage or reads the block of bytes from secodary storage to the primary storage.
The block driver deals with the data in fixed size of blocks. Mostly all the devices which are used as the secondary storage are the block devices.
We require to mount a filesystem on the block devices. Filesystem provides the way of arrangment in the device and meaning of the simple 0s and 1s(raw data stored on the device) to the Operating System. The device file provides the interface between the filesystem and the block device driver. Filesystem can divide the disk (Mostly the secondary storage) into multiple logical parts i.e. partitions of the disk.
Block devices support random access and generally use buffered input and output routines. The operating system allocates a data buffer to hold a single block each for input and output. When a program sends a request to read data from, or write data to, the device, the system stores each character of that data in the appropriate buffer. When the buffer fills up, the appropriate operation takes place (data transfer) and the system clears the buffer.
The sector is the smallest addressable unit of the disk. Each sector stores a fixed amount of user-accessible data, traditionally 512 bytes for hard drives and 2048 bytes for CD-ROMs and DVD-ROMs. Newer hard drives use 4096-byte sectors.