Background
There are lots types of special files in Unix, for example symlinks, device files and proc files (under /proc
). /proc
files are just normal files or even text files. But for the rest, I only know how to use them, but I don't know their internal structure and what they are (in depth). And unfortunately, all the ways to access files can only get the object which they represent. In other words there is no way to get the internal representation.
Questions
For symlinks, there is no doubt that there is a string which store the paths of their targets. However, if there is only a string, how can they be distinguished from plaintext files? If there is a special header which is specified by filesystem drivers, what is it? Is there any convention? Can anyone tell me what the binary representation of a symlink pointing at /usr/bin/bash
is?
For device files (nodes), what are their binary structure and representation? According to their behaviors, they must include information about relevant interface number and drivers. But this will make their size vary greatly. Can anyone explain this at a binary level?
For compatibility of symlinks and device file (I know it is impossible for a same device file to work in two different environment, but we can use our imagination to make an experiment) is the binary content of these files strongly dependent on file system type and the kernel of the operating system? For example, if I copy (not via cp
command, just write identical binary content) to a different file system (like from ext4 to xfs), is this file (symlink or device file) still valid and functional? How about when copying it from a Linux machine to a BSD machine?
Or are they not files, and just special records in file system header part?