9
0
Fork 0

Fix access to aligned partition table values

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1046 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-10-15 19:12:33 +00:00
parent cd838849fc
commit 19c6eb59f4
4 changed files with 50 additions and 14 deletions

View File

@ -505,4 +505,6 @@
* Added LPC214x SPI1 driver to interface with MMC on mcu123.com board.
* Added a simple SPI-based MMC/SD block driver
* NSH: Add LPC214x-specific support to NSH; NSH now mounts any SD cards in the slot.
(Now that I have large media support so many partition and FAT fixes should follow).
* FAT: Fix access to unaligned 32-bit values in partion table (start sector & size)

View File

@ -1137,10 +1137,12 @@ nuttx-0.3.17 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Added LPC214x SPI1 driver to interface with MMC on mcu123.com board.
* Added a simple SPI-based MMC/SD block driver
* NSH: Add LPC214x-specific support to NSH; NSH now mounts any SD cards in the slot.
(Now that I have large media support so many partition and FAT fixes should follow).
* FAT: Fix access to unaligned 32-bit values in partion table (start sector & size)
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
buildroot-0.1.1 2008-xx-xx <spudmonkey@racsa.co.cr&gt
buildroot-0.1.1 2008-xx-xx <spudmonkey@racsa.co.cr>
* Support for m68k-elf and m68hc11 toolchain
</pre></ul>

View File

@ -119,6 +119,29 @@
#define EXTBOOT_SIGNATURE 0x29
/****************************************************************************
* These offsets describes the partition table.
*/
/* 446@0: Generally unused and zero; but may
* include IDM Boot Manager menu entry at 8@394 */
#define PART_ENTRY1 446 /* 16@446: Partition table, first entry */
#define PART_ENTRY2 462 /* 16@462: Partition table, second entry */
/* 32@478: Unused, should be zero */
#define PART_SIGNATURE /* 2@510: Valid partitions have 0x55aa here */
/****************************************************************************
* These offsets describes one partition table entry. NOTE that ent entries
* are aligned to 16-bit offsets so that the STARTSECTOR and SIZE values are
* not properly aligned.
*/
#define PART_BOOTINDICATOR 0 /* 1@0: Boot indicator (0x80: active;0x00:otherwise) */
#define PART_STARTCHS 1 /* 3@1: Starting Cylinder/Head/Sector values */
#define PART_TYPE 4 /* 1@4: Partition type description */
#define PART_ENDCHS 5 /* 3@5: Ending Cylinder/Head/Sector values */
#define PART_STARTSECTOR 8 /* 4@8: Starting sector */
#define PART_SIZE 12 /* 4@12: Partition size (in sectors) */
/****************************************************************************
* Each FAT directory entry is 32-bytes long. The following define offsets
* relative to the beginning of a directory entry.
@ -208,7 +231,7 @@
#define FAT_MAXCLUST12 ((1 << 12) - 16)
/* FAT16: For M$, the calculation is ((1 << 16) - 19). */
#define FAT_MINCLUST16 (FAT_MAXCLUST12 + 1)
#define FAT_MAXCLUST16 ((1 << 16) - 16)
@ -250,6 +273,9 @@
#define MBR_GETBOOTSIG16(p) UBYTE_VAL(p,BS16_BOOTSIG)
#define MBR_GETBOOTSIG32(p) UBYTE_VAL(p,BS32_BOOTSIG)
#define PART1_GETTYPE(p) UBYTE_VAL(p,PART_ENTRY1+PART_TYPE)
#define PART2_GETTYPE(p) UBYTE_VAL(p,PART_ENTRY2+PART_TYPE)
#define DIR_GETATTRIBUTES(p) UBYTE_VAL(p,DIR_ATTRIBUTES)
#define DIR_GETNTRES(p) UBYTE_VAL(p,DIR_NTRES)
#define DIR_GETCRTTIMETENTH(p) UBYTE_VAL(p,DIR_CRTTIMETENTH)
@ -262,6 +288,9 @@
#define MBR_PUTBOOTSIG16(p,v) UBYTE_PUT(p,BS16_BOOTSIG,v)
#define MBR_PUTBOOTSIG32(p,v) UBYTE_PUT(p,BS32_BOOTSIG,v)
#define PART1_PUTTYPE(p,v) UBYTE_PUT(p,PART_ENTRY1+PART_TYPE,v)
#define PART2_PUTTYPE(p,v) UBYTE_PUT(p,PART_ENTRY2+PART_TYPE,v)
#define DIR_PUTATTRIBUTES(p,v) UBYTE_PUT(p,DIR_ATTRIBUTES,v)
#define DIR_PUTNTRES(p,v) UBYTE_PUT(p,DIR_NTRES,v)
#define DIR_PUTCRTTIMETENTH(p,v) UBYTE_PUT(p,DIR_CRTTIMETENTH,v)
@ -279,12 +308,22 @@
#define MBR_GETVOLID16(p) fat_getuint32(UBYTE_PTR(p,BS16_VOLID))
#define MBR_GETVOLID32(p) fat_getuint32(UBYTE_PTR(p,BS32_VOLID))
#define PART1_GETSTARTSECTOR(p) fat_getuint32(UBYTE_PTR(p,PART_ENTRY1+PART_STARTSECTOR))
#define PART1_GETSIZE(p) fat_getuint32(UBYTE_PTR(p,PART_ENTRY1+PART_SIZE))
#define PART2_GETSTARTSECTOR(p) fat_getuint32(UBYTE_PTR(p,PART_ENTRY2+PART_STARTSECTOR))
#define PART2_GETSIZE(p) fat_getuint32(UBYTE_PTR(p,PART_ENTRY2+PART_SIZE))
#define MBR_PUTBYTESPERSEC(p,v) fat_putuint16(UBYTE_PTR(p,BS_BYTESPERSEC),v)
#define MBR_PUTROOTENTCNT(p,v) fat_putuint16(UBYTE_PTR(p,BS_ROOTENTCNT),v)
#define MBR_PUTTOTSEC16(p,v) fat_putuint16(UBYTE_PTR(p,BS_TOTSEC16),v)
#define MBR_PUTVOLID16(p,v) fat_putuint32(UBYTE_PTR(p,BS16_VOLID),v)
#define MBR_PUTVOLID32(p,v) fat_putuint32(UBYTE_PTR(p,BS32_VOLID),v)
#define PART1_PUTSTARTSECTOR(p,v) fat_putuint32(UBYTE_PTR(p,PART_ENTRY1+PART_STARTSECTOR,v))
#define PART1_PUTSIZE(p,v) fat_putuint32(UBYTE_PTR(p,PART_ENTRY1+PART_SIZE,v))
#define PART2_PUTSTARTSECTOR(p,v) fat_putuint32(UBYTE_PTR(p,PART_ENTRY2+PART_STARTSECTOR,v))
#define PART2_PUTSIZE(p,v) fat_putuint32(UBYTE_PTR(p,PART_ENTRY2+PART_SIZE,v))
/* But for multi-byte values, the endian-ness of the target vs. the little
* endian order of the byte stream or alignment of the data within the byte
* stream can force special, byte-by-byte accesses.
@ -310,8 +349,6 @@
# define MBR_GETBKBOOTSEC(p) fat_getuint16(UBYTE_PTR(p,BS32_BKBOOTSEC))
# define MBR_GETSIGNATURE(p) fat_getuint16(UBYTE_PTR(p,BS_SIGNATURE))
# define MBR_GETPARTSECTOR(s) fat_getuint32(s)
# define FSI_GETLEADSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_LEADSIG))
# define FSI_GETSTRUCTSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_STRUCTSIG))
# define FSI_GETFREECOUNT(p) fat_getuint32(UBYTE_PTR(p,FSI_FREECOUNT))
@ -394,8 +431,6 @@
# define MBR_GETBKBOOTSEC(p) UINT16_VAL(p,BS32_BKBOOTSEC)
# define MBR_GETSIGNATURE(p) UINT16_VAL(p,BS_SIGNATURE)
# define MBR_GETPARTSECTOR(s) (*((uint32*)(s)))
# define FSI_GETLEADSIG(p) UINT32_VAL(p,FSI_LEADSIG)
# define FSI_GETSTRUCTSIG(p) UINT32_VAL(p,FSI_STRUCTSIG)
# define FSI_GETFREECOUNT(p) UINT32_VAL(p,FSI_FREECOUNT)

View File

@ -649,22 +649,19 @@ int fat_mount(struct fat_mountpt_s *fs, boolean writeable)
* partition, however. Assume it is a partition and get the offset
* into the partition table. This table is at offset MBR_TABLE and is
* indexed by 16x the partition number. Here we support only
* parition 0.
*/
ubyte *partition = &fs->fs_buffer[MBR_TABLE + 0];
/* Check if the partition exists and, if so, get the bootsector for that
* partition 0.
*
* Check if the partition exists and, if so, get the bootsector for that
* partition and see if we can find the boot record there.
*/
if (partition[4])
if (PART1_GETTYPE(fs->fs_buffer) != 0)
{
/* There appears to be a partition, get the sector number of the
* partition (LBA)
*/
fs->fs_fatbase = MBR_GETPARTSECTOR(&partition[8]);
fs->fs_fatbase = PART1_GETSTARTSECTOR(fs->fs_buffer);
/* Read the new candidate boot sector */