Linux – the TTY major number of your Unix

bsdlinuxserial portsolaristty

I'm currently working on a serial port library which already uses special frameworks to get information about serial ports on the system. Though serial ports are a fundamental design in Unix—as an answer such as this one proves—I thought that a good way to test whether a file is a serial port is by testing the major mode of the character device
and check whether this is actually a TTY or not.

Crawling on Internet, I could not find any documentation talking about the major modes of TTYs across unices. Well, there's only one Linux man page stating that ptmx has major mode 5.

Though I already asked about the implementation details of tty character device based on this Stack Overflow
question, I thought I might ask the Unix Stack Exchange community to find out how stable the tty values are across Unix flavors.

So, I'm asking your help to build a knowledge base of the Major mode of all your tty
files on your system(s), i.e.: what's the major mode of

  • real serial ports?
  • pseudo terminal (PTS) ports?
  • FTDI USB Serial ports?
  • other USB Serial ports?

To get the values for major mode of a character device, you shall look using:

% stat -f " * %N: %Hr%n" /dev/tty* /dev/pts/*
 * /dev/ttys001: 16
                 ^^- major mode

or using good old ls:

% ls -l /dev/ttys001
crw--w----  1 <user>  tty   16,   1 Apr 30 03:25 /dev/ttys001
                major mode -^^   ^^- minor mode

You can put information in answer of your own, or extend the community wiki answer with additional information.

Best Answer

Unix version 7 (1979):

# ls -l /dev/console /dev/tty?*
crw--w--w- 1 root    0,  0 Sep 22 06:46 /dev/console
crw-rw-r-- 1 root    0,  1 Sep 22 05:47 /dev/tty1
crw-rw-r-- 1 root    0,  2 Sep 22 05:47 /dev/tty2

(no pty there yet)

Linux 3.2.0 (debian wheezy).

Note: you can also find these by searching /dev for owned by group tty and dialout. That's a Debian thing.

  • Virtual consoles
    • /dev/tty[0-9]*: 4
  • Real serial ports:
    • /dev/ttyS[0-9]+: 4
  • Pseudo terminals:
    • /dev/pts/[0-9]+: 136
    • /dev/pts/ptmx: 5
  • FTDI USB serial port:
    • /dev/ttyUSB[0-9]+: 188
  • USB serial port: (AVR embedded USB/Arduino Uno)
    • /dev/ttyACM[0-9]+: 166

Linux 3.4.0 (Android 4.4.2 / Nexus 5)

Note: has all linux ones plus:

  • ttyACM (cell modem control)
    • (no /dev entry, apparently): 166
  • ttyHSL (Bluetooth)
    • /dev/ttyHSL0: 247
  • ttyHS (Bluetooth)
    • /dev/ttyHS99: 248

Darwin 13.1.0 (MacOS 10.9.2):

  • Real serial ports:
    • /dev/ttys[0-9a-f]: 4
  • Pseudo terminals:
    • /dev/ttys[0-9]{3}: 16
  • FTDI USB serial port:
    • /dev/tty.usbserial.*: 18
  • USB serial port: (AVR embedded USB/Arduino Uno)
    • /dev/tty.usbmodem.*: 18

Solaris 10 x86/amd64:

  • Pseudo terminals:

    • /dev/pty[p-r][0-9a-f] (pty master): 25
    • /dev/tty[p-r][0-9a-f] (pty slave): 26
    • /dev/pts/[0-9]+: 24
    • /dev/ptmx: 23
  • Serial devices:

    • /dev/tty[abc...] aka /dev/term/[abc...] or /dev/tty0[012..] (uart serial, also ): 106
    • also as /dev/ttyd[012...] but with different interface (dial, modem) also on 106 but high minors.

OpenBSD 6.0

As documented in the commentary in /dev/MAKEDEV

  • PC/AT UART serial ports:
    • /dev/tty[0-7][0-9a-f]: 8
    • /dev/cua[0-7][0-9a-f]: 8
  • Cyclades serial ports:
    • /dev/ttyc*: 38
    • /dev/cuac*: 38
  • Virtio serial ports:
    • /dev/ttyVI*: 94
  • USB serial ports:
    • /dev/ttyU[0-3]: 66
    • /dev/cuaU[0-3]: 66
  • wscons terminals:
    • /dev/tty[C-J][0-b]: 12
  • Pseudo terminal master and slave (non-UNIX 98)
    • /dev/pty[p-zP-T][0-9a-zA-Z]: 6
    • /dev/tty[p-zP-T][0-9a-zA-Z]: 5

FreeBSD 10.0 and TrueOS

FreeBSD (and its derivatives such as TrueOS) is where your idea shows a fatal flaw. There is no major+minor device number scheme in FreeBSD.

The devfs pseudo-filesystem on FreeBSD, conventionally mounted at /dev, does not use a major+minor system for grouping devices into "major" classes at all. Rather, the rdev for the device is the same as its i-node number in the pseudo-filesystem, with i-nodes simply assigned in ascending order as device nodes are generated, depending from the exact hardware on the machine at hand at the time.

So device number cannot be used as a shortcut for isatty().

Related Question