Wednesday, September 29, 2010

ReadyNAS Duo Internals

This very cool NAS Box runs a version of Linux (I think Debian):

nas-D0-E9-23:/c/home/admin# uname -a
Linux nas-D0-E9-23 2.6.17.8ReadyNAS #1 Tue Jun 9 13:59:28 PDT 2009 padre unknown

nas-D0-E9-23:/c/home/admin# cat /proc/cpuinfo
cpu : Infrant Technologics, Inc. - neon version: 0
fpu : Softfpu
ncpus probed : 1
ncpus active : 1
BogoMips : 186.36
MMU : version: 0
LP : HW.FW version: 0.1
FPGA : fpga000000-0 Configuration: 0
AHB arbitraion : 7
CPU id : 0
Switch : 0
ASIC : IT3107

nas-D0-E9-23:/c/home/admin# lspci
0000:00:17.0 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.1 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.2 USB Controller: VIA Technologies, Inc. USB 2.0 (rev 65)

nas-D0-E9-23:/proc# fdisk -l /dev/hdc

Disk /dev/hdc: 999.9 GB, 999991611392 bytes
255 heads, 63 sectors/track, 121575 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/hdc1 1 255 2048000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/hdc2 255 287 256000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/hdc3 287 121575 974242116 5 Extended
/dev/hdc5 287 121575 974242115+ 8e Linux LVM

Compared to my HP desktop machine, this NAS Box is away slower:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz
stepping        : 11
cpu MHz         : 1600.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 4
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dt
s acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aper
fmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriori
ty
bogomips        : 12479.54
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

Despite the fact, I love this new toy!

Sunday, September 26, 2010

Useful status line in vi

:set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]

Tuesday, September 14, 2010

Cool Real gauge measuring your PC performance:





Google Graph

Cool way to draw gauges via Google Graph API:
http://code.google.com/apis/visualization/documentation/gallery/gauge.html

Saturday, July 17, 2010

Array of Strings

// strtok.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *SkipChars(char *buf, const char charToSkip)
{
    char *p = buf;
    while (p && (*p) && (*p == charToSkip)) p++;
    return p;
}


char *SkipString(char *buf, const char *str)
{
    char *p;
    p = strstr(buf, str);
    if (p) {
        p += strlen(str);
    }
    return p;
}


char *GetToken(char *buf, char *tok, int toksize)
{
char *start;
int i = 0;

start = SkipChars(buf, ' ');
while (start && (*start != 0) && (*start != ' ') && (i < toksize)) {
tok[i++] = *start;
start++;
}
tok[i] = 0;
return start;
}


int ParseLine(char *buf, char delim, char **toks, int tokSize, int n)
{
    char *start, *item;
    int i = 0;

    if ((!buf) || (!toks)) return NULL;
    start = SkipChars(buf, delim);
if (*start==0) return NULL;
while (start && (*start) && (i<n)) {
  /* convert to first-major pointer */
item = ((char *)&toks[0] + tokSize*i);
start = GetToken(start, (char *)item, tokSize);
i++;
}
    return i;
}

char *GetStringVal(char *buf, char *key, char *val, int valSize)
{
char *p = SkipString(buf, key);
if (p) {
p = GetToken(p, val, valSize);
}
return val;
}

const char desc[] = "This is just an example for skipstring function";
char res[] = "Mac             Type      Interface\n"
             "1111.2222.3333  S         fe0/0\n"
             "aabc.ddef.8754  S         fe0/0\n"
             "553a.4455.6789  D         fe0/1\n"
             "Total Macs 0\n";
char set[] = "mac-learning alarm 90 clear 60";


#define TOKEN_LEN 80
int _tmain(int argc, _TCHAR* argv[])
{
    int i,balance,len;
    char *p, *q, **pp;
    char token[100];
char tokens[3][TOKEN_LEN] = {"saya", "makan", "nasi"};

#if 0
    /* Program entry point */
    if (argc) {
        for( i=0; i<argc; i++) {
            printf("argv[%d] = %s\n", i, argv[i]);
            p = SkipChars(argv[i], ' ');
            p = SkipChars(p, '"');
            while (p) {
                if (balance) balance=0;
                 end = SkipChars(p, '"');
                 if (end) {
                    balance = 1;
                    len = end-p;
                    strncpy(token, p, len);
                    token[len] = 0;
                    printf("token=%s\n", token);
                    p = end;
                    printf("p = %s\n", p);
                }
                if ((!balance) || (!len))
                    break;
            }
        }
    }
    printf("original string: %s\n", desc);
    p = SkipString((char*)&desc[0], "an example for ");
    if (p) {
        printf("After SkipString: %s\n", p);
    }
#endif
    p = SkipString((char *)res, "Interface\n");
    if (p) {
        p = strtok(p, "\n");
        //printf("original p=%s\n", p);
        while (p) {
            if (strstr(p, "Total Mac")) break;
            printf("\n\n--------------------------------------\n");
printf("address of tokens[0][0] = %X\n", &tokens[0][0]);
//printf("q = %X\n", q);
            len = ParseLine(p, ' ', (char **)&tokens, TOKEN_LEN, 3);
for(i=0; i<len; i++) {
printf("token%d = %s\n", i+1, tokens[i]);
}
            printf("%s\n", p);
            printf("--------------------------------------\n");
            p = strtok(NULL, "\n");
        }
    }
printf("alarm=%s\n", GetStringVal(set, "alarm", token, sizeof(token)));
printf("clear=%s\n", GetStringVal(set, "clear", token, sizeof(token)));
return 0;
}

Friday, July 16, 2010

Get String

// strtok.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *SkipChars(char *buf, const char charToSkip)
{
    char *p = buf;
    while (p && (*p) && (*p == charToSkip)) p++;
    return p;
}


char *SkipString(char *buf, const char *str)
{
    char *p;
    p = strstr(buf, str);
    if (p) {
        p += strlen(str);
    }
    return p;
}


char *ParseLine(char *buf, char delim, char *token)
{
    char *start, *end;
    int len;

    if ((!buf) || (!token)) return NULL;
    start = SkipChars(buf, delim);
if (*start==0) return NULL;
    end=NULL;
    if (start) {
         end = start;
         while ((end) && (*end) && (*end != delim)) end++;
         len = end-start;
         strncpy(token, start, len);
         token[len] = 0;
    }
    start = SkipChars(end, delim);
    return start;
}

char *GetStringVal(char *buf, char *key, char *val)
{
char *p = SkipString(buf, key);
if (p) {
p = ParseLine(p, ' ', val);
}
return val;
}

const char desc[] = "This is just an example for skipstring function";
char res[] = "Mac             Type      Interface\n"
             "1111.2222.3333  S         fe0/0\n"
             "aabc.ddef.8754  S         fe0/0\n"
             "553a.4455.6789  D         fe0/1\n"
             "Total Macs 0\n";
char set[] = "mac-learning alarm 90 clear 60";


int _tmain(int argc, _TCHAR* argv[])
{
    int i,balance,len;
    char *p, *end;
    char token[100];
    char *saveptr;

#if 0
    /* Program entry point */
    if (argc) {
        for( i=0; i<argc; i++) {
            printf("argv[%d] = %s\n", i, argv[i]);
            p = SkipChars(argv[i], ' ');
            p = SkipChars(p, '"');
            while (p) {
                if (balance) balance=0;
                 end = SkipChars(p, '"');
                 if (end) {
                    balance = 1;
                    len = end-p;
                    strncpy(token, p, len);
                    token[len] = 0;
                    printf("token=%s\n", token);
                    p = end;
                    printf("p = %s\n", p);
                }
                if ((!balance) || (!len))
                    break;
            }
        }
    }
    printf("original string: %s\n", desc);
    p = SkipString((char*)&desc[0], "an example for ");
    if (p) {
        printf("After SkipString: %s\n", p);
    }
#endif
    p = SkipString((char *)res, "Interface\n");
    if (p) {
        p = strtok(p, "\n");
        //printf("original p=%s\n", p);
        while (p) {
            if (strstr(p, "Total Mac")) break;
            printf("\n\n--------------------------------------\n");
            #if 1
            end = ParseLine(p, ' ', token);
            printf("end=%s\n", end);
            i = 0;
            while (end){
                p = end;
                printf("Token%d=%s\n", i+1, token);
                end = ParseLine(p, ' ', token);
                i++;
            }
            #endif
            printf("%s\n", p);
            printf("--------------------------------------\n");
            p = strtok(NULL, "\n");
        }
    }
printf("alarm=%s\n", GetStringVal(set, "alarm", token));
printf("clear=%s\n", GetStringVal(set, "clear", token));
return 0;
}