Blob


1 package p9p
3 import (
4 "fmt"
5 "time"
6 )
8 const (
9 // DefaultMSize messages size used to establish a session.
10 DefaultMSize = 64 << 10
12 // DefaultVersion for this package. Currently, the only supported version.
13 DefaultVersion = "9P2000"
14 )
16 // Mode constants for use Dir.Mode.
17 const (
18 DMDIR = 0x80000000 // mode bit for directories
19 DMAPPEND = 0x40000000 // mode bit for append only files
20 DMEXCL = 0x20000000 // mode bit for exclusive use files
21 DMMOUNT = 0x10000000 // mode bit for mounted channel
22 DMAUTH = 0x08000000 // mode bit for authentication file
23 DMTMP = 0x04000000 // mode bit for non-backed-up files
25 // 9p2000.u extensions
27 DMSYMLINK = 0x02000000
28 DMDEVICE = 0x00800000
29 DMNAMEDPIPE = 0x00200000
30 DMSOCKET = 0x00100000
31 DMSETUID = 0x00080000
32 DMSETGID = 0x00040000
34 DMREAD = 0x4 // mode bit for read permission
35 DMWRITE = 0x2 // mode bit for write permission
36 DMEXEC = 0x1 // mode bit for execute permission
37 )
39 // Flag defines the flag type for use with open and create
40 type Flag uint8
42 // Constants to use when opening files.
43 const (
44 OREAD Flag = 0x00 // open for read
45 OWRITE Flag = 0x01 // write
46 ORDWR Flag = 0x02 // read and write
47 OEXEC Flag = 0x03 // execute, == read but check execute permission
49 // PROPOSAL(stevvooe): Possible protocal extension to allow the create of
50 // symlinks. Initially, the link is created with no value. Read and write
51 // to read and set the link value.
53 OSYMLINK Flag = 0x04
55 OTRUNC Flag = 0x10 // or'ed in (except for exec), truncate file first
56 OCEXEC Flag = 0x20 // or'ed in, close on exec
57 ORCLOSE Flag = 0x40 // or'ed in, remove on close
58 )
60 // QType indicates the type of a resource within the Qid.
61 type QType uint8
63 // Constants for use in Qid to indicate resource type.
64 const (
65 QTDIR QType = 0x80 // type bit for directories
66 QTAPPEND QType = 0x40 // type bit for append only files
67 QTEXCL QType = 0x20 // type bit for exclusive use files
68 QTMOUNT QType = 0x10 // type bit for mounted channel
69 QTAUTH QType = 0x08 // type bit for authentication file
70 QTTMP QType = 0x04 // type bit for not-backed-up file
71 QTFILE QType = 0x00 // plain file
72 )
74 func (qt QType) String() string {
75 switch qt {
76 case QTDIR:
77 return "dir"
78 case QTAPPEND:
79 return "append"
80 case QTEXCL:
81 return "excl"
82 case QTMOUNT:
83 return "mount"
84 case QTAUTH:
85 return "auth"
86 case QTTMP:
87 return "tmp"
88 case QTFILE:
89 return "file"
90 }
92 return "unknown"
93 }
95 // Tag uniquely identifies an outstanding fcall in a 9p session.
96 type Tag uint16
98 // NOTAG is a reserved values for messages sent before establishing a session,
99 // such as Tversion.
100 const NOTAG Tag = ^Tag(0)
102 // Fid defines a type to hold Fid values.
103 type Fid uint32
105 // NOFID indicates the lack of an Fid.
106 const NOFID Fid = ^Fid(0)
108 // Qid indicates the type, path and version of the resource returned by a
109 // server. It is only valid for a session.
110 //
111 // Typically, a client maintains a mapping of Fid-Qid as Qids are returned by
112 // the server.
113 type Qid struct {
114 Type QType `9p:"type,1"`
115 Version uint32
116 Path uint64
119 func (qid Qid) String() string {
120 return fmt.Sprintf("qid(%v, v=%x, p=%x)",
121 qid.Type, qid.Version, qid.Path)
124 // Dir defines the structure used for expressing resources in stat/wstat and
125 // when reading directories.
126 type Dir struct {
127 Type uint16
128 Dev uint32
129 Qid Qid
130 Mode uint32
132 // BUG(stevvooe): The Year 2038 is coming soon. 9p wire protocol has these
133 // as 4 byte epoch times. Some possibilities include time dilation fields
134 // or atemporal files. We can also just not use them and set them to zero.
136 AccessTime time.Time
137 ModTime time.Time
139 Length uint64
140 Name string
141 UID string
142 GID string
143 MUID string
146 func (d Dir) String() string {
147 return fmt.Sprintf("dir(%v mode=%v atime=%v mtime=%v length=%v name=%v uid=%v gid=%v muid=%v)",
148 d.Qid, d.Mode, d.AccessTime, d.ModTime, d.Length, d.Name, d.UID, d.GID, d.MUID)