1 /*
2     Common routines between Xen store user library and daemon.
3     Copyright (C) 2005 Rusty Russell IBM Corporation
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef XENSTORE_LIB_H
20 #define XENSTORE_LIB_H
21 
22 #include <stddef.h>
23 #include <stdbool.h>
24 #include <limits.h>
25 #include <errno.h>
26 #include <stdint.h>
27 #include <xen/io/xs_wire.h>
28 
29 struct xs_permissions
30 {
31 	unsigned int id;
32 	unsigned int perms;	/* Bitmask of permissions. */
33 #define XS_PERM_NONE		0x00
34 #define XS_PERM_READ		0x01
35 #define XS_PERM_WRITE		0x02
36 	/* Internal use. */
37 #define XS_PERM_ENOENT_OK	0x04
38 #define XS_PERM_OWNER		0x08
39 #define XS_PERM_IGNORE		0x10
40 };
41 
42 /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
43 #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
44 
45 /* Path for various daemon things: env vars can override. */
46 const char *xs_daemon_rundir(void);
47 const char *xs_daemon_socket(void);
48 const char *xs_daemon_socket_ro(void);
49 
50 /* Convert strings to permissions.  False if a problem. */
51 bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
52 			 const char *strings);
53 
54 #endif /* XENSTORE_LIB_H */
55