xref: /titanic_50/usr/src/lib/libcmdutils/libcmdutils.h (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*da6c28aaSamw  * Common Development and Distribution License (the "License").
6*da6c28aaSamw  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Declarations for the functions in libcmdutils.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_LIBCMDUTILS_H
317c478bd9Sstevel@tonic-gate #define	_LIBCMDUTILS_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * This is a private header file.  Applications should not directly include
377c478bd9Sstevel@tonic-gate  * this file.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
40*da6c28aaSamw #include <stdio.h>
41*da6c28aaSamw #include <unistd.h>
42*da6c28aaSamw #include <stdlib.h>
43*da6c28aaSamw #include <errno.h>
44*da6c28aaSamw #include <fcntl.h>
45*da6c28aaSamw #include <limits.h>
46*da6c28aaSamw #include <libintl.h>
47*da6c28aaSamw #include <string.h>
48*da6c28aaSamw #include <dirent.h>
49*da6c28aaSamw #include <attr.h>
507c478bd9Sstevel@tonic-gate #include <sys/avl.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
52*da6c28aaSamw #include <sys/stat.h>
53*da6c28aaSamw #include <sys/mman.h>
54*da6c28aaSamw #include <libnvpair.h>
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
577c478bd9Sstevel@tonic-gate extern "C" {
587c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate 
60*da6c28aaSamw /* extended system attribute support */
61*da6c28aaSamw #define	_NOT_SATTR	0
62*da6c28aaSamw #define	_RO_SATTR	1
63*da6c28aaSamw #define	_RW_SATTR	2
64*da6c28aaSamw 
65*da6c28aaSamw #define	MAXMAPSIZE	(1024*1024*8)	/* map at most 8MB */
66*da6c28aaSamw #define	SMALLFILESIZE	(32*1024)	/* don't use mmap on little file */
67*da6c28aaSamw #define	ISREG(A)	(((A).st_mode & S_IFMT) == S_IFREG)
68*da6c28aaSamw 
697c478bd9Sstevel@tonic-gate /* avltree */
707c478bd9Sstevel@tonic-gate #define	OFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* Type used for a node containing a device id and inode number */
737c478bd9Sstevel@tonic-gate typedef struct tree_node {
747c478bd9Sstevel@tonic-gate 	dev_t		node_dev;
757c478bd9Sstevel@tonic-gate 	ino_t		node_ino;
767c478bd9Sstevel@tonic-gate 	avl_node_t	avl_link;
777c478bd9Sstevel@tonic-gate } tree_node_t;
787c478bd9Sstevel@tonic-gate 
79*da6c28aaSamw 
80*da6c28aaSamw 		/* extended system attribute support */
81*da6c28aaSamw 
82*da6c28aaSamw /* Determine if a file is the name of an extended system attribute file */
83*da6c28aaSamw extern int sysattr_type(char *);
84*da6c28aaSamw 
85*da6c28aaSamw /* Determine if the underlying file system supports system attributes */
86*da6c28aaSamw extern int sysattr_support(char *, int);
87*da6c28aaSamw 
88*da6c28aaSamw /* Copies the content of the source file to the target file */
89*da6c28aaSamw extern int writefile(int, int, char *, char *, char *, char *,
90*da6c28aaSamw struct stat *, struct stat *);
91*da6c28aaSamw 
92*da6c28aaSamw /* Gets file descriptors of the source and target attribute files */
93*da6c28aaSamw extern int get_attrdirs(int, int, char *, int *, int *);
94*da6c28aaSamw 
95*da6c28aaSamw /* Move extended attribute and extended system attribute */
96*da6c28aaSamw extern int mv_xattrs(char *, char *, char *, int, int);
97*da6c28aaSamw 
98*da6c28aaSamw /* Returns non default extended system attribute list */
99*da6c28aaSamw extern nvlist_t *sysattr_list(char *, int, char *);
100*da6c28aaSamw 
101*da6c28aaSamw 
102*da6c28aaSamw 
103*da6c28aaSamw 		/* avltree */
104*da6c28aaSamw 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * Used to compare two nodes.  We are attempting to match the 1st
1077c478bd9Sstevel@tonic-gate  * argument (node) against the 2nd argument (a node which
1087c478bd9Sstevel@tonic-gate  * is already in the search tree).
1097c478bd9Sstevel@tonic-gate  */
110*da6c28aaSamw 
1117c478bd9Sstevel@tonic-gate extern int tnode_compare(const void *, const void *);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * Used to add a single node (containing the input device id and
1157c478bd9Sstevel@tonic-gate  * inode number) to the specified search tree.  The calling
1167c478bd9Sstevel@tonic-gate  * application must set the tree pointer to NULL before calling
1177c478bd9Sstevel@tonic-gate  * add_tnode() for the first time.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate extern int add_tnode(avl_tree_t **, dev_t, ino_t);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * Used to destroy a whole tree (all nodes) without rebalancing.
1237c478bd9Sstevel@tonic-gate  * The calling application is responsible for setting the tree
1247c478bd9Sstevel@tonic-gate  * pointer to NULL upon return.
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate extern void destroy_tree(avl_tree_t *);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #endif /* _LIBCMDUTILS_H */
133