xref: /openbsd/usr.sbin/mtree/mtree.h (revision ea7ffa33)
1 /*	$OpenBSD: mtree.h,v 1.14 2023/08/11 05:07:28 guenther Exp $	*/
2 /*	$NetBSD: mtree.h,v 1.7 1995/03/07 21:26:27 cgd Exp $	*/
3 
4 /*-
5  * Copyright (c) 1990, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)mtree.h	8.1 (Berkeley) 6/6/93
33  */
34 
35 #include <string.h>
36 #include <stdlib.h>
37 
38 #define	MTREE_O_FLAGS \
39 	(O_RDONLY | O_NONBLOCK | O_NOFOLLOW)
40 
41 #define	KEYDEFAULT \
42 	(F_GID | F_MODE | F_NLINK | F_SIZE | F_SLINK | F_TIME | F_UID)
43 
44 #define	ERROREXIT	1
45 #define	MISMATCHEXIT	2
46 
47 typedef struct _node {
48 	struct _node	*parent, *child;	/* up, down */
49 	struct _node	*prev, *next;		/* left, right */
50 	off_t	st_size;			/* size */
51 	struct timespec	st_mtim;		/* last modification time */
52 	u_int32_t cksum;			/* check sum */
53 	char	*md5digest;			/* MD5 digest */
54 	char	*rmd160digest;			/* RIPEMD-160 digest */
55 	char	*sha1digest;			/* SHA-1 digest */
56 	char	*sha256digest;			/* SHA-256 digest */
57 	char	*slink;				/* symbolic link reference */
58 	uid_t	st_uid;				/* uid */
59 	gid_t	st_gid;				/* gid */
60 #define	MBITS	(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
61 	mode_t	st_mode;			/* mode */
62 	nlink_t	st_nlink;			/* link count */
63 	u_int32_t file_flags;			/* file flags */
64 
65 #define	F_CKSUM		0x000001		/* checksum */
66 #define	F_DONE		0x000002		/* directory done */
67 #define	F_GID		0x000004		/* gid */
68 #define	F_GNAME		0x000008		/* group name */
69 #define	F_IGN		0x000010		/* ignore */
70 #define	F_MAGIC		0x000020		/* name has magic chars */
71 #define	F_MD5		0x000040		/* MD5 digest */
72 #define	F_MODE		0x000080		/* mode */
73 #define	F_NLINK		0x000100		/* number of links */
74 #define F_OPT		0x000200		/* existence optional */
75 #define	F_RMD160	0x000400		/* RIPEMD-160 digest */
76 #define	F_SHA1		0x000800		/* SHA-1 digest */
77 #define	F_SIZE		0x001000		/* size */
78 #define	F_SLINK		0x002000		/* link count */
79 #define	F_TIME		0x004000		/* modification time */
80 #define	F_TYPE		0x008000		/* file type */
81 #define	F_UID		0x010000		/* uid */
82 #define	F_UNAME		0x020000		/* user name */
83 #define	F_VISIT		0x040000		/* file visited */
84 #define	F_FLAGS		0x080000		/* file flags */
85 #define	F_NOCHANGE	0x100000		/* do not change owner/mode */
86 #define	F_SHA256	0x200000		/* SHA-256 digest */
87 	u_int32_t flags;			/* items set */
88 
89 #define	F_BLOCK	0x001				/* block special */
90 #define	F_CHAR	0x002				/* char special */
91 #define	F_DIR	0x004				/* directory */
92 #define	F_FIFO	0x008				/* fifo */
93 #define	F_FILE	0x010				/* regular file */
94 #define	F_LINK	0x020				/* symbolic link */
95 #define	F_SOCK	0x040				/* socket */
96 	u_char	type;				/* file type */
97 
98 	char	name[1];			/* file name (must be last) */
99 } NODE;
100 
101 #define	RP(p)	\
102 	((p)->fts_path[0] == '.' && (p)->fts_path[1] == '/' ? \
103 	    (p)->fts_path + 2 : (p)->fts_path)
104