mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Franck Jullien <franck.jullien@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox <barebox@lists.infradead.org>
Subject: Re: [RFC][FAT] Handle MBR on the first sector
Date: Fri, 14 Sep 2012 09:22:07 +0200	[thread overview]
Message-ID: <CAJfOKBwqwKGcTZ7X0Z9yLiD6EezXoZmjqfar3koM=d0pvRCCmQ@mail.gmail.com> (raw)
In-Reply-To: <20120914071804.GR6180@pengutronix.de>

2012/9/14 Sascha Hauer <s.hauer@pengutronix.de>:
> Hi Franck,
>
> On Thu, Sep 13, 2012 at 02:13:29PM +0200, Franck Jullien wrote:
>> *** Did not send this email with git because it's no working where I am **
>>
>> We may have some disk with MBR as a first sector. In this case, the
>> current FAT check returns an error. However, the FAT sector exist and
>> the MBR can tell us where it is.
>>
>> This patch make the FAT fs try to find the FAT boot sector on the first
>> sector of the first partition in case it is not on sector 0.
>
> The patch looks good. Not applying it because it's RFC, but I would if
> you give your ok.
>

You have it.

> Sascha
>
>>
>> Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
>> ---
>>  fs/fat/ff.c |   24 ++++++++++++++++++++----
>>  1 files changed, 20 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/fat/ff.c b/fs/fat/ff.c
>> index 66db1d6..6a4ae32 100644
>> --- a/fs/fat/ff.c
>> +++ b/fs/fat/ff.c
>> @@ -191,6 +191,7 @@
>>  #define      FSI_Nxt_Free            492     /* FSI: Last allocated cluster (4) */
>>  #define MBR_Table            446     /* MBR: Partition table offset (2) */
>>  #define      SZ_PTE                  16      /* MBR: Size of a partition table entry */
>> +#define MBR_StartSector              8       /* MBR: Offset of Starting Sector in
>> Partition Table Entry */
>>  #define BS_55AA                      510     /* Boot sector signature (2) */
>>
>>  #define      DIR_Name                0       /* Short file name (11) */
>> @@ -1533,11 +1534,15 @@ int follow_path (     /* 0(0): successful, !=0:
>> error code */
>>   */
>>  static int check_fs (        /* 0:The FAT BR, 1:Valid BR but not an FAT,
>> 2:Not a BR, 3:Disk error */
>>       FATFS *fs,      /* File system object */
>> -     DWORD sect      /* Sector# (lba) to check if it is an FAT boot record or not */
>> +     DWORD sect,     /* Sector# (lba) to check if it is an FAT boot record or not */
>> +     DWORD *bootsec
>>  )
>>  {
>>       int ret;
>>
>> +     if(bootsec)
>> +             *bootsec = 0;
>> +
>>       /* Load boot record */
>>       ret = disk_read(fs, fs->win, sect, 1);
>>       if (ret)
>> @@ -1553,6 +1558,12 @@ static int check_fs (  /* 0:The FAT BR, 1:Valid
>> BR but not an FAT, 2:Not a BR, 3:
>>       if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
>>               return 0;
>>
>> +     if(bootsec)
>> +             /* This must be an MBR, so return the starting sector of the
>> +              * first partition so we could check if there is a FAT boot
>> +              * sector there */
>> +             *bootsec = LD_WORD(&fs->win[MBR_Table + MBR_StartSector]);
>> +
>>       return -ENODEV;
>>  }
>>
>> @@ -1565,6 +1576,7 @@ static int chk_mounted (        /* 0(0): successful,
>> !=0: any error occurred */
>>  )
>>  {
>>       BYTE fmt, b;
>> +     DWORD first_boot_sect;
>>       DWORD bsect, fasize, tsect, sysect, nclst, szbfat;
>>       WORD nrsv;
>>
>> @@ -1579,9 +1591,13 @@ static int chk_mounted (       /* 0(0): successful,
>> !=0: any error occurred */
>>               return -EIO;
>>  #endif
>>       /* Search FAT partition on the drive. Supports only generic
>> partitionings, FDISK and SFD. */
>> -     fmt = check_fs(fs, bsect = 0);  /* Check sector 0 if it is a VBR */
>> -     if (fmt)
>> -             return fmt; /* No FAT volume is found */
>> +     fmt = check_fs(fs, bsect = 0, &first_boot_sect);        /* Check sector 0
>> if it is a VBR */
>> +     if (fmt && first_boot_sect != 0) {
>> +             /* Sector 0 is an MBR, now check for FAT in the first partition */
>> +             fmt = check_fs(fs, bsect = first_boot_sect, NULL);
>> +             if(fmt)
>> +                     return fmt; /* No FAT volume is found */
>> +     }
>>
>>       /* Following code initializes the file system object */
>>
>> --
>> 1.7.1
>>
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-09-14  7:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13 12:13 Franck Jullien
2012-09-14  7:18 ` Sascha Hauer
2012-09-14  7:22   ` Franck Jullien [this message]
2012-09-14  7:25     ` Sascha Hauer
2012-09-14  7:44       ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  8:47         ` Franck Jullien
2012-09-14  8:50           ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  9:02             ` Franck Jullien
2012-09-14  9:04               ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  9:06               ` Franck Jullien

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='CAJfOKBwqwKGcTZ7X0Z9yLiD6EezXoZmjqfar3koM=d0pvRCCmQ@mail.gmail.com' \
    --to=franck.jullien@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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