1 /* 2 * Copyright 2012 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Paweł Dziepak, pdziepak@quarnos.org 7 */ 8 #ifndef NFS4DEFS_H 9 #define NFS4DEFS_H 10 11 12 #include <fcntl.h> 13 #include <sys/stat.h> 14 15 #include <SupportDefs.h> 16 17 18 enum Procedure { 19 ProcNull = 0, 20 ProcCompound = 1 21 }; 22 23 enum CallbackProcedure { 24 CallbackProcNull = 0, 25 CallbackProcCompound = 1 26 }; 27 28 enum CallbackOpcode { 29 OpCallbackGetAttr = 3, 30 OpCallbackRecall = 4 31 }; 32 33 enum Opcode { 34 OpAccess = 3, 35 OpClose = 4, 36 OpCommit = 5, 37 OpCreate = 6, 38 OpDelegReturn = 8, 39 OpGetAttr = 9, 40 OpGetFH = 10, 41 OpLink = 11, 42 OpLock = 12, 43 OpLockT = 13, 44 OpLockU = 14, 45 OpLookUp = 15, 46 OpLookUpUp = 16, 47 OpNverify = 17, 48 OpOpen = 18, 49 OpOpenAttrDir = 19, 50 OpOpenConfirm = 20, 51 OpPutFH = 22, 52 OpPutRootFH = 24, 53 OpRead = 25, 54 OpReadDir = 26, 55 OpReadLink = 27, 56 OpRemove = 28, 57 OpRename = 29, 58 OpRenew = 30, 59 OpSaveFH = 32, 60 OpSetAttr = 34, 61 OpSetClientID = 35, 62 OpSetClientIDConfirm = 36, 63 OpVerify = 37, 64 OpWrite = 38, 65 OpReleaseLockOwner = 39 66 }; 67 68 enum Access { 69 ACCESS4_READ = 0x00000001, 70 ACCESS4_LOOKUP = 0x00000002, 71 ACCESS4_MODIFY = 0x00000004, 72 ACCESS4_EXTEND = 0x00000008, 73 ACCESS4_DELETE = 0x00000010, 74 ACCESS4_EXECUTE = 0x00000020 75 }; 76 77 enum Attribute { 78 // Mandatory Attributes 79 FATTR4_SUPPORTED_ATTRS = 0, 80 FATTR4_TYPE = 1, 81 FATTR4_FH_EXPIRE_TYPE = 2, 82 FATTR4_CHANGE = 3, 83 FATTR4_SIZE = 4, 84 FATTR4_LINK_SUPPORT = 5, 85 FATTR4_SYMLINK_SUPPORT = 6, 86 FATTR4_NAMED_ATTR = 7, 87 FATTR4_FSID = 8, 88 FATTR4_UNIQUE_HANDLES = 9, 89 FATTR4_LEASE_TIME = 10, 90 FATTR4_RDATTR_ERROR = 11, 91 FATTR4_FILEHANDLE = 19, 92 93 // Recommended Attributes 94 FATTR4_ACL = 12, 95 FATTR4_ACLSUPPORT = 13, 96 FATTR4_ARCHIVE = 14, 97 FATTR4_CANSETTIME = 15, 98 FATTR4_CASE_INSENSITIVE = 16, 99 FATTR4_CASE_PRESERVING = 17, 100 FATTR4_CHOWN_RESTRICTED = 18, 101 FATTR4_FILEID = 20, 102 FATTR4_FILES_AVAIL = 21, 103 FATTR4_FILES_FREE = 22, 104 FATTR4_FILES_TOTAL = 23, 105 FATTR4_FS_LOCATIONS = 24, 106 FATTR4_HIDDEN = 25, 107 FATTR4_HOMOGENEOUS = 26, 108 FATTR4_MAXFILESIZE = 27, 109 FATTR4_MAXLINK = 28, 110 FATTR4_MAXNAME = 29, 111 FATTR4_MAXREAD = 30, 112 FATTR4_MAXWRITE = 31, 113 FATTR4_MIMETYPE = 32, 114 FATTR4_MODE = 33, 115 FATTR4_NO_TRUNC = 34, 116 FATTR4_NUMLINKS = 35, 117 FATTR4_OWNER = 36, 118 FATTR4_OWNER_GROUP = 37, 119 FATTR4_QUOTA_AVAIL_HARD = 38, 120 FATTR4_QUOTA_AVAIL_SOFT = 39, 121 FATTR4_QUOTA_USED = 40, 122 FATTR4_RAWDEV = 41, 123 FATTR4_SPACE_AVAIL = 42, 124 FATTR4_SPACE_FREE = 43, 125 FATTR4_SPACE_TOTAL = 44, 126 FATTR4_SPACE_USED = 45, 127 FATTR4_SYSTEM = 46, 128 FATTR4_TIME_ACCESS = 47, 129 FATTR4_TIME_ACCESS_SET = 48, 130 FATTR4_TIME_BACKUP = 49, 131 FATTR4_TIME_CREATE = 50, 132 FATTR4_TIME_DELTA = 51, 133 FATTR4_TIME_METADATA = 52, 134 FATTR4_TIME_MODIFY = 53, 135 FATTR4_TIME_MODIFY_SET = 54, 136 FATTR4_MOUNTED_ON_FILEID = 55, 137 FATTR4_MAXIMUM_ATTR_ID 138 }; 139 140 enum CallbackAttr { 141 CallbackAttrSize = 1, 142 CallbackAttrChange = 2 143 }; 144 145 static inline bool sIsAttrSet(Attribute attr, const uint32* bitmap, 146 uint32 count) 147 { 148 if ((uint32)attr / 32 >= count) 149 return false; 150 151 return (bitmap[attr / 32] & 1 << attr % 32) != 0; 152 } 153 154 155 enum FileType { 156 NF4REG = 1, /* Regular File */ 157 NF4DIR = 2, /* Directory */ 158 NF4BLK = 3, /* Special File - block device */ 159 NF4CHR = 4, /* Special File - character device */ 160 NF4LNK = 5, /* Symbolic Link */ 161 NF4SOCK = 6, /* Special File - socket */ 162 NF4FIFO = 7, /* Special File - fifo */ 163 NF4ATTRDIR = 8, /* Attribute Directory */ 164 NF4NAMEDATTR = 9 /* Named Attribute */ 165 }; 166 167 static const mode_t sNFSFileTypeToHaiku[] = { 168 S_IFREG, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFSOCK, S_IFIFO, 169 S_IFDIR, S_IFREG 170 }; 171 172 enum FileHandleExpiryType { 173 FH4_PERSISTENT = 0x00, 174 FH4_NOEXPIRE_WITH_OPEN = 0x01, 175 FH4_VOLATILE_ANY = 0x02, 176 FH4_VOL_MIGRATION = 0x04, 177 FH4_VOL_RENAME = 0x08 178 }; 179 180 enum OpenAccess { 181 OPEN4_SHARE_ACCESS_READ = 1, 182 OPEN4_SHARE_ACCESS_WRITE = 2, 183 OPEN4_SHARE_ACCESS_BOTH = 3 184 }; 185 186 187 static inline OpenAccess 188 sModeToAccess(int mode) 189 { 190 switch (mode & O_RWMASK) { 191 case O_RDONLY: 192 return OPEN4_SHARE_ACCESS_READ; 193 case O_WRONLY: 194 return OPEN4_SHARE_ACCESS_WRITE; 195 case O_RDWR: 196 return OPEN4_SHARE_ACCESS_BOTH; 197 } 198 199 return OPEN4_SHARE_ACCESS_READ; 200 } 201 202 203 enum OpenCreate { 204 OPEN4_NOCREATE = 0, 205 OPEN4_CREATE = 1 206 }; 207 208 enum OpenCreateHow { 209 UNCHECKED4 = 0, 210 GUARDED4 = 1, 211 EXCLUSIVE4 = 2 212 }; 213 214 enum OpenClaim { 215 CLAIM_NULL = 0, 216 CLAIM_PREVIOUS = 1, 217 CLAIM_DELEGATE_CUR = 2, 218 CLAIM_DELEGATE_PREV = 3 219 }; 220 221 enum OpenDelegation { 222 OPEN_DELEGATE_NONE = 0, 223 OPEN_DELEGATE_READ = 1, 224 OPEN_DELEGATE_WRITE = 2 225 }; 226 227 struct OpenDelegationData { 228 OpenDelegation fType; 229 230 uint32 fStateSeq; 231 uint32 fStateID[3]; 232 233 bool fRecall; 234 uint64 fSpaceLimit; 235 }; 236 237 enum OpenFlags { 238 OPEN4_RESULT_CONFIRM = 2, 239 OPEN4_RESULT_LOCKTYPE_POSIX = 4 240 }; 241 242 enum { 243 NFS_LIMIT_SIZE = 1, 244 NFS_LIMIT_BLOCKS = 2 245 }; 246 247 struct ChangeInfo { 248 bool fAtomic; 249 uint64 fBefore; 250 uint64 fAfter; 251 }; 252 253 enum WriteStable { 254 UNSTABLE4 = 0, 255 DATA_SYNC4 = 1, 256 FILE_SYNC4 = 2 257 }; 258 259 enum LockType { 260 READ_LT = 1, 261 WRITE_LT = 2, 262 READW_LT = 3, 263 WRITEW_LT = 4 264 }; 265 266 267 static inline LockType 268 sGetLockType(short type, bool wait) { 269 switch (type) { 270 case F_RDLCK: return wait ? READW_LT : READ_LT; 271 case F_WRLCK: return wait ? WRITEW_LT : WRITE_LT; 272 default: return READ_LT; 273 } 274 } 275 276 277 static inline short 278 sLockTypeToHaiku(LockType type) { 279 switch (type) { 280 case READ_LT: 281 case READW_LT: 282 return F_RDLCK; 283 284 case WRITE_LT: 285 case WRITEW_LT: 286 return F_WRLCK; 287 288 default: return F_UNLCK; 289 } 290 } 291 292 293 enum Errors { 294 NFS4_OK = 0, 295 NFS4ERR_PERM = 1, 296 NFS4ERR_NOENT = 2, 297 NFS4ERR_IO = 5, 298 NFS4ERR_NXIO = 6, 299 NFS4ERR_ACCESS = 13, 300 NFS4ERR_EXIST = 17, 301 NFS4ERR_XDEV = 18, 302 NFS4ERR_NOTDIR = 20, 303 NFS4ERR_ISDIR = 21, 304 NFS4ERR_INVAL = 22, 305 NFS4ERR_FBIG = 27, 306 NFS4ERR_NOSPC = 28, 307 NFS4ERR_ROFS = 30, 308 NFS4ERR_MLINK = 31, 309 NFS4ERR_NAMETOOLONG = 63, 310 NFS4ERR_NOTEMPTY = 66, 311 NFS4ERR_DQUOT = 69, 312 NFS4ERR_STALE = 70, 313 NFS4ERR_BADHANDLE = 10001, 314 NFS4ERR_BAD_COOKIE = 10003, 315 NFS4ERR_NOTSUPP = 10004, 316 NFS4ERR_TOOSMALL = 10005, 317 NFS4ERR_SERVERFAULT = 10006, 318 NFS4ERR_BADTYPE = 10007, 319 NFS4ERR_DELAY = 10008, 320 NFS4ERR_SAME = 10009, 321 NFS4ERR_DENIED = 10010, 322 NFS4ERR_EXPIRED = 10011, 323 NFS4ERR_LOCKED = 10012, 324 NFS4ERR_GRACE = 10013, 325 NFS4ERR_FHEXPIRED = 10014, 326 NFS4ERR_SHARE_DENIED = 10015, 327 NFS4ERR_WRONGSEC = 10016, 328 NFS4ERR_CLID_INUSE = 10017, 329 NFS4ERR_RESOURCE = 10018, 330 NFS4ERR_MOVED = 10019, 331 NFS4ERR_NOFILEHANDLE = 10020, 332 NFS4ERR_MINOR_VERS_MISMATCH = 10021, 333 NFS4ERR_STALE_CLIENTID = 10022, 334 NFS4ERR_STALE_STATEID = 10023, 335 NFS4ERR_OLD_STATEID = 10024, 336 NFS4ERR_BAD_STATEID = 10025, 337 NFS4ERR_BAD_SEQID = 10026, 338 NFS4ERR_NOT_SAME = 10027, 339 NFS4ERR_LOCK_RANGE = 10028, 340 NFS4ERR_SYMLINK = 10029, 341 NFS4ERR_RESTOREFH = 10030, 342 NFS4ERR_LEASE_MOVED = 10031, 343 NFS4ERR_ATTRNOTSUPP = 10032, 344 NFS4ERR_NO_GRACE = 10033, 345 NFS4ERR_RECLAIM_BAD = 10034, 346 NFS4ERR_RECLAIM_CONFLICT = 10035, 347 NFS4ERR_BADXDR = 10036, 348 NFS4ERR_LOCKS_HELD = 10037, 349 NFS4ERR_OPENMODE = 10038, 350 NFS4ERR_BADOWNER = 10039, 351 NFS4ERR_BADCHAR = 10040, 352 NFS4ERR_BADNAME = 10041, 353 NFS4ERR_BAD_RANGE = 10042, 354 NFS4ERR_LOCK_NOTSUPP = 10043, 355 NFS4ERR_OP_ILLEGAL = 10044, 356 NFS4ERR_DEADLOCK = 10045, 357 NFS4ERR_FILE_OPEN = 10046, 358 NFS4ERR_ADMIN_REVOKED = 10047, 359 NFS4ERR_CB_PATH_DOWN = 10048 360 }; 361 362 363 static inline bigtime_t 364 sSecToBigTime(uint32 sec) 365 { 366 return static_cast<bigtime_t>(sec) * 1000000; 367 } 368 369 370 static inline bool 371 IsFileHandleInvalid(uint32 error) 372 { 373 return error == NFS4ERR_BADHANDLE || error == NFS4ERR_FHEXPIRED 374 || error == NFS4ERR_STALE; 375 } 376 377 378 #endif // NFS4DEFS_H 379 380