My Tech notes: 2008
Subscribe

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Tuesday, December 30, 2008

DHCP Client Server Porting Guide Steps Here

Looking for DHCP Client Server Porting Guide Steps? read on,

1.Download udhcp-0.9.8.tar.gz and Untar it
>tar -zxvf udhcp-0.9.8.tar.gz

2.You will get udhcp-0.9.8 directory.Go to that directory
>cd udhcp-0.9.8

3.The code can be compiled directly for gcc.For arm-linux
> Go to Makefile and uncomment the CROSS-COMPILE (line 19) and edit
>CROSS-COMPILE=arm-linux-

4.Now run make command from that directory.
>make

5.You will get two binaries
1.udhcpd -- DHCP Server
2.udhcpc -- DHCP Client

6.For DHCP server:
1.copy udhcpd(binary) to /usr/sbin
2.copy udhcpd.conf in the directory samples to /etc directory
3.create an empty file udhcpd.leases in /var/lib/misc directoty

7.For DHCP client:
1.copy udhcpc(binary) to /sbin directory
2.copy all the scripts except udhcpd.conf in samples directory to
/usr/share/udhcpc directory
3.Create an empty directory udhcpc in /etc directory.
(In this directory the client will create a file resolv.conf for
DNS entries)

8.For running DHCP client

eth0 :> /sbin/udhcpc -s /usr/share/udhcpc/sample.bound
eth1 :> /sbin/udhcpc -i eth1 -s /usr/share/udhcpc/sample.bound
eth2 :> /sbin/udhcpc -i eth2 -s /usr/share/udhcpc/sample.bound

9.For running DHCP server

interface : Change the interface in config file udhcpd.conf in /etc
directory to the interface on which you want to run.
Ex: interface eth0 (for running server on eth0 interface)

>/usr/sbin/udhcpd

Sunday, December 21, 2008

NFS Based ROOTFS Mounting From NFS

How to boot from NFS?
Network File System (NFS) is a Network file system protocol allowing a user on a client computer to access files over a network as easily as if the network devices were attached to its local disks. All kernels after 2.2 support NFS over TCP.


Mounting the root file system from NFS steps.

1) Go to kernel source directory and type "make menuconfig".
2) In order to configure root NFS support in the kernel, it is first necessary to enable "IP Autoconfiguration". This setting is accessed by selecting "Network" and then "Networking Options" in the menu. On the Network options screen select "IP: kernel level autoconfiguration". type / to search config options from make menucnfig.
3) Main menu select "File Systems" select "Network File Systems". On the Network File Systems page select the "NFS file system support" as built-in (select as *). Then scroll down and select "Root File system on NFS".
4) Now give the boot options to the kernel so that it mounts the NFS directory. From the main menu of kernel configuration select "Boot Options" and select "Default kernel command string". Here give something like the following:
root=/dev/nfs rw nfsroot=192.168.xx.xx:/home/xyz/fs_image ip=192.168.yy.yy:192.168.xx.xx::::eth0:off mem=32M@0x0 console=ttyMCS

Where 192.168.xx.xx is the server IP i.e where the actual Root File system exists. And 192.168.yy.yy is the Board's IP address.

5) Save the kernel configuration. Go to the "dev" folder inside the "fs_image" and create a device entry for ttyMCS by giving "mknod ttyMCS c 204 32". Also create a soft link ttyS0. "ln -s ttyMCS ttyS0". If it is not there. You need to be in root to do this.

6) Now create a kernel image with modified configuration.
7) Next, Setup the NFS server side. Open the /etc/exports file and add the following line
/home/xyz/fs_image/ 192.168.2.yy.yy (rw,no_root_squash)

Save and exit the file.
8) Restart the two services in the server PC.
# service portmap restart
# service nfs restart
9) On the board, from the bootloader Remove the Bootargs, since by having this will override kernel command line arguments. Just give "setenv bootargs" to unset.
10) Next step is to just do TFTP of the kernel image and run "bootmf".

Any question and doubts put comments.

Saturday, December 20, 2008

Steps For Booting Linux Kernel From USB Pen Drive

Boot Linux kernel from USB:
Here are the steps for Booting Linux kernel from USB pen drive. If you have kernel image in pen drive then use these steps to boot from pen drive.

1) Create ext2 file system on USB.
2) Copy the kernel image to USB.
3) Connect the USB to embedded board.
4) From u-boot: Execute following commands.
5) “usb start” :– This will probe for usb mass storage devices.
6) “usb storage”:- shows the details of mass storage device.
7) “ext2ls usb o” :- lists the files in the USB.
8) “ext2load usb 0 7fc0 scp_zimage “ :- copies the embedded linux kernel file from usb and stores it in RAM 7fc0
9) Then do “bootm” to boot Linux.

Friday, December 19, 2008

What is Boot loader in embedded System Init Steps

Lets talk about Boot loader in embedded system and its basics.
What is Boot loader in embedded System and its initialization steps?
What happens on power on? What does bootloader do on power on? Read on for answers to these question .
Boot loader is a program which will execute on power-on in an embedded system. The main functionality of the boot loader is to initialize the hardware and make a platform for, and load the Operating system. Hardware initialization includes the CPU, memory controller, UART, etc. As system is up the CPU will be initialized then the memory controller (i.e. DDR controller, Flash controller) will be initialized. The Boot loader code will itself relocate to the RAM and do further hardware initialization like UART, MAC, PCI etc.
The very first initialization code should be from a non-volatile memory on board, which will have the capability of XIP (execute in place). IF you have serial Flash as boot code holder, which cannot be used for XIP, then other options are

1. Boot from IROM
2. Boot from SPI flash

IROM code will be a one time programmable on-chip memory. This memory should be enough to hold a minimal boot loader. This memory will have the capability of XIP. On power-up, if boot strap selects this mode of operation IROM code will initialize the hardware. After initialization is over the code will be relocated to DDR.
Basic operations provided in the boot loader will be
1. Memory read
2. Memory write
3. SPI & I2C EEPROM support
4. SPI Flash read, write & erase
5. TFTP support for Upgrade
Algorithm for the boot-up procedure from IROM
1. On power-up IROM will be mapped to address 0x00 by H/W.
2. Read the configuration data from I2C/SPI memory for configuring memory controller and SPI Flash Support.

a. If I2C EEPROM is not present, I2C flag provided by the ASIC will be cleared. Thus boot loader can do a conditional read, either from SPI EEPROM or I2C EEPROM.
b. When neither SPI EEPROM nor I2C EEPROM has the configuration data, default configuration will be used.
3. Configure the memory controller and SPI Flash support

4. The IROM code will be relocated to the DDR
5. Control of execution will be transferred to DDR.

In summary
Internal bootloader (IBoot) is present in the IROM memory of the chip and the main purpose of this is to do the critical initializations. The IBoot is divided into following.
Booting procedure:
• Jump to Internal ROM address 0xE8000100.
• Initialize CPU (peripheral port configuration).
• Disable the IROM on region0 i.e. at address 0x00 so that DDR can be configured.
• Initialize DDR memory controller.
• Check for PCIe RC/EP mode and if EP mode is enabled then configure the device properties.
• Check for external booting mode and if it is enabled relocate code from SPI flash and execute it.
• If external booting is not enabled then relocate the IBoot code from IROM to RAM and jump to the start_iboot ().
• Initialize UART with baud rate 57600.
• Initialize the stack.
• Print the IBoot command prompt.
• Now IBoot is ready to execute commands given by the user.

Thursday, December 18, 2008

ntfsprogs and Fuse Compilation errors and Solution here

Got some luck to compile ntfsprogs. Ntfsprogs are a collection of utilities for doing stuff with NTFS volumes. Steps to compile ntfsprogs .
1. get the FUSE and compile it.
$ tar xvzf fuse-2.7.4.tar.gz
$ ./configure --disable-kernel-module
$ make
getting error while compiling examples dir.

libtool: link: gcc -Wall -W -Wno-sign-compare -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -g -O2 -fno-strict-aliasing -o .libs/fusexmp fusexmp.o -pthread -pthread ../lib/.libs/libfuse.so -ldl
../lib/.libs/libfuse.so: undefined reference to `clock_gettime'
make[1]: Leaving directory `/home/bhagwat/fuse-2.7.4/example'
Solution is
$ cd examples
open Makefile go to line no 205 change the option from -ldl to -lrt
$ cd ../make
$ make install

FUSE will be installed in default dir ie /usr/local/lib
Get the ntfsprogs from linux-ntfs. untar ntfsprograms
$ tar xvzf ntfsprogs-2.0.0.tar.gz
$ ./configure --enable-ntfsmount

still getting same error
smount ntfsmount-ntfsmount.o ntfsmount-utils.o -pthread ../libntfs/.libs/libntfs.so -L/usr/local/lib /usr/local/lib/libfuse.so -ldl
/usr/local/lib/libfuse.so: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make[2]: *** [ntfsmount] Error 1
make[2]: Leaving directory `/home/bhagwat/ntfsprogs-2.0.0/ntfsprogs'

so go to ntfsprogs and change the -ldl option to -lrt in Makefile.
and done.
I got successfully compiled ntfsprogs and got ntfsmount for my embedded linux box.
Note:- I have compiled these utilities in Scratchbox is a cross-compilation toolkit designed to make embedded Linux application development easier.
Also note that FUSE require libpthred lib in scratchbox home, before compiling setup libpthred also.
The shortcut to all this compilation error and efforts is use Debian pre-compiled source for ntfsprogs for ARM.

Wednesday, December 17, 2008

Useful Windows DOS Commands For Linux Users

Useful Windows DOS Commands For Linux Users
the most useful DOS commands available in Windows XP. DOS Commands must be run at the prompt of the Cmd.exe. To open Command Prompt, click Start, click Run, type cmd, and then click OK.
Now try some useful commands;
1. To convert FAt32 volume into NTFS volume
use :- CONVERT F: /FS:NTFS
converts F drive into NTFS format.
2. Disconnect all the connection using net use
use : - net use * /del /yes
This will delete all the connection to your windows system; means If you have already connected to some system with shared folders and provided log in and password. After using this command you need to type login and password again. One can disconnect specific connection using net use.
: net use will display all the connection list.

3. Today I learn about SDelete command. (works on Windows NT/2000's (Win2K) )
SDelete is a command line utility that takes a number of options. In any given use, it allows you to delete one or more files and/or directories, or to cleanse the free space on a logical disk. SDelete accepts wild card characters as part of the directory or file specifier.
usage is to securely delete existing files (replacement of delete). or in other words Delete Files Permanently from your Computer.
why use sdelete?
When you delete files or folders, the data is not initially removed from the hard disk. Instead, the space on the disk that was occupied by the deleted data is "deallocated." After it is deallocated, the space is available for use when new data is written to the disk. Until the space is overwritten, it is possible to recover the deleted data by using a low-level disk editor or data-recovery software.
To view help at the command-line, at the command prompt, type the following:
CommandName /?

Tuesday, December 16, 2008

dda housing scheme 2008 results at www.dda.org.in

Housing Scheme 08 — the Delhi Development Authority’s latest offering of affordable houses for citizens. The much-awaited draw of lots to the Delhi Development Authority (DDA) Housing Scheme 2008 – under which 5,010 flats are up for sale.
The DDA will, however, upload the list of successful allottees on its website www.dda.org.in by 3 p.m. To view your Registration/Allotment/Application Status please:
1. Select Scheme, either enter Registration/Application No. or Priority No., and select Flat category. Scheme:
Of the 12.64 lakh application forms which were sold, 5,60,000 forms were found eligible for inclusion in the lottery by DDA.
The list will also appear in all national newspapers on Wednesday,” said Dhar.
ALLOTMENTS TO CTRL GOV PSU, AMBEDKAR AWAS YOJNA, CGHS, DDA HOUSING SCHEME 2006, DDA HOUSING SCHEME 2008, DWARKA HIG HOUSING SCHEME 2003 ...
www.dda.org.in
direct link is dda.org.in/housing/results/reg_results.asp
dda, dda housing scheme 2008, dda delhi, dda website, dda results

dda, www.dda.org.in, dda draw result, urbanindia.nic.in, dda draw 2008
DDA had launched the Housing Scheme on August 6 this year.
reports hindustan times. dda, dda housing scheme 2008, dda.org.in, dda.org, www.dda.com
delhi development authority, dda housing scheme 2008, dda delhi, dda draw, dda housing scheme 2008 results.
site is coming slow have patience. Draw Results

Monday, December 15, 2008

Calling User Space Program From Kernel Space

Invoking user mode application from kernel modules, yes its possible with help of CALL_USERMODEHELPER.
With the following kernel API, we can invoke user mode application from Kernel modules/threads.


int call_usermodehelper (char * path, char ** argv, char ** envp, int wait);

path: pathname for the application.
argv: null-terminated argument list.
envp: null-terminated environment list.
wait: wait for application to finish and return status.


Example:

Kernel Module:
#include
#include

char name[]="user_program";

static int init_function(void)
{
int ret;
char *argv[] = {name, "hello", "world", NULL };
static char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL };

printk("We r in init_function\n");


ret= call_usermodehelper(name, argv, envp, 1);
if ( ret <>
#include
int main(int argc,char *argv[],char *envp[])
{
int i=0,fd;

fd=open("/dev/ttyMCS",O_WRONLY);
if( fd <>

Sunday, December 14, 2008

Ruby.rewrite Ruby Fringe talk by Braithwaite

Ruby.rewrite(Ruby).In this RubyFringe talk, Reginald Braithwaite shows how to write Ruby that reads, writes, and rewrites Ruby. The demos include extending the Ruby language with conditional expressions, new forms of evaluation such as call-by-name and call-by-need, and more.
RubyFringe is an avant-garde conference for developers that are excited about emerging Ruby projects and technologies. They're mounting a unique and eccentric gathering of the people and projects that are driving things forward in our community.
about Author
Reginald Braithwaite was the tech lead on the team that created JProbe Threadalyzer, a tool that did automatic detection of potential threading-related bugs.
check out the presentation here.
Ruby.rewrite(Ruby).001.png by raganwald

Friday, December 12, 2008

The 10 Most Puzzling Ancient Artifacts

What are we to make of these finds? There are several possibilities:

* Intelligent humans date back much, much further than we realize.
* Other intelligent beings and civilizations existed on earth far beyond our recorded history.
* Our dating methods are completely inaccurate, and that stone, coal and fossils form much more rapidly than we now estimate.

In any case, these examples - and there are many more - should prompt any curious and open-minded scientist to reexamine and rethink the true history of life on earth.
clipped from www.ancientx.com
There is a great deal of archeological evidence that the history of life on earth might be far different than what current geological and anthropological texts tell us.
Could it be, however, that conventional science is just as mistaken as the Bible stories?
Consider these astonishing finds:
The Grooved Spheres
Over the last few decades, miners in South Africa have been digging up mysterious metal spheres.
The kicker is that the rock in which they where found is Precambrian - and dated to 2.8 billion years old!
The Dropa Stones
The spiral groove, it turns out, is actually composed of tiny hieroglyphics that tell the incredible story of spaceships from some distant world that crash-landed in the mountains.
The Ica Stones
The most astonishing etchings, however, clearly represent dinosaurs - brontosaurs, triceratops (see photo), stegosaurus and pterosaurs.
The Antikythera Mechanism
The Baghdad Battery
The Coso Artifact
Ancient Model Aircraft
Giant Stone Balls of Costa Rica
Impossible Fossils
 blog it

Nanotechnology vs. God

A team of American and Singaporean scientists conducted a survey of attitudes towards nanotechnology, and found that the more religious the community, the more they opposed the science of nanotechnology
clipped from www.dailygalaxy.com
Nanotechnology_main
The U.S. is experiencing an apocalyptic showdown even as we speak.  In one corner we have nanotechnology, which could potentially end the world through rogue replication or uncontrolled alteration.  In the other we have God, who has - and this according to his fans, remember - killed almost everything on Earth at least once and will do so again the very instant he decides he wants to, under the euphemistic name of "Rapture".  The public is the referee and, amazingly, they're on the "I drowned all but one family of you people once" guy's side.
A team of American and Singaporean scientists conducted a survey of
attitudes towards nanotechnology, and found that the more religious the
community, the more they opposed the science of nanotechnology
Making societal technology
choices based on religion is like altering the economy based on a
knowledge of macramé: it might be something you care about in your
daily life, but that doesn't make it valid for everyone else.
 blog it

Monday, December 1, 2008

Taking A Shower Improves Moral Judgment

The research was conducted through two experiments with university students. In the first, they were asked to complete a scrambled sentence task involving 40 sets of four words each. By underlining any three words, a sentence could be formed. For the neutral condition, the task contained 40 sets of neutral words, but for the cleanliness condition, half of the sets contained words such as ‘pure, washed, clean, immaculate, and pristine’. The participants were then asked to rate a series of moral dilemmas including keeping money found inside a wallet, putting false information on a resume and killing a terminally ill plane crash survivor in order to avoid starvation.

The second experiment saw the students watch a ‘disgusting’ film clip before rating the same moral dilemmas. However, half the group were asked to first wash their hands.

The next time you have to make a difficult moral decision, you might think twice about mulling it over in the bath or shower.
New research in Psychological Science has found that the physical notion of cleanliness significantly reduces the severity of moral judgments showing that intuition, rather than deliberate reasoning, can influence our perception of what is right and wrong.
“When we exercise moral judgment, we believe we are making a conscious, rational decision, but this research shows that we are subconsciously influenced by how clean or ‘pure’ we feel.
“Take for example the situation of a jury member or voting in an election - if the jury member had washes their hands prior to delivering their verdict, they may judge the crime less harshly.”
Similarly, someone may find it easier to overlook a political misdemeanor had they performed an action that made them feel ‘clean’ prior to casting their vote.”
 blog it

Tuesday, November 25, 2008

Best Buy black friday ads 2009 slick deals Released

Check out information on black friday ads,
Best Buy black friday ads 2009 slick deals Released target, best buy black friday ads, walmart black friday ads, best buy deals


Best Buy From target.com black friday ads

Target.com Home Page
Target.com
Target
Target Black Friday ad listing for 2008 at BlackFriday.info along with the Target.com Black Friday, and online coupons.


Best Buy Black Friday 2008 From Sears Circuit City and Wal-Mart

1. How to start making out of best deals and best buy?
2. Why slickDeals is favorite?
They have created a Excel spreadsheet to get idea and quick overview of items and prices. No need to scan through tons of color ad pages.
and Kmart, Target, Meijer, and a few others will be opening at 6:00am.
Check out some of best deals for 2009 black friday.
Laptops
HDTV
Best Buy
Blu-ray from Circuit City titles for $8.99, $11.99, and $17.99.
Blu-rays, DVDs, and CDs
www.theblackfriday.com black friday ads, walmart black friday ads, target black friday ads, shopko black friday ads, sears black friday ads
 blog it

SATA disk is Not Detecting While Linux bootup

Did you experience below kind of error anytime with SATA disk,

PCI: enabling device 0000:00:01.0 (0140 -> 0143)
ata1: SATA max UDMA/100 cmd 0xC2852080 ctl 0xC285208A bmdma 0xC2852000 irq 22
ata2: SATA max UDMA/100 cmd 0xC28520C0 ctl 0xC28520CA bmdma 0xC2852008 irq 22
ata1 is slow to respond, please be patient

after waiting you get
ata1: no device found (phy stat 00000000)
scsi0 : sata_sil

and at last
ata2 failed to respond (30 secs)

And you know how simple answer is for this.
Yes only thing is knowing is the key.

The answer lies in power source connector; SATA disks are very sensitive to power source, so if you see such errors coming while bootup and your SATA disk is not getting detected then press the power connector, And your are saved. This is my experience after struggling for an hour with changing SATA disk and changing SMPS, changing target board, but nothing worked; finally press hold on power connector to SATA disk and done. bbuuuurrr..

Sunday, November 23, 2008

what does /dev/null 2>&1 command do?

what does /dev/null 2>&1 command do ?
or
What does > /dev/null 2>&1″ mean?
I was running some CGI for disk formatting and during this process some warning messages were coming on screen; even though I was duplicating standard out file pointer to some temporary file pointer. It was not redirecting standard error messages to this temporary file. Searched on google, but was not able to hit google with right keyword. Got this answer of using /dev/null 2>&1.
Here is explanation,

In Linux There are three standard file descriptors, Standard In (STDIN, file descriptor 0), Standard Output (STDOUT, file descriptor 1) and Standard Error (STDERR, file descriptor 2). /dev/null is the null device, which is like "write only memory". > will write to the specified file (overwriting its contents) and >> will append to the specified file.

> /dev/null 2>&1 redirect both output and error to /dev/null
> /file 2>&1 redirect both output and error to /file

Explanation:
> redirects output to /dev/null
2>&1 redirect error to where > is redirected
So error also gets redirected to /dev/null

“> /dev/null” will redirect STDOUT to a BLACK HOLE

“2 > &1” will redirect STDERR to STDOUT which in turn is redirected to a BLACK HOLE

Friday, November 21, 2008

Use of CUT Grep AWK Linux Command Combinations

Today I learn about power usage of grep cut and awk command;
My requirement was to know on which physical USB port which device is connected,
I can get this information from /proc/bus/usb/devices; which tells me about on which port which device is connected; my udev script will automatically mount the USB device with combination of Manufacturer name and serial number;
Here is the steps how I reached to simple solution instead of coding hundred lines of code.

To search for the SerialNumber in proc file i used
$ grep 'SerialNumber' /proc/bus/usb/devices

was giving me output in "S: SerialNumber=LDVTCGP6" format, I don't need that S: so used pipe;
$ grep 'SerialNumber' /proc/bus/usb/devices | awk '{print $2}'

This removes initial "S:" The output is combination of SerialNumber=LDVTCGP6 lines;
I need to separate each strings with individual values; use cut command from linux.
$ grep 'SerialNumber' /proc/bus/usb/devices | awk '{print $2}' | cut -d= -f2

This gives me "LDVTCGP6" as serial number; I need only for two ports so use tail command.
$ grep 'SerialNumber' /proc/bus/usb/devices | awk '{print $2}' | cut -d= -f2 | tail -2

This gives me only last two values; redirect this to some file like
$ grep 'SerialNumber' /proc/bus/usb/devices | awk '{print $2}' | cut -d= -f2 | tail -2 > /var/usb_port

This file contains now serialnumbers of usb device connected now for same way append values for port in same file;
$ grep 'Port' /proc/bus/usb/devices | awk '{print $5}' | cut -d= -f2 | tail -2 >> /var/usb_port

This way I got serialnumbers and physical ports connected values in one file now I can open this file and manipulate to meet my requirements.
Life is easy with cut,grep and awk commands in linux.

Some more examples to work out.
To print only the second and third lines of a file:
head -3 some.file | tail -2

Cut Command
------------
Divide a file into several parts (columns)
syntax:
cut [-b] [-c] [-f] list [-n] [-d delim] [-s] [file]
You have a file test.txt which has colon(:) seperated data

406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed

If you want to print first set of data from each row, you can use cut command as follow:

cut -d":" -f1 test.txt

Thursday, November 20, 2008

It's a Bigger World than Java and C++

We hear a lot about Java and C++, but that doesn't mean they're the only languages developers are using.
Tokeneer was developed for the U.S. National Security Agency (NSA), an outfit known for keeping things secret. Which makes it even more surprising that not only did the NSA acknowledge Tokeneer's existence, but they released it as open source software.
In a nutshell, Tokeneer is a proof-of-concept of what's called "high-assurance software engineering." Secure software, in other words. Software you can trust. Software that must work correctly or else the consequences could be calamitous. And software that's written in Ada—yes, Ada—and developed using Praxis High Integrity Systems (www.praxis-his.com) Correctness-by-Construction (CbyC) methodology, the SPARK Ada language (www.sparkada.com), and AdaCore's GNAT Pro environment (www.adacore.com). The project demonstrates how to meet or exceed all those things that are necessary to achieve high assurance, such as Evaluation Assurance Level 5 in the Common Criteria (whatever that is). All in all, Tokeneer was created in just 260-person days, and implemented in about 10,000 lines of code. Originally a subset of the Ada language, SPARK Ada is designed in such a way that all SPARK programs are legal Ada programs.
No less than Tony Hoare, Fellow of the Royal Society of Microsoft Research, says that "the Tokeneer project is a milestone in the transfer of program verification technology into industrial application. Publication of the full documents for the project has provided unprecedented experimental material for yet further development of the technology by pure academic research. It will serve as a touchstone to chart and measure progress of the basic science of programming, on which the technology is based." Tokeneer is aimed at both the industrial and academic communities, forming an base for research in program verification and as a high-level teaching aid for educators. You can download the entire Tokeneer project, including requirements, security target, specifications, designs, source code, and proofs at www.adacore.com/home/gnatpro/tokeneer/.
Jonathan Erickson
Editor-in-Chief
jerickson@ddj.com
Read more on:
www.adacore.com/home/gnatpro/tokeneer/.
IntellaSys (www.intellasys.net) ,www.python.org,

Wednesday, November 19, 2008

Refresh HTML Page Every 5 Seconds Usages META tag

How to Refresh HTML/CGI page every 5 seconds?
Today I was searching for page refresh after a certain activity is completed. I was running some task in say CGI 1; which uses fork() to execute another task; once this task is done CGI 1 should get refreshed or should show me the updated status which is being updated by new task.
I tried lot of other combination like calling refresh function from new task; with window.opener.refresh_fucntion(); and a lot.
Finally got the solution using meta tag of html.

Meta HTML tag,The element provides meta-information about your page
And the answer to question is just include before head element this tag;
Refresh page every 5 seconds:






Refresh page every 5 seconds:

<meta http-equiv="refresh" content="5" />
and my job is done.
Thanks to meta tag.

Tuesday, November 18, 2008

C Programming Caution while using execlp function

What is C Programming Caution while using execlp function?

programming caution while using execl function series. execlp function series most of the time are used with fork() system call;
If the requirement is there to kill the process started by execl function, then one caution need to take care, as execl functions will replace complete child process image with the new process image, This means new process started is having new pid and not as same as child pid.
In order to kill the process we need to call getpid function in calling function and store this pid in temp file and while killing this new process use
kill(pid) system call.

Example usage assuming in pid is stored in /var/childpid.

fptr = fopen("/var/childpid","r");
if(fptr != NULL)
fgets(child_pid,10,fptr);
else
printf("Can't open childpid file");
close(fptr);
child_pid[strlen(child_pid)-1] = '\0';

sprintf(cmd,"kill %s >/var/done",child_pid);
system(cmd);

Monday, November 17, 2008

How to Check Directory Size In Linux Also lists file size

How to check directory size in linux?
du is the answer.
du - estimate file space usage
Summarize disk usage of each FILE, recursively for directories.
useful options are
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize
display only a total for each argument
To check the directory size use $ du -hs
this will give current working directory size if specified gives specific directory size ie
$du -hs /home/bhagwat/test/dir
gives size of /dir.

while df is also there but it gives disk space not directory space
df - report filesystem disk space usage
df displays the amount of disk space
available on the filesystem containing each file name argument. If no file name is given,
the space available on all currently mounted filesystems is shown.

Sunday, November 16, 2008

Use of Execlp Functions C program Explained

Below code listing illustrates usage of execl function series, and talks about how to redirect the output from these functions.
Here is trick to redirect the output from execlp command series
In other words implematiation of "ls -l >/var/test.log"
first open file using "open" system call

#include
#include
#include

int open(const char *pathname, int flags);

then duplicate this file pointer with stdio file pointers
stdio file pointer are 0 for stdin
1 for stdout and 2 for stderr

use of dup2

dup and dup2 create a copy of the file descriptor oldfd.
int dup2(int oldfd, int newfd);


here is c example implementation in function;

int spawn(char* cmd)
{
pid_t child_pid;
int fptr,fptr2;
char tmp_devfs[20];
int child_status=-1,ret=-1;

// printf("executing cmd=%s\n",cmd);
fptr=open("/var/test.log",O_RDWR);
/*create new process */
child_pid = fork();
if (child_pid != 0){
/* This is the parent process. */
ret = child_pid;
//printf("c_pid=%d",child_pid);
}
else
{
/*Here is trick to direct or redirect the output to execlp*/
dup2(fptr,1);
close(fptr);
execl("/bin/sh","sh","-c",cmd,(char*)NULL);
/* The execl function returns only if an error occurs. */
fprintf (stderr, "an error occurred in execl sfdisk\n.");
exit -1;
}
//printf("done with cmd=%s child ret=%d\n",cmd,ret);

return ret;
}

The child process starts executing in another shell replacing the current process image or child;
parent process continues to execute.

if one has to wait for child to finish one can make use of wait() functions;

wait(&child_status);
if (WIFEXITED (child_status))
ret = WEXITSTATUS (child_status);
else
ret = -1;

Add this code before return statement.
In a simillar way if one needs to read input from file while using exece series function open that file in read mode and duplicate the file descriptor with stdin file descriptor.
ie simply change

dup2(fptr,0);
close(fptr);

Related questions:
use the execlp command in my C program to run the PS command and send the output into a file specified in the Argument.
Man pages for fork, open, exec and wait function.
man page for open
The fork system call creates a new child process.
The exec functions (there are more than one) are a family of functions that execute some program within the current process space.
The two versions of exec that we will be using are execlp and execvp. The difference is in the way they accept arguments, however both of them are typically called the same way.
The wait function is in and it’s a special function that allows a parent process to wait for its child processes to exit.

Thursday, November 13, 2008

Why We Need to Call a Pig a Pig - The politics of language ..

We know Orwell for his novels, but it's the way he saw the politics of language that makes him relevant.
clipped from www.newsweek.com

Why We Need to Call a Pig a Pig (With Or Without Lipstick)

We know Orwell for his novels, but it's the way he saw the politics of language that makes him relevant.

clipped from www.newsweek.com

Though many of Orwell's essays describe single incidents, his concerns are political, in the largest sense: the way human dignity is corrupted by false phrases. He was less interested in what motivates people to act without integrity than in the words they use to camouflage and perpetuate their dishonesty: for Orwell, bad language and bad politics were one and the same. Yet for all his penury and despair, his faith in the power of clear, strong language can only be read as optimistic.

Orwell's ideas have been bastardized and simplified over time, so that "Big Brother," the totalitarian, state-run citizen-control mechanism of "1984," is now the name of a reality-TV show that bears little resemblance to the book, except for the fact that contestants are watched by cameras
 blog it

Stupid Products

Consumers MUST BE SATISFIED!
clipped from www.guidespot.com

Inflatable Toast

Widget_cvap_rjbbbfqdarhfizxdt

The Goatee Saver

Widget_beie-hph5g5rdaev8v9dpr

Taco Propers

Widget_cpcckmqgfjhjdjos9dchms

Sci Fi Themed Condoms

Widget_cv-ch5pexphbwssdx9qxvi

Handsets for cell phones

Widget_aekst-_9vn84adzwqo_s-m

Cassette Tape Dispenser

Widget_byl2hi9alalkdxsx55tjcx

Day-Glo Camouflage

Widget_bcsbfpymtprjai6l7ybssr

Zaky Infant Pillow

Widget_bizgxqhs1nnof7mg_dmlsx

Two-da-loo Tandom Toilet

Widget_d8bdxeljpic7ulyj8artbq

CLEAN-UP SLIPPERS

Widget_b0mzil4crna5pyxwocwxa6

Hair Guard for Noodle Eating

Widget_cxw0uhz0nl8qvz1_0d8rh-

DVD Rewinder

Widget_ba5rpld3rlj4ubtsbyvlyg

Noodle Cooling Fan

Widget_cz0r08s2xcli5k6a579wfi

Umbrella Shoes

Widget_csuahucxdpxlivtsywnnfj
 blog it

Wednesday, November 12, 2008

Get Mounted File System Type C function

How to get Mounted file system type using C program?
Here is trick to get mounted file system type or say this trick can be applied to get variable from linux; This is simple combination of "grep" and "awk" commands. check out below; this function takes mounted point name like where you have mounted the disk example
/dev/sda1 is being mounted at /mnt/test so the input argument to this function is test and the output should get is /dev/sda1 filesytem type.
If you type mount command you will get the file type

on my system with one pen drive; it shows
dev/sda1 on /mnt/JetFlash type ext3 (rw)
input to this function is JetFlash and I will get return as ext3 which is file system type.
Description          : returns mounted FS type
char *get_fs_type(char *mount_point_name)
{
char temp[20];
char cmd[100],*ret_p;
FILE *fptr;


sprintf(cmd,"/sbin/fdisk -l | grep %s | awk '{print $6,$7}' > /var/mpt",mount_point_name);
system(cmd);

fptr = fopen("/var/mpt","r");
fgets(cmd,20,fptr);
fclose(fptr);
ret_p = (char*)malloc(strlen(cmd) + 1);
if(ret_p != NULL)
strcpy(ret_p,cmd);
else
strcpy(ret_p,"NULL");

return ret_p;
}



one word of caution
this function uses fgets to read from file; the returned output contains an appended new line character; so before using this returned output in other commands one must remove new line char using simple trick like;
temp_p[strlen(temp_p)-l] = '\0'

Tuesday, November 11, 2008

Scratchbox Cross-compiling Made Easy

Often Getting problems with corss compiling here is the perfect solution, read on.
Scratchbox is a configuration and compilation environment for building Linux software and entire Linux distributions.
The basic idea of Scratchbox is to offer developers an environment that works and looks like the target environment before the target environment is available.
The Scratchbox is an environment that you log into like you would log into some machine. However, the Scratchbox tools can be used either inside or outside of Scratchbox download
scratchbox-core
http://www.scratchbox.org/download/files/sbox-releases/1.0/tarball/scratchbox-core-1.0.1-i386.tar.gz
scratchbox-libs
http://www.scratchbox.org/download/files/sbox-releases/1.0/tarball/scratchbox-libs-1.0.1-i386.tar.gz
scratchbox-toolchain-arm-glibc
http://www.scratchbox.org/download/files/sbox-releases/1.0/tarball/scratchbox-toolchain-arm-gcc3.3-glibc2.3-1.0.1-i386.tar.gz
untar all tar ball using tar -xzf command
then run
$/scratchbox/run_me_first.sh

’run_me_first.sh’ asks you some questions, just use defaults. After this we need to add user for
Scratchbox. User must be some user that you have in your system.

Cross-compiling outside Scratchbox
$/scratchbox/compilers/arm-gcc-3.3.4-glibc-2.3.2/bin/arm-linux-gcc -Wall -o arm-hello hello.c

Cross-compiling in Scratchbox
Scratchbox is a chrooted cross-compilation environment. This means one has to log into the Scratchbox like one would log into a some real machine
You can log into the Scratchbox system with a command: ’/scratchbox/login’. You should get some welcome messages and your prompt should change to something like
’[sbox-HOST: ~] > ’..

The Scratchbox prompt ’[sbox-HOST: ~] > ’ tells you that you are in Scratchbox environment and that you are using target called HOST. In Scratchbox you can have multiple targets which means that you can compile programs for many different architectures and settings.
then create a target for our cross-compilation needs.

[sbox-HOST: ~] > sb-conf setup MYTARGET -c arm-gcc-3.3.4-glibc-2.3.2
-t qemu-arm
[sbox-HOST: ~] > sb-conf select MYTARGET
[sbox-MYTARGET: ~] >

Scratchbox comes with ARM emulator QEMU.

[sbox-MYTARGET: ~] > gcc -Wall -o sb-arm-hello hello.c
as we are inside the Scratchbox environment we can also run the program although it is an ARM
binary and we are on X86 machine. This was because we have the emulator:
[sbox-MYTARGET: ~] > ./sb-arm-hello
Hello World!


Scratchbox website (http://scratchbox.org/).
Installing Scratchbox (http://www.scratchbox.org/documentation/docbook/installdoc.html).
QEMU (http://fabrice.bellard.free.fr/qemu/).

Monday, November 10, 2008

fdisk Compilation for ARM-Target board Errors

Today Trying my luck with compiling fdisk utility;

Source code at:
http://www.gnu.org/software/fdisk

Current fdisk 1.0 is July 7 2007 370K source .tar.gz

./configure --disable-cfdisk --host=arm-linux --build=i686 --disable-largefile
./configure says to install GNU/Parted before compiling.
It needs parted/parted.h.


http://www.gnu.org/software/parted Latest version is 1.8.7 of May 2007.
1.4GB source code tar.gz.
./configure --host=arm-linux --build=i686
configure: error: GNU Parted requires libuuid - a part of the e2fsprogs package (but
GNU Parted requires libuuid - a part of the e2fsprogs package (but
sometimes distributed separately in uuid-devel or similar)
This can probably be found on your distribution's CD or FTP site or at:
http://web.mit.edu/tytso/www/linux/e2fsprogs.html
Note: if you are using pre compiled packages you will also need the development
package as well (which may be called e2fsprogs-devel or something similar).
If you compile e2fsprogs yourself then you need to do 'make install' and
'make install-libs'.

I got the e2fsprogs tools, still same error.
Well while doing this I discovered about an easy way of cross-compilation ie Scratchbox;
will post more about Scratchbox after I install and test it.

Thursday, November 6, 2008

Install NTFS read Write Support ntfsmount a big Bang

Today's leanings are
1. How to create NTFS partition from FAT32 filesystem?
Need to have windows XP or NT to run this command.
Created NTFS partition using command from cmd prompt; -
CONVERT F: /FS:NTFS

2. Major task was to enable NTFS Read/write support;
Started with enabling NTFS_RW in Linux kernel, its help says;
CONFIG_NTFS_RW:
This enables the partial, but safe, write support in the NTFS driver.
The only supported operation is overwriting existing files, without changing the file length. No file or directory creation, deletion or renaming is possible. Note only non-resident files can be written to so you may find that some very small files (<500 href="http://bhagwat-masalkar.blogspot.com/2008/10/about-ntfs-tools-and-library-ntfsprogs.html"> user level driver(requires FUSE) and kernel mode driver.

Started with kernel mode driver from ntfs-3g which uses mkedev function ref to our arm-tool chain in file /tools/arm-tools-3.3.1/tools.Linux/hard_fp/armv5-linux/sys-include/sys/stat.h which is not there in my arm-linux toolchain. bangg...

Now back to last option ie compile user level read-write module from
http://www.linux-ntfs.org/doku.php?id=ntfsmount.
with option
./configure --host=arm-linux --target=arm-linux --build=i686 --enable-ntfsmount PKG_CONFIG=/home/bhagwat/test_softwares/fuse-2.7.4/fuse.pc


and I am lost again with below error
checking pkg-config is at least version 0.9.0... ./configure: line 20202: /home/bhagwat/test_softwares/fuse-2.7.4/fuse.pc: Permission denied
no
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for LIBNTFS_GNOMEVFS... configure: WARNING: Linux-NTFS Gnome VFS module requires glib-2.0 and gnome-vfs-module-2.0 libraries.
checking for FUSE... configure: error: ntfsmount requires FUSE version >= 2.6.1.

Anyone have any IDEA.

Tuesday, November 4, 2008

UDEV Simple Rules For Events In Linux

How to execute external program upon certain events occurred in linux?
This is quite wide requirement if you are running embedded linux on target board. Well The answer could be varied as question is more general. Lets limit the scope of question to USB devices.
Running external programs upon certain events to be specific want to run a program on USB device connection and on USB device removal.
Well I am going to do it with UDEV,
For the beginners/novices about UDEV and howto write UDEV rules the howto is pretty nice and easy to apply. udev plus tux, from the udev page
One can do it with signals also, but I like this way. To start with,
I have written simple udev rules file and kept in /etc/udev/rules.d/90-local.rules (off course you can give any name but with ext .rules and start with some no like 90 here); My udev rules are in 50-udev.rules files which defines the way to mount on USB connection and unmount on USB device disconnect.
I can't believe myself that with simple two lines rule placed in 90-local.rules file my job is done;
Here is 90-local.rules file

KERNEL=="sd*[0-9]",ACTION=="add",RUN+="/usr/sbin/usb_detect"

KERNEL=="sd*[0-9]",ACTION=="remove",RUN+="/usr/sbin/usb_detect"

These two line says on connection of disconnection run the local file ie kept in /usr/sbin/.
You can write whatever you want in this exe; I am creating a default share on USB detection and making it to available for others to see the USB contents. On device removal I am deleting the shares.

The functionality introduced here allows you to run a program after the device node is put in place. This program can act on the device, however it must not run for any extended period of time, because udev is effectively paused while these programs are running. One workaround for this limitation is to make sure your program immediately detaches itself.

Here is an example rule which demonstrates the use of the RUN list assignment:

KERNEL=="sdb", RUN+="/usr/bin/my_program"
One observation if you enable printf inside your my_program you will not get the output on consol. Don't get panic, rather read the UDEV howto.

Monday, November 3, 2008

Palindrome Number Checking for Int C program Functions

Write a c program to know if given number is palindrome or not?
Well first try to digg out what is palindrome?
A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction. Palindrome example is TENT on either direction characters are same.
The most familiar palindromes, in English at least, are character-by-character: the written characters read the same backwards as forwards. Palindromes may consist of a single word (civic, level, racecar, rotator, Malayalam), or a phrase or sentence ("Was it a rat I saw?", "Wasilla: All I saw", "Mr. Owl ate my metal worm", "Sit on a potato pan, Otis", "Neil, a trap! Sid is part alien!", "Go hang a salami I'm a lasagna hog.", "Satan, oscillate my metallic sonatas", "I roamed under it as a tired nude Maori"). Punctuation, case and spacing are usually ignored, although some (such as "Rats live on no evil star") include the spacing.
That was about palindrome strings or char.
What is importance of palindrome number?

A palindromic number is a number where the digits, with decimal representation usually assumed, are the same read backwards, for example, 58285. They are studied in recreational mathematics where palindromic numbers with special properties are sought. A palindromic prime is a palindromic number that is a prime number.

Now time for C-code;
Its very easy for string or words to know if it is palindrome or not; like

#include
#include
#define size 26
int main(void)
{
char strsrc[size];
char strtmp[size];
printf("\n Enter String:= "); gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not palindrome",strsrc);
return 0;
}


here is simple program for int palindrome numbers

int main()
{
int i,j,k=0 ;

i = 122223;
printf("i=%d\n",i);
while( i>0 )
{
j = i % 10;
i = i/10;
k = k*10 + j ;
}
return 0;
}

One can customize this for checking given int is numbers are palindrome are not.