---
name: "nfssvc"
section: "2"
platform: "macos"
package: "xnu"
version: "12377.121.6"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/nfssvc"
---

# nfssvc(2)

NFS services

## NAME

**nfssvc** – NFS services

## SYNOPSIS

**#include \<unistd.h\>**

**#include \<nfs/nfs.h\>**

*int*\

**nfssvc**(*int flags*, *void \*argstructp*);

## DESCRIPTION

The **nfssvc**() function is used by the NFS server daemon to pass information into and out of the kernel and also to enter the kernel as a server daemon. The *flags* argument consists of several bits that show what action is to be taken once in the kernel and the *argstructp* points to any corresponding data that the action may require.

**nfssvc**() is called with the flag NFSSVC\_NFSD and a NULL *argstructp* to enter the kernel as an [nfsd(8)](/nfsd/8.md) daemon. The NFSSVC\_NFSD action normally does not return until the NFS server is stopped.

The [nfsd(8)](/nfsd/8.md) server daemon calls **nfssvc**() with the flag NFSSVC\_ADDSOCK and a pointer to a

```
struct nfsd_args {
	int	sock;		/* Socket to serve */
	caddr_t	name;		/* Client address for connection based sockets */
	int	namelen;	/* Length of name */
};
```

to pass a server side NFS socket into the kernel for servicing by the [nfsd(8)](/nfsd/8.md) daemons.

The [nfsd(8)](/nfsd/8.md) server daemon calls **nfssvc**() with the flag NFSSVC\_EXPORT and a pointer to a

```
struct nfs_export_args {
	uint32_t		nxa_fsid;	/* export FS ID */
	uint32_t		nxa_expid;	/* export ID */
	char			*nxa_fspath;	/* export FS path */
	char			*nxa_exppath;	/* export sub-path */
	uint32_t		nxa_flags;	/* export arg flags */
	uint32_t		nxa_netcount;	/* #entries in ex_nets array */
	struct nfs_export_net_args *nxa_nets;	/* array of net args */
};
```

to pass exported file system information into the kernel.

Additionally, the **nfssvc**() is used by [nfsstat(1)](/nfsstat/1.md) tool to receive statistic about the server from kernel. While used, *argstructp* points to *struct*, *iovec* of size 2. The first *iovec* entry specifies the base address and length of an area in memory from which data should be written. The size of the available data will be returned in the location pointed by the second *iovec* entry. The following flags are supported :

- **NFSSVC\_EXPORTSTATS**

  Used to receive exported directory status.

- **NFSSVC\_USERSTATS**

  Used to receive exported directory active user status.

- **NFSSVC\_USERCOUNT**

  Used to receive current count of active NFS users.

- **NFSSVC\_ZEROSTATS**

  Used to zero NFS server statistics.

- **NFSSVC\_SRVSTATS**

  Used to receive NFS server statistics.

## RETURN VALUES

Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned the global variable *errno* is set to specify the error.

## ERRORS

- \[EPERM\]

  The caller is not the super-user.

- \[EINVAL\]

  The action specified by the *flags* argument was not valid.

- \[EFAULT\]

  *argstructp* points to an invalid address.

- \[ENOMEM\]

  A memory allocation failure prevented the action from completing.

- \[EEXIST\]

  An attempt was made to add a UDP socket via the NFSSVC\_ADDSOCK action, but the UDP socket has already been added.

## SEE ALSO

[nfsstat(1)](/nfsstat/1.md), [nfsd(8)](/nfsd/8.md)

## HISTORY

The **nfssvc** function first appeared in 4.4BSD.

## BUGS

The **nfssvc** system call is designed specifically for the NFS server daemons and as such is specific to their requirements. Several fields of the argument structures are assumed to be valid, such that **nfssvc** must be used with extreme care.
