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