Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Aug 2022 04:05:10 +1000
From:      Ian Smith <smithi@nimnet.asn.au>
To:        Matthias Apitz <guru@unixarea.de>,Michael Schuster <michaelsprivate@gmail.com>
Cc:        David Christensen <dpchrist@holgerdanske.com>,questions <questions@freebsd.org>
Subject:   Re: What is the best way to look for a lost file in the disk blocks
Message-ID:  <E691054B-9D07-40CC-8011-7477485CEDFB@nimnet.asn.au>
In-Reply-To: <YvNdo46mftXd%2BBTJ@c720-r368166>
References:  <20220809122357.GA17@sh4-5.1blu.de> <448ac676-5acd-02b2-00c6-5ae0c6773438@holgerdanske.com> <CADqw_g%2BGSiKhF8G7d=d%2B8qFiLekWpSdnxxHrxizWuvCRimzyhw@mail.gmail.com> <YvNdo46mftXd%2BBTJ@c720-r368166>

next in thread | previous in thread | raw e-mail | index | archive | help
On 10 August 2022 5:26:27 pm AEST, Matthias Apitz <guru@unixarea=2Ede> wrot=
e:
 > El d=C3=ADa mi=C3=A9rcoles, agosto 10, 2022 a las 07:18:03a=2E m=2E +02=
00, Michael
 > Schuster escribi=C3=B3:
 >=20
 > > On Wed, Aug 10, 2022 at 3:55 AM David Christensen
 > > <dpchrist@holgerdanske=2Ecom> wrote:
 > > >
 > > > On 8/9/22 05:23, Matthias Apitz wrote:
 > > > >
 > > > > Hello,
 > > > >
 > > > > Last night I damaged a plain UTF-8 HTML file (I copied by
 > accident a
 > > > > JPEG file over it) and it turned out that the backup was done a
 > month
 > > > > ago=2E I learned my lesson from this re/ doing backups more often
 > of files
 > > > > I'm working on=2E=2E=2E
 >=20
 > Thanks for the hints=2E
 >=20
 > The file in question is my diary, written in Spanish and every day
 > is headed by a line like
 >=20
 > <dt><b>Viernes, 29 de julio de 2022 </b>
 >=20
 > So I wrote a 35 line C-programm reading any 1024 byte block from the
 > device, terminate it with '\0' to make sure that a=20
 >=20
 > char *p =3D strstr(block, " de 2022 </b>");
 >=20
 > would not fail, and with p !=3D NULL I printed with printf(p-16);
 > the diary entry; and the
 > current block number to be used in dd(1) later=2E
 > It finds all the lines of this year, but not the missing between July
 > 10
 > and August 1 :-(
 > So the blocks have been lost=2E I was hoping that UFS puts them back to
 > free block chains for later use, but it seems that
 > the 'cp picture=2Ejpg diary=2Ehtml' directly overwrote the used blocks=
=2E
 >=20
 > Lesson learned=2E I'm attaching the C-pgm, maybe someone can use it or
 > at
 > least its idea=2E
 >=20
 > 	matthias
=20
"Necessity is the mother of Invention" alright=2E  A neat solution=2E

Could any other files written since have reused those blocks?  I'm a littl=
e surprised if the cp did that =2E=2E=2E

FWIW, I was about to offer a different method that came from my own need -=
 finding a small but rare string in the 12=2E3-RELEASE dvd1=2Eiso to be rep=
laced, so that the 2+GiB of included packages may be installed - after 3 pa=
tches to bsdconfig, but that's another story - so I'll share it as it could=
 be used on each (say) 10MiB block dd'd from a disk or partition as well=2E=
  play=2Eiso is a copy of the 4=2E1GiB dvd1=2Eiso

<code>
smithi@t430s:/home/dvds % strings -an7 -td play=2Eiso | grep -i2 'pkg=2Etx=
z'

2442269512 sod=2EJ{++I
2442271727 %R:*lAS
2442277052      PKG=2ETXZ;1PX,
2442277146 pkg-1=2E17=2E2=2EtxzNM
2442277165 pkg=2Etxz
2442278912 version =3D 2;
2442278925 packing_format =3D "txz";
--
4377882256 Signature type %s is not supported for bootstrapping=2E
4377882310 %s/%s=2Epubkeysig=2EXXXXXX
4377882333 pkg=2Etxz
4377882341 Invalid configuration format, ignoring the configuration fi
4377882420 Consider changing PACKAGESITE or installing it from ports:
4377882498 REPOS_DIR
4377882508 asprintf
4377882517 Path to pkg=2Etxz required
4377882543 %s/trusted
4377882556 A pre-built version of pkg could not be found for your syst
--
4466242378 pistrings
4466242388 pkg=2Econf
4466242397 pkg=2Etxz
4466242410 plasma_saver
4466242423 plasma_saver=2Eko
</code>

The numbers are byte offsets into the =2Eiso file=2E -n7 is the size of th=
e string I was after; increase if hunting a longer string=2E

Something to consider - in a general case, probably not yours - is that th=
e desired string/s might be split over adjacent blocks, requiring some over=
lap of perhaps a few kb=2E

cheers, Ian



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E691054B-9D07-40CC-8011-7477485CEDFB>