styxserver.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #define Qroot 0
  2. #define MSGMAX ((((8192+128)*2)+3) & ~3)
  3. extern char Enomem[]; /* out of memory */
  4. extern char Eperm[]; /* permission denied */
  5. extern char Enodev[]; /* no free devices */
  6. extern char Ehungup[]; /* i/o on hungup channel */
  7. extern char Eexist[]; /* file exists */
  8. extern char Enonexist[]; /* file does not exist */
  9. extern char Ebadcmd[]; /* bad command */
  10. extern char Ebadarg[]; /* bad arguments */
  11. typedef uvlong Path;
  12. typedef struct Styxserver Styxserver;
  13. typedef struct Styxops Styxops;
  14. typedef struct Styxfile Styxfile;
  15. typedef struct Client Client;
  16. typedef struct Fid Fid;
  17. struct Styxserver
  18. {
  19. Styxops *ops;
  20. Path qidgen;
  21. int connfd;
  22. int needfile;
  23. Client *clients;
  24. Client *curc;
  25. Styxfile *root;
  26. Styxfile **ftab;
  27. void *priv; /* private */
  28. };
  29. struct Client
  30. {
  31. Styxserver *server;
  32. Client *next;
  33. int fd;
  34. char msg[MSGMAX];
  35. uint nread; /* valid bytes in msg (including nc)*/
  36. int nc; /* bytes consumed from front of msg by convM2S */
  37. char data[MSGMAX]; /* Tread/Rread data */
  38. int state;
  39. Fid *fids;
  40. char *uname; /* uid */
  41. char *aname; /* attach name */
  42. void *u;
  43. };
  44. struct Styxops
  45. {
  46. char *(*newclient)(Client *c);
  47. char *(*freeclient)(Client *c);
  48. char *(*attach)(char *uname, char *aname);
  49. char *(*walk)(Qid *qid, char *name);
  50. char *(*open)(Qid *qid, int mode);
  51. char *(*create)(Qid *qid, char *name, int perm, int mode);
  52. char *(*read)(Qid qid, char *buf, ulong *n, vlong offset);
  53. char *(*write)(Qid qid, char *buf, ulong *n, vlong offset);
  54. char *(*close)(Qid qid, int mode);
  55. char *(*remove)(Qid qid);
  56. char *(*stat)(Qid qid, Dir *d);
  57. char *(*wstat)(Qid qid, Dir *d);
  58. };
  59. struct Styxfile
  60. {
  61. Dir d;
  62. Styxfile *parent;
  63. Styxfile *child;
  64. Styxfile *sibling;
  65. Styxfile *next;
  66. int ref;
  67. int open;
  68. void *u;
  69. };
  70. char *styxinit(Styxserver *server, Styxops *ops, char *port, int perm, int needfile);
  71. char *styxwait(Styxserver *server);
  72. char *styxprocess(Styxserver *server);
  73. char *styxend(Styxserver *server);
  74. Client *styxclient(Styxserver *server);
  75. Styxfile *styxaddfile(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner);
  76. Styxfile *styxadddir(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner);
  77. int styxrmfile(Styxserver *server, Path qid);
  78. Styxfile *styxfindfile(Styxserver *server, Path qid);
  79. int styxperm(Styxfile *file, char *uid, int mode);
  80. long styxreadstr(ulong off, char *buf, ulong n, char *str);
  81. Qid styxqid(int path, int isdir);
  82. void *styxmalloc(int n);
  83. void styxfree(void *p);
  84. void styxdebug(void);
  85. void styxsetowner(char*);