Sunday, 30 March 2008

GNU/Linux SYSTEM DIRECTORIES and their FILESYSTEMS

Executing $ ls / lists the top level of the root filesystem tree. There appear directories like:
/dev, /etc, /proc, /sys, /var, /tmp and others.

In this article we are going to deal with directories that have special filesystems associated with them.


For a general view of the filesystem hierarchy we can visit the Filesystem Hierarchy Standard page.

FHS standard is a set of guidelines about where to place files and directories within UNIX based operating systems.


Check which filesystems are mounted


Two commands allow us to examine which filesystems and where are currently mounted in our system.

$ mount
or
$ cat /etc/mtab


Their response will be something like that:
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.22-14-generic/volatile type tmpfs (rw)
securityfs on /sys/kernel/security type securityfs (rw)


We are specially interested in /proc, /sys, /var/run, /var/lock, /dev, /dev/shm, /dev/pts, /sys/kernel/security




/proc directory

Wednesday, 26 March 2008

Reverse Engineering Python Code with PyNSource

PyNSource is a tool that allow us to obtain UML diagrams from python source code.

PyNSource Web Page


INSTALLING PyNSource ON AN UBUNTU GUTSY SYSTEM.

NOTE: You must have python already installed in your system. I assume 2.5 version.

$mkdir PyNSource
$cd PyNSource


Now we download the program and install it:
$wget http://www.atug.com/downloads/pynsource1.4c.zip
$unzip pynsource1.4c.zip
$sudo python setup.py install


We want to run the GUI so we need a graphical library:
$sudo aptitude install python2.5-wxgtk2.6

Current code does not work with version wxgtk2.6 so we need to update it:
$wget http://www.atug.com/andypatterns/code/pyNsourceGui1.4c-wx26.zip
$unzip pyNsourceGui1.4c-wx26.zip
$sudo cp pyNsourceGui-wx26.py /usr/lib/python2.5/site-packages/pynsource/


Finally we exec the GUI module
$python /usr/lib/python2.5/site-packages/pynsource/pyNsourceGui-wx26.py


This application presents some annoying bugs:

* There are problems when moving shapes on the screen. It does not refresh correctly.
* It is difficult to adjust page size when you try to print it.
* When you press right click button on the mouse to delete an object, usually it doesn't delete all the arrows that point to it, messing the schema.
* Saving and opening diagram feature is not implemented yet, so you cannot save temporary work.


Well, you know, this bugs are annoying, but it you dont like them, it is free software, so hack the code. :-)

Friday, 14 March 2008

GNU Readline Library Short Description

GNU Readline is a software library that provides a set of functions that allow users to edit command lines as they are typed in.

Every program that uses this library provides the same user command line interface improving consistency between applications.

It is part of the GNU Project and it is licensed under the GPL.

Current version is 5.2 and it is used in projects like bash.

There are two editing modes available: Emacs (default) and Vi

Readline library includes additional functions to maintain a list of previously-entered command lines.
Exec this command to obtain more info about this feature:
$help history


INSTALLATION

In Debian and Ubuntu this library is packed in readline-common package.
$sudo aptitude install readline-common

Once installed, you can access a complete documentation using info command:
$info rluserman


SHORT KEYSTROKE REMINDER

NOTATION:
C-k means while ctrl key is mantained pressed, depress 'k' key.
M-k means while "meta" key is pressed, depress 'k' key.

Usually "meta" refers to ALT key, but if you have no meta key you can use ESC key instead.


Emacs mode commmands:

Movement

C-b Move back the cursor one character.
C-f Move one character forward.
DEL or Backspace Delete the character placed left at the cursor.
C-d Delete the character underneath the cursor.
C-_ or C-x C-u Undo the last editing command.

C-a Move to the beginning of the line.
C-e Move to the end of the line.
M-f Move forward a word.
M-b Move backward a word.
C-l Clear the screen, reprinting the current line at the top.

Killing and yanking (cutting and pasting) commands

C-k Kill the text from the current cursor position to the end of the line.
M-d Kill from the cursor to the end of the current word.
M-DEL Kill from the cursor the start of the current word.
C-w Kill from the cursor to the previous whitespace.

After killing(cutting) text, we yank(paste) it back into the line.

C-y Yank the most recently killed text back into the buffer at the cursor.
M-y Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or M-y.

Searching commands

C-r Searchs backwards on the previous commands you typed.
C-s Perform a forward search from the command line history you are now.

Passing arguments to a command

e.g: M-2 3 C-d means delete next 23 characters on input line.



CONFIGURING THE LIBRARY

GNU Readline keybindings and more can be changed editing ~/.initrc or /etc/initrc files.


URLs
GNU Readline Official page
GNU Readline (Wikipedia)
Official online Readline documentation