[X-Unix] /dev basics

Jon Allen Boone ipmonger at delamancha.org
Mon May 9 05:19:41 PDT 2005


The directory that Linux installations use that contains a lot of  
information is /proc [as in the process filesystem] -- it contains  
info on bus devices, memory, cpu, etc., as well as providing a means  
for accessing the open files of a running process by ID.

On May 09, 2005, at 02:45, Kuestner, Bjoern wrote:

> Different devices:
>
> - No hd*, disk0s[1-9] instead, disk0 exists
> - tty[p-w]* instead of tty[C,D,X,S,R]*
> - bpf, console, cu.modem, fd, fsevents, klog, kmem, mem, vn* exist

   The names of devices in /dev typically give you some clue as to  
how the system views the devices themselves.

   For example, Linux uses /dev/hd* for IDE disk drives, but used / 
dev/sd* for both SCSI disks and for accessing IDE drives in SCSI  
emulation mode.  The first IDE disk is a, the next is b, and so on.   
But, since IDE buses are limited to 2 drives per bus, the first bus  
has a/b [if either exists], while the second bus has c/d [if either  
exists], the 3rd bus has e/f, etc.  So, with /dev/hd?, you know that  
you are accessing a particular drive on a particular bus.  Finally,  
partitions are numeric in nature, with 1-4 being primary partitions  
and 5-??? being "logical" partitions.  All of this is due to the  
origins of Linux as an x86-based OS.

   Under OS X, the presentation of volumes is more elegant.  All  
media, regardless of type, appears as a /dev/disk*  The number of the  
disk is dependent on the order in which the device was "discovered"  
by the kernel.  So, in a single hard-drive installation [which is  
typical of consumer machines and laptops], you have a disk0 only  
[until you insert a CD-ROM, or plug in a FW/USB drive].  For example,  
here's my 17" PB with 3 drives attached:

-ipmonger at amicus.delamancha.org:~ 21% df
/dev/disk0s3        /
/dev/disk1s1s2       /Volumes/hp aio installer
/dev/disk2s3         /Volumes/Panther Boot
/dev/disk2s5         /Volumes/FW Data Drive 1

   There's no need for the application to care about the fact that  
disk0 is an IDE drive, while disk1 is a CD-ROm and disk2 is a FW HD.

   These are fundamental differences in system design, which is not  
atypical for unices.  Each vendor decides what they think is the  
"best" way to handle these issues and makes the appropriate  
modifications to their system.

> But more generally I considered the /dev directory something that's  
> very
> close to the kernel. And isn't that where OS X differs a good bit  
> from the
> rest?

   /dev is a "unix thing".  Anyone who's presenting a Unix interface  
would implement /dev, albeit with some differences between  
implementations.  For a truly radical understanding of what Mach  
allows, you should consider that it's possible to present an  
*alternate* view of the devices via a different interface.  When DEC  
was all gung ho about working with Microsoft back in 1992, there was  
talk of using Mach as the kernel, with a Unix-style, a VMS-style and  
Windows-style interface to the system.

   Of course, for an actual extant system, you should google on  
"Perq" --- a workstation produced by Three Rivers Systems in the late  
1980s/early 1990s.  It used Mach as the core of it's kernel and  
presented multiple interface views to the user, one of which was a  
Lisp-workstation.

> I just find it awkward to rely on information which might look  
> similar but
> actually isn't.

   You should learn the system you're using.  That's the key to doing  
system administration effectively.

>> Would somebody please give an intro to what what can be learnt  
>> about the
>> system by looking at the /dev directory?
>>
>
> What are the tools for instance to read information from /dev  
> beyond "ls"?
> "cat disk0" for instance has some output but not very valuable it  
> seems.
> What tools are fit to explore and learn about /dev entries?

   You should not be accessing /dev entries directly using cli tools  
[except possibly dd/diskutil for copying].  The Unix API gives you  
the proper interfaces for dealing with devices in a consistent fashion.

> I simply could not find any info page about /dev in OS X. I tried  
> Google.
> But something like "os x cu.modem fsevents klog kmem" or "os x '/dev'
> -developer" is about as explicit as my Google-skills go, and it still
> doesn't turn out with anything useful.

   That's because the relevant information is more likely to be found  
on the Apple developer site:  http://developer.apple.com

--jon



More information about the X-Unix mailing list