How do I validate / fsck my ecryptfs filesystem?

Asked by Eric Shattow

I ran out of diskspace on a computer running Ubuntu Jaunty and an ecryptfs mounted home directory. As a result of this, there are files that when accessed, report "Either the lower file is not in a valid eCryptfs format, or the key could not be retrieved. Plaintext passthrough mode is not enabled; returning -EIO" in dmesg.

How do I identify which files have become corrupted?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu ecryptfs-utils Edit question
Assignee:
No assignee Edit question
Solved by:
Eric Shattow
Solved:
Last query:
Last reply:
Revision history for this message
Eric Shattow (eshattow) said :
#1

In the course of making a backup, I have found that 'tar' reports Input/Output error on suspect files:

tar: user/.dmrc.CKS2OU: Cannot open: Input/output error
tar: user/.ICEauthority.swo: Cannot open: Input/output error
tar: user/.viminfo.tmp: Cannot open: Input/output error
tar: user/.ICEauthority.swp: Cannot open: Input/output error
tar: user/.gconf/system/networking/connections/1/802-11-wireless-security/%gconf.xml: Cannot open: Input/output error
tar: user/.gconf/system/networking/connections/1/802-11-wireless/%gconf.xml: Cannot open: Input/output error
tar: user/.nautilus/metafiles/x-nautilus-desktop\:%2F%2F%2F.xmlWEMPOU: Cannot open: Input/output error
tar: user/.nautilus/metafiles/file\:%2F%2F%2Fhome%2Feshattow%2FDesktop.xmlN5S1OU: Cannot open: Input/output error
tar: user/.nautilus/metafiles/x-nautilus-desktop\:%2F%2F%2F.xmlA1I1OU: Cannot open: Input/output error

Desktop operation is broken when such files are not in a consistent state. It is important to be able to find these files quickly.

I devised a Ruby script that does so, as follows:

#!/usr/bin/ruby

# mounted_filesystem_error_check.rb - r1

if ARGV[0] == "--help"
  puts "Walk a mounted filesystem and check for input/output errors in files"
  puts "Usage: #{__FILE__} [directory1] [directory2] [directory3..]"
  exit 8
end

basedir = []

unless ARGV.length > 0
  basedir << Dir.pwd
else
  ARGV.each do |dirname|
    if FileTest.directory? dirname
      basedir << dirname
    else
      puts "### WARNING Skipped invalid directory: #{dirname}"
    end
  end
end

basedir.each do |dirname|
  Dir[File.join(dirname, "**/.*")].each do |filename|
    begin
    File.open(filename, "r") {} unless FileTest.directory? filename
    rescue Errno::EIO
      $stdout.puts "Input/Output Error: #{filename}"
    rescue Errno::EACCES
      $stderr.puts "Skipping file (No permission to access): #{filename}"
    end
  end
end