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 8a7ec697 2015-10-26 adrien NOFID = ^Fid(0)
10 8a7ec697 2015-10-26 adrien NOTAG = ^Tag(0)
11 8a7ec697 2015-10-26 adrien )
12 8a7ec697 2015-10-26 adrien
13 8a7ec697 2015-10-26 adrien 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 8a7ec697 2015-10-26 adrien const (
35 fb37ce2a 2015-10-30 stephen.d OREAD = 0x00 // open for read
36 fb37ce2a 2015-10-30 stephen.d OWRITE = 0x01 // write
37 fb37ce2a 2015-10-30 stephen.d ORDWR = 0x02 // read and write
38 fb37ce2a 2015-10-30 stephen.d OEXEC = 0x03 // execute, == read but check execute permission
39 fb37ce2a 2015-10-30 stephen.d
40 fb37ce2a 2015-10-30 stephen.d // PROPOSAL(stevvooe): Possible protocal extension to allow the create of
41 fb37ce2a 2015-10-30 stephen.d // symlinks. Initially, the link is created with no value. Read and write
42 fb37ce2a 2015-10-30 stephen.d // to read and set the link value.
43 fb37ce2a 2015-10-30 stephen.d OSYMLINK = 0x04
44 fb37ce2a 2015-10-30 stephen.d
45 fb37ce2a 2015-10-30 stephen.d // or'd in
46 fb37ce2a 2015-10-30 stephen.d OTRUNC = 0x10 // or'ed in (except for exec), truncate file first
47 fb37ce2a 2015-10-30 stephen.d OCEXEC = 0x20 // or'ed in, close on exec
48 fb37ce2a 2015-10-30 stephen.d ORCLOSE = 0x40 // or'ed in, remove on close
49 8a7ec697 2015-10-26 adrien )
50 8a7ec697 2015-10-26 adrien
51 8a7ec697 2015-10-26 adrien type QType uint8
52 8a7ec697 2015-10-26 adrien
53 8a7ec697 2015-10-26 adrien const (
54 8a7ec697 2015-10-26 adrien QTDIR QType = 0x80 // type bit for directories
55 8a7ec697 2015-10-26 adrien QTAPPEND QType = 0x40 // type bit for append only files
56 8a7ec697 2015-10-26 adrien QTEXCL QType = 0x20 // type bit for exclusive use files
57 8a7ec697 2015-10-26 adrien QTMOUNT QType = 0x10 // type bit for mounted channel
58 8a7ec697 2015-10-26 adrien QTAUTH QType = 0x08 // type bit for authentication file
59 8a7ec697 2015-10-26 adrien QTTMP QType = 0x04 // type bit for not-backed-up file
60 d6198009 2015-10-28 stephen.d QTFILE QType = 0x00 // plain file
61 8a7ec697 2015-10-26 adrien )
62 8a7ec697 2015-10-26 adrien
63 fb37ce2a 2015-10-30 stephen.d func (qt QType) String() string {
64 fb37ce2a 2015-10-30 stephen.d switch qt {
65 fb37ce2a 2015-10-30 stephen.d case QTDIR:
66 fb37ce2a 2015-10-30 stephen.d return "dir"
67 fb37ce2a 2015-10-30 stephen.d case QTAPPEND:
68 fb37ce2a 2015-10-30 stephen.d return "append"
69 fb37ce2a 2015-10-30 stephen.d case QTEXCL:
70 fb37ce2a 2015-10-30 stephen.d return "excl"
71 fb37ce2a 2015-10-30 stephen.d case QTMOUNT:
72 fb37ce2a 2015-10-30 stephen.d return "mount"
73 fb37ce2a 2015-10-30 stephen.d case QTAUTH:
74 fb37ce2a 2015-10-30 stephen.d return "auth"
75 fb37ce2a 2015-10-30 stephen.d case QTTMP:
76 fb37ce2a 2015-10-30 stephen.d return "tmp"
77 fb37ce2a 2015-10-30 stephen.d case QTFILE:
78 fb37ce2a 2015-10-30 stephen.d return "file"
79 fb37ce2a 2015-10-30 stephen.d }
80 fb37ce2a 2015-10-30 stephen.d
81 fb37ce2a 2015-10-30 stephen.d return "unknown"
82 fb37ce2a 2015-10-30 stephen.d }
83 fb37ce2a 2015-10-30 stephen.d
84 8a7ec697 2015-10-26 adrien type Fid uint32
85 8a7ec697 2015-10-26 adrien
86 8a7ec697 2015-10-26 adrien type Qid struct {
87 fb37ce2a 2015-10-30 stephen.d Type QType `9p:type,1`
88 8a7ec697 2015-10-26 adrien Version uint32
89 8a7ec697 2015-10-26 adrien Path uint64
90 8a7ec697 2015-10-26 adrien }
91 8a7ec697 2015-10-26 adrien
92 fb37ce2a 2015-10-30 stephen.d func (qid Qid) String() string {
93 74ec7ac9 2015-10-30 stephen.d return fmt.Sprintf("qid(%v, v=%x, p=%x)",
94 fb37ce2a 2015-10-30 stephen.d qid.Type, qid.Version, qid.Path)
95 fb37ce2a 2015-10-30 stephen.d }
96 fb37ce2a 2015-10-30 stephen.d
97 8a7ec697 2015-10-26 adrien type Dir struct {
98 fb37ce2a 2015-10-30 stephen.d Type uint16
99 fb37ce2a 2015-10-30 stephen.d Dev uint32
100 fb37ce2a 2015-10-30 stephen.d Qid Qid
101 fb37ce2a 2015-10-30 stephen.d Mode uint32
102 fb37ce2a 2015-10-30 stephen.d
103 fb37ce2a 2015-10-30 stephen.d // BUG(stevvooe): The Year 2038 is coming soon. 9p wire protocol has these
104 fb37ce2a 2015-10-30 stephen.d // as 4 byte epoch times. Some possibilities include time dilation fields
105 fb37ce2a 2015-10-30 stephen.d // or atemporal files. We can also just not use them and set them to zero.
106 fb37ce2a 2015-10-30 stephen.d
107 d6198009 2015-10-28 stephen.d AccessTime time.Time
108 d6198009 2015-10-28 stephen.d ModTime time.Time
109 8a7ec697 2015-10-26 adrien
110 fb37ce2a 2015-10-30 stephen.d Length uint64
111 fb37ce2a 2015-10-30 stephen.d Name string
112 fb37ce2a 2015-10-30 stephen.d UID string
113 fb37ce2a 2015-10-30 stephen.d GID string
114 fb37ce2a 2015-10-30 stephen.d MUID string
115 8a7ec697 2015-10-26 adrien }
116 8a7ec697 2015-10-26 adrien
117 74ec7ac9 2015-10-30 stephen.d func (d Dir) String() string {
118 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)",
119 74ec7ac9 2015-10-30 stephen.d d.Qid, d.Mode, d.AccessTime, d.ModTime, d.Length, d.Name, d.UID, d.GID, d.MUID)
120 74ec7ac9 2015-10-30 stephen.d }
121 74ec7ac9 2015-10-30 stephen.d
122 8a7ec697 2015-10-26 adrien //
123 8a7ec697 2015-10-26 adrien type Tag uint16