corrupted tdb files under FreeBSD (Was Re: Why do we truncate the file and write to it in expand_file in tdb.c)

Richard Sharpe rsharpe at richardsharpe.com
Wed Mar 30 18:56:44 GMT 2005


On Wed, 30 Mar 2005, Richard Sharpe wrote:

> In tdb.c, when we are expanding the tdb file, in expand_file, the first
> thing we do is:
>
>         char buf[1024];
> #if HAVE_FTRUNCATE_EXTEND
>         if (ftruncate(tdb->fd, size+addition) != 0) {
>                 TDB_LOG((tdb, 0, "expand_file ftruncate to %d failed
> (%s)\n",
>                            size+addition, strerror(errno)));
>                 return -1;
>         }
> #else
>
> Then, below, we write 'B' to every byte of the extended portion.
>
> So, why do we bother to ftruncate the file?

So, I was complaining on another list that tdb's use of mmap/munmap on
FreeBSD lead to corrupted tdb files.

I have now tested the removal of ftruncate on FreeBSD 4.10, and things
work correctly.

I will soon test on Linux and another version of FreeBSD, and if all works
OK, I propose removing the seemingly bogus ftruncate (etc) code from
expand_file in tdb.c.

Regards
-----
Richard Sharpe, rsharpe[at]richardsharpe.com, rsharpe[at]samba.org,
sharpe[at]ethereal.com, http://www.richardsharpe.com


More information about the samba-technical mailing list