summaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-10-15 19:12:33 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-10-15 19:12:33 +0000
commit034e605c8ea9a466e6bf463832ab74037d1cd50c (patch)
tree90f8ad3b8450a7cb15a253ea0d4925cdf3e1c7c1 /nuttx/fs
parent92f75985b66793da5d2c5f0a3ad6ff06d58c69e2 (diff)
downloadpx4-nuttx-034e605c8ea9a466e6bf463832ab74037d1cd50c.tar.gz
px4-nuttx-034e605c8ea9a466e6bf463832ab74037d1cd50c.tar.bz2
px4-nuttx-034e605c8ea9a466e6bf463832ab74037d1cd50c.zip
Fix access to aligned partition table values
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1046 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/fat/fs_fat32.h45
-rw-r--r--nuttx/fs/fat/fs_fat32util.c13
2 files changed, 45 insertions, 13 deletions
diff --git a/nuttx/fs/fat/fs_fat32.h b/nuttx/fs/fat/fs_fat32.h
index 8d67250df..89d2c5754 100644
--- a/nuttx/fs/fat/fs_fat32.h
+++ b/nuttx/fs/fat/fs_fat32.h
@@ -120,6 +120,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)
diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c
index f38cc3741..6c96746cc 100644
--- a/nuttx/fs/fat/fs_fat32util.c
+++ b/nuttx/fs/fat/fs_fat32util.c
@@ -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 */