xref: /titanic_41/usr/src/lib/libcmdutils/libcmdutils.h (revision a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7b)
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
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * 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 /*
22da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*a7fe1d5bSAndy Stormont /*
26*a7fe1d5bSAndy Stormont  * Copyright (c) 2013 RackTop Systems.
27*a7fe1d5bSAndy Stormont  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Declarations for the functions in libcmdutils.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	_LIBCMDUTILS_H
347c478bd9Sstevel@tonic-gate #define	_LIBCMDUTILS_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * This is a private header file.  Applications should not directly include
387c478bd9Sstevel@tonic-gate  * this file.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
41da6c28aaSamw #include <stdio.h>
42da6c28aaSamw #include <unistd.h>
43da6c28aaSamw #include <stdlib.h>
44da6c28aaSamw #include <errno.h>
45da6c28aaSamw #include <fcntl.h>
46da6c28aaSamw #include <limits.h>
47da6c28aaSamw #include <libintl.h>
48da6c28aaSamw #include <string.h>
49da6c28aaSamw #include <dirent.h>
50da6c28aaSamw #include <attr.h>
517c478bd9Sstevel@tonic-gate #include <sys/avl.h>
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
53da6c28aaSamw #include <sys/stat.h>
54da6c28aaSamw #include <sys/mman.h>
55da6c28aaSamw #include <libnvpair.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
587c478bd9Sstevel@tonic-gate extern "C" {
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate 
61da6c28aaSamw /* extended system attribute support */
62da6c28aaSamw #define	_NOT_SATTR	0
63da6c28aaSamw #define	_RO_SATTR	1
64da6c28aaSamw #define	_RW_SATTR	2
65da6c28aaSamw 
66da6c28aaSamw #define	MAXMAPSIZE	(1024*1024*8)	/* map at most 8MB */
67da6c28aaSamw #define	SMALLFILESIZE	(32*1024)	/* don't use mmap on little file */
68da6c28aaSamw #define	ISREG(A)	(((A).st_mode & S_IFMT) == S_IFREG)
69da6c28aaSamw 
707c478bd9Sstevel@tonic-gate /* avltree */
717c478bd9Sstevel@tonic-gate #define	OFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /* Type used for a node containing a device id and inode number */
747c478bd9Sstevel@tonic-gate typedef struct tree_node {
757c478bd9Sstevel@tonic-gate 	dev_t		node_dev;
767c478bd9Sstevel@tonic-gate 	ino_t		node_ino;
777c478bd9Sstevel@tonic-gate 	avl_node_t	avl_link;
787c478bd9Sstevel@tonic-gate } tree_node_t;
797c478bd9Sstevel@tonic-gate 
80da6c28aaSamw 
81da6c28aaSamw 		/* extended system attribute support */
82da6c28aaSamw 
83da6c28aaSamw /* Determine if a file is the name of an extended system attribute file */
84da6c28aaSamw extern int sysattr_type(char *);
85da6c28aaSamw 
86da6c28aaSamw /* Determine if the underlying file system supports system attributes */
87da6c28aaSamw extern int sysattr_support(char *, int);
88da6c28aaSamw 
89da6c28aaSamw /* Copies the content of the source file to the target file */
90da6c28aaSamw extern int writefile(int, int, char *, char *, char *, char *,
91da6c28aaSamw struct stat *, struct stat *);
92da6c28aaSamw 
93da6c28aaSamw /* Gets file descriptors of the source and target attribute files */
94da6c28aaSamw extern int get_attrdirs(int, int, char *, int *, int *);
95da6c28aaSamw 
96da6c28aaSamw /* Move extended attribute and extended system attribute */
97da6c28aaSamw extern int mv_xattrs(char *, char *, char *, int, int);
98da6c28aaSamw 
99da6c28aaSamw /* Returns non default extended system attribute list */
100da6c28aaSamw extern nvlist_t *sysattr_list(char *, int, char *);
101da6c28aaSamw 
102da6c28aaSamw 
103da6c28aaSamw 
104da6c28aaSamw 		/* avltree */
105da6c28aaSamw 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Used to compare two nodes.  We are attempting to match the 1st
1087c478bd9Sstevel@tonic-gate  * argument (node) against the 2nd argument (a node which
1097c478bd9Sstevel@tonic-gate  * is already in the search tree).
1107c478bd9Sstevel@tonic-gate  */
111da6c28aaSamw 
1127c478bd9Sstevel@tonic-gate extern int tnode_compare(const void *, const void *);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Used to add a single node (containing the input device id and
1167c478bd9Sstevel@tonic-gate  * inode number) to the specified search tree.  The calling
1177c478bd9Sstevel@tonic-gate  * application must set the tree pointer to NULL before calling
1187c478bd9Sstevel@tonic-gate  * add_tnode() for the first time.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate extern int add_tnode(avl_tree_t **, dev_t, ino_t);
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * Used to destroy a whole tree (all nodes) without rebalancing.
1247c478bd9Sstevel@tonic-gate  * The calling application is responsible for setting the tree
1257c478bd9Sstevel@tonic-gate  * pointer to NULL upon return.
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate extern void destroy_tree(avl_tree_t *);
1287c478bd9Sstevel@tonic-gate 
129*a7fe1d5bSAndy Stormont 
130*a7fe1d5bSAndy Stormont 
131*a7fe1d5bSAndy Stormont 		/* user/group id helpers */
132*a7fe1d5bSAndy Stormont 
133*a7fe1d5bSAndy Stormont /*
134*a7fe1d5bSAndy Stormont  * Used to get the next available user id in given range.
135*a7fe1d5bSAndy Stormont  */
136*a7fe1d5bSAndy Stormont extern int findnextuid(uid_t, uid_t, uid_t *);
137*a7fe1d5bSAndy Stormont 
138*a7fe1d5bSAndy Stormont /*
139*a7fe1d5bSAndy Stormont  * Used to get the next available group id in given range.
140*a7fe1d5bSAndy Stormont  */
141*a7fe1d5bSAndy Stormont extern int findnextgid(gid_t, gid_t, gid_t *);
142*a7fe1d5bSAndy Stormont 
1437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate #endif
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #endif /* _LIBCMDUTILS_H */
148