rostring: renamed funcs to mixpsrv_*(), added close and str is copied now
[libmixpsrv.git] / ixpserv / fs.c
blob6a6b2a6f10c117ac2d428deb12d1a02eca371e59
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <errno.h>
7 #include <string.h>
9 #include <9p-mixp/mixp.h>
10 #include <9p-mixpsrv/types.h>
11 #include <9p-mixpsrv/p9srv.h>
12 #include <9p-mixpsrv/prototypes.h>
13 #include <9p-mixpsrv/errors.h>
15 extern MIXPSRV_FILE_HANDLE* open_root();
17 MIXPSRV_FILESERVER fileserver = {
18 .magic = MIXPSRV_FILESERVER_MAGIC,
19 .openRoot = open_root
22 /* --------------------- root directory ops ----------------------- */
24 MIXPSRV_FILE_HANDLE* rootops_lookup(MIXPSRV_FILE_HANDLE*parent, char* name)
26 printf("rootops_lookup() requested: \"%s\"\n",name);
28 if ((!name) || (!strlen(name)) || (!strcmp(name,"/")))
30 printf("rootops_lookup() requested the root directory\n");
31 return open_root();
34 if (!strcmp(name,"etc"))
36 printf(" --> /etc\n");
37 return p9srv_get_file();
40 if (!strcmp(name,"foo"))
42 printf(" --> /foo\n");
43 MIXPSRV_FILE_HANDLE* n = p9srv_get_file();
44 mixpsrv_hostfile_ops_init(n,"/etc/hosts");
45 return n;
48 return NULL;
51 MIXPSRV_FILE_OPS rootops = {
52 .size = NULL,
53 .open = NULL,
54 .lookup = rootops_lookup,
55 .classname = "etcdir"
58 MIXPSRV_FILE_HANDLE* open_root(MIXPSRV_FILESERVER* server)
60 MIXPSRV_FILE_HANDLE *f = p9srv_get_file();
61 f->ops = rootops;
62 f->name = strdup("/");
63 f->qtype = P9_QTDIR;
64 f->type = 0;
65 f->perm = 0500|P9_DMDIR;
66 return f;
69 int main()
71 printf("starting 9p \n");
72 char* errstr = "OKAY";
73 int fd;
75 fd = ixp_serversock_tcp("*",9999,&errstr);
76 if (fd<0)
78 printf("fd=%d err=%s\n",fd,errstr);
79 return -1;
82 p9srv_run_server(fd, &fileserver);
83 return 0;