xref: /freebsd/sys/contrib/openzfs/include/sys/zfs_project.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2017, Intel Corporation. All rights reserved.
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 #include <sys/vfs.h>
37 
38 #ifdef FS_PROJINHERIT_FL
39 #define	ZFS_PROJINHERIT_FL	FS_PROJINHERIT_FL
40 #else
41 #define	ZFS_PROJINHERIT_FL	0x20000000
42 #endif
43 
44 #ifdef FS_IOC_FSGETXATTR
45 typedef struct fsxattr zfsxattr_t;
46 
47 #define	ZFS_IOC_FSGETXATTR	FS_IOC_FSGETXATTR
48 #define	ZFS_IOC_FSSETXATTR	FS_IOC_FSSETXATTR
49 #else
50 struct zfsxattr {
51 	uint32_t	fsx_xflags;	/* xflags field value (get/set) */
52 	uint32_t	fsx_extsize;	/* extsize field value (get/set) */
53 	uint32_t	fsx_nextents;	/* nextents field value (get)   */
54 	uint32_t	fsx_projid;	/* project identifier (get/set) */
55 	uint32_t	fsx_cowextsize;
56 	unsigned char	fsx_pad[8];
57 };
58 typedef struct zfsxattr zfsxattr_t;
59 
60 #define	ZFS_IOC_FSGETXATTR	_IOR('X', 31, zfsxattr_t)
61 #define	ZFS_IOC_FSSETXATTR	_IOW('X', 32, zfsxattr_t)
62 #endif
63 
64 #define	ZFS_DEFAULT_PROJID	(0ULL)
65 /*
66  * It is NOT ondisk project ID value. Just means either the object has
67  * no project ID or the operation does not touch project ID attribute.
68  */
69 #define	ZFS_INVALID_PROJID	(-1ULL)
70 
71 static inline boolean_t
zpl_is_valid_projid(uint32_t projid)72 zpl_is_valid_projid(uint32_t projid)
73 {
74 	/*
75 	 * zfsxattr::fsx_projid is 32-bits, when convert to uint64_t,
76 	 * the higher 32-bits will be set as zero, so cannot directly
77 	 * compare with ZFS_INVALID_PROJID (-1ULL)
78 	 */
79 	if ((uint32_t)ZFS_INVALID_PROJID == projid)
80 		return (B_FALSE);
81 	return (B_TRUE);
82 }
83 
84 #endif	/* _SYS_ZFS_PROJECT_H */
85