code: purgatorio

ref: 248c637d25154f762a7d675662c405a169594ca0
dir: /doc/

View raw version
.\"<-xtx-*> tbl | troff -ms | lp -d stdout
.FP palatino
.ps 9
.nr PS 9
.vs 11
.nr VS 11
.nr dP 1
.nr dV 1p
.nr dT 4m
.nr XT 4
System and Interface Changes to Inferno
C H Forsyth
Vita Nuova
9 June 2003
This paper describes some of the changes made to Inferno
interfaces as they stood in the published Third Edition manuals,
to form the current Fourth Edition of the system,
and the broad effects on internal and external interfaces.
Changes include: extensions to the Limbo language;
new instructions in Dis and the virtual machine; extra content
in Dis object files; structure of the source tree; configuration of
.CW emu ;
replacement of the window system with changes to the client interface;
commands renamed, replaced, and removed;
revised support for network booting;
9P2000 becomes the basis for Styx;
a graphics model offering alpha-blended compositing and general pixel structure;
and improvements to Tk.
.NH 1
Exceptions and fixed point have been added to the Limbo language.
They are described in more detail in separate notes by John Firth,
shortly to be available on the Vita Nuova web site
.CW .
Channels can now be buffered.
A form of polymorphism is now available in Limbo.
.NH 2
Discussion of exceptions will be restricted here to implications for existing source code.
The most obvious changes are that
.CW Sys->rescue ,
.CW Sys->rescued ,
.CW Sys->unrescue
.CW Sys->raise
have vanished.
Instead the exception handling is expressed using constructions in the Limbo language.
Named exceptions can be declared and used (these are described in the note by Firth), and
they are declared as part of the type of functions that raise them.
There is also a general `failure' exception that effectively subsumes the old
.CW Sys->rescue
scheme, including run-time errors such as `out of memory' that can happen in almost any function.
Unlike named exceptions a `failure' exception can be raised or caught by any function,
and its value is a string.
.CW raise
statement raises an exception.
This is most obvious in commands that wish to produce an `exit status'.
Instead of
one must now write
raise "fail:usage";
(That is one of the more common source changes required to Third Edition Limbo commands,
since that was the most common use of exceptions before.)
A block can have an
.CW exception
	a := array[128] of byte;
} exception e {
"out of memory:*" =>
	sys->print("i need more space: %s\en", e);
"fail:*" =>
	sys->print("exit status: %s\en", e);
"*" =>
	sys->print("unexpected error: %s\en", e);
	raise;	# propagate it
If an exception is raised during the execution of the block (including functions it calls),
execution of the block is abandoned, and control transfers to the appropriate exception handler
(which is outside the block).
Because the compiler and run-time system know the scope of the exception,
values such as
.CW a
above are correctly reclaimed on exit from the faulty block.
Unhandled failures are propagated to callers; unhandled named exceptions (currently) become failures.
A process group can cause unhandled exceptions in any process in the group either to
propagate to all members of the group, or to be propagated to the process group leader
after destroying the other processes in the group.
This makes it easier to program recovery from exceptions within a group of concurrent processes.
For instance, if a process is expected to send to another on a channel, but fails unexpectedly instead
(eg, because memory was exhausted),
instead of leaving the intended recipient blocked on a receive operation, it can be sent
an exception to notify it of the failure of the other process, allowing it to take appropriate recovery action.
(This could sometimes be programmed using the
.CW wait
file of
.I prog (3),
but not always.)
Exception handling is intended for recovering from disaster.
We still think it is better Limbo style
to use tuples, channels and processes to make ordinary error handling explicit.
The few attempts to use failure exceptions to achieve `pretty' but peculiar control flow have had exactly the usual
effect of making the code hard to follow and error-prone.
.NH 2
Buffered channels have been added:
c := chan [N] of int;
.I N
is an integer value,
creates a channel that will allow up to
.I N
integer values to be sent to it without an intervening receive without blocking the sender.
.I N
is zero, the channel is unbuffered, equivalent to plain
.CW "chan of int" ,
and synchronises sender and receiver as before.
The restriction that a given channel value could not be sent to or received from in two
.CW alt
statements simultaneously has been removed.
.NH 2
John Firth has implemented a form of parametric polymorphism in Limbo.
It too will be described in a separate note.
Currently we are still fussing over aspects of the constraint syntax
and some other implications of the most general form, and since some aspects are
therefore subject to change, including syntax, we have not yet published the details.
We think it is possible to use the following subset without having to change the code later:
.IP 1.
Function declarations can be parametrised by one or more type variables:
For example:
reverse[T](l: list of T): list of T
	rl: list of T;
	for(; l != nil; l = tl l)
		rl = hd l :: rl;
	return rl;
Such a function can then be invoked on any compatible set of values.
The function invocation does not specify the type (the compiler does type unification on the parameters).
Thus the above can be used as:
l1: list of string;
l2: list of ref Item;
l3: list of list of string;
l1 = reverse(l1);
l2 = reverse(l2);
l3 = reverse(l3);
.IP 2.
ADTs can also be parametrised:
Tree: adt[T] {
	v: T;
	l, r: cyclic ref Tree[T];
allowing declaration of
.CW "Tree[ref Item]"
.CW "Tree[string]"
for instance.
.IP 3.
Values of the parametrised type can only be declared, assigned, passed as parameters, returned,
or sent down channels.
The only types that can be used as actual parameter types are reference types (ie,
.CW ref " ADT,"
.CW array ,
.CW chan ,
.CW list
.CW module ),
.CW string
(which is a value type but is implemented using a reference).
At some point we shall allow a function such as
.CW reverse
above to be invoked with any compatible type (not just reference types) but
that requires changes to Dis and the virtual machine not yet made.
The formal type parameters can be further constrained by listing a set
of operations that they must have (which currently implies the actual parameters
must be ADT types with compatible operations).
We are not completely happy with the current constraint syntax, and some other
aspects of the scheme, and so that
be described here later once we have settled it.
.NH 1
Dis and virtual machine
To make the Limbo changes and extensions some new operators were added to
the virtual machine.
(We also added a
.CW casel
operator to allow
.CW case
statements to work on
.CW big
Modules that have exception handlers also have a (new) exception table,
added to the Dis object format.
Furthermore, we moved the import table used by the
.CW load
operator out of the Dis data space into the object format
(which also makes it available for inspection by
.CW wm/rt
amongst others).
There is now an internal interface to set conditions under
which modules must be signed to be loaded, and to check a signature on a module.
Appropriate stubs are defined when module signing is not configured; if
.I sign (3)
is configured, however, it replaces them by ones that enforce its signing policy.
.NH 1
Window manager
The window manager
.I wm (1)
has been reimplemented by Roger Peppe.
It now multiplexes pointer and keyboard input to applications,
and manages windows on the display.
.I Tk (2)
no longer manages windows from inside the kernel.
In some ways the structure is closer to that of
.I mux (1)
and more specifically the design described in Rob Pike's paper ``A Concurrent Window System''.
It is possible to import and export window system environments between hosts.
This is one of the bigger causes of source file changes, although many of them
can be done by global substitutions (eg, using
.I acme (1)).
Appendix A gives details.
.CW Wmlib
is no longer the application's interface to the window system.
Instead that is done through a new
.CW Tkclient
module; see
.I tkclient (2).
(It uses a different
.CW Wmlib
as an auxiliary module,
and also uses a new
.CW Titlebar
module to allow the look of the window decoration to be changed more easily).
An application acquires a window by a call to
.CW Tkclient->toplevel ;
starts pointer or keyboard input if desired by calling
.CW Tkclient->startinput ;
and puts the window on screen (after sending it Tk configuration commands)
.CW Tkclient->onscreen .
Nothing appears on screen until that is called (which amongst other things avoids the resizing on start up that afflicted
the original scheme).
.CW Onscreen
gives it a connection to the window manager for pointer, keyboard and control input,
with a separate channel for each.
When it receives data from any of the channels
(typically using
.CW alt )
it must pass it to Tk using calls to appropriate
.CW Tkclient
The toolbar used by the old
.I wm
is now provided by a separate program
.CW wm/toolbar
.I toolbar (1)),
and it is
.CW toolbar
that interprets the
.CW /lib/wmsetup
.CW Wm
.CW wm/toolbar
by default so most users will see no difference, but it does make it easier to develop alternative interfaces.
More visible is that
.CW wm/logon
is now a
.I client
of the window manager, and must be invoked as follows:
wm/wm wm/logon
Applications need not even use
.I tk (2).
There is an interface for
.CW draw -only
.I wmclient (2).
.NH 1
Inferno source tree
The structure of the Inferno source tree has changed in the following ways.
.NH 2
Library source
.CW image
.CW memimage
directories have gone, replaced by
.CW libdraw
.CW libmemdraw .
The directories in the Inferno root that contain the source for libraries
always have names starting `\f5lib\f1':
.CW libcrypt ,
.CW libinterp ,
.CW libkeyring ,
.CW libmath ,
.NH 2
Emu source
.CW emu
directory now contains a subdirectory structure similar to the
.CW os
kernels, and uses a similar configuration file (parts list) to say what goes in
a given instance of
.CW emu .
This allows platform-dependent selection of drivers, libraries and even
.CW #/
.I root (3))
contents to be done easily.
The top directory,
.CW /emu ,
.CW mkfile
that simply moves to the platform configured by
.CW /mkconfig ,
allowing builds in the Inferno root as before;
a subdirectory
.CW port
containing portable code (including some code shared by several platforms, such as
.CW devfs-posix.c );
and a subdirectory for each hosting platform, distinguished by an upper-case initial letter.
Current platforms include
.CW FreeBSD ,
.CW Irix ,
.CW Linux ,
.CW Nt
(for all Windows platforms after 95),
.CW Plan9 ,
.CW Solaris ,
and several others.
.NH 2
Emu configuration
Each platform-specific directory contains a configuration file with the
same structure and indeed similar contents to the ones used for the native kernel.
The default configuration file is called
.CW emu .
Another can be chosen, again in a similar way to the native kernel, by using
mk 'CONF=\fIcfile\fP'
.I cfile
is the name of the configuration file.
The name of the resulting executable file contains the configuration file name but depends on the platform:
it is \fIcfile\fP\f5.exe\fP on Windows, \f5o.\fP\fIcfile\fP on Unix systems, and \f58.\fP\fIcfile\fP on 386 Plan 9 systems.
The configuration file format and contents is documented for all types of kernels by
.I conf (10.6).
.NH 2
Tk source
The Tk implementation in
.CW libtk
has been made more modular.
It allows a significantly different `style' to be implemented,
and although that is by no means trivial to do, there is at least an interface to do it.
We hope to change various aspects of the standard style further, but that has not yet been done.
.NH 1
Commands and modules
There are new commands and library modules, others have become obsolete and been removed,
and a few existing ones have been given new names (typically when ones with similar function have been
collected together).
The biggest change has been to
.I wm (1),
which retains the same name but slightly different invocation and completely different
as discussed above.
Here I shall simply note the bigger changes, rather than discuss new functionality.
.NH 2
Renamed commands
As part of a mild reorganisation of the
.CW /appl
.CW /dis
trees, we have moved commands out of
.CW /dis/lib
so that it now contains only library modules except for a few commands left
there temporarily for compatibility.
Commands themselves have sometimes been shuffled to subdirectories,
often copying seemingly better structure from Plan 9,
so that authentication commands are
.CW auth/ ...,
naming service commands are
.CW ndb/ ...,
IP-specific commands are
.CW ip/ "... ."
One noticeable change is that
.CW lib/cs
is now
.CW ndb/cs .
More dramatically, the command
.CW lib/srv
.I srv (8))
has been replaced by
.I sh (1)
scripts, all described by
.I svc (8),
that contain appropriate calls to
.I listen (1)
after setting up any locally-desired environment.
Other commands have also moved:
.IP •
.CW lib/plumber
is now simply
.CW plumber
.IP •
.CW lib/bootp
.CW lib/tfptd
have become
.CW ip/bootpd
.CW ip/tftpd ,
documented in
.I bootpd (8)
.IP •
.CW lib/virgild
has become
.CW ip/virgild
.I virgild (8))
.IP •
.CW lib/chatsrv ,
.CW lib/rdbgsrv
.CW cpuslave
have moved to
.CW auxi
.CW /dis/auxi
.CW /appl/cmd/auxi)
.IP •
.CW csquery
has become
.CW ndb/csquery
.NH 2
New or newly-documented commands
.IP •
an authentication server (signer) can use
.I keyfs (4)
to store its keys securely in the encrypted file
.CW /keydb/keys
(instead of the unencrypted
.CW /keydb/password ),
and run
.I keysrv (4)
to offer secure change of password remotely.
They are typically started, with other signing services, by
.CW svc/auth
described in
.I svc (8).
.IP •
.CW /dis/auth
.CW /appl/cmd/auth
contain commands related to authentication;
they rely on
.I keyfs (4)
in most cases.
The older ones that use
.CW /keydb/passwd
are still in
.CW /dis/lib
.CW /appl/lib
during the transition
.IP •
.I dns (8)
has replaced the
.CW lib/ipsrv
implementation of
.I srv (2);
when used, it must be started before
.CW ndb/cs .
.I Srv (2)
has reverted to being a hosted-only interface to the hosting system's native
DNS resolver.
It is automatically used by
.I cs (8)
if it cannot find
.I dns (8),
.I dns (8)
will also use it if available before consulting the DNS network.
.IP •
.I chgrp (1),
.I cpuview (1),
.I grid (1),
.I 9660srv (4),
.I cpuslave (4),
.I dossrv (4),
.I keyfs (4),
.I keysrv (4),
.I nsslave (4),
.I palmsrv (4),
.I registry (4),
.I rioimport ,
.I styxchat (1),
.I styxlisten ,
.I wmexport ,
.I wmimport ,
.I uniq (1)
are new
.IP •
the multiplayer games software previously in
.CW /appl/games
has been replaced by a related but significantly different system in
.CW /appl/spree .
(Also see
.I spree (2)
for supporting modules.)
.IP •
.I Registry (4)
provides dynamic registration and location of services using sets of attributes/value pairs,
through a name space.
.I Registries (2)
provides a convenient Limbo interface for registration and query.
.NH 2
Commands removed
.IP •
.CW lib/csget
.I cs (8)
for its replacement
.CW csquery )
.IP •
the undocumented and obsolete commands
.CW lib/isrv
.CW lib/istyxd
have been removed, since either the
.CW none
authentication protocol, or the
.CW -A
option to
.CW mount
can be used if no authentication is needed
.IP •
.CW lib/srv
has been replaced by
.I svc (8)
as mentioned above.
.IP •
.CW getenv
.CW setenv
have been removed since the Shell provides alternatives
.IP •
.CW wm/license
is no longer needed
.NH 2
New modules
There are library modules to support: registries and configuration files of attribute/value pairs;
Internet address parsing and manipulation; management of windows and subwindows (used by
.I wm (1)
itself); timers; Styx; Styx servers; exception handling; memory
and performance profiling; Freetype interface; parsing Palm databases; and navigating XML files (without reading them all into memory) and interpreting style sheets.
.NH 1
Styx was derived from the 9P protocol used by Plan 9 in 1995, with changes that reflected the requirements
of the Inferno project of the time, mainly by removing features that were thought too closely tied to the Plan 9
Some 9P messages were removed, particularly those
that incorporated details of the Plan 9 authentication methods;
Styx moved authentication outside the file service protocol.
Other changes eliminated file locking and append-only files.
Some restrictions that 9P imposed were retained, however, such as limiting file names to 27 bytes.
This last restriction is fine for synthetic network services, but
has been troublesome when trying to access Unix and Windows systems, amongst others.
A recent revision of 9P adds support for much longer file names
and takes the opportunity to improve other aspects of the protocol.
It also removes details of authentication algorithms from the protocol.
The Styx implementation now uses the new version of 9P as the default file service protocol.
(It is possible that for interoperation with older Inferno systems the system will be able to
interact with both old and new versions of Styx.)
.NH 2
Protocol changes
The messages
.CW Tauth
.CW Tversion
are new to Styx.
.CW Tversion
includes negotiation (at connection start) of the message size and protocol version;
it also introduces a new session.
.CW Tauth
obtains access to a special authentication file if the server requires
authentication within a Styx session.
.CW Tclone
has been replaced by a more elaborate form of
.CW Twalk
that allows zero to MAXWELEM (16) elements to be walked, perhaps to a new fid, in a single message,
returning a sequence of qid values in
.CW Rwalk .
(A clone is simply a walk of a fid to a new fid with zero elements.)
A walk of several elements can return partial results if the walk of the first element succeeds but
subsequent ones fail.
A partial walk leaves the state of the fids unchanged.
.CW Ropen
.CW Rcreate
return a suggested size for atomic I/O on the fid (0 means `not given').
All strings are variable length, and consequently
.CW Twstat
.CW Rstat
data is variable length and formatted differently.
Data returned from
.CW Tread
of a directory is similarly changed, because
directory entries are not fixed length.
.CW Tnop
has gone.
Tags remain 16-bit integers, but fids and counts
become 32-bit integers (mainly of interest to large systems),
and qids have a different structure.
Previously a qid was a pair of 32-bit integers, path and vers, where
path had the top bit set for a directory.
Now a qid is a triple: a 64-bit path, 32-bit vers, and 8-bit type.
The type is defined to be the top 8 bits of the file's mode.
The path does not have the top bit set for a directory, and indeed the
path value is not interpreted by the protocol.
There are now bits in the file mode for append-only and exclusive-use
files (new for Inferno), and for authentication files (new for both Plan 9 and Inferno).
The stat information includes the user name that last caused the file's mtime to be changed.
All strings in the protocol are variable length: file names, attach names, user names, and error text.
The message format on the wire is significantly different.
The message size is negotiated for a connection by
.CW Tversion ,
and messages can be large, allowing much more data to be sent in single
.CW Twrite
.CW Rread
The header includes a 32-bit message size, making it easy to find message boundaries without
parsing the contents.
Strings are
represented as a 16-bit size followed by the string's UTF-8 encoding (without zero byte).
R-messages do not carry a copy of the fid from the T-message.
Padding bytes have gone.
The order of some fields has changed of course to match message parameter changes.
Authentication of the connection itself, and optionally
establishing the keys for digesting and encryption,
is done before the protocol starts, in both Inferno and Plan 9.
Details will follow on the protocol for that, and Limbo interfaces.
For now, it can be assumed that the old authentication messages can still be used,
even after a more flexible protocol has been implemented.
.CW Tauth
can be used to authenticate particular accesses within such a session, but
implies trust by the server that the client system will not cheat its users.
(That trust is typically established by the connection level authentication which is needed
anyway for link encryption, and thus for single-user clients further authentication
seems extraneous in most cases.)
Most Inferno services that run as file servers within a system (eg,
.CW 9660srv )
will, like Plan 9's, reply to
.CW Tauth
with an
.CW Rerror
stating ``authentication not required''.
Access to them when exported is typically controlled as now by verifying the incoming connection.
.NH 2
Limbo interface changes
Because Limbo's interface to file service via
.CW Sys
and other modules uses Limbo
.CW string
for names, and that is inherently
variable length, there are no interface changes required for that aspect of the protocol change,
and consequently no source changes
(in contrast to the introduction of 9P2000 in C implementations).
Similarly the Inferno directory reading interfaces remain unchanged.
The `directory mode' bit previously called
is now called
It is used
.I only
.CW Dir.mode .
is no longer defined, partly because it was used both
.CW Dir.mode
.CW Qid.path ,
and the latter instances must change (discussed below).
There are bits (new to Inferno) for
(append-only file),
(exclusive-use file),
(authentication file).
The protocol can return the user name of the user that caused
.CW mtime
to be changed on a file; that is now available as
.CW Dir.muid .
The structure of
.CW Qid
has changed.
Previously a Qid had a 32-bit
.CW path
and a 32-bit version number,
.CW vers .
The top bit
.CW path
was set iff the Qid was that of a directory.
.CW path
is now 64 bits (which is
.CW big
in Limbo and
.CW vlong
in the kernel), and there is no longer the convention that the top bit of
.CW path
must be 1 for a directory.
Instead, there is a new, separate
.CW type
field (called
.CW qtype
in Limbo)
that has the value of the top 8 bits of the file's mode.
Each bit \f5DM\fIx\f1 in
.CW Dir.mode ,
has got a corresponding bit \f5QT\fIx\f1
.CW Qid.qtype :
The bit
.I must
be set in the
.CW Qid.qtype
for a directory, and only then.
There is an extra constant
that is defined to be zero, and is used for clarity when neither
is set.
In Styx file servers, changes are required to reflect the slightly different set of message types
and a few new parameters, but the main changes are:
handling zero or more name elements at once in
.CW Twalk
.CW Rwalk ;
.CW Dir.mode
the use of the new
.CW Qid.qtype
instead of
.CW Qid.path
(a little more effort);
and (typically) the insertion of casts to force
.CW Qid.path
.CW int
and thus ensure the use of 32-bit operations except where 64-bit paths really are needed
(hardly ever in synthetic file servers).
The new modules for use by file servers are discussed in the next section.
The revised definition of
.CW Twstat
.I stat (5),
and thus
.CW sys->wstat ,
provides for ``don't care'' values in
.CW Dir
that are tedious to provide directly; a new adt value
.CW Sys->nulldir
provides the right initial value for a
.CW Dir
which is then changed as needed for
.CW wstat .
.I "Examples"
Create a directory:
fd := sys->create(name, Sys->OREAD, Sys->CHDIR | 8r777);

fd := sys->create(name, Sys->OREAD, Sys->DMDIR | 8r777); # not CHDIR
Make Qids
for a file and a directory:
Qdir, Qdata: con iota;
qd := Sys->Qid(Sys->CHDIR | Qdir, 0);
qf := Sys->Qid(Qdata, 0);

Qdir, Qdata: con iota;
qd := Sys->Qid(big Qdir, 0, Sys->QTDIR);
qf := Sys->Qid(big Qdata, 0, Sys->QTFILE);
Test if a file is a directory:
isdir(d: Sys->Dir): int
	return (d.mode & Sys->CHDIR) != 0;
	return (d.qid.path & Sys->CHDIR) != 0;

isdir(d: Sys->Dir): int
	return (d.mode & Sys->DMDIR) != 0;
	return (d.qid.qtype & Sys->QTDIR) != 0;
If one wishes to have values
.CW big
only when required, one can write:
case int dir.qid.path {
Qdir =>
Qdata =>
Qctl =>
Of course with the Dis change mentioned above,
.CW case
can now be applied to
.CW big
values, so it is no longer necessary to add the cast (as it once was).
Even so, 32-bit operations are faster when they suffice.
.NH 2
Styx protocol in Limbo: Styx and Styxservers
A new module
.CW Styx ,
defined by
.CW styx.m ,
provides access to the Styx protocol messages, as variants of pick adts
.CW Tmsg
.CW Rmsg .
(There was an old, undocumented
.CW Styx
module but this new interface is completely different.)
It is used by several file servers, such as
.CW dossrv ,
.CW cdfs ,
and the new
.CW logfs .
See the attached manual page.
There are several implementations with the same signature, covering different
combinations of old and new Inferno and old and new protocols, through
the same interface.
There are slight differences in the application code for old and new
systems because of the changed
type and structure of
.CW Qid .
The versions that talk the old protocol need to store some internal state,
and are intended only to meet compatibility requirements during the transition.
Many file service applications, however, serve a simple name space,
requiring more than can be done with
.CW file2chan ,
but wishing some help in handling the protocol details.
Two new modules
.CW Styxservers
.CW Nametree
are provided to make such applications easier to write.
They are closely related and thus both modules are defined by
.CW styxservers.m .
.CW Styxservers
provides help in handling fids and interpreting the Styx requests for navigating a
name space, and provides a reasonable set of default actions,
allowing the application to focus on implementing
read and write access to the files in the name space.
It uses
.CW Styx
to talk to the Styx client on a connection.
It interacts with the application through a channel interface and
.CW Navigator
adt to navigate an abstract
representation of the application's name space.
The module can be used on its own, with the application doing the work
of replying to those queries itself, or it can get extra help in the common cases from
.CW Nametree .
.CW Nametree
provides a
.CW Tree
adt and operations for the application to build an abstract representation of a name space
and maintain it dynamically quite simply, and it exports the channel interface used by
.CW Styxservers
for navigation, thus connecting the two, but leaving the application in complete
control of the name space contents viewed by Styx.
See the manual pages
.I styxservers (2)
.I styxservers-nametree (2),
The latter includes a short working example of combining the two modules.
The previous release of the system had a module
.CW Styxlib
that combined the functions of
.CW Styx
.CW Styxservers .
It remains for a time for transition, but newer applications should use either
.CW Styx
.CW Styxservers .
A new command
.I styxchat (8)
exchanges Styx messages with a server, reading a textual representation of T-messages
on standard input.
It can be helpful when testing a Styx server implementation.
(It was originally developed to test the
.CW Styx
module implementations in several configurations.)
See the attached manual page for details.
It also supports an option that allows it to act as a server,
printing T-messages as they are received from clients, and
reading R-messages in a textual form from standard input for replies.
.NH 2
Device driver changes
Most of the differences for most drivers are relatively minor
.CW diff
Throughout the hosted and emulated kernels:
.IP \(bu
.CW Qid
now is the structure:
struct Qid {
    vlong   path;
    ulong   vers;
    uchar   type;
.CW type
field has values
The test previously written
if(qid.path & CHDIR)
is now written
if(qid.type & QTDIR)
Because of that change, the various
.CW switch
statements in the drivers that previously read
switch(c->qid.path & ~Sys->CHDIR){
now read
to keep operations to 32 bits (except where otherwise required).
.IP \(bu
The first entry of a driver's
.CW Dirtab
.I must
be an entry for
if the driver uses
.CW devgen
to help implement
.I walk ,
.I stat ,
.I devdirread
.I open
.IP \(bu
Offsets passed to the driver's
.I read
.I write
entry points are
.CW vlong ,
not 32-bit
.CW ulong .
.IP \(bu
.I stat
entry point has an extra buffer size parameter:
int \fIxyz\f5stat(Chan *c, uchar *dp, int n)
It also returns an integer: the size of the result.
.CW Devstat
accepts the extra parameter and returns an appropriate result:
static int
\fIxyz\f5stat(Chan *c, uchar *dp, int n)
	return devstat(c, dp, n, rtcdir, nelem(\fIxyz\f5dir), devgen);
.IP \(bu
The biggest change is to
.I walk .
It has the signature:
Walkqid *\fIxyz\f5walk(Chan *c, Chan *nc, char **names, int nname);
and it allows zero or more elements to be walked in a single call,
returning its result in a newly-allocated
.CW Walkqid
struct Walkqid {
	Chan*	clone;
	int	nqid;
	Qid	qid[1];
Note that the array
.CW Walkqid.qid
must actually hold up to
.I nname
Qids, and thus is allocated as follows:
wq = smalloc(sizeof(Walkqid)+(nname-1)*sizeof(Qid));
The driver must take care that the space is reclaimed if
.CW error
is called before its
.I walk
function returns, by using
.CW waserror
as required.
.CW devwalk
looks after the details of
.I walk
.CW walkqid
for most drivers:
static Walkqid*	 
\fIxyz\f5walk(Chan* c, Chan *nc, char** name, int nname)
	return devwalk(c, nc, name, nname, \fIxyz\f5dir,
		nelem(\fIxyz\f5dir), devgen);
.IP \(bu
.I clone
entry point has gone, since cloning is seen by a driver as a particular form of call to its
.I walk
where the parameter values satisfy:
c != nc && nwname == 0
One difference is that a node can be cloned and walked in a single operation,
in other words
.CW nwname
can be non-zero,
and the incoming
.CW nc
is often nil and a new
.CW Chan
must be allocated.
Note that if the driver found it adequate to call
.CW devclone
previously, then
the new
.CW devwalk
generally look after it as well.
.CW Devclone
remains for use as a utility function for the few drivers that need to
clone a channel themselves,
in their
.I walk
operations or elsewhere.
.IP \(bu
.I detach
entry has been renamed
.I shutdown
(it was never the opposite of
.I attach ).
The stub
.CW devshutdown
can be used by devices that do not need it.
For drivers that serve a simple name space using the functions of
.CW dev.c
(described in
.I devattach (10.2)),
only a handful of simple changes are required.
Most are pointed out by the compilers as type clashes.
The main exception is the need for a
.CW Dirtab
to have its first entry be an entry for \f5"."\fP if the
.CW Dirtab
will be passed to
.CW devgen
.CW devwalk ,
.CW devstat
.CW devdirread .
.NH 1
Sys module changes
.NH 2
Sys: name change(s)
The name
has become
(since it is the limit to any error string, not its necessary length).
has been removed,
to allow each instance to be found (by compilation) and either removed
(where it was simply limiting the length of a file name), or replaced by
where it was used as a buffer size to read in names such as
.CW /dev/sysname
.CW /dev/user .
.NH 2
Sys: file sizes
The Styx protocol has always supported 64-bit file sizes and file offsets.
The Inferno interface has not.
.CW Sys
has changed so that length and offset values become
.CW big ,
file size
.CW Dir.length ,
the offset parameter to
.CW seek ,
.CW seek 's
These and the Qid changes account for quite a few changes in
our own source tree.
Typically, applications did things like this:
buf := array[d.length] of byte;

sys->seek(fd, 0, Sys->SEEKSTART);
off := sys->seek(fd, 0, Sys->SEEKRELA);	rec := off + HDRLEN;
for(offset := 0; offset < d.length; offset += RECSIZE){
	sys->seek(fd, offset, Sys->SEEKSTART);
The compiler now objects in each case because
.CW big
values are now appearing where
.CW int
is required, or conversely.
In some cases it is obvious that adding a cast is correct;
in others it is worth considering whether the calculation should indeed
.CW big
because file sizes for instance can in practice exceed the range of a
signed integer without too much trouble today, especially when the `file'
is a storage device.
The case that some people like and some dislike is:
if(sys->seek(fd, big offset, Sys->SEEKSTART) < big 0) ...
where the
.CW "big 0"
is needed because
.CW sys->seek
.CW big ,
and there are no `usual arithmetic conversions' as in C.
(Given the tangle that several languages have made of such conversions, perhaps
being strict is correct.)
.NH 2
Sys: export
.CW Sys->export
now has the signature:
export:	fn(c: ref Sys->FD, dir: string, flag: int): int;
allowing a directory
.I dir
other than \f5"/"\f1
to be exported.
It replaces the
.CW exportdir
function of (later) Third Edition.
.NH 2
Sys: Styx support
The revision of Styx has caused three calls to be added:
fauth:    fn(fd: ref Sys->FD, aname: string): ref Sys->FD;
fversion: fn(fd: ref Sys->FD, msize: int, version: string): (int, string);
iounit:   fn(fd: ref Sys->FD): int;
.CW Fversion
initialises a Styx session on connection
.I fd ,
sending the message size
.I msize
and protocol version string
.I version ;
it returns a tuple giving the message size and version returned by the Styx server.
It is rarely called directly; the
.CW mount
operation does it automatically on an uninitialised connection.
.CW Fauth
sends a Styx
.CW Tauth
message on connection
.I fd ,
and if successful, returns a file descriptor that
refers to an authentication file provided by the file server,
which may be read and written by
.CW Sys->read
.CW Sys->write
to implement the authentication protocol(s) supported by the server.
.CW Fauth
is needed only when the server requires authentication.
.CW Iounit
returns the `atomic IO unit' suggested for the file
.I fd
by its file server when it was opened.
.NH 2
Sys: mount
.CW mount
system call has acquired a second file descriptor parameter:
mount: fn(fd: ref Sys->FD, afd: ref Sys->FD, on: string,
          flags: int, spec: string): int;
.I Afd
is nil if the file server is known not to require authentication within a Styx session.
(The connection might itself have been authenticated previously, for instance,
and most file servers such as
.CW dossrv ,
.CW ftpfs
.CW dbfs
are invoked to provide services to an already-authenticated user, and therefore
do not require authentication within a session.)
If the server does require authentication,
.I afd
refers to a file descriptor returned by a previous
.CW fauth
on connection
.I fd ,
on which an authentication protocol has subsequently been executed as required by the file server connected to
.I fd .
.NH 2
Sys: other new system calls
There are two more new system calls:
fd2path: fn(fd: ref Sys->FD): string;
werrstr: fn(s: string): int;
.CW Fd2path
returns the path name under which the file descriptor
.I fd
was originally opened (if known).
One result is that
.I workdir (2)
produces reasonable results for the name of the current directory
in the presence of mounts and binds.
.CW Werrstr
sets the per-process system error string to
.I s ,
to allow a Limbo function to save and restore an error string over
other system calls, to present a similar interface
as the system calls on errors, or to annotate the error from a system call
for its own caller.
.NH 2
Sys: directory reading
.I sys-dirread (2)
system call's signature has changed:
dirread: fn(fd: ref Sys->FD): (int, array of Sys->Dir);
Previously it accepted an array of
.CW Dir
to fill and returned a count;
now it returns a tuple containing the count and the array of values read.
The change was needed because the representation of directory entries
is now variable length, and it is difficult to limit the number returned
(it is possible, but all the methods have disadvantages).
.CW Dirread
still reads a directory incrementally, requesting a block of directory entries
of reasonable size from the file server, and unpacking them into the returned array.
.I readdir (2)
to read whole directories at once.
.NH 1
There are several changes to
.CW Bufio :
Iobuf: adt {
	seek:	fn(b: self ref Iobuf, n: big, where: int): big;
	offset:	fn(b: self ref Iobuf): big;
# flush: fn();	# deleted
The module-level function
.CW Bufio->flush
has been removed
.CW Iobuf.flush ),
to allow concurrent use of a single
.CW Bufio
instance; applications must
.CW close
.CW flush
each output file explicitly.
As a result of the change to 64-bit offsets for
.CW Sys->seek ,
also accepts and returns
.CW big
.CW Iobuf.offset
is new, and returns the current file offset in bytes, taking account of any buffering.
.CW Iobuf.flush
has been extended to flush any data buffered on input files.
.NH 1
The graphics model represented by the
.I draw (3)
device and the
.CW Draw
module is significantly different, including support for a range of pixel formats,
and compositing in the drawing operations.
Most source code that uses Images
directly will require some changes, but the scope of them is limited: needing only extra
or different parameter values to individual operations, not radical restructuring.
The following changes affect most non-Tk graphics application code:
.IP \(bu
Pixels in an
.CW Image
can now be more than 8 bits and have a more flexible structure
(eg, several colour channels, and an optional alpha channel, of up to 8 bits each).
To support that, the old
.CW ldepth
field has gone, replaced by a channel descriptor
.CW chans
of type
.CW Chans ,
which describes the pixel structure, and an integer
.CW depth
field, which gives the total pixel size (depth) in bits.
.IP \(bu
The colour parameters are now 32-bit RGBA values
(red, green, blue and alpha components, 8-bit each, and big-endian
only when an
.CW int ).
.IP \(bu
The graphics subsystem supports Porter-Duff compositing,
combining a destination image with a source image (within an optional matte)
according to a compositing operator.
The interpretation of the old `mask' Image parameter to
.CW draw
.CW gendraw
has changed.
Previously it provided a simple binary mask;
it now provides a `matte', and its
alpha channel shapes the source image and adds partial transparencies.
If the matte parameter is nil, the source image is used unmodified.
If it lacks an alpha channel, one is computed from the matte image colour channels.
The drawing operations
.CW draw ,
.CW gendraw ,
.CW line ,
.CW text ,
and so on,
have all got variants
.CW drawop ,
.CW gendrawop ,
.CW lineop ,
.CW textop ,
and so on,
each taking an extra final parameter that specifies a Porter-Duff
compositing operator from a set predefined by
.CW Draw :
.CW SoverD ,
.CW SinD ,
.CW DatopS ,
and so on.
In each case,
refers to the source image (within a matte, if provided), and
refers to the destination image.
Most of them are useful only when either or both source or destination images have got
alpha channels (or a matte is used to shape the source).
The old function names without the
.CW op
suffix use the most common compositing operation
.CW Draw->SoverD ,
drawing the source image over the destination,
taking account of the shaping of the source and destination images by their alpha channels,
with the source further shaped by the optional matte.
.CW Image.draw
continues to do the `obvious' thing.
.IP \(bu
There are new colour map conversion functions.
.CW Chans
adt is the following:
Chans: adt
	# interpret standard channel string
	mk:    fn(s: string): Chans;
	# standard printable form
	text:  fn(c: self Chans): string;
	# equality
	eq:    fn(c: self Chans, d: Chans): int;
	# bits per pixel
	depth: fn(c: self Chans): int;
Values are created by
.CW ,
which accepts a string that is a sequence of channel descriptors,
each being a letter representing a channel type followed by an integer giving the channel's size (depth, width) in bits.
The letters include:
.CW r ,
.CW g
.CW b
for red, green and blue;
.CW a
for alpha;
.CW k
(!) for greyscale; and
.CW x
for padding (``unspecified'', ``don't care'').
produces a descriptor for a 32-bit pixel with 8-bit colour and alpha components.
The same descriptor is used in the revised
.I image (6)
format, although the older image file format with ldepth only is still recognised.
Given a Chans value
.I c ,
\fIc\fP\f5.text()\fP returns such a descriptor for it as a string.
.CW newimage
previously was called with a specific value for
.CW ldepth ,
an appropriate
.CW Chans
value must replace it.
A few common variants are defined as constants of type
.CW Chans
.CW Draw .
(We extended the Limbo compiler last year to support the use of
.CW con
with adt and tuple constants with this use in mind.)
For example, the value
.CW Draw->CMAP8
is the descriptor for the 8-bit deep
.I rgbv
colour-mapped Image format previously used by Inferno.
The list of predefined channels includes:
cfI cfI cfI cfI
n lf(CW) n lw(3i) .
Old ldepth	Name	Bit depth	Description
0	GREY1	1	single 1-bit deep greyscale channel
1	GREY2	2	single 2-bit deep greyscale
2	GREY4	4	single 4-bit deep greyscale
\-	GREY8	8	single 8-bit deep greyscale
3	CMAP8	8	single 8-bit deep \fIrgbv\f1 colour-mapped channel
\-	RGB15	15	three channels RGB: r5g5b5
\-	RGB16	16	three channels RGB: r5g6b5
\-	RGB24	24	three channels RGB: r8g8b8
\-	RGBA32	32	four channels: RGB and alpha: r8g8b8a8
The use of
.CW Chans
instead of
.CW ldepth
means that calls to
.CW Display.newimage
must be changed.
For instance:
buffer := display.newimage(r.inset(3), t.image.ldepth, 0, Draw->White);
buffer := display.newimage(r.inset(3), t.image.chans, 0, Draw->White);
There is an obvious difference: the
use of
.CW t.image.chans
instead of
.CW t.image.ldepth
to create a buffer Image with the same pixel structure as
.CW t .
There is, however, another difference.
The final colour parameter to
.CW newimage
is also different in structure: in the new graphics model, it is a 32-bit integer value giving RGBA
not a colour map index, and the name
.CW Draw->White
has the value
.CW 0 .
Because a symbolic name was used, however, the source need not change.
As another example,
.CW Draw->Palegreyblue
.CW "int 16r4993DDFF" .
Note the final
for the alpha component (creating a fully opaque colour).
When the top bit is set, the
.CW int
cast shown here is needed to force the otherwise
.CW big
value to 32 bits.
The values of colour components are now uniformly expressed as
intensity, so that a pixel with all zero colour components is black and
one with all colour components at maximum (all ones, full intensity)
is white.
.I rgbv
map has therefore been reversed.
Given a map index,
.CW Display.cmap2rgba
returns the 32-bit RGBA format used as a parameter in other calls.
All colour components are
.I linear
values, as required for compositing to work properly;
gamma correction is done as required by the display subsystem.
The colour components of a pixel with an alpha component are always
.I pre-multiplied
by the alpha value, following Porter and Duff, as further justified by Alvy Ray Smith and Jim Blinn.
``Thus a 50% red is
.CW 16r7F00007F
.CW 16rFF00007F .''
The function
.CW Draw->setalpha
does the computation.
Because of the changes to colours and the replacement of simple masks by mattes, the Images
.CW Display.ones
.CW Display.zeros
are no longer defined.
Instead, when they were intended to represent colours, the new Images
.CW Display.white
provide the obvious colours.
.CW ones
.CW zeros
were used as masks, the new predefined Images
.CW Display.opaque
.CW Display.transparent
are used instead as constant mattes, with alpha channels (fully opaque and fully transparent, respectively).
As noted above, where
.CW Display.ones
was used as a mask parameter in drawing operations, one can
simply specify a nil Image as a matte (`no matte') instead.
(That has been allowed for quite some time and is in use but might not be widely known.)
For example, Charon allocated a mask using:
dpicmask = display.newimage(pic.r, 0, 0, Draw->White);
which becomes
dpicmask = display.newimage(pic.r, Draw->GREY1, 0, Draw->Opaque);
is a constant value of the
.CW Chans
adt type, predefined by Draw, for Images that have a single 1-bit deep grey channel (ie, a bitmap).
(Note that to form a fully-opaque matte,
.CW Draw->Opaque
was used for clarity, not
.CW Draw->White ;
.CW Draw->Transparent
could also be used, as the basis for building a matte with transparency.)
A small if obscure change is that
.CW Display.newwindow
has a new parameter:
newwindow:	fn(screen: self ref Screen, r: Rect,
	backing: int, color: int): ref Image;
.I backing
parameter should usually be
.CW Draw->Refbackup ,
except for windows allocated on an image that already has got backing store
assigned, for instance because it is an image on a screen on an existing window image, in which case it should be
.CW Draw->Refnone ,
because the parent window already provides the backing.
As a small but helpful change, the adt
.CW Draw->Pointer
has a new element
.CW msec
that reports a
relative time stamp in milliseconds.
.CW Draw->Context
content is significantly different, for the benefit of the new
window system implementation.
.NH 1
Tk module
There is a new function in
.CW Tk :
quote:   fn(s: string): string;
.CW Quote
returns string
.I s
quoted according to Tk's `\f5{}\f1' quoting conventions.
It replaces
.CW Wmlib->tkquote .
There is a new widget type:
.I panel (9).
A panel instance can be packed and otherwise manipulated in the same way as any other Tk widget.
An image is associated with it by calling
.CW Tk->putimage
defined in
.I tk (2).
The associated images can be drawn on directly by the application, using all the operations provided by
.CW Draw .
The coordinates of the changed rectangle must be given to Tk
using the
.CW panel
widget command
.CW dirty ;
that part of the image will be redrawn if necessary at the next Tk
.CW update .
A panel has no default bindings.
.I panel (9)
for details.
For example,
.CW wm/coffee
now uses the following:
r := Rect((0, 0), (400, 300));
buffer := display.newimage(r, t.image.chans, 0, Draw->Black);
tk->cmd(t, "panel .f.p -bd 3 -relief flat");
tk->cmd(t, "pack .f.p -fill both -expand 1");
tk->cmd(t, "update");
org := buffer.r.min;
tk->putimage(t, ".f.p", buffer, nil);
When it has updated the
.CW buffer ,
it tells Tk:
tk->cmd(t, ".f.p dirty; update");
In this case the whole image is marked dirty, but
.CW dirty
can be given an optional rectangle parameter to restrict redrawing.
.CW Tk->putimage
.CW Tk->getimage
.CW imageput
.CW imageget .
.NH 1
Selectfile, Tabs and Dialog
The functions
.CW filename ,
.CW mktabs
.CW tabsctl ),
.CW dialog
.CW getstring
have been moved to separate new modules, to allow those aspects of the
user interface to be changed by replacing the implementations,
and to allow standard modules to be provided for picking colours (for instance).
.CW Selectfile
.CW filename ,
.CW Tabs
acquires the `tabs' Tk pseudo-widget, and
.CW Dialog
.CW dialog ,
which is renamed
.CW prompt ,
.CW getstring .
In cases where the functions took a
.CW Tk->Toplevel
as a parameter to specify a
.CW parent
they now take a
.CW Draw->Context
and (parent)
.CW Image
given a Toplevel
.CW t ,
.CW t.image .
.I dialog (2),
.I selectfile (2)
.I tabs (2).
Appendix A: Tk client conversion
.I Wm (1)
applications now have to feed their own pointer and keyboard
input to Tk. The window manager is now kept informed about the placement
of windows.
A Tk toplevel now holds a window manager context:
Wmcontext: adt
	kbd: 		chan of int;		# incoming characters from keyboard
	ptr: 		chan of ref Pointer;	# incoming stream of mouse positions
	ctl:		chan of string;		# commands from wm to application
	wctl:		chan of string;		# commands from application to wm
	images:	chan of ref Image;	# exchange of images
	connfd:	ref Sys->FD;		# connection control
	ctxt:		ref Context;
It contains some channels on which the window manager
sends information to the application, and a file
descriptor that can be used to write requests to the window
The channels used directly by the application are:
.IP \f(CWkbd\fP
characters typed by the user (pass them to
.CW Tk->pointer )
.IP \f(CWptr\fP
pointer events (pass them to
.CW Tk->keyboard )
.IP \f(CWctl\fP
application control requests.
Passing these to
.CW Tkclient->wmctl
will do the default action.
Requests starting with an exclamation mark
.CW ! ) (
can cause the application's image to change.
The toplevel also holds a channel
.CW wreq
on which it sends application
control requests; these have the same form as those
sent on
.CW Wmcontext.ctl ,
and can be forwarded to
.CW Tkclient->wmctl
in the same way.
Control requests currently understood by
.I wm (1)
.IP "\f(CW!reshape \fItag\fP \fIreqid\fP \fIminx\fP \fIminy\fP \fImaxx\fP \fImaxy\fP [\fIhow\fP]\fR
Reshape the window referenced by
.I tag ,
creating a new image if
.I tag
did not previously exist.
.I Reqid
is ignored.
.I How
can be one of:
.IP \f(CWplace\fP 15
.I Wm
attempts to find a suitable patch of screen real estate on which to place
the window; the size of the given rectangle
is taken to be the minimum size for that window.
.IP \f(CWexact\fP
Reshape to the exact rectangle requested.
This is the default if
.I how
is not given.
.IP \f(CWonscreen\fP
The given rectangle is adjusted so that it is no bigger than the available
screen space, and is entirely on screen.
.IP "\f(CWdelete \fItag\fP\fR
Delete the image associated with
.I tag .
.IP "\f(CWraise\fP
Raise the window
.IP "\f(CWlower\fP
Lower the window
.IP "\f(CW!move \fItag\fP \fIreqid\fP \fIstartx\fP \fIstarty\fP\fR
Request the user to move the window to a new place.
.I Startx
.I starty
are the coordinates of the pointer when the request was initiated.
.IP "\f(CW!size \fItag\fP\fR
Request the user to resize the window.
To convert a typical Tk application, do the following.
.IP 1.
Use an editor to make the following changes:
cfI cfI
lf(CW) lf(CW) .
Old	New
Wmlib	Tkclient
wmlib	tkclient
tkclient->titlebar	tkclient->toplevel
tkclient->titlectl	tkclient->wmctl
tkclient->taskbar	tkclient->settitle
tk->imageput	tk->putimage
tk->imageget	tk->getimage
.IP 2.
Insert the following code at the top of the central
.CW alt
The names
.CW wmctl ' `
.CW top ` '
will need changing to the appropriate variables in the program:
s := <-top.ctxt.kbd =>
	tk->keyboard(top, s);
s := <-top.ctxt.ptr =>
	tk->pointer(top, *s);
s := <-top.ctxt.ctl or
s = <-top.wreq or
s = <-wmctl =>
	tkclient->wmctl(top, s);
.IP 3.
Add the following just after the Tk configuration code and
before the main processing starts:
tkclient->onscreen(top, nil);
tkclient->startinput(top, "kbd"::"ptr"::nil);
This is possibly the easiest part to forget.
Be careful of cases where a blocking function is called
from the main loop that relies on keyboard/mouse input.
The easiest solution can be to spawn a thread to handle the
keyboard and mouse independently.