Archives: August 2014

GNU/Linux: read-only file system error when accessing FAT/FAT32 drive

Sometimes and for no obvious reason, I suddenly cannot write or delete a file located on a removable USB drive using a FAT file system. Having no knowledge about all the magic going on under file system operations, I can just observe that some actions previously done successfully on some drives are no longer possible!

$ rm -r /path/to/some/obsolete/data/*
rm: cannot remove '/path/to/some/obsolete/data/data1': Read-only file system

It happened a few times in the previous years and I think it always involved FAT, but this is maybe not limited to that file system. We can easily solve this issue by running fsck, in this case in the form of its vfat variant:

$ sudo fsck.vfat -a /dev/sdc1

Replace /dev/sdc1 with your rebellious partition. The -a flag tells fsck to automatically repair the file system. The man page warns to use this feature with caution. You may prefer the -r flag which makes fsck asking you confirmation.

Note that fsck comes with lot of flavors, such as fsck.ext2|3|4, fsck.msdos, fsck.nfs... You may have to install some of them depending on your GNU/Linux distribution.

A massive surveillance program targeting 27 countries and involving the intelligence agencies of the United States, Canada, United Kingdom, Australia and New Zealand has been unveiled by GNU hackers.

Install PHP CodeSniffer with PEAR

This article should be useful for other tools than CodeSniffer. To put some context, I installed PEAR some time ago for PHPUnit, before I read that PHPUnit had moved away from PEAR and can now be installed using Composer or a simple PHAR (PHp ARchive) file. I had troubles with the default PEAR configuration and the various steps to add the right folders in the system $PATH, PHP configuration, ... and my stubbornness to have everything exactly where I want and behave exactly the way I want!

On my Arch Linux system, PEAR install its packages by default in /usr/bin. I prefer to put them in /usr/share/pear/bin to be more restrictive on what folders I include in my PHP configuration and avoid including the whole /usr/bin in the open_basedir directive. As a reminder, PEAR is installed on Arch Linux with

$ yaourt -S php-pear

and should be available on most distributions through their respective package manager.

First, if, like me, you make 20 mistakes before doing something right, this is the command for uninstalling a package:

$ sudo pear uninstall <packagename></packagename>

To change the PEAR executables directory globally:

$ sudo pear config-set bin_dir /usr/share/pear/bin/

Don't use sudo if you want to apply the changes locally. In this case, it should create, I think automatically, a hidden file named .pearrc in your home directory.

We can check PEAR configuration with

$ sudo pear config-show

Output of $ pear config-show

We can now install CodeSniffer:

$ sudo pear install PHP_CodeSniffer

and adapt our PATH to find its executable by adding the following in our ~/.bashrc: PATH=/usr/share/pear/bin:$PATH.

We reload our config and check if the CodeSniffer executable is found in the right place:

$ . ~/.bashrc
$ whereis phpcs

Output of $ whereis phpcs

I use the open_basedir directive to add a bit of security. Of course, I don't remember that kind of details but PHP reminds me:

Error thrown by phpcs with open_basedir restriction

We fix this by editing /etc/php/php.ini or wherever your PHP configuration file is by adding the PEAR folder: open_basedir = /srv/http/:/tmp/:/usr/share/pear/.

We can now start refactoring...

$ phpcs path/to/file.php|js|css or $ phpcs path/to/folder

Example of output from phpcs

The following command:

$ phpcs -sp --encoding=utf-8 --standard=PSR2 --tab-width=4 --ignore={External/,Tests/coverage/} -v .

  • shows sniff codes, e.g.: (PSR2.Namespaces.UseDeclaration.SpaceAfterLastUse)
  • shows progress
  • specifies that the encoding of the files is utf-8
  • only uses the PSR-2 standard
  • specifies the number of spaces I use as tab
  • ignores the sub folders External and Tests/coverage
  • prints one level of verbosity
  • and processes the current folder.