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