Thanks  !

The problem was that lseek of fastfs behaves differently from the posix specs.
If you do a fatfs lseek to a place beyond the actual file size and the file is 
opened for writing, he will automatically increase the file size which is not 
OK according to posix.
(lseek is called by de read function to read at an offset)

And the next time you do xFileSize() you will get a non zero result, resulting 
in the not a valid database file error.

The strange thing is that even though the file size is increased in the SW 
structures maintained by fatfs, the larger file is never actually written to 
disk so i did not notice it when checking the file system. 




-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Dan Kennedy
Sent: zaterdag 28 juli 2018 17:59
To: sqlite-users@mailinglists.sqlite.org
Subject: Re: [sqlite] sqlite on freertos/fatfs : SQLITE_NOTADB during create 
table

On 07/28/2018 10:51 PM, Bram Peeters wrote:
> Ah maybe that is also interesting to know: i put a breakpoint on the write 
> convenience wrapper in sqlite, it is never called.
> So it is not that there is a problem with the write function .
> It is that there is never an attempt to write anything to the file before it 
> is being read...
> Which is why i started looking at who might be responsible for writing 
> this, but it is a bit hard to debug why something does not happen if 
> you are not familiar with the 211k lines of code :)
>



Suggest checking the xFileSize() implementation. Is it setting the output 
variable to 0 when the file is 0 bytes in size on disk?

I think if the file on disk is zero bytes in size, this bit:

   sqlite3PagerPagecount(pBt->pPager, &nPageFile);

should set nPageFile to 0. Not 1.

Dan.




>
> Regards
> Bram
>
> ________________________________________
> From: sqlite-users [sqlite-users-boun...@mailinglists.sqlite.org] on 
> behalf of Bram Peeters [bram.peet...@dekimo.com]
> Sent: Saturday, July 28, 2018 17:45
> To: SQLite mailing list
> Subject: Re: [sqlite] sqlite on freertos/fatfs : SQLITE_NOTADB during 
> create table
>
>> An empty file and a file filled with zeros are two different things
> The file is empty/has size 0 in the file system.
>
> So the filesystem interface indeed returns SQLITE_IOERR_SHORT_READ.
>
> But the page1 pointer (this is not in the file, but in the structures managed 
> by sqlite)  points to a buffer in memory with all 0's (probably cos it is 
> malloced somewhere and it does not get filled with contents of the file).
>
> Regards,
> Bram
>
>
>
>
>
> ________________________________________
> From: sqlite-users [sqlite-users-boun...@mailinglists.sqlite.org] on 
> behalf of Clemens Ladisch [clem...@ladisch.de]
> Sent: Saturday, July 28, 2018 15:07
> To: sqlite-users@mailinglists.sqlite.org
> Subject: Re: [sqlite] sqlite on freertos/fatfs : SQLITE_NOTADB during 
> create table
>
> Bram Peeters wrote:
>> He reads a page from the file in sqlite3PagerSharedLock, but the file is 
>> still 0 so the page is all zeros.
>
> An empty file and a file filled with zeros are two different things.
>
> Does the file system return SQLITE_IOERR_SHORT_READ?
>
>
> Regards,
> Clemens
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to