2 * support/export/xtab.c
4 * Interface to the xtab file.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
11 #include <sys/fcntl.h>
22 xtab_read(char *xtab, int is_export)
24 /* is_export == 0 => reading /proc/fs/nfs/exports - we know these things are exported to kernel
25 * is_export == 1 => reading /var/lib/nfs/etab - these things are allowed to be exported
26 * is_export == 2 => reading /var/lib/nfs/xtab - these things might be known to kernel
32 if ((lockid = xflock(xtab, "r")) < 0)
34 setexportent(xtab, "r");
35 while ((xp = getexportent(is_export==0, 0)) != NULL) {
36 if (!(exp = export_lookup(xp->e_hostname, xp->e_path, is_export != 1)) &&
37 !(exp = export_create(xp, is_export!=1))) {
49 exp->m_exported = -1;/* may be exported */
63 if ((fd=open(_PATH_PROC_EXPORTS, O_RDONLY))>=0) {
65 return xtab_read(_PATH_PROC_EXPORTS, 0);
67 return xtab_read(_PATH_XTAB, 2);
71 xtab_export_read(void)
73 return xtab_read(_PATH_ETAB, 1);
77 xtab_write(char *xtab, char *xtabtmp, int is_export)
83 if ((lockid = xflock(xtab, "w")) < 0) {
84 xlog(L_ERROR, "can't lock %s for writing", xtab);
87 setexportent(xtabtmp, "w");
89 for (i = 0; i < MCL_MAXTYPES; i++) {
90 for (exp = exportlist[i]; exp; exp = exp->m_next) {
91 if (is_export && !exp->m_xtabent)
93 if (!is_export && ! exp->m_exported)
96 /* write out the export entry using the FQDN */
98 strncpy(xe.e_hostname,
99 exp->m_client->m_hostname,
100 sizeof (xe.e_hostname) - 1);
101 xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';
107 rename(xtabtmp, xtab);
117 return xtab_write(_PATH_ETAB, _PATH_ETABTMP, 1);
123 return xtab_write(_PATH_XTAB, _PATH_XTABTMP, 0);
127 xtab_append(nfs_export *exp)
132 if ((lockid = xflock(_PATH_XTAB, "w")) < 0)
134 setexportent(_PATH_XTAB, "a");
136 strncpy(xe.e_hostname, exp->m_client->m_hostname,
137 sizeof (xe.e_hostname) - 1);
138 xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';