fusd_msg.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. *
  3. * Copyright (c) 2003 The Regents of the University of California. All
  4. * rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * - Neither the name of the University nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  20. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. */
  30. /*
  31. * FUSD: the Framework for User-Space Devices
  32. *
  33. * Defines the interface between the kernel module and userspace library.
  34. *
  35. */
  36. #ifndef __FUSD_MSG_H__
  37. #define __FUSD_MSG_H__
  38. /* filenames */
  39. #define DEFAULT_DEV_ROOT "/dev/"
  40. #define FUSD_CONTROL_FILENAME "fusd/control"
  41. #define FUSD_STATUS_FILENAME "fusd/status"
  42. #define FUSD_CONTROL_DEVNAME DEFAULT_DEV_ROOT FUSD_CONTROL_FILENAME
  43. #define FUSD_STATUS_DEVNAME DEFAULT_DEV_ROOT FUSD_STATUS_FILENAME
  44. /* ioctl number to tell FUSD status device to return binary info */
  45. #define FUSD_STATUS_USE_BINARY _IO('F', 100)
  46. /* constants */
  47. #define FUSD_MAX_NAME_LENGTH 47 /* 47, to avoid expanding union size */
  48. /* commands */
  49. #define FUSD_REGISTER_DEVICE 0 /* device registration */
  50. #define FUSD_UNREGISTER_DEVICE 1 /* device unregistration */
  51. /* these two must have successive numbers */
  52. #define FUSD_FOPS_CALL 2 /* synchronous round-trip call: request */
  53. #define FUSD_FOPS_REPLY (FUSD_FOPS_CALL + 1)
  54. /* these two must have successive numbers */
  55. #define FUSD_FOPS_NONBLOCK 4 /* call that does not block for a reply */
  56. #define FUSD_FOPS_NONBLOCK_REPLY (FUSD_FOPS_NONBLOCK + 1)
  57. #define FUSD_FOPS_CALL_DROPREPLY 6 /* call that doesn't want a reply */
  58. /* subcommands */
  59. #define FUSD_OPEN 100
  60. #define FUSD_CLOSE 101
  61. #define FUSD_READ 102
  62. #define FUSD_WRITE 103
  63. #define FUSD_IOCTL 104
  64. #define FUSD_POLL_DIFF 105
  65. #define FUSD_UNBLOCK 106
  66. #define FUSD_MMAP 107
  67. /* other constants */
  68. #define FUSD_MSG_MAGIC 0x7a6b93cd
  69. #pragma pack(1)
  70. /* user->kernel: register a device */
  71. typedef struct {
  72. char name[FUSD_MAX_NAME_LENGTH+1];
  73. char clazz[FUSD_MAX_NAME_LENGTH+1];
  74. char devname[FUSD_MAX_NAME_LENGTH+1];
  75. mode_t mode;
  76. void *device_info;
  77. } register_msg_t;
  78. /* kernel->user: fops request message (common data) */
  79. typedef struct {
  80. pid_t pid;
  81. uid_t uid;
  82. gid_t gid;
  83. unsigned long flags; /* flags from file struct */
  84. void *device_info; /* device info */
  85. void *private_info; /* file info */
  86. /* parameters and return values for various calls. should be a
  87. * union but it just makes things too complex and doesn't save all
  88. * that much memory anyway */
  89. ssize_t retval;
  90. unsigned long length;
  91. unsigned long offset;
  92. unsigned int cmd; /* ioctl cmd, poll_diff cached_state */
  93. /* mmap parameters */
  94. unsigned long mmprot;
  95. unsigned long mmflags;
  96. unsigned long mmoffset;
  97. union {
  98. unsigned long arg; /* ioctl */
  99. void *ptr_arg;
  100. } arg;
  101. /* the following are cookies that have meaning internal to the kernel
  102. * but must be returned, untouched, by userspace */
  103. void *fusd_file;
  104. long transid;
  105. int hint;
  106. } fops_msg_t;
  107. /* the message struct written to FUSD control channel */
  108. typedef struct {
  109. int magic;
  110. short int cmd;
  111. short int subcmd;
  112. char *data; /* yes, it's slightly inefficient to push this useless
  113. * pointer between user and kernel space, but it makes
  114. * it much easier to have a pointer available in this
  115. * structure that both the kernel and userlib can make
  116. * their own use of. */
  117. int datalen;
  118. union {
  119. register_msg_t register_msg; /* device registration (U->K) */
  120. fops_msg_t fops_msg; /* U->K and K->U fops messages */
  121. } parm;
  122. } fusd_msg_t;
  123. /* structure read from FUSD binary status device */
  124. typedef struct {
  125. char name[FUSD_MAX_NAME_LENGTH+1];
  126. int zombie;
  127. pid_t pid;
  128. int num_open;
  129. } fusd_status_t;
  130. #pragma pack()
  131. #endif /* __FUSD_MSG_H__ */