api.lisp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. (in-package :hurd-translator)
  2. (defmacro %add-callback (name args doc &body body)
  3. "Add a new API classback function."
  4. `(progn
  5. (defgeneric ,name (translator ,@args)
  6. (:documentation ,doc))
  7. (defmethod ,name ((translator translator) ,@args)
  8. ,@(if (null body)
  9. (list `(declare (ignore translator ,@args)))
  10. body))))
  11. (%add-callback make-root-node (underlying-node underlying-stat)
  12. "Called when the translator wants to create the root node.
  13. 'underlying-stat' refers to the stat structure from the file
  14. where the translator is being set up. 'underlying-node' is the port to that file."
  15. (declare (ignore underlying-node))
  16. (make-instance 'node :stat underlying-stat))
  17. (%add-callback pathconf (node user what)
  18. "This is called when the io-pathconf RPC is called.
  19. 'what' refers to the type of information the user wants,
  20. please see common/pathconf.lisp. Return a number for success, NIL for invalid argument."
  21. (declare (ignore translator node user))
  22. (case what
  23. ((:link-max :max-canon :max-input
  24. :pipe-buf :vdisable :sock-maxbuf)
  25. -1)
  26. ((:name-max) 1024)
  27. ((:chown-restricted :no-trunc) 1)
  28. ((:prio-io :sync-io :async-io) 0)
  29. (:filesizebits 32)))
  30. (%add-callback allow-open-p (node user flags is-new-p)
  31. "'user' wants to open 'node' with flags 'flags', 'is-new-p' indicates that this is a newly created node. This should return T for success, NIL for operation not permitted and anything else for an error."
  32. (declare (ignore is-new-p))
  33. (when (flag-is-p flags :read)
  34. (unless (has-access-p node user :read)
  35. (return-from allow-open-p nil)))
  36. (when (flag-is-p flags :write)
  37. (unless (has-access-p node user :write)
  38. (return-from allow-open-p nil)))
  39. (when (flag-is-p flags :exec)
  40. (unless (has-access-p node user :exec)
  41. (return-from allow-open-p nil)))
  42. t)
  43. (%add-callback chmod-file (node user mode)
  44. "The user is attempting to 'chmod' node with the mode permission bits. Return T for success, NIL for not permitted, anything else, a specific error."
  45. (cond
  46. ((is-owner-p node user)
  47. (copy-perms mode (stat node))
  48. t)
  49. (t nil)))
  50. (%add-callback chown-file (node user uid gid)
  51. "The user is attempting to 'chown' node with uid and gid. Return T for success, NIL for operation not permitted or a specific error."
  52. (cond
  53. ((is-owner-p node user)
  54. (when (valid-id-p uid)
  55. (setf (stat-get (stat node) 'st-uid) uid))
  56. (when (valid-id-p gid)
  57. (setf (stat-get (stat node) 'st-gid) gid))
  58. t)
  59. (t nil)))
  60. (%add-callback utimes-file (node user atime mtime)
  61. "The user is attempting to change the access and modification time of the node. Both 'atime' and 'mtime' are time-value objects. 'atime' or 'mtime' can also be +now-time-value+.
  62. Using (setf (stat-get (stat node) 'st-mtime) mtime) will do it for you in both cases.
  63. Return T for success, NIL for operation not permitted or a specific error for other conditions."
  64. (cond
  65. ((is-owner-p node user)
  66. (when atime
  67. (setf (stat-get (stat node) 'st-atime) atime))
  68. (when mtime
  69. (setf (stat-get (stat node) 'st-mtime) mtime))
  70. t)
  71. (t nil)))
  72. (%add-callback directory-lookup (node user filename)
  73. "This must return the node with the name 'filename' in the directory 'node', NIL when it is not found.")
  74. (%add-callback create-file (node user filename mode)
  75. "The user wants to create a file on the directory 'node' with name 'filename' and mode 'mode'. Return a new node or NIL for operation not permitted.")
  76. (%add-callback number-of-entries (node user)
  77. "This must return the number of entries in the directory 'node' from the 'user' point of view."
  78. (declare (ignore node user))
  79. 0)
  80. (%add-callback get-entries (node user start end)
  81. "This sould return a list of dirent objects representing the contents of the directory 'node' from 'start' to 'end' (index is zero based).")
  82. (%add-callback allow-author-change-p (node user author)
  83. "User wants to change the file's author, return T if it is ok, NIL for not permitted."
  84. (declare (ignore author))
  85. (is-owner-p node user))
  86. (%add-callback create-directory (node user name mode)
  87. "The user wants to create a directory in the directory 'node' with 'name' and 'mode'.
  88. Return T for success, NIL if don't permitted or a specific error.")
  89. (%add-callback remove-directory-entry (node user name)
  90. "The user wants to remove an entry named 'name' from the directory 'node'.
  91. Return T for success, NIL for not permitted or a specific error.")
  92. (%add-callback read-file (node user start amount stream)
  93. "User wants to read 'amount' bytes starting at 'start'. These bytes should be written to the stream 'stream'. Return T in case of success, NIL for not permitted.")
  94. (%add-callback sync-file (node user wait-p omit-metadata-p)
  95. "User wants to sync the contents in node. 'wait-p' indicates the user wants to wait. 'omit-metadata-p' indicates we must omit the update of the file metadata (like stat information).
  96. Return T for success, NIL for unsupported operation."
  97. (declare (ignore translator node user wait-p omit-metadata-p))
  98. t)
  99. (%add-callback sync-fs (user wait-p)
  100. "User wants to sync the entire filesystem. 'wait-p' indicates the user wants to wait for it. Return T for success, NIL for unsupported operation."
  101. (declare (ignore translator user wait-p do-children-p))
  102. t)
  103. (%add-callback write-file (node user offset stream amount)
  104. "The user wants to write the bytes in the input stream 'stream' starting at 'offset'. 'amount' indicates number of bytes in the stream.
  105. Return T for success, NIL for not permitted or a specific error.")
  106. (%add-callback drop-node (node)
  107. "The 'node' has no more references, drop it.")
  108. (%add-callback report-access (node user)
  109. "This should return a list of permitted access modes for 'user'.
  110. Permitted modes are: :read :write :exec."
  111. (let ((ret))
  112. (when (has-access-p node user :read)
  113. (push :read ret))
  114. (when (has-access-p node user :write)
  115. (push :write ret))
  116. (when (has-access-p node user :exec)
  117. (push :exec ret))
  118. ret))
  119. (%add-callback refresh-statfs (user)
  120. "The statfs translator field must be updated for 'user'.
  121. Return T for success, NIL for unsupported operation."
  122. (declare (ignore translator user))
  123. t)
  124. (%add-callback file-change-size (node user new-size)
  125. "The user wants to change node size to 'new-size'.
  126. Return T on success, NIL for unsupported operation or a specific error."
  127. (declare (ignore translator node user new-size))
  128. t)
  129. (%add-callback file-rename (user old-dir old-name new-dir new-name)
  130. "Rename file 'old-name' from 'old-dir' to 'new-name' in 'new-dir'.
  131. Return T for success, NIL for unsupported, or some other error code for other conditions.")
  132. (%add-callback shutdown ()
  133. "Shutdown the translator.")
  134. (%add-callback create-anonymous-file (node user mode)
  135. "Create an anonymous file related to directory 'node'.
  136. Return NIL for unsupported operation.")
  137. (%add-callback create-hard-link (dir user node name)
  138. "Create an hard link in directory with 'name' pointing to 'node'.
  139. Return T for success, NIL for not permitted or some specific error.")
  140. (%add-callback block-read (node user)
  141. "Block until we can read data from node.
  142. Return T when this is possible, NIL otherwise."
  143. (declare (ignore translator node user))
  144. t)
  145. (%add-callback block-write (node user)
  146. "Block until we can write data to node.
  147. Return T when this is possible, NIL otherwise."
  148. (declare (ignore translator node user))
  149. t)
  150. (%add-callback set-options (new-options)
  151. "Define a new set of translator options."
  152. (setf (options translator) new-options)
  153. ; Inform translator about option changes.
  154. (options-changed translator))
  155. (%add-callback options-changed ()
  156. "Indicates that translator options have changed. You don't need to implement this if you implement 'set-options'.")
  157. (%add-callback create-symlink (node user target)
  158. "Turn 'node' into a symlink to 'target'. Return T for success, NIL otherwise."
  159. (when (is-owner-p node user)
  160. (setf (link node) target)
  161. t))
  162. (%add-callback allow-link-p (node user)
  163. "Return T to allow reading from the symlink 'node' to 'user', NIL otherwise."
  164. (has-access-p node user :read))
  165. (%add-callback create-block (node user device)
  166. "Turn 'node' into a block device with device-id 'device'. Return T for success, NIL otherwise.")
  167. (%add-callback create-character (node user device)
  168. "Turn 'node' into a character device with device-id 'device'. Return T for success, NIL otherwise.")
  169. (%add-callback create-fifo (node user)
  170. "Turn 'node' into a fifo. Return T for success, NIL otherwise.")
  171. (%add-callback create-socket (node user)
  172. "Turn 'node' into a socket. Return T for success, NIL otherwise.")
  173. (%add-callback refresh-node (node user)
  174. "'node' will be accessed by 'user'. Please update its metadata.")
  175. (%add-callback report-seek (node user new-offset)
  176. "'user' seek the file 'node' to 'new-offset'.")
  177. (%add-callback report-new-user (node)
  178. "'node' is now being used.")
  179. (%add-callback report-no-users (node)
  180. "'node' is now not being used.")
  181. (defmacro define-callback (name trans-type args &body body)
  182. "Defines one the api callbacks defined above."
  183. `(defmethod ,name ((translator ,trans-type) ,@args)
  184. ,@body))