xref: /titanic_52/usr/src/uts/common/nfs/nfs4_attr.h (revision 56f33205c9ed776c3c909e07d52e94610a675740)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _NFS4_ATTR_H
27 #define	_NFS4_ATTR_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #define	FATTR4_WORD0	32
34 #define	FATTR4_WORD1	0
35 
36 /*
37  * Attributes
38  */
39 #define	FATTR4_SUPPORTED_ATTRS_MASK	(1ULL << (FATTR4_WORD0 + 0))
40 #define	FATTR4_TYPE_MASK		(1ULL << (FATTR4_WORD0 + 1))
41 #define	FATTR4_FH_EXPIRE_TYPE_MASK	(1ULL << (FATTR4_WORD0 + 2))
42 #define	FATTR4_CHANGE_MASK		(1ULL << (FATTR4_WORD0 + 3))
43 #define	FATTR4_SIZE_MASK		(1ULL << (FATTR4_WORD0 + 4))
44 #define	FATTR4_LINK_SUPPORT_MASK	(1ULL << (FATTR4_WORD0 + 5))
45 #define	FATTR4_SYMLINK_SUPPORT_MASK	(1ULL << (FATTR4_WORD0 + 6))
46 #define	FATTR4_NAMED_ATTR_MASK		(1ULL << (FATTR4_WORD0 + 7))
47 #define	FATTR4_FSID_MASK		(1ULL << (FATTR4_WORD0 + 8))
48 #define	FATTR4_UNIQUE_HANDLES_MASK	(1ULL << (FATTR4_WORD0 + 9))
49 #define	FATTR4_LEASE_TIME_MASK		(1ULL << (FATTR4_WORD0 + 10))
50 #define	FATTR4_RDATTR_ERROR_MASK	(1ULL << (FATTR4_WORD0 + 11))
51 #define	FATTR4_ACL_MASK			(1ULL << (FATTR4_WORD0 + 12))
52 #define	FATTR4_ACLSUPPORT_MASK		(1ULL << (FATTR4_WORD0 + 13))
53 #define	FATTR4_ARCHIVE_MASK		(1ULL << (FATTR4_WORD0 + 14))
54 #define	FATTR4_CANSETTIME_MASK		(1ULL << (FATTR4_WORD0 + 15))
55 #define	FATTR4_CASE_INSENSITIVE_MASK	(1ULL << (FATTR4_WORD0 + 16))
56 #define	FATTR4_CASE_PRESERVING_MASK	(1ULL << (FATTR4_WORD0 + 17))
57 #define	FATTR4_CHOWN_RESTRICTED_MASK	(1ULL << (FATTR4_WORD0 + 18))
58 #define	FATTR4_FILEHANDLE_MASK		(1ULL << (FATTR4_WORD0 + 19))
59 #define	FATTR4_FILEID_MASK		(1ULL << (FATTR4_WORD0 + 20))
60 #define	FATTR4_FILES_AVAIL_MASK		(1ULL << (FATTR4_WORD0 + 21))
61 #define	FATTR4_FILES_FREE_MASK		(1ULL << (FATTR4_WORD0 + 22))
62 #define	FATTR4_FILES_TOTAL_MASK		(1ULL << (FATTR4_WORD0 + 23))
63 #define	FATTR4_FS_LOCATIONS_MASK	(1ULL << (FATTR4_WORD0 + 24))
64 #define	FATTR4_HIDDEN_MASK		(1ULL << (FATTR4_WORD0 + 25))
65 #define	FATTR4_HOMOGENEOUS_MASK		(1ULL << (FATTR4_WORD0 + 26))
66 #define	FATTR4_MAXFILESIZE_MASK		(1ULL << (FATTR4_WORD0 + 27))
67 #define	FATTR4_MAXLINK_MASK		(1ULL << (FATTR4_WORD0 + 28))
68 #define	FATTR4_MAXNAME_MASK		(1ULL << (FATTR4_WORD0 + 29))
69 #define	FATTR4_MAXREAD_MASK		(1ULL << (FATTR4_WORD0 + 30))
70 #define	FATTR4_MAXWRITE_MASK		(1ULL << (FATTR4_WORD0 + 31))
71 
72 #define	FATTR4_MIMETYPE_MASK		(1ULL << (FATTR4_WORD1 + 0))
73 #define	FATTR4_MODE_MASK		(1ULL << (FATTR4_WORD1 + 1))
74 #define	FATTR4_NO_TRUNC_MASK		(1ULL << (FATTR4_WORD1 + 2))
75 #define	FATTR4_NUMLINKS_MASK		(1ULL << (FATTR4_WORD1 + 3))
76 #define	FATTR4_OWNER_MASK		(1ULL << (FATTR4_WORD1 + 4))
77 #define	FATTR4_OWNER_GROUP_MASK		(1ULL << (FATTR4_WORD1 + 5))
78 #define	FATTR4_QUOTA_AVAIL_HARD_MASK	(1ULL << (FATTR4_WORD1 + 6))
79 #define	FATTR4_QUOTA_AVAIL_SOFT_MASK	(1ULL << (FATTR4_WORD1 + 7))
80 #define	FATTR4_QUOTA_USED_MASK		(1ULL << (FATTR4_WORD1 + 8))
81 #define	FATTR4_RAWDEV_MASK		(1ULL << (FATTR4_WORD1 + 9))
82 #define	FATTR4_SPACE_AVAIL_MASK		(1ULL << (FATTR4_WORD1 + 10))
83 #define	FATTR4_SPACE_FREE_MASK		(1ULL << (FATTR4_WORD1 + 11))
84 #define	FATTR4_SPACE_TOTAL_MASK		(1ULL << (FATTR4_WORD1 + 12))
85 #define	FATTR4_SPACE_USED_MASK		(1ULL << (FATTR4_WORD1 + 13))
86 #define	FATTR4_SYSTEM_MASK		(1ULL << (FATTR4_WORD1 + 14))
87 #define	FATTR4_TIME_ACCESS_MASK		(1ULL << (FATTR4_WORD1 + 15))
88 #define	FATTR4_TIME_ACCESS_SET_MASK	(1ULL << (FATTR4_WORD1 + 16))
89 #define	FATTR4_TIME_BACKUP_MASK		(1ULL << (FATTR4_WORD1 + 17))
90 #define	FATTR4_TIME_CREATE_MASK		(1ULL << (FATTR4_WORD1 + 18))
91 #define	FATTR4_TIME_DELTA_MASK		(1ULL << (FATTR4_WORD1 + 19))
92 #define	FATTR4_TIME_METADATA_MASK	(1ULL << (FATTR4_WORD1 + 20))
93 #define	FATTR4_TIME_MODIFY_MASK		(1ULL << (FATTR4_WORD1 + 21))
94 #define	FATTR4_TIME_MODIFY_SET_MASK	(1ULL << (FATTR4_WORD1 + 22))
95 #define	FATTR4_MOUNTED_ON_FILEID_MASK	(1ULL << (FATTR4_WORD1 + 23))
96 
97 /*
98  * Common bitmap4 of file attributes to be gathered
99  */
100 #define	NFS4_NTOV_ATTR_MASK (		\
101 	FATTR4_TYPE_MASK |		\
102 	FATTR4_CHANGE_MASK |		\
103 	FATTR4_SIZE_MASK |		\
104 	FATTR4_FSID_MASK |		\
105 	FATTR4_FILEID_MASK |		\
106 	FATTR4_MODE_MASK |		\
107 	FATTR4_OWNER_MASK |		\
108 	FATTR4_OWNER_GROUP_MASK |	\
109 	FATTR4_NUMLINKS_MASK |		\
110 	FATTR4_TIME_ACCESS_MASK |	\
111 	FATTR4_TIME_MODIFY_MASK |	\
112 	FATTR4_TIME_METADATA_MASK |	\
113 	FATTR4_RAWDEV_MASK |		\
114 	FATTR4_SPACE_USED_MASK |	\
115 	FATTR4_MOUNTED_ON_FILEID_MASK)
116 
117 #define	NFS4_VATTR_MASK (		\
118 	FATTR4_TYPE_MASK |		\
119 	FATTR4_CHANGE_MASK |		\
120 	FATTR4_SIZE_MASK |		\
121 	FATTR4_FSID_MASK |		\
122 	FATTR4_FILEID_MASK |		\
123 	FATTR4_MODE_MASK |		\
124 	FATTR4_OWNER_MASK |		\
125 	FATTR4_OWNER_GROUP_MASK |	\
126 	FATTR4_NUMLINKS_MASK |		\
127 	FATTR4_TIME_ACCESS_MASK |	\
128 	FATTR4_TIME_MODIFY_MASK |	\
129 	FATTR4_TIME_METADATA_MASK |	\
130 	FATTR4_RAWDEV_MASK |		\
131 	FATTR4_SPACE_USED_MASK |	\
132 	FATTR4_MOUNTED_ON_FILEID_MASK)
133 
134 #define	NFS4_PATHCONF_MASK (		\
135 	NFS4_VATTR_MASK |		\
136 	FATTR4_NO_TRUNC_MASK |		\
137 	FATTR4_CHOWN_RESTRICTED_MASK |	\
138 	FATTR4_CASE_INSENSITIVE_MASK |	\
139 	FATTR4_CASE_PRESERVING_MASK |	\
140 	FATTR4_NAMED_ATTR_MASK |	\
141 	FATTR4_LINK_SUPPORT_MASK |	\
142 	FATTR4_SYMLINK_SUPPORT_MASK |	\
143 	FATTR4_UNIQUE_HANDLES_MASK |	\
144 	FATTR4_CANSETTIME_MASK |	\
145 	FATTR4_HOMOGENEOUS_MASK |	\
146 	FATTR4_MAXLINK_MASK |		\
147 	FATTR4_MAXNAME_MASK |		\
148 	FATTR4_MAXFILESIZE_MASK)
149 
150 /*
151  * The corresponding AT_MASK
152  */
153 #define	NFS4_NTOV_ATTR_AT_MASK (	\
154 	AT_TYPE |			\
155 	AT_SIZE |			\
156 	AT_FSID |			\
157 	AT_NODEID |			\
158 	AT_MODE |			\
159 	AT_UID |			\
160 	AT_GID |			\
161 	AT_NLINK |			\
162 	AT_ATIME |			\
163 	AT_MTIME |			\
164 	AT_CTIME |			\
165 	AT_RDEV |			\
166 	AT_NBLOCKS)
167 
168 /*
169  * Common bitmap4 of filesystem attributes to be gathered
170  */
171 #define	NFS4_FS_ATTR_MASK (		\
172 	FATTR4_FILES_AVAIL_MASK |	\
173 	FATTR4_FILES_FREE_MASK |	\
174 	FATTR4_FILES_TOTAL_MASK |	\
175 	FATTR4_SPACE_AVAIL_MASK |	\
176 	FATTR4_SPACE_FREE_MASK |	\
177 	FATTR4_SPACE_TOTAL_MASK)
178 
179 #define	NFS4_STATFS_ATTR_MASK (		\
180 	FATTR4_FILES_AVAIL_MASK |	\
181 	FATTR4_FILES_FREE_MASK |	\
182 	FATTR4_FILES_TOTAL_MASK |	\
183 	FATTR4_SPACE_AVAIL_MASK |	\
184 	FATTR4_SPACE_FREE_MASK |	\
185 	FATTR4_SPACE_TOTAL_MASK |	\
186 	FATTR4_MAXNAME_MASK)
187 
188 /*
189  * The corresponding AT_MASK
190  */
191 #define	NFS4_FS_ATTR_AT_MASK	0
192 
193 /*
194  * Common bitmap4 to gather attr cache state
195  */
196 #define	NFS4_NTOV_ATTR_CACHE_MASK (	\
197 	FATTR4_TIME_METADATA_MASK |	\
198 	FATTR4_TIME_MODIFY_MASK |	\
199 	FATTR4_SIZE_MASK)
200 
201 /*
202  * The corresponding AT_MASK
203  */
204 #define	NFS4_NTOV_ATTR_CACHE_AT_MASK (	\
205 	AT_CTIME |			\
206 	AT_MTIME |			\
207 	AT_SIZE)
208 
209 #define	NFS4_VTON_ATTR_MASK (		\
210 	AT_TYPE |			\
211 	AT_MODE |			\
212 	AT_UID |			\
213 	AT_GID |			\
214 	AT_NODEID |			\
215 	AT_SIZE |			\
216 	AT_NLINK |			\
217 	AT_ATIME |			\
218 	AT_MTIME |			\
219 	AT_CTIME |			\
220 	AT_RDEV |			\
221 	AT_NBLOCKS |			\
222 	AT_FSID)
223 
224 #define	NFS4_VTON_ATTR_MASK_SET (	\
225 	AT_MODE |			\
226 	AT_UID |			\
227 	AT_GID |			\
228 	AT_SIZE |			\
229 	AT_ATIME |			\
230 	AT_MTIME)
231 
232 /* solaris-supported, non-vattr_t per-vnode scoped attrs */
233 #define	NFS4_VP_ATTR_MASK (		\
234 	FATTR4_CHANGE_MASK |		\
235 	FATTR4_CHOWN_RESTRICTED_MASK |	\
236 	FATTR4_FILEHANDLE_MASK |	\
237 	FATTR4_MAXFILESIZE_MASK |	\
238 	FATTR4_MAXLINK_MASK |		\
239 	FATTR4_MAXNAME_MASK |		\
240 	FATTR4_MOUNTED_ON_FILEID_MASK)
241 
242 #define	FATTR4_FSINFO_MASK (		\
243 	FATTR4_SUPPORTED_ATTRS_MASK |	\
244 	FATTR4_TYPE_MASK |		\
245 	FATTR4_FH_EXPIRE_TYPE_MASK |	\
246 	FATTR4_LINK_SUPPORT_MASK |	\
247 	FATTR4_SYMLINK_SUPPORT_MASK |	\
248 	FATTR4_FSID_MASK |		\
249 	FATTR4_MAXFILESIZE_MASK |	\
250 	FATTR4_MAXREAD_MASK |		\
251 	FATTR4_MAXWRITE_MASK)
252 
253 /*
254  * These are the support attributes for the NFSv4 server
255  */
256 #define	NFS4_SRV_RDDIR_SUPPORTED_ATTRS (	\
257 	FATTR4_SUPPORTED_ATTRS_MASK |	\
258 	FATTR4_TYPE_MASK |		\
259 	FATTR4_FH_EXPIRE_TYPE_MASK |	\
260 	FATTR4_CHANGE_MASK |		\
261 	FATTR4_SIZE_MASK |		\
262 	FATTR4_LINK_SUPPORT_MASK |	\
263 	FATTR4_SYMLINK_SUPPORT_MASK |	\
264 	FATTR4_NAMED_ATTR_MASK |	\
265 	FATTR4_FSID_MASK |		\
266 	FATTR4_UNIQUE_HANDLES_MASK |	\
267 	FATTR4_LEASE_TIME_MASK |	\
268 	FATTR4_RDATTR_ERROR_MASK |	\
269 	FATTR4_CANSETTIME_MASK |	\
270 	FATTR4_CASE_INSENSITIVE_MASK |	\
271 	FATTR4_CASE_PRESERVING_MASK |	\
272 	FATTR4_CHOWN_RESTRICTED_MASK |	\
273 	FATTR4_FILEHANDLE_MASK |	\
274 	FATTR4_FILEID_MASK |		\
275 	FATTR4_FILES_AVAIL_MASK |	\
276 	FATTR4_FILES_FREE_MASK |	\
277 	FATTR4_FILES_TOTAL_MASK |	\
278 	FATTR4_HOMOGENEOUS_MASK |	\
279 	FATTR4_MAXFILESIZE_MASK |	\
280 	FATTR4_MAXLINK_MASK |		\
281 	FATTR4_MAXNAME_MASK |		\
282 	FATTR4_MAXREAD_MASK |		\
283 	FATTR4_MAXWRITE_MASK |		\
284 	FATTR4_MODE_MASK |		\
285 	FATTR4_NO_TRUNC_MASK |		\
286 	FATTR4_NUMLINKS_MASK |		\
287 	FATTR4_OWNER_MASK |		\
288 	FATTR4_OWNER_GROUP_MASK |	\
289 	FATTR4_RAWDEV_MASK |		\
290 	FATTR4_SPACE_AVAIL_MASK |	\
291 	FATTR4_SPACE_FREE_MASK |	\
292 	FATTR4_SPACE_TOTAL_MASK |	\
293 	FATTR4_SPACE_USED_MASK |	\
294 	FATTR4_TIME_ACCESS_MASK |	\
295 	FATTR4_TIME_DELTA_MASK |	\
296 	FATTR4_TIME_METADATA_MASK |	\
297 	FATTR4_TIME_MODIFY_MASK |	\
298 	FATTR4_MOUNTED_ON_FILEID_MASK	\
299 )
300 
301 
302 #define	FATTR4_FSID_EQ(a, b)	\
303 	((a)->major == (b)->major && (a)->minor == (b)->minor)
304 
305 #define	NFS4_MAXNUM_BITWORDS	2
306 #define	NFS4_MAXNUM_ATTRS	56
307 
308 union nfs4_attr_u {
309 	fattr4_supported_attrs		supported_attrs;
310 	fattr4_type			type;
311 	fattr4_fh_expire_type		fh_expire_type;
312 	fattr4_change			change;
313 	fattr4_size			size;
314 	fattr4_link_support		link_support;
315 	fattr4_symlink_support		symlink_support;
316 	fattr4_named_attr		named_attr;
317 	fattr4_fsid			fsid;
318 	fattr4_unique_handles		unique_handles;
319 	fattr4_lease_time		lease_time;
320 	fattr4_rdattr_error		rdattr_error;
321 	fattr4_acl			acl;
322 	fattr4_aclsupport		aclsupport;
323 	fattr4_archive			archive;
324 	fattr4_cansettime		cansettime;
325 	fattr4_case_insensitive		case_insensitive;
326 	fattr4_case_preserving		case_preserving;
327 	fattr4_chown_restricted		chown_restricted;
328 	fattr4_fileid			fileid;
329 	fattr4_files_avail		files_avail;
330 	fattr4_filehandle		filehandle;
331 	fattr4_files_free		files_free;
332 	fattr4_files_total		files_total;
333 	fattr4_fs_locations		fs_locations;
334 	fattr4_hidden			hidden;
335 	fattr4_homogeneous		homogeneous;
336 	fattr4_maxfilesize		maxfilesize;
337 	fattr4_maxlink			maxlink;
338 	fattr4_maxname			maxname;
339 	fattr4_maxread			maxread;
340 	fattr4_maxwrite			maxwrite;
341 	fattr4_mimetype			mimetype;
342 	fattr4_mode			mode;
343 	fattr4_no_trunc			no_trunc;
344 	fattr4_numlinks			numlinks;
345 	fattr4_owner			owner;
346 	fattr4_owner_group		owner_group;
347 	fattr4_quota_avail_hard		quota_avail_hard;
348 	fattr4_quota_avail_soft		quota_avail_soft;
349 	fattr4_quota_used		quota_used;
350 	fattr4_rawdev			rawdev;
351 	fattr4_space_avail		space_avail;
352 	fattr4_space_free		space_free;
353 	fattr4_space_total		space_total;
354 	fattr4_space_used		space_used;
355 	fattr4_system			system;
356 	fattr4_time_access		time_access;
357 	fattr4_time_access_set		time_access_set;
358 	fattr4_time_backup		time_backup;
359 	fattr4_time_create		time_create;
360 	fattr4_time_delta		time_delta;
361 	fattr4_time_metadata		time_metadata;
362 	fattr4_time_modify		time_modify;
363 	fattr4_time_modify_set		time_modify_set;
364 	fattr4_mounted_on_fileid	mounted_on_fileid;
365 };
366 
367 /*
368  * Error details when processing the getattr response.
369  */
370 #define	NFS4_GETATTR_OP_OK		0
371 #define	NFS4_GETATTR_STATUS_ERR		1
372 #define	NFS4_GETATTR_MANDATTR_ERR	2
373 #define	NFS4_GETATTR_BITMAP_ERR		3
374 #define	NFS4_GETATTR_ATSIZE_ERR		4
375 #define	NFS4_GETATTR_ATUID_ERR		5
376 #define	NFS4_GETATTR_ATGID_ERR		6
377 #define	NFS4_GETATTR_ATATIME_ERR	7
378 #define	NFS4_GETATTR_ATMTIME_ERR	8
379 #define	NFS4_GETATTR_ATCTIME_ERR	9
380 #define	NFS4_GETATTR_RAWDEV_ERR		10
381 #define	NFS4_GETATTR_ATNBLOCK_ERR	11
382 #define	NFS4_GETATTR_MAXFILESIZE_ERR	12
383 #define	NFS4_GETATTR_FHANDLE_ERR	13
384 #define	NFS4_GETATTR_MAXREAD_ERR	14
385 #define	NFS4_GETATTR_MAXWRITE_ERR	15
386 #define	NFS4_GETATTR_NOCACHE_OK		16
387 
388 typedef struct nfs4_pathconf_info {
389 	unsigned pc4_cache_valid:1;	/* When in rnode4, is data valid? */
390 	unsigned pc4_no_trunc:1;
391 	unsigned pc4_chown_restricted:1;
392 	unsigned pc4_case_insensitive:1;
393 	unsigned pc4_case_preserving:1;
394 	unsigned pc4_xattr_valid:1;
395 	unsigned pc4_xattr_exists:1;
396 	unsigned pc4_link_support:1;
397 	unsigned pc4_symlink_support:1;
398 	unsigned pc4_unique_handles:1;
399 	unsigned pc4_cansettime:1;
400 	unsigned pc4_homogeneous:1;
401 	uint_t	pc4_link_max;
402 	uint_t	pc4_name_max;
403 	uint_t	pc4_filesizebits;
404 } nfs4_pathconf_info_t;
405 
406 /*
407  * Used for client only to process incoming getattr results.
408  */
409 typedef struct nfs4_ga_ext_res {
410 	bitmap4				n4g_suppattrs;
411 	nfsstat4			n4g_rdattr_error;
412 	fattr4_fh_expire_type		n4g_fet;
413 	fattr4_lease_time		n4g_leasetime;
414 	uint64_t			n4g_maxfilesize;
415 	uint64_t			n4g_maxread;
416 	uint64_t			n4g_maxwrite;
417 	nfstime4			n4g_delta;
418 	nfs4_pathconf_info_t		n4g_pc4;
419 	struct statvfs64		n4g_sb;
420 	union {
421 		nfs_fh4 n4g_fh;
422 		struct {
423 			uint_t len;
424 			char *val;
425 			char data[NFS4_FHSIZE];
426 		} nfs_fh4_alt;
427 	} n4g_fh_u;
428 	/*
429 	 * Bitmask with valid fields being:
430 	 * ACL4_SUPPORT_ALLOW_ACL
431 	 * ACL4_SUPPORT_DENY_ACL
432 	 * ACL4_SUPPORT_AUDIT_ACL
433 	 * ACL4_SUPPORT_ALARM_ACL
434 	 */
435 	fattr4_aclsupport		n4g_aclsupport;
436 	fattr4_fs_locations		n4g_fslocations;
437 } nfs4_ga_ext_res_t;
438 
439 extern bitmap4 rfs4_supported_attrs;
440 
441 #ifdef	__cplusplus
442 }
443 #endif
444 
445 #endif /* _NFS4_ATTR_H */
446