xref: /haiku/src/add-ons/kernel/file_systems/nfs4/NFS4Defs.h (revision f7bf941a8c770ed5963f1598f268fec16908827e)
14aeb5952SPawel Dziepak /*
24aeb5952SPawel Dziepak  * Copyright 2012 Haiku, Inc. All rights reserved.
34aeb5952SPawel Dziepak  * Distributed under the terms of the MIT License.
44aeb5952SPawel Dziepak  *
54aeb5952SPawel Dziepak  * Authors:
64aeb5952SPawel Dziepak  *		Paweł Dziepak, pdziepak@quarnos.org
74aeb5952SPawel Dziepak  */
84aeb5952SPawel Dziepak #ifndef NFS4DEFS_H
94aeb5952SPawel Dziepak #define NFS4DEFS_H
104aeb5952SPawel Dziepak 
114aeb5952SPawel Dziepak 
127d0b8c97SPawel Dziepak #include <fcntl.h>
13d38e98d8SPawel Dziepak #include <sys/stat.h>
14d38e98d8SPawel Dziepak 
1545aa18acSPawel Dziepak #include <SupportDefs.h>
1645aa18acSPawel Dziepak 
177bfa4fe8SPawel Dziepak #include "Filehandle.h"
18196403c9SPawel Dziepak 
194aeb5952SPawel Dziepak enum Procedure {
204aeb5952SPawel Dziepak 	ProcNull		= 0,
214aeb5952SPawel Dziepak 	ProcCompound	= 1
224aeb5952SPawel Dziepak };
234aeb5952SPawel Dziepak 
244aeb5952SPawel Dziepak enum Opcode {
254aeb5952SPawel Dziepak 	OpAccess				= 3,
2660a8140dSPawel Dziepak 	OpClose					= 4,
27f5baf2efSPawel Dziepak 	OpCreate				= 6,
284aeb5952SPawel Dziepak 	OpGetAttr				= 9,
294aeb5952SPawel Dziepak 	OpGetFH					= 10,
30c0de7acaSPawel Dziepak 	OpLink					= 11,
317d0b8c97SPawel Dziepak 	OpLock					= 12,
327d0b8c97SPawel Dziepak 	OpLockT					= 13,
337d0b8c97SPawel Dziepak 	OpLockU					= 14,
344aeb5952SPawel Dziepak 	OpLookUp				= 15,
357bfa4fe8SPawel Dziepak 	OpLookUpUp				= 16,
3697378968SPawel Dziepak 	OpNverify				= 17,
372a292557SPawel Dziepak 	OpOpen					= 18,
382a292557SPawel Dziepak 	OpOpenConfirm			= 20,
39bf31ee39SPawel Dziepak 	OpPutFH					= 22,
404b48348fSPawel Dziepak 	OpPutRootFH				= 24,
412f2e57d0SPawel Dziepak 	OpRead					= 25,
422a292557SPawel Dziepak 	OpReadDir				= 26,
43f2da914dSPawel Dziepak 	OpReadLink				= 27,
446fb3845bSPawel Dziepak 	OpRemove				= 28,
451ec6b0c1SPawel Dziepak 	OpRename				= 29,
4627a291deSPawel Dziepak 	OpRenew					= 30,
471ec6b0c1SPawel Dziepak 	OpSaveFH				= 32,
48abba2fddSPawel Dziepak 	OpSetAttr				= 34,
492a292557SPawel Dziepak 	OpSetClientID			= 35,
50cf511f24SPawel Dziepak 	OpSetClientIDConfirm	= 36,
51e36a5442SPawel Dziepak 	OpVerify				= 37,
52e36a5442SPawel Dziepak 	OpWrite					= 38
534aeb5952SPawel Dziepak };
544aeb5952SPawel Dziepak 
554aeb5952SPawel Dziepak enum Access {
564aeb5952SPawel Dziepak 	ACCESS4_READ		= 0x00000001,
574aeb5952SPawel Dziepak 	ACCESS4_LOOKUP		= 0x00000002,
584aeb5952SPawel Dziepak 	ACCESS4_MODIFY		= 0x00000004,
594aeb5952SPawel Dziepak 	ACCESS4_EXTEND		= 0x00000008,
604aeb5952SPawel Dziepak 	ACCESS4_DELETE		= 0x00000010,
614aeb5952SPawel Dziepak 	ACCESS4_EXECUTE		= 0x00000020
624aeb5952SPawel Dziepak };
634aeb5952SPawel Dziepak 
644aeb5952SPawel Dziepak enum Attribute {
654aeb5952SPawel Dziepak 	// Mandatory Attributes
664aeb5952SPawel Dziepak 	FATTR4_SUPPORTED_ATTRS		= 0,
674aeb5952SPawel Dziepak 	FATTR4_TYPE					= 1,
684aeb5952SPawel Dziepak 	FATTR4_FH_EXPIRE_TYPE		= 2,
694aeb5952SPawel Dziepak 	FATTR4_CHANGE				= 3,
704aeb5952SPawel Dziepak 	FATTR4_SIZE					= 4,
714aeb5952SPawel Dziepak 	FATTR4_LINK_SUPPORT			= 5,
724aeb5952SPawel Dziepak 	FATTR4_SYMLINK_SUPPORT		= 6,
734aeb5952SPawel Dziepak 	FATTR4_NAMED_ATTR			= 7,
744aeb5952SPawel Dziepak 	FATTR4_FSID					= 8,
754aeb5952SPawel Dziepak 	FATTR4_UNIQUE_HANDLES		= 9,
764aeb5952SPawel Dziepak 	FATTR4_LEASE_TIME			= 10,
774aeb5952SPawel Dziepak 	FATTR4_RDATTR_ERROR			= 11,
784aeb5952SPawel Dziepak 	FATTR4_FILEHANDLE			= 19,
794aeb5952SPawel Dziepak 
804aeb5952SPawel Dziepak 	// Recommended Attributes
814aeb5952SPawel Dziepak 	FATTR4_ACL					= 12,
824aeb5952SPawel Dziepak 	FATTR4_ACLSUPPORT			= 13,
834aeb5952SPawel Dziepak 	FATTR4_ARCHIVE				= 14,
844aeb5952SPawel Dziepak 	FATTR4_CANSETTIME			= 15,
854aeb5952SPawel Dziepak 	FATTR4_CASE_INSENSITIVE		= 16,
864aeb5952SPawel Dziepak 	FATTR4_CASE_PRESERVING		= 17,
874aeb5952SPawel Dziepak 	FATTR4_CHOWN_RESTRICTED		= 18,
884aeb5952SPawel Dziepak 	FATTR4_FILEID				= 20,
894aeb5952SPawel Dziepak 	FATTR4_FILES_AVAIL			= 21,
904aeb5952SPawel Dziepak 	FATTR4_FILES_FREE			= 22,
914aeb5952SPawel Dziepak 	FATTR4_FILES_TOTAL			= 23,
924aeb5952SPawel Dziepak 	FATTR4_FS_LOCATIONS			= 24,
934aeb5952SPawel Dziepak 	FATTR4_HIDDEN				= 25,
944aeb5952SPawel Dziepak 	FATTR4_HOMOGENEOUS			= 26,
954aeb5952SPawel Dziepak 	FATTR4_MAXFILESIZE			= 27,
964aeb5952SPawel Dziepak 	FATTR4_MAXLINK				= 28,
974aeb5952SPawel Dziepak 	FATTR4_MAXNAME				= 29,
984aeb5952SPawel Dziepak 	FATTR4_MAXREAD				= 30,
994aeb5952SPawel Dziepak 	FATTR4_MAXWRITE				= 31,
1004aeb5952SPawel Dziepak 	FATTR4_MIMETYPE				= 32,
1014aeb5952SPawel Dziepak 	FATTR4_MODE					= 33,
1024aeb5952SPawel Dziepak 	FATTR4_NO_TRUNC				= 34,
1034aeb5952SPawel Dziepak 	FATTR4_NUMLINKS				= 35,
1044aeb5952SPawel Dziepak 	FATTR4_OWNER				= 36,
1054aeb5952SPawel Dziepak 	FATTR4_OWNER_GROUP			= 37,
1064aeb5952SPawel Dziepak 	FATTR4_QUOTA_AVAIL_HARD		= 38,
1074aeb5952SPawel Dziepak 	FATTR4_QUOTA_AVAIL_SOFT		= 39,
1084aeb5952SPawel Dziepak 	FATTR4_QUOTA_USED			= 40,
1094aeb5952SPawel Dziepak 	FATTR4_RAWDEV				= 41,
1104aeb5952SPawel Dziepak 	FATTR4_SPACE_AVAIL			= 42,
1114aeb5952SPawel Dziepak 	FATTR4_SPACE_FREE			= 43,
1124aeb5952SPawel Dziepak 	FATTR4_SPACE_TOTAL			= 44,
1134aeb5952SPawel Dziepak 	FATTR4_SPACE_USED			= 45,
1144aeb5952SPawel Dziepak 	FATTR4_SYSTEM				= 46,
1154aeb5952SPawel Dziepak 	FATTR4_TIME_ACCESS			= 47,
1164aeb5952SPawel Dziepak 	FATTR4_TIME_ACCESS_SET		= 48,
1174aeb5952SPawel Dziepak 	FATTR4_TIME_BACKUP			= 49,
1184aeb5952SPawel Dziepak 	FATTR4_TIME_CREATE			= 50,
1194aeb5952SPawel Dziepak 	FATTR4_TIME_DELTA			= 51,
1204aeb5952SPawel Dziepak 	FATTR4_TIME_METADATA		= 52,
1214aeb5952SPawel Dziepak 	FATTR4_TIME_MODIFY			= 53,
1224aeb5952SPawel Dziepak 	FATTR4_TIME_MODIFY_SET		= 54,
123f29ac4afSPawel Dziepak 	FATTR4_MOUNTED_ON_FILEID	= 55,
124f29ac4afSPawel Dziepak 	FATTR4_MAXIMUM_ATTR_ID
1254aeb5952SPawel Dziepak };
1264aeb5952SPawel Dziepak 
127*f7bf941aSPawel Dziepak 
128*f7bf941aSPawel Dziepak static inline bool sIsAttrSet(Attribute attr, const uint32* bitmap,
129*f7bf941aSPawel Dziepak 	uint32 count)
130*f7bf941aSPawel Dziepak {
131*f7bf941aSPawel Dziepak 	if ((uint32)attr / 32 >= count)
132*f7bf941aSPawel Dziepak 		return false;
133*f7bf941aSPawel Dziepak 
134*f7bf941aSPawel Dziepak 	return (bitmap[attr / 32] & 1 << attr % 32) != 0;
135*f7bf941aSPawel Dziepak }
136*f7bf941aSPawel Dziepak 
137*f7bf941aSPawel Dziepak 
138d38e98d8SPawel Dziepak enum FileType {
139d38e98d8SPawel Dziepak 	NF4REG			= 1,    /* Regular File */
140d38e98d8SPawel Dziepak 	NF4DIR			= 2,    /* Directory */
141d38e98d8SPawel Dziepak 	NF4BLK			= 3,    /* Special File - block device */
142d38e98d8SPawel Dziepak 	NF4CHR			= 4,    /* Special File - character device */
143d38e98d8SPawel Dziepak 	NF4LNK			= 5,    /* Symbolic Link */
144d38e98d8SPawel Dziepak 	NF4SOCK			= 6,    /* Special File - socket */
145d38e98d8SPawel Dziepak 	NF4FIFO			= 7,    /* Special File - fifo */
146d38e98d8SPawel Dziepak 	NF4ATTRDIR		= 8,    /* Attribute Directory */
147d38e98d8SPawel Dziepak 	NF4NAMEDATTR	= 9     /* Named Attribute */
148d38e98d8SPawel Dziepak };
149d38e98d8SPawel Dziepak 
150d38e98d8SPawel Dziepak static const mode_t sNFSFileTypeToHaiku[] = {
151212de720SPawel Dziepak 	S_IFREG, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFSOCK, S_IFIFO,
152212de720SPawel Dziepak 	S_IFDIR, S_IFREG
153d38e98d8SPawel Dziepak };
154d38e98d8SPawel Dziepak 
1554aeb5952SPawel Dziepak enum FileHandleExpiryType {
1564aeb5952SPawel Dziepak 	FH4_PERSISTENT			= 0x00,
1574aeb5952SPawel Dziepak 	FH4_NOEXPIRE_WITH_OPEN	= 0x01,
1584aeb5952SPawel Dziepak 	FH4_VOLATILE_ANY		= 0x02,
1594aeb5952SPawel Dziepak 	FH4_VOL_MIGRATION		= 0x04,
1604aeb5952SPawel Dziepak 	FH4_VOL_RENAME			= 0x08
1614aeb5952SPawel Dziepak };
1624aeb5952SPawel Dziepak 
1632a292557SPawel Dziepak enum OpenAccess {
1642a292557SPawel Dziepak 	OPEN4_SHARE_ACCESS_READ		= 1,
16520bd3ee1SPawel Dziepak 	OPEN4_SHARE_ACCESS_WRITE	= 2,
16620bd3ee1SPawel Dziepak 	OPEN4_SHARE_ACCESS_BOTH		= 3
1672a292557SPawel Dziepak };
1682a292557SPawel Dziepak 
1692a292557SPawel Dziepak enum OpenCreate {
1702a292557SPawel Dziepak 	OPEN4_NOCREATE			= 0,
1712a292557SPawel Dziepak 	OPEN4_CREATE			= 1
1722a292557SPawel Dziepak };
1732a292557SPawel Dziepak 
17420bd3ee1SPawel Dziepak enum OpenCreateHow {
17520bd3ee1SPawel Dziepak 	UNCHECKED4				= 0,
17620bd3ee1SPawel Dziepak 	GUARDED4				= 1,
17720bd3ee1SPawel Dziepak 	EXCLUSIVE4				= 2
17820bd3ee1SPawel Dziepak };
17920bd3ee1SPawel Dziepak 
180d1e6b61eSPawel Dziepak enum OpenClaim {
181d1e6b61eSPawel Dziepak 	CLAIM_NULL				= 0,
182d1e6b61eSPawel Dziepak 	CLAIM_PREVIOUS			= 1,
183d1e6b61eSPawel Dziepak 	CLAIM_DELEGATE_CUR		= 2,
184d1e6b61eSPawel Dziepak 	CLAIM_DELEGATE_PREV		= 3
185d1e6b61eSPawel Dziepak };
186d1e6b61eSPawel Dziepak 
1872a292557SPawel Dziepak enum OpenFlags {
1882a292557SPawel Dziepak 	OPEN4_RESULT_CONFIRM		= 2,
1892a292557SPawel Dziepak 	OPEN4_RESULT_LOCKTYPE_POSIX	= 4
1902a292557SPawel Dziepak };
1912a292557SPawel Dziepak 
192e36a5442SPawel Dziepak enum WriteStable {
193e36a5442SPawel Dziepak 	UNSTABLE4				= 0,
194e36a5442SPawel Dziepak 	DATA_SYNC4				= 1,
195e36a5442SPawel Dziepak 	FILE_SYNC4				= 2
196e36a5442SPawel Dziepak };
197e36a5442SPawel Dziepak 
1987d0b8c97SPawel Dziepak enum LockType {
1997d0b8c97SPawel Dziepak 	READ_LT			= 1,
2007d0b8c97SPawel Dziepak 	WRITE_LT		= 2,
2017d0b8c97SPawel Dziepak 	READW_LT		= 3,
2027d0b8c97SPawel Dziepak 	WRITEW_LT		= 4
2037d0b8c97SPawel Dziepak };
2047d0b8c97SPawel Dziepak 
2057d0b8c97SPawel Dziepak 
2067d0b8c97SPawel Dziepak static inline
2077d0b8c97SPawel Dziepak LockType sGetLockType(short type, bool wait) {
2087d0b8c97SPawel Dziepak 	switch (type) {
2097d0b8c97SPawel Dziepak 		case F_RDLCK:	return wait ? READW_LT : READ_LT;
2107d0b8c97SPawel Dziepak 		case F_WRLCK:	return wait ? WRITEW_LT : WRITE_LT;
2117d0b8c97SPawel Dziepak 		default:		return READ_LT;
2127d0b8c97SPawel Dziepak 	}
2137d0b8c97SPawel Dziepak }
2147d0b8c97SPawel Dziepak 
2157d0b8c97SPawel Dziepak 
2167d0b8c97SPawel Dziepak static inline
2177d0b8c97SPawel Dziepak short sLockTypeToHaiku(LockType type) {
2187d0b8c97SPawel Dziepak 	switch (type) {
2197d0b8c97SPawel Dziepak 		case READ_LT:
2207d0b8c97SPawel Dziepak 		case READW_LT:
2217d0b8c97SPawel Dziepak 						return F_RDLCK;
2227d0b8c97SPawel Dziepak 
2237d0b8c97SPawel Dziepak 		case WRITE_LT:
2247d0b8c97SPawel Dziepak 		case WRITEW_LT:
2257d0b8c97SPawel Dziepak 						return F_WRLCK;
2267d0b8c97SPawel Dziepak 
2277d0b8c97SPawel Dziepak 		default:		return F_UNLCK;
2287d0b8c97SPawel Dziepak 	}
2297d0b8c97SPawel Dziepak }
2307d0b8c97SPawel Dziepak 
2317d0b8c97SPawel Dziepak 
2324aeb5952SPawel Dziepak enum Errors {
2334aeb5952SPawel Dziepak 	NFS4_OK						= 0,
2344aeb5952SPawel Dziepak 	NFS4ERR_PERM				= 1,
2354aeb5952SPawel Dziepak 	NFS4ERR_NOENT				= 2,
2364aeb5952SPawel Dziepak 	NFS4ERR_IO					= 5,
2374aeb5952SPawel Dziepak 	NFS4ERR_NXIO				= 6,
2384aeb5952SPawel Dziepak 	NFS4ERR_ACCESS				= 13,
2394aeb5952SPawel Dziepak 	NFS4ERR_EXIST				= 17,
2404aeb5952SPawel Dziepak 	NFS4ERR_XDEV				= 18,
2414aeb5952SPawel Dziepak 	NFS4ERR_NOTDIR				= 20,
2424aeb5952SPawel Dziepak 	NFS4ERR_ISDIR				= 21,
2434aeb5952SPawel Dziepak 	NFS4ERR_INVAL				= 22,
244b268b6f2SPawel Dziepak 	NFS4ERR_FBIG				= 27,
245b268b6f2SPawel Dziepak 	NFS4ERR_BADHANDLE			= 10001,
246b268b6f2SPawel Dziepak 	NFS4ERR_BAD_COOKIE			= 10003,
247b268b6f2SPawel Dziepak 	NFS4ERR_NOTSUPP				= 10004,
248b268b6f2SPawel Dziepak 	NFS4ERR_TOOSMALL			= 10005,
249b268b6f2SPawel Dziepak 	NFS4ERR_SERVERFAULT			= 10006,
250b268b6f2SPawel Dziepak 	NFS4ERR_BADTYPE				= 10007,
251b268b6f2SPawel Dziepak 	NFS4ERR_DELAY				= 10008,
252b268b6f2SPawel Dziepak 	NFS4ERR_SAME				= 10009,
253b268b6f2SPawel Dziepak 	NFS4ERR_DENIED				= 10010,
254b268b6f2SPawel Dziepak 	NFS4ERR_EXPIRED				= 10011,
255b268b6f2SPawel Dziepak 	NFS4ERR_LOCKED				= 10012,
256b268b6f2SPawel Dziepak 	NFS4ERR_GRACE				= 10013,
257b268b6f2SPawel Dziepak 	NFS4ERR_FHEXPIRED			= 10014,
258b268b6f2SPawel Dziepak 	NFS4ERR_SHARE_DENIED		= 10015,
259b268b6f2SPawel Dziepak 	NFS4ERR_WRONGSEC			= 10016,
260b268b6f2SPawel Dziepak 	NFS4ERR_CLID_INUSE			= 10017,
261b268b6f2SPawel Dziepak 	NFS4ERR_RESOURCE			= 10018,
262b268b6f2SPawel Dziepak 	NFS4ERR_MOVED				= 10019,
263b268b6f2SPawel Dziepak 	NFS4ERR_NOFILEHANDLE		= 10020,
264b268b6f2SPawel Dziepak 	NFS4ERR_MINOR_VERS_MISMATCH	= 10021,
265b268b6f2SPawel Dziepak 	NFS4ERR_STALE_CLIENTID		= 10022,
266b268b6f2SPawel Dziepak 	NFS4ERR_STALE_STATEID		= 10023,
267b268b6f2SPawel Dziepak 	NFS4ERR_OLD_STATEID			= 10024,
268b268b6f2SPawel Dziepak 	NFS4ERR_BAD_STATEID			= 10025,
269b268b6f2SPawel Dziepak 	NFS4ERR_BAD_SEQID			= 10026,
270b268b6f2SPawel Dziepak 	NFS4ERR_NOT_SAME			= 10027,
271b268b6f2SPawel Dziepak 	NFS4ERR_LOCK_RANGE			= 10028,
272b268b6f2SPawel Dziepak 	NFS4ERR_SYMLINK				= 10029,
273b268b6f2SPawel Dziepak 	NFS4ERR_RESTOREFH			= 10030,
274b268b6f2SPawel Dziepak 	NFS4ERR_LEASE_MOVED			= 10031,
275b268b6f2SPawel Dziepak 	NFS4ERR_ATTRNOTSUPP			= 10032,
276b268b6f2SPawel Dziepak 	NFS4ERR_NO_GRACE			= 10033,
277b268b6f2SPawel Dziepak 	NFS4ERR_RECLAIM_BAD			= 10034,
278b268b6f2SPawel Dziepak 	NFS4ERR_RECLAIM_CONFLICT	= 10035,
279b268b6f2SPawel Dziepak 	NFS4ERR_BADXDR				= 10036,
280b268b6f2SPawel Dziepak 	NFS4ERR_LOCKS_HELD			= 10037,
281b268b6f2SPawel Dziepak 	NFS4ERR_OPENMODE			= 10038,
282b268b6f2SPawel Dziepak 	NFS4ERR_BADOWNER			= 10039,
283b268b6f2SPawel Dziepak 	NFS4ERR_BADCHAR				= 10040,
284b268b6f2SPawel Dziepak 	NFS4ERR_BADNAME				= 10041,
285b268b6f2SPawel Dziepak 	NFS4ERR_BAD_RANGE			= 10042,
286b268b6f2SPawel Dziepak 	NFS4ERR_LOCK_NOTSUPP		= 10043,
287b268b6f2SPawel Dziepak 	NFS4ERR_OP_ILLEGAL			= 10044,
288b268b6f2SPawel Dziepak 	NFS4ERR_DEADLOCK			= 10045,
289b268b6f2SPawel Dziepak 	NFS4ERR_FILE_OPEN			= 10046,
290b268b6f2SPawel Dziepak 	NFS4ERR_ADMIN_REVOKED		= 10047,
291b268b6f2SPawel Dziepak 	NFS4ERR_CB_PATH_DOWN		= 10048
2924aeb5952SPawel Dziepak };
2934aeb5952SPawel Dziepak 
2944aeb5952SPawel Dziepak 
2954aeb5952SPawel Dziepak #endif	// NFS4DEFS_H
2964aeb5952SPawel Dziepak 
297