2 * Copyright (C) 2013 IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #if defined(HAVE_CONFIG_H)
24 #include <talloc/talloc.h>
25 #include <types/types.h>
27 #include <util/util.h>
30 #include "nc-textscreen.h"
31 #include "nc-sysinfo.h"
33 struct sysinfo_screen {
34 struct text_screen text_scr;
37 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
39 return text_screen_scr(&screen->text_scr);
42 static void if_info_mac_str(struct interface_info *info,
43 char *buf, unsigned int buflen)
45 return mac_str(info->hwaddr, info->hwaddr_size, buf, buflen);
48 static void sysinfo_screen_populate(struct sysinfo_screen *screen,
49 const struct system_info *sysinfo)
53 text_screen_clear(&screen->text_scr);
55 #define line(...) text_screen_append_line(&screen->text_scr, __VA_ARGS__)
57 line("Waiting for system information...");
61 line("%-12s %s", "System type:", sysinfo->type ?: "");
62 line("%-12s %s", "System id:", sysinfo->identifier ?: "");
64 if (sysinfo->n_blockdevs) {
66 line("Storage devices");
69 for (i = 0; i < sysinfo->n_blockdevs; i++) {
70 struct blockdev_info *info = sysinfo->blockdevs[i];
72 line("%s:", info->name);
73 line(" UUID: %s", info->uuid);
74 line(" mounted at: %s", info->mountpoint);
78 if (sysinfo->n_interfaces) {
80 line("Network interfaces");
83 for (i = 0; i < sysinfo->n_interfaces; i++) {
84 struct interface_info *info = sysinfo->interfaces[i];
87 if_info_mac_str(info, macbuf, sizeof(macbuf));
89 line("%s:", info->name);
90 line(" MAC: %s", macbuf);
91 line(" link: %s", info->link ? "up" : "down");
98 void sysinfo_screen_update(struct sysinfo_screen *screen,
99 const struct system_info *sysinfo)
101 sysinfo_screen_populate(screen, sysinfo);
102 text_screen_draw(&screen->text_scr);
105 struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
106 const struct system_info *sysinfo,
107 void (*on_exit)(struct cui *))
109 struct sysinfo_screen *screen;
111 screen = talloc_zero(cui, struct sysinfo_screen);
112 text_screen_init(&screen->text_scr, cui,
113 "Petitboot System Information", on_exit);
115 sysinfo_screen_update(screen, sysinfo);