3 intro \- introduction to the Plan 9 File Protocol, 9P
9 is an agent that provides one or more hierarchical file systems
11 that may be accessed by Plan 9 processes.
12 A server responds to requests by
14 to navigate the hierarchy,
15 and to create, remove, read, and write files.
16 The prototypical server is a separate machine that stores
17 large numbers of user files on permanent media;
18 such a machine is called, somewhat confusingly, a
21 Another possibility for a server is to synthesize
22 files on demand, perhaps based on information on data structures
23 maintained in memory; the
25 server is an example of such a server.
29 to a server is a bidirectional communication path from the client to the server.
30 There may be a single client or
31 multiple clients sharing the same connection.
34 .IR "Plan 9 File Protocol" ,
35 9P, is used for messages between
47 The combined acts of transmitting (receiving) a request of a particular type,
48 and receiving (transmitting)
53 Each message consists of a sequence of bytes.
54 Two-, four-, and eight-byte fields hold unsigned
55 integers represented in little-endian order
56 (least significant byte first).
57 Data items of larger or variable lengths are represented
58 by a two-byte field specifying a count,
63 Text strings are represented this way,
64 with the text itself stored as a UTF-8
65 encoded sequence of Unicode characters (see
67 Text strings in 9P messages are not
71 counts the bytes of UTF-8 data, which include no final zero byte.
74 character is illegal in all text strings in 9P, and is therefore
75 excluded from file names, user names, and so on.
77 Each 9P message begins with a four-byte size field
78 specifying the length in bytes of the complete message including
79 the four bytes of the size field itself.
80 The next byte is the message type, one of the constants
81 in the enumeration in the include file
83 The next two bytes are an identifying
86 The remaining bytes are parameters of different sizes.
87 In the message descriptions, the number of bytes in a field
88 is given in brackets after the field name.
93 is not a constant represents a variable-length parameter:
97 bytes of data forming the
109 (Systems may choose to reduce the set of legal characters
110 to reduce syntactic problems,
111 for example to remove slashes from name components,
112 but the protocol has no such restriction.
113 Plan 9 names may contain any printable character (that is, any character
114 outside hexadecimal 00-1F and 80-9F)
116 Messages are transported in byte form to allow for machine independence;
118 describes routines that convert to and from this form into a machine-dependent
121 .ta \w'\fLTsession 'u
187 .IR nwname *( wname [ s ])
193 .IR nwqid *( wqid [13])
309 field, chosen and used by the client to identify the message.
310 The reply to the message will have the same tag.
311 Clients must arrange that no two outstanding messages
312 on the same connection have the same tag.
313 An exception is the tag
319 the client can use it, when establishing a connection,
321 override tag matching in
325 The type of an R-message will either be one greater than the type
326 of the corresponding T-message or
328 indicating that the request failed.
329 In the latter case, the
331 field contains a string describing the reason for failure.
335 message identifies the version of the protocol and indicates
336 the maximum message size the system is prepared to handle.
337 It also initializes the connection and
338 aborts all outstanding I/O on the connection.
339 The set of messages between
344 Most T-messages contain a
346 a 32-bit unsigned integer that the client uses to identify
347 a ``current file'' on the server.
348 Fids are somewhat like file descriptors in a user process,
349 but they are not restricted to files open for I/O:
350 directories being examined, files being accessed by
352 calls, and so on \(em all files being manipulated by the operating
353 system \(em are identified by fids.
354 Fids are chosen by the client.
355 All requests on a connection share the same fid space;
356 when several clients share a connection,
357 the agent managing the sharing must arrange
358 that no two clients choose the same fid.
360 The fid supplied in an
363 will be taken by the server to refer to the root of the served file tree.
367 to the server and may specify a particular file tree served
368 by the server (for those that supply more than one).
370 Permission to attach to the service is proven by providing a special fid, called
376 is established by exchanging
378 messages and subsequently manipulated using
382 messages to exchange authentication information not defined explicitly by 9P.
383 Once the authentication protocol is complete, the
387 to permit the user to access the service.
391 message causes the server to change the current file associated
392 with a fid to be a file in the directory that is the old current file, or one of
395 returns a new fid that refers to the resulting file.
396 Usually, a client maintains a fid for the root,
401 A client can send multiple T-messages without waiting for the corresponding
402 R-messages, but all outstanding T-messages must specify different tags.
403 The server may delay the response to a request
404 and respond to later ones;
405 this is sometimes necessary, for example when the client reads
406 from a file that the server synthesizes from external events
407 such as keyboard characters.
409 Replies (R-messages) to
418 field back to the client.
419 The qid represents the server's unique identification for the
421 two files on the same server hierarchy are the same if and only if their qids
423 (The client may have multiple fids pointing to a single file on a server
424 and hence having a single qid.)
425 The thirteen-byte qid fields hold a one-byte type,
426 specifying whether the file is a directory, append-only file, etc.,
427 and two unsigned integers:
428 first the four-byte qid
430 then the eight-byte qid
432 The path is an integer unique among all files in the hierarchy.
433 If a file is deleted and recreated with the
434 same name in the same directory, the old and new path components of the qids
436 The version is a version number for a file;
437 typically, it is incremented every time the file is modified.
439 An existing file can be
443 in the current (directory) file.
444 I/O of a given number of bytes
446 on an open file is done by
453 any fid that is no longer needed.
456 transaction deletes files.
459 is an extension used by Unix utilities to allow traditional Unix programs
460 to have their input or output attached to fids on 9P servers.
469 transaction retrieves information about the file.
472 field in the reply includes the file's
474 access permissions (read, write and execute for owner, group and public),
475 access and modification times, and
476 owner and group identifications
479 The owner and group identifications are textual names.
482 transaction allows some of a file's properties
485 A request can be aborted with a
488 When a server receives a
490 it should not reply to the message with tag
492 (unless it has already replied),
493 and it should immediately send an
498 (even if the reply to the original message arrives in the interim),
503 Because the message size is negotiable and some elements of the
504 protocol are variable length, it is possible (although unlikely) to have
505 a situation where a valid message is too large to fit within the negotiated size.
506 For example, a very long file name may cause a
510 of its directory entry to be too large to send.
511 In most such cases, the server should generate an error rather than
512 modify the data to fit, such as by truncating the file name.
513 The exception is that a long error string in an
515 message should be truncated if necessary, since the string is only
516 advisory and in some sense arbitrary.
518 Most programs do not see the 9P protocol directly;
519 on Plan 9, calls to library
520 routines that access files are
521 translated by the kernel's mount driver
524 On Unix, 9P services are posted as Unix domain sockets in a
525 well-known directory (see
529 Clients connect to these servers using a 9P client library
533 Directories are created by
537 set in the permissions argument (see
539 The members of a directory can be found with
541 All directories must support
546 meaning parent directory, although by convention directories
547 contain no explicit entry for
552 The parent of the root directory of a server's tree is itself.
553 .SH "ACCESS PERMISSIONS"
554 This section describes the access permission conventions
555 implemented by most Plan 9 file servers. These conventions
556 are not enforced by the protocol and may differ between servers,
557 especially servers built on top of foreign operating systems.
559 Each file server maintains a set of user and group names.
560 Each user can be a member of any number of groups.
563 who has special privileges (see
566 Plan 9's \fIusers\fR(6)).
567 Every file request has an implicit user id (copied from the original
569 and an implicit set of groups (every group of which the user is a member).
571 Each file has an associated
576 three sets of permissions:
577 those of the owner, those of the group, and those of ``other'' users.
578 When the owner attempts to do something to a file, the owner, group,
579 and other permissions are consulted, and if any of them grant
580 the requested permission, the operation is allowed.
581 For someone who is not the owner, but is a member of the file's group,
582 the group and other permissions are consulted.
583 For everyone else, the other permissions are used.
584 Each set of permissions says whether reading is allowed,
585 whether writing is allowed, and whether executing is allowed.
588 in a directory is regarded as executing the directory,
590 Permissions are kept in the low-order bits of the file
592 owner read/write/execute permission represented as 1 in bits 8, 7, and 6
593 respectively (using 0 to number the low order).
594 The group permissions are in bits 5, 4, and 3,
595 and the other permissions are in bits 2, 1, and 0.
599 contains some additional attributes besides the permissions.
602 is set, the file is a directory;
605 is set, the file is append-only (offset is ignored in writes);
608 is set, the file is exclusive-use (only one client may have it
612 is set, the file is an authentication file established by
617 is set, the contents of the file (or directory) are not included in nightly archives.
618 (Bit 28 is skipped for historical reasons.)
619 These bits are reproduced, from the top bit down, in the type byte of the Qid:
630 identifies the value of the type for a plain file.