I realize that drh responded he will remove such uses of ftruncate
doing this sort of thing in the future, but for sqlite 3.5.3 and previous 
it would be marginally more efficient if you only checked the file 
size after ftruncate fails and take appropriate action. This way the 
"typical" use of ftruncate would not be slowed down. You should probably 
zero-fill the extension only because that's what Linux does, and you'd 
produce databases that are byte-for-byte md5sum identical, which could
aid testing and validation.

--- Mark Brown <[EMAIL PROTECTED]> wrote:
> For the method: static int unixTruncate(sqlite3_file *id, i64 nByte)
> 
> It seems like an easy fix would be:
> 
> 1.) Check size of file
> 2.) If file size is less than or equal to nByte, call ftruncate.
> 3.) Else, lseek to position nByte-1 and then write a NULL character at that
> position.
> 
> That will quickly expand the size of the file to desired size.  However, I
> think the fill for the file will be random.
> 
> So, the question would be:  Is it ok for the data in the extended portion of
> the file to be something other than NULL characters?  Does SQLite already
> know that this area of the file is not valid, or does it assume (from the
> ftruncate documentation) that the file will be zero-extended?
> 
> Thanks,
> Mark
> 
> 
> > -----Original Message-----
> > From: Joe Wilson [mailto:[EMAIL PROTECTED] 
> > Sent: Thursday, November 29, 2007 9:28 AM
> > To: sqlite-users@sqlite.org
> > Subject: Re: [sqlite] ftruncate() for values greater than file size
> > 
> > 
> > > On Nov 29, 2007, at 9:19 PM, Mark Brown wrote:
> > > > I have finally tracked down a bug that has plagued by vxWorks  
> > > > port.  It
> > > > appears that our file system's implementation of 
> > ftruncate() does  
> > > > not like
> > > > to "truncate" a file larger than its current size, and returns  
> > > > EINVAL for
> > > > this operation.
> > 
> > This is interesting - ftruncate's behavior is not defined by POSIX
> > in this case.  SQLite shouldn't rely on the commonly implemented 
> > zero-fill extension.
> > 
> >  http://www.opengroup.org/onlinepubs/007908799/xsh/ftruncate.html
> > 
> >  "If the file previously was larger than length, the extra data is 
> >  discarded. If it was previously shorter than length, it is 
> > unspecified 
> >  whether the file is changed or its size increased."
> > 
> > One could easily write a wrapper function for ftruncate and use it
> > instead.



      
____________________________________________________________________________________
Get easy, one-click access to your favorites. 
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs 

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to