typically has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

This may be completely Ubuntu-related, so I apologize in advance, but I haven't had much luck on that forum yet, and there's a possibility that it's perl-related.

I have a simple perl script which wants to read all the folders in a directory on my external HDD using:

@subjects = grep { -d } glob ( "*" );

Doing this causes my HDD to go from writable to read-only. I.e., before I run the code I can create a directory in the terminal, but not directly afterwards. Also the commands I want to run from perl after enumerating the folders cannot write to the disk.

Just wondering if someone has a clue why this might happen, and whether it has something to do with perl itself...?? Thanks!

Replies are listed 'Best First'.
Re: running perl script makes my external HDD read-only
by Corion (Patriarch) on Aug 26, 2008 at 12:31 UTC

    Most likely this is because your kernel reads through the directory structure and while doing so finds that the directory structure has become broken. It then switches the filesystem to read-only as a safety measure.

    You can confirm this by looking into your kernel log, there should be a message about this, and you can possibly replicate this from outside of Perl by using

    ls -lR /
    .

    Perl itself has no capability to set a filesystem to read-only unless the user that runs Perl has those permissions already.

Re: running perl script makes my external HDD read-only
by moritz (Cardinal) on Aug 26, 2008 at 12:32 UTC
    I think it has nothing to do with perl.

    On Linux I can think of a scenario that can lead to such a behaviour: the file system is mounted with the option that automatically remounts the FS as ro when an error occurs. Now your script reads through the whole directory, and the file system is corrupted. An error is reported, and the FS is mounted read-only.

    Of course that's just a theory. You can check that by looking at the output of the dmesg program, or by looking into various log files in /var/log/ (messages, kern.log, syslog).

      You are exactly right:

      Aug 26 14:44:50 typically-desktop kernel: [ 176.616936] FAT: Filesyst +em panic (dev sdb1) Aug 26 14:44:50 typically-desktop kernel: [ 176.616944] fat_get_c +luster: invalid cluster chain (i_pos 0) Aug 26 14:44:50 typically-desktop kernel: [ 176.616951] File syst +em has been set read-only

      Solved it with a simple fsck command

      Thanks for your (non-Perl) expertise! I shall most probably return with real perl questions :)