summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2006-11-18 20:22:17 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2006-11-18 20:22:17 +0000
commit99d0488dc1a2de1e1701bdae3a35b3cd5605d7fe (patch)
tree60e301af19fd3f53d6bf68ee3f1fe9562f1d0318
parentee1fa4b725acd32a8549f0d5f16f6e5f1ec1fbd5 (diff)
More CD-ROM information
-rw-r--r--hardinfo2/arch/linux/common/storage.h58
-rw-r--r--hardinfo2/hardinfo.h7
-rw-r--r--hardinfo2/util.c12
3 files changed, 67 insertions, 10 deletions
diff --git a/hardinfo2/arch/linux/common/storage.h b/hardinfo2/arch/linux/common/storage.h
index 3f65b04e..7e25745c 100644
--- a/hardinfo2/arch/linux/common/storage.h
+++ b/hardinfo2/arch/linux/common/storage.h
@@ -165,7 +165,8 @@ scan_ide(void)
FILE *proc_ide;
gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry =
NULL;
- gint n = 0, i = 0, cache;
+ gint n = 0, i = 0, cache, nn = 0;
+ gchar *capab = NULL, *speed = NULL;
/* remove old devices from global device table */
g_hash_table_foreach_remove(devices, remove_ide_devices, NULL);
@@ -197,6 +198,34 @@ scan_ide(void)
buf[strlen(buf) - 1] = 0;
media = g_strdup(buf);
+ if (g_str_equal(media, "cdrom")) {
+ /* obtain cd-rom drive information from cdrecord */
+ gchar *tmp = g_strdup_printf("cdrecord dev=/dev/hd%c -prcap 2>/dev/null", iface);
+ FILE *prcap;
+
+ if ((prcap = popen(tmp, "r"))) {
+ while (fgets(buf, 64, prcap)) {
+ if (g_str_has_prefix(buf, " Does") && g_str_has_suffix(buf, "media\n") && !strstr(buf, "speed")) {
+ gchar *media_type = g_strstrip(strstr(buf, "Does "));
+ gchar **ttmp = g_strsplit(media_type, " ", 0);
+
+ capab = g_strdup_printf("%s\nCan %s#%d=%s\n",
+ capab ? capab : "",
+ ttmp[1], ++nn, ttmp[2]);
+
+ g_strfreev(ttmp);
+ } else if ((strstr(buf, "read") || strstr(buf, "write")) && strstr(buf, "kB/s")) {
+ speed = g_strconcat(speed ? speed : "",
+ strreplace(g_strstrip(buf), ":", '='),
+ "\n", NULL);
+ }
+ }
+
+ pclose(prcap);
+ }
+
+ g_free(tmp);
+ }
g_free(device);
@@ -254,21 +283,36 @@ scan_ide(void)
iface,
media,
cache);
- if (pgeometry && lgeometry)
+ if (pgeometry && lgeometry) {
strhash = g_strdup_printf("%s[Geometry]\n"
"Physical=%s\n"
"Logical=%s\n",
strhash, pgeometry, lgeometry);
+
+ g_free(pgeometry);
+ pgeometry = NULL;
+ g_free(lgeometry);
+ lgeometry = NULL;
+ }
+
+ if (capab) {
+ strhash = g_strdup_printf("%s[Capabilities]\n%s", strhash, capab);
+
+ g_free(capab);
+ capab = NULL;
+ }
+
+ if (speed) {
+ strhash = g_strdup_printf("%s[Speeds]\n%s", strhash, speed);
+
+ g_free(speed);
+ speed = NULL;
+ }
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);
diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h
index d0da307b..42c65d4f 100644
--- a/hardinfo2/hardinfo.h
+++ b/hardinfo2/hardinfo.h
@@ -37,9 +37,10 @@ struct _ModuleEntry {
};
/* String utility functions */
-inline void remove_quotes(gchar *str);
-inline void strend(gchar *str, gchar chr);
-inline void remove_linefeed(gchar *str);
+inline void remove_quotes(gchar *str);
+inline void strend(gchar *str, gchar chr);
+inline void remove_linefeed(gchar *str);
+gchar *strreplace(gchar *string, gchar *replace, gchar new_char);
/* Widget utility functions */
void widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type);
diff --git a/hardinfo2/util.c b/hardinfo2/util.c
index b18283eb..0c691f00 100644
--- a/hardinfo2/util.c
+++ b/hardinfo2/util.c
@@ -291,3 +291,15 @@ open_url(gchar *url)
g_warning("Couldn't find a Web browser to open URL %s.", url);
}
+
+/* Copyright: Jens Låås, SLU 2002 */
+gchar *strreplace(gchar *string, gchar *replace, gchar new_char)
+{
+ gchar *s;
+ for(s=string;*s;s++)
+ if(strchr(replace, *s))
+ *s = new_char;
+
+ return string;
+}
+