1156230Smux/*-
2156230Smux * Copyright (c) 2003-2006, Maxime Henrion <mux@FreeBSD.org>
3156230Smux * All rights reserved.
4156230Smux *
5156230Smux * Redistribution and use in source and binary forms, with or without
6156230Smux * modification, are permitted provided that the following conditions
7156230Smux * are met:
8156230Smux * 1. Redistributions of source code must retain the above copyright
9156230Smux *    notice, this list of conditions and the following disclaimer.
10156230Smux * 2. Redistributions in binary form must reproduce the above copyright
11156230Smux *    notice, this list of conditions and the following disclaimer in the
12156230Smux *    documentation and/or other materials provided with the distribution.
13156230Smux *
14156230Smux * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15156230Smux * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16156230Smux * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17156230Smux * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18156230Smux * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19156230Smux * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20156230Smux * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21156230Smux * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22156230Smux * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23156230Smux * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24156230Smux * SUCH DAMAGE.
25156230Smux *
26156230Smux * $FreeBSD$
27156230Smux */
28156230Smux#ifndef _FATTR_H_
29156230Smux#define _FATTR_H_
30156230Smux
31156230Smux#include <sys/types.h>
32156230Smux
33156230Smux#include <fcntl.h>
34156230Smux#include <time.h>
35156230Smux
36156230Smux/*
37156230Smux * File types.
38156230Smux */
39156230Smux#define	FT_UNKNOWN	0			/* Unknown file type. */
40156230Smux#define	FT_FILE		1			/* Regular file. */
41156230Smux#define	FT_DIRECTORY	2			/* Directory. */
42156230Smux#define	FT_CDEV		3			/* Character device. */
43156230Smux#define	FT_BDEV		4			/* Block device. */
44156230Smux#define	FT_SYMLINK	5			/* Symbolic link. */
45156230Smux#define	FT_MAX		FT_SYMLINK		/* Maximum file type number. */
46156230Smux#define	FT_NUMBER	(FT_MAX + 1)		/* Number of file types. */
47156230Smux
48156230Smux/*
49156230Smux * File attributes.
50156230Smux */
51156230Smux#define	FA_FILETYPE	0x0001		/* True for all supported file types. */
52156230Smux#define	FA_MODTIME	0x0002		/* Last file modification time. */
53156230Smux#define	FA_SIZE		0x0004		/* Size of the file. */
54156230Smux#define	FA_LINKTARGET	0x0008		/* Target of a symbolic link. */
55156230Smux#define	FA_RDEV		0x0010		/* Device for a device node. */
56156230Smux#define	FA_OWNER	0x0020		/* Owner of the file. */
57156230Smux#define	FA_GROUP	0x0040		/* Group of the file. */
58156230Smux#define	FA_MODE		0x0080		/* File permissions. */
59156230Smux#define	FA_FLAGS	0x0100		/* 4.4BSD flags, a la chflags(2). */
60156230Smux#define	FA_LINKCOUNT	0x0200		/* Hard link count. */
61156230Smux#define	FA_DEV		0x0400		/* Device holding the inode. */
62156230Smux#define	FA_INODE	0x0800		/* Inode number. */
63156230Smux
64156230Smux#define	FA_MASK		0x0fff
65156230Smux
66156230Smux#define	FA_NUMBER	12		/* Number of file attributes. */
67156230Smux
68156230Smux/* Attributes that we might be able to change. */
69156230Smux#define	FA_CHANGEABLE	(FA_MODTIME | FA_OWNER | FA_GROUP | FA_MODE | FA_FLAGS)
70156230Smux
71156230Smux/*
72156230Smux * Attributes that we don't want to save in the "checkouts" file
73156230Smux * when in checkout mode.
74156230Smux */
75156230Smux#define	FA_COIGNORE	(FA_MASK & ~(FA_FILETYPE|FA_MODTIME|FA_SIZE|FA_MODE))
76156230Smux
77156230Smux/* These are for fattr_frompath(). */
78156230Smux#define	FATTR_FOLLOW	0
79156230Smux#define	FATTR_NOFOLLOW	1
80156230Smux
81156230Smuxstruct stat;
82156230Smuxstruct fattr;
83156230Smux
84156230Smuxtypedef int	fattr_support_t[FT_NUMBER];
85156230Smux
86156230Smuxextern const struct fattr *fattr_bogus;
87156230Smux
88156230Smuxvoid		 fattr_init(void);
89156230Smuxvoid		 fattr_fini(void);
90156230Smux
91156230Smuxstruct fattr	*fattr_new(int, time_t);
92156230Smuxstruct fattr	*fattr_default(int);
93156230Smuxstruct fattr	*fattr_fromstat(struct stat *);
94156230Smuxstruct fattr	*fattr_frompath(const char *, int);
95156230Smuxstruct fattr	*fattr_fromfd(int);
96156230Smuxstruct fattr	*fattr_decode(char *);
97156230Smuxstruct fattr	*fattr_forcheckout(const struct fattr *, mode_t);
98156230Smuxstruct fattr	*fattr_dup(const struct fattr *);
99156230Smuxchar		*fattr_encode(const struct fattr *, fattr_support_t, int);
100156230Smuxint		 fattr_type(const struct fattr *);
101156230Smuxvoid		 fattr_maskout(struct fattr *, int);
102156230Smuxint		 fattr_getmask(const struct fattr *);
103156230Smuxnlink_t		 fattr_getlinkcount(const struct fattr *);
104186781Slulfchar		*fattr_getlinktarget(const struct fattr *);
105156230Smuxvoid		 fattr_umask(struct fattr *, mode_t);
106156230Smuxvoid		 fattr_merge(struct fattr *, const struct fattr *);
107156230Smuxvoid		 fattr_mergedefault(struct fattr *);
108156230Smuxvoid		 fattr_override(struct fattr *, const struct fattr *, int);
109156230Smuxint		 fattr_makenode(const struct fattr *, const char *);
110156230Smuxint		 fattr_delete(const char *path);
111156230Smuxint		 fattr_install(struct fattr *, const char *, const char *);
112156230Smuxint		 fattr_equal(const struct fattr *, const struct fattr *);
113156230Smuxvoid		 fattr_free(struct fattr *);
114156230Smuxint		 fattr_supported(int);
115186781Slulfoff_t		 fattr_filesize(const struct fattr *);
116156230Smux
117186781Slulf
118156230Smux#endif /* !_FATTR_H_ */
119