Cannot remove : Input/output error

In an ext3 root file system, there is a temporary file in it.

$ sudo rm -f .rc.local.swp 
rm: cannot remove ‘.rc.local.swp’: Input/output error

Also reported an error when ls:

$ ls -la
ls: cannot access .rc.local.swp: Input/output error
total 11
drwxr-xr-x  3 root    root    1024 Sep 12 23:20 .
drwxrwxr-x 18 charles charles 1024 Sep  8 01:05 ..
-rw-r--r--  1 root    root     980 Jan  2  2014 bootchartd.conf
-rw-r--r--  1 root    root     293 Sep 12 23:15 fstab
-rw-r--r--  1 root    root      44 Dec 16  2013 group
drwxr-xr-x  2 root    root    1024 Sep 12 23:05 init.d
-rw-r--r--  1 root    root     153 Dec 16  2013 inittab
-rw-r--r--  1 root    root     118 Dec 16  2013 passwd
-rw-r--r--  1 root    root     128 Dec 22  2013 profile
-rwxr-xr-x  1 root    root     502 Sep 12 23:20 rc.local
-????????? ??      ?         ?           ?.rc.local.swp

The solution is to fix the file system using FSCK:

$ fsck.ext3  rootfs.img 
e2fsck 1.42.9 (4-Feb-2014)
rootfs.img contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Entry '.rc.local.swp' in /etc (119889) has deleted/unused inode 119892.  Clear<y>?yes
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences:  -7170 -(485381--485388) -(488452--488455)
Fix<y>?yes
Free blocks count wrong for group #0 (7655, counted=7656).
Fix<y>?yes
Free blocks count wrong for group #59 (7896, counted=7908).
Fix<y>?yes
Free blocks count wrong (438258, counted=438271).
Fix<y>?yes
Inode bitmap differences:  -119892
Fix<y>?yes
Free inodes count wrong for group #59 (2020, counted=2021).
Fix<y>?yes
Free inodes count wrong (127446, counted=127447).
Fix<y>?yes

rootfs.img: ***** FILE SYSTEM WAS MODIFIED *****
rootfs.img: 569/128016 files (2.6% non-contiguous), 73729/512000 blocks

Later, remount the filesystem and discover that the file has been deleted.

Read More: