Blob


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