sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libcmdutils / libcmdutils.h
blob7c3d0ebbc10c5c0d4a0a807d96ac1e7f32a5da55
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 2013 RackTop Systems.
29 * Copyright 2016 Joyent, Inc.
33 * Declarations for the functions in libcmdutils.
36 #ifndef _LIBCMDUTILS_H
37 #define _LIBCMDUTILS_H
40 * This is a private header file. Applications should not directly include
41 * this file.
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <stdarg.h>
48 #include <errno.h>
49 #include <fcntl.h>
50 #include <limits.h>
51 #include <libintl.h>
52 #include <string.h>
53 #include <dirent.h>
54 #include <attr.h>
55 #include <sys/avl.h>
56 #include <sys/types.h>
57 #include <sys/stat.h>
58 #include <sys/mman.h>
59 #include <libnvpair.h>
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 /* extended system attribute support */
66 #define _NOT_SATTR 0
67 #define _RO_SATTR 1
68 #define _RW_SATTR 2
70 #define MAXMAPSIZE (1024*1024*8) /* map at most 8MB */
71 #define SMALLFILESIZE (32*1024) /* don't use mmap on little file */
73 /* avltree */
74 #define OFFSETOF(s, m) ((size_t)(&(((s *)0)->m)))
76 /* Type used for a node containing a device id and inode number */
77 typedef struct tree_node {
78 dev_t node_dev;
79 ino_t node_ino;
80 avl_node_t avl_link;
81 } tree_node_t;
84 /* extended system attribute support */
86 /* Determine if a file is the name of an extended system attribute file */
87 extern int sysattr_type(char *);
89 /* Determine if the underlying file system supports system attributes */
90 extern int sysattr_support(char *, int);
92 /* Copies the content of the source file to the target file */
93 extern int writefile(int, int, char *, char *, char *, char *,
94 struct stat *, struct stat *);
96 /* Gets file descriptors of the source and target attribute files */
97 extern int get_attrdirs(int, int, char *, int *, int *);
99 /* Move extended attribute and extended system attribute */
100 extern int mv_xattrs(char *, char *, char *, int, int);
102 /* Returns non default extended system attribute list */
103 extern nvlist_t *sysattr_list(char *, int, char *);
107 /* avltree */
110 * Used to compare two nodes. We are attempting to match the 1st
111 * argument (node) against the 2nd argument (a node which
112 * is already in the search tree).
115 extern int tnode_compare(const void *, const void *);
118 * Used to add a single node (containing the input device id and
119 * inode number) to the specified search tree. The calling
120 * application must set the tree pointer to NULL before calling
121 * add_tnode() for the first time.
123 extern int add_tnode(avl_tree_t **, dev_t, ino_t);
126 * Used to destroy a whole tree (all nodes) without rebalancing.
127 * The calling application is responsible for setting the tree
128 * pointer to NULL upon return.
130 extern void destroy_tree(avl_tree_t *);
134 /* user/group id helpers */
137 * Used to get the next available user id in given range.
139 extern int findnextuid(uid_t, uid_t, uid_t *);
142 * Used to get the next available group id in given range.
144 extern int findnextgid(gid_t, gid_t, gid_t *);
148 /* dynamic string utilities */
150 typedef struct custr custr_t;
153 * Allocate and free a "custr_t" dynamic string object. Returns 0 on success
154 * and -1 otherwise.
156 extern int custr_alloc(custr_t **);
157 extern void custr_free(custr_t *);
160 * Allocate a "custr_t" dynamic string object that operates on a fixed external
161 * buffer.
163 extern int custr_alloc_buf(custr_t **, void *, size_t);
166 * Append a single character, or a NUL-terminated string of characters, to a
167 * dynamic string. Returns 0 on success and -1 otherwise. The dynamic string
168 * will be unmodified if the function returns -1.
170 extern int custr_appendc(custr_t *, char);
171 extern int custr_append(custr_t *, const char *);
174 * Append a format string and arguments as though the contents were being parsed
175 * through snprintf. Returns 0 on success and -1 otherwise. The dynamic string
176 * will be unmodified if the function returns -1.
178 extern int custr_append_printf(custr_t *, const char *, ...);
179 extern int custr_append_vprintf(custr_t *, const char *, va_list);
182 * Determine the length in bytes, not including the NUL terminator, of the
183 * dynamic string.
185 extern size_t custr_len(custr_t *);
188 * Clear the contents of a dynamic string. Does not free the underlying
189 * memory.
191 extern void custr_reset(custr_t *);
194 * Retrieve a const pointer to a NUL-terminated string version of the contents
195 * of the dynamic string. Storage for this string should not be freed, and
196 * the pointer will be invalidated by any mutations to the dynamic string.
198 extern const char *custr_cstr(custr_t *str);
200 #ifdef __cplusplus
202 #endif
204 #endif /* _LIBCMDUTILS_H */