Blob


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