Blob


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