forked from len0rd/rockbox
Cosmetic: Replaced dozens of openfiles[fd] with 'file' pointers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2831 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4059ea61d4
commit
94fb95f00b
1 changed files with 94 additions and 84 deletions
|
@ -63,6 +63,7 @@ int open(const char* pathname, int flags)
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
int fd;
|
int fd;
|
||||||
char* name;
|
char* name;
|
||||||
|
struct filedesc* file = NULL;
|
||||||
|
|
||||||
LDEBUGF("open(\"%s\",%d)\n",pathname,flags);
|
LDEBUGF("open(\"%s\",%d)\n",pathname,flags);
|
||||||
|
|
||||||
|
@ -83,15 +84,17 @@ int open(const char* pathname, int flags)
|
||||||
errno = EMFILE;
|
errno = EMFILE;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
memset(&openfiles[fd], 0, sizeof (struct filedesc));
|
|
||||||
|
file = &openfiles[fd];
|
||||||
|
memset(file, 0, sizeof(struct filedesc));
|
||||||
|
|
||||||
if (flags & (O_RDWR | O_WRONLY)) {
|
if (flags & (O_RDWR | O_WRONLY)) {
|
||||||
openfiles[fd].write = true;
|
file->write = true;
|
||||||
|
|
||||||
if (flags & O_TRUNC)
|
if (flags & O_TRUNC)
|
||||||
openfiles[fd].trunc = true;
|
file->trunc = true;
|
||||||
}
|
}
|
||||||
openfiles[fd].busy = true;
|
file->busy = true;
|
||||||
|
|
||||||
/* locate filename */
|
/* locate filename */
|
||||||
name=strrchr(pathname+1,'/');
|
name=strrchr(pathname+1,'/');
|
||||||
|
@ -108,7 +111,7 @@ int open(const char* pathname, int flags)
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
DEBUGF("Failed opening dir\n");
|
DEBUGF("Failed opening dir\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
openfiles[fd].busy = false;
|
file->busy = false;
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,38 +119,38 @@ int open(const char* pathname, int flags)
|
||||||
while ((entry = readdir(dir))) {
|
while ((entry = readdir(dir))) {
|
||||||
if ( !strcasecmp(name, entry->d_name) ) {
|
if ( !strcasecmp(name, entry->d_name) ) {
|
||||||
fat_open(entry->startcluster,
|
fat_open(entry->startcluster,
|
||||||
&(openfiles[fd].fatfile),
|
&(file->fatfile),
|
||||||
&(dir->fatdir));
|
&(dir->fatdir));
|
||||||
openfiles[fd].size = entry->size;
|
file->size = entry->size;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if ( !entry ) {
|
if ( !entry ) {
|
||||||
LDEBUGF("Didn't find file %s\n",name);
|
LDEBUGF("Didn't find file %s\n",name);
|
||||||
if ( openfiles[fd].write && (flags & O_CREAT) ) {
|
if ( file->write && (flags & O_CREAT) ) {
|
||||||
if (fat_create_file(name,
|
if (fat_create_file(name,
|
||||||
&(openfiles[fd].fatfile),
|
&(file->fatfile),
|
||||||
&(dir->fatdir)) < 0) {
|
&(dir->fatdir)) < 0) {
|
||||||
DEBUGF("Couldn't create %s in %s\n",name,pathname);
|
DEBUGF("Couldn't create %s in %s\n",name,pathname);
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
openfiles[fd].busy = false;
|
file->busy = false;
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
openfiles[fd].size = 0;
|
file->size = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUGF("Couldn't find %s in %s\n",name,pathname);
|
DEBUGF("Couldn't find %s in %s\n",name,pathname);
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
openfiles[fd].busy = false;
|
file->busy = false;
|
||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
openfiles[fd].fileoffset = 0;
|
file->fileoffset = 0;
|
||||||
|
|
||||||
if (openfiles[fd].write && (flags & O_APPEND)) {
|
if (file->write && (flags & O_APPEND)) {
|
||||||
if (lseek(fd,0,SEEK_END) < 0 )
|
if (lseek(fd,0,SEEK_END) < 0 )
|
||||||
return -7;
|
return -7;
|
||||||
}
|
}
|
||||||
|
@ -157,6 +160,7 @@ int open(const char* pathname, int flags)
|
||||||
|
|
||||||
int close(int fd)
|
int close(int fd)
|
||||||
{
|
{
|
||||||
|
struct filedesc* file = &openfiles[fd];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
LDEBUGF("close(%d)\n",fd);
|
LDEBUGF("close(%d)\n",fd);
|
||||||
|
@ -165,53 +169,55 @@ int close(int fd)
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!openfiles[fd].busy) {
|
if (!file->busy) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (openfiles[fd].write) {
|
if (file->write) {
|
||||||
/* truncate? */
|
/* truncate? */
|
||||||
if (openfiles[fd].trunc) {
|
if (file->trunc) {
|
||||||
if (ftruncate(fd, openfiles[fd].fileoffset) < 0)
|
if (ftruncate(fd, file->fileoffset) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flush sector cache */
|
/* flush sector cache */
|
||||||
if ( openfiles[fd].dirty ) {
|
if ( file->dirty ) {
|
||||||
if (flush_cache(fd) < 0)
|
if (flush_cache(fd) < 0)
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tie up all loose ends */
|
/* tie up all loose ends */
|
||||||
if (fat_closewrite(&(openfiles[fd].fatfile), openfiles[fd].size) < 0)
|
if (fat_closewrite(&(file->fatfile), file->size) < 0)
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
openfiles[fd].busy = false;
|
file->busy = false;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int remove(const char* name)
|
int remove(const char* name)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
struct filedesc* file;
|
||||||
int fd = open(name, O_WRONLY);
|
int fd = open(name, O_WRONLY);
|
||||||
if ( fd < 0 )
|
if ( fd < 0 )
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
rc = fat_truncate(&(openfiles[fd].fatfile));
|
file = &openfiles[fd];
|
||||||
|
rc = fat_truncate(&(file->fatfile));
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("Failed truncating file\n");
|
DEBUGF("Failed truncating file\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fat_remove(&(openfiles[fd].fatfile));
|
rc = fat_remove(&(file->fatfile));
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("Failed removing file\n");
|
DEBUGF("Failed removing file\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfiles[fd].size = 0;
|
file->size = 0;
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -221,24 +227,25 @@ int remove(const char* name)
|
||||||
int ftruncate(int fd, unsigned int size)
|
int ftruncate(int fd, unsigned int size)
|
||||||
{
|
{
|
||||||
int rc, sector;
|
int rc, sector;
|
||||||
|
struct filedesc* file = &openfiles[fd];
|
||||||
|
|
||||||
sector = size / SECTOR_SIZE;
|
sector = size / SECTOR_SIZE;
|
||||||
if (size % SECTOR_SIZE)
|
if (size % SECTOR_SIZE)
|
||||||
sector++;
|
sector++;
|
||||||
|
|
||||||
rc = fat_seek(&(openfiles[fd].fatfile), sector);
|
rc = fat_seek(&(file->fatfile), sector);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fat_truncate(&(openfiles[fd].fatfile));
|
rc = fat_truncate(&(file->fatfile));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfiles[fd].size = size;
|
file->size = size;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -246,21 +253,22 @@ int ftruncate(int fd, unsigned int size)
|
||||||
static int flush_cache(int fd)
|
static int flush_cache(int fd)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int sector = openfiles[fd].fileoffset / SECTOR_SIZE;
|
struct filedesc* file = &openfiles[fd];
|
||||||
|
int sector = file->fileoffset / SECTOR_SIZE;
|
||||||
|
|
||||||
DEBUGF("Flushing dirty sector cache %x\n", sector);
|
DEBUGF("Flushing dirty sector cache %x\n", sector);
|
||||||
|
|
||||||
/* seek back one sector to get file position right */
|
/* seek back one sector to get file position right */
|
||||||
rc = fat_seek(&(openfiles[fd].fatfile), sector);
|
rc = fat_seek(&(file->fatfile), sector);
|
||||||
if ( rc < 0 )
|
if ( rc < 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
rc = fat_readwrite(&(openfiles[fd].fatfile), 1,
|
rc = fat_readwrite(&(file->fatfile), 1,
|
||||||
openfiles[fd].cache, true );
|
file->cache, true );
|
||||||
if ( rc < 0 )
|
if ( rc < 0 )
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
openfiles[fd].dirty = false;
|
file->dirty = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -269,8 +277,9 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
{
|
{
|
||||||
int sectors;
|
int sectors;
|
||||||
int nread=0;
|
int nread=0;
|
||||||
|
struct filedesc* file = &openfiles[fd];
|
||||||
|
|
||||||
if ( !openfiles[fd].busy ) {
|
if ( !file->busy ) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -279,41 +288,41 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
fd,buf,count,write?"write":"read");
|
fd,buf,count,write?"write":"read");
|
||||||
|
|
||||||
/* attempt to read past EOF? */
|
/* attempt to read past EOF? */
|
||||||
if (!write && count > openfiles[fd].size - openfiles[fd].fileoffset)
|
if (!write && count > file->size - file->fileoffset)
|
||||||
count = openfiles[fd].size - openfiles[fd].fileoffset;
|
count = file->size - file->fileoffset;
|
||||||
|
|
||||||
/* any head bytes? */
|
/* any head bytes? */
|
||||||
if ( openfiles[fd].cacheoffset != -1 ) {
|
if ( file->cacheoffset != -1 ) {
|
||||||
int headbytes;
|
int headbytes;
|
||||||
int offs = openfiles[fd].cacheoffset;
|
int offs = file->cacheoffset;
|
||||||
if ( count <= SECTOR_SIZE - openfiles[fd].cacheoffset ) {
|
if ( count <= SECTOR_SIZE - file->cacheoffset ) {
|
||||||
headbytes = count;
|
headbytes = count;
|
||||||
openfiles[fd].cacheoffset += count;
|
file->cacheoffset += count;
|
||||||
if ( openfiles[fd].cacheoffset >= SECTOR_SIZE )
|
if ( file->cacheoffset >= SECTOR_SIZE )
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
headbytes = SECTOR_SIZE - openfiles[fd].cacheoffset;
|
headbytes = SECTOR_SIZE - file->cacheoffset;
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
memcpy( openfiles[fd].cache + offs, buf, headbytes );
|
memcpy( file->cache + offs, buf, headbytes );
|
||||||
if (offs+headbytes == SECTOR_SIZE) {
|
if (offs+headbytes == SECTOR_SIZE) {
|
||||||
int rc = fat_readwrite(&(openfiles[fd].fatfile), 1,
|
int rc = fat_readwrite(&(file->fatfile), 1,
|
||||||
openfiles[fd].cache, true );
|
file->cache, true );
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
openfiles[fd].dirty = false;
|
file->dirty = false;
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
openfiles[fd].dirty = true;
|
file->dirty = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memcpy( buf, openfiles[fd].cache + offs, headbytes );
|
memcpy( buf, file->cache + offs, headbytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
nread = headbytes;
|
nread = headbytes;
|
||||||
|
@ -321,7 +330,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if buffer has been modified, write it back to disk */
|
/* if buffer has been modified, write it back to disk */
|
||||||
if (count && openfiles[fd].dirty) {
|
if (count && file->dirty) {
|
||||||
if (flush_cache(fd) < 0)
|
if (flush_cache(fd) < 0)
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +338,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
/* read whole sectors right into the supplied buffer */
|
/* read whole sectors right into the supplied buffer */
|
||||||
sectors = count / SECTOR_SIZE;
|
sectors = count / SECTOR_SIZE;
|
||||||
if ( sectors ) {
|
if ( sectors ) {
|
||||||
int rc = fat_readwrite(&(openfiles[fd].fatfile), sectors,
|
int rc = fat_readwrite(&(file->fatfile), sectors,
|
||||||
buf+nread, write );
|
buf+nread, write );
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("Failed read/writing %d sectors\n",sectors);
|
DEBUGF("Failed read/writing %d sectors\n",sectors);
|
||||||
|
@ -350,27 +359,27 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
count=0;
|
count=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* any tail bytes? */
|
/* any tail bytes? */
|
||||||
if ( count ) {
|
if ( count ) {
|
||||||
if (write) {
|
if (write) {
|
||||||
if ( openfiles[fd].fileoffset + nread < openfiles[fd].size ) {
|
if ( file->fileoffset + nread < file->size ) {
|
||||||
/* sector is only partially filled. copy-back from disk */
|
/* sector is only partially filled. copy-back from disk */
|
||||||
int rc;
|
int rc;
|
||||||
LDEBUGF("Copy-back tail cache\n");
|
LDEBUGF("Copy-back tail cache\n");
|
||||||
rc = fat_readwrite(&(openfiles[fd].fatfile), 1,
|
rc = fat_readwrite(&(file->fatfile), 1,
|
||||||
openfiles[fd].cache, false );
|
file->cache, false );
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("Failed reading\n");
|
DEBUGF("Failed reading\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
/* seek back one sector to put file position right */
|
/* seek back one sector to put file position right */
|
||||||
rc = fat_seek(&(openfiles[fd].fatfile),
|
rc = fat_seek(&(file->fatfile),
|
||||||
(openfiles[fd].fileoffset + nread) /
|
(file->fileoffset + nread) /
|
||||||
SECTOR_SIZE);
|
SECTOR_SIZE);
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("fat_seek() failed\n");
|
DEBUGF("fat_seek() failed\n");
|
||||||
|
@ -378,29 +387,29 @@ static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
return -7;
|
return -7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy( openfiles[fd].cache, buf + nread, count );
|
memcpy( file->cache, buf + nread, count );
|
||||||
openfiles[fd].dirty = true;
|
file->dirty = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( fat_readwrite(&(openfiles[fd].fatfile), 1,
|
if ( fat_readwrite(&(file->fatfile), 1,
|
||||||
&(openfiles[fd].cache),false) < 1 ) {
|
&(file->cache),false) < 1 ) {
|
||||||
DEBUGF("Failed caching sector\n");
|
DEBUGF("Failed caching sector\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -8;
|
return -8;
|
||||||
}
|
}
|
||||||
memcpy( buf + nread, openfiles[fd].cache, count );
|
memcpy( buf + nread, file->cache, count );
|
||||||
}
|
}
|
||||||
|
|
||||||
nread += count;
|
nread += count;
|
||||||
openfiles[fd].cacheoffset = count;
|
file->cacheoffset = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfiles[fd].fileoffset += nread;
|
file->fileoffset += nread;
|
||||||
LDEBUGF("fileoffset: %d\n", openfiles[fd].fileoffset);
|
LDEBUGF("fileoffset: %d\n", file->fileoffset);
|
||||||
|
|
||||||
/* adjust file size to length written */
|
/* adjust file size to length written */
|
||||||
if ( write && openfiles[fd].fileoffset > openfiles[fd].size )
|
if ( write && file->fileoffset > file->size )
|
||||||
openfiles[fd].size = openfiles[fd].fileoffset;
|
file->size = file->fileoffset;
|
||||||
|
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
@ -427,10 +436,11 @@ int lseek(int fd, int offset, int whence)
|
||||||
int oldsector;
|
int oldsector;
|
||||||
int sectoroffset;
|
int sectoroffset;
|
||||||
int rc;
|
int rc;
|
||||||
|
struct filedesc* file = &openfiles[fd];
|
||||||
|
|
||||||
LDEBUGF("lseek(%d,%d,%d)\n",fd,offset,whence);
|
LDEBUGF("lseek(%d,%d,%d)\n",fd,offset,whence);
|
||||||
|
|
||||||
if ( !openfiles[fd].busy ) {
|
if ( !file->busy ) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -441,59 +451,59 @@ int lseek(int fd, int offset, int whence)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
pos = openfiles[fd].fileoffset + offset;
|
pos = file->fileoffset + offset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
pos = openfiles[fd].size + offset;
|
pos = file->size + offset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if ((pos < 0) || (pos > openfiles[fd].size)) {
|
if ((pos < 0) || (pos > file->size)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new sector? */
|
/* new sector? */
|
||||||
newsector = pos / SECTOR_SIZE;
|
newsector = pos / SECTOR_SIZE;
|
||||||
oldsector = openfiles[fd].fileoffset / SECTOR_SIZE;
|
oldsector = file->fileoffset / SECTOR_SIZE;
|
||||||
sectoroffset = pos % SECTOR_SIZE;
|
sectoroffset = pos % SECTOR_SIZE;
|
||||||
|
|
||||||
if ( (newsector != oldsector) ||
|
if ( (newsector != oldsector) ||
|
||||||
((openfiles[fd].cacheoffset==-1) && sectoroffset) ) {
|
((file->cacheoffset==-1) && sectoroffset) ) {
|
||||||
|
|
||||||
if ( newsector != oldsector ) {
|
if ( newsector != oldsector ) {
|
||||||
if (openfiles[fd].dirty) {
|
if (file->dirty) {
|
||||||
if (flush_cache(fd) < 0)
|
if (flush_cache(fd) < 0)
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fat_seek(&(openfiles[fd].fatfile), newsector);
|
rc = fat_seek(&(file->fatfile), newsector);
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( sectoroffset ) {
|
if ( sectoroffset ) {
|
||||||
rc = fat_readwrite(&(openfiles[fd].fatfile), 1,
|
rc = fat_readwrite(&(file->fatfile), 1,
|
||||||
&(openfiles[fd].cache),false);
|
&(file->cache),false);
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
openfiles[fd].cacheoffset = sectoroffset;
|
file->cacheoffset = sectoroffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
openfiles[fd].cacheoffset = -1;
|
file->cacheoffset = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( openfiles[fd].cacheoffset != -1 )
|
if ( file->cacheoffset != -1 )
|
||||||
openfiles[fd].cacheoffset = sectoroffset;
|
file->cacheoffset = sectoroffset;
|
||||||
|
|
||||||
openfiles[fd].fileoffset = pos;
|
file->fileoffset = pos;
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue