xref: /freebsd/sys/contrib/xen/hypfs.h (revision 8eb2bee6c0f4957c6c1cea826e59cda4d18a2a64)
1 /******************************************************************************
2  * Xen Hypervisor Filesystem
3  *
4  * Copyright (c) 2019, SUSE Software Solutions Germany GmbH
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  */
25 
26 #ifndef __XEN_PUBLIC_HYPFS_H__
27 #define __XEN_PUBLIC_HYPFS_H__
28 
29 #include "xen.h"
30 
31 /*
32  * Definitions for the __HYPERVISOR_hypfs_op hypercall.
33  */
34 
35 /* Highest version number of the hypfs interface currently defined. */
36 #define XEN_HYPFS_VERSION      1
37 
38 /* Maximum length of a path in the filesystem. */
39 #define XEN_HYPFS_MAX_PATHLEN  1024
40 
41 struct xen_hypfs_direntry {
42     uint8_t type;
43 #define XEN_HYPFS_TYPE_DIR     0
44 #define XEN_HYPFS_TYPE_BLOB    1
45 #define XEN_HYPFS_TYPE_STRING  2
46 #define XEN_HYPFS_TYPE_UINT    3
47 #define XEN_HYPFS_TYPE_INT     4
48 #define XEN_HYPFS_TYPE_BOOL    5
49     uint8_t encoding;
50 #define XEN_HYPFS_ENC_PLAIN    0
51 #define XEN_HYPFS_ENC_GZIP     1
52     uint16_t pad;              /* Returned as 0. */
53     uint32_t content_len;      /* Current length of data. */
54     uint32_t max_write_len;    /* Max. length for writes (0 if read-only). */
55 };
56 typedef struct xen_hypfs_direntry xen_hypfs_direntry_t;
57 
58 struct xen_hypfs_dirlistentry {
59     xen_hypfs_direntry_t e;
60     /* Offset in bytes to next entry (0 == this is the last entry). */
61     uint16_t off_next;
62     /* Zero terminated entry name, possibly with some padding for alignment. */
63     char name[XEN_FLEX_ARRAY_DIM];
64 };
65 
66 /*
67  * Hypercall operations.
68  */
69 
70 /*
71  * XEN_HYPFS_OP_get_version
72  *
73  * Read highest interface version supported by the hypervisor.
74  *
75  * arg1 - arg4: all 0/NULL
76  *
77  * Possible return values:
78  * >0: highest supported interface version
79  * <0: negative Xen errno value
80  */
81 #define XEN_HYPFS_OP_get_version     0
82 
83 /*
84  * XEN_HYPFS_OP_read
85  *
86  * Read a filesystem entry.
87  *
88  * Returns the direntry and contents of an entry in the buffer supplied by the
89  * caller (struct xen_hypfs_direntry with the contents following directly
90  * after it).
91  * The data buffer must be at least the size of the direntry returned. If the
92  * data buffer was not large enough for all the data -ENOBUFS and no entry
93  * data is returned, but the direntry will contain the needed size for the
94  * returned data.
95  * The format of the contents is according to its entry type and encoding.
96  * The contents of a directory are multiple struct xen_hypfs_dirlistentry
97  * items.
98  *
99  * arg1: XEN_GUEST_HANDLE(path name)
100  * arg2: length of path name (including trailing zero byte)
101  * arg3: XEN_GUEST_HANDLE(data buffer written by hypervisor)
102  * arg4: data buffer size
103  *
104  * Possible return values:
105  * 0: success
106  * <0 : negative Xen errno value
107  */
108 #define XEN_HYPFS_OP_read              1
109 
110 /*
111  * XEN_HYPFS_OP_write_contents
112  *
113  * Write contents of a filesystem entry.
114  *
115  * Writes an entry with the contents of a buffer supplied by the caller.
116  * The data type and encoding can't be changed. The size can be changed only
117  * for blobs and strings.
118  *
119  * arg1: XEN_GUEST_HANDLE(path name)
120  * arg2: length of path name (including trailing zero byte)
121  * arg3: XEN_GUEST_HANDLE(content buffer read by hypervisor)
122  * arg4: content buffer size
123  *
124  * Possible return values:
125  * 0: success
126  * <0 : negative Xen errno value
127  */
128 #define XEN_HYPFS_OP_write_contents    2
129 
130 #endif /* __XEN_PUBLIC_HYPFS_H__ */
131