summaryrefslogtreecommitdiffstats
path: root/utils/mountd/rmtab.c
diff options
context:
space:
mode:
authorhjl <hjl>2000-06-01 00:57:09 +0000
committerhjl <hjl>2000-06-01 00:57:09 +0000
commit70a0e44cc77a7d8fc78c5514889bcd5d4fde3599 (patch)
treeb00d1063e2c1228d84d74c0aac0c82b7157b4963 /utils/mountd/rmtab.c
parent62393e334ac95e4cd61d959a4a2e675cf32f58a7 (diff)
downloadnfs-utils-70a0e44cc77a7d8fc78c5514889bcd5d4fde3599.tar.gz
nfs-utils-70a0e44cc77a7d8fc78c5514889bcd5d4fde3599.tar.xz
nfs-utils-70a0e44cc77a7d8fc78c5514889bcd5d4fde3599.zip
2000-05-31 H.J. Lu <hjl@lucon.org>
* configure.in (VERSION): Set to "0.1.7.5". * configure: Regenerated. * nfs-utils.spec: Updated. * support/include/nfslib.h (exportent): Add a new field, r_count, to count the number of mounts from a client. (getrmtabent): Take a new argument for position in file. (putrmtabent): Likewise. (fgetrmtabent): Likewise. (fputrmtabent): Likewise. * support/nfs/rmtab.c (getrmtabent): Handle the new argument for position in file. (fgetrmtabent): Likewise. (putrmtabent): Likewise. (fputrmtabent): Likewise. * support/nfs/rmtab.c (fgetrmtabent): Get value for the new field, r_count. * support/export/rmtab.c (rmtab_read): Pass NULL as the new argument to getrmtabent (), fgetrmtabent (), putrmtabent () and fputrmtabent (). * utils/mountd/rmtab.c (mountlist_add): Likewise. (mountlist_del): Likewise. (mountlist_del_all): Likewise. (mountlist_list): Likewise. * utils/mountd/rmtab.c (mountlist_add): Increment "r_count" for the existing entry and initialize "r_count" to 1. (mountlist_del): Decrement "r_count".
Diffstat (limited to 'utils/mountd/rmtab.c')
-rw-r--r--utils/mountd/rmtab.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/utils/mountd/rmtab.c b/utils/mountd/rmtab.c
index 289a42e..170d859 100644
--- a/utils/mountd/rmtab.c
+++ b/utils/mountd/rmtab.c
@@ -24,14 +24,17 @@ mountlist_add(nfs_export *exp, const char *path)
struct rmtabent xe;
struct rmtabent *rep;
int lockid;
+ long pos;
if ((lockid = xflock(_PATH_RMTAB, "a")) < 0)
return;
- setrmtabent("r");
- while ((rep = getrmtabent(1)) != NULL) {
+ setrmtabent("r+");
+ while ((rep = getrmtabent(1, &pos)) != NULL) {
if (strcmp (rep->r_client,
exp->m_client->m_hostname) == 0
&& strcmp(rep->r_path, path) == 0) {
+ rep->r_count++;
+ putrmtabent(rep, &pos);
endrmtabent();
xfunlock(lockid);
return;
@@ -43,8 +46,9 @@ mountlist_add(nfs_export *exp, const char *path)
xe.r_client [sizeof (xe.r_client) - 1] = '\0';
strncpy(xe.r_path, path, sizeof (xe.r_path) - 1);
xe.r_path [sizeof (xe.r_path) - 1] = '\0';
+ xe.r_count = 1;
if (setrmtabent("a")) {
- putrmtabent(&xe);
+ putrmtabent(&xe, NULL);
endrmtabent();
}
xfunlock(lockid);
@@ -57,6 +61,7 @@ mountlist_del(nfs_export *exp, const char *path)
FILE *fp;
char *hname = exp->m_client->m_hostname;
int lockid;
+ int match;
if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
return;
@@ -69,10 +74,13 @@ mountlist_del(nfs_export *exp, const char *path)
xfunlock(lockid);
return;
}
- while ((rep = getrmtabent(1)) != NULL) {
- if (strcmp (rep->r_client, hname)
- || strcmp(rep->r_path, path))
- fputrmtabent(fp, rep);
+ while ((rep = getrmtabent(1, NULL)) != NULL) {
+ match = !strcmp (rep->r_client, hname)
+ && !strcmp(rep->r_path, path);
+ if (match)
+ rep->r_count--;
+ if (!match || rep->r_count)
+ fputrmtabent(fp, rep, NULL);
}
if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
xlog(L_ERROR, "couldn't rename %s to %s",
@@ -114,13 +122,13 @@ mountlist_del_all(struct sockaddr_in *sin)
free (hp);
return;
}
- while ((rep = getrmtabent(1)) != NULL) {
+ while ((rep = getrmtabent(1, NULL)) != NULL) {
if (strcmp(rep->r_client, hp->h_name) == 0 &&
(exp = auth_authenticate("umountall", sin, rep->r_path))) {
export_reset(exp);
continue;
}
- fputrmtabent(fp, rep);
+ fputrmtabent(fp, rep, NULL);
}
if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
xlog(L_ERROR, "couldn't rename %s to %s",
@@ -158,7 +166,7 @@ mountlist_list(void)
last_mtime = stb.st_mtime;
setrmtabent("r");
- while ((rep = getrmtabent(1)) != NULL) {
+ while ((rep = getrmtabent(1, NULL)) != NULL) {
m = (mountlist) xmalloc(sizeof(*m));
m->ml_hostname = xstrdup(rep->r_client);
m->ml_directory = xstrdup(rep->r_path);