LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Frank Seidel <fseidel@suse.de>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Subject: Re: [RFC][PATCH] fs/partitions/msdos: directly check if FAT boot sector
Date: Fri, 29 Feb 2008 17:02:46 -0800	[thread overview]
Message-ID: <20080229170246.67391f7b.akpm@linux-foundation.org> (raw)
In-Reply-To: <47C6A9C1.8000008@suse.de>

On Thu, 28 Feb 2008 13:32:01 +0100
Frank Seidel <fseidel@suse.de> wrote:

> Most fat formatted media without partition table contains
> zeros in the boot indication and the other tested bytes
> and so falls through the checks in msdos_partition, leading
> it to return with 1 (all is fine).
> But some (e.g. WinXP formatted) fat fomated medias don't
> use boot_ind and so the check fails and causes a
> "unkown partition table" warning eventhough there is none
> and everything would be fine.
> This additional check directly verifies if there is a
> fat formatted medium without a partition table.
> 
> Signed-off-by: Frank Seidel <fseidel@suse.de>
> ---
>  fs/partitions/msdos.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> --- a/fs/partitions/msdos.c
> +++ b/fs/partitions/msdos.c
> @@ -18,7 +18,7 @@
>   *
>   *  Re-organised Feb 1998 Russell King
>   */
> -
> +#include <linux/msdos_fs.h>
>  
>  #include "check.h"
>  #include "msdos.h"
> @@ -419,6 +419,7 @@ int msdos_partition(struct parsed_partit
>  	Sector sect;
>  	unsigned char *data;
>  	struct partition *p;
> +	struct fat_boot_sector *fb;
>  	int slot;
>  
>  	data = read_dev_sector(bdev, 0, &sect);
> @@ -441,6 +442,12 @@ int msdos_partition(struct parsed_partit
>  	 * partition table. Reject this in case the boot indicator
>  	 * is not 0 or 0x80.
>  	 */
> +	fb = (struct fat_boot_sector *) data;
> +	if (fb->reserved && fb->fats && FAT_VALID_MEDIA(fb->media)) {
> +		printk("\n");
> +		put_dev_sector(sect);
> +		return 1;
> +	}
>  	p = (struct partition *) (data + 0x1be);
>  	for (slot = 1; slot <= 4; slot++, p++) {
>  		if (p->boot_ind != 0 && p->boot_ind != 0x80) {

fs/partitions/msdos.c: In function 'msdos_partition':
fs/partitions/msdos.c:446: warning: comparison is always true due to limited range of data type

didn't you get this?

The reason is that FAT_VALID_MEDIA() is bogus:

#define FAT_VALID_MEDIA(x)      ((0xF8 <= (x) && (x) <= 0xFF) || (x) == 0xF0)

It appears that the on-disk field which FAT_VALID_MEDIA() is designed to
test is only 8-bit, so the comparison with 0xff is pointless.  The only
existing caller of FAT_VALID_MEDIA() cheats by copying the value into a
local unsigned int first.

So I'll leave things as they are for now, but I'd ask that someone can
confirm that we should simply remove the 0xff test from FAT_VALID_MEDIA()?


  parent reply	other threads:[~2008-03-01  1:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-28 12:32 Frank Seidel
2008-02-29  2:16 ` Andreas Dilger
2008-03-01  1:02 ` Andrew Morton [this message]
2008-03-01  9:38   ` Frank Seidel

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=20080229170246.67391f7b.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=fseidel@suse.de \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [RFC][PATCH] fs/partitions/msdos: directly check if FAT boot sector' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).