+
+static int
+mounts(const char *name)
+{
+ char buffer[4096], *next;
+ FILE *fp;
+
+ /* Being unable to read e.g. the nfsd stats file shouldn't
+ * be a fatal error -- it usually means the module isn't loaded.
+ */
+ if ((fp = fopen(name, "r")) == NULL) {
+ fprintf(stderr, "Warning: %s: %m\n", name);
+ return 0;
+ }
+
+ while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+ char *line = buffer;
+ char *device, *mount, *type, *flags;
+
+ if ((next = strchr(line, '\n')) != NULL)
+ *next = '\0';
+
+ if (!(device = strtok(line, " \t")))
+ continue;
+
+ if (!(mount = strtok(NULL, " \t")))
+ continue;
+
+ if (!(type = strtok(NULL, " \t")))
+ continue;
+
+ if (strcmp(type, "nfs")) {
+ continue;
+ }
+
+ if (!(flags = strtok(NULL, " \t")))
+ continue;
+
+ printf("%s from %s\n", mount, device);
+ printf(" Flags:\t%s\n", flags);
+ printf("\n");
+
+ continue;
+ }
+
+ fclose(fp);
+ return 1;
+}
+
+static void
+get_stats(const char *file, statinfo *info, int *opt, int other_opt, const char *label)
+{
+ if (!parse_statfile(file, info)) {
+ if (!other_opt) {
+ fprintf(stderr, "Warning: No %s Stats (%s: %m). \n", label, file);
+ exit(2);
+ }
+ *opt = 0;
+ }
+}
+
+static int
+has_stats(const unsigned int *info)
+{
+ return (info[0] && info[info[0] + 1] != info[0]);
+}
+
+/* clone 'src' to 'dest' */
+static void
+copy_stats(struct statinfo *dest, struct statinfo *src)
+{
+ int i, j;
+
+ for (i = 0; src[i].tag; i++) {
+ dest[i].tag = src[i].tag;
+ dest[i].nrvals = src[i].nrvals;
+ for (j = 0; j < dest[i].nrvals; j++)
+ dest[i].valptr[j] = src[i].valptr[j];
+ }
+}
+
+/*
+ * take the difference of each individual stat value in 'new' and 'old'
+ * and store the results back into 'new'
+ */
+static void
+diff_stats(struct statinfo *new, struct statinfo *old)
+{
+ int i, j, is_srv, should_diff;
+
+ is_srv = (new == srvinfo);
+ for (i = 0; old[i].tag; i++) {
+ for (j = 0; j < new[i].nrvals; j++) {
+ /* skip items in valptr that shouldn't be changed */
+ should_diff = (i < (3 + is_srv) || j > 0);
+ if (should_diff)
+ new[i].valptr[j] -= old[i].valptr[j];
+ }
+ }
+}
+
+static void
+unpause(int sig)
+{
+ double time_diff;
+ int minutes, seconds;
+ time_t endtime;
+
+ endtime = time(NULL);
+ time_diff = difftime(endtime, starttime);
+ minutes = time_diff / 60;
+ seconds = (int)time_diff % 60;
+ printf("Signal received; displaying (only) statistics gathered over the last %d minutes, %d seconds:\n\n", minutes, seconds);
+}