1 /* 2 * Copyright (c) 2019 SUSE Software Solutions Germany GmbH 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; 7 * version 2.1 of the License. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef XENHYPFS_H 18 #define XENHYPFS_H 19 20 #include <stdbool.h> 21 #include <stdint.h> 22 #include <sys/types.h> 23 24 /* Callers who don't care don't need to #include <xentoollog.h> */ 25 struct xentoollog_logger; 26 27 typedef struct xenhypfs_handle xenhypfs_handle; 28 29 enum xenhypfs_type { 30 xenhypfs_type_dir, 31 xenhypfs_type_blob, 32 xenhypfs_type_string, 33 xenhypfs_type_uint, 34 xenhypfs_type_int, 35 xenhypfs_type_bool, 36 }; 37 38 enum xenhypfs_encoding { 39 xenhypfs_enc_plain, 40 xenhypfs_enc_gzip 41 }; 42 43 struct xenhypfs_dirent { 44 char *name; 45 size_t size; 46 unsigned short type; 47 unsigned short encoding; 48 unsigned int flags; 49 #define XENHYPFS_FLAG_WRITABLE 0x00000001 50 }; 51 52 xenhypfs_handle *xenhypfs_open(struct xentoollog_logger *logger, 53 unsigned int open_flags); 54 int xenhypfs_close(xenhypfs_handle *fshdl); 55 56 /* 57 * Return the raw contents of a Xen hypfs entry and its dirent containing 58 * the size, type and encoding. 59 * Returned buffer and dirent should be freed via free(). 60 */ 61 void *xenhypfs_read_raw(xenhypfs_handle *fshdl, const char *path, 62 struct xenhypfs_dirent **dirent); 63 64 /* 65 * Return the contents of a Xen hypfs entry as a string. 66 * Returned buffer should be freed via free(). 67 */ 68 char *xenhypfs_read(xenhypfs_handle *fshdl, const char *path); 69 70 /* 71 * Return the contents of a Xen hypfs directory in form of an array of 72 * dirents. 73 * Returned buffer should be freed via free(). 74 */ 75 struct xenhypfs_dirent *xenhypfs_readdir(xenhypfs_handle *fshdl, 76 const char *path, 77 unsigned int *num_entries); 78 79 /* 80 * Write a Xen hypfs entry with a value. The value is converted from a string 81 * to the appropriate type. 82 */ 83 int xenhypfs_write(xenhypfs_handle *fshdl, const char *path, const char *val); 84 85 #endif /* XENHYPFS_H */ 86 87 /* 88 * Local variables: 89 * mode: C 90 * c-file-style: "BSD" 91 * c-basic-offset: 4 92 * tab-width: 4 93 * indent-tabs-mode: nil 94 * End: 95 */ 96