summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorgmorris <gmorris>2005-04-12 15:40:34 +0000
committergmorris <gmorris>2005-04-12 15:40:34 +0000
commit93407d94dd7d74a0f083bc43656151901f1c62b0 (patch)
tree9ecf91a0a7ebdfaccc22de9b4fac42da17cdc16d /utils
parent934f548d729ea94a6a84c48bafef8a9514e0a1fe (diff)
downloadnfs-utils-93407d94dd7d74a0f083bc43656151901f1c62b0.tar.gz
nfs-utils-93407d94dd7d74a0f083bc43656151901f1c62b0.tar.xz
nfs-utils-93407d94dd7d74a0f083bc43656151901f1c62b0.zip
Added list mounted nfs filesystems (-m) option
Diffstat (limited to 'utils')
-rw-r--r--utils/nfsstat/nfsstat.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c
index 55c4096..3b695f2 100644
--- a/utils/nfsstat/nfsstat.c
+++ b/utils/nfsstat/nfsstat.c
@@ -9,6 +9,8 @@
#define NFSSVCSTAT "/proc/net/rpc/nfsd"
#define NFSCLTSTAT "/proc/net/rpc/nfs"
+#define MOUNTSFILE "/proc/mounts"
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -110,6 +112,7 @@ static int parse_statfile(const char *, struct statinfo *);
static statinfo *get_stat_info(const char *, struct statinfo *);
+static int mounts(const char *);
#define PRNT_CALLS 0x0001
#define PRNT_RPC 0x0002
@@ -129,7 +132,7 @@ main(int argc, char **argv)
opt_prt = 0;
int c;
- while ((c = getopt(argc, argv, "acno:rsz")) != -1) {
+ while ((c = getopt(argc, argv, "acmno:rsz")) != -1) {
switch (c) {
case 'a':
opt_all = 1;
@@ -167,6 +170,8 @@ main(int argc, char **argv)
fprintf(stderr, "nfsstat: zeroing of nfs statistics "
"not yet supported\n");
return 2;
+ case 'm':
+ return mounts(MOUNTSFILE);
}
}
@@ -388,3 +393,51 @@ parse_statfile(const char *name, struct statinfo *statp)
fclose(fp);
return 1;
}
+
+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 -1;
+ }
+
+ 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 0;
+}