0

My question is related to the way device nodes are implemented in Linux. I know there are pseudo files systems like udev or devtmpfs available - in this case there is no real storage behind and the file system is an illusion presented to applications by kernel drivers. However, my questions remain valid for:

  1. The way /dev is visible to user space in case devtmpfs or udev is used.
  2. The case where /dev is a regular directory containing manually created device nodes.

The questions are:

  1. Are device nodes files stored in file systems (inodes used) or are they just special entries in directories?
  2. If they are stored as files, how are they distinguished from binary files? Do device nodes have special magic number assigned?
mrn
  • 149

1 Answers1

1
  1. In the POSIX model, all files use an inode, regardless of their type. A directory entry is only a name pointing to an inode; file type, permissions etc. are stored in the inode. So device nodes involve an inode too. You can see this by running ls -li /dev: each entry has a corresponding inode number.

  2. Device nodes are distinguished from other file types by their file type, stored in the inode; this is part of the file mode. All the different file types (see Understanding UNIX permissions and file types) have “magic” numbers associated with them.

Stephen Kitt
  • 434,908