Util-Linux package development
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: "Jean-Loup 'clippix' Bogalho" <clippix@lse.epita.fr>
Cc: util-linux@vger.kernel.org, gabriel@lse.epita.fr
Subject: Re: [PATCH V2] dos: copy previous bootsector for dos partition table
Date: Tue, 7 Apr 2015 11:45:35 +0200	[thread overview]
Message-ID: <20150407094535.GF3923@ws.net.home> (raw)
In-Reply-To: <20150404160526.GA24261@clippix.lab.lse.epita.fr>

On Sat, Apr 04, 2015 at 06:05:26PM +0200, Jean-Loup 'clippix' Bogalho wrote:
> In order to create a dos partition scheme, libfdisk erase the first disk sector
> and then add the needed values (partitions, magic numbers).
> In the case the disk already contains code in the bootsection, it will be
> erased.  

 Yes.

> This was not the case in v2.25 of util-linux.

 Are you sure? I see fdisk_init_firstsector_buffer() in 

    git show v2.25:libfdisk/src/utils.c

 and we zeroize the first sector all time, for example see
 create_doslabel() and get_boot() from 

    git show v2.13:fdisk/fdisk.c


 I have tested v2.17:

 # hexdump -C /dev/sdc
 00000000  48 45 4c 4c 4f 0a 00 00  00 00 00 00 00 00 00 00  |HELLO...........|
 00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *

 # fdisk /dev/sdc
 ... create MBR ....


 # hexdump -C /dev/sdc
 00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
 000001b0  00 00 00 00 00 00 00 00  b4 19 30 de 00 00 00 01  |..........0.....|
 000001c0  01 00 83 10 fb fb 3b 00  00 00 19 9c 0f 00 00 00  |......;.........|
 000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
 000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|


> Since fdisk can be used to repair messed partition tables, maybe we don't want
> to have to rewrite the boot section.

 That's question. If you keep the begin of the device unchanged then
 you can create horrible mix of more labels or you can keep any unwanted
 filesystem or raid superblock on the device. I don't think we want this 
 by default. (Well, in many cases this problem should be detected by 
 warn_wipe() in context.c.)

 Note that GNU parted also modifies the begin of the device (it
 tries to be smart and it writes some generic "boot code" there:-)
 
 Maybe it would be better to add --protect-bootsector command line option;
 if you want to implement it:

    - add protect_boot flag to struct fdisk_context (fdiskP.h)
    - add a new function fdisk_protect_boot(cxt, enable) to set/unset the new flag

    - extend fdisk_init_firstsector_buffer() to protect specified area:
         fdisk_init_firstsector_buffer(cxt, 0, 446)

    - call fdisk_init_firstsector_buffer() from dos_create_disklabel()
      with proper offset and size when the protect_boot flag is enabled

    - add fdisk_protect_boot() to 
        libfdisk/src/libfdisk.h.in
        libfdisk/src/libfdisk.sym
        libfdisk/docs/libfdisk-sections.txt

  Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2015-04-07  9:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-04 16:05 [PATCH V2] dos: copy previous bootsector for dos partition table Jean-Loup 'clippix' Bogalho
2015-04-07  9:45 ` Karel Zak [this message]
2015-04-13 11:20   ` Karel Zak

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=20150407094535.GF3923@ws.net.home \
    --to=kzak@redhat.com \
    --cc=clippix@lse.epita.fr \
    --cc=gabriel@lse.epita.fr \
    --cc=util-linux@vger.kernel.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox