1

As per my understanding, READ/WRITE etc are file system operations in linux. The file systems registers callbacks with the Kernel (VFS) and are in turn called by it when the particular FS is detected during a READ/WRITE operation.

For example:

EXT4_write:

VFS write request -> ext4_writepages()

F2FS_write:

VFS write request -> f2fs_write_data_page()

But what if the storage medium is not formatted. It does not have any file system. When a READ/WRITE operation is performed on it, which filesystem operation is selected by default ?

3
  • 2
    A disk must be in some recognized format before an OS can writer to it. Commented Jul 12, 2020 at 14:04
  • Are you asking how to open a raw device and perform read/write/seek operations on it without going through the VFS layer?
    – jsbillings
    Commented Jul 12, 2020 at 15:18
  • @jsbillings well, yes that was one of my questions, maybe you could answer this other quesiton: unix.stackexchange.com/questions/598121/… Commented Jul 12, 2020 at 16:35

2 Answers 2

3

In order for the VFS layer to be able to do read/write operations on a file, then that file must be opened in one way or another. If you have a medium that has no filesystem, then you cannot mount it. If you cannot mount it, then you cannot have a path to it for use by open(). If you cannot open a file on it, then you cannot perform read/write operations on it. Thus, you cannot do read/write operations on a medium with no filesystem.

You would have the block device (assuming all necessary drivers are available), which would enable you to do I/O on the device itself in order to format it.

2

You do not need to have a formatted filesystem on a block device in order to do read/write operations to it. You can open the block device or partition (e.g. /dev/sda1) and read/write the blocks directly. This is how tools like mke2fs and e2fsck read and write the blocks of the device itself to format or repair the filesystem therein.

Having a similar access method for different types of devices (HDD, CDROM, NVMe, different filesystems, files, directories, etc.) is one of the strengths of Unix-like systems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .