mirror of
https://github.com/wiiu-env/libfat.git
synced 2024-11-25 19:36:52 +01:00
Propagate disc errors up to the user app
This commit is contained in:
parent
359b38085a
commit
c26b60e6e0
@ -39,6 +39,9 @@
|
|||||||
|
|
||||||
2006-08-13 - Chishm
|
2006-08-13 - Chishm
|
||||||
* Moved all externally visible directory related functions to fatdir
|
* Moved all externally visible directory related functions to fatdir
|
||||||
|
|
||||||
|
2007-02-11 - Chishm
|
||||||
|
* Propagate disc errors up to the user app
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -348,16 +351,21 @@ int _FAT_read_r (struct _reent *r, int fd, char *ptr, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((tempVar > 0) && flagNoError) {
|
if ((tempVar > 0) && flagNoError) {
|
||||||
_FAT_disc_readSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster) + position.sector,
|
if (! _FAT_disc_readSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster) + position.sector,
|
||||||
tempVar, ptr);
|
tempVar, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
} else {
|
||||||
ptr += tempVar * BYTES_PER_READ;
|
ptr += tempVar * BYTES_PER_READ;
|
||||||
remain -= tempVar * BYTES_PER_READ;
|
remain -= tempVar * BYTES_PER_READ;
|
||||||
position.sector += tempVar;
|
position.sector += tempVar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Move onto next cluster
|
// Move onto next cluster
|
||||||
// It should get to here without reading anything if a cluster is due to be allocated
|
// It should get to here without reading anything if a cluster is due to be allocated
|
||||||
if (position.sector >= partition->sectorsPerCluster) {
|
if ((position.sector >= partition->sectorsPerCluster) && flagNoError) {
|
||||||
tempNextCluster = _FAT_fat_nextCluster(partition, position.cluster);
|
tempNextCluster = _FAT_fat_nextCluster(partition, position.cluster);
|
||||||
if ((remain == 0) && (tempNextCluster == CLUSTER_EOF)) {
|
if ((remain == 0) && (tempNextCluster == CLUSTER_EOF)) {
|
||||||
position.sector = partition->sectorsPerCluster;
|
position.sector = partition->sectorsPerCluster;
|
||||||
@ -372,7 +380,14 @@ int _FAT_read_r (struct _reent *r, int fd, char *ptr, int len) {
|
|||||||
|
|
||||||
// Read in whole clusters
|
// Read in whole clusters
|
||||||
while ((remain >= partition->bytesPerCluster) && flagNoError) {
|
while ((remain >= partition->bytesPerCluster) && flagNoError) {
|
||||||
_FAT_disc_readSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster), partition->sectorsPerCluster, ptr);
|
if ( !_FAT_disc_readSectors (
|
||||||
|
partition->disc, _FAT_fat_clusterToSector (partition, position.cluster),
|
||||||
|
partition->sectorsPerCluster, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
ptr += partition->bytesPerCluster;
|
ptr += partition->bytesPerCluster;
|
||||||
remain -= partition->bytesPerCluster;
|
remain -= partition->bytesPerCluster;
|
||||||
|
|
||||||
@ -392,12 +407,17 @@ int _FAT_read_r (struct _reent *r, int fd, char *ptr, int len) {
|
|||||||
// Read remaining sectors
|
// Read remaining sectors
|
||||||
tempVar = remain / BYTES_PER_READ; // Number of sectors left
|
tempVar = remain / BYTES_PER_READ; // Number of sectors left
|
||||||
if ((tempVar > 0) && flagNoError) {
|
if ((tempVar > 0) && flagNoError) {
|
||||||
_FAT_disc_readSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster),
|
if (!_FAT_disc_readSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster),
|
||||||
tempVar, ptr);
|
tempVar, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
} else {
|
||||||
ptr += tempVar * BYTES_PER_READ;
|
ptr += tempVar * BYTES_PER_READ;
|
||||||
remain -= tempVar * BYTES_PER_READ;
|
remain -= tempVar * BYTES_PER_READ;
|
||||||
position.sector += tempVar;
|
position.sector += tempVar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Last remaining sector
|
// Last remaining sector
|
||||||
// Check if anything is left
|
// Check if anything is left
|
||||||
@ -526,7 +546,7 @@ int _FAT_write_r (struct _reent *r,int fd, const char *ptr, int len) {
|
|||||||
// Make sure we can actually write to the file
|
// Make sure we can actually write to the file
|
||||||
if ((file == NULL) || !file->inUse || !file->write) {
|
if ((file == NULL) || !file->inUse || !file->write) {
|
||||||
r->_errno = EBADF;
|
r->_errno = EBADF;
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
partition = file->partition;
|
partition = file->partition;
|
||||||
@ -602,12 +622,17 @@ int _FAT_write_r (struct _reent *r,int fd, const char *ptr, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((tempVar > 0) && flagNoError) {
|
if ((tempVar > 0) && flagNoError) {
|
||||||
_FAT_disc_writeSectors (partition->disc,
|
if (!_FAT_disc_writeSectors (partition->disc,
|
||||||
_FAT_fat_clusterToSector (partition, position.cluster) + position.sector, tempVar, ptr);
|
_FAT_fat_clusterToSector (partition, position.cluster) + position.sector, tempVar, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
} else {
|
||||||
ptr += tempVar * BYTES_PER_READ;
|
ptr += tempVar * BYTES_PER_READ;
|
||||||
remain -= tempVar * BYTES_PER_READ;
|
remain -= tempVar * BYTES_PER_READ;
|
||||||
position.sector += tempVar;
|
position.sector += tempVar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((position.sector >= partition->sectorsPerCluster) && flagNoError && (remain > 0)) {
|
if ((position.sector >= partition->sectorsPerCluster) && flagNoError && (remain > 0)) {
|
||||||
position.sector = 0;
|
position.sector = 0;
|
||||||
@ -627,8 +652,13 @@ int _FAT_write_r (struct _reent *r,int fd, const char *ptr, int len) {
|
|||||||
|
|
||||||
// Write whole clusters
|
// Write whole clusters
|
||||||
while ((remain >= partition->bytesPerCluster) && flagNoError) {
|
while ((remain >= partition->bytesPerCluster) && flagNoError) {
|
||||||
_FAT_disc_writeSectors (partition->disc, _FAT_fat_clusterToSector(partition, position.cluster),
|
if ( !_FAT_disc_writeSectors (partition->disc, _FAT_fat_clusterToSector(partition, position.cluster),
|
||||||
partition->sectorsPerCluster, ptr);
|
partition->sectorsPerCluster, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
ptr += partition->bytesPerCluster;
|
ptr += partition->bytesPerCluster;
|
||||||
remain -= partition->bytesPerCluster;
|
remain -= partition->bytesPerCluster;
|
||||||
if (remain > 0) {
|
if (remain > 0) {
|
||||||
@ -653,12 +683,17 @@ int _FAT_write_r (struct _reent *r,int fd, const char *ptr, int len) {
|
|||||||
// Write remaining sectors
|
// Write remaining sectors
|
||||||
tempVar = remain / BYTES_PER_READ; // Number of sectors left
|
tempVar = remain / BYTES_PER_READ; // Number of sectors left
|
||||||
if ((tempVar > 0) && flagNoError) {
|
if ((tempVar > 0) && flagNoError) {
|
||||||
_FAT_disc_writeSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster),
|
if (!_FAT_disc_writeSectors (partition->disc, _FAT_fat_clusterToSector (partition, position.cluster),
|
||||||
tempVar, ptr);
|
tempVar, ptr))
|
||||||
|
{
|
||||||
|
flagNoError = false;
|
||||||
|
r->_errno = EIO;
|
||||||
|
} else {
|
||||||
ptr += tempVar * BYTES_PER_READ;
|
ptr += tempVar * BYTES_PER_READ;
|
||||||
remain -= tempVar * BYTES_PER_READ;
|
remain -= tempVar * BYTES_PER_READ;
|
||||||
position.sector += tempVar;
|
position.sector += tempVar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Last remaining sector
|
// Last remaining sector
|
||||||
if ((remain > 0) && flagNoError) {
|
if ((remain > 0) && flagNoError) {
|
||||||
|
Loading…
Reference in New Issue
Block a user