2 * support/export/nfsctl.c
4 * Communicate export information to knfsd.
6 * Copyright (C) 1995 Olaf Kirch <okir@monad.swb.de>
20 static int expsetup(struct nfsctl_export *exparg, nfs_export *exp, int unexport);
21 static int cltsetup(struct nfsctl_client *cltarg, nfs_client *clp);
24 export_export(nfs_export *exp)
26 nfs_client * clp = exp->m_client;
27 struct nfsctl_export exparg;
28 struct nfsctl_client cltarg;
30 if (!clp->m_exported) {
31 if (!cltsetup(&cltarg, clp))
33 if (nfsaddclient(&cltarg) < 0)
37 if (!expsetup(&exparg, exp, 0))
39 if (nfsexport(&exparg) < 0)
46 export_unexport(nfs_export *exp)
48 struct nfsctl_export exparg;
50 if (!expsetup(&exparg, exp, 1) || nfsunexport(&exparg) < 0)
65 cltsetup(struct nfsctl_client *cltarg, nfs_client *clp)
69 if (clp->m_type != MCL_FQDN) {
70 xlog(L_ERROR, "internal: can't export non-FQDN host");
73 memset(cltarg, 0, sizeof(*cltarg));
74 strncpy(cltarg->cl_ident, clp->m_hostname,
75 sizeof (cltarg->cl_ident) - 1);
76 str_tolower(cltarg->cl_ident);
77 cltarg->cl_naddr = clp->m_naddr;
78 for (i = 0; i < cltarg->cl_naddr && i < NFSCLNT_ADDRMAX; i++)
79 cltarg->cl_addrlist[i] = clp->m_addrlist[i];
85 expsetup(struct nfsctl_export *exparg, nfs_export *exp, int unexport)
87 nfs_client *clp = exp->m_client;
90 if (stat(exp->m_export.m_path, &stb) < 0)
93 if (exp->m_export.e_maptype != CLE_MAP_IDENT) {
94 xlog(L_ERROR, "%s: unsupported mapping; kernel supports only 'identity' (default)",
95 exp->m_export.m_path);
99 memset(exparg, 0, sizeof(*exparg));
100 strncpy(exparg->ex_path, exp->m_export.m_path,
101 sizeof (exparg->ex_path) - 1);
102 strncpy(exparg->ex_client, clp->m_hostname,
103 sizeof (exparg->ex_client) - 1);
104 str_tolower(exparg->ex_client);
105 exparg->ex_flags = exp->m_export.e_flags;
106 exparg->ex_dev = (!unexport && (exp->m_export.e_flags & NFSEXP_FSID)) ?
107 exp->m_export.e_fsid : stb.st_dev;
108 exparg->ex_ino = stb.st_ino;
109 exparg->ex_anon_uid = exp->m_export.e_anonuid;
110 exparg->ex_anon_gid = exp->m_export.e_anongid;