/*
* Copyright (c) 2011 François Tigeot <ftigeot@wolfpond.org>
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* 3. Neither the name of The DragonFly Project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific, prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*/
#include <sys/stat.h>
+#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
static void usage(int);
static int get_dirsize(char *);
+static int get_fslist(void);
static void
usage(int retcode)
{
fprintf(stderr, "usage: vquota check directory\n");
+ fprintf(stderr, " vquota lsfs\n");
exit(retcode);
}
retval = 1;
break;
default:
-#if 0
- /* files with more than one link, undecided */
- // if (p->fts_statp->st_nlink > 1 && linkchk(p))
- if (p->fts_statp->st_nlink > 1)
- fprintf(stderr, "%s has more than one link\n",
- p->fts_name );
-#endif
size_of_files += p->fts_statp->st_size;
}
}
return retval;
}
+/* print a list of filesystems with accounting enabled */
+static int get_fslist(void) {
+ struct statfs *mntbufp;
+ int nloc, i;
+
+ /* read mount table from kernel */
+ nloc = getmntinfo(&mntbufp, MNT_NOWAIT|MNT_LOCAL);
+ if (nloc <= 0) {
+ perror("getmntinfo");
+ exit(1);
+ }
+
+ /* iterate mounted filesystems */
+ for (i=0; i<nloc; i++) {
+ /* vfs accounting enabled on this one ? */
+ if (mntbufp[i].f_flags & MNT_ACCOUNTING)
+ printf("%s on %s\n", mntbufp[i].f_mntfromname,
+ mntbufp[i].f_mntonname);
+ }
+
+ return 0;
+}
+
int
main(int argc, char **argv)
{
- if (argc < 3)
+ if (argc < 2)
usage(1);
if (strcmp(argv[1], "check") == 0) {
+ if (argc < 3)
+ usage(1);
return get_dirsize(argv[2]);
- } else {
- usage(1);
+ }
+ if (strcmp(argv[1], "lsfs") == 0) {
+ return get_fslist();
}
- return 0;
+ return(0);
}
mp->mnt_acct.ac_bytes = 0;
- /* and enable data collection */
+ /* enable data collection */
mp->mnt_op->vfs_account = vfs_stdaccount;
+ /* mark this filesystem as having accounting enabled */
+ mp->mnt_flag |= MNT_ACCOUNTING;
if (bootverbose)
kprintf("vfs accounting enabled for %s\n",
mp->mnt_stat.f_mntonname);
#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
#define MNT_USER 0x00008000 /* mounted by a user */
+#define MNT_ACCOUNTING 0x00020000 /* accounting is enabled on filesystem */
#define MNT_IGNORE 0x00800000 /* do not show entry in df */
/*
MNT_LOCAL | MNT_USER | MNT_QUOTA | \
MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \
MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP | \
- MNT_IGNORE | MNT_NOSYMFOLLOW | MNT_EXPUBLIC | MNT_TRIM)
+ MNT_IGNORE | MNT_NOSYMFOLLOW | MNT_EXPUBLIC| \
+ MNT_ACCOUNTING | MNT_TRIM)
/*
* External filesystem command modifier flags.
* Unmount can use the MNT_FORCE flag.