6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
11 #include <sys/fcntl.h>
20 static FILE *rmfp = NULL;
23 setrmtabent(char *type)
27 rmfp = fsetrmtabent(_PATH_RMTAB, type);
28 return (rmfp != NULL);
32 fsetrmtabent(char *fname, char *type)
34 int readonly = !strcmp(type, "r");
39 if ((fp = fopen(fname, type)) == NULL) {
40 xlog(L_ERROR, "can't open %s for %sing", fname,
41 readonly ? "read" : "writ");
48 getrmtabent(int log, long *pos)
50 return fgetrmtabent(rmfp, log, pos);
54 fgetrmtabent(FILE *fp, int log, long *pos)
56 static struct rmtabent re;
57 char buf[2048], *count, *host, *path;
65 if (fgets(buf, sizeof(buf)-1, fp) == NULL)
68 if ((path = strchr(host, '\n')) != NULL)
70 if (!(path = strchr(host, ':'))) {
72 xlog(L_ERROR, "malformed entry in rmtab file");
77 count = strchr(path, ':');
80 re.r_count = strtol (count, NULL, 0);
85 strncpy(re.r_client, host, sizeof (re.r_client) - 1);
86 re.r_client[sizeof (re.r_client) - 1] = '\0';
87 strncpy(re.r_path, path, sizeof (re.r_path) - 1);
88 re.r_path[sizeof (re.r_path) - 1] = '\0';
93 putrmtabent(struct rmtabent *rep, long *pos)
95 fputrmtabent(rmfp, rep, pos);
99 fputrmtabent(FILE *fp, struct rmtabent *rep, long *pos)
101 if (!fp || (pos && fseek (fp, *pos, SEEK_SET) != 0))
103 fprintf(fp, "%s:%s:0x%.8x\n", rep->r_client, rep->r_path,
115 fendrmtabent(FILE *fp)
118 /* If it was written to, we really want
119 * to flush to disk before returning
122 fdatasync(fileno(fp));
135 frewindrmtabent(FILE *fp)