From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Fix the destroyed disk image partition table in a raw image file using Emacs.
Date: Thu, 15 Apr 2021 22:16:22 +0800 [thread overview]
Message-ID: <CAGP6POK8QibadfYYbgEz2UXdLF=HU+sMzDr4qU3LWQ9ZZM3eLw@mail.gmail.com> (raw)
In-Reply-To: <87tuocfx5g.fsf@no.workgroup>
On Mon, Apr 12, 2021 at 3:18 AM Gregor Zattler <telegraph@gmx.net> wrote:
>
> Hi Hongyi Zhao,
> * Hongyi Zhao <hongyi.zhao@gmail.com> [2021-04-11; 21:34]:
> > $ dd if=disk.img bs=1 count=4 skip=440 2>/dev/null | od -t x4 -An
> > 761b36b0
> >
> > It's well known that Emacs is an 8-bit clean editor which makes it
> > safe to edit binary files. So, I want to whether I can fix the above
> > destroyed disk image file with Emacs for my scenario.
>
> If your emacs is able to handle the disk image in memory
> (which probably means you need a 64bit emacs and enough RAM
> installed) you could open the file of the disk image with
>
> find-file-literally
>
> Visit file FILENAME with no conversion of any kind.
>
> Format conversion and character code conversion are both
> disabled, and multibyte characters are disabled in the
> resulting buffer. The major mode used is Fundamental
> mode regardless of the file name, and local variable
> specifications in the file are ignored. Automatic
> uncompression and adding a newline at the end of the file
> due to require-final-newline is also disabled.
>
> And then the first thing to do would be
>
> binary-overwrite-mode
>
> When Binary Overwrite mode is enabled, printing
> characters typed in replace existing text. Newlines are
> not treated specially, so typing at the end of a line
> joins the line to the next, with the typed character
> between them. Typing before a tab character simply
> replaces the tab with the character typed. C-q replaces
> the text at the cursor, just as ordinary typing
> characters do.
>
>
> You then can move point in the disk image to the desired
> place and type in whatever you want and later save the
> buffer to its file.
>
>
> Ciao; Gregor
> --
> -... --- .-. . -.. ..--.. ...-.-
If the 'conv=notrunc' option of 'dd' is used, the following is a pure
*nix tools based restore method given on comp.unix.shell newsgroup by
Helmut Waitzmann. For the more detailed discussion, see
<https://groups.google.com/g/comp.unix.shell/c/-4jQ-6tkOgs/m/FZl_96n-AQAJ>:
<quote>
[The 'conv=notrunc' option of 'dd']
>Assuming I have used this option, what exact restore command should
>I use?
First you should check, that the command
{
printf '%s\n' 'ibase=16' &&
printf '%s\n' b0 36 1b 76 |
LC_ALL=POSIX tr -- '[:lower:]' '[:upper:]'
} | bc | xargs -E '' -- printf \''\\%.4o'\''\n' |
xargs -E '' -- printf '%b' |
od -v -A n -t x4
yields the output '761b36b0'. If that's the case, you could have
done
{
printf '%s\n' 'ibase=16' &&
printf '%s\n' b0 36 1b 76 |
LC_ALL=POSIX tr -- '[:lower:]' '[:upper:]'
} | bc | xargs -E '' -- printf \''\\%.4o'\''\n' |
xargs -E '' -- printf '%b' |
dd of=disk.img bs=1 seek=440 conv=notrunc
to restore the original partuuid.
</quote>
To be frank, the internal logic of the above code is still unclear to
me. I post it here for your reference.
Regards
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China
prev parent reply other threads:[~2021-04-15 14:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 13:34 Fix the destroyed disk image partition table in a raw image file using Emacs Hongyi Zhao
2021-04-11 13:39 ` Jean Louis
2021-04-11 17:26 ` Dan Hitt
2021-04-11 18:45 ` tomas
2021-04-11 19:56 ` Dan Hitt
2021-04-11 20:58 ` Stefan Monnier
2021-04-11 21:15 ` GNU ELPA problem (was: Re: Fix the destroyed disk image partition table in a raw image file using Emacs.) Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-11 19:18 ` Fix the destroyed disk image partition table in a raw image file using Emacs Gregor Zattler
2021-04-12 6:29 ` Hongyi Zhao
2021-04-15 14:16 ` Hongyi Zhao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGP6POK8QibadfYYbgEz2UXdLF=HU+sMzDr4qU3LWQ9ZZM3eLw@mail.gmail.com' \
--to=hongyi.zhao@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.