1

Can filesystems be created only on block devices, but not on character devices?

Can a filesystem be viewed as a block device itself (for example, when programming to use a file system)?

My guess is yes, not very surely based on the followings:

  • There is a diagram for Linux, from Operating System Concepts:

    enter image description here

  • It seems that in Understanding the Linux Kernel, the IO operations on regular files and on block device files are largely implemented similarly to each other above device drivers, compared to IO operations on character device files.

Thanks.

I seem to remember there are filesystems not built upon physical devices, such as /proc. But I am not thinking about them, or just think of them as being built upon RAM, which is a block device, isn't it?

Tim
  • 101,790
  • Are you after a conceptual answer, or the answer based on the Linux implementation? – Stephen Kitt Sep 25 '18 at 16:43
  • Thanks for asking. Actually both. If not possible, either is fine. I prefer Linux for more practical reason. But I like to be clear at concept level in the first place. – Tim Sep 25 '18 at 16:44
  • 1
    This question rather presumes the falsehood that all Unix and Linux operating systems have block devices. https://unix.stackexchange.com/questions/89887/ https://unix.stackexchange.com/questions/259193/ – JdeBP Sep 25 '18 at 16:45

1 Answers1

3

File systems in general are built on block devices, unless they are used as an interface to the kernel or access files across the network or are implemented in user space. If you want to store files on a hard disk or ssd, accessing it as a block device is the easiest way. There exist file systems like SquashFS that don't align data on block boundaries, but they still use the underlying buffer cache that works on block devices. Some Unix systems present character devices to access the disk without using the buffer cache, on Linux open with the O_DIRECT flag is used for this.

You can use a file as a block device, see losetup.

A file system is not a block device.

Edit

To answer a question form the comments about file systems not on block devices

  • "an interface to the kernel": This is mainly /proc, /sysbut also a bunch of cgroup file systems, usually mounted under /sys/fs/cgroup, and some more.
  • "access files across the network": NFS (usually on Unix/Linux), SMB/CIFS (Windows) and others
  • "implemented in user space": "FUSE" means "Filesystem in Userspace". From the kernel's point of view, this is backed by a userspace program. This program may in turn use a block device (fuseblk), NTFS is implemented with fuseblk. It may also use the network or anything else to present a file system.
RalfFriedl
  • 8,981
  • Thanks. "they are used as an interface to the kernel or access files across the network or are implemented in user space". Can you give examples for the three cases? – Tim Oct 05 '18 at 03:12