fusd_msg.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /* user->kernel: register a device */
  70. typedef struct {
  71. char name[FUSD_MAX_NAME_LENGTH+1];
  72. char clazz[FUSD_MAX_NAME_LENGTH+1];
  73. char devname[FUSD_MAX_NAME_LENGTH+1];
  74. mode_t mode;
  75. void *device_info;
  76. } register_msg_t;
  77. /* kernel->user: fops request message (common data) */
  78. typedef struct {
  79. pid_t pid;
  80. uid_t uid;
  81. gid_t gid;
  82. unsigned int flags; /* flags from file struct */
  83. void *device_info; /* device info */
  84. void *private_info; /* file info */
  85. /* parameters and return values for various calls. should be a
  86. * union but it just makes things too complex and doesn't save all
  87. * that much memory anyway */
  88. ssize_t retval;
  89. size_t length;
  90. loff_t offset;
  91. unsigned int cmd; /* ioctl cmd, poll_diff cached_state */
  92. union {
  93. unsigned long arg; /* ioctl */
  94. void *ptr_arg;
  95. } arg;
  96. /* the following are cookies that have meaning internal to the kernel
  97. * but must be returned, untouched, by userspace */
  98. void *fusd_file;
  99. long transid;
  100. int hint;
  101. } fops_msg_t;
  102. /* the message struct written to FUSD control channel */
  103. typedef struct {
  104. int magic;
  105. short int cmd;
  106. short int subcmd;
  107. char *data; /* yes, it's slightly inefficient to push this useless
  108. * pointer between user and kernel space, but it makes
  109. * it much easier to have a pointer available in this
  110. * structure that both the kernel and userlib can make
  111. * their own use of. */
  112. int datalen;
  113. union {
  114. register_msg_t register_msg; /* device registration (U->K) */
  115. fops_msg_t fops_msg; /* U->K and K->U fops messages */
  116. } parm;
  117. } fusd_msg_t;
  118. /* structure read from FUSD binary status device */
  119. typedef struct {
  120. char name[FUSD_MAX_NAME_LENGTH+1];
  121. int zombie;
  122. pid_t pid;
  123. int num_open;
  124. } fusd_status_t;
  125. #endif /* __FUSD_MSG_H__ */