mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-10-10 08:03:04 -04:00
Much simpler implementation of large virtual sector support, not needing larger sector buffers and not touching file.c at all. secmult is simply used to normalize all sector counts to 512-byte physical sectors. * Moved MAX_SECTOR_SIZE definition to config-*.h, and enabled it for iPod Video only. MAX_SECTOR_SIZE now only enables checking for alternate disk layouts due to sector size (as iPod Video G5.5 is presented as having 2048-byte _physical_ sectors to the PC). Large virtual sector support in fat.c is always enabled.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11659 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
74369b4a7b
commit
ef3e129b65
5 changed files with 95 additions and 140 deletions
|
|
@ -152,26 +152,29 @@ int disk_mount(int drive)
|
|||
real problem. */
|
||||
for (i=0; volume != -1 && i<4; i++)
|
||||
{
|
||||
#ifdef MAX_SECTOR_SIZE
|
||||
int j;
|
||||
|
||||
for (j = 1; j <= (MAX_SECTOR_SIZE/SECTOR_SIZE); j <<= 1)
|
||||
{
|
||||
if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start * j))
|
||||
{
|
||||
pinfo[i].start *= j;
|
||||
pinfo[i].size *= j;
|
||||
mounted++;
|
||||
vol_drive[volume] = drive; /* remember the drive for this volume */
|
||||
volume = get_free_volume(); /* prepare next entry */
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start))
|
||||
{
|
||||
mounted++;
|
||||
vol_drive[volume] = drive; /* remember the drive for this volume */
|
||||
volume = get_free_volume(); /* prepare next entry */
|
||||
continue;
|
||||
}
|
||||
|
||||
# if MAX_SECTOR_SIZE != PHYSICAL_SECTOR_SIZE
|
||||
/* Try again with sector size 2048 */
|
||||
if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start
|
||||
* (MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE)))
|
||||
{
|
||||
pinfo[i].start *= MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE;
|
||||
pinfo[i].size *= MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE;
|
||||
mounted++;
|
||||
vol_drive[volume] = drive; /* remember the drive for this volume */
|
||||
volume = get_free_volume(); /* prepare next entry */
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
struct filedesc {
|
||||
unsigned char cache[MAX_SECTOR_SIZE];
|
||||
unsigned char cache[SECTOR_SIZE];
|
||||
int cacheoffset; /* invariant: 0 <= cacheoffset <= SECTOR_SIZE */
|
||||
long fileoffset;
|
||||
long size;
|
||||
|
|
@ -415,10 +415,9 @@ int ftruncate(int fd, off_t size)
|
|||
{
|
||||
int rc, sector;
|
||||
struct filedesc* file = &openfiles[fd];
|
||||
int secsize = fat_get_secsize(&(file->fatfile));
|
||||
|
||||
sector = size / secsize;
|
||||
if (size % secsize)
|
||||
sector = size / SECTOR_SIZE;
|
||||
if (size % SECTOR_SIZE)
|
||||
sector++;
|
||||
|
||||
rc = fat_seek(&(file->fatfile), sector);
|
||||
|
|
@ -445,7 +444,7 @@ static int flush_cache(int fd)
|
|||
{
|
||||
int rc;
|
||||
struct filedesc* file = &openfiles[fd];
|
||||
long sector = file->fileoffset / fat_get_secsize(&(file->fatfile));
|
||||
long sector = file->fileoffset / SECTOR_SIZE;
|
||||
|
||||
DEBUGF("Flushing dirty sector cache\n");
|
||||
|
||||
|
|
@ -474,7 +473,6 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
long sectors;
|
||||
long nread=0;
|
||||
struct filedesc* file = &openfiles[fd];
|
||||
int secsize = fat_get_secsize(&(file->fatfile));
|
||||
int rc;
|
||||
|
||||
if ( !file->busy ) {
|
||||
|
|
@ -492,7 +490,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
/* any head bytes? */
|
||||
if ( file->cacheoffset != -1 ) {
|
||||
int offs = file->cacheoffset;
|
||||
int headbytes = MIN(count, secsize - offs);
|
||||
int headbytes = MIN(count, SECTOR_SIZE - offs);
|
||||
|
||||
if (write) {
|
||||
memcpy( file->cache + offs, buf, headbytes );
|
||||
|
|
@ -502,7 +500,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
memcpy( buf, file->cache + offs, headbytes );
|
||||
}
|
||||
|
||||
if (offs + headbytes == secsize) {
|
||||
if (offs + headbytes == SECTOR_SIZE) {
|
||||
if (file->dirty) {
|
||||
int rc = flush_cache(fd);
|
||||
if ( rc < 0 ) {
|
||||
|
|
@ -525,7 +523,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
* more data to follow in this call). Do NOT flush here. */
|
||||
|
||||
/* read/write whole sectors right into/from the supplied buffer */
|
||||
sectors = count / secsize;
|
||||
sectors = count / SECTOR_SIZE;
|
||||
if ( sectors ) {
|
||||
int rc = fat_readwrite(&(file->fatfile), sectors,
|
||||
(unsigned char*)buf+nread, write );
|
||||
|
|
@ -543,8 +541,8 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
}
|
||||
else {
|
||||
if ( rc > 0 ) {
|
||||
nread += rc * secsize;
|
||||
count -= sectors * secsize;
|
||||
nread += rc * SECTOR_SIZE;
|
||||
count -= sectors * SECTOR_SIZE;
|
||||
|
||||
/* if eof, skip tail bytes */
|
||||
if ( rc < sectors )
|
||||
|
|
@ -577,7 +575,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
/* seek back one sector to put file position right */
|
||||
rc = fat_seek(&(file->fatfile),
|
||||
(file->fileoffset + nread) /
|
||||
secsize);
|
||||
SECTOR_SIZE);
|
||||
if ( rc < 0 ) {
|
||||
DEBUGF("fat_seek() failed\n");
|
||||
errno = EIO;
|
||||
|
|
@ -643,7 +641,6 @@ off_t lseek(int fd, off_t offset, int whence)
|
|||
int sectoroffset;
|
||||
int rc;
|
||||
struct filedesc* file = &openfiles[fd];
|
||||
int secsize = fat_get_secsize(&(file->fatfile));
|
||||
|
||||
LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence);
|
||||
|
||||
|
|
@ -675,9 +672,9 @@ off_t lseek(int fd, off_t offset, int whence)
|
|||
}
|
||||
|
||||
/* new sector? */
|
||||
newsector = pos / secsize;
|
||||
oldsector = file->fileoffset / secsize;
|
||||
sectoroffset = pos % secsize;
|
||||
newsector = pos / SECTOR_SIZE;
|
||||
oldsector = file->fileoffset / SECTOR_SIZE;
|
||||
sectoroffset = pos % SECTOR_SIZE;
|
||||
|
||||
if ( (newsector != oldsector) ||
|
||||
((file->cacheoffset==-1) && sectoroffset) ) {
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@
|
|||
#define FATLONG_TYPE 12
|
||||
#define FATLONG_CHKSUM 13
|
||||
|
||||
#define CLUSTERS_PER_FAT_SECTOR ((unsigned int)(fat_bpb->bpb_bytspersec / 4))
|
||||
#define CLUSTERS_PER_FAT16_SECTOR ((unsigned int)(fat_bpb->bpb_bytspersec / 2))
|
||||
#define DIR_ENTRIES_PER_SECTOR ((unsigned int)(fat_bpb->bpb_bytspersec / DIR_ENTRY_SIZE))
|
||||
#define CLUSTERS_PER_FAT_SECTOR (SECTOR_SIZE / 4)
|
||||
#define CLUSTERS_PER_FAT16_SECTOR (SECTOR_SIZE / 2)
|
||||
#define DIR_ENTRIES_PER_SECTOR (SECTOR_SIZE / DIR_ENTRY_SIZE)
|
||||
#define DIR_ENTRY_SIZE 32
|
||||
#define NAME_BYTES_PER_ENTRY 13
|
||||
#define FAT_BAD_MARK 0x0ffffff7
|
||||
|
|
@ -128,6 +128,9 @@ struct fsinfo {
|
|||
#define FSINFO_FREECOUNT 488
|
||||
#define FSINFO_NEXTFREE 492
|
||||
|
||||
/* Note: This struct doesn't hold the raw values after mounting if
|
||||
* bpb_bytspersec isn't 512. All sector counts are normalized to 512 byte
|
||||
* physical sectors. */
|
||||
struct bpb
|
||||
{
|
||||
int bpb_bytspersec; /* Bytes per sector, typically 512 */
|
||||
|
|
@ -165,8 +168,6 @@ struct bpb
|
|||
int drive; /* on which physical device is this located */
|
||||
bool mounted; /* flag if this volume is mounted */
|
||||
#endif
|
||||
|
||||
int secmult; /* bpb_bytspersec / PHYSICAL_SECTOR_SIZE */
|
||||
};
|
||||
|
||||
static struct bpb fat_bpbs[NUM_VOLUMES]; /* mounted partition info */
|
||||
|
|
@ -193,7 +194,7 @@ struct fat_cache_entry
|
|||
#endif
|
||||
};
|
||||
|
||||
static char fat_cache_sectors[FAT_CACHE_SIZE][MAX_SECTOR_SIZE];
|
||||
static char fat_cache_sectors[FAT_CACHE_SIZE][SECTOR_SIZE];
|
||||
static struct fat_cache_entry fat_cache[FAT_CACHE_SIZE];
|
||||
static struct mutex cache_mutex;
|
||||
|
||||
|
|
@ -235,11 +236,9 @@ void fat_size(IF_MV2(int volume,) unsigned long* size, unsigned long* free)
|
|||
#endif
|
||||
struct bpb* fat_bpb = &fat_bpbs[volume];
|
||||
if (size)
|
||||
*size = (fat_bpb->dataclusters * fat_bpb->bpb_secperclus
|
||||
* fat_bpb->secmult) / 2;
|
||||
*size = fat_bpb->dataclusters * fat_bpb->bpb_secperclus / 2;
|
||||
if (free)
|
||||
*free = (fat_bpb->fsinfo.freecount * fat_bpb->bpb_secperclus
|
||||
* fat_bpb->secmult) / 2;
|
||||
*free = fat_bpb->fsinfo.freecount * fat_bpb->bpb_secperclus / 2;
|
||||
}
|
||||
|
||||
void fat_init(void)
|
||||
|
|
@ -273,8 +272,9 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
|
|||
const int volume = 0;
|
||||
#endif
|
||||
struct bpb* fat_bpb = &fat_bpbs[volume];
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
int rc;
|
||||
int secmult;
|
||||
long datasec;
|
||||
#ifdef HAVE_FAT16SUPPORT
|
||||
int rootdirsectors;
|
||||
|
|
@ -295,19 +295,20 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
|
|||
#endif
|
||||
|
||||
fat_bpb->bpb_bytspersec = BYTES2INT16(buf,BPB_BYTSPERSEC);
|
||||
fat_bpb->bpb_secperclus = buf[BPB_SECPERCLUS];
|
||||
fat_bpb->bpb_rsvdseccnt = BYTES2INT16(buf,BPB_RSVDSECCNT);
|
||||
secmult = fat_bpb->bpb_bytspersec / SECTOR_SIZE;
|
||||
/* Sanity check is performed later */
|
||||
|
||||
fat_bpb->bpb_secperclus = secmult * buf[BPB_SECPERCLUS];
|
||||
fat_bpb->bpb_rsvdseccnt = secmult * BYTES2INT16(buf,BPB_RSVDSECCNT);
|
||||
fat_bpb->bpb_numfats = buf[BPB_NUMFATS];
|
||||
fat_bpb->bpb_totsec16 = BYTES2INT16(buf,BPB_TOTSEC16);
|
||||
fat_bpb->bpb_media = buf[BPB_MEDIA];
|
||||
fat_bpb->bpb_fatsz16 = BYTES2INT16(buf,BPB_FATSZ16);
|
||||
fat_bpb->bpb_fatsz32 = BYTES2INT32(buf,BPB_FATSZ32);
|
||||
fat_bpb->bpb_totsec32 = BYTES2INT32(buf,BPB_TOTSEC32);
|
||||
fat_bpb->bpb_fatsz16 = secmult * BYTES2INT16(buf,BPB_FATSZ16);
|
||||
fat_bpb->bpb_fatsz32 = secmult * BYTES2INT32(buf,BPB_FATSZ32);
|
||||
fat_bpb->bpb_totsec16 = secmult * BYTES2INT16(buf,BPB_TOTSEC16);
|
||||
fat_bpb->bpb_totsec32 = secmult * BYTES2INT32(buf,BPB_TOTSEC32);
|
||||
fat_bpb->last_word = BYTES2INT16(buf,BPB_LAST_WORD);
|
||||
|
||||
/* calculate a few commonly used values */
|
||||
fat_bpb->secmult = fat_bpb->bpb_bytspersec / PHYSICAL_SECTOR_SIZE;
|
||||
|
||||
if (fat_bpb->bpb_fatsz16 != 0)
|
||||
fat_bpb->fatsize = fat_bpb->bpb_fatsz16;
|
||||
else
|
||||
|
|
@ -320,8 +321,8 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
|
|||
|
||||
#ifdef HAVE_FAT16SUPPORT
|
||||
fat_bpb->bpb_rootentcnt = BYTES2INT16(buf,BPB_ROOTENTCNT);
|
||||
rootdirsectors = ((fat_bpb->bpb_rootentcnt * 32)
|
||||
+ (fat_bpb->bpb_bytspersec - 1)) / fat_bpb->bpb_bytspersec;
|
||||
rootdirsectors = secmult * ((fat_bpb->bpb_rootentcnt * DIR_ENTRY_SIZE
|
||||
+ fat_bpb->bpb_bytspersec - 1) / fat_bpb->bpb_bytspersec);
|
||||
#endif /* #ifdef HAVE_FAT16SUPPORT */
|
||||
|
||||
fat_bpb->firstdatasector = fat_bpb->bpb_rsvdseccnt
|
||||
|
|
@ -375,7 +376,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
|
|||
#endif /* #ifdef HAVE_FAT16SUPPORT */
|
||||
{ /* FAT32 specific part of BPB */
|
||||
fat_bpb->bpb_rootclus = BYTES2INT32(buf,BPB_ROOTCLUS);
|
||||
fat_bpb->bpb_fsinfo = BYTES2INT16(buf,BPB_FSINFO);
|
||||
fat_bpb->bpb_fsinfo = secmult * BYTES2INT16(buf,BPB_FSINFO);
|
||||
fat_bpb->rootdirsector = cluster2sec(IF_MV2(fat_bpb,) fat_bpb->bpb_rootclus);
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +398,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
|
|||
{
|
||||
/* Read the fsinfo sector */
|
||||
rc = ata_read_sectors(IF_MV2(drive,)
|
||||
startsector + (fat_bpb->bpb_fsinfo * fat_bpb->secmult), 1, buf);
|
||||
startsector + fat_bpb->bpb_fsinfo, 1, buf);
|
||||
if (rc < 0)
|
||||
{
|
||||
DEBUGF( "fat_mount() - Couldn't read FSInfo (error code %d)\n", rc);
|
||||
|
|
@ -512,15 +513,12 @@ static int bpb_is_sane(IF_MV_NONVOID(struct bpb* fat_bpb))
|
|||
#ifndef HAVE_MULTIVOLUME
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
if(fat_bpb->bpb_bytspersec > MAX_SECTOR_SIZE
|
||||
|| fat_bpb->bpb_bytspersec < PHYSICAL_SECTOR_SIZE
|
||||
|| fat_bpb->bpb_bytspersec % PHYSICAL_SECTOR_SIZE)
|
||||
if(fat_bpb->bpb_bytspersec % SECTOR_SIZE)
|
||||
{
|
||||
DEBUGF( "bpb_is_sane() - Error: sector size is not sane (%d)\n",
|
||||
fat_bpb->bpb_bytspersec);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((long)fat_bpb->bpb_secperclus * (long)fat_bpb->bpb_bytspersec > 128L*1024L)
|
||||
{
|
||||
DEBUGF( "bpb_is_sane() - Error: cluster size is larger than 128K "
|
||||
|
|
@ -564,20 +562,17 @@ static void flush_fat_sector(struct fat_cache_entry *fce,
|
|||
{
|
||||
int rc;
|
||||
long secnum;
|
||||
int secmult;
|
||||
|
||||
/* With multivolume, use only the FAT info from the cached sector! */
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
secmult = fce->fat_vol->secmult;
|
||||
secnum = (fce->secnum * secmult) + fce->fat_vol->startsector;
|
||||
secnum = fce->secnum + fce->fat_vol->startsector;
|
||||
#else
|
||||
secmult = fat_bpbs[0].secmult;
|
||||
secnum = (fce->secnum * secmult) + fat_bpbs[0].startsector;
|
||||
secnum = fce->secnum + fat_bpbs[0].startsector;
|
||||
#endif
|
||||
|
||||
/* Write to the first FAT */
|
||||
rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,)
|
||||
secnum, secmult,
|
||||
secnum, 1,
|
||||
sectorbuf);
|
||||
if(rc < 0)
|
||||
{
|
||||
|
|
@ -593,12 +588,12 @@ static void flush_fat_sector(struct fat_cache_entry *fce,
|
|||
{
|
||||
/* Write to the second FAT */
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
secnum += fce->fat_vol->fatsize * secmult;
|
||||
secnum += fce->fat_vol->fatsize;
|
||||
#else
|
||||
secnum += fat_bpbs[0].fatsize * secmult;
|
||||
secnum += fat_bpbs[0].fatsize;
|
||||
#endif
|
||||
rc = ata_write_sectors(IF_MV2(fce->fat_vol->drive,)
|
||||
secnum, secmult, sectorbuf);
|
||||
secnum, 1, sectorbuf);
|
||||
if(rc < 0)
|
||||
{
|
||||
panicf("flush_fat_sector() - Could not write sector %ld"
|
||||
|
|
@ -644,8 +639,8 @@ static void *cache_fat_sector(IF_MV2(struct bpb* fat_bpb,)
|
|||
if(!fce->inuse)
|
||||
{
|
||||
rc = ata_read_sectors(IF_MV2(fat_bpb->drive,)
|
||||
(secnum * fat_bpb->secmult) + fat_bpb->startsector,
|
||||
fat_bpb->secmult, sectorbuf);
|
||||
secnum + fat_bpb->startsector,1,
|
||||
sectorbuf);
|
||||
if(rc < 0)
|
||||
{
|
||||
DEBUGF( "cache_fat_sector() - Could not read sector %ld"
|
||||
|
|
@ -821,10 +816,10 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry, un
|
|||
|
||||
static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry)
|
||||
{
|
||||
#ifdef HAVE_FAT16SUPPORT
|
||||
#ifndef HAVE_MULTIVOLUME
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
#ifdef HAVE_FAT16SUPPORT
|
||||
if (fat_bpb->is_fat16)
|
||||
{
|
||||
int sector = entry / CLUSTERS_PER_FAT16_SECTOR;
|
||||
|
|
@ -888,7 +883,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
|
|||
#ifndef HAVE_MULTIVOLUME
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char fsinfo[MAX_SECTOR_SIZE];
|
||||
unsigned char fsinfo[SECTOR_SIZE];
|
||||
unsigned long* intptr;
|
||||
int rc;
|
||||
|
||||
|
|
@ -899,8 +894,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
|
|||
|
||||
/* update fsinfo */
|
||||
rc = ata_read_sectors(IF_MV2(fat_bpb->drive,)
|
||||
fat_bpb->startsector +
|
||||
(fat_bpb->bpb_fsinfo * fat_bpb->secmult), 1, fsinfo);
|
||||
fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo);
|
||||
if (rc < 0)
|
||||
{
|
||||
DEBUGF( "flush_fat() - Couldn't read FSInfo (error code %d)\n", rc);
|
||||
|
|
@ -913,8 +907,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
|
|||
*intptr = htole32(fat_bpb->fsinfo.nextfree);
|
||||
|
||||
rc = ata_write_sectors(IF_MV2(fat_bpb->drive,)
|
||||
fat_bpb->startsector +
|
||||
(fat_bpb->bpb_fsinfo * fat_bpb->secmult), 1, fsinfo);
|
||||
fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo);
|
||||
if (rc < 0)
|
||||
{
|
||||
DEBUGF( "flush_fat() - Couldn't write FSInfo (error code %d)\n", rc);
|
||||
|
|
@ -1050,12 +1043,7 @@ static int write_long_name(struct fat_file* file,
|
|||
const unsigned char* shortname,
|
||||
bool is_directory)
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
struct bpb *fat_bpb = &fat_bpbs[file->volume];
|
||||
#else
|
||||
struct bpb *fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
unsigned char* entry;
|
||||
unsigned int idx = firstentry % DIR_ENTRIES_PER_SECTOR;
|
||||
unsigned int sector = firstentry / DIR_ENTRIES_PER_SECTOR;
|
||||
|
|
@ -1213,7 +1201,7 @@ static int add_dir_entry(struct fat_dir* dir,
|
|||
#else
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
unsigned char shortname[12];
|
||||
int rc;
|
||||
unsigned int sector;
|
||||
|
|
@ -1448,12 +1436,7 @@ static void randomize_dos_name(unsigned char *name)
|
|||
|
||||
static int update_short_entry( struct fat_file* file, long size, int attr )
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
struct bpb *fat_bpb = &fat_bpbs[file->volume];
|
||||
#else
|
||||
struct bpb *fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
int sector = file->direntry / DIR_ENTRIES_PER_SECTOR;
|
||||
unsigned char* entry =
|
||||
buf + DIR_ENTRY_SIZE * (file->direntry % DIR_ENTRIES_PER_SECTOR);
|
||||
|
|
@ -1618,7 +1601,7 @@ int fat_create_dir(const char* name,
|
|||
#else
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
int i;
|
||||
long sector;
|
||||
int rc;
|
||||
|
|
@ -1740,10 +1723,10 @@ int fat_closewrite(struct fat_file *file, long size, int attr)
|
|||
LDEBUGF("cluster %ld: %lx\n", count, next);
|
||||
count++;
|
||||
}
|
||||
len = count * fat_bpb->bpb_secperclus * fat_bpb->bpb_bytspersec;
|
||||
len = count * fat_bpb->bpb_secperclus * SECTOR_SIZE;
|
||||
LDEBUGF("File is %ld clusters (chainlen=%ld, size=%ld)\n",
|
||||
count, len, size );
|
||||
if ( len > size + fat_bpb->bpb_secperclus * fat_bpb->bpb_bytspersec)
|
||||
if ( len > size + fat_bpb->bpb_secperclus * SECTOR_SIZE)
|
||||
panicf("Cluster chain is too long\n");
|
||||
if ( len < size )
|
||||
panicf("Cluster chain is too short\n");
|
||||
|
|
@ -1755,12 +1738,7 @@ int fat_closewrite(struct fat_file *file, long size, int attr)
|
|||
|
||||
static int free_direntries(struct fat_file* file)
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
struct bpb *fat_bpb = &fat_bpbs[file->volume];
|
||||
#else
|
||||
struct bpb *fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
unsigned char buf[MAX_SECTOR_SIZE];
|
||||
unsigned char buf[SECTOR_SIZE];
|
||||
struct fat_file dir;
|
||||
int numentries = file->direntries;
|
||||
unsigned int entry = file->direntry - numentries + 1;
|
||||
|
|
@ -1962,9 +1940,6 @@ static int transfer(IF_MV2(struct bpb* fat_bpb,)
|
|||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
int rc;
|
||||
|
||||
start *= fat_bpb->secmult;
|
||||
count *= fat_bpb->secmult;
|
||||
|
||||
LDEBUGF("transfer(s=%lx, c=%lx, %s)\n",
|
||||
start+ fat_bpb->startsector, count, write?"write":"read");
|
||||
|
|
@ -1977,9 +1952,9 @@ static int transfer(IF_MV2(struct bpb* fat_bpb,)
|
|||
#endif
|
||||
firstallowed = fat_bpb->firstdatasector;
|
||||
|
||||
if (start < (firstallowed * fat_bpb->secmult))
|
||||
if (start < firstallowed)
|
||||
panicf("Write %ld before data\n", firstallowed - start);
|
||||
if (start + count > (fat_bpb->totalsectors * fat_bpb->secmult))
|
||||
if (start + count > fat_bpb->totalsectors)
|
||||
panicf("Write %ld after data\n",
|
||||
start + count - fat_bpb->totalsectors);
|
||||
rc = ata_write_sectors(IF_MV2(fat_bpb->drive,)
|
||||
|
|
@ -2073,14 +2048,13 @@ long fat_readwrite( struct fat_file *file, long sectorcount,
|
|||
first = sector;
|
||||
|
||||
if ( ((sector != first) && (sector != last+1)) || /* not sequential */
|
||||
(last-first+1 == (256 / fat_bpb->secmult)) ) {
|
||||
/* max 256 sectors per ata request */
|
||||
(last-first+1 == 256) ) { /* max 256 sectors per ata request */
|
||||
long count = last - first + 1;
|
||||
rc = transfer(IF_MV2(fat_bpb,) first, count, buf, write );
|
||||
if (rc < 0)
|
||||
return rc * 10 - 1;
|
||||
|
||||
buf = (char *)buf + count * fat_bpb->bpb_bytspersec;
|
||||
buf = (char *)buf + count * SECTOR_SIZE;
|
||||
first = sector;
|
||||
}
|
||||
|
||||
|
|
@ -2110,16 +2084,6 @@ long fat_readwrite( struct fat_file *file, long sectorcount,
|
|||
return i;
|
||||
}
|
||||
|
||||
int fat_get_secsize(const struct fat_file *file)
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
return fat_bpbs[file->volume].bpb_bytspersec;
|
||||
#else
|
||||
(void)file;
|
||||
return fat_bpbs[0].bpb_bytspersec;
|
||||
#endif
|
||||
}
|
||||
|
||||
int fat_seek(struct fat_file *file, unsigned long seeksector )
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
|
|
@ -2239,11 +2203,6 @@ static int fat_copy_long_name_segment(unsigned char *utf16src,
|
|||
|
||||
int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
struct bpb* fat_bpb = &fat_bpbs[dir->file.volume];
|
||||
#else
|
||||
struct bpb* fat_bpb = &fat_bpbs[0];
|
||||
#endif
|
||||
bool done = false;
|
||||
int i;
|
||||
int rc;
|
||||
|
|
@ -2277,7 +2236,7 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
|
|||
}
|
||||
|
||||
for (i = dir->entry % DIR_ENTRIES_PER_SECTOR;
|
||||
i < (int)DIR_ENTRIES_PER_SECTOR; i++)
|
||||
i < DIR_ENTRIES_PER_SECTOR; i++)
|
||||
{
|
||||
unsigned int entrypos = i * DIR_ENTRY_SIZE;
|
||||
|
||||
|
|
@ -2331,20 +2290,20 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
|
|||
unsigned char* ptr = cached_buf;
|
||||
int index = longarray[j];
|
||||
/* current or cached sector? */
|
||||
if ( sectoridx >= fat_bpb->bpb_bytspersec ) {
|
||||
if ( sectoridx >= fat_bpb->bpb_bytspersec*2 ) {
|
||||
if ( ( index >= fat_bpb->bpb_bytspersec ) &&
|
||||
( index < fat_bpb->bpb_bytspersec*2 ))
|
||||
if ( sectoridx >= SECTOR_SIZE ) {
|
||||
if ( sectoridx >= SECTOR_SIZE*2 ) {
|
||||
if ( ( index >= SECTOR_SIZE ) &&
|
||||
( index < SECTOR_SIZE*2 ))
|
||||
ptr = dir->sectorcache[1];
|
||||
else
|
||||
ptr = dir->sectorcache[2];
|
||||
}
|
||||
else {
|
||||
if ( index < fat_bpb->bpb_bytspersec )
|
||||
if ( index < SECTOR_SIZE )
|
||||
ptr = dir->sectorcache[1];
|
||||
}
|
||||
|
||||
index &= fat_bpb->bpb_bytspersec-1;
|
||||
index &= SECTOR_SIZE-1;
|
||||
}
|
||||
|
||||
/* Try to append each segment of the long name. Check if we'd
|
||||
|
|
@ -2404,10 +2363,10 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
|
|||
|
||||
/* save this sector, for longname use */
|
||||
if ( sectoridx )
|
||||
memcpy( dir->sectorcache[2], dir->sectorcache[0], fat_bpb->bpb_bytspersec );
|
||||
memcpy( dir->sectorcache[2], dir->sectorcache[0], SECTOR_SIZE );
|
||||
else
|
||||
memcpy( dir->sectorcache[1], dir->sectorcache[0], fat_bpb->bpb_bytspersec );
|
||||
sectoridx += fat_bpb->bpb_bytspersec;
|
||||
memcpy( dir->sectorcache[1], dir->sectorcache[0], SECTOR_SIZE );
|
||||
sectoridx += SECTOR_SIZE;
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -2419,7 +2378,7 @@ unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume))
|
|||
const int volume = 0;
|
||||
#endif
|
||||
struct bpb* fat_bpb = &fat_bpbs[volume];
|
||||
return fat_bpb->bpb_secperclus * fat_bpb->bpb_bytspersec;
|
||||
return fat_bpb->bpb_secperclus * SECTOR_SIZE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
|
|
|
|||
|
|
@ -121,6 +121,10 @@
|
|||
/* Define this if you can read an absolute wheel position */
|
||||
#define HAVE_WHEEL_POSITION
|
||||
|
||||
/* define this if the device has larger sectors when accessed via USB */
|
||||
/* (only relevant in disk.c, fat.c now always supports large virtual sectors) */
|
||||
#define MAX_SECTOR_SIZE 2048
|
||||
|
||||
#define BOOTFILE_EXT "ipod"
|
||||
#define BOOTFILE "rockbox." BOOTFILE_EXT
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,7 @@
|
|||
#include "ata.h" /* for volume definitions */
|
||||
#include "config.h"
|
||||
|
||||
#define PHYSICAL_SECTOR_SIZE 512
|
||||
|
||||
/* Some never players (such as iPod 5.5G) might have 2048 bytes per sector. */
|
||||
#ifdef IPOD_VIDEO
|
||||
#define MAX_SECTOR_SIZE 2048
|
||||
#else
|
||||
#define MAX_SECTOR_SIZE 512
|
||||
#endif
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
/* Number of bytes reserved for a file name (including the trailing \0).
|
||||
Since names are stored in the entry as UTF-8, we won't be able to
|
||||
|
|
@ -86,7 +79,7 @@ struct fat_dir
|
|||
unsigned int entrycount;
|
||||
long sector;
|
||||
struct fat_file file;
|
||||
unsigned char sectorcache[3][MAX_SECTOR_SIZE];
|
||||
unsigned char sectorcache[3][SECTOR_SIZE];
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -109,7 +102,6 @@ extern int fat_create_file(const char* name,
|
|||
extern long fat_readwrite(struct fat_file *ent, long sectorcount,
|
||||
void* buf, bool write );
|
||||
extern int fat_closewrite(struct fat_file *ent, long size, int attr);
|
||||
extern int fat_get_secsize(const struct fat_file *file);
|
||||
extern int fat_seek(struct fat_file *ent, unsigned long sector );
|
||||
extern int fat_remove(struct fat_file *ent);
|
||||
extern int fat_truncate(const struct fat_file *ent);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue