Matteo Mattei

Hello, my name is Matteo Mattei and this is my personal website. I am computer engineer with a long experience in Linux system administration and web software development.

linkedin rss twitter google+ github facebook

Extract u-boot multi-file image in Python

This simple piece of code shows how to extract/decompress a u-boot multi-file image created with mkimage using Python. The image format is very simple:

64 bytes of image header.
4 bytes for the size of first image.
4 bytes for the size of second image.
...
4 bytes of zeros for termination.
image1.
image2.
...

You need to remember also that each image is padded to 4 bytes.


PySide Signals and Slots with QThread example

In these days I started studying PySide. After some days spent in reading lot of stuff, I thought that a real example could be useful for who intends to start learning PySide as well. In this example I can show you how you can implement a custom signal (MySignal) together with the usage of threads with QThread.

The following code creates a window with two buttons: the first starts and stop a thread (MyThread) that runs a batch that prints a point in the stdout every seconds continuously. The second button lets you only start another thread (MyLongThread) that prints an asterisk in the stdout every second for 10 seconds.

This example uses the api version 2 (introduced with PyQt 4.5) to connect signals to slots.

For more information you can look at:


Export MySQL table in CSV format using PHP

The following PHP code is intended to be used to export a MySQL table in CSV format in order to be used with MS Excel.


How to execute commands with specific user privilege in C and Python under Linux

If you have root access but you need to run some applications/scripts with some other user credentials you can do it with

su - username -c "command to execute"

But if you need to do it within a C/C++ program you need to write something like this:

This is how to compile and execute the above code:

[root@barracuda ~]# gcc mysu.c -o mysu
[root@barracuda ~]# id
uid=0(root) gid=0(root) gruppi=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),19(log)
[root@barracuda ~]# ./mysu matteo /bin/bash
[matteo@barracuda /root]$ id
uid=1000(matteo) gid=100(users) groups=100(users),3(sys),10(wheel),14(uucp),91(video),92(audio),93(optical),95(storage),96(scanner),97(camera),98(power),108(vboxusers)

The same result could be obtained also in Python with a very little effort:


How to really erase an Hard Drive

Since a REALLY secure Hard Disk erase procedure does not exist, the only way to clean every private data from a storage device is to use a powerful tool. Today we experimented the secure data cleaning on a 2.5” HD with an hammer. Yes, you have understood, an HAMMER!!! What’s more powerful than an hammer?!

This is the result of our experiment:

Broken HD

Any further feedback is really appreciated!


Shrink Ext4 partition on VMware player

VMWARE Few days ago I spent some times trying to shrink my Ubuntu 11.04 appliance with root partition formatted with EXT4 filesystem.

The main problem is that the current VMware tools (8.4.6, build-385536) does not support the ext4 shrink. If you run sudo vmware-toolbox, your root partition is formatted in ext4 and you try to execute the shrink, an error message like the following could appear.

VMWARE SHRINK ERROR

Anyway there is a trick to streamline the final vmdk size. Run this command within a shell into the guest system:

sudo dd if=/dev/zero of=/zero.raw bs=20480
rm -f /zero.raw

Then, shutdown the virtual image and download the vdiskmanager tool from VMware website.

Now run the vmware-vdiskmanager with the -k parameter:

vmware-diskmanager -k /path/to/image.vmdk

This operation will take a while, but at the end you will get a considerable smaller vmdk image file.