diff options
| author | Agney Lopes Roth Ferraz <agney@debian.org> | 2006-05-22 19:43:53 -0300 | 
|---|---|---|
| committer | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:34 -0500 | 
| commit | 1db37ee0b1dbfebe11ff6a0eee8000392e4f3f61 (patch) | |
| tree | 02b7da09dbd8cdf8828c01f47154fc76269eb9cc /arch | |
| parent | 1a3b201e8e94d8c07b3e0a2ce1af22293a53b506 (diff) | |
| parent | 854292407779593a401a1d5ce71add51880fa84f (diff) | |
Import Debian changes 0.4-1
hardinfo (0.4-1) unstable; urgency=low
  * new upstream release
Diffstat (limited to 'arch')
113 files changed, 3288 insertions, 0 deletions
| diff --git a/arch/common/blowfish.h b/arch/common/blowfish.h new file mode 100644 index 00000000..7333d069 --- /dev/null +++ b/arch/common/blowfish.h @@ -0,0 +1,64 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include <blowfish.h> + +gchar * +benchmark_fish(void) +{ +    BLOWFISH_CTX ctx; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; +    unsigned long L, R; +    int i; + +    tmpsrc = src; + +    L = 0xBEBACAFE; +    R = 0xDEADBEEF; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Benchmarking..."); +     +    for (i = 0; i <= 50000; i++) {  +        g_timer_start(timer); + +        Blowfish_Init(&ctx, (unsigned char*)tmpsrc, srclen); +        Blowfish_Encrypt(&ctx, &L, &R); +        Blowfish_Decrypt(&ctx, &L, &R); +         +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +         +        shell_status_set_percentage(i/500); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "Blowfish"); +} diff --git a/arch/common/display.h b/arch/common/display.h new file mode 100644 index 00000000..6731e3e3 --- /dev/null +++ b/arch/common/display.h @@ -0,0 +1,137 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static void +get_glx_info(DisplayInfo *di) +{ +    gchar *output; +    if (g_spawn_command_line_sync("glxinfo", &output, NULL, NULL, NULL)) { +	gchar **output_lines, **old; + +	output_lines = g_strsplit(output, "\n", 0); +	g_free(output); + +	old = output_lines; +	while (*(++output_lines)) { +	    if (strstr(*output_lines, "OpenGL")) { +		gchar **tmp = g_strsplit(*output_lines, ":", 0); + +		tmp[1] = g_strchug(tmp[1]); + +		get_str("OpenGL vendor str", di->ogl_vendor); +		get_str("OpenGL renderer str", di->ogl_renderer); +		get_str("OpenGL version str", di->ogl_version); + +		g_strfreev(tmp); +	    } +	} + +	g_strfreev(old); + +	if (!di->ogl_vendor) +	    di->ogl_vendor = "Unknown"; +	if (!di->ogl_renderer) +	    di->ogl_renderer = "Unknown"; +	if (!di->ogl_version) +	    di->ogl_version = "Unknown"; +    } else { +	di->ogl_vendor = di->ogl_renderer = di->ogl_version = "Unknown"; +    } + +} + +static void +get_x11_info(DisplayInfo *di) +{ +    gchar *output; +     +    if (g_spawn_command_line_sync("xdpyinfo", &output, NULL, NULL, NULL)) { +	gchar **output_lines, **old; + +	output_lines = g_strsplit(output, "\n", 0); +	g_free(output); + +	old = output_lines; +	while (*(output_lines++)) { +            gchar **tmp = g_strsplit(*output_lines, ":", 0); + +            if (tmp[1] && tmp[0]) { +              tmp[1] = g_strchug(tmp[1]); + +              get_str("vendor string", di->vendor); +              get_str("X.Org version", di->version); +              get_str("XFree86 version", di->version); + +              if (g_str_has_prefix(tmp[0], "number of extensions")) { +                int n; +                 +                di->extensions = ""; +                 +                for (n = atoi(tmp[1]); n; n--) { +                  di->extensions = g_strconcat(di->extensions,  +                                               g_strstrip(*(++output_lines)), +                                               "=\n", +                                               NULL); +                } +                g_strfreev(tmp); +                 +                break; +              } +            } + +            g_strfreev(tmp); +	} + +	g_strfreev(old); +    } +     +    GdkScreen *screen = gdk_screen_get_default(); +     +    if (screen && GDK_IS_SCREEN(screen)) { +        gint n_monitors = gdk_screen_get_n_monitors(screen); +        gint i; +         +        di->monitors = ""; +        for (i = 0; i < n_monitors; i++) { +            GdkRectangle rect; +             +            gdk_screen_get_monitor_geometry(screen, i, &rect); +             +            di->monitors = g_strdup_printf("%sMonitor %d=%dx%d pixels\n", +                                           di->monitors, i, rect.width, rect.height); +        } +      } else { +          di->monitors = ""; +      } +} + +static DisplayInfo * +computer_get_display(void) +{ +    DisplayInfo *di = g_new0(DisplayInfo, 1); +     +    GdkScreen *screen = gdk_screen_get_default(); + +    di->width = gdk_screen_get_width(screen); +    di->height = gdk_screen_get_height(screen); + +    get_glx_info(di); +    get_x11_info(di); + +    return di; +} diff --git a/arch/common/fib.h b/arch/common/fib.h new file mode 100644 index 00000000..493cfd0f --- /dev/null +++ b/arch/common/fib.h @@ -0,0 +1,50 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static unsigned long long +fib(unsigned long long n) +{ +    if (n == 0) +        return 0; +    else if (n == 1 || n == 2) +        return 1; +    return fib(n - 1) + fib(n - 2); +} + +static gchar * +benchmark_fib(void) +{ +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Calculating the 42<sup>th</sup> Fibonacci number..."); +     +    g_timer_start(timer); +    fib(42);		/* the answer? :) */ +    g_timer_stop(timer); + +    elapsed = g_timer_elapsed(timer, NULL); +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "Fibonacci"); +} + diff --git a/arch/common/languages.h b/arch/common/languages.h new file mode 100644 index 00000000..3a31ef7f --- /dev/null +++ b/arch/common/languages.h @@ -0,0 +1,102 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ +void +scan_languages(OperatingSystem * os) +{ +    FILE *locale; +    gchar buf[128], *retval = ""; + +    locale = popen("locale -va", "r"); +    if (!locale) +	return; + +    gchar name[32]; +    gchar *title = NULL, +          *source = NULL, +	  *address = NULL, +	  *email = NULL, +	  *language = NULL, +	  *territory = NULL, +	  *revision = NULL, +	  *date = NULL, +	  *codeset = NULL; + +    while (fgets(buf, 128, locale)) { +	if (!strncmp(buf, "locale:", 7)) { +	    sscanf(buf, "locale: %s", name); +	    fgets(buf, 128, locale); +	} else if (strchr(buf, '|')) { +	    gchar **tmp = g_strsplit(buf, "|", 2); + +	    tmp[0] = g_strstrip(tmp[0]); + +	    if (tmp[1]) { +		tmp[1] = g_strstrip(tmp[1]); + +		get_str("title", title); +		get_str("source", source); +		get_str("address", address); +		get_str("email", email); +		get_str("language", language); +		get_str("territory", territory); +		get_str("revision", revision); +		get_str("date", date); +		get_str("codeset", codeset); +	    } + +	    g_strfreev(tmp); +	} else { +	    gchar *currlocale; + +	    retval = g_strdup_printf("%s$%s$%s=%s\n", retval, name, name, title); + +	    currlocale = g_strdup_printf("[Locale Information]\n" +					 "Name=%s (%s)\n" +					 "Source=%s\n" +					 "Address=%s\n" +					 "Email=%s\n" +					 "Language=%s\n" +					 "Territory=%s\n" +					 "Revision=%s\n" +					 "Date=%s\n" +					 "Codeset=%s\n", name, title, +					 source, address, email, language, +					 territory, revision, date, +					 codeset); + +	    g_hash_table_insert(moreinfo, g_strdup(name), currlocale); + +	    g_free(title); +	    g_free(source); +	    g_free(address); +	    g_free(email); +	    g_free(language); +	    g_free(territory); +	    g_free(revision); +	    g_free(date); +	    g_free(codeset); +	     +	    title = source = address = email = language = territory = \ +	        revision = date = codeset = NULL; +	} +    } + +    fclose(locale); + +    os->languages = retval; +} diff --git a/arch/common/md5.h b/arch/common/md5.h new file mode 100644 index 00000000..f61aef0f --- /dev/null +++ b/arch/common/md5.h @@ -0,0 +1,62 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include <md5.h> + +gchar * +benchmark_md5(void) +{ +    struct MD5Context ctx; +    guchar checksum[16]; +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; + +    tmpsrc = src; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Generating MD5 sum for 312MiB of data..."); +     +    for (i = 0; i <= 5000; i++) {  +        g_timer_start(timer); + +        MD5Init(&ctx); +        MD5Update(&ctx, (guchar*)tmpsrc, srclen); +        MD5Final(checksum, &ctx); +         +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +         +        shell_status_set_percentage(i/50); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "MD5"); +} + diff --git a/arch/common/printers.h b/arch/common/printers.h new file mode 100644 index 00000000..8632ea18 --- /dev/null +++ b/arch/common/printers.h @@ -0,0 +1,67 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +void +scan_printers(void) +{ +    GModule *cups; +    static int (*cupsGetPrinters) (char ***printers) = NULL; +    static char *(*cupsGetDefault) (void) = NULL; + +    if (printer_list) +	g_free(printer_list); + +    if (!(cupsGetPrinters && cupsGetDefault)) { +	cups = g_module_open("libcups", G_MODULE_BIND_LAZY); +	if (!cups) { +	    printer_list = g_strdup("[Printers]\n" +				    "CUPS libraries cannot be found="); +	    return; +	} + +	if (!g_module_symbol(cups, "cupsGetPrinters", (gpointer) & cupsGetPrinters) +	    || !g_module_symbol(cups, "cupsGetDefault", +				(gpointer) & cupsGetDefault)) { +	    printer_list = +		g_strdup("[Printers]\n" "No suitable CUPS library found="); +            g_module_close(cups); +	    return; +	} +    } + +    gchar **printers; +    int noprinters, i; +    const char *default_printer; + +    noprinters = cupsGetPrinters(&printers); +    default_printer = cupsGetDefault(); + +    if (noprinters > 0) { +	printer_list = g_strdup_printf("[Printers (CUPS)]\n"); +	for (i = 0; i < noprinters; i++) { +	    printer_list = g_strconcat(printer_list, printers[i], +				       !strcmp(default_printer, +					       printers[i]) ? +				       "=<i>(Default)</i>\n" : "=\n", +				       NULL); +	    g_free(printers[i]); +	} +    } else { +	printer_list = g_strdup("[Printers]\n" "No printers found"); +    } +} diff --git a/arch/common/sha1.h b/arch/common/sha1.h new file mode 100644 index 00000000..521cbcae --- /dev/null +++ b/arch/common/sha1.h @@ -0,0 +1,61 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ +#include <sha1.h> + +gchar * +benchmark_sha1(void) +{ +    SHA1_CTX ctx; +    guchar checksum[20]; +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; +     +    tmpsrc = src; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Generating SHA1 sum for 312MiB of data..."); +     +    for (i = 0; i <= 5000; i++) {  +        g_timer_start(timer); + +        SHA1Init(&ctx); +        SHA1Update(&ctx, (guchar*)tmpsrc, srclen); +        SHA1Final(checksum, &ctx); +         +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +         +        shell_status_set_percentage(i/50); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "SHA1"); +} + diff --git a/arch/common/zlib.h b/arch/common/zlib.h new file mode 100644 index 00000000..f68d60f4 --- /dev/null +++ b/arch/common/zlib.h @@ -0,0 +1,85 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar * +benchmark_zlib(void) +{ +    GModule *libz; +    static gulong (*compressBound) (glong srclen) = NULL; +    static gint (*compress) (gchar *dst, glong *dstlen, +                             const gchar *src, glong srclen) = NULL; + +    if (!(compress && compressBound)) { +	libz = g_module_open("libz", G_MODULE_BIND_LAZY); +	if (!libz) { +            libz = g_module_open("/lib/libz.so", G_MODULE_BIND_LAZY); +            if (!libz) { +                g_print("%s\n", g_module_error()); +                return g_strdup("[Error]\n" +                       "ZLib not found="); +            } +	} + +	if (!g_module_symbol(libz, "compress", (gpointer) & compress) +	    || !g_module_symbol(libz, "compressBound", (gpointer) & compressBound)) { +	     +            g_module_close(libz); +	    return g_strdup("[Error]\n" +	           "Invalid Z-Lib found="); +	} +    } + +    shell_view_set_enabled(FALSE); + +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_status_update("Compressing 64MB with default options..."); +     +    for (i = 0; i <= 1000; i++) {  +        g_timer_start(timer); +         +        gchar *dst; +        glong dstlen = compressBound(srclen); +         +        dst = g_new0(gchar, dstlen); +        compress(dst, &dstlen, src, srclen); + +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +        g_free(dst); +         +        shell_status_set_percentage(i/10); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "ZLib"); +} + diff --git a/arch/linux/common/alsa.h b/arch/linux/common/alsa.h new file mode 100644 index 00000000..0c0744ae --- /dev/null +++ b/arch/linux/common/alsa.h @@ -0,0 +1,69 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +gchar * +computer_get_alsacards(Computer * computer) +{ +    GSList *p; +    gchar *tmp = ""; +    gint n = 0; + +    if (computer->alsa) { +	for (p = computer->alsa->cards; p; p = p->next) { +	    AlsaCard *ac = (AlsaCard *) p->data; + +	    tmp = +		g_strdup_printf("Audio Adapter#%d=%s\n%s", ++n, +				ac->friendly_name, tmp); +	} +    } + +    return tmp; +} + +static AlsaInfo * +computer_get_alsainfo(void) +{ +    AlsaInfo *ai; +    AlsaCard *ac; +    FILE *cards; +    gchar buffer[128]; + +    cards = fopen("/proc/asound/cards", "r"); +    if (!cards) +	return NULL; + +    ai = g_new0(AlsaInfo, 1); + +    while (fgets(buffer, 128, cards)) { +	gchar **tmp; + +	ac = g_new0(AlsaCard, 1); + +	tmp = g_strsplit(buffer, ":", 0); + +	ac->friendly_name = g_strdup(tmp[1]); +	ai->cards = g_slist_append(ai->cards, ac); + +	g_strfreev(tmp); +	fgets(buffer, 128, cards);	/* skip next line */ +    } +    fclose(cards); + +    return ai; +} diff --git a/arch/linux/common/filesystem.h b/arch/linux/common/filesystem.h new file mode 100644 index 00000000..37e5a730 --- /dev/null +++ b/arch/linux/common/filesystem.h @@ -0,0 +1,103 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + * + * Some code from xfce4-mount-plugin, version 0.4.3 + *  Copyright (C) 2005 Jean-Baptiste jb_dul@yahoo.com  + *  Distributed under the terms of GNU GPL 2.  + */ +#include <sys/vfs.h> +#define KB 1024 +#define MB 1048576 +#define GB 1073741824 + +static gchar *fs_list = NULL; + +static gchar * +fs_human_readable(gfloat size) +{ +    if (size < KB) +	return g_strdup_printf("%.1f B", size); +    if (size < MB) +	return g_strdup_printf("%.1f KiB", size / KB); +    if (size < GB) +	return g_strdup_printf("%.1f MiB", size / MB); + +    return g_strdup_printf("%.1f GiB", size / GB); +} + +static void +scan_filesystems(void) +{ +    FILE *mtab; +    gchar buf[128]; +    struct statfs sfs; + +    g_free(fs_list); +    fs_list = g_strdup(""); + +    mtab = fopen("/etc/mtab", "r"); +    if (!mtab) +	return; + +    while (fgets(buf, 128, mtab)) { +	gfloat size, used, avail; +	gchar **tmp; + +	tmp = g_strsplit(buf, " ", 0); +	statfs(tmp[1], &sfs); + +	size = (float) sfs.f_bsize * (float) sfs.f_blocks; +	avail = (float) sfs.f_bsize * (float) sfs.f_bavail; +	used = size - avail; + +	gchar *strsize = fs_human_readable(size), +	    *stravail = fs_human_readable(avail), +	    *strused = fs_human_readable(used); + +	gchar *strhash; +	if ((strhash = g_hash_table_lookup(moreinfo, tmp[0]))) { +	    g_hash_table_remove(moreinfo, tmp[0]); +	    g_free(strhash); +	} + +	strhash = g_strdup_printf("[%s]\n" +				  "Filesystem=%s\n" +				  "Mounted As=%s\n" +				  "Mount Point=%s\n" +				  "Size=%s\n" +				  "Used=%s\n" +				  "Available=%s\n", +				  tmp[0], +				  tmp[2], +				  strstr(tmp[3], +					 "rw") ? "Read-Write" : +				  "Read-Only", tmp[1], strsize, strused, +				  stravail); +	g_hash_table_insert(moreinfo, g_strdup(tmp[0]), strhash); + +	fs_list = g_strdup_printf("%s$%s$%s=%s total, %s free\n", +				  fs_list, +				  tmp[0], tmp[0], strsize, stravail); + +	g_free(strsize); +	g_free(stravail); +	g_free(strused); +	g_strfreev(tmp); +    } + +    fclose(mtab); +} diff --git a/arch/linux/common/inputdevices.h b/arch/linux/common/inputdevices.h new file mode 100644 index 00000000..c32015a2 --- /dev/null +++ b/arch/linux/common/inputdevices.h @@ -0,0 +1,117 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar *input_icons = NULL; + +static gboolean +remove_input_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "INP", 3)) { +	g_free((gchar *) key); +	g_free((GtkTreeIter *) value); +	return TRUE; +    } + +    return FALSE; +} + +static struct { +    char *name; +    char *icon; +} input_devices[] = { +    { "Keyboard", "keyboard.png" }, +    { "Joystick", "joystick.png" }, +    { "Mouse",    "mouse.png"    }, +    { "Unknown",  "module.png"   }, +}; + +void +scan_inputdevices(void) +{ +    FILE *dev; +    gchar buffer[128]; +    gchar *tmp, *name = NULL, *phys = NULL; +    gint bus, vendor, product, version; +    int d = 0, n = 0; + +    dev = fopen("/proc/bus/input/devices", "r"); +    if (!dev) +	return; + +    if (input_list) { +	g_hash_table_foreach_remove(devices, remove_input_devices, NULL); +	g_free(input_list); +	g_free(input_icons); +    } +    input_list = g_strdup(""); +    input_icons = g_strdup(""); + +    while (fgets(buffer, 128, dev)) { +	tmp = buffer; + +	switch (*tmp) { +	case 'N': +	    name = g_strdup(tmp + strlen("N: Name=")); +	    remove_quotes(name); +	    break; +	case 'P': +	    phys = g_strdup(tmp + strlen("P: Phys=")); +	    break; +	case 'I': +	    sscanf(tmp, "I: Bus=%x Vendor=%x Product=%x Version=%x", +		   &bus, &vendor, &product, &version); +	    break; +	case 'H': +	    if (strstr(tmp, "kbd")) +		d = 0;		//INPUT_KEYBOARD; +	    else if (strstr(tmp, "js")) +		d = 1;		//INPUT_JOYSTICK; +	    else if (strstr(tmp, "mouse")) +		d = 2;		//INPUT_MOUSE; +	    else +		d = 3;		//INPUT_UNKNOWN; +	    break; +	case '\n': +	    tmp = g_strdup_printf("INP%d", ++n); +	    input_list = g_strdup_printf("%s$%s$%s=\n", +					 input_list, +					 tmp, name); +	    input_icons = g_strdup_printf("%sIcon$%s$%s=%s\n", +				 	  input_icons, +					  tmp, name, +					  input_devices[d].icon); +	    gchar *strhash = g_strdup_printf("[Device Information]\n" +					     "Name=%s\n" +					     "Type=%s\n" +					     "Bus=0x%x\n" +					     "Vendor=0x%x\n" +					     "Product=0x%x\n" +					     "Version=0x%x\n" +					     "Connected to=%s\n", +					     name, input_devices[d].name, +					     bus, vendor, product, +					     version, phys); +	    g_hash_table_insert(devices, tmp, strhash); + +	    g_free(phys); +	    g_free(name); +	} +    } + +    fclose(dev); +} diff --git a/arch/linux/common/loadavg.h b/arch/linux/common/loadavg.h new file mode 100644 index 00000000..28132b5f --- /dev/null +++ b/arch/linux/common/loadavg.h @@ -0,0 +1,47 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static LoadInfo * +computer_get_loadinfo(void) +{ +    LoadInfo *li = g_new0(LoadInfo, 1); +    FILE *procloadavg; + +    procloadavg = fopen("/proc/loadavg", "r"); +    fscanf(procloadavg, "%f %f %f", &(li->load1), &(li->load5), +	   &(li->load15)); +    fclose(procloadavg); + +    return li; +} + +static gchar * +computer_get_formatted_loadavg() +{ +    LoadInfo *li; +    gchar *tmp; + +    li = computer_get_loadinfo(); + +    tmp = +	g_strdup_printf("%.2f, %.2f, %.2f", li->load1, li->load5, +			li->load15); + +    g_free(li); +    return tmp; +} diff --git a/arch/linux/common/memory.h b/arch/linux/common/memory.h new file mode 100644 index 00000000..def4cc1d --- /dev/null +++ b/arch/linux/common/memory.h @@ -0,0 +1,56 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static MemoryInfo * +computer_get_memory(void) +{ +    MemoryInfo *mi; +    FILE *procmem; +    gchar buffer[128]; + +    procmem = fopen("/proc/meminfo", "r"); +    if (!procmem) +	return NULL; +    mi = g_new0(MemoryInfo, 1); + +    while (fgets(buffer, 128, procmem)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	tmp[0] = g_strstrip(tmp[0]); +	tmp[1] = g_strstrip(tmp[1]); + +	get_int("MemTotal", mi->total); +	get_int("MemFree", mi->free); +	get_int("Cached", mi->cached); + +	g_strfreev(tmp); +    } +    fclose(procmem); +     +    mi->used = mi->total - mi->free; + +    mi->total  /= 1000; +    mi->cached /= 1000; +    mi->used   /= 1000; +    mi->free   /= 1000; + +    mi->used -= mi->cached; +    mi->ratio = 1 - (gdouble) mi->used / mi->total; + +    return mi; +} diff --git a/arch/linux/common/modules.h b/arch/linux/common/modules.h new file mode 100644 index 00000000..69f7ebd6 --- /dev/null +++ b/arch/linux/common/modules.h @@ -0,0 +1,129 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +void +scan_modules(void) +{ +    FILE *lsmod; +    gchar buffer[1024]; + +    lsmod = popen("/sbin/lsmod", "r"); +    if (!lsmod) +	return; + +    fgets(buffer, 1024, lsmod);	/* Discards the first line */ + +    while (fgets(buffer, 1024, lsmod)) { +	gchar *buf, *strmodule, *hashkey; +	gchar *author = NULL, +	    *description = NULL, +	    *license = NULL, +	    *deps = NULL, *vermagic = NULL, *filename = NULL, modname[64]; +	FILE *modi; +	glong memory; + +	shell_status_pulse(); + +	buf = buffer; + +	sscanf(buf, "%s %ld", modname, &memory); + +	hashkey = g_strdup_printf("MOD%s", modname); +	buf = g_strdup_printf("/sbin/modinfo %s", modname); + +	modi = popen(buf, "r"); +	while (fgets(buffer, 1024, modi)) { +	    gchar **tmp = g_strsplit(buffer, ":", 2); + +	    GET_STR("author", author); +	    GET_STR("description", description); +	    GET_STR("license", license); +	    GET_STR("depends", deps); +	    GET_STR("vermagic", vermagic); +	    GET_STR("filename", filename); + +	    g_strfreev(tmp); +	} +	pclose(modi); +	g_free(buf); + +	/* old modutils includes quotes in some strings; strip them */ +	/*remove_quotes(modname); +	   remove_quotes(description); +	   remove_quotes(vermagic); +	   remove_quotes(author); +	   remove_quotes(license); */ + +	/* old modutils displays <none> when there's no value for a +	   given field; this is not desirable in the module name  +	   display, so change it to an empty string */ +	if (description && !strcmp(description, "<none>")) { +	    g_free(description); +	    description = g_strdup(""); +	} + +	/* append this module to the list of modules */ +	module_list = g_strdup_printf("%s$%s$%s=%s\n", +				      module_list, +				      hashkey, +				      modname, +				      description ? description : ""); + +#define NONE_IF_NULL(var) (var) ? (var) : "N/A" + +	/* create the module information string */ +	strmodule = g_strdup_printf("[Module Information]\n" +				    "Path=%s\n" +				    "Used Memory=%.2fKiB\n" +				    "[Description]\n" +				    "Name=%s\n" +				    "Description=%s\n" +				    "Version Magic=%s\n" +				    "[Copyright]\n" +				    "Author=%s\n" +				    "License=%s\n", +				    NONE_IF_NULL(filename), +				    memory / 1024.0, +				    NONE_IF_NULL(modname), +				    NONE_IF_NULL(description), +				    NONE_IF_NULL(vermagic), +				    NONE_IF_NULL(author), +				    NONE_IF_NULL(license)); + +	/* if there are dependencies, append them to that string */ +	if (deps && strlen(deps)) { +	    gchar **tmp = g_strsplit(deps, ",", 0); + +	    strmodule = g_strconcat(strmodule, +                                    "\n[Dependencies]\n", +                                    g_strjoinv("=\n", tmp), +                                    "=\n", NULL); +	    g_strfreev(tmp); +	    g_free(deps); +	} + +	g_hash_table_insert(devices, hashkey, strmodule); + +	g_free(license); +	g_free(description); +	g_free(author); +	g_free(vermagic); +	g_free(filename); +    } +    pclose(lsmod); +} diff --git a/arch/linux/common/net.h b/arch/linux/common/net.h new file mode 100644 index 00000000..87e7e59b --- /dev/null +++ b/arch/linux/common/net.h @@ -0,0 +1,203 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar *network_interfaces = NULL; + +#include <sys/ioctl.h> +#include <net/if.h> +#include <netinet/in.h> +#include <linux/sockios.h> +#include <sys/socket.h> + +typedef struct _NetInfo NetInfo; +struct _NetInfo { +    char                name[16];  +    int                 mtu; +    unsigned char       mac[8]; +}; + + +void get_net_info(char *if_name, NetInfo *netinfo) +{ +    struct ifreq ifr; +    int fd; + +    fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + +    strcpy(ifr.ifr_name, if_name); +    strcpy(netinfo->name, if_name); + +    if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) { +        netinfo->mtu = 0; +    } else { +        netinfo->mtu = ifr.ifr_mtu; +    } +     +    strcpy(ifr.ifr_name, if_name); +    if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { +        memset(netinfo->mac, 0, 8); +    } else { +        memcpy(netinfo->mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 8); +    } + +    shutdown(fd, 0); +} + +static struct { +    char *type; +    char *label; +} netdev2type[] = { +    { "eth",	"Ethernet" }, +    { "lo",	"Loopback" }, +    { "ppp",	"Point-to-Point" }, +    { "ath",	"Wireless" }, +    { "wlan",	"Wireless" }, +    { "tun",    "Virtual Point-to-Point (TUN)" }, +    { "tap",    "Ethernet (TAP)" }, +    { "plip",   "Parallel Line Internet Protocol" }, +    { "irlan",  "Infrared" }, +    { "slip",   "Serial Line Internet Protocol" }, +    { "isdn",	"Integrated Services Digital Network" }, +    { "sit",	"IPv6-over-IPv4 Tunnel" }, +    { "vmnet8", "VMWare Virtual Network Interface (NAT)" }, +    { "vmnet",  "VMWare Virtual Network Interface" }, +    { NULL,	"Unknown" }, +}; + +static const gchar * +net_get_iface_type(gchar *name) +{ +    int i; +     +    for (i = 0; netdev2type[i].type; i++) { +        if (g_str_has_prefix(name, netdev2type[i].type)) +            break; +    } +     +    return netdev2type[i].label; +} + +static gboolean +remove_net_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "NET", 4)) { +	g_free((gchar *) key); +	g_free((GtkTreeIter *) value); +	return TRUE; +    } +    return FALSE; +} + +static void +scan_net_interfaces_24(void) +{ +    FILE *proc_net; +    NetInfo ni; +    gchar buffer[256]; +    gchar *devid, *detailed; +    gulong recv_bytes; +    gulong recv_errors; +    gulong recv_packets; +     +    gulong trans_bytes; +    gulong trans_errors; +    gulong trans_packets; +     +    if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) { +        if (network_interfaces) { +            g_free(network_interfaces); +            network_interfaces = g_strdup("[Network Interfaces]\n" +                                          "None found=\n"); +        } + +	return; +    } + +    if (network_interfaces) { +        g_free(network_interfaces); +    } +     +    network_interfaces = g_strdup("[Network Interfaces]\n"); + +    proc_net = fopen("/proc/net/dev", "r"); +    while (fgets(buffer, 256, proc_net)) { +	if (strchr(buffer, ':')) { +	    gint trash; +	    gchar ifacename[16]; +	    gchar *buf = buffer; +	    gint i; + +	    buf = g_strstrip(buf); + +	    memset(ifacename, 0, 16); + +	    for (i = 0; buffer[i] != ':' && i < 16; i++) { +		ifacename[i] = buffer[i]; +	    } + +	    buf = strchr(buf, ':') + 1; + +	    /* iface: bytes packets errs drop fifo frame compressed multicast */ +	    sscanf(buf, "%ld %ld %ld %d %d %d %d %d %ld %ld %ld", +		   &recv_bytes, &recv_packets, +		   &recv_errors, &trash, &trash, &trash, &trash, +		   &trash, &trans_bytes, &trans_packets, +		   &trans_errors); + +            gfloat recv_mb = recv_bytes / 1048576.0; +            gfloat trans_mb = trans_bytes / 1048576.0; +             +            devid = g_strdup_printf("NET%s", ifacename); +	    network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB\n", +                                                  network_interfaces, +                                                  devid, +                                                  ifacename, +                                                  trans_mb, +                                                  recv_mb); +             +            get_net_info(ifacename, &ni); +            detailed = g_strdup_printf("[Network Adapter Properties]\n" +                                        "Interface Type=%s\n" +                                        "Hardware Address=%02x:%02x:%02x:%02x:%02x:%02x\n" +                                        "MTU=%d\n" +                                        "Bytes Sent=%ld (%.2fMiB)\n" +                                        "Bytes Received=%ld (%.2fMiB)\n", +                                        net_get_iface_type(ifacename), +                                        ni.mac[0], ni.mac[1], +                                        ni.mac[2], ni.mac[3], +                                        ni.mac[4], ni.mac[5], +                                        ni.mtu, +                                        recv_bytes, recv_mb, +                                        trans_bytes, trans_mb); +            g_hash_table_insert(moreinfo, devid, detailed); +	} +    } +    fclose(proc_net); +} + +static void +scan_net_interfaces(void) +{ +    /* FIXME: See if we're running Linux 2.6 and if /sys is mounted, then use +              that instead of /proc/net/dev */ + +    /* remove old devices from global device table */ +    g_hash_table_foreach_remove(moreinfo, remove_net_devices, NULL); + +    scan_net_interfaces_24(); +} diff --git a/arch/linux/common/os.h b/arch/linux/common/os.h new file mode 100644 index 00000000..0f7b59e3 --- /dev/null +++ b/arch/linux/common/os.h @@ -0,0 +1,203 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar * +get_libc_version(void) +{ +    FILE *libc; +    gchar buf[256], *tmp, *p; +     +    libc = popen("/lib/libc.so.6", "r"); +    if (!libc) goto err; +     +    fgets(buf, 256, libc); +    if (pclose(libc)) goto err; +     +    tmp = strstr(buf, "version "); +    if (!tmp) goto err; +     +    p = strchr(tmp, ','); +    if (p) *p = '\0'; +    else goto err; +     +    return g_strdup_printf("GNU C Library version %s (%sstable)", +                           strchr(tmp, ' ') + 1, +                           strstr(buf, " stable ") ? "" : "un"); +  err: +    return g_strdup("Unknown"); +} + +static gchar * +get_os_compiled_date(void) +{ +    FILE *procversion; +    gchar buf[512]; + +    procversion = fopen("/proc/sys/kernel/version", "r"); +    if (!procversion) +	return g_strdup("Unknown"); + +    fgets(buf, 512, procversion); +    fclose(procversion); + +    return g_strdup(buf); +} + + +#include <gdk/gdkx.h> + +void +detect_desktop_environment(OperatingSystem * os) +{ +    const gchar *tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); +    FILE *version; +    int maj, min; + +    if (tmp) { +	/* FIXME: this might not be true, as the gnome-panel in path +	   may not be the one that's running. +	   see where the user's running panel is and run *that* to +	   obtain the version. */ +	version = popen("gnome-panel --version", "r"); +	if (version) { +	    fscanf(version, "Gnome gnome-panel %d.%d", &maj, &min); +	    if (pclose(version)) +	        goto unknown; +	} else { +	    goto unknown; +	} + +	os->desktop = +	    g_strdup_printf("GNOME %d.%d (session name: %s)", maj, min, +			    tmp); +    } else if (g_getenv("KDE_FULL_SESSION")) { +	version = popen("kcontrol --version", "r"); +	if (version) { +	    char buf[32]; + +	    fgets(buf, 32, version); + +	    fscanf(version, "KDE: %d.%d", &maj, &min); +	    if (pclose(version)) +	        goto unknown; +	} else { +	    goto unknown; +	} + +	os->desktop = g_strdup_printf("KDE %d.%d", maj, min); +    } else { +      unknown: +	if (!g_getenv("DISPLAY")) { +	    os->desktop = g_strdup("Terminal"); +	} else { +            const gchar *windowman; +            GdkScreen *screen = gdk_screen_get_default(); + +            windowman = gdk_x11_screen_get_window_manager_name(screen); +             +            if (g_str_equal(windowman, "Xfwm4")) { +                /* FIXME: check if xprop -root | grep XFCE_DESKTOP_WINDOW +                   is defined */ +                os->desktop = g_strdup("XFCE 4"); +            } else { +  	        os->desktop = g_strdup_printf("Unknown (Window Manager: %s)", +  	                                      windowman); +            } +	} +    } +} + +static OperatingSystem * +computer_get_os(void) +{ +    struct utsname utsbuf; +    OperatingSystem *os; +    int i; + +    os = g_new0(OperatingSystem, 1); + +    os->compiled_date = get_os_compiled_date(); + +    /* Attempt to get the Distribution name; try using /etc/lsb-release first, +       then doing the legacy method (checking for /etc/$DISTRO-release files) */ +    if (g_file_test("/etc/lsb-release", G_FILE_TEST_EXISTS)) { +	FILE *release; +	gchar buffer[128]; + +	release = popen("lsb_release -d", "r"); +	fgets(buffer, 128, release); +	pclose(release); + +	os->distro = buffer; +	os->distro = g_strdup(os->distro + strlen("Description:\t")); +    } + +    for (i = 0;; i++) { +	if (distro_db[i].file == NULL) { +	    os->distrocode = g_strdup("unk"); +	    os->distro = g_strdup("Unknown distribution"); +	    break; +	} + +	if (g_file_test(distro_db[i].file, G_FILE_TEST_EXISTS)) { + + +	    FILE *distro_ver; +	    char buf[128]; + +	    distro_ver = fopen(distro_db[i].file, "r"); +	    fgets(buf, 128, distro_ver); +	    fclose(distro_ver); + +	    buf[strlen(buf) - 1] = 0; + +	    if (!os->distro) { +		/* +		 * HACK: Some Debian systems doesn't include +		 * the distribuition name in /etc/debian_release, +		 * so add them here.  +		 */ +		if (!strncmp(distro_db[i].codename, "deb", 3) && +		    ((buf[0] >= '0' && buf[0] <= '9') || buf[0] != 'D')) { +		    os->distro = g_strdup_printf +			("Debian GNU/Linux %s", buf); +		} else { +		    os->distro = g_strdup(buf); +		} +	    } +	    os->distrocode = g_strdup(distro_db[i].codename); + +	    break; +	} +    } + +    /* Kernel and hostname info */ +    uname(&utsbuf); +    os->kernel = g_strdup_printf("%s %s (%s)", utsbuf.sysname, +				 utsbuf.release, utsbuf.machine); +    os->hostname = g_strdup(utsbuf.nodename); +    os->language = g_strdup(g_getenv("LC_MESSAGES")); +    os->homedir = g_strdup(g_get_home_dir()); +    os->username = g_strdup_printf("%s (%s)", +				   g_get_user_name(), g_get_real_name()); +    os->libc = get_libc_version(); +    scan_languages(os); +    detect_desktop_environment(os); + +    return os; +} diff --git a/arch/linux/common/pci.h b/arch/linux/common/pci.h new file mode 100644 index 00000000..f8c9d319 --- /dev/null +++ b/arch/linux/common/pci.h @@ -0,0 +1,190 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +void +scan_pci(void) +{ +    FILE *lspci; +    gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; +    gchar *category = NULL, *name = NULL; +    gint n = 0; + +    //if (g_file_test("/usr/bin/gksudo", G_FILE_TEST_EXISTS)) { +    //  lspci = popen("gksudo '/bin/lspci -v'", "r"); +    //} else { +    lspci = popen(LSPCI, "r"); +    //} + +    if (!lspci) { +	return; +    } + +    gchar *icon; +     +    int x = 0;			/* unique Memory, Capability and I/O port */ +    while (fgets(buffer, 256, lspci)) { +	buf = g_strstrip(buffer); + +	if (!strncmp(buf, "Flags", 5)) { +	    gint irq = 0, freq = 0, latency = 0, i; +	    gchar **list; +	    gboolean bus_master; + +	    buf += 7; + +	    bus_master = FALSE; + +	    list = g_strsplit(buf, ", ", 10); +	    for (i = 0; i <= 10; i++) { +		if (!list[i]) +		    break; + +		if (!strncmp(list[i], "IRQ", 3)) +		    sscanf(list[i], "IRQ %d", &irq); +		else if (strstr(list[i], "Mhz")) +		    sscanf(list[i], "%dMhz", &freq); +		else if (!strncmp(list[i], "bus master", 10)) +		    bus_master = TRUE; +		else if (!strncmp(list[i], "latency", 7)) +		    sscanf(list[i], "latency %d", &latency); +	    } +	    g_strfreev(list); + +	    if (irq) +		strdevice = g_strdup_printf("%sIRQ=%d\n", strdevice, irq); +	    if (freq) +		strdevice = +		    g_strdup_printf("%sFrequency=%dMHz\n", strdevice, +				    freq); +	    if (latency) +		strdevice = +		    g_strdup_printf("%sLatency=%d\n", strdevice, latency); + +	    strdevice = +		g_strdup_printf("%sBus Master=%s\n", strdevice, +				bus_master ? "Yes" : "No"); +	} else if (!strncmp(buf, "Subsystem", 9)) { +	    WALK_UNTIL(' '); +	    buf++; +	    strdevice = +		g_strdup_printf("%sOEM Vendor=%s\n", strdevice, buf); +	} else if (!strncmp(buf, "Capabilities", 12) +		   && !strstr(buf, "only to root") &&  +		      !strstr(buf, "access denied")) { +	    WALK_UNTIL(' '); +	    WALK_UNTIL(']'); +	    buf++; +	    strdevice = +		g_strdup_printf("%sCapability#%d=%s\n", strdevice, ++x, +				buf); +	} else if (!strncmp(buf, "Memory at", 9) && strstr(buf, "[size=")) { +	    gint mem; +	    gchar unit; +	    gboolean prefetch; +	    gboolean _32bit; + +	    prefetch = strstr(buf, "non-prefetchable") ? FALSE : TRUE; +	    _32bit = strstr(buf, "32-bit") ? TRUE : FALSE; + +	    WALK_UNTIL('['); +	    sscanf(buf, "[size=%d%c", &mem, &unit); + +	    strdevice = g_strdup_printf("%sMemory#%d=%d%cB (%s%s)\n", +					strdevice, ++x, +					mem, +					(unit == ']') ? ' ' : unit, +					_32bit ? "32-bit, " : "", +					prefetch ? "prefetchable" : +					"non-prefetchable"); + +	} else if (!strncmp(buf, "I/O", 3)) { +	    guint io_addr, io_size; + +	    sscanf(buf, "I/O ports at %x [size=%d]", &io_addr, &io_size); + +	    strdevice = +		g_strdup_printf("%sI/O ports at#%d=0x%x - 0x%x\n", +				strdevice, ++x, io_addr, +				io_addr + io_size); +	} else if ((buf[0] >= '0' && buf[0] <= '9') && (buf[4] == ':' || buf[2] == ':')) { +	    gint bus, device, function, domain; +	    gpointer start, end; + +	    if (strdevice != NULL && strhash != NULL) { +		g_hash_table_insert(devices, strhash, strdevice); +                g_free(category); +                g_free(name); +	    } + +	    if (buf[4] == ':') { +		sscanf(buf, "%x:%x:%x.%d", &domain, &bus, &device, &function); +	    } else { +	    	/* lspci without domain field */ +	    	sscanf(buf, "%x:%x.%x", &bus, &device, &function); +	    	domain = 0; +	    } + +	    WALK_UNTIL(' '); + +	    start = buf; + +	    WALK_UNTIL(':'); +	    end = buf + 1; +	    *buf = 0; + +	    buf = start + 1; +	    category = g_strdup(buf); + +	    buf = end; +	    start = buf; +	    WALK_UNTIL('('); +	    *buf = 0; +	    buf = start + 1; + +            if (strstr(category, "RAM memory")) icon = "mem"; +            else if (strstr(category, "Multimedia")) icon = "media"; +            else if (strstr(category, "USB")) icon = "usb"; +            else icon = "pci"; +             +	    name = g_strdup(buf); + +	    strhash = g_strdup_printf("PCI%d", n); +	    strdevice = g_strdup_printf("[Device Information]\n" +					"Name=%s\n" +					"Class=%s\n" +					"Domain=%d\n" +					"Bus, device, function=%d, %d, %d\n", +					name, category, domain, bus, +					device, function); +	    pci_list = g_strdup_printf("%s$PCI%d$%s=%s\n", pci_list, n, category, +				name); + +	    n++; +	} +    } +     +    if (pclose(lspci)) { +        /* error (no pci, perhaps?) */ +        pci_list = g_strconcat(pci_list, "No PCI devices found=\n", NULL); +    } else if (strhash) { +	/* insert the last device */ +        g_hash_table_insert(devices, strhash, strdevice); +        g_free(category); +        g_free(name); +    } +} diff --git a/arch/linux/common/samba.h b/arch/linux/common/samba.h new file mode 100644 index 00000000..538659a6 --- /dev/null +++ b/arch/linux/common/samba.h @@ -0,0 +1,80 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar *shares_list = NULL; +void +scan_shared_directories(void) +{ +    GKeyFile *keyfile; +    GError *error = NULL; +    gchar **groups; +    gchar *smbconf; +    gsize length; + +    if (shares_list) { +        g_free(shares_list); +    } +     +    keyfile = g_key_file_new(); +     +    if (!g_file_get_contents("/etc/samba/smb.conf", &smbconf, &length, &error)) { +        shares_list = g_strdup("Cannot open /etc/samba/smb.conf=\n"); +        g_error_free(error); +        goto cleanup; +    } +     +    gchar *_smbconf = smbconf; +    for (; *_smbconf; _smbconf++) +        if (*_smbconf == ';') *_smbconf = '\0'; +     +    if (!g_key_file_load_from_data(keyfile, smbconf, length, 0, &error)) { +        shares_list = g_strdup("Cannot parse smb.conf=\n"); +        g_error_free(error); +        goto cleanup; +    } + +    shares_list = g_strdup(""); + +    groups = g_key_file_get_groups(keyfile, NULL); +    gchar **_groups = groups; +    while (*groups) { +        if (g_key_file_has_key(keyfile, *groups, "path", NULL) && +            g_key_file_has_key(keyfile, *groups, "available", NULL)) { +             +            gchar *available = g_key_file_get_string(keyfile, *groups, "available", NULL); +         +            if (g_str_equal(available, "yes")) { +                gchar *path = g_key_file_get_string(keyfile, *groups, "path", NULL); +                shares_list = g_strconcat(shares_list, *groups, "=", +                                          path, "\n", NULL); +                g_free(path); +            } +             +            g_free(available); +        } +         +        *groups++; +    } +     +    g_strfreev(_groups); +   +  cleanup: +    g_key_file_free(keyfile); +    g_free(smbconf); +} + diff --git a/arch/linux/common/sensors.h b/arch/linux/common/sensors.h new file mode 100644 index 00000000..ef834de2 --- /dev/null +++ b/arch/linux/common/sensors.h @@ -0,0 +1,237 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar *sensors = NULL; +static GHashTable *sensor_labels = NULL; +static GHashTable *sensor_compute = NULL; + +static void +read_sensor_labels(gchar *driver) +{ +    FILE *conf; +    gchar buf[256], *line, *p; +    gboolean lock = FALSE; +    gint i; +     +    sensor_labels = g_hash_table_new_full(g_str_hash, g_str_equal, +                                          g_free, g_free); +    sensor_compute = g_hash_table_new(g_str_hash, g_str_equal); +     +    conf = fopen("/etc/sensors.conf", "r"); +    if (!conf) +        return; +         +    while (fgets(buf, 256, conf)) { +        line = buf; +         +        remove_linefeed(line); +        strend(line, '#'); +         +        if (*line == '\0') { +            continue; +        } else if (lock && strstr(line, "label")) {	/* label lines */ +            gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0); +            gchar *name = NULL, *value = NULL; +             +            for (i = 0; names[i]; i++) { +                if (names[i][0] == '\0') +                    continue; +                 +                if (!name) name = g_strdup(names[i]); +                else if (!value) value = g_strdup(names[i]); +                else value = g_strconcat(value, " ", names[i], NULL);             +            } +             +            remove_quotes(value); +            g_hash_table_insert(sensor_labels, name, value); +             +            g_strfreev(names);             +        } else if (lock && strstr(line, "ignore")) {	/* ignore lines */ +            p = strstr(line, "ignore") + 6; +            if (!strchr(p, ' ')) +                continue; +             +            while (*p == ' ') p++; +            g_hash_table_insert(sensor_labels, g_strdup(p), "ignore"); +        } else if (lock && strstr(line, "compute")) {	/* compute lines */ +            gchar **formulas = g_strsplit(strstr(line, "compute") + 7, " ", 0); +            gchar *name = NULL, *formula = NULL; +             +            for (i = 0; formulas[i]; i++) { +                if (formulas[i][0] == '\0') +                    continue; +                if (formulas[i][0] == ',') +                    break; +                 +                if (!name) name = g_strdup(formulas[i]); +                else if (!formula) formula = g_strdup(formulas[i]); +                else formula = g_strconcat(formula, formulas[i], NULL);             +            } +             +            g_strfreev(formulas); +            g_hash_table_insert(sensor_compute, name, math_string_to_postfix(formula)); +        } else if (g_str_has_prefix(line, "chip")) {	/* chip lines (delimiter) */ +            if (lock == FALSE) { +                gchar **chips = g_strsplit(line, " ", 0); +                 +                for (i = 1; chips[i]; i++) { +                    strend(chips[i], '*'); +                     +                    if (g_str_has_prefix(driver, chips[i] + 1)) { +                        lock = TRUE; +                        break; +                    } +                } +                 +                g_strfreev(chips); +            } else { +                break; +            } +        } +    } +     +    fclose(conf); +} + +static gchar * +get_sensor_label(gchar *sensor) +{ +    gchar *ret; +     +    ret = g_hash_table_lookup(sensor_labels, sensor); +    if (!ret) ret = g_strdup(sensor); +    else      ret = g_strdup(ret); + +    return ret; +} + +static float +adjust_sensor(gchar *name, float value) +{ +    GSList *postfix; +     +    postfix = g_hash_table_lookup(sensor_compute, name); +    if (!postfix) return value; +     +    return math_postfix_eval(postfix, value); +} + +static void +read_sensors(void) +{ +    gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; +    int hwmon, count; +     +    if (sensors) +        g_free(sensors); +     +    hwmon = 0; +    sensors = g_strdup(""); +     +    path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon); +    while (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { +        tmp = g_strdup_printf("%sdriver", path_hwmon); +        driver = g_file_read_link(tmp, NULL); +        g_free(tmp); + +        tmp = g_path_get_basename(driver); +        g_free(driver); +        driver = tmp; +         +        if (!sensor_labels) { +            read_sensor_labels(driver); +        } + +        sensors = g_strdup_printf("%s[Driver Info]\n" +                                  "Name=%s\n", sensors, driver); +     +        sensors = g_strconcat(sensors, "[Cooling Fans]\n", NULL); +        for (count = 1; ; count++) { +            path_sensor = g_strdup_printf("%sfan%d_input", path_hwmon, count); +            if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { +                g_free(path_sensor); +                break; +            } +             +            mon = g_strdup_printf("fan%d", count); +            name = get_sensor_label(mon); +            if (!g_str_equal(name, "ignore")) { +                sensors = g_strdup_printf("%s%s=%.0fRPM\n", +                                          sensors, name, +                                          adjust_sensor(mon, atof(tmp))); +            } +             +            g_free(name); +            g_free(mon); +            g_free(tmp); +            g_free(path_sensor); +        } + +        sensors = g_strconcat(sensors, "[Temperatures]\n", NULL); +        for (count = 1; ; count++) { +            path_sensor = g_strdup_printf("%stemp%d_input", path_hwmon, count); +            if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { +                g_free(path_sensor); +                break; +            } + +            mon = g_strdup_printf("temp%d", count); +            name = get_sensor_label(mon); +            if (!g_str_equal(name, "ignore")) { +                sensors = g_strdup_printf("%s%s=%.2f\302\260C\n", +                                          sensors, name, +                                          adjust_sensor(mon, atof(tmp) / 1000.0)); +            } +             +            g_free(tmp); +            g_free(name); +            g_free(path_sensor); +            g_free(mon); +        } + +        sensors = g_strconcat(sensors, "[Voltage Values]\n", NULL); +        for (count = 0; ; count++) { +            path_sensor = g_strdup_printf("%sin%d_input", path_hwmon, count); +            if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { +                g_free(path_sensor); +                break; +            } +             + +            mon = g_strdup_printf("in%d", count); +            name = get_sensor_label(mon); +            if (!g_str_equal(name, "ignore")) { +                sensors = g_strdup_printf("%s%s=%.3fV\n", +                                          sensors, name, +                                          adjust_sensor(mon, atof(tmp) / 1000.0)); +            } +             +            g_free(tmp); +            g_free(mon); +            g_free(name); +            g_free(path_sensor); +        } +     +        g_free(path_hwmon); +        g_free(driver); +        path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", ++hwmon); +    } +     +    g_free(path_hwmon);     +} + diff --git a/arch/linux/common/storage.h b/arch/linux/common/storage.h new file mode 100644 index 00000000..4fb682a9 --- /dev/null +++ b/arch/linux/common/storage.h @@ -0,0 +1,268 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar *storage_icons = ""; + +static gboolean +remove_scsi_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "SCSI", 4)) { +	g_free((gchar *) key); +	g_free((GtkTreeIter *) value); +	return TRUE; +    } +    return FALSE; +} + +/* SCSI support by Pascal F.Martin <pascalmartin@earthlink.net> */ +void +scan_scsi(void) +{ +    FILE *proc_scsi; +    gchar buffer[256], *buf; +    gint n = 0; +    gint scsi_controller; +    gint scsi_channel; +    gint scsi_id; +    gint scsi_lun; +    gchar *vendor = NULL, *revision = NULL, *model = NULL; + +    /* remove old devices from global device table */ +    g_hash_table_foreach_remove(devices, remove_scsi_devices, NULL); + +    if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS)) +	return; + +    storage_list = g_strconcat(storage_list, "\n[SCSI Disks]\n", NULL); + +    proc_scsi = fopen("/proc/scsi/scsi", "r"); +    while (fgets(buffer, 256, proc_scsi)) { +	buf = g_strstrip(buffer); +	if (!strncmp(buf, "Host: scsi", 10)) { +	    sscanf(buf, +		   "Host: scsi%d Channel: %d Id: %d Lun: %d", +		   &scsi_controller, &scsi_channel, &scsi_id, &scsi_lun); + +	    n++; +	} else if (!strncmp(buf, "Vendor: ", 8)) { +	    char *p; +	    char *rev = strstr(buf, "Rev: "); + +	    model = strstr(buf, "Model: "); + +	    if (model == NULL) { +		model = buf + strlen(buf); +	    } +	    p = model; +	    while (*(--p) == ' '); +	    *(++p) = 0; +	    vendor = g_strdup(buf + 8); + +	    if (rev != NULL) { +		revision = g_strdup(rev + 5); +	    } else { +		rev = model + strlen(model); +	    } +	    p = rev; +	    while (*(--p) == ' '); +	    *(++p) = 0; +	    model = g_strdup_printf("%s %s", vendor, model + 7); + +	} else if (!strncmp(buf, "Type:   ", 8)) { +	    char *p = strstr(buf, "ANSI SCSI revi"); +	    gchar *type = NULL, *icon = NULL; + +	    if (p != NULL) { +		while (*(--p) == ' '); +		*(++p) = 0; + +                static struct { +                    char *type; +                    char *label; +                    char *icon; +                } type2icon[] = { +                    { "Direct-Access", "Disk", "hdd"}, +                    { "Sequential-Access", "Tape", "tape"}, +                    { "Printer", "Printer", "lpr"}, +                    { "WORM", "CD-ROM", "cd"}, +                    { "CD-ROM", "CD-ROM", "cd"}, +                    { "Scanner", "Scanner", "scanner"}, +                    { NULL, "Generic", "scsi"}  +                }; +                int i; + +                for (i = 0; type2icon[i].type != NULL; i++) +                    if (!strcmp(buf + 8, type2icon[i].type)) +                        break; + +                type = type2icon[i].label; +                icon = type2icon[i].icon; +	    } +	     +	    gchar *devid = g_strdup_printf("SCSI%d", n); +	    storage_list = g_strdup_printf("%s$%s$%s=\n", storage_list, devid, model); +	    storage_icons = g_strdup_printf("%sIcon$%s$%s=%s.png\n", storage_icons, devid, model, icon); + +	    gchar *strhash = g_strdup_printf("[Device Information]\n" +					     "Model=%s\n" +					     "Type=%s\n" +					     "Revision=%s\n" +					     "[SCSI Controller]\n" +					     "Controller=scsi%d\n" +					     "Channel=%d\n" +					     "ID=%d\n" "LUN=%d\n", +					     model, +					     type, +					     revision, +					     scsi_controller, +					     scsi_channel, +					     scsi_id, +					     scsi_lun); +	    g_hash_table_insert(devices, devid, strhash); + +	    g_free(model); +	    g_free(revision); +	    g_free(vendor); +	} +    } +    fclose(proc_scsi); +} + +static gboolean +remove_ide_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "IDE", 3)) { +	g_free((gchar *) key); +	g_free((gchar *) value); + +	return TRUE; +    } +    return FALSE; +} + + +void +scan_ide(void) +{ +    FILE *proc_ide; +    gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry = +	NULL; +    gint n = 0, i = 0, cache; + +    /* remove old devices from global device table */ +    g_hash_table_foreach_remove(devices, remove_ide_devices, NULL); + +    storage_list = g_strdup_printf("%s\n[IDE Disks]\n", storage_list); + +    iface = 'a'; +    for (i = 0; i <= 16; i++) { +	device = g_strdup_printf("/proc/ide/hd%c/model", iface); +	if (g_file_test(device, G_FILE_TEST_EXISTS)) { +	    gchar buf[64]; + +	    cache = 0; + +	    proc_ide = fopen(device, "r"); +	    fgets(buf, 64, proc_ide); +	    fclose(proc_ide); + +	    buf[strlen(buf) - 1] = 0; + +	    model = g_strdup(buf); + +	    g_free(device); + +	    device = g_strdup_printf("/proc/ide/hd%c/media", iface); +	    proc_ide = fopen(device, "r"); +	    fgets(buf, 64, proc_ide); +	    fclose(proc_ide); +	    buf[strlen(buf) - 1] = 0; + +	    media = g_strdup(buf); + +	    g_free(device); + +	    device = g_strdup_printf("/proc/ide/hd%c/cache", iface); +	    if (g_file_test(device, G_FILE_TEST_EXISTS)) { +		proc_ide = fopen(device, "r"); +		fscanf(proc_ide, "%d", &cache); +		fclose(proc_ide); +	    } +	    g_free(device); + +	    device = g_strdup_printf("/proc/ide/hd%c/geometry", iface); +	    if (g_file_test(device, G_FILE_TEST_EXISTS)) { +		gchar *tmp; + +		proc_ide = fopen(device, "r"); + +		fgets(buf, 64, proc_ide); +		for (tmp = buf; *tmp; tmp++) { +		    if (*tmp >= '0' && *tmp <= '9') +			break; +		} + +		pgeometry = g_strdup(g_strstrip(tmp)); + +		fgets(buf, 64, proc_ide); +		for (tmp = buf; *tmp; tmp++) { +		    if (*tmp >= '0' && *tmp <= '9') +			break; +		} +		lgeometry = g_strdup(g_strstrip(tmp)); + +		fclose(proc_ide); +	    } +	    g_free(device); + +	    n++; + +	    gchar *devid = g_strdup_printf("IDE%d", n); + +	    storage_list = g_strdup_printf("%s$%s$%s=\n", storage_list, +					 devid, model); +	    storage_icons = g_strdup_printf("%sIcon$%s$%s=%s.png\n", storage_icons, devid, +	                                  model, g_str_equal(media, "cdrom") ? \ +	                                         "cdrom" : "hdd"); + +	    gchar *strhash = g_strdup_printf("[Device Information]\n" +					     "Model=%s\n" +					     "Device Name=hd%c\n" +					     "Media=%s\n" "Cache=%dkb\n", +					     model, iface, media, cache); +	    if (pgeometry && lgeometry) +		strhash = g_strdup_printf("%s[Geometry]\n" +					  "Physical=%s\n" +					  "Logical=%s\n", +					  strhash, pgeometry, lgeometry); +             +	    g_hash_table_insert(devices, devid, strhash); + +	    g_free(model); +	    model = ""; + +	    g_free(pgeometry); +	    pgeometry = NULL; +	    g_free(lgeometry); +	    lgeometry = NULL; +	} else +	    g_free(device); + +	iface++; +    } +} diff --git a/arch/linux/common/uptime.h b/arch/linux/common/uptime.h new file mode 100644 index 00000000..cf339bf3 --- /dev/null +++ b/arch/linux/common/uptime.h @@ -0,0 +1,75 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static UptimeInfo * +computer_get_uptime(void) +{ +    UptimeInfo *ui = g_new0(UptimeInfo, 1); +    FILE *procuptime; +    gulong minutes; + +    if ((procuptime = fopen("/proc/uptime", "r")) != NULL) { +	fscanf(procuptime, "%lu", &minutes); +	ui->minutes = minutes / 60; +	fclose(procuptime); +    } else { +	return NULL; +    } + +    ui->hours = ui->minutes / 60; +    ui->minutes %= 60; +    ui->days = ui->hours / 24; +    ui->hours %= 24; + +    return ui; +} + +static gchar * +computer_get_formatted_uptime() +{ +    UptimeInfo *ui; +    gchar *tmp; + +    ui = computer_get_uptime(); + +    /* FIXME: Use ngettext */ +#define plural(x) ((x > 1) ? "s" : "") + + +    if (ui->days < 1) { +	if (ui->hours < 1) { +	    tmp = +		g_strdup_printf("%d minute%s", ui->minutes, +				plural(ui->minutes)); +	} else { +	    tmp = +		g_strdup_printf("%d hour%s, %d minute%s", ui->hours, +				plural(ui->hours), ui->minutes, +				plural(ui->minutes)); +	} +    } else { +	tmp = +	    g_strdup_printf("%d day%s, %d hour%s and %d minute%s", +			    ui->days, plural(ui->days), ui->hours, +			    plural(ui->hours), ui->minutes, +			    plural(ui->minutes)); +    } + +    g_free(ui); +    return tmp; +} diff --git a/arch/linux/common/usb.h b/arch/linux/common/usb.h new file mode 100644 index 00000000..a52be2cb --- /dev/null +++ b/arch/linux/common/usb.h @@ -0,0 +1,132 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gboolean +remove_usb_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "USB", 3)) { +	GtkTreeIter *iter = (GtkTreeIter *) data; + +	g_free((gchar *) value); +	g_free(iter); + +	return TRUE; +    } +    return FALSE; +} + +static gchar *usb_list = NULL; +void +scan_usb(void) +{ +    FILE *dev; +    gchar buffer[128]; +    gchar *tmp, *manuf = NULL, *product = NULL, *mxpwr; +    gint bus, level, port, classid, trash; +    gint vendor, prodid; +    gfloat ver, rev, speed; +    int n = 0; + +    dev = fopen("/proc/bus/usb/devices", "r"); +    if (!dev) +	return; + +    if (usb_list) { +	g_hash_table_foreach_remove(devices, remove_usb_devices, NULL); +	g_free(usb_list); +    } +    usb_list = g_strdup(""); + +    while (fgets(buffer, 128, dev)) { +	tmp = buffer; + +	switch (*tmp) { +	case 'T': +	    sscanf(tmp, +		   "T:  Bus=%d Lev=%d Prnt=%d Port=%d Cnt=%d Dev#=%d Spd=%f", +		   &bus, &level, &trash, &port, &trash, &trash, &speed); +	    break; +	case 'D': +	    sscanf(tmp, "D:  Ver=%f Cls=%x", &ver, &classid); +	    break; +	case 'P': +	    sscanf(tmp, "P:  Vendor=%x ProdID=%x Rev=%f", +		   &vendor, &prodid, &rev); +	    break; +	case 'S': +	    if (strstr(tmp, "Manufacturer=")) { +		manuf = g_strdup(strchr(tmp, '=') + 1); +		remove_linefeed(manuf); +	    } else if (strstr(tmp, "Product=")) { +		product = g_strdup(strchr(tmp, '=') + 1); +		remove_linefeed(product); +	    } +	    break; +	case 'C': +	    mxpwr = strstr(buffer, "MxPwr=") + 6; + +	    tmp = g_strdup_printf("USB%d", ++n); +	     +	    if (*product == '\0') { +	        g_free(product); +	        if (classid == 9) { +                    product = g_strdup_printf("USB %.2f Hub", ver); +                } else { +  	            product = g_strdup_printf("Unknown USB %.2f Device (class %d)", +                                              ver, classid); +                } +	    } +	     + +	    if (classid == 9) {	/* hub */ +    	        usb_list = g_strdup_printf("%s[%s#%d]\n", +		      		           usb_list, product, n); +            } else { /* everything else */ +    	        usb_list = g_strdup_printf("%s$%s$%s=\n", +		      		           usb_list, tmp, product); + +                gchar *strhash = g_strdup_printf("[Device Information]\n" +                                                 "Product=%s\n" +                                                 "Manufacturer=%s\n" +                                                 "[Port #%d]\n" +                                                 "Speed=%.2fMbit/s\n" +                                                 "Max Current=%s\n" +                                                 "[Misc]\n" +                                                 "USB Version=%.2f\n" +                                                 "Revision=%.2f\n" +                                                 "Class=0x%x\n" +                                                 "Vendor=0x%x\n" +                                                 "Product ID=0x%x\n" +                                                 "Bus=%d\n" "Level=%d\n", +                                                 product, manuf, +                                                 port, speed, mxpwr, +                                                 ver, rev, classid, +                                                 vendor, prodid, bus, level); + +                g_hash_table_insert(devices, tmp, strhash); +            } + +	    g_free(manuf); +	    g_free(product); +	    manuf = g_strdup(""); +	    product = g_strdup(""); +	} +    } + +    fclose(dev); +} diff --git a/arch/linux/m68k/alsa.h b/arch/linux/m68k/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/m68k/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/m68k/filesystem.h b/arch/linux/m68k/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/m68k/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/m68k/inputdevices.h b/arch/linux/m68k/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/m68k/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/m68k/loadavg.h b/arch/linux/m68k/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/m68k/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/m68k/memory.h b/arch/linux/m68k/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/m68k/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/m68k/modules.h b/arch/linux/m68k/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/m68k/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/m68k/net.h b/arch/linux/m68k/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/m68k/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/m68k/os.h b/arch/linux/m68k/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/m68k/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/m68k/pci.h b/arch/linux/m68k/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/m68k/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/m68k/processor.h b/arch/linux/m68k/processor.h new file mode 100644 index 00000000..0a1bab62 --- /dev/null +++ b/arch/linux/m68k/processor.h @@ -0,0 +1,74 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("CPU", processor->model_name); +	    get_float("Clocking", processor->cpu_mhz); +	    get_float("bogomips", processor->bogomips); + +	    get_str("FPU", processor->has_fpu); +	} +	g_strfreev(tmp); +    } +     +    gchar *tmp; +    tmp = g_strconcat("Motorola ", processor->model_name, NULL); +    g_free(processor->model_name); +    processor->model_name = tmp; +     +    fclose(cpuinfo); + +    return processor; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	return g_strdup_printf("[Processor]\n" +	                       "Name=%s\n" +			       "Frequency=%.2fMHz\n" +			       "BogoMips=%.2f\n" +			       "Byte Order=%s\n", +			       processor->model_name, +			       processor->cpu_mhz, +			       processor->bogomips, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +                               "Little Endian" +#else +                               "Big Endian" +#endif +                               ); +} diff --git a/arch/linux/m68k/samba.h b/arch/linux/m68k/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/m68k/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/m68k/sensors.h b/arch/linux/m68k/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/m68k/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/m68k/storage.h b/arch/linux/m68k/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/m68k/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/m68k/uptime.h b/arch/linux/m68k/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/m68k/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/m68k/usb.h b/arch/linux/m68k/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/m68k/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/mips/alsa.h b/arch/linux/mips/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/mips/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/mips/filesystem.h b/arch/linux/mips/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/mips/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/mips/inputdevices.h b/arch/linux/mips/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/mips/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/mips/loadavg.h b/arch/linux/mips/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/mips/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/mips/memory.h b/arch/linux/mips/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/mips/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/mips/modules.h b/arch/linux/mips/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/mips/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/mips/net.h b/arch/linux/mips/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/mips/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/mips/os.h b/arch/linux/mips/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/mips/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/mips/pci.h b/arch/linux/mips/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/mips/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/mips/processor.h b/arch/linux/mips/processor.h new file mode 100644 index 00000000..8be922f9 --- /dev/null +++ b/arch/linux/mips/processor.h @@ -0,0 +1,70 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("system type", processor->model_name); +	    get_str("cpu model", processor->vendor_id); +	    get_float("cpu MHz", processor->cpu_mhz); +	    get_float("BogoMIPS", processor->bogomips); +	} +	g_strfreev(tmp); +    } + +    fclose(cpuinfo); + +    return processor; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	return g_strdup_printf("[Processor]\n" +	                       "System Type=%s\n" +	                       "CPU Model=%s\n" +                               "Frequency=%.2fMHz\n" +			       "BogoMIPS=%.2f\n" +			       "Byte Order=%s\n", +			       processor->model_name, +			       processor->vendor_id, +			       processor->cpu_mhz, +			       processor->bogomips, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +                               "Little Endian" +#else +                               "Big Endian" +#endif +			       ); +} diff --git a/arch/linux/mips/samba.h b/arch/linux/mips/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/mips/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/mips/sensors.h b/arch/linux/mips/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/mips/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/mips/storage.h b/arch/linux/mips/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/mips/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/mips/uptime.h b/arch/linux/mips/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/mips/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/mips/usb.h b/arch/linux/mips/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/mips/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/parisc/alsa.h b/arch/linux/parisc/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/parisc/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/parisc/filesystem.h b/arch/linux/parisc/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/parisc/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/parisc/inputdevices.h b/arch/linux/parisc/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/parisc/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/parisc/loadavg.h b/arch/linux/parisc/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/parisc/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/parisc/memory.h b/arch/linux/parisc/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/parisc/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/parisc/modules.h b/arch/linux/parisc/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/parisc/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/parisc/net.h b/arch/linux/parisc/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/parisc/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/parisc/os.h b/arch/linux/parisc/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/parisc/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/parisc/pci.h b/arch/linux/parisc/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/parisc/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/parisc/processor.h b/arch/linux/parisc/processor.h new file mode 100644 index 00000000..41b628f4 --- /dev/null +++ b/arch/linux/parisc/processor.h @@ -0,0 +1,82 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("cpu family", processor->model_name); +	    get_str("cpu", processor->vendor_id); +	    get_float("cpu MHz", processor->cpu_mhz); +	    get_float("bogomips", processor->bogomips); +	     +	    get_str("model name", processor->strmodel); +	     +	    get_int("I-cache", processor->has_fpu); +	    get_int("D-cache", processor->flags); + +	} +	g_strfreev(tmp); +    } + +    fclose(cpuinfo); + +    return processor; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	return  g_strdup_printf("[Processor]\n" +	                       "CPU Family=%s\n" +	                       "CPU=%s\n" +                               "Frequency=%.2fMHz\n" +			       "Bogomips=%.2f\n" +			       "Model Name=%s\n" +			       "Byte Order=%s\n" +			       "[Cache]\n" +			       "I-Cache=%s\n" +			       "D-Cache=%s\n", +			       processor->model_name, +			       processor->vendor_id, +			       processor->cpu_mhz, +			       processor->bogomips, +			       processor->strmodel, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +                               "Little Endian", +#else +                               "Big Endian", +#endif +			       processor->has_fpu, +			       processor->flags); +} diff --git a/arch/linux/parisc/samba.h b/arch/linux/parisc/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/parisc/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/parisc/sensors.h b/arch/linux/parisc/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/parisc/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/parisc/storage.h b/arch/linux/parisc/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/parisc/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/parisc/uptime.h b/arch/linux/parisc/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/parisc/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/parisc/usb.h b/arch/linux/parisc/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/parisc/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/ppc/alsa.h b/arch/linux/ppc/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/ppc/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/ppc/filesystem.h b/arch/linux/ppc/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/ppc/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/ppc/inputdevices.h b/arch/linux/ppc/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/ppc/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/ppc/loadavg.h b/arch/linux/ppc/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/ppc/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/ppc/memory.h b/arch/linux/ppc/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/ppc/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/ppc/modules.h b/arch/linux/ppc/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/ppc/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/ppc/net.h b/arch/linux/ppc/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/ppc/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/ppc/os.h b/arch/linux/ppc/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/ppc/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/ppc/pci.h b/arch/linux/ppc/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/ppc/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/ppc/processor.h b/arch/linux/ppc/processor.h new file mode 100644 index 00000000..f4ff5b0e --- /dev/null +++ b/arch/linux/ppc/processor.h @@ -0,0 +1,78 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("cpu", processor->model_name); +	    get_str("machine", processor->vendor_id); +	    get_int("L2 cache", processor->cache_size); +	    get_float("clock", processor->cpu_mhz); +	    get_float("bogomips", processor->bogomips); + +	} +	g_strfreev(tmp); +    } +     +    gchar *tmp = g_strconcat("PowerPC ", processor->model_name, NULL); +    g_free(processor->model_name); +    processor->model_name = tmp; + +    fclose(cpuinfo); + +    return processor; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	return g_strdup_printf("[Processor]\n" +	                       "Machine=%s\n" +	                       "CPU=%s\n" +	                       "L2 Cache=%.2f\n" +	                       "Frequency=%.2fMHz\n" +	                       "BogoMips=%.2f" +	                       "Byte Order=%s\n", +			       processor->vendor_id, +			       processor->model_name, +			       processor->cache_size, +			       processor->cpu_mhz, +			       processor->bogomips, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +                               "Little Endian" +#else +                               "Big Endian" +#endif +                              ); +} diff --git a/arch/linux/ppc/samba.h b/arch/linux/ppc/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/ppc/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/ppc/sensors.h b/arch/linux/ppc/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/ppc/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/ppc/storage.h b/arch/linux/ppc/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/ppc/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/ppc/uptime.h b/arch/linux/ppc/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/ppc/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/ppc/usb.h b/arch/linux/ppc/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/ppc/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/sparc/alsa.h b/arch/linux/sparc/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/sparc/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/sparc/filesystem.h b/arch/linux/sparc/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/sparc/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/sparc/inputdevices.h b/arch/linux/sparc/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/sparc/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/sparc/loadavg.h b/arch/linux/sparc/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/sparc/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/sparc/memory.h b/arch/linux/sparc/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/sparc/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/sparc/modules.h b/arch/linux/sparc/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/sparc/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/sparc/net.h b/arch/linux/sparc/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/sparc/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/sparc/os.h b/arch/linux/sparc/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/sparc/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/sparc/pci.h b/arch/linux/sparc/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/sparc/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/sparc/processor.h b/arch/linux/sparc/processor.h new file mode 100644 index 00000000..211ea56b --- /dev/null +++ b/arch/linux/sparc/processor.h @@ -0,0 +1,59 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("cpu", processor->model_name); +	    get_str("fpu", processor->has_fpu); +	} +	g_strfreev(tmp); +    } + +    get_processor_strfamily(processor); + +    fclose(cpuinfo); + +    return processor; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	return g_strdup_printf("[Processor]\n" +	                       "CPU=%s\n" +	                       "FPU=%s\n", +			       processor->model_name, +			       processor->has_fpu); +} diff --git a/arch/linux/sparc/samba.h b/arch/linux/sparc/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/sparc/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/sparc/sensors.h b/arch/linux/sparc/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/sparc/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/sparc/storage.h b/arch/linux/sparc/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/sparc/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/sparc/uptime.h b/arch/linux/sparc/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/sparc/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/sparc/usb.h b/arch/linux/sparc/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/sparc/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/x86/alsa.h b/arch/linux/x86/alsa.h new file mode 120000 index 00000000..0216845a --- /dev/null +++ b/arch/linux/x86/alsa.h @@ -0,0 +1 @@ +../../linux/common/alsa.h
\ No newline at end of file diff --git a/arch/linux/x86/filesystem.h b/arch/linux/x86/filesystem.h new file mode 120000 index 00000000..6b325b40 --- /dev/null +++ b/arch/linux/x86/filesystem.h @@ -0,0 +1 @@ +../../linux/common/filesystem.h
\ No newline at end of file diff --git a/arch/linux/x86/inputdevices.h b/arch/linux/x86/inputdevices.h new file mode 120000 index 00000000..b9226a29 --- /dev/null +++ b/arch/linux/x86/inputdevices.h @@ -0,0 +1 @@ +../../linux/common/inputdevices.h
\ No newline at end of file diff --git a/arch/linux/x86/loadavg.h b/arch/linux/x86/loadavg.h new file mode 120000 index 00000000..daaed6d5 --- /dev/null +++ b/arch/linux/x86/loadavg.h @@ -0,0 +1 @@ +../../linux/common/loadavg.h
\ No newline at end of file diff --git a/arch/linux/x86/memory.h b/arch/linux/x86/memory.h new file mode 120000 index 00000000..5ffc013e --- /dev/null +++ b/arch/linux/x86/memory.h @@ -0,0 +1 @@ +../../linux/common/memory.h
\ No newline at end of file diff --git a/arch/linux/x86/modules.h b/arch/linux/x86/modules.h new file mode 120000 index 00000000..8ce5a808 --- /dev/null +++ b/arch/linux/x86/modules.h @@ -0,0 +1 @@ +../../linux/common/modules.h
\ No newline at end of file diff --git a/arch/linux/x86/net.h b/arch/linux/x86/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/arch/linux/x86/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/arch/linux/x86/os.h b/arch/linux/x86/os.h new file mode 120000 index 00000000..ef547be5 --- /dev/null +++ b/arch/linux/x86/os.h @@ -0,0 +1 @@ +../../linux/common/os.h
\ No newline at end of file diff --git a/arch/linux/x86/pci.h b/arch/linux/x86/pci.h new file mode 120000 index 00000000..63760048 --- /dev/null +++ b/arch/linux/x86/pci.h @@ -0,0 +1 @@ +../../linux/common/pci.h
\ No newline at end of file diff --git a/arch/linux/x86/processor.h b/arch/linux/x86/processor.h new file mode 100644 index 00000000..571943f6 --- /dev/null +++ b/arch/linux/x86/processor.h @@ -0,0 +1,303 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +/* + * This function is partly based on x86cpucaps + * by Osamu Kayasono <jacobi@jcom.home.ne.jp> + */    +static void +get_processor_strfamily(Processor *processor) +{ +    gint family = processor->family; +    gint model = processor->model; + +    if (g_str_equal(processor->vendor_id, "GenuineIntel")) { +        if (family == 4) { +            processor->strmodel = g_strdup("i486 series"); +        } else if (family == 5) { +            if (model < 4) { +                processor->strmodel = g_strdup("Pentium Classic"); +            } else { +                processor->strmodel = g_strdup("Pentium MMX"); +            } +        } else if (family == 6) { +            if (model <= 1) { +                processor->strmodel = g_strdup("Pentium Pro"); +            } else if (model < 7) { +                processor->strmodel = g_strdup("Pentium II/Pentium II Xeon/Celeron"); +            } else if (model == 9) { +                processor->strmodel = g_strdup("Pentium M"); +            } else { +                processor->strmodel = g_strdup("Pentium III/Pentium III Xeon/Celeron"); +            } +        } else if (family > 6) { +            processor->strmodel = g_strdup("Pentium 4"); +        } else { +            processor->strmodel = g_strdup("i386 class"); +        } +    } else if (g_str_equal(processor->vendor_id, "AuthenticAMD")) { +        if (family == 4) { +            if (model <= 9) { +                processor->strmodel = g_strdup("AMD i80486 series"); +            } else { +                processor->strmodel = g_strdup("AMD 5x86"); +            } +        } else if (family == 5) { +            if (model <= 3) { +                processor->strmodel = g_strdup("AMD K5"); +            } else if (model <= 7) { +                processor->strmodel = g_strdup("AMD K6"); +            } else if (model == 8) { +                processor->strmodel = g_strdup("AMD K6-2"); +            } else if (model == 9) { +                processor->strmodel = g_strdup("AMD K6-III"); +            } else { +                processor->strmodel = g_strdup("AMD K6-2+/III+"); +            } +        } else if (family == 6) { +            if (model == 1) { +                processor->strmodel = g_strdup("AMD Athlon (K7"); +            } else if (model == 2) { +                processor->strmodel = g_strdup("AMD Athlon (K75)"); +            } else if (model == 3) { +                processor->strmodel = g_strdup("AMD Duron (Spitfire)"); +            } else if (model == 4) { +                processor->strmodel = g_strdup("AMD Athlon (Thunderbird)"); +            } else if (model == 6) { +                processor->strmodel = g_strdup("AMD Athlon XP/MP/4 (Palomino)"); +            } else if (model == 7) { +                processor->strmodel = g_strdup("AMD Duron (Morgan)"); +            } else if (model == 8) { +                processor->strmodel = g_strdup("AMD Athlon XP/MP (Thoroughbred)"); +            } else if (model == 10) { +                processor->strmodel = g_strdup("AMD Athlon XP/MP (Barton)"); +            } else { +                processor->strmodel = g_strdup("AMD Athlon (unknown)"); +            } +        } else if (family > 6) { +            processor->strmodel = g_strdup("AMD Opteron/Athlon64/FX"); +        } else { +            processor->strmodel = g_strdup("AMD i386 class"); +        } +    } else if (g_str_equal(processor->vendor_id, "CyrixInstead")) { +        if (family == 4) { +            processor->strmodel = g_strdup("Cyrix 5x86"); +        } else if (family == 5) { +            processor->strmodel = g_strdup("Cyrix M1 (6x86)"); +        } else if (family == 6) { +            if (model == 0) { +                processor->strmodel = g_strdup("Cyrix M2 (6x86MX)"); +            } else if (model <= 5) { +                processor->strmodel = g_strdup("VIA Cyrix III (M2 core)"); +            } else if (model == 6) { +                processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5A)"); +            } else if (model == 7) { +                processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5B/C)"); +            } else { +                processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5C-T)"); +            } +        } else { +            processor->strmodel = g_strdup("Cyrix i386 class"); +        } +    } else if (g_str_equal(processor->vendor_id, "CentaurHauls")) { +        if (family == 5) { +            if (model <= 4) { +                processor->strmodel = g_strdup("Centaur WinChip C6"); +            } else if (model <= 8) { +                processor->strmodel = g_strdup("Centaur WinChip 2"); +            } else { +                processor->strmodel = g_strdup("Centaur WinChip 2A"); +            } +        } else { +            processor->strmodel = g_strdup("Centaur i386 class"); +        } +    } else if (g_str_equal(processor->vendor_id, "GenuineTMx86")) { +        processor->strmodel = g_strdup("Transmeta Crusoe TM3x00/5x00"); +    } else { +        processor->strmodel = g_strdup("Unknown"); +    } +} + +static Processor * +computer_get_processor(void) +{ +    Processor *processor; +    FILE *cpuinfo; +    gchar buffer[128]; + +    cpuinfo = fopen("/proc/cpuinfo", "r"); +    if (!cpuinfo) +	return NULL; + +    processor = g_new0(Processor, 1); +    while (fgets(buffer, 128, cpuinfo)) { +	gchar **tmp = g_strsplit(buffer, ":", 2); + +	if (tmp[0] && tmp[1]) { +	    tmp[0] = g_strstrip(tmp[0]); +	    tmp[1] = g_strstrip(tmp[1]); + +	    get_str("model name", processor->model_name); +	    get_str("vendor_id", processor->vendor_id); +	    get_str("flags", processor->flags); +	    get_int("cache size", processor->cache_size); +	    get_float("cpu MHz", processor->cpu_mhz); +	    get_float("bogomips", processor->bogomips); + +	    get_str("fpu", processor->has_fpu); + +	    get_str("fdiv_bug", processor->bug_fdiv); +	    get_str("hlt_bug", processor->bug_hlt); +	    get_str("f00f_bug", processor->bug_f00f); +	    get_str("coma_bug", processor->bug_coma); +	     +	    get_int("model", processor->model); +	    get_int("cpu family", processor->family); +	    get_int("stepping", processor->stepping); +	} +	g_strfreev(tmp); +    } + +    get_processor_strfamily(processor); + +    fclose(cpuinfo); + +    return processor; +} + +static struct { +    char *name, *meaning; +} flag_meaning[] = { +    { "3dnow",		"3DNow! Technology" }, +    { "3dnowext",	"Extended 3DNow! Technology" }, +    { "fpu",		"Floating Point Unit" }, +    { "vme",		"Virtual 86 Mode Extension" }, +    { "de",		"Debug Extensions - I/O breakpoints" }, +    { "pse",		"Page Size Extensions (4MB pages)" }, +    { "tsc",		"Time Stamp Counter and RDTSC instruction" }, +    { "msr",		"Model Specific Registers" }, +    { "pae",		"Physical Address Extensions (36-bit address, 2MB pages)" }, +    { "mce",		"Machine Check Architeture" }, +    { "cx8",		"CMPXCHG8 instruction" }, +    { "apic",		"Advanced Programmable Interrupt Controller" }, +    { "sep",		"Fast System Call (SYSENTER/SYSEXIT instructions)" }, +    { "mtrr",		"Memory Type Range Registers" }, +    { "pge",		"Page Global Enable" }, +    { "mca",		"Machine Check Architecture" }, +    { "cmov",		"Conditional Move instruction" }, +    { "pat",		"Page Attribute Table" }, +    { "pse36",		"36bit Page Size Extensions" }, +    { "psn",		"96 bit Processor Serial Number" }, +    { "mmx",		"MMX technology" }, +    { "mmxext",		"Extended MMX Technology" }, +    { "cflush",		"Cache Flush" }, +    { "dtes",		"Debug Trace Store" }, +    { "fxsr",		"FXSAVE and FXRSTOR instructions" }, +    { "kni",		"Streaming SIMD instructions" }, +    { "xmm",		"Streaming SIMD instructions" }, +    { "ht",		"HyperThreading" }, +    { "mp",		"Multiprocessing Capable" }, +    { "sse",		"SSE instructions" }, +    { "sse2",		"SSE2 (WNI) instructions" }, +    { "acc",		"Automatic Clock Control" }, +    { "ia64",		"IA64 Instructions" }, +    { "syscall",	"SYSCALL and SYSEXIT instructions" }, +    { "nx",		"No-execute Page Protection" }, +    { "xd",		"Execute Disable" }, +    { "clflush",	"Cache Line Flush instruction" }, +    { "acpi",		"Thermal Monitor and Software Controlled Clock Facilities" }, +    { "dts",		"Debug Store" }, +    { "ss",		"Self Snoop" }, +    { "tm",		"Thermal Monitor" }, +    { "pbe",		"Pending Break Enable" }, +    { "pb",		"Pending Break Enable" }, +    { NULL, NULL} +}; + +gchar * +processor_get_capabilities_from_flags(gchar * strflags) +{ +    /* FIXME: * Separate between processor capabilities, additional instructions and whatnot.  */ +    gchar **flags, **old; +    gchar *tmp = ""; +    gint i; + +    flags = g_strsplit(strflags, " ", 0); +    old = flags; + +    while (*flags) { +	gchar *meaning = ""; +	for (i = 0; flag_meaning[i].name != NULL; i++) { +	    if (!strcmp(*flags, flag_meaning[i].name)) { +		meaning = flag_meaning[i].meaning; +		break; +	    } +	} + +	tmp = g_strdup_printf("%s%s=%s\n", tmp, *flags, meaning); +	*flags++; +    } + +    g_strfreev(old); +    return tmp; +} + +static gchar * +processor_get_info(Processor *processor) +{ +	gchar *tmp = processor_get_capabilities_from_flags(processor-> +						  flags); +	gchar *ret = g_strdup_printf("[Processor]\n" +	                       "Name=%s\n" +	                       "Specification=%s\n" +                               "Family, model, stepping=%d, %d, %d\n" +			       "Vendor=%s\n" +			       "Cache Size=%dkb\n" +			       "Frequency=%.2fMHz\n" +			       "BogoMips=%.2f\n" +			       "Byte Order=%s\n" +			       "[Features]\n" +			       "FDIV Bug=%s\n" +			       "HLT Bug=%s\n" +			       "F00F Bug=%s\n" +			       "Coma Bug=%s\n" +			       "Has FPU=%s\n" +			       "[Capabilities]\n" "%s", +			       processor->strmodel, +			       processor->model_name, +			       processor->family, +			       processor->model, +			       processor->stepping, +			       processor->vendor_id, +			       processor->cache_size, +			       processor->cpu_mhz, +			       processor->bogomips, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +                               "Little Endian", +#else +                               "Big Endian", +#endif +			       processor->bug_fdiv, +			       processor->bug_hlt, +			       processor->bug_f00f, +			       processor->bug_coma, +			       processor->has_fpu, +			       tmp); +      g_free(tmp); +      return ret; +} diff --git a/arch/linux/x86/samba.h b/arch/linux/x86/samba.h new file mode 120000 index 00000000..9227f722 --- /dev/null +++ b/arch/linux/x86/samba.h @@ -0,0 +1 @@ +../../linux/common/samba.h
\ No newline at end of file diff --git a/arch/linux/x86/sensors.h b/arch/linux/x86/sensors.h new file mode 120000 index 00000000..35e5f37a --- /dev/null +++ b/arch/linux/x86/sensors.h @@ -0,0 +1 @@ +../../linux/common/sensors.h
\ No newline at end of file diff --git a/arch/linux/x86/storage.h b/arch/linux/x86/storage.h new file mode 120000 index 00000000..55b68de3 --- /dev/null +++ b/arch/linux/x86/storage.h @@ -0,0 +1 @@ +../../linux/common/storage.h
\ No newline at end of file diff --git a/arch/linux/x86/uptime.h b/arch/linux/x86/uptime.h new file mode 120000 index 00000000..78c026ff --- /dev/null +++ b/arch/linux/x86/uptime.h @@ -0,0 +1 @@ +../../linux/common/uptime.h
\ No newline at end of file diff --git a/arch/linux/x86/usb.h b/arch/linux/x86/usb.h new file mode 120000 index 00000000..8b8fbb5d --- /dev/null +++ b/arch/linux/x86/usb.h @@ -0,0 +1 @@ +../../linux/common/usb.h
\ No newline at end of file diff --git a/arch/linux/x86_64 b/arch/linux/x86_64 new file mode 120000 index 00000000..f4bad791 --- /dev/null +++ b/arch/linux/x86_64 @@ -0,0 +1 @@ +x86
\ No newline at end of file | 
