I was trying to get TinyXML2 running and the example included with the library failed on me. I was using libfatfs and thought id try and use the above functions but they don't compile(undefined reference).
fs.h says:
/* 64-bit file access functions. Generally, you should only define one of
the 64-bit or 32-bit versions of these functions.*/
so lets say I ONLY have the 64 bit file access functions defined, will fs_total() call the 64 bit version since the 32-bit version isn't defined?
I tried to compile ext2 example by calling fs_total64() and I get the same compile error.
How do we call the 64-bit versions?
fseek64, fs_total64, ftell64, fread, fwrite
- BB Hood
- DC Developer
- Posts: 189
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Fri Mar 30, 2007 12:09 am
- Has thanked: 41 times
- Been thanked: 10 times
fseek64, fs_total64, ftell64, fread, fwrite
Last edited by BB Hood on Sun Oct 13, 2013 3:04 pm, edited 1 time in total.
- BlueCrab
- The Crabby Overlord
- Posts: 5666
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: fseek64, fs_total64, ftell64
Can you actually give the full error? The fs_seek64, fs_total64, and fs_tell64 functions should all be defined. fseek64 and ftell64 are not part of KOS (they'd be in newlib, if anywhere).BB Hood wrote:I was trying to get TinyXML2 running and the example included with the library failed on me. I was using libfatfs and thought id try and use the above functions but they don't compile(undefined reference).
Correct. fs_total will prefer the 32-bit version, but fall-back to the 64-bit version if needed. fs_total64 does the opposite (prefers 64-bit, falls back to 32-bit). See the following code snippet from fs.c:fs.h says:
/* 64-bit file access functions. Generally, you should only define one of
the 64-bit or 32-bit versions of these functions.*/
so lets say I ONLY have the 64 bit file access functions defined, will fs_total() call the 64 bit version since the 32-bit version isn't defined?
Code: Select all
size_t fs_total(file_t fd) {
fs_hnd_t *h = fs_map_hnd(fd);
if(h == NULL) return -1;
if(h->handler == NULL) {
errno = EINVAL;
return -1;
}
/* Prefer the 32-bit version, but fall back if needed to the 64-bit one. */
if(h->handler->total)
return h->handler->total(h->hnd);
else if(h->handler->total64)
return (size_t)h->handler->total64(h->hnd);
errno = EINVAL;
return -1;
}
uint64 fs_total64(file_t fd) {
fs_hnd_t *h = fs_map_hnd(fd);
if(h == NULL) return -1;
if(h->handler == NULL) {
errno = EINVAL;
return -1;
}
/* Prefer the 64-bit version, but fall back if needed to the 32-bit one. */
if(h->handler->total64)
return h->handler->total64(h->hnd);
else if(h->handler->total)
return (uint64)h->handler->total(h->hnd);
errno = EINVAL;
return -1;
}
fs_total64 shouldn't give you any problems. The other two functions in the topic title aren't in KOS -- they're newlib's responsibility. I dunno if newlib even provides them (it probably doesn't, as they aren't standard functions, IIRC).I tried to compile ext2 example by calling fs_total64() and I get the same compile error.
How do we call the 64-bit versions?
- BB Hood
- DC Developer
- Posts: 189
- Joined: Fri Mar 30, 2007 12:09 am
- Has thanked: 41 times
- Been thanked: 10 times
Re: fseek64, fs_total64, ftell64
ugh looks like KallistiOS just needed a good cleaning and recompile. As for fseek64 and ftell64. There are actually supposed to be fseeko and ftello.
More about those functions are explained here: http://man7.org/linux/man-pages/man3/fseeko.3.html
Thanks again BlueCrab.
EDIT: So it seems fs_total()/fs_total64() only works for file descriptors and not file pointers?
Also fread() and (most likely; didnt test yet) fwrite() work differently than read() and write() for some reason.
When I use read(file descriptor) it reads the amount of bytes I tell it to in one go. When I use fread(file pointer) it reads in multiplies of 1024 bytes(repeat calls). For example:
the debug output I put into fs_read() says that I want to read 1024 bytes instead of 10. Another example:
the debug output I put into fs_read() says that I want to read 1024 bytes instead of 1025. However, fs_read() is (automatically) called again reading another 1024 bytes starting from ptr = 1024.
read(file descriptor) doesn't do this. It reads it in one go (the right amount of bytes asked for) instead of being called again.
More about those functions are explained here: http://man7.org/linux/man-pages/man3/fseeko.3.html
Thanks again BlueCrab.
EDIT: So it seems fs_total()/fs_total64() only works for file descriptors and not file pointers?
Also fread() and (most likely; didnt test yet) fwrite() work differently than read() and write() for some reason.
When I use read(file descriptor) it reads the amount of bytes I tell it to in one go. When I use fread(file pointer) it reads in multiplies of 1024 bytes(repeat calls). For example:
Code: Select all
fread(buf, 1, 10, fp );
Code: Select all
fread( buf, 1, 1025, fp );
read(file descriptor) doesn't do this. It reads it in one go (the right amount of bytes asked for) instead of being called again.