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 (c) 2017, Intel Corporation. All rights reserved.
23  * Copyright 2019 Joyent, Inc.
24  */
25 
26 #ifndef	_SYS_ZFS_PROJECT_H
27 #define	_SYS_ZFS_PROJECT_H
28 
29 #ifndef _KERNEL
30 #ifndef _SYS_MOUNT_H
31 /* XXX: some hack to avoid include sys/mount.h */
32 #define	_SYS_MOUNT_H
33 #endif
34 #endif
35 
36 #ifdef FS_PROJINHERIT_FL
37 #define	ZFS_PROJINHERIT_FL	FS_PROJINHERIT_FL
38 #else
39 #define	ZFS_PROJINHERIT_FL	0x20000000
40 #endif
41 
42 #ifdef FS_IOC_FSGETXATTR
43 typedef struct fsxattr zfsxattr_t;
44 
45 #define	ZFS_IOC_FSGETXATTR	FS_IOC_FSGETXATTR
46 #define	ZFS_IOC_FSSETXATTR	FS_IOC_FSSETXATTR
47 #else
48 #include <sys/ioccom.h>
49 typedef struct zfsxattr {
50 	uint32_t	fsx_xflags;	/* xflags field value (get/set) */
51 	uint32_t	fsx_projid;	/* project identifier (get/set) */
52 } zfsxattr_t;
53 
54 #define	ZFS_IOC_FSGETXATTR	_IOR('X', 31, zfsxattr_t)
55 #define	ZFS_IOC_FSSETXATTR	_IOW('X', 32, zfsxattr_t)
56 #endif
57 
58 #define	ZFS_DEFAULT_PROJID	(0ULL)
59 /*
60  * It is NOT ondisk project ID value. Just means either the object has
61  * no project ID or the operation does not touch project ID attribute.
62  */
63 #define	ZFS_INVALID_PROJID	(-1ULL)
64 
65 static inline boolean_t
zpl_is_valid_projid(uint32_t projid)66 zpl_is_valid_projid(uint32_t projid)
67 {
68 	/*
69 	 * zfsxattr::fsx_projid is 32-bits, when convert to uint64_t,
70 	 * the higher 32-bits will be set as zero, so cannot directly
71 	 * compare with ZFS_INVALID_PROJID (-1ULL)
72 	 */
73 	if ((uint32_t)ZFS_INVALID_PROJID == projid)
74 		return (B_FALSE);
75 	return (B_TRUE);
76 }
77 
78 #endif	/* _SYS_ZFS_PROJECT_H */
79