11

I'm trying to learn the POSIX standard. When using Unix, I have /bin, /etc, /dev, /media, and usually /opt, but is that standardized or up to your spec implementation? Could there be many directories in the root, or is it limited by the standard?

  • 3
    POSIX doesn't touch on this area. – Thomas Dickey Jul 14 '16 at 23:43
16

According to The Open Group's published standard, the only required directories are:

  • /
  • /dev, which contains console, null, and tty
  • /tmp, guaranteed writable but not necessarily preserved.

The Linux Foundation maintains a Filesystem Hierarchy Standard (FHS) which extends this to include the directories you will typically see on a Linux system:

  • /bin: Essential user command binaries
  • /boot: Static files of the bootloader
  • /dev: Device files
  • /etc: Host-specific system configuration
  • /home: User home directories (optional)
  • /lib: Essential shared libraries and kernel modules
  • /lib<qual>: Alternate format essential shared libraries (optional)
  • /media: Mount point for removable media
  • /mnt: Mount point for a temporarily mounted filesystem
  • /opt: Add-on application software packages
  • /root: Home directory for the root user (optional)
  • /run: Run-time variable data
  • /sbin: System binaries
  • /srv: Data for services provided by this system
  • /tmp: Temporary files
  • As well as the /usr hierarchy and the /var hierarchy

The FHS was designed to be as generic as possible, to allow for incorporation in any UNIX system. The additional directories are likely to exist in any reasonable system, but this is not mandated by POSIX.

However, note that The Open Group also states that

Strictly conforming applications shall not assume the ability to create files in any of these directories, unless specified below.

Since directories are really just files, this implies that a strictly conforming application will not create any files or directories at the root level. Therefore, POSIX does not necessarily limit what a distribution may place at the root level, but does seem to state that an application conforming to its specification cannot assume that it will be able to.

  • 5
    The question wasn't which directories are standard, but asked if there was a limit. POSIX doesn't answer that question. – Thomas Dickey Jul 15 '16 at 0:07
  • It adds an opinion without pointing to a quote from POSIX. – Thomas Dickey Jul 15 '16 at 0:14
  • The last paragraph is what I referred to: "does seem to state". POSIX avoids mentioning a limit in this area, focusing on commonality rather than differences. – Thomas Dickey Jul 15 '16 at 0:29
  • 1
    Thank you Fox. Your answer was the information I was looking for. – Niklas Rosencrantz Jul 15 '16 at 0:40
13

In 10.1 Directory Structure and Files, POSIX lists directories which must exist. But it specifies no limit on the number of other directories which can exist at the root-level of a filesystem.

For that matter, it does not appear to place limits on the size of other directories.

POSIX's attention in this area is focused on commonality rather than differences.

  • As on a *nix system potentially every directory (including /) can be a root directory, it would be pretty silly to impose an upper limit on the number of entries in a root directory. / isn't particularly special in this regard, thus it follows that it would be pretty equally silly to impose an upper limit on the number of entries in / specifically. – a CVn Jul 15 '16 at 13:35
8

There is no limitation to the number of entries in a directory, either in POSIX or in typical Unix implementations. There may be an indirect limit for the number of subdirectories, which is the maximum hard link count (each subdirectory's .. entry is a hard link to the directory); that's 216 for many common filesystems, which limits a directory to 65533 subdirectories (at least for those filesystems that store .. entries explicitly). You'll start hitting poor performance before that. According to POSIX, an implementation is allowed to support only 8 hard links on a file (_POSIX_LINK_MAX), but no actual implementation is limited to 6 subdirectories. And anyway, on many filesystems, including ext4, the hard link count is not maintained for .. entries, so the only limit is how much space or how many inodes are available on the filesystem.

POSIX doesn't say much about the organization of files on the system. It only mandates the existence of a few files. The only mandatory entries in the root directory are /dev and /tmp. Other habitual Unix entries such as /usr, /var, /bin, /etc, /lib, /home, etc. are Unix conventions that are not codified by POSIX.

On Linux, the FHS codifies the classics and a couple more. Most Linux distributions stick to the FHS entries. Other Unix systems typically have mostly the same entries, maybe with a few differences, but the number is about the same.

System administrators may create more, although this is discouraged: there are well-defined places for most things (software goes under /usr or /opt, system data goes under /var, user data goes under /net, mount points go under /media or /mnt, etc.), so there is rarely any good reason to create new directories at the top level.

  • This is not correct. Most "reasonable" filesystems have a maximum number of subdirectories per directory, or a maximum number of inodes per device. However, it is usually obscenely large relative to the number of directories you're likely to see in the root of the drive. – Kevin Jul 15 '16 at 6:36
  • @Kevin Oh, good point, on common filesystems you'd hit the maximum hard link count first, and that could be as low as 16 bits. – Gilles Jul 15 '16 at 14:03
  • @Kevin Though this is not the case on ext4, there doesn't appear to be a limit on the number of subdirectories other than available space (blocks or inodes). Were you thinking of some other limit on the number of subdirectories per directory? – Gilles Jul 15 '16 at 14:11
  • A properly designed filesystem does not create hard links to the .. directory entries. In a properly designed filesystem the link count of a directory is 1 unless there are manually created hard links. – schily Jul 15 '16 at 15:15
  • 1
    No, there is no such limit on a 100% POSIX compliant filesystem. As mentioned already, POSIX does not require . and .. to be hardlinks to other directories. If they are, this is an implementation detail that is a result of the hacks introduced in the V7 filesystem. There are other POSIX compliant filesystems that work completely different. – schily Jul 18 '16 at 9:43
2

unlike FAT the filesystems used by UNIX don't have a special size limit on the root directory, but once the partition is full you won't be able to add more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.