]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/cifs/info.c
realemu: implement IDIV, mark 0xE0000 writeable, fix DIV overfow trap
[plan9front.git] / sys / src / cmd / cifs / info.c
1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <fcall.h>
5 #include <thread.h>
6 #include <9p.h>
7 #include "cifs.h"
8
9
10 struct {
11         char *name;
12         int (*func)(Fmt *f);
13         char *buf;
14         int len;
15 } Infdir[] = {
16         { "Users" , userinfo },
17         { "Groups" , groupinfo },
18         { "Shares" , shareinfo },
19         { "Connection" , conninfo },
20         { "Sessions" , sessioninfo },
21         { "Dfsroot" , dfsrootinfo },
22         { "Dfscache" , dfscacheinfo },
23         { "Domains" , domaininfo },
24         { "Openfiles" , openfileinfo },
25         { "Workstations" , workstationinfo },
26         { "Filetable" , filetableinfo },
27 };
28
29 int
30 walkinfo(char *name)
31 {
32         int i;
33
34         for(i = 0; i < nelem(Infdir); i++)
35                 if(strcmp(Infdir[i].name, name) == 0)
36                         return(i);
37         return -1;
38 }
39
40 int
41 numinfo(void)
42 {
43         return nelem(Infdir);
44 }
45
46 int
47 dirgeninfo(int slot, Dir *d)
48 {
49         if(slot < 0 || slot > nelem(Infdir))
50                 return -1;
51
52         memset(d, 0, sizeof(Dir));
53         d->type = 'N';
54         d->dev = 99;
55         d->name = estrdup9p(Infdir[slot].name);
56         d->uid = estrdup9p("other");
57         d->muid = estrdup9p("other");
58         d->gid = estrdup9p("other");
59         d->mode = 0666;
60         d->atime = time(0);
61         d->mtime = d->atime;
62         d->qid = mkqid(Infdir[slot].name, 0, 1, Pinfo, slot);
63         d->qid.vers = 1;
64         d->qid.path = slot;
65         d->qid.type = 0;
66
67         return 0;
68 }
69
70 int
71 makeinfo(int path)
72 {
73         Fmt f;
74
75         if(path < 0 || path > nelem(Infdir))
76                 return -1;
77         if(Infdir[path].buf != nil)
78                 return 0;
79         fmtstrinit(&f);
80         if((*Infdir[path].func)(&f) == -1)
81                 return -1;
82         if((Infdir[path].buf = fmtstrflush(&f)) == nil)
83                 return -1;
84         if((Infdir[path].len = strlen(Infdir[path].buf)) <= 0)
85                 return -1;
86         return 0;
87 }
88
89 int
90 readinfo(int path, char *buf, int len, int off)
91 {
92         if(path < 0 || path > nelem(Infdir))
93                 return -1;
94         if(off > Infdir[path].len)
95                 return 0;
96         if(len + off > Infdir[path].len)
97                 len = Infdir[path].len - off;
98         memmove(buf, Infdir[path].buf + off, len);
99         return len;
100 }
101
102 void
103 freeinfo(int path)
104 {
105         if(path < 0 || path > nelem(Infdir))
106                 return;
107         free(Infdir[path].buf);
108         Infdir[path].buf = nil;
109 }
110