5

I have a corrupt file according to btrfs

BTRFS info (device sdb1): csum failed ino 367 off 310013952 csum 1601485211 expected csum 3692975992

I assumed ino 367 means inode 367, so I can use find and try to restore the file. However find /path -inum 367 finds nothing. Anyone know how to find the corrupt file?

  • FWIW, find worked for me: find /path -xdev -inum 367 turned up a file for three different inodes. My log messages are the same. Ubuntu 15.10, kernel 4.2.0. – Reid Jan 7 '16 at 22:33
  • Also look into btrfs inspect-internal inode-resolve. I'll convert this into an answer if/when I become more confident about what I'm doing. – Reid Jan 8 '16 at 0:12
  • thanks @Reid btrfs inspect-internal inode-resolve does not list the filename. From irc chat on #btrfs it seems this may be a bug with older kernels – user192749 Jan 8 '16 at 7:57
4

Example:

sudo btrfs inspect-internal inode-resolve 15380 /home

man btrfs-inspect-internal says:

   inode-resolve [-v] <ino> <path>
       (needs root privileges)

       resolve paths to all files with given inode number ino in a given
       subvolume at path, ie. all hardlinks

       Options

       -v
           verbose mode, print count of returned paths and ioctl()
           return value
| improve this answer | |
  • +1 excellent suggestion, thanks! – Avio Mar 9 at 15:00
1

I'm not sure why find command didn't work for you. May be ino#367 deleted? For me, both find and btrfs-debug-tree seems to be working fine.

$ find  /btrfs/ -inum 257
/btrfs/100kbfile.txt
$ ls -li /btrfs/100kbfile.txt 
257 -rw-r--r--. 1 root root 102400 Nov 25 21:07 /btrfs/100kbfile.txt

You can also try using 'btrfs-debug-tree' and grep for the objectid.

./btrfs-debug-tree  /btrfs/partition | grep -A2 257

find your inode/objectid from output. You can see the name associated with objectid 257.

location key (257 INODE_ITEM 0) type FILE

namelen 13 datalen 0 name: 100kbfile.txt

| improve this answer | |
  • Thanks, as stated this appears to be a bug in older kernels, 3,14 in this case. – user192749 Mar 11 '16 at 3:45
1

The method "find /path -inum xxx" works with newer kernels, issue is a bug in older brtfs kernel code.

| improve this answer | |
0

If you want to print out the filenames of multiple inodes, here's a script based on this answer.

#!/bin/bash

set -eu

usage() {
    printf "Usage: %s /filesytem inode(s)\n" "$(basename "$0")" 2>&1
}

if [[ $# -lt 2 ]]; then
    usage; exit 1
fi

fs=$1
shift

if [[ ! -e $fs ]]; then
    usage; exit 1
fi

for i in "$@"; do
    # printf "%s " "$i"
    sudo btrfs inspect-internal inode-resolve "$fs" "$i"
done
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.