6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
13 #include <sys/fcntl.h>
22 static FILE *rmfp = NULL;
25 setrmtabent(char *type)
29 rmfp = fsetrmtabent(_PATH_RMTAB, type);
30 return (rmfp != NULL);
34 fsetrmtabent(char *fname, char *type)
36 int readonly = !strcmp(type, "r");
41 if ((fp = fopen(fname, type)) == NULL) {
42 xlog(L_ERROR, "can't open %s for %sing", fname,
43 readonly ? "read" : "writ");
50 getrmtabent(int log, long *pos)
52 return fgetrmtabent(rmfp, log, pos);
56 fgetrmtabent(FILE *fp, int log, long *pos)
58 static struct rmtabent re;
59 char buf[2048], *count, *host, *path;
67 if (fgets(buf, sizeof(buf)-1, fp) == NULL)
70 if ((path = strchr(host, '\n')) != NULL)
72 if (!(path = strchr(host, ':'))) {
74 xlog(L_ERROR, "malformed entry in rmtab file");
79 count = strchr(path, ':');
82 re.r_count = strtol (count, NULL, 0);
87 strncpy(re.r_client, host, sizeof (re.r_client) - 1);
88 re.r_client[sizeof (re.r_client) - 1] = '\0';
89 strncpy(re.r_path, path, sizeof (re.r_path) - 1);
90 re.r_path[sizeof (re.r_path) - 1] = '\0';
95 putrmtabent(struct rmtabent *rep, long *pos)
97 fputrmtabent(rmfp, rep, pos);
101 fputrmtabent(FILE *fp, struct rmtabent *rep, long *pos)
103 if (!fp || (pos && fseek (fp, *pos, SEEK_SET) != 0))
105 fprintf(fp, "%s:%s:0x%.8x\n", rep->r_client, rep->r_path,
117 fendrmtabent(FILE *fp)
120 /* If it was written to, we really want
121 * to flush to disk before returning
124 fdatasync(fileno(fp));
137 frewindrmtabent(FILE *fp)