1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef XENBUS_H__ 4 #define XENBUS_H__ 5 6 #include <xen/interface/xen.h> 7 #include <xen/interface/io/xenbus.h> 8 9 typedef unsigned long xenbus_transaction_t; 10 #define XBT_NIL ((xenbus_transaction_t)0) 11 12 extern u32 xenbus_evtchn; 13 14 /* Initialize the XenBus system. */ 15 void init_xenbus(void); 16 /* Finalize the XenBus system. */ 17 void fini_xenbus(void); 18 19 /** 20 * xenbus_read() - Read the value associated with a path. 21 * 22 * Returns a malloc'd error string on failure and sets *value to NULL. 23 * On success, *value is set to a malloc'd copy of the value. 24 */ 25 char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value); 26 27 char *xenbus_wait_for_state_change(const char *path, XenbusState *state); 28 char *xenbus_switch_state(xenbus_transaction_t xbt, const char *path, 29 XenbusState state); 30 31 /** 32 * xenbus_write() - Associates a value with a path. 33 * 34 * Returns a malloc'd error string on failure. 35 */ 36 char *xenbus_write(xenbus_transaction_t xbt, const char *path, 37 const char *value); 38 39 /** 40 * xenbus_rm() - Removes the value associated with a path. 41 * 42 * Returns a malloc'd error string on failure. 43 */ 44 char *xenbus_rm(xenbus_transaction_t xbt, const char *path); 45 46 /** 47 * xenbus_ls() - List the contents of a directory. 48 * 49 * Returns a malloc'd error string on failure and sets *contents to NULL. 50 * On success, *contents is set to a malloc'd array of pointers to malloc'd 51 * strings. The array is NULL terminated. May block. 52 */ 53 char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents); 54 55 /** 56 * xenbus_get_perms() - Reads permissions associated with a path. 57 * 58 * Returns a malloc'd error string on failure and sets *value to NULL. 59 * On success, *value is set to a malloc'd copy of the value. 60 */ 61 char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value); 62 63 /** 64 * xenbus_set_perms() - Sets the permissions associated with a path. 65 * 66 * Returns a malloc'd error string on failure. 67 */ 68 char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom, 69 char perm); 70 71 /** 72 * xenbus_transaction_start() - Start a xenbus transaction. 73 * 74 * Returns the transaction in xbt on success or a malloc'd error string 75 * otherwise. 76 */ 77 char *xenbus_transaction_start(xenbus_transaction_t *xbt); 78 79 /** 80 * xenbus_transaction_end() - End a xenbus transaction. 81 * 82 * Returns a malloc'd error string if it fails. Abort says whether the 83 * transaction should be aborted. 84 * Returns 1 in *retry if the transaction should be retried. 85 */ 86 char *xenbus_transaction_end(xenbus_transaction_t xbt, int abort, 87 int *retry); 88 89 /** 90 * xenbus_read_integer() - Read path and parse it as an integer. 91 * 92 * Returns -1 on error. 93 */ 94 int xenbus_read_integer(const char *path); 95 96 /** 97 * xenbus_read_uuid() - Read path and parse it as 16 byte uuid. 98 * 99 * Returns 1 if read and parsing were successful, 0 if not 100 */ 101 int xenbus_read_uuid(const char *path, unsigned char uuid[16]); 102 103 /** 104 * xenbus_printf() - Contraction of snprintf and xenbus_write(path/node). 105 */ 106 char *xenbus_printf(xenbus_transaction_t xbt, 107 const char *node, const char *path, 108 const char *fmt, ...) 109 __attribute__((__format__(printf, 4, 5))); 110 111 /** 112 * xenbus_get_self_id() - Utility function to figure out our domain id 113 */ 114 domid_t xenbus_get_self_id(void); 115 116 #endif /* XENBUS_H__ */ 117