xref: /titanic_50/usr/src/lib/libcmdutils/libcmdutils.h (revision 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Copyright (c) 2013 RackTop Systems.
27  */
28 
29 /*
30  * Declarations for the functions in libcmdutils.
31  */
32 
33 #ifndef	_LIBCMDUTILS_H
34 #define	_LIBCMDUTILS_H
35 
36 /*
37  * This is a private header file.  Applications should not directly include
38  * this file.
39  */
40 
41 #include <stdio.h>
42 #include <unistd.h>
43 #include <stdlib.h>
44 #include <errno.h>
45 #include <fcntl.h>
46 #include <limits.h>
47 #include <libintl.h>
48 #include <string.h>
49 #include <dirent.h>
50 #include <attr.h>
51 #include <sys/avl.h>
52 #include <sys/types.h>
53 #include <sys/stat.h>
54 #include <sys/mman.h>
55 #include <libnvpair.h>
56 
57 #ifdef	__cplusplus
58 extern "C" {
59 #endif
60 
61 /* extended system attribute support */
62 #define	_NOT_SATTR	0
63 #define	_RO_SATTR	1
64 #define	_RW_SATTR	2
65 
66 #define	MAXMAPSIZE	(1024*1024*8)	/* map at most 8MB */
67 #define	SMALLFILESIZE	(32*1024)	/* don't use mmap on little file */
68 #define	ISREG(A)	(((A).st_mode & S_IFMT) == S_IFREG)
69 
70 /* avltree */
71 #define	OFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
72 
73 /* Type used for a node containing a device id and inode number */
74 typedef struct tree_node {
75 	dev_t		node_dev;
76 	ino_t		node_ino;
77 	avl_node_t	avl_link;
78 } tree_node_t;
79 
80 
81 		/* extended system attribute support */
82 
83 /* Determine if a file is the name of an extended system attribute file */
84 extern int sysattr_type(char *);
85 
86 /* Determine if the underlying file system supports system attributes */
87 extern int sysattr_support(char *, int);
88 
89 /* Copies the content of the source file to the target file */
90 extern int writefile(int, int, char *, char *, char *, char *,
91 struct stat *, struct stat *);
92 
93 /* Gets file descriptors of the source and target attribute files */
94 extern int get_attrdirs(int, int, char *, int *, int *);
95 
96 /* Move extended attribute and extended system attribute */
97 extern int mv_xattrs(char *, char *, char *, int, int);
98 
99 /* Returns non default extended system attribute list */
100 extern nvlist_t *sysattr_list(char *, int, char *);
101 
102 
103 
104 		/* avltree */
105 
106 /*
107  * Used to compare two nodes.  We are attempting to match the 1st
108  * argument (node) against the 2nd argument (a node which
109  * is already in the search tree).
110  */
111 
112 extern int tnode_compare(const void *, const void *);
113 
114 /*
115  * Used to add a single node (containing the input device id and
116  * inode number) to the specified search tree.  The calling
117  * application must set the tree pointer to NULL before calling
118  * add_tnode() for the first time.
119  */
120 extern int add_tnode(avl_tree_t **, dev_t, ino_t);
121 
122 /*
123  * Used to destroy a whole tree (all nodes) without rebalancing.
124  * The calling application is responsible for setting the tree
125  * pointer to NULL upon return.
126  */
127 extern void destroy_tree(avl_tree_t *);
128 
129 
130 
131 		/* user/group id helpers */
132 
133 /*
134  * Used to get the next available user id in given range.
135  */
136 extern int findnextuid(uid_t, uid_t, uid_t *);
137 
138 /*
139  * Used to get the next available group id in given range.
140  */
141 extern int findnextgid(gid_t, gid_t, gid_t *);
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif /* _LIBCMDUTILS_H */
148