proposal for generic interface to /proc text files

Daniel Quinlan (quinlan@proton.pathname.com)
Sat, 28 Sep 96 19:13 PDT


This is a proposal for a generic interface for text files in /proc.
It is designed to be easy to parse with most languages as well as
humans. It is also designed to be extensible, modular, etc.

This issue of particular interest of me since it is related to the
filesystem interface of Linux and also because I'm to blame for the
proc(5) manual page (where I became disgusted with the inconsistency
in the /proc interface).

This could be implemented in the 2.1 experimental series. A patch to
update /proc to use this proposal would be very easy. Most files
would only require minimal modification. Cleaning this up now, while
some files in /proc are not actually used by programs would be better
than waiting until later when more files are in use.

Records
Text files in /proc are composed of "records". The end of a record
is indicated by a newline. Most files will have only one record,
but some may have multiple records, such as cpuinfo on SMP
machines and the device list in /proc/pci. The terminal newline is
omitted from the last record in any file.

Fields
Records are composed of "fields", which are delimited by a newline.
Mulitiple line fields may be continued past a single line by
preceding each additional line with a tab. (The last field in a
record is followed by a newline. If there is another record in
the file, there is another newline, creating a blank line to
separate different records.)

Subfields
Each field is composed of "subfields". Subfields are delimited by
a single space. Subfields should not be justified or padded with any
extra whitespace. These characters should probably be prohibited
from records: tab, backslash, and space, single quote, double
quote, and apostrophe. I'd like to recommend lowercase letters
(in the Unix tradition), but don't feel it would be smart to
prohibit uppercase letters.

Numeric subfields
We need to decide on a common format for different types of numeric
fields (common for instances of a type, not for all types). Memory
addresses should all be in hex format (0x0123), ranges should be
expressed as [number]-[number], IP numbers should be in a
consistent format (not necessarily hex), etc.

Labels
The first subfield in any field is a "label" if there are multiple
fields in the record. Labels are followed by a colon character,
which is not separated from the text of the label by any whitespace.

Comments
Including comments or extra unnecessary information in text /proc
files are discouraged. Please update the proc(5) manual page as
necessary.

Here are some examples:

/proc/cpuinfo on a dual Pentium:

(this is quite fictional since I don't own a dual Pentium)

------- start of file --------------
processor: 0
cpu: 586
model: Pentium75+
vendor_id: GenuineIntel
stepping: 4
fdiv_bug: no
hlt_bug: no
fpu: yes
fpu_exception: yes
cpuid: yes
wp: yes
flags: fpu vme de pse tsc msr mce cx8
bogomips: 35.94

processor: 1
cpu: 586
model: Pentium75+
vendor_id: GenuineIntel
stepping: 4
fdiv_bug: no
hlt_bug: no
fpu: yes
fpu_exception: yes
cpuid: yes
wp: yes
flags: fpu vme de pse tsc msr mce cx8
bogomips: 35.94
------- end of file ----------------

Another example, /proc/devices:

------- start of file --------------
type: character
1: mem
2: pty
3: ttyp
4: ttyp
5: cua
6: lp
7: vcs
14: sound

type: block
2: fd
3: ide0
8: sd
------- end of file ----------------

or /proc/devices could also be implemented like this:

(this is probably a better implementation, using a single record)

------- start of file --------------
mem: c 1
pty: c 2
ttyp: c 3
ttyp: c 4
cua: c 5
lp: c 6
vcs: c 7
sound: c 14
fd: b 2
ide0: b 3
sd: b 8
------- end of file ----------------

-- 
Daniel Quinlan                  http://www.pathname.com/~quinlan/
quinlan@pathname.com