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 /*
27 * Declarations for the functions in libcmdutils.
28 */
29
30 #ifndef _LIBCMDUTILS_H
31 #define _LIBCMDUTILS_H
32
33 #pragma ident "%Z%%M% %I% %E% SMI"
34
35 /*
36 * This is a private header file. Applications should not directly include
37 * this file.
38 */
39
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <stdlib.h>
43 #include <errno.h>
44 #include <fcntl.h>
45 #include <limits.h>
46 #include <libintl.h>
47 #include <string.h>
48 #include <dirent.h>
49 #include <attr.h>
50 #include <sys/avl.h>
51 #include <sys/types.h>
52 #include <sys/stat.h>
53 #include <sys/mman.h>
54 #include <libnvpair.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /* extended system attribute support */
61 #define _NOT_SATTR 0
62 #define _RO_SATTR 1
63 #define _RW_SATTR 2
64
65 #define MAXMAPSIZE (1024*1024*8) /* map at most 8MB */
66 #define SMALLFILESIZE (32*1024) /* don't use mmap on little file */
67 #define ISREG(A) (((A).st_mode & S_IFMT) == S_IFREG)
68
69 /* avltree */
70 #define OFFSETOF(s, m) ((size_t)(&(((s *)0)->m)))
71
72 /* Type used for a node containing a device id and inode number */
73 typedef struct tree_node {
74 dev_t node_dev;
75 ino_t node_ino;
76 avl_node_t avl_link;
77 } tree_node_t;
78
79
80 /* extended system attribute support */
81
82 /* Determine if a file is the name of an extended system attribute file */
83 extern int sysattr_type(char *);
84
85 /* Determine if the underlying file system supports system attributes */
86 extern int sysattr_support(char *, int);
87
88 /* Copies the content of the source file to the target file */
89 extern int writefile(int, int, char *, char *, char *, char *,
90 struct stat *, struct stat *);
91
92 /* Gets file descriptors of the source and target attribute files */
93 extern int get_attrdirs(int, int, char *, int *, int *);
94
95 /* Move extended attribute and extended system attribute */
96 extern int mv_xattrs(char *, char *, char *, int, int);
97
98 /* Returns non default extended system attribute list */
99 extern nvlist_t *sysattr_list(char *, int, char *);
100
101
102
103 /* avltree */
104
105 /*
106 * Used to compare two nodes. We are attempting to match the 1st
107 * argument (node) against the 2nd argument (a node which
108 * is already in the search tree).
109 */
110
111 extern int tnode_compare(const void *, const void *);
112
113 /*
114 * Used to add a single node (containing the input device id and
115 * inode number) to the specified search tree. The calling
116 * application must set the tree pointer to NULL before calling
117 * add_tnode() for the first time.
118 */
119 extern int add_tnode(avl_tree_t **, dev_t, ino_t);
120
121 /*
122 * Used to destroy a whole tree (all nodes) without rebalancing.
123 * The calling application is responsible for setting the tree
124 * pointer to NULL upon return.
125 */
126 extern void destroy_tree(avl_tree_t *);
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif /* _LIBCMDUTILS_H */