xref: /freebsd/sys/contrib/openzfs/include/sys/zfs_project.h (revision 8ac904ce090b1c2e355da8aa122ca2252183f4e1)
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_IOC_FSGETXATTR
39 typedef struct fsxattr zfsxattr_t;
40 
41 #define	ZFS_IOC_FSGETXATTR	FS_IOC_FSGETXATTR
42 #define	ZFS_IOC_FSSETXATTR	FS_IOC_FSSETXATTR
43 #else
44 /* Non-Linux OS */
45 #define	FS_PROJINHERIT_FL	0x20000000
46 #define	FS_XFLAG_PROJINHERIT	FS_PROJINHERIT_FL
47 
48 struct zfsxattr {
49 	uint32_t	fsx_xflags;	/* xflags field value (get/set) */
50 	uint32_t	fsx_extsize;	/* extsize field value (get/set) */
51 	uint32_t	fsx_nextents;	/* nextents field value (get)   */
52 	uint32_t	fsx_projid;	/* project identifier (get/set) */
53 	uint32_t	fsx_cowextsize;
54 	unsigned char	fsx_pad[8];
55 };
56 typedef struct zfsxattr zfsxattr_t;
57 
58 #define	ZFS_IOC_FSGETXATTR	_IOR('X', 31, zfsxattr_t)
59 #define	ZFS_IOC_FSSETXATTR	_IOW('X', 32, zfsxattr_t)
60 #endif
61 
62 #define	ZFS_DEFAULT_PROJID	(0ULL)
63 /*
64  * It is NOT ondisk project ID value. Just means either the object has
65  * no project ID or the operation does not touch project ID attribute.
66  */
67 #define	ZFS_INVALID_PROJID	(-1ULL)
68 
69 static inline boolean_t
zpl_is_valid_projid(uint32_t projid)70 zpl_is_valid_projid(uint32_t projid)
71 {
72 	/*
73 	 * zfsxattr::fsx_projid is 32-bits, when convert to uint64_t,
74 	 * the higher 32-bits will be set as zero, so cannot directly
75 	 * compare with ZFS_INVALID_PROJID (-1ULL)
76 	 */
77 	if ((uint32_t)ZFS_INVALID_PROJID == projid)
78 		return (B_FALSE);
79 	return (B_TRUE);
80 }
81 
82 #endif	/* _SYS_ZFS_PROJECT_H */
83