summaryrefslogtreecommitdiffstats
path: root/sbin/vinum/list.c
diff options
context:
space:
mode:
authorgrog <grog@FreeBSD.org>1999-05-02 08:02:03 +0000
committergrog <grog@FreeBSD.org>1999-05-02 08:02:03 +0000
commit6817ec0781bfd9c802ec52bbb802bd87949995cf (patch)
tree2c657f4db36a3b674cf64f15ea351619d6436cd1 /sbin/vinum/list.c
parentc54171c955493d08e58e6a8575f92165e9cb3acb (diff)
downloadFreeBSD-src-6817ec0781bfd9c802ec52bbb802bd87949995cf.zip
FreeBSD-src-6817ec0781bfd9c802ec52bbb802bd87949995cf.tar.gz
printconfig:
split into vinum_printconfig (interactive) and printconfig (called from vinum_printconfig and from vinum_create when starting an interactive update.
Diffstat (limited to 'sbin/vinum/list.c')
-rw-r--r--sbin/vinum/list.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/sbin/vinum/list.c b/sbin/vinum/list.c
index 873c8c0..e4fa78c 100644
--- a/sbin/vinum/list.c
+++ b/sbin/vinum/list.c
@@ -788,12 +788,40 @@ vinum_info(int argc, char *argv[], char *argv0[])
#endif
}
-/* Print config file to a file. This is a userland version
- * of kernel format_config */
+/*
+ * Print config file to a file. This is a userland version
+ * of kernel format_config
+ */
void
vinum_printconfig(int argc, char *argv[], char *argv0[])
{
FILE *of;
+
+ if (argc > 1) {
+ fprintf(stderr, "Usage: \tprintconfig [<outfile>]\n");
+ return;
+ } else if (argc == 1)
+ of = fopen(argv[0], "w");
+ else
+ of = stdout;
+ if (of == NULL) {
+ fprintf(stderr, "Can't open %s: %s\n", argv[0], strerror(errno));
+ return;
+ }
+ printconfig(of, "");
+ if (argc == 1)
+ fclose(of);
+}
+
+/*
+ * The guts of printconfig. This is called from
+ * vinum_printconfig and from vinum_create when
+ * called without an argument, in order to give
+ * the user something to edit.
+ */
+void
+printconfig(FILE * of, char *comment)
+{
struct utsname uname_s;
time_t now;
int i;
@@ -802,19 +830,10 @@ vinum_printconfig(int argc, char *argv[], char *argv0[])
struct sd sd;
struct drive drive;
- if (argc != 1) {
- fprintf(stderr, "Usage: \tprintconfig <outfile>\n");
- return;
- }
if (ioctl(superdev, VINUM_GETCONFIG, &vinum_conf) < 0) {
perror("Can't get vinum config");
return;
}
- of = fopen(argv[0], "w");
- if (of == NULL) {
- fprintf(stderr, "Can't open %s: %s\n", argv[0], strerror(errno));
- return;
- }
uname(&uname_s); /* get our system name */
time(&now); /* and the current time */
fprintf(of,
@@ -822,11 +841,14 @@ vinum_printconfig(int argc, char *argv[], char *argv0[])
uname_s.nodename,
ctime(&now)); /* say who did it */
+ if (comment[0] != 0) /* abuse this for commented version */
+ fprintf(of, "# Current configuration:\n");
for (i = 0; i < vinum_conf.drives_allocated; i++) {
get_drive_info(&drive, i);
if (drive.state != drive_unallocated) {
fprintf(of,
- "drive %s device %s\n",
+ "%sdrive %s device %s\n",
+ comment,
drive.label.name,
drive.devicename);
}
@@ -837,11 +859,12 @@ vinum_printconfig(int argc, char *argv[], char *argv0[])
if (vol.state != volume_unallocated) {
if (vol.preferred_plex >= 0) /* preferences, */
fprintf(of,
- "volume %s readpol prefer %s\n",
+ "%svolume %s readpol prefer %s\n",
+ comment,
vol.name,
vinum_conf.plex[vol.preferred_plex].name);
else /* default round-robin */
- fprintf(of, "volume %s\n", vol.name);
+ fprintf(of, "%svolume %s\n", comment, vol.name);
}
}
@@ -849,7 +872,8 @@ vinum_printconfig(int argc, char *argv[], char *argv0[])
for (i = 0; i < vinum_conf.plexes_allocated; i++) {
get_plex_info(&plex, i);
if (plex.state != plex_unallocated) {
- fprintf(of, "plex name %s org %s ",
+ fprintf(of, "%splex name %s org %s ",
+ comment,
plex.name,
plex_org(plex.organization));
if ((plex.organization == plex_striped)
@@ -871,7 +895,8 @@ vinum_printconfig(int argc, char *argv[], char *argv0[])
get_drive_info(&drive, sd.driveno);
get_plex_info(&plex, sd.plexno);
fprintf(of,
- "sd name %s drive %s plex %s len %qdb driveoffset %qdb plexoffset %qdb\n",
+ "%ssd name %s drive %s plex %s len %qdb driveoffset %qdb plexoffset %qdb\n",
+ comment,
sd.name,
drive.label.name,
plex.name,
OpenPOWER on IntegriCloud