From: Gratian Crisan <nelu@iv.ro>
To: Savin Zlobec <savin@elatec.si>
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] fatfs lseek EOF bug
Date: Tue, 10 May 2005 12:05:00 -0000 [thread overview]
Message-ID: <200505101258.48354.nelu@iv.ro> (raw)
In-Reply-To: <4280594B.4070703@elatec.si>
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
Hi,
please see my answers below:
On Tuesday 10 May 2005 09:48, Savin Zlobec wrote:
> Gratian Crisan wrote:
> >Hi all,
> >
> >I think I've found a bug in the ecos FAT implementation for lseek
> > function. (fatfs_fo_lseek).
> >When calling the function like this 'lseek(fd, 0, SEEK_CUR)' to get the
> >current file position and the postion is right at the end of the file the
> > fat lseek function returns end of file error EEOF. I've looked at the
> > other filesystems from ecos and did a test in linux and the correct
> > behavior seems to be to return the current position of the end of file if
> > the read/write pointer is at the end of file (equal with the file size).
> >This bug occurs for example when creating a new file, writing some data in
> > it and calling lseek(fd, 0, SEEK_CUR) to get the current file position.
> >
> >Suggestions?
>
> Hi,
>
> I've tryed to reproduce the bug you described but without success.
> Are you using the latest CVS version of fatfs ?
***
Yes.
> Can you send me an test case, so I can look into it ?
***
See the file attached. The test is for an MMC driver but should be pretty
straight forward to adapt (only the mount command should be changed).
The test creates a file and writes blocks of data into it while printing the
current file offset. In a new file after writing the first block, for which
the value returned is 0, the value returned by lseek function is -1. The
strange thing is that if you overwrite an existing file the lseek function
correctly returns the current file offset (equal to EOF).
Thanks,
Nelu
[-- Attachment #2: mmc_test.c --]
[-- Type: text/x-csrc, Size: 1139 bytes --]
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <cyg/fileio/fileio.h>
#include <cyg/infra/diag.h>
void mmc_write(char fileName[], long nBlocks, long blockSize, unsigned char testChar)
{
char *buf;
int i;
int fd;
ssize_t wrote;
if ((buf = (char*)malloc(blockSize)) == NULL) {
diag_printf("[error] memory allocation failed!\n");
return;
}
memset(buf, testChar, blockSize);
if ((fd = open(fileName, O_WRONLY|O_CREAT)) < 0){
diag_printf("[error] opening file %s for write failed!\n", fileName);
return;
}
for(i=0;i<nBlocks;i++) {
diag_printf("off:%d\n",lseek(fd, 0, SEEK_CUR));
wrote = write( fd, buf, blockSize );
if (wrote != blockSize) {
diag_printf("[warning] incomplete write at block %d\n", i);
}
}
close(fd);
}
int main()
{
int err;
int i;
diag_printf("MMC test start ...\n");
if ((err = mount( "/dev/mmcda0/1", "/", "fatfs" )) < 0) {
diag_printf("[error] mounting MMC card!\n");
return 0;
}
mmc_write("test.txt", 5, 1024, 'x');
umount( "/" );
return 1;
}
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
next prev parent reply other threads:[~2005-05-10 10:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-09 11:25 Gratian Crisan
2005-05-10 10:51 ` Savin Zlobec
2005-05-10 12:05 ` Gratian Crisan [this message]
2005-05-10 12:30 ` Savin Zlobec
2005-05-10 13:00 ` Gratian Crisan
2005-05-11 9:32 ` Savin Zlobec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200505101258.48354.nelu@iv.ro \
--to=nelu@iv.ro \
--cc=ecos-discuss@ecos.sourceware.org \
--cc=savin@elatec.si \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).