4 * Copyright (C) 2012 VMware, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 and no later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #ifndef _VMCI_HANDLE_ARRAY_H_
17 #define _VMCI_HANDLE_ARRAY_H_
19 #include <linux/vmw_vmci_defs.h>
20 #include <linux/limits.h>
21 #include <linux/types.h>
23 struct vmci_handle_arr {
28 struct vmci_handle entries[];
31 #define VMCI_HANDLE_ARRAY_HEADER_SIZE \
32 offsetof(struct vmci_handle_arr, entries)
33 /* Select a default capacity that results in a 64 byte sized array */
34 #define VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY 6
35 /* Make sure that the max array size can be expressed by a u32 */
36 #define VMCI_HANDLE_ARRAY_MAX_CAPACITY \
37 ((U32_MAX - VMCI_HANDLE_ARRAY_HEADER_SIZE - 1) / \
38 sizeof(struct vmci_handle))
40 struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity);
41 void vmci_handle_arr_destroy(struct vmci_handle_arr *array);
42 int vmci_handle_arr_append_entry(struct vmci_handle_arr **array_ptr,
43 struct vmci_handle handle);
44 struct vmci_handle vmci_handle_arr_remove_entry(struct vmci_handle_arr *array,
47 struct vmci_handle vmci_handle_arr_remove_tail(struct vmci_handle_arr *array);
49 vmci_handle_arr_get_entry(const struct vmci_handle_arr *array, u32 index);
50 bool vmci_handle_arr_has_entry(const struct vmci_handle_arr *array,
51 struct vmci_handle entry_handle);
52 struct vmci_handle *vmci_handle_arr_get_handles(struct vmci_handle_arr *array);
54 static inline u32 vmci_handle_arr_get_size(
55 const struct vmci_handle_arr *array)
61 #endif /* _VMCI_HANDLE_ARRAY_H_ */