Skip to content
Snippets Groups Projects
Commit c6ad3e0d authored by patacongo's avatar patacongo
Browse files

Added search for good cluster size

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@804 42af7a65-404d-4744-a932-0658087f49c3
parent a88a6ecb
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -482,7 +482,7 @@ struct fat_mountpt_s
size_t fs_fsinfo; /* MBR: Sector number of FSINFO sector */
size_t fs_currentsector; /* The sector number buffered in fs_buffer */
uint32 fs_nclusters; /* Maximum number of data clusters */
uint32 fs_fatsize; /* MBR: Count of sectors occupied by one fat */
uint32 fs_nfatsects; /* MBR: Count of sectors occupied by one fat */
uint32 fs_fattotsec; /* MBR: Total count of sectors on the volume */
uint32 fs_fsifreecount; /* FSI: Last free cluster count on volume */
uint32 fs_fsinextfree; /* FSI: Cluster number of 1st free cluster */
......
......@@ -284,7 +284,7 @@ static int fat_checkfsinfo(struct fat_mountpt_s *fs)
static int fat_checkbootrecord(struct fat_mountpt_s *fs)
{
uint32 ndatasectors;
uint32 fatsize;
uint32 ntotalfatsects;
uint16 rootdirsectors = 0;
boolean notfat32 = FALSE;
......@@ -320,17 +320,17 @@ static int fat_checkbootrecord(struct fat_mountpt_s *fs)
/* Determine the number of sectors in a FAT. */
fs->fs_fatsize = MBR_GETFATSZ16(fs->fs_buffer); /* Should be zero */
if (fs->fs_fatsize)
fs->fs_nfatsects = MBR_GETFATSZ16(fs->fs_buffer); /* Should be zero */
if (fs->fs_nfatsects)
{
notfat32 = TRUE; /* Must be zero for FAT32 */
}
else
{
fs->fs_fatsize = MBR_GETFATSZ32(fs->fs_buffer);
fs->fs_nfatsects = MBR_GETFATSZ32(fs->fs_buffer);
}
if (!fs->fs_fatsize || fs->fs_fatsize >= fs->fs_hwnsectors)
if (!fs->fs_nfatsects || fs->fs_nfatsects >= fs->fs_hwnsectors)
{
return -ENODEV;
}
......@@ -363,11 +363,11 @@ static int fat_checkbootrecord(struct fat_mountpt_s *fs)
/* Get the number of FATs. This is probably two but could have other values */
fs->fs_fatnumfats = MBR_GETNUMFATS(fs->fs_buffer);
fatsize = fs->fs_fatnumfats * fs->fs_fatsize;
ntotalfatsects = fs->fs_fatnumfats * fs->fs_nfatsects;
/* Get the total number of data sectors */
ndatasectors = fs->fs_fattotsec - fs->fs_fatresvdseccount - fatsize - rootdirsectors;
ndatasectors = fs->fs_fattotsec - fs->fs_fatresvdseccount - ntotalfatsects - rootdirsectors;
if (ndatasectors > fs->fs_hwnsectors)
{
return -ENODEV;
......@@ -415,10 +415,10 @@ static int fat_checkbootrecord(struct fat_mountpt_s *fs)
}
else
{
fs->fs_rootbase = fs->fs_fatbase + fatsize;
fs->fs_rootbase = fs->fs_fatbase + ntotalfatsects;
}
fs->fs_database = fs->fs_fatbase + fatsize + fs->fs_rootentcnt / DIRSEC_NDIRS(fs);
fs->fs_database = fs->fs_fatbase + ntotalfatsects + fs->fs_rootentcnt / DIRSEC_NDIRS(fs);
fs->fs_fsifreecount = 0xffffffff;
return OK;
......@@ -708,7 +708,7 @@ int fat_mount(struct fat_mountpt_s *fs, boolean writeable)
fdbg("\t data sector: %d\n", fs->fs_database);
fdbg("\t FSINFO sector: %d\n", fs->fs_fsinfo);
fdbg("\t Num FATs: %d\n", fs->fs_fatnumfats);
fdbg("\t FAT size: %d\n", fs->fs_fatsize);
fdbg("\t FAT sectors: %d\n", fs->fs_nfatsects);
fdbg("\t sectors/cluster: %d\n", fs->fs_fatsecperclus);
fdbg("\t max clusters: %d\n", fs->fs_nclusters);
fdbg("\tFSI free count %d\n", fs->fs_fsifreecount);
......@@ -2115,14 +2115,14 @@ int fat_fscacheflush(struct fat_mountpt_s *fs)
/* Does the sector lie in the FAT region? */
if (fs->fs_currentsector < fs->fs_fatbase + fs->fs_fatsize)
if (fs->fs_currentsector < fs->fs_fatbase + fs->fs_nfatsects)
{
/* Yes, then make the change in the FAT copy as well */
int i;
for (i = fs->fs_fatnumfats; i >= 2; i--)
{
fs->fs_currentsector += fs->fs_fatsize;
fs->fs_currentsector += fs->fs_nfatsects;
ret = fat_hwwrite(fs, fs->fs_buffer, fs->fs_currentsector, 1);
if (ret < 0)
{
......
......@@ -99,7 +99,7 @@ struct fat_var_s
ubyte fv_jump[3]; /* 3-byte boot jump instruction */
ubyte fv_sectshift; /* Log2 of fv_sectorsize */
ubyte fv_nrootdirsects; /* Number of root directory sectors */
ubyte fv_fatsize; /* FAT size: 0 (not determined), 12, 16, or 32 */
ubyte fv_fattype; /* FAT size: 0 (not determined), 12, 16, or 32 */
uint16 fv_bootcodesize; /* Size of array at fv_bootcode */
uint32 fv_createtime; /* Creation time */
uint32 fv_sectorsize; /* Size of one hardware sector */
......
......@@ -133,7 +133,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt,
/* Most of the rest of the sector depends on the FAT size */
if (fmt->ff_fatsize != 32)
if (fmt->ff_fattype != 32)
{
/* 2@22: FAT12/16: Must be 0, see BS32_FATSZ32 */
......@@ -156,11 +156,11 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt,
/* 8@54: "FAT12 ", "FAT16 ", or "FAT " */
if (fmt->ff_fatsize == 12)
if (fmt->ff_fattype == 12)
{
memcpy(&var->fv_sect[BS16_FILESYSTYPE], "FAT12 ", 8);
}
else /* if (fmt->ff_fatsize == 16) */
else /* if (fmt->ff_fattype == 16) */
{
memcpy(&var->fv_sect[BS16_FILESYSTYPE], "FAT16 ", 8);
}
......@@ -338,7 +338,7 @@ static inline int mkfatfs_writembr(FAR struct fat_format_s *fmt,
/* Write FAT32-specific sectors */
if (ret >= 0 && fmt->ff_fatsize == 32)
if (ret >= 0 && fmt->ff_fattype == 32)
{
/* Write the backup master boot record */
......@@ -405,7 +405,7 @@ static inline int mkfatfs_writefat(FAR struct fat_format_s *fmt,
if (sectno == 0)
{
memset(var->fv_sect, 0, var->fv_sectorsize);
switch(fmt->ff_fatsize)
switch(fmt->ff_fattype)
{
case 12:
/* Mark the first two full FAT entries -- 24 bits, 3 bytes total */
......
......@@ -49,7 +49,7 @@
#define MKFATFS_DEFAULT_BBCHECK FALSE /* FALSE: No bad block check */
#define MKFATFS_DEFAULT_NFATS 2 /* 2: Default number of FATs */
#define MKFATFS_DEFAULT_FATSIZE 0xff /* 0: Autoselect FAT size */
#define MKFATFS_DEFAULT_FATTYPE 0xff /* 0: Autoselect FAT size */
#define MKFATFS_DEFAULT_CLUSTSIZE 0 /* 0: Autoselect cluster size */
#define MKFATFS_DEFAULT_VOLUMELABEL { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }
#define MKFATFS_DEFAULT_BKUPBOOT 0 /* 0: Determine sector number of the backup boot sector */
......@@ -63,7 +63,7 @@
{ \
MKFATFS_DEFAULT_BBCHECK, \
MKFATFS_DEFAULT_NFAT, \
MKFATFS_DEFAULT_FATSIZE, \
MKFATFS_DEFAULT_FATTYPE, \
MKFATFS_DEFAULT_CLUSTSIZE, \
MKFATFS_DEFAULT_VOLUMELABEL, \
MKFATFS_DEFAULT_BKUPBOOT, \
......@@ -85,7 +85,7 @@
struct fat_format_s
{
ubyte ff_nfats; /* Number of FATs */
ubyte ff_fatsize; /* FAT size: 0 (autoselect), 12, 16, or 32 */
ubyte ff_fattype; /* FAT size: 0 (autoselect), 12, 16, or 32 */
ubyte ff_clustshift; /* Log2 of sectors per cluster: 0-5, 0xff (autoselect) */
ubyte ff_volumelabel[11]; /* Volume label */
uint16 ff_backupboot; /* Sector number of the backup boot sector (0=use default)*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment