joany Is there away except just checking smart status to test if the cards are ok.
I mean the blocks on the disk it self, so if needed i can resue them
You can use fsdb
to locate the file-blocks, then use dd
on 'em.
For example (on FreeBSD, reading a NetBSD partition):
root# fsdb -r /dev/da0p2
** /dev/da0p2 (NO WRITE)
Examining file system `/dev/da0p2'
Last Mounted on /
current inode: directory
I=2 MODE=40755 SIZE=512
BTIME=Aug 28 10:54:13 2023 [0 nsec]
MTIME=Aug 28 11:15:13 2023 [930956602 nsec]
CTIME=Aug 28 11:15:13 2023 [930956602 nsec]
ATIME=Aug 28 11:15:43 2023 [147991185 nsec]
OWNER=root GRP=wheel LINKCNT=22 FLAGS=0 BLKCNT=4 GEN=238267c8
fsdb (inum: 2)> ls
slot 0 off 0 ino 2 reclen 12: directory, `.'
slot 1 off 12 ino 2 reclen 12: directory, `..'
slot 2 off 24 ino 1237248 reclen 12: directory, `etc'
slot 3 off 36 ino 1053952 reclen 16: directory, `kern'
slot 4 off 52 ino 1122688 reclen 16: directory, `proc'
slot 5 off 68 ino 2497408 reclen 12: directory, `dev'
slot 6 off 80 ino 45824 reclen 12: directory, `var'
slot 7 off 92 ino 2474496 reclen 12: directory, `mnt'
slot 8 off 104 ino 10 reclen 16: regular, `netbsd' # <-- note file's inode-num.
slot 9 off 120 ino 779008 reclen 16: directory, `stand'
slot 10 off 136 ino 641536 reclen 16: directory, `altroot'
slot 11 off 152 ino 22912 reclen 12: directory, `bin'
slot 12 off 164 ino 572800 reclen 12: directory, `lib'
slot 13 off 176 ino 229120 reclen 16: directory, `libdata'
slot 14 off 192 ino 1260160 reclen 16: directory, `libexec'
slot 15 off 208 ino 1970432 reclen 16: directory, `rescue'
slot 16 off 224 ino 1993344 reclen 16: directory, `root'
slot 17 off 240 ino 1191424 reclen 16: directory, `sbin'
slot 18 off 256 ino 595712 reclen 12: directory, `tmp'
slot 19 off 268 ino 962304 reclen 12: directory, `usr'
slot 20 off 280 ino 4 reclen 16: regular, `.cshrc'
slot 21 off 296 ino 5 reclen 20: regular, `.profile'
slot 22 off 316 ino 3 reclen 20: symlink, `boot.cfg'
slot 23 off 336 ino 7 reclen 20: regular, `netbsd.new'
slot 24 off 356 ino 664448 reclen 16: directory, `home'
slot 25 off 372 ino 68736 reclen 12: directory, `opt'
slot 26 off 384 ino 6 reclen 24: regular, `boot.cfg.std'
slot 27 off 408 ino 9 reclen 24: regular, `boot.cfg.genfb'
slot 28 off 432 ino 160384 reclen 80: directory, `targetroot'
fsdb (inum: 2)> inode 10 # <-- use inode
current inode: regular file
I=10 MODE=100755 SIZE=29542104
BTIME=Aug 28 15:17:50 2023 [0 nsec]
MTIME=Aug 28 15:17:50 2023 [0 nsec]
CTIME=Aug 28 15:04:41 2023 [32079651 nsec]
ATIME=Aug 28 16:04:39 2023 [0 nsec]
OWNER=root GRP=wheel LINKCNT=1 FLAGS=0 BLKCNT=e1a0 GEN=40f74def
fsdb (inum: 10)> blocks # <-- get block-list
regular file, size 29542104 # <-- note size
lbn 0-11 blkno 36888-36983 # <-- dir. blocks
First-level indirect, blkno 36984-36991 distance 0
lbn 12-676 blkno 36992-42311 distance 0 # <-- indir. blocks
lbn 677-691 blkno 42328-42447 distance 16 # <-- "
lbn 692-1803 blkno 42832-51727 distance 384 # <-- "
fsdb (inum: 10)> q # <-- quit
root# cd /tmp
root# dumpfs -s /dev/da0p2 | fgrep fsize # get frag-size
fsize 2048 shift 11 mask 0xfffff800
root# ./rawrd.sh -d /dev/da0p2 -f 2048 -s 29542104 -o netbsd 36888-36983 36992-42311 42328-42447 42832-51727
root# mount -r /dev/da0p2 /mnt
root# cmp /mnt/netbsd netbsd
root# umount /mnt
root# ^D
Since fsdb
has neither a cat
nor a cp
command, use this script:
(Achtung! only lightly tested!)
rawrd.sh
#!/bin/sh
set -eu -o pipefail
me=${0##*/}
fragsz=0
filesz=0
devf=""
outf=""
err() {
echo >&2 "$me: $*"
exit 1
}
usage() {
echo "Usage: $me -d DEV -f FRAGSZ -o OUTFILE -s FILESZ BLOCKNO ..."
}
while getopts d:f:ho:s: opt
do case $opt in
d) devf=$OPTARG
;;
f) fragsz=$((OPTARG + 0))
;;
h) usage
exit 0
;;
o) outf=$OPTARG
;;
s) filesz=$((OPTARG + 0))
;;
\?) usage >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
[ $(id -u) -eq 0 ] || err "You are not super-user"
[ -n "$devf" ] || err "no device given"
[ -n "$outf" ] || err "no output file given"
[ $filesz -gt 0 ] || err "$filesz: FILESZ must be >0"
[ $fragsz -gt 0 ] || err "$fragsz: FRAGSZ must be >0"
[ $((fragsz % 512)) -eq 0 ] \
|| err "$fragsz: FRAGSZ not a multiple of 512"
P='^([[:digit:]]+|[[:digit:]]+-[[:digit:]]+)$'
tmpf=$(mktemp -t "${outf##*/}")
# cleanup
#
trap 'rc=$?; rm -f "$tmpf"; exit $rc' EXIT HUP INT QUIT TERM
# get file blocks
#
for bno
do echo "$bno" | grep -Eq "$P" || err "$bno: invalid block-number"
case $bno in
*-*) IFS=- read start end <<EoF
$bno
EoF
[ $start -lt $end ] || err "bad range: $start >= $end"
count=$(( end - start + 1 ))
iseek=$start
;;
*) count=1
iseek=$bno
;;
esac
dd if="$devf" count=$count bs=$fragsz iseek=$iseek 2>/dev/null
done > $tmpf
# truncate to actual size
#
dd if="$tmpf" of="$outf" bs=$filesz count=1 2>/dev/null