Discussion:
Porting Sqlite to NuttX - undefined reference to 'utimes' and 'ftruncate'
(too old to reply)
lj2057@163.com [nuttx]
2018-01-03 14:12:30 UTC
Permalink
Hi NuttX Group members,
In these days, I tried to port Sqlite to NuttX. Now I have successfully cross-compiled Sqlite as a library on Atmel Studio 7 using NuttX API. When I tried to use Sqlite in my application and found there were 2 undefined reference errors at the final linking process. One error was 'undefined reference to 'utimes' and the other was 'ftruncate'.
The question is where can I find proper source code of these 2 undefined functions? I hope there was no license conflict, so we can submit it to NuttX mainline.


Thanks & Best Regards
spudarnia@yahoo.com [nuttx]
2018-01-03 14:30:03 UTC
Permalink
There are several file system features that are not currently supported by NuttX. ftruncate/truncate is one that is noted in the TODO list:

https://bitbucket.org/nuttx/nuttx/src/aa1a06899935b5a7be1545f4277124e1f675a68e/TODO?at=master&fileviewer=file-view-default#TODO-1745

utimes() is another. Currently only FAT supports file times and there is no file system interface to change file times. http://pubs.opengroup.org/onlinepubs/009695399/functions/utimes.html

You can see the current file system interface in the file include/nuttx/fs/fs.h, struct mountpt_operations. Any new file system operations would need to add methods to that structure (and implement them in all existing file systems... that is the hard part).

I suspect that you could just stub out utimes(). But fruncate() is a problem. ftruncate can be used to either make a file smaller or larger. Larger is not a problem; I think you can do that with lseek (http://pubs.opengroup.org/onlinepubs/009695399/functions/lseek.html) or just by extending the file with zero data (I have never tried lseek for that purpose, however.). But I don't know if any way to make a file smaller without ftruncate.

I assume that SQLite really just wants to create a fixed size file form random access. If that is the case, there are other ways around that.

Greg
lj2057@163.com [nuttx]
2018-01-03 14:52:52 UTC
Permalink
Thanks for your suggestion, Greg.

Yes, ftruncate is a big problem to be implemented on current NuttX. I will try lseek as you suggested.


Best Regards
spudarnia@yahoo.com [nuttx]
2018-01-03 18:48:50 UTC
Permalink
I decided to "bite the bullet" and start the correct implementation of ftruncate. The basic infrastructure is completed and available on the truncate branch: https://bitbucket.org/nuttx/nuttx/branch/truncate

It will, of course, have to stay on the branch until the detailed support has been implemented in all of the file systems. That will take awhile.

You are welcome to contribute if you want to accelerate this. Otherwise, you can use a workaround as I suggested and integrate the real ftruncate when it is available on the master.

Greg

Continue reading on narkive:
Loading...