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)
28 if ((lockid = xflock(xtab, "r")) < 0)
30 setexportent(xtab, "r");
31 while ((xp = getexportent()) != NULL) {
32 if (!(exp = export_lookup(xp->e_hostname, xp->e_path)) &&
33 !(exp = export_create(xp))) {
52 if ((fd=open(_PATH_PROC_EXPORTS, O_RDONLY))>=0) {
54 return xtab_read(_PATH_PROC_EXPORTS, 0);
56 return xtab_read(_PATH_XTAB, 0);
60 xtab_export_read(void)
62 return xtab_read(_PATH_ETAB, 1);
66 xtab_write(char *xtab, char *xtabtmp, int is_export)
72 if ((lockid = xflock(xtab, "w")) < 0) {
73 xlog(L_ERROR, "can't lock %s for writing", xtab);
76 setexportent(xtabtmp, "w");
78 for (i = 0; i < MCL_MAXTYPES; i++) {
79 for (exp = exportlist[i]; exp; exp = exp->m_next) {
80 if (is_export && !exp->m_xtabent)
82 if (!is_export && ! exp->m_exported)
85 /* write out the export entry using the FQDN */
87 strncpy(xe.e_hostname,
88 exp->m_client->m_hostname,
89 sizeof (xe.e_hostname) - 1);
90 xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';
96 rename(xtabtmp, xtab);
106 return xtab_write(_PATH_ETAB, _PATH_ETABTMP, 1);
112 return xtab_write(_PATH_XTAB, _PATH_XTABTMP, 0);
116 xtab_append(nfs_export *exp)
121 if ((lockid = xflock(_PATH_XTAB, "w")) < 0)
123 setexportent(_PATH_XTAB, "a");
125 strncpy(xe.e_hostname, exp->m_client->m_hostname,
126 sizeof (xe.e_hostname) - 1);
127 xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';