Blame


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