This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
romfs on linux / use of fread
- To: <ecos-discuss at sources dot redhat dot com>
- Subject: [ECOS] romfs on linux / use of fread
- From: rob dot wj dot jansen at philips dot com
- Date: Thu, 14 Jun 2001 14:58:41 +0200
All,
after having some problems with fread() on my private filesystem I decided to test this with the romfs package.
It seems that fread() works in CYGNUM_LIBC_STDIO_BUFSIZE and it will read a maximum of this number of
bytes from a file at a time.
performing an fread(buff, 1, 4096, fp) (right after opening the file) tells me that 256 items have been read.
Performing multiple fread(buff, 1, 250, fp) operations return 250, 6, 250, 6 etc. and looking at the implementation
I found that indeed the function stops after reading all data from the current buffer.
According to the linux man-page of fread (which is according to ISO - I guess) the function should read the full
amount requested or "a short item count" on EOF or error.
I consider this to be a bug, it makes no sense to have the application to loop until its buffer is filled.
Is there a good reason for this behaviour or should I fix this ?
I tested this on a synthetic linux target with the romfs package added.
The romfs image file is read into memory and mounted using the following code:
externC int cyg_hal_sys_open(const char *, int, unsigned int);
externC int cyg_hal_sys_close(int);
externC unsigned long cyg_hal_sys_read(int, void *, long);
externC unsigned long cyg_hal_sys_lseek(int, unsigned long, int);
#define O_RDONLY 0
#define SEEK_END 2
#define SEEK_SET 0
int rom_mount(void) {
int fd;
int result;
unsigned long fsize;
unsigned long bytesRead;
void *rombase;
char address[16];
int err;
fd = cyg_hal_sys_open("../../romfs.img", O_RDONLY, 0);
if(fd) {
fsize = cyg_hal_sys_lseek(fd, 0, SEEK_END); // Determine size
rombase = malloc(fsize+32); // Alloc mem
rombase = (void *)((unsigned int)rombase & 0xffffffe0) + 0x20;
cyg_hal_sys_lseek(fd, 0, SEEK_SET); // Rewind
bytesRead =
cyg_hal_sys_read(fd, rombase, fsize); // Read complete file
cyg_hal_sys_close(fd);
sprintf(address, "%p", (void *)rombase);
err = mount(address, "/rom", "romfs");
} else {
printf("Cannot open romfs.img file. Aborting\n");
exit(1);
}
return err;
}
Regards,
Rob Jansen
Software Engineer
Competence Center Platforms
BU Mobile Communications
Meijhorst 60-10, 6537 KT Nijmegen, The Netherlands
Tel: +31-24-353-6329
Fax: +31-24-353-3613
mailto:Rob.WJ.Jansen@philips.com