From: <ow...@us...> - 2008-02-15 12:08:41
|
Revision: 1095 http://ipcop.svn.sourceforge.net/ipcop/?rev=1095&view=rev Author: owes Date: 2008-02-15 04:08:44 -0800 (Fri, 15 Feb 2008) Log Message: ----------- Also display size of disk (approximation) when installing. Modified Paths: -------------- ipcop/trunk/src/installer/hardware.c Modified: ipcop/trunk/src/installer/hardware.c =================================================================== --- ipcop/trunk/src/installer/hardware.c 2008-02-14 16:34:52 UTC (rev 1094) +++ ipcop/trunk/src/installer/hardware.c 2008-02-15 12:08:44 UTC (rev 1095) @@ -15,6 +15,7 @@ #include <discover/discover-conf.h> #include <newt.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -36,7 +37,46 @@ static int have_idecd = 0; static int install_setup = 0; /* 0 when running setup (NIC detection), 1 for installer */ + /* + Retrieve disk capacity from proc or sys. + Size is reported in blocks of 512 bytes, make a string with info GB, MB, KB. +*/ +static void getdrivesize(char *procname, char *strsize) +{ + FILE *f; + uint64_t size; /* using 32bit would limit to 1000 GB, not too far away */ + + strcpy(strsize, "? KB"); + + if ( (f = fopen(procname, "r")) != NULL ) + { + if ( fgets(strsize, STRING_SIZE, f) ) + { + size = strtoull(strsize, NULL, 10); + size = size * 512 / 1000; /* use the disk vendor way of specifying KBytes */ + + if ( size >= 4000000 ) + { + /* Everything larger than 4000 MB */ + snprintf(strsize, STRING_SIZE, "%llu GB", size / 1000000); + } + else if ( size >= 4000 ) + { + /* Everything larger than 4000 KB */ + snprintf(strsize, STRING_SIZE, "%llu MB", size / 1000); + } + else + { + /* Anything else, unlikely since we need something like 100+ MB anyway */ + snprintf(strsize, STRING_SIZE, "%llu KB", size); + } + } + } +} + + +/* Add something to our hardware list */ static void hardwareadd(supported_media_t type, char *module, char *device, char *vendor, char *description, char *vendorid, char *modelid) @@ -132,6 +172,7 @@ supported_media_t type = none; char command[STRING_SIZE]; char deviceletter; + char strsize[STRING_SIZE]; /* look for IDE harddisk and cdrom */ for (deviceletter = 'a'; deviceletter <= 'z'; deviceletter++) @@ -185,7 +226,17 @@ if ( fgets(model, STRING_SIZE, f) ) { stripnl(model); - strcpy(description, model); + if ( type == harddisk ) + { + snprintf(procname, STRING_SIZE, "/proc/ide/hd%c/capacity", deviceletter); + getdrivesize(procname, strsize); + + snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize); + } + else + { + strcpy(description, model); + } } fclose(f); } @@ -212,10 +263,16 @@ if ( fgets(model, STRING_SIZE, f) ) { char device[4]; + char description[STRING_SIZE] = "Unknown"; stripnl(model); sprintf(device, "sd%c", deviceletter); - hardwareadd(harddisk, NULL, device, NULL, model, NULL, NULL); + + snprintf(procname, STRING_SIZE, "/sys/block/sd%c/size", deviceletter); + getdrivesize(procname, strsize); + snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize); + + hardwareadd(harddisk, NULL, device, NULL, description, NULL, NULL); } fclose(f); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |