9p-synth.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * 9p
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. */
  13. #ifndef QEMU_9P_SYNTH_H
  14. #define QEMU_9P_SYNTH_H
  15. typedef struct V9fsSynthNode V9fsSynthNode;
  16. typedef ssize_t (*v9fs_synth_read)(void *buf, int len, off_t offset,
  17. void *arg);
  18. typedef ssize_t (*v9fs_synth_write)(void *buf, int len, off_t offset,
  19. void *arg);
  20. typedef struct V9fsSynthNodeAttr {
  21. int mode;
  22. int inode;
  23. int nlink;
  24. v9fs_synth_read read;
  25. v9fs_synth_write write;
  26. } V9fsSynthNodeAttr;
  27. struct V9fsSynthNode {
  28. QLIST_HEAD(, V9fsSynthNode) child;
  29. QLIST_ENTRY(V9fsSynthNode) sibling;
  30. char name[NAME_MAX];
  31. V9fsSynthNodeAttr *attr;
  32. V9fsSynthNodeAttr actual_attr;
  33. void *private;
  34. int open_count;
  35. };
  36. typedef struct V9fsSynthOpenState {
  37. off_t offset;
  38. V9fsSynthNode *node;
  39. struct dirent dent;
  40. /*
  41. * Ensure there is enough space for 'dent' above, some systems have a
  42. * d_name size of just 1, which would cause a buffer overrun.
  43. */
  44. char dent_trailing_space[NAME_MAX];
  45. } V9fsSynthOpenState;
  46. int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
  47. const char *name, V9fsSynthNode **result);
  48. int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
  49. const char *name, v9fs_synth_read read,
  50. v9fs_synth_write write, void *arg);
  51. /* qtest stuff */
  52. #define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d"
  53. #define QTEST_V9FS_SYNTH_LOPEN_FILE "LOPEN"
  54. #define QTEST_V9FS_SYNTH_WRITE_FILE "WRITE"
  55. /* for READDIR test */
  56. #define QTEST_V9FS_SYNTH_READDIR_DIR "ReadDirDir"
  57. #define QTEST_V9FS_SYNTH_READDIR_FILE "ReadDirFile%d"
  58. #define QTEST_V9FS_SYNTH_READDIR_NFILES 100
  59. /* Any write to the "FLUSH" file is handled one byte at a time by the
  60. * backend. If the byte is zero, the backend returns success (ie, 1),
  61. * otherwise it forces the server to try again forever. Thus allowing
  62. * the client to cancel the request.
  63. */
  64. #define QTEST_V9FS_SYNTH_FLUSH_FILE "FLUSH"
  65. #endif