My words on free/open source software

Tuesday, October 20, 2009

Understanding how fontconfig scan conf files

I've been fixing fonts issues in Moblin for some time, and I've to admit that GNOME fontconfig is really hard to understand.

The rules in /etc/fonts/conf.d/ are scanned in alphanumeric order. After carefully read the fontconfig user's manual, I thought that if they were processed in alphanumeric order, the later conf should overwrite the earlier conf. WRONG! But rules scanned first take precedence over rules later. Let's see how they are applied to the Pattern.

For example: if you run `fc-match sans`, the Pattern here is family="sans".

Let's say we've a 01-rulefile:

After processing it the Pattern becomes:

family="DejaVu", "sans"

Then a 02-rulefile:

After it the Pattern becomes:

family="DejaVu", "Droid", "sans"

Noted that the "Droid" from 02-rulefile is prepended to "sans", not
the whole Pattern. So 01-rulefile takes precedence over 02-rulefile.

Tuesday, October 13, 2009

Zero Config! Huawei EC1260 / China Telecom CDMA2000 EVDO 3G USB Dongle on Debian Sid

I bought a Huawei EC1260 USB modem to access the CDMA2000 EVDO mobile broadband provided by China Telecom. To my big surprise, the USB modem works out-of-box on my Debian Sid. Plug the USB modem and click the CDMA item in my NetworkManager and Bingo! I'm online! This is really zero config!

Thank you, great developers of NetworkManager and Debian for making this great progress.

Sunday, March 15, 2009

Beijing Tax Declaration Website Supports Firefox, Great!

I'm glad to finish my tax declaration online by using Firefox running on Linux. Every function of Beijing Taxation Bureau's website works well with Firefox.

Though there are spaces for them to improve, such as adding HTTPS support.

Compiling GIMP 2.6.5 on CentOS 5

GIMP 2.6.5 is the fantastic tool for photographers that live in the free world. But sadly it has no official RPM built for CentOS/RHEL users. I have spent 4 hours and compiled GIMP 2.6.5 on CentOS 5 for Tina by using the official tarball.

I planned to use the GIMP SRPM from Fedora Rawhide (which was 2.6.5) but after Fedora 10 the Rawhide had moved to a new format of RPM and I have no way to install nor unpack those new SRPMs to get the code (neither on CentOS 5 or Debian Unstable). Therefore I had to fall back to use official tarball and install it to /opt. By this I lost the benefit of package management. So I have no RPM here to share with you but only a rough record of the steps:

  1. download, build and install babl 0.0.22

  2. download, build and install gegl 0.0.22

  3. install intltool RPM from Fedora 10

  4. download gettext SRPM (gettext-0.17-8.fc10.src.rpm) from Fedora 10 and rpmbuild it (with Java disabled). the GCJ shipped with CentOS 5 couldn't compile the Java code within gettext so they had to be disabled by the patch following.

  5. build GIMP 2.6.5

The patch to disable Java of gettext:

--- /usr/src/redhat/SPECS/gettext.spec 2008-08-29 09:07:58.000000000 +0800
+++ gettext-for-el5.spec 2009-03-15 11:06:11.000000000 +0800
@@ -1,5 +1,5 @@
# libintl.jar requires gcj >= 4.3 to build
-%define buildjar 1
+%define buildjar 0

Summary: GNU libraries and utilities for producing multi-lingual messages
Name: gettext
@@ -86,12 +86,12 @@
export JAR=fastjar
%configure --without-included-gettext --enable-nls --disable-static \
- --enable-shared --with-pic-=yes --disable-csharp --enable-java \
+ --enable-shared --with-pic-=yes --disable-csharp --disable-java \
make %{?_smp_mflags} GCJFLAGS="-findirect-dispatch"

# For generating gettext-tools/src/gnu.gettext.*
-make -C gettext-tools/src gnu.gettext.DumpResource
+#make -C gettext-tools/src gnu.gettext.DumpResource

@@ -215,7 +215,7 @@
-%exclude %{_libdir}/%{name}/gnu.gettext.*
+#%exclude %{_libdir}/%{name}/gnu.gettext.*
%dir %{_datadir}/%{name}
@@ -244,8 +244,8 @@
-%doc gettext-runtime/intl-java/javadoc*
+#%doc gettext-runtime/intl-java/javadoc*

%files libs

Wednesday, February 04, 2009

Another GPL violation case from top China IT firm? Hanwang this time.

Hanwang's eBook Reader products (汉王电纸书产品系列, are very popular in China market. They features an ARM processor and are running Linux with cramfs, which can be easily discovered from the update firmware the company has released. Also they are shipping BusyBox within them.

By no means I can find the source code to their Linux kernel / BusyBox. So perhaps this is yet another GPL violation case from top China IT firm. Anyone bother a law suit?

Saturday, January 03, 2009

Safely remove an USB hard drive in Linux

I bought a new USB hard drive, Western Digital My Book® Essential Edition™ 1TB, and use it with Linux. Here I'm discussing about how to safely remove (then disconnect) it from a Linux system.

The problem: according to its user manual, you should disconnect the drive safely when it is not active, but in a Linux system how to do this is not very straightforward. You may notice that after you unmount it (whether through command-line or a desktop environment), the drive is still spinning and it's LED on. If you read it's user manual carefully you'll find that the manufacturer never said it's safe to disconnect it from your system in such condition.

The quick solution to this problem:

  1. send SYNC, then STOP command to the device, this can be done easily in Linux by unbinding the device

  2. suspend the USB port by echoing a "suspend" to the "/sys/bus/usb/devices/$DEVICE/power/level", where $DEVICE corresponding to the device of your USB device.

To put it simple, I wrote a script to do this for you. Download and try it. For developers, you can get it from the github repo.

If you saw an error message like this when running it:
bash: /sys/bus/usb/devices/5-8/power/level: No such file or directory

that means your kernel doesn't support USB suspend. You can just disconnect your device now, it's already safer enough to unplug it.

To those who is interested, discussion of technical detail following.

From the hardware aspect, the drive should only be removed when the following requirements are met:

  1. there's no pending I/O request and software cache flushed

  2. it's hardware cache flushed

  3. it's driver spins down (means "not spinning")

  4. (optional) the USB port is put into "suspend" mode

The user's manual read (page 6, section "Turning Off/Disconnecting the Device"): "(for Windows systems): Right-click the Safely Remove Hardware icon in your system tray and select Safely Remove Hardware. You may hear the drive power down before the Power LED turns off. The drive is now shut down properly, and you may disconnect the drive safely. (for Macintosh systems) Drag the My Book icon to the Trash icon for proper dismount. You may hear the drive power down as the Power LED flashes. When the Power LED is steady, you may press the Power button once or disconnect the drive’s power cord to turn off the drive safely." (there's a mistake, this device doesn't have a Power button) If you read carefully you can tell that Windows and Macintosh don't do the same things when told to remove an USB device. As the bold text as shown, in a Windows system it will be turned off while in a Macintosh system you hear the drive power down but the Power LED would finally become steady rather than off. Therefore we know that Windows does all 4 steps and Macintosh do the first 3 steps only when told to remove a USB device. (BTW, it's funny that you have to use your ear before disconnecting a device.)

(This is only the case for Windows XP. For Windows Vista seems only the first 3 steps are done thus the drive remained active after you removing it from the system.)

Some may argue that they always disconnect their drives directly after unmounting (step 1 only) and never experience any damage, but as an operating system developer and a serious user, I always follow the manufacturer's manual or specification whenever it make sense and possible because I know electronic devices are fragile, rigid and obtuse if you don't use them as the way they are designed. For a well-designed and robust piece of hardware, theoretically you can disconnect the device safely when the first two steps are done. The firmware on the device would notice the USB cable was unplugged and shut down the disk drive properly. If not, the drive would be stopped sharply as if you pulled it's power when it's running and this damages the hardware gradually. As an outsider of the manufacturer, we hardly know whether it's well-designed or not so the only safe principle is to follow it's manual, means we should not disconnect the device until at least all three steps are done.

At the Linux kernel part. To finish all the 4 steps, you have to unmount the device, unbind the device from the driver, then tell the USB core driver to put that device into suspend mode, as shown in the solution above. And you have to be running a kernel with CONFIG_USB_SUSPEND enabled.

CONFIG_USB_SUSPEND is not enabled by default in a vanilla kernel. I'm pushing it in this discussion.

Properly removing a device from a running Linux should be done by either the HAL or desktop manager. If you can, please push the developers you know working on any DM that missing this feature to implement this function properly.

Try my script, and write me if you found a problem. Welcome patches.

About Me

My photo
Santa Cruz, California, United States