+/** Arguments passed to each afs callback. */
+struct afs_callback_arg {
+ /** The local socket connecting afs and the command handler. */
+ int fd;
+ /** Callback-specific data. */
+ struct osl_object query;
+ /** Will be written on band SBD_OUTPUT, fully buffered. */
+ struct para_buffer pbout;
+ /**
+ * Convenience pointer for the deserialized parse result.
+ *
+ * Most afs command handlers call \ref send_lls_callback_request() to
+ * serialize the parse result of the subcommand and pass it to the
+ * callback. In afs context a pointer to the deserialized parse result
+ * is stored here.
+ */
+ struct lls_parse_result *lpr;
+};
+
+/**
+ * Afs command handlers run as a process which is not related to the afs
+ * process, i.e. they can not change the address space of afs directly.
+ * Therefore afs commands typically consist of two functions: The command
+ * handler and the corresponding callback function that runs in afs context.
+ *
+ * \sa \ref send_callback_request().
+ */
+typedef int afs_callback(struct afs_callback_arg *aca);
+
+/**
+ * Some AFS callbacks need to send data back to the command handler. Pointers
+ * to this type of function are passed to \ref send_callback_request() and
+ * related functions to dispatch the data in the command handler process.
+ */
+typedef int callback_result_handler(struct osl_object *result, uint8_t band, void *private);
+int afs_cb_result_handler(struct osl_object *result, uint8_t band, void *private);
+int pass_buffer_as_shm(int fd, uint8_t band, const char *buf, size_t size);
+
+/** Structure passed to the AFS max_size handler. */
+struct afs_max_size_handler_data {
+ /** Local socket connecting the command handler and the AFS process. */
+ int fd;
+ /** The sideband designator for this data packet. */
+ uint8_t band;
+};
+
+/**
+ * Standard max_size handler for AFS commands.
+ *
+ * \param buf Contains (part of) the AFS command output.
+ * \param size The number of bytes in \a buf.
+ * \param private Pointer to a \ref afs_max_size_handler_data structure.
+ *
+ * Whenever the output of an AFS command exceeds the maximal size of a shared
+ * memory area, the max size handler of the para_buffer which holds the command
+ * output is called with \a private being a pointer to a structure of type
+ * afs_max_size_handler_data.
+ *
+ * \return The return value of the underlying call to \ref
+ * pass_buffer_as_shm().
+ */
+_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private)
+{
+ struct afs_max_size_handler_data *amshd = private;
+ return pass_buffer_as_shm(amshd->fd, amshd->band, buf, size);
+}
+
+__noreturn void afs_init(int socket_fd);
+__must_check int afs_event(enum afs_events event, struct para_buffer *pb,