Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/cgdconfig List all cgd's no matter if they are not cont...
details: https://anonhg.NetBSD.org/src/rev/168a2d2a35ed
branches: trunk
changeset: 787293:168a2d2a35ed
user: christos <christos%NetBSD.org@localhost>
date: Sun Jun 09 18:37:40 2013 +0000
description:
List all cgd's no matter if they are not contiguously allocated
diffstat:
sbin/cgdconfig/cgdconfig.c | 136 ++++++++++++++++++++++++++------------------
1 files changed, 81 insertions(+), 55 deletions(-)
diffs (180 lines):
diff -r a0df10d0ebe9 -r 168a2d2a35ed sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c Sun Jun 09 18:29:25 2013 +0000
+++ b/sbin/cgdconfig/cgdconfig.c Sun Jun 09 18:37:40 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.34 2012/12/05 02:23:20 christos Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.35 2013/06/09 18:37:40 christos Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 2002, 2003\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.34 2012/12/05 02:23:20 christos Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.35 2013/06/09 18:37:40 christos Exp $");
#endif
#include <err.h>
@@ -45,6 +45,8 @@
#include <string.h>
#include <unistd.h>
#include <util.h>
+#include <paths.h>
+#include <dirent.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h>
@@ -52,6 +54,7 @@
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/statvfs.h>
+#include <sys/bitops.h>
#include <dev/cgdvar.h>
@@ -999,68 +1002,91 @@
}
}
+
+static void
+show(const char *dev) {
+ char path[64];
+ struct cgd_user cgu;
+ int fd;
+
+ fd = opendisk(dev, O_RDONLY, path, sizeof(path), 0);
+ if (fd == -1) {
+ warn("open: %s", dev);
+ return;
+ }
+
+ cgu.cgu_unit = -1;
+ if (prog_ioctl(fd, CGDIOCGET, &cgu) == -1) {
+ close(fd);
+ err(1, "CGDIOCGET");
+ }
+
+ printf("%s: ", dev);
+
+ if (cgu.cgu_dev == 0) {
+ printf("not in use");
+ goto out;
+ }
+
+ dev = devname(cgu.cgu_dev, S_IFBLK);
+ if (dev != NULL)
+ printf("%s ", dev);
+ else
+ printf("dev %llu,%llu ", (unsigned long long)major(cgu.cgu_dev),
+ (unsigned long long)minor(cgu.cgu_dev));
+
+ if (verbose)
+ printf("%s ", cgu.cgu_alg);
+ if (verbose > 1) {
+ printf("keylen %d ", cgu.cgu_keylen);
+ printf("blksize %zd ", cgu.cgu_blocksize);
+ printf("%s ", iv_method(cgu.cgu_mode));
+ }
+
+out:
+ putchar('\n');
+ close(fd);
+}
+
static int
do_list(int argc, char **argv)
{
- char path[64], buf[16];
- struct cgd_user cgu;
- const char *fn;
- int fd, n, rv;
if (argc != 0 && argc != 1)
usage();
- fn = argc ? argv[0] : "cgd0";
- n = 0;
- for (;;) {
- fd = opendisk(fn, O_RDONLY, path, sizeof(path), 0);
- if (fd == -1) {
- if (argc)
- err(1, "open: %s", fn);
- break;
- }
-
- cgu.cgu_unit = argc ? -1 : n;
- rv = prog_ioctl(fd, CGDIOCGET, &cgu);
- if (rv == -1) {
- close(fd);
- err(1, "CGDIOCGET");
- }
-
- printf("%s: ", fn);
-
- if (cgu.cgu_dev == 0)
- printf("not in use");
- else {
- char *dev;
-
- dev = devname(cgu.cgu_dev, S_IFBLK);
- if (dev != NULL)
- printf("%s ", dev);
- else
- printf("dev %llu,%llu ",
- (unsigned long long)major(cgu.cgu_dev),
- (unsigned long long)minor(cgu.cgu_dev));
-
- if (verbose)
- printf("%s ", cgu.cgu_alg);
- if (verbose > 1) {
- printf("keylen %d ", cgu.cgu_keylen);
- printf("blksize %zd ", cgu.cgu_blocksize);
- printf("%s ", iv_method(cgu.cgu_mode));
- }
- }
- putchar('\n');
- close(fd);
-
- if (argc)
- break;
-
- n++;
- snprintf(buf, sizeof(buf), "cgd%d", n);
- fn = buf;
+ if (argc) {
+ show(argv[0]);
+ return 0;
}
+ DIR *dirp;
+ struct dirent *dp;
+ __BITMAP_TYPE(, uint32_t, 65536) bm;
+
+ __BITMAP_ZERO(&bm);
+
+ if ((dirp = opendir(_PATH_DEV)) == NULL)
+ err(1, "opendir: %s", _PATH_DEV);
+
+ while ((dp = readdir(dirp)) != NULL) {
+ char *ep;
+ if (strncmp(dp->d_name, "rcgd", 4) != 0)
+ continue;
+ errno = 0;
+ int n = (int)strtol(dp->d_name + 4, &ep, 0);
+ if (ep == dp->d_name + 4 || errno != 0) {
+ warnx("bad name %s", dp->d_name);
+ continue;
+ }
+ *ep = '\0';
+ if (__BITMAP_ISSET(n, &bm))
+ continue;
+ __BITMAP_SET(n, &bm);
+ show(dp->d_name + 1);
+ }
+
+ closedir(dirp);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index