gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] Device numbers for non-linux systems


From: Eric S. Raymond
Subject: [gpsd-dev] Device numbers for non-linux systems
Date: Fri, 23 Jan 2015 10:23:01 -0500 (EST)

The adaptive-delay code means the sourcetype() function in serial.c
can no longer be a Linux-only thing.  Hunting around in the NetBSD 
sources I found

#
# MI major assignments for standard devices
#
device-major    cons            char 240
device-major    ctty            char 241
device-major    mem             char 242
device-major    swap            char 243   block 1      vmswap
device-major    pts             char 244                pty
device-major    ptc             char 245                pty
device-major    log             char 246
device-major    filedesc        char 247
device-major    rnd             char 248                rnd
device-major    clockctl        char 249                clockctl
device-major    sysmon          char 250                sysmon_envsys | 
sysmon_wdog
device-major    ksyms           char 251                ksyms

#
# MI major assignments for tty(*) devices
#

device-major    com             char 260                com
device-major    lpt             char 261                lpt
device-major    cy              char 262                cy
device-major    cz              char 263                cz


#
# MI major assignments for USB devices
#
device-major    usb             char 220                usb
device-major    uhid            char 221                uhid
device-major    ulpt            char 222                ulpt
device-major    ugen            char 223                ugen
device-major    ucom            char 224                ucom
device-major    urio            char 225                urio
device-major    uscanner        char 226                uscanner

Which suggests code something like this:

#ifdef __netbsd__
        /*
         * NetBSD device numbers live in 
         * /usr/src/sys/conf/majors 
         */
        int devmajor = major(sb.st_rdev);
        else if (devmajor == 220)
            devtype = source_usb;
        else if (devmajor == 244 || devmajor == 245)
            devtype = source_pty;
#endif /* __netbsd__ */

But this needs work.  First, I don't know which of the tty* device
types corresponds to a vanilla tty.  Secondly, if there is a generated
header that makes the names available it would be vastly preferable
to write this:

#ifdef __netbsd__
        /*
         * NetBSD device numbers live in 
         * /usr/src/sys/conf/majors 
         */
        int devmajor = major(sb.st_rdev);
        else if (devmajor == usb)
            devtype = source_usb;
        else if (devmajor == pts || devmajor == ptc)
            devtype = source_pty;
#endif /* __netbsd__ */

in case the assigned numbers change.
-- 
                <a href="http://www.catb.org/~esr/";>Eric S. Raymond</a>

There's a truism that the road to Hell is often paved with good intentions.
The corollary is that evil is best known not by its motives but by its
*methods*.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]