/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2009 Rick Macklem, University of Guelph4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/*29* These macros handle nfsvattr fields. They look a bit silly here, but30* are quite different for the Darwin port.31*/32#define NFSVNO_ATTRINIT(n) (VATTR_NULL(&((n)->na_vattr)))33#define NFSVNO_SETATTRVAL(n, f, v) ((n)->na_##f = (v))34#define NFSVNO_SETACTIVE(n, f)35#define NFSVNO_UNSET(n, f) ((n)->na_##f = VNOVAL)36#define NFSVNO_NOTSETMODE(n) ((n)->na_mode == ((mode_t)VNOVAL))37#define NFSVNO_ISSETMODE(n) ((n)->na_mode != ((mode_t)VNOVAL))38#define NFSVNO_NOTSETUID(n) ((n)->na_uid == ((uid_t)VNOVAL))39#define NFSVNO_ISSETUID(n) ((n)->na_uid != ((uid_t)VNOVAL))40#define NFSVNO_NOTSETGID(n) ((n)->na_gid == ((gid_t)VNOVAL))41#define NFSVNO_ISSETGID(n) ((n)->na_gid != ((gid_t)VNOVAL))42#define NFSVNO_NOTSETSIZE(n) ((n)->na_size == VNOVAL)43#define NFSVNO_ISSETSIZE(n) ((n)->na_size != VNOVAL)44#define NFSVNO_NOTSETATIME(n) ((n)->na_atime.tv_sec == VNOVAL)45#define NFSVNO_ISSETATIME(n) ((n)->na_atime.tv_sec != VNOVAL)46#define NFSVNO_NOTSETMTIME(n) ((n)->na_mtime.tv_sec == VNOVAL)47#define NFSVNO_ISSETMTIME(n) ((n)->na_mtime.tv_sec != VNOVAL)48#define NFSVNO_NOTSETFLAGS(n) ((n)->na_flags == VNOVAL)49#define NFSVNO_ISSETFLAGS(n) ((n)->na_flags != VNOVAL)5051/*52* This structure acts as a "catch-all" for information that53* needs to be returned by nfsd_fhtovp().54*/55struct nfsexstuff {56uint64_t nes_exflag; /* export flags */57int nes_numsecflavor; /* # of security flavors */58int nes_secflavors[MAXSECFLAVORS]; /* and the flavors */59};6061/*62* These are NO-OPS for BSD until Isilon upstreams EXITCODE support.63* EXITCODE is an in-memory ring buffer that holds the routines failing status.64* This is a valuable tool to use when debugging and analyzing issues.65* In addition to recording a routine's failing status, it offers66* logging of routines for call stack tracing.67* EXITCODE should be used only in routines that return a true errno value, as68* that value will be formatted to a displayable errno string. Routines that69* return regular int status that are not true errno should not set EXITCODE.70* If you want to log routine tracing, you can add EXITCODE(0) to any routine.71* NFS extended the EXITCODE with EXITCODE2 to record either the routine's72* exit errno status or the nd_repstat.73*/74#define NFSEXITCODE(error)75#define NFSEXITCODE2(error, nd)7677#define NFSVNO_EXINIT(e) ((e)->nes_exflag = 0)78#define NFSVNO_EXPORTED(e) ((e)->nes_exflag & MNT_EXPORTED)79#define NFSVNO_EXRDONLY(e) ((e)->nes_exflag & MNT_EXRDONLY)80#define NFSVNO_EXPORTANON(e) ((e)->nes_exflag & MNT_EXPORTANON)81#define NFSVNO_EXSTRICTACCESS(e) ((e)->nes_exflag & MNT_EXSTRICTACCESS)82#define NFSVNO_EXV4ONLY(e) ((e)->nes_exflag & MNT_EXV4ONLY)83#define NFSVNO_EXTLS(e) ((e)->nes_exflag & MNT_EXTLS)84#define NFSVNO_EXTLSCERT(e) ((e)->nes_exflag & MNT_EXTLSCERT)85#define NFSVNO_EXTLSCERTUSER(e) ((e)->nes_exflag & MNT_EXTLSCERTUSER)8687#define NFSVNO_SETEXRDONLY(e) ((e)->nes_exflag = (MNT_EXPORTED|MNT_EXRDONLY))8889#define NFSVNO_CMPFH(f1, f2) \90(fsidcmp(&(f1)->fh_fsid, &(f2)->fh_fsid) == 0 && \91bcmp(&(f1)->fh_fid, &(f2)->fh_fid, sizeof(struct fid)) == 0)9293#define NFSLOCKHASH(f) \94(&NFSD_VNET(nfslockhash)[nfsrv_hashfh(f) % nfsrv_lockhashsize])9596#define NFSFPVNODE(f) ((f)->f_vnode)97#define NFSFPCRED(f) ((f)->f_cred)98#define NFSFPFLAG(f) ((f)->f_flag)99100#define NFSNAMEICNDSET(n, c, o, f) do { \101(n)->cn_cred = (c); \102(n)->cn_nameiop = (o); \103(n)->cn_flags = (f); \104} while (0)105106#define NFSPATHLEN_T size_t107108/*109* These are set to the minimum and maximum size of a server file110* handle.111*/112#define NFSRV_MINFH (sizeof (fhandle_t))113#define NFSRV_MAXFH (sizeof (fhandle_t))114115/* Use this macro for debug printfs. */116#define NFSD_DEBUG(level, ...) do { \117if (nfsd_debuglevel >= (level)) \118printf(__VA_ARGS__); \119} while (0)120121122