Blame


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